Эх сурвалжийг харах

refactor: 更改登录逻辑

await 11 сар өмнө
parent
commit
98fb4d86a5

+ 61 - 5
src/pages/home/index.tsx

@@ -12,7 +12,7 @@ import UserHelper from "@/helper/userHelper";
 import ImageUtil from "@/utils/imgUtils";
 import RouteUtil from "@/utils/routeUtil";
 import { Image, ScrollView, View, Text } from "@tarojs/components";
-import { pxTransform } from "@tarojs/taro";
+import Taro, { pxTransform } from "@tarojs/taro";
 import { useRequest } from "ahooks";
 import React, { useContext, useMemo, useState } from "react";
 
@@ -20,6 +20,7 @@ const Home = () => {
   const appContext = useContext(AppContext);
   const { screenWidth, statusBarHeight } = appContext.systemInfo!;
   const [bottomRemark, setBottomRemark] = useState('')
+  const isUserLogin = UserHelper.isLogin()
 
   const indexInfoResult = useRequest(() => {
     return UserApi.getIndexInfoUsingPost({
@@ -67,6 +68,61 @@ const Home = () => {
       </View>
     );
   };
+
+
+  const ApplyButton = ({ isLogin }) => {
+    console.log("isLogin", isLogin)
+    return (
+      <>
+        {
+          isLogin ? (<Button className='index-back-btn' onClick={() => {
+            UserHelper.afterLogin({
+              pop: false,
+              callback: async () => {
+                indexInfoResult.data &&
+                  RouteUtil.toWebViewPage({
+                    url: indexInfoResult.data.link,
+                  });
+              },
+            });
+          }}
+          >立即申请额度</Button>) : (<Button openType='getPhoneNumber' 
+            onGetPhoneNumber={async (e) => {
+          if (e.detail.code && await UserHelper.userWxLogin(e.detail.code) === true) {
+            indexInfoResult.data &&
+            RouteUtil.toWebViewPage({
+              url: indexInfoResult.data.link,
+            });
+              // if (params.callbackBeforeRoute?.toString() === "1") {
+              //     console.log('进来了', params)
+              //     if (params.page) {
+              //         RouteUtil.replace(params.page, { params: params.params });
+              //     }
+              //     else {
+              //         +pop && RouteUtil.pop();
+              //     }
+              // }
+              // console.log('进来了----71', params)
+              if (UserHelper.callback) {
+                  await UserHelper.callback();
+              }
+              // if (params.callbackBeforeRoute?.toString() !== "1") {
+              //     if (params.page) {
+              //         RouteUtil.replace(params.page, { params: params.params });
+              //     }
+              //     else {
+
+              //         +pop && RouteUtil.pop();
+              //     }
+              // }
+          }
+      }} fill
+            className='index-back-btn'
+          >立即申请额度</Button>)
+        }
+      </>
+    )
+  }
   return (
     <Layout safe className='index' bottomBarIndex={0}>
       <ScrollView className='index-container'>
@@ -111,7 +167,8 @@ const Home = () => {
                 <View className='index-back-btn-tip'>
                   现在申请,最快1分钟激活额度
                 </View>
-                <Button
+                <ApplyButton isLogin={isUserLogin}></ApplyButton>
+                {/* <Button
                   onClick={() => {
                     UserHelper.afterLogin({
                       pop: false,
@@ -125,8 +182,8 @@ const Home = () => {
                   }}
                   className='index-back-btn'
                 >
-                  {indexInfoResult.data?.name || "立即激活"}
-                </Button>
+                  立即申请额度
+                </Button> */}
               </View>
             </Flex>
           </View>
@@ -190,7 +247,6 @@ const Home = () => {
         >
           <View>
             { bottomRemark }
-            {/* { channelResult.data?.bottomRemark || "哈哈哈哈" } */}
             {/* 郑重声明:平台只提供贷款咨询和推荐服务,放款由银行或金融机构进行,贷款额度、放款时间以资金分审批结果为准,所有贷款申请在未成功贷款前绝不收取任何费用,为了保证您的资金安全,请不要相信任何要求您支付费用的信息、邮件、电话等不实信息。 */}
           </View>
           <View>如遇问题请向{ channelResult.data?.customerServiceInfo || '400-003-9350'}举报投诉,平台将及时为您解决!</View>

+ 44 - 2
src/pages/user/mine/index.tsx

@@ -22,11 +22,52 @@ const Mine = (props: PropsWithChildren<IMineProps>) => {
   const { screenSize } = useContext(AppContext);
   const { statusBarHeight } = appContext.systemInfo!;
   const userInfo = useStore((p) => p.userInfo);
+  const isUserLogin = UserHelper.isLogin()
+
   const indexInfoResult = useRequest(() => {
     return UserApi.getIndexInfoUsingPost({
       params: { appId: APPConfig.APPID },
     }).toData();
   });
+
+
+
+  const ApplyButton = ({ isLogin }) => {
+    console.log("isLogin", isLogin)
+    return (
+      <>
+        {
+          isLogin ? (<Button className='mine-apply-panel-button' onClick={() => {
+            UserHelper.afterLogin({
+              pop: false,
+              callback: async () => {
+                indexInfoResult.data &&
+                  RouteUtil.toWebViewPage({
+                    url: indexInfoResult.data.link,
+                  });
+              },
+            });
+          }}
+          >立即申请</Button>) : (<Button openType='getPhoneNumber' 
+            onGetPhoneNumber={async (e) => {
+          if (e.detail.code && await UserHelper.userWxLogin(e.detail.code) === true) {
+            indexInfoResult.data &&
+            RouteUtil.toWebViewPage({
+              url: indexInfoResult.data.link,
+            });
+              if (UserHelper.callback) {
+                  await UserHelper.callback();
+              }
+          }
+      }}
+            className='mine-apply-panel-button'
+          >立即申请</Button>)
+        }
+      </>
+    )
+  }
+  
+
   return (
     <Layout className='mine' bottomBarIndex={1}>
       <SizeBox height={statusBarHeight}></SizeBox>
@@ -44,7 +85,7 @@ const Mine = (props: PropsWithChildren<IMineProps>) => {
         <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
+          {/* <Button
             className='mine-apply-panel-button'
             onClick={() => {
               UserHelper.afterLogin({
@@ -59,7 +100,8 @@ const Mine = (props: PropsWithChildren<IMineProps>) => {
             }}
           >
             立即申请
-          </Button>
+          </Button> */}
+          <ApplyButton isLogin={isUserLogin}></ApplyButton>
         </Flex>
         <Flex
           justifyContent='flex-start'