From 7ed1e4f30ba4d8204152cb157ceaee07374da080 Mon Sep 17 00:00:00 2001
From: zhengyiming <540361168@qq.com>
Date: 星期一, 17 三月 2025 14:29:14 +0800
Subject: [PATCH] fix: 修改支付方式选择

---
 apps/taro/src/stores/modules/user.ts |  157 ++++++++++++++++++++++++++++++++++------------------
 1 files changed, 102 insertions(+), 55 deletions(-)

diff --git a/apps/taro/src/stores/modules/user.ts b/apps/taro/src/stores/modules/user.ts
index 7c3f0ab..7b10216 100644
--- a/apps/taro/src/stores/modules/user.ts
+++ b/apps/taro/src/stores/modules/user.ts
@@ -8,9 +8,12 @@
   setUserDetail,
   getUserDetail,
   removeUserDetail,
+  setStorageVirtualUserId,
+  getStorageVirtualUserId,
+  removeStorageVirtualUserId,
+  LoginVirtualRes,
 } from '@/utils/storage/auth';
 import * as accountServices from '@life-payment/services/api/Account';
-import * as userServices from '@life-payment/services/api/User';
 import Taro, { useRouter } from '@tarojs/taro';
 import { ButtonProps } from '@tarojs/components';
 import { debounce } from 'lodash';
@@ -29,13 +32,19 @@
   locationCity?: string;
   locationProvince?: string;
   firstSetLocation?: boolean;
+
+  virtualUserId?: string;
+  virtualPhoneNumber?: string;
+
+  wxCode?: string;
+  wxOpenId?: string;
 }
 
 const goAuthorization = debounce(
   () => {
     const route = Taro.getCurrentInstance().router;
     if (route.path !== RouterPath.authorization) {
-      Taro.navigateTo({
+      RouteHelper.navigateTo({
         url: RouterPath.authorization,
       });
     }
@@ -52,6 +61,7 @@
   state: (): UserState => {
     const userInfo = getCacheUserInfo();
     const userDetail = getUserDetail();
+    const storageVirtualUser = getStorageVirtualUserId();
 
     return {
       // user info
@@ -62,6 +72,12 @@
       refreshToken: userInfo?.refreshToken ?? '',
       userDetail: userDetail,
       firstGetUserDetail: true,
+
+      virtualUserId: storageVirtualUser?.virtualUserId ?? '',
+      virtualPhoneNumber: storageVirtualUser?.virtualPhoneNumber ?? '',
+
+      wxCode: '',
+      wxOpenId: '',
     };
   },
   getters: {
@@ -93,56 +109,61 @@
       wxMiniAppUserLoginRes: any
     ) {
       try {
-        let res: API.IdentityModelTokenCacheItem;
-        if (!wxMiniAppUserLoginRes.accessToken) {
-          let params: API.WxMiniAppPhoneLoginInput = {
-            openId: wxMiniAppUserLoginRes.openId,
-            sessionKey: wxMiniAppUserLoginRes.sessionKey,
-            encryptedData: detail.encryptedData,
-            iv: detail.iv,
-            // wxMiniApp: WxMiniAppEnum.C绔皬绋嬪簭,
-          };
-          res = await accountServices.wxMiniAppPhoneAuthLogin(params);
-          this.loginSuccess(res);
-        }
-        return res;
+        // let res: API.IdentityModelTokenCacheItem;
+        // if (!wxMiniAppUserLoginRes.accessToken) {
+        //   let params: API.WxMiniAppPhoneLoginInput = {
+        //     openId: wxMiniAppUserLoginRes.openId,
+        //     sessionKey: wxMiniAppUserLoginRes.sessionKey,
+        //     encryptedData: detail.encryptedData,
+        //     iv: detail.iv,
+        //     // wxMiniApp: WxMiniAppEnum.C绔皬绋嬪簭,
+        //   };
+        //   res = await accountServices.wxMiniAppPhoneAuthLogin(params);
+        //   this.loginSuccess(res);
+        // }
+        // return res;
+        return 1;
       } catch (error) {
         console.log('error3: ', error);
       }
     },
 
     // 鐢ㄦ埛鎵嬫満楠岃瘉鐮佺櫥鍏�
-    async loginByUsername(data: API.PhoneMesssageCodeLoginInput) {
-      let res = await accountServices.phoneMesssageCodeLogin(
+    async loginByUsername(data: any) {
+      let res = await accountServices.lifePayPhoneMesssageCodeLogin(
         {
           phoneNumber: data.phoneNumber,
-          code: data.code,
+          // code: data.code,
         },
         { showLoading: false }
       );
 
       if (res) {
-        this.loginSuccess(res);
+        this.loginVirtualSuccess({
+          virtualUserId: res,
+          virtualPhoneNumber: data.phoneNumber,
+        });
       }
       return res;
     },
 
     // 鐢ㄦ埛璐﹀彿瀵嗙爜鐧诲叆
     async loginByPassword(data: API.AccessRequestDto) {
-      let res = await accountServices.passwordLogin(
-        {
-          loginName: data.userName,
-          password: data.userPassword,
-        },
-        { showLoading: false }
-      );
-      if (res) {
-        this.loginSuccess(res);
-      }
-      return res;
+      // let res = await accountServices.passwordLogin(
+      //   {
+      //     loginName: data.userName,
+      //     password: data.userPassword,
+      //   },
+      //   { showLoading: false }
+      // );
+      // if (res) {
+      //   this.loginSuccess(res);
+      // }
+      // return res;
     },
 
     async loginSuccess(res: API.IdentityModelTokenCacheItem) {
+      console.log('res: ', res);
       try {
         this.setUserInfoAction(res);
         this.setTokenAction(res);
@@ -150,15 +171,28 @@
       } catch (error) {}
     },
 
+    async loginVirtualSuccess(virtualUserRes: LoginVirtualRes) {
+      try {
+        this.setVirtualUserId(virtualUserRes);
+      } catch (error) {}
+    },
+
+    setVirtualUserId(virtualUserRes: LoginVirtualRes) {
+      this.virtualUserId = virtualUserRes.virtualUserId;
+      this.virtualPhoneNumber = virtualUserRes.virtualPhoneNumber;
+      setStorageVirtualUserId(virtualUserRes);
+    },
+
     async wxMiniAppUserLoginFromScan(wxIndentityRes: API.WxMiniAppIndentityInfo, uuid: string) {
       try {
-        let res = await accountServices.wxMiniAppUserLoginFromScan({
-          uId: uuid,
-          userName: wxIndentityRes.userName,
-          openId: wxIndentityRes.openId,
-        });
-        this.loginSuccess(res);
-        return res;
+        // let res = await accountServices.wxMiniAppUserLoginFromScan({
+        //   uId: uuid,
+        //   userName: wxIndentityRes.userName,
+        //   openId: wxIndentityRes.openId,
+        // });
+        // this.loginSuccess(res);
+        // return res;
+        return 1;
       } catch (error) {}
     },
 
@@ -168,28 +202,29 @@
       uuid: string
     ) {
       try {
-        let res = await accountServices.wxMiniAppPhoneAuthLoginFromScan({
-          uId: uuid,
-          openId: wxIndentityRes.openId,
-          sessionKey: wxIndentityRes.sessionKey,
-          encryptedData: detail.encryptedData,
-          iv: detail.iv,
-          // wxMiniApp: WxMiniAppEnum.C绔皬绋嬪簭,
-        });
-        this.loginSuccess(res);
-        return res;
+        // let res = await accountServices.wxMiniAppPhoneAuthLoginFromScan({
+        //   uId: uuid,
+        //   openId: wxIndentityRes.openId,
+        //   sessionKey: wxIndentityRes.sessionKey,
+        //   encryptedData: detail.encryptedData,
+        //   iv: detail.iv,
+        //   // wxMiniApp: WxMiniAppEnum.C绔皬绋嬪簭,
+        // });
+        // this.loginSuccess(res);
+        // return res;
+        return 1;
       } catch (error) {}
     },
 
     async getCurrentUserInfo() {
       try {
-        let res = await userServices.getUserInfo({ showLoading: false });
-        if (res) {
-          res.originalAvatarUrl = res.avatarUrl;
-          res.avatarUrl = res.avatarUrl ? setOSSLink(res.avatarUrl) : DefaultAvatar;
-          this.setUserDetail(res);
-          this.firstGetUserDetail = false;
-        }
+        // let res = await userServices.getUserInfo({ showLoading: false });
+        // if (res) {
+        //   res.originalAvatarUrl = res.avatarUrl;
+        //   res.avatarUrl = res.avatarUrl ? setOSSLink(res.avatarUrl) : DefaultAvatar;
+        //   this.setUserDetail(res);
+        //   this.firstGetUserDetail = false;
+        // }
       } catch (error) {}
     },
 
@@ -208,13 +243,25 @@
       setUserDetail(detail);
     },
 
+    setWxCode(code: string) {
+      this.wxCode = code;
+    },
+    setWxOpenId(openId: string) {
+      this.wxOpenId = openId;
+    },
+
     resetState() {
       this.userInfo = null;
       this.token = '';
       this.refreshToken = '';
       this.userDetail = null;
+      this.virtualUserId = '';
+      this.virtualPhoneNumber = '';
+      this.wxCode = '';
+      this.wxOpenId = '';
       removeUserInfo();
       removeUserDetail();
+      removeStorageVirtualUserId();
     },
 
     /**
@@ -223,7 +270,7 @@
     logout() {
       this.resetState();
       myClient.removeQueries();
-      goAuthorization();
+      // goAuthorization();
     },
 
     logoutAndToHome() {

--
Gitblit v1.9.1