Просмотр исходного кода

perf(小程序/代码): 代码格式化

qq12rrr 1 день назад
Родитель
Сommit
0eba536b3d
3 измененных файлов с 229 добавлено и 199 удалено
  1. 25 29
      src/pages/bottomNavBar/index.tsx
  2. 93 73
      src/pages/home/index.tsx
  3. 111 97
      src/pages/user/mine/index.tsx

+ 25 - 29
src/pages/bottomNavBar/index.tsx

@@ -1,32 +1,28 @@
-import { useState } from 'react';
-import Home from '../home';
-import Mine from '../user/mine';
-import BottomBarContext from '@/context/bottomBarContext';
-import useStore from '@/hooks/useRedux';
-
+import { useState } from "react";
+import Home from "../home";
+import Mine from "../user/mine";
+import BottomBarContext from "@/context/bottomBarContext";
+import useStore from "@/hooks/useRedux";
 
 const BottomNavBar = () => {
-    const [index, setIndex] = useState(0);
-    const menu = useStore(p => p.tabMenu);
-    return (
-        <BottomBarContext.Provider value={{
-            switchTo: setIndex,
-            index
-        }}  >
-            {
-                menu.map(p => {
-                    if (p.code === "home") {
-                        return (
-                            <Home />
-                        )
-                    }
-                    else if (p.code === "user_center") {
-                        return <Mine />
-                    }
-                })
-            }
-        </BottomBarContext.Provider>
-    )
-}
+  const [index, setIndex] = useState(0);
+  const menu = useStore((p) => p.tabMenu);
+  return (
+    <BottomBarContext.Provider
+      value={{
+        switchTo: setIndex,
+        index,
+      }}
+    >
+      {menu.map((p) => {
+        if (p.code === "home") {
+          return <Home />;
+        } else if (p.code === "user_center") {
+          return <Mine />;
+        }
+      })}
+    </BottomBarContext.Provider>
+  );
+};
 
-export default BottomNavBar;
+export default BottomNavBar;

+ 93 - 73
src/pages/home/index.tsx

@@ -16,52 +16,59 @@ import { Image, ScrollView, View, Text, Input } from "@tarojs/components";
 import { parseQueryParams, isOuterLink } from "@/utils/toolsUtil";
 import Taro, { pxTransform } from "@tarojs/taro";
 import { useRequest } from "ahooks";
-import React, { useContext, useMemo, useState , useEffect ,useRef } from "react";
+import React, { useContext, useMemo, useState, useEffect, useRef } from "react";
 import LoginBox from "../user/components/LoginBox";
 
 const Home = () => {
-  const childRef:any = useRef()
+  const childRef: any = useRef();
   const handleOpen = () => {
-    childRef.current.handleOpen()
-  }
+    childRef.current.handleOpen();
+  };
   const appContext = useContext(AppContext);
   const { screenWidth, statusBarHeight } = appContext.systemInfo!;
-  const [bottomRemark, setBottomRemark] = useState('')
-  const isUserLogin = UserHelper.isLogin()
+  const [bottomRemark, setBottomRemark] = useState("");
+  const isUserLogin = UserHelper.isLogin();
   const indexInfoResult = useRequest(() => {
     return UserApi.getIndexInfoUsingPost({
       params: { appId: APPConfig.APPID },
     }).toData();
   });
-  
+
   const channelResult = useRequest(() => {
     return UserApi.homeFetchChannel({
-      data: { channelCode: 'hrqbxcx', refer: '' },
-    }).toData().then(res => {
-      setBottomRemark(res.bottom_remark)
+      data: { channelCode: "hrqbxcx", refer: "" },
     })
+      .toData()
+      .then((res) => {
+        setBottomRemark(res.bottom_remark);
+      });
   });
 
   const postJumpUrlResult = () => {
-          const params = parseQueryParams(indexInfoResult.data.link)
-          return UserApi.getJumpUrlPost({
-            loading: true,
-            data: { appId: APPConfig.APPID, channelCode: params.channelCode, productId: params.productId }
-          }).toData().then(res => {
-            console.log("获取跳转链接结果", res)
-            RouteUtil.toWebViewPage({ url: res?.adJumpLink })
-          })
-  }
+    const params = parseQueryParams(indexInfoResult.data.link);
+    return UserApi.getJumpUrlPost({
+      loading: true,
+      data: {
+        appId: APPConfig.APPID,
+        channelCode: params.channelCode,
+        productId: params.productId,
+      },
+    })
+      .toData()
+      .then((res) => {
+        console.log("获取跳转链接结果", res);
+        RouteUtil.toWebViewPage({ url: res?.adJumpLink });
+      });
+  };
 
   const loginFlowHandler = async () => {
-    await UserHelper.UpdateOpenId()
+    await UserHelper.UpdateOpenId();
     if (isOuterLink(indexInfoResult.data.link)) {
-      await postJumpUrlResult()
+      await postJumpUrlResult();
     } else {
-      await RouteUtil.toWebViewPage({ url: indexInfoResult.data.link })
+      await RouteUtil.toWebViewPage({ url: indexInfoResult.data.link });
     }
-  }
-
+  };
 
   const imgBackStyle = useMemo(() => {
     return {
@@ -73,21 +80,21 @@ const Home = () => {
     return (
       <View style={imgBackStyle}>
         <Image
-          className='background-image'
+          className="background-image"
           src={require(`../../assets/icon_home_characteristic_b_${index}.png`)}
         />
         <Flex
-          rowGap='sm'
-          className='background-content background-content-wrap'
+          rowGap="sm"
+          className="background-content background-content-wrap"
         >
-          <Flex columnGap='sm' direction='row' alignItem='center'>
+          <Flex columnGap="sm" direction="row" alignItem="center">
             <Image
-              className='background-content-i'
+              className="background-content-i"
               src={require(`../../assets/icon_home_characteristic_i_${index}.png`)}
             />
             <Label bold>{title}</Label>
           </Flex>
-          <Label style={{ fontSize: pxTransform(22) }} type='secondary'>
+          <Label style={{ fontSize: pxTransform(22) }} type="secondary">
             {desc}
           </Label>
         </Flex>
@@ -95,33 +102,42 @@ const Home = () => {
     );
   };
 
-  const BottomRemark = () => bottomRemark.split(';').map(text => <View style={{ margin: '4px 0' }}>{text}</View>)
+  const BottomRemark = () =>
+    bottomRemark
+      .split(";")
+      .map((text) => <View style={{ margin: "4px 0" }}>{text}</View>);
   const ApplyButton = ({ isLogin }) => {
     return (
       <>
-        {
-          isLogin ? (<Button className='index-back-btn' onClick={() => {
-            UserHelper.afterLogin({
-              pop: false,
-              callback: async () => {
-                indexInfoResult.data && loginFlowHandler()
-                // indexInfoResult.data && postJumpUrlResult()
+        {isLogin ? (
+          <Button
+            className="index-back-btn"
+            onClick={() => {
+              UserHelper.afterLogin({
+                pop: false,
+                callback: async () => {
+                  indexInfoResult.data && loginFlowHandler();
+                  // indexInfoResult.data && postJumpUrlResult()
                   // RouteUtil.toWebViewPage({
                   //   url: indexInfoResult.data.link,
                   // });
-              },
-            });
-          }}
-          >立即申请额度</Button>) : (<Button onClick={handleOpen} fill
-            className='index-back-btn'
-          >立即申请</Button>)
-        }
+                },
+              });
+            }}
+          >
+            立即申请额度
+          </Button>
+        ) : (
+          <Button onClick={handleOpen} fill className="index-back-btn">
+            立即申请
+          </Button>
+        )}
       </>
-    )
-  }
+    );
+  };
   return (
-    <Layout safe className='index' bottomBarIndex={0}>
-      <ScrollView className='index-container'>
+    <Layout safe className="index" bottomBarIndex={0}>
+      <ScrollView className="index-container">
         <SizeBox height={statusBarHeight} />
         <SizeBox height={60} />
         {/* <Image
@@ -137,30 +153,30 @@ const Home = () => {
               ),
               position: "relative",
             }}
-            className='index-panel'
+            className="index-panel"
           >
             <Flex
-              alignItem='center'
-              justifyContent='center'
+              alignItem="center"
+              justifyContent="center"
               // rowGap={24}
-              className='index-back-content'
+              className="index-back-content"
             >
-              <Label className='index-back-se'>最高可申请(元)</Label>
-              <Label className='index-back-amount'>200,000.00</Label>
-              <View className='index-back-tip'>具体额度以资金方审批为准</View>
+              <Label className="index-back-se">最高可申请(元)</Label>
+              <Label className="index-back-amount">200,000.00</Label>
+              <View className="index-back-tip">具体额度以资金方审批为准</View>
               <Flex
-                alignItem='center'
-                justifyContent='center'
-                direction='row'
-                className='index-back-info'
+                alignItem="center"
+                justifyContent="center"
+                direction="row"
+                className="index-back-info"
                 columnGap={12}
               >
                 <Text>年化利率7.2-24%(单利)</Text>
-                <View className='split-char'></View>
+                <View className="split-char"></View>
                 <Text>期限3-36个月</Text>
               </Flex>
-              <View className='index-back-btn-container'>
-                <View className='index-back-btn-tip'>
+              <View className="index-back-btn-container">
+                <View className="index-back-btn-tip">
                   现在申请,快速评估需求
                 </View>
                 <ApplyButton isLogin={isUserLogin}></ApplyButton>
@@ -183,12 +199,12 @@ const Home = () => {
               </View>
             </Flex>
           </View>
-          <View className='index-step-container'>
-            <View className='background'></View>
+          <View className="index-step-container">
+            <View className="background"></View>
             <Flex
-              alignItem='center'
-              justifyContent='center'
-              direction='row'
+              alignItem="center"
+              justifyContent="center"
+              direction="row"
               columnGap={8}
             >
               <Text>01.提交申请</Text>
@@ -231,22 +247,26 @@ const Home = () => {
         <Padding padding={EdgeInsets.symmetric({ horizontal: 32 })}>
           <Image
             src={require("../../assets/new-edition/platform.png")}
-            className='index-platform-image'
+            className="index-platform-image"
           />
         </Padding>
 
         <Flex
-          justifyContent='center'
-          alignItem='center'
+          justifyContent="center"
+          alignItem="center"
           rowGap={24}
-          className='index-bottom-tip'
+          className="index-bottom-tip"
         >
           <View>
             <BottomRemark />
             {/* { bottomRemark } */}
             {/* 郑重声明:平台只提供贷款咨询和推荐服务,放款由银行或金融机构进行,贷款额度、放款时间以资金分审批结果为准,所有贷款申请在未成功贷款前绝不收取任何费用,为了保证您的资金安全,请不要相信任何要求您支付费用的信息、邮件、电话等不实信息。 */}
           </View>
-          <View>如遇问题请向{ channelResult.data?.customerServiceInfo || '400-003-9350'}举报投诉,平台将及时为您解决!</View>
+          <View>
+            如遇问题请向
+            {channelResult.data?.customerServiceInfo || "400-003-9350"}
+            举报投诉,平台将及时为您解决!
+          </View>
         </Flex>
       </ScrollView>
       <LoginBox ref={childRef}></LoginBox>

+ 111 - 97
src/pages/user/mine/index.tsx

@@ -7,8 +7,14 @@ import Padding, { EdgeInsets } from "@/component/padding";
 import SizeBox from "@/component/sizeBox";
 import AppContext from "@/context/appContext";
 import ImageUtil from "@/utils/imgUtils";
-import { Image, View, Text ,Input, Button as TaroButton } from "@tarojs/components";
-import { PropsWithChildren, useContext ,useRef} from "react";
+import {
+  Image,
+  View,
+  Text,
+  Input,
+  Button as TaroButton,
+} from "@tarojs/components";
+import { PropsWithChildren, useContext, useRef } from "react";
 import useStore from "@/hooks/useRedux";
 import RouteUtil from "@/utils/routeUtil";
 import UserHelper from "@/helper/userHelper";
@@ -23,7 +29,7 @@ const Mine = (props: PropsWithChildren<IMineProps>) => {
   const { screenSize } = useContext(AppContext);
   const { statusBarHeight } = appContext.systemInfo!;
   const userInfo = useStore((p) => p.userInfo);
-  const isUserLogin = UserHelper.isLogin()
+  const isUserLogin = UserHelper.isLogin();
 
   const indexInfoResult = useRequest(() => {
     return UserApi.getIndexInfoUsingPost({
@@ -31,100 +37,106 @@ const Mine = (props: PropsWithChildren<IMineProps>) => {
     }).toData();
   });
 
-  const childRef:any = useRef()
+  const childRef: any = useRef();
   const handleOpen = () => {
-    childRef.current.handleOpen()
-  }
+    childRef.current.handleOpen();
+  };
   const postJumpUrlResult = () => {
-    const params = parseQueryParams(indexInfoResult.data.link)
+    const params = parseQueryParams(indexInfoResult.data.link);
     return UserApi.getJumpUrlPost({
       loading: true,
-      data: { appId: APPConfig.APPID, channelCode: params.channelCode, productId: params.productId }
-    }).toData().then(res => {
-      console.log("获取跳转链接结果", res)
-      RouteUtil.toWebViewPage({ url: res?.adJumpLink })
+      data: {
+        appId: APPConfig.APPID,
+        channelCode: params.channelCode,
+        productId: params.productId,
+      },
     })
-  }
+      .toData()
+      .then((res) => {
+        console.log("获取跳转链接结果", res);
+        RouteUtil.toWebViewPage({ url: res?.adJumpLink });
+      });
+  };
 
   const loginFlowHandler = () => {
-    UserHelper.UpdateOpenId()
+    UserHelper.UpdateOpenId();
     if (isOuterLink(indexInfoResult.data.link)) {
-      postJumpUrlResult()
+      postJumpUrlResult();
     } else {
-      RouteUtil.toWebViewPage({ url: indexInfoResult.data.link })
+      RouteUtil.toWebViewPage({ url: indexInfoResult.data.link });
     }
-  }
-
-
+  };
 
   const ApplyButton = ({ isLogin }) => {
     return (
       <>
-        {
-          isLogin ? (<Button className='mine-apply-panel-button' onClick={() => {
-            UserHelper.afterLogin({
-              pop: false,
-              callback: async () => {
-                indexInfoResult.data && loginFlowHandler()
-              },
-            });
-          }}
-          >立即申请</Button>) : (<Button onClick={handleOpen}
-            className='mine-apply-panel-button'
-          >立即申请</Button>)
-        }
+        {isLogin ? (
+          <Button
+            className="mine-apply-panel-button"
+            onClick={() => {
+              UserHelper.afterLogin({
+                pop: false,
+                callback: async () => {
+                  indexInfoResult.data && loginFlowHandler();
+                },
+              });
+            }}
+          >
+            立即申请
+          </Button>
+        ) : (
+          <Button onClick={handleOpen} className="mine-apply-panel-button">
+            立即申请
+          </Button>
+        )}
       </>
-    )
-  }
-  const LoginBoxs = ({ isLogin ,userName}) => {
-    return(
+    );
+  };
+  const LoginBoxs = ({ isLogin, userName }) => {
+    return (
       <>
-       { isLogin? 
-        <View
-          className="mine-info"
-          >
-          <Padding padding={EdgeInsets.symmetric({ horizontal: 20 })}>
-            <Image
-              src={require("../../../assets/icon_head.png")}
-              className='avatar-image-head'
-            />
-          </Padding>
-          <View className="mine-box">
-            <Text className='mine-login'>{userName}</Text>
-            <Text className='mine-text'>欢迎来到惠融钱包~</Text>
+        {isLogin ? (
+          <View className="mine-info">
+            <Padding padding={EdgeInsets.symmetric({ horizontal: 20 })}>
+              <Image
+                src={require("../../../assets/icon_head.png")}
+                className="avatar-image-head"
+              />
+            </Padding>
+            <View className="mine-box">
+              <Text className="mine-login">{userName}</Text>
+              <Text className="mine-text">欢迎来到惠融钱包~</Text>
+            </View>
           </View>
-        </View> :
-          <View
-          className="mine-info"
-          onClick={handleOpen}
-          >
-          <Padding padding={EdgeInsets.symmetric({ horizontal: 20 })}>
-            <Image
-              src={require("../../../assets/icon_head.png")}
-              className='avatar-image-head'
-            />
-          </Padding>
-          <View className="mine-box">
-            <Text className='mine-login'>登录/注册</Text>
-            <Text className='mine-text'>欢迎来到惠融钱包~</Text>
+        ) : (
+          <View className="mine-info" onClick={handleOpen}>
+            <Padding padding={EdgeInsets.symmetric({ horizontal: 20 })}>
+              <Image
+                src={require("../../../assets/icon_head.png")}
+                className="avatar-image-head"
+              />
+            </Padding>
+            <View className="mine-box">
+              <Text className="mine-login">登录/注册</Text>
+              <Text className="mine-text">欢迎来到惠融钱包~</Text>
+            </View>
           </View>
-        </View>
-      }
+        )}
       </>
-    )
-  }
-  const maskPhone = (phone:string) => {
+    );
+  };
+  const maskPhone = (phone: string) => {
     if (!phone || phone.length !== 11) return phone; // 确保电话号码有效且长度为11位
-    return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1***$2');
-  }
+    return phone.replace(/(\d{3})\d{4}(\d{4})/, "$1***$2");
+  };
   const userName = maskPhone(userInfo.userMobile);
   return (
-    <Layout className='mine' bottomBarIndex={1}>
+    <Layout className="mine" bottomBarIndex={1}>
       <SizeBox height={statusBarHeight}></SizeBox>
       <SizeBox height={36}></SizeBox>
       <LoginBoxs isLogin={isUserLogin} userName={userName}></LoginBoxs>
       <View
-        className='mine-apply-panel'
+        className="mine-apply-panel"
         style={{
           ...ImageUtil.calculationHeight(
             750 / 324,
@@ -133,9 +145,9 @@ const Mine = (props: PropsWithChildren<IMineProps>) => {
           position: "relative",
         }}
       >
-        <Text className='mine-apply-panel-title'>最高可申请(元)</Text>
-        <Flex justifyContent='space-between' alignItem='center' direction='row'>
-          <Text className='mine-apply-panel-money'>200,000</Text>
+        <Text className="mine-apply-panel-title">最高可申请(元)</Text>
+        <Flex justifyContent="space-between" alignItem="center" direction="row">
+          <Text className="mine-apply-panel-money">200,000</Text>
           {/* <Button
             className='mine-apply-panel-button'
             onClick={() => {
@@ -155,23 +167,25 @@ const Mine = (props: PropsWithChildren<IMineProps>) => {
           <ApplyButton isLogin={isUserLogin}></ApplyButton>
         </Flex>
         <Flex
-          justifyContent='flex-start'
-          alignItem='center'
-          direction='row'
+          justifyContent="flex-start"
+          alignItem="center"
+          direction="row"
           columnGap={12}
-          className='mine-apply-panel-tip'
+          className="mine-apply-panel-tip"
         >
           <Text>年化利率7.2-24%(单利)</Text>
-          <View className='split-char'></View>
+          <View className="split-char"></View>
           <Text>期限3-36个月</Text>
         </Flex>
       </View>
 
-      <View className='mine-apply-panel-warn'>
-          <Image src={require('@/assets/new-edition/icon-info.png')} className='icon-info' />
-          <Text>具体额度以资金方审批为准</Text>
-        </View>
-        
+      <View className="mine-apply-panel-warn">
+        <Image
+          src={require("@/assets/new-edition/icon-info.png")}
+          className="icon-info"
+        />
+        <Text>具体额度以资金方审批为准</Text>
+      </View>
 
       {/* <View
         style={{
@@ -201,37 +215,37 @@ const Mine = (props: PropsWithChildren<IMineProps>) => {
       </View> */}
       <SizeBox height={16} />
       <Padding padding={EdgeInsets.symmetric({ horizontal: 32 })}>
-        <View className='mine-tools-panel-title'>我的工具</View>
-        <View className='mine-tools-panel'>
+        <View className="mine-tools-panel-title">我的工具</View>
+        <View className="mine-tools-panel">
           <TaroButton
-            open-type='contact'
-            session-from='sessionFrom'
-            className='mine-tools-item'
+            open-type="contact"
+            session-from="sessionFrom"
+            className="mine-tools-item"
           >
             <Image
               src={require("@/assets/new-edition/icon-service.svg")}
-              className='mine-tools-item-icon'
+              className="mine-tools-item-icon"
             />
-            <Text className='mine-tools-item-title'>在线客服</Text>
+            <Text className="mine-tools-item-title">在线客服</Text>
             <Image
               src={require("@/assets/new-edition/icon-arrow-right.svg")}
-              className='icon-arrow'
+              className="icon-arrow"
             />
           </TaroButton>
           <View
-            className='mine-tools-item'
+            className="mine-tools-item"
             onClick={() => {
               RouteUtil.push("/pages/user/setting/index");
             }}
           >
             <Image
               src={require("@/assets/new-edition/icon-setting.svg")}
-              className='mine-tools-item-icon'
+              className="mine-tools-item-icon"
             />
-            <View className='mine-tools-item-title'>系统设置</View>
+            <View className="mine-tools-item-title">系统设置</View>
             <Image
               src={require("@/assets/new-edition/icon-arrow-right.svg")}
-              className='icon-arrow'
+              className="icon-arrow"
             />
           </View>
         </View>
@@ -247,7 +261,7 @@ const Mine = (props: PropsWithChildren<IMineProps>) => {
             });
           }}
           src={require("@/assets/new-edition/wechat-official.png")}
-          className='mine-image-wechat-official'
+          className="mine-image-wechat-official"
         />
       </Padding>
       {/* <Flex direction="row" className="mine-menu">