Kaynağa Gözat

Merge branch 'dev_v3_lqw' into dev_v3

ext.liuqiwen3 1 ay önce
ebeveyn
işleme
852fcc845c

+ 7 - 0
api/user.js

@@ -212,3 +212,10 @@ export function faceVerify(data) {
 export function getFaceVerify(data) {
   return request.post(`faceVerify/list`, data);
 }
+/**
+ * 微信登录
+ *
+ */
+export function wxLogin(data) {
+  return request.post('login/loginAuthorize', data, {noAuth:true,noVerify:true});
+}

+ 9 - 2
pages/index/index.vue

@@ -283,6 +283,8 @@ onLoad(async (options) => {
       toLogin();
       return; // 登录后页面会刷新,避免继续执行
     }
+  }else if(appStore?.userInfo?.lastVisitedMerchantId){
+    merchantId.value = appStore?.userInfo?.lastVisitedMerchantId;
   } else if (appStore?.userInfo?.merchant?.id) {
     merchantId.value = appStore.userInfo.merchant.id;
   } else {
@@ -298,19 +300,24 @@ onLoad(async (options) => {
 onShow(async () => {
   // 隐藏原生 tabBar,使用自定义 tabBar
   uni.hideTabBar();
-  
+  console.log('appStore.userInfo',appStore.userInfo)
   const isLogin = appStore.isLogin;
   if(isLogin){
     rightsStore.getUserBenefits(appStore.userInfo?.userId);
     getUserBenefits();
   }
   if (appStore.merchantId && appStore.merchantId !== '') {
+    console.log('111111111')
     merchantId.value = appStore.merchantId;
     if (!isLogin) {
       toLogin();
       return; // 登录后页面会刷新,避免继续执行
     }
+  }else if(appStore?.userInfo?.lastVisitedMerchantId){
+    console.log('2222222222222222')
+    merchantId.value = appStore?.userInfo?.lastVisitedMerchantId;
   } else if (appStore?.userInfo?.merchant?.id) {
+    console.log('333333333333333')
     merchantId.value = appStore.userInfo.merchant.id;
     if(!merchantInfo.merchantName){
       getSbmerchantInfoFn()
@@ -586,7 +593,7 @@ const toGoodsCate = (item) => {
   uni.switchTab({url:`/pages/goods_cate/goods_cate`})
 }
 const merchantNameShow = () => {
-  if(!appStore.userInfo ||((appStore.userInfo && !appStore.userInfo.merchant && !appStore.merchantId))){
+  if(!appStore.userInfo ||(appStore.userInfo && !appStore.userInfo.merchant && !appStore.merchantId && !appStore.userInfo.lastVisitedMerchantId)){
     return true;
   }else{
     return false;

+ 1 - 1
pages/merchantCenter/index.vue

@@ -147,7 +147,7 @@ const commonFunctions = computed(() => {
     { src: `${HTTP_REQUEST_URL_IMG}setting/fabu.png`, name: '发布商品',pageUrl:'/pages/merchantCenters/postInformation',show:true },
     { src: `${HTTP_REQUEST_URL_IMG}setting/shangpin.png`, name: '商品管理',pageUrl:'/pages/merchantCenters/productManagement',show:true },
     { src: `${HTTP_REQUEST_URL_IMG}setting/kucun.png`, name: '库存管理',pageUrl:'/pages/users/user_asset/asset_info/asset_info' ,show:!kcglShow.value},
-    { src: `${HTTP_REQUEST_URL_IMG}setting/jinqian.png`, name: '我的收益',pageUrl: '/pages/users/my_merchant/index' ,show:wdsyShow.value},
+    { src: `${HTTP_REQUEST_URL_IMG}setting/jinqian.png`, name: '我的收益',pageUrl: '' ,show:wdsyShow.value},
     { src: `${HTTP_REQUEST_URL_IMG}setting/kabao.png`, name: '卡包管理',pageUrl: '/pages/users/card_page/indexWX' ,show:!kcglShow.value},
     { src: `${HTTP_REQUEST_URL_IMG}setting/mendian.png`, name: '门店推广',pageUrl: '/pages/users/my_merchant/index',show:true },
     { src: `${HTTP_REQUEST_URL_IMG}setting/dianpu.png`, name: '我的商城',pageUrl: `/pages/index/index` ,show:true},

+ 2 - 2
pages/user/index.vue

@@ -45,7 +45,7 @@
                 {{ userInfoAddres }}
               </view>
 
-              <view class="item" v-if="appStore.$userInfo?.sex !== 0">{{ sexMap[appStore.$userInfo?.sex] }}·{{ appStore.$userInfo?.age }}岁</view>
+              <view class="item" v-if="appStore.$userInfo?.sex && appStore.$userInfo?.sex !== 0 ">{{ sexMap[appStore.$userInfo?.sex] }}·{{ appStore.$userInfo?.age }}岁</view>
             </view>
           </view>
         </view>
@@ -505,7 +505,7 @@ const viewTransactionDetail = () => {
     toLogin();
   } else {
     // uni.navigateTo({ url: "/pages/users/vault/index" });
-    goDetail("/pages/users/vault/indexWX")
+    goDetail("/pages/users/vault/index1")
   }
 };
 

+ 1 - 1
pages/users/browsing_history/index.vue

@@ -7,7 +7,7 @@
           class="record-item"
       >
         <view>
-          <image class="icon-container" :src="record.merchantLogo" mode="aspectFit"></image>
+          <image class="icon-container" :src="record.merchantLogo"></image>
         </view>
         <view class="info-container">
           <view class="shop-name">{{ record.merchantName }}</view>

+ 39 - 4
pages/users/login/index.vue

@@ -58,8 +58,9 @@
 				<view class="privacy-text" @click.stop="openPrivacy">《隐私政策》</view>
 			</div>
 			<view class="footer">
-				<div class="logon" @click="loginMobile" v-if="current !== 0">登录</div>
-				<div class="logon" @click="submit" v-if="current === 0">登录</div>
+				<button class="logon" @click="loginMobile" v-if="current !== 0">登录</button>
+				<button class="logonWX"  open-type="getPhoneNumber" @getphonenumber="getPhoneNumberFn" v-if="current !== 0">微信登录</button>
+				<button class="logon" @click="submit" v-if="current === 0">登录</button>
 			</view>
 		
 		</div>
@@ -97,6 +98,7 @@
 		useSendCode
 	} from "@/hooks/useSendCode";
 	import Cache from "@/utils/cache";
+  import { getPhoneNumber } from "@/utils/util.js";
 	import {
 		useToast
 	} from "@/hooks/useToast.js";
@@ -464,6 +466,26 @@
     const res = await footprintScan(data);
     Toast({ title: "登录成功" });
     backHome();
+  }
+  const getPhoneNumberFn = async (e) => {
+    // Toast({ title: "登录中..." });
+    if (!aloneChecked.value) {
+      return Toast({
+        title: "请阅读并同意用户协议和隐私政策",
+        icon: "none"
+      });
+    }
+    const res = await getPhoneNumber(e);
+    console.log('res',res);
+    if (res) {
+      appStore.LOGIN({
+        token: res.data.token
+      });
+      // 保存过期时间(999天后过期)
+      const expiresTime = Math.round(new Date() / 1000) + 999 * 24 * 60 * 60;
+      Cache.set(EXPIRES_TIME, expiresTime, 0);
+      await getUserInfoFn(res.data);
+    }
   }
 	onLoad(() => {
     console.log(appStore.$wxConfig)
@@ -694,8 +716,21 @@
 				font-size: 32rpx;
 				font-weight: bold;
 			}
-
-			
+      .logonWX{
+        display: flex;
+        align-items: center;
+        justify-content: center;
+        height: 88rpx;
+        background-color: #28C445;
+        border-radius: 16rpx;
+        color: #ffffff;
+        font-size: 32rpx;
+        font-weight: bold;
+        margin-top: 30rpx;
+      }
+      .logonWX[disabled]{
+        background-color: #BEEDC7;
+      }
 		}
 
 		.privacy-box {

+ 39 - 0
utils/util.js

@@ -7,6 +7,7 @@ import { footprintScan } from "@/api/merchant.js";
 import { pathToBase64 } from "@/plugin/image-tools/index.js";
 import { useToast } from "@/hooks/useToast";
 import pageJson from "@/pages.json";
+import { wxLogin } from "@/api/user.js";
 const appStore = useAppStore(); // 调用函数获取实例
 export default {
   /**
@@ -910,6 +911,7 @@ export async function getSceneInfo(e, index) {
         userId: appStore.userInfo.userId,
       };
       await footprintScan(obj);
+      await appStore.USERINFO();
     }
     console.log("获取邀请码-params", params);
     return params;
@@ -1282,3 +1284,40 @@ export const Calc = {
     return result;
   },
 };
+export async function getPhoneNumber(e, inviteCode) {
+  const { Toast } = useToast();
+  console.log('getPhoneNumber123', e);
+
+  // 用户拒绝授权
+  if (e.detail.errMsg !== 'getPhoneNumber:ok') {
+    Toast({ title: '请授权手机号以完成登录' });
+    return null;
+  }
+
+  // 授权成功
+  if (e.detail.code) {
+    try {
+      // 2. 将授权码发送到后端换取手机号
+      const res = await wxLogin({ code: e.detail.code });
+      console.log('wxLogin接口res=', res);
+
+      // 3. 处理后端响应
+      if (res.code === 200) {
+        return res; // 返回数据
+      } else {
+        Toast({ title: res.message || '获取失败' });
+        return null;
+      }
+    } catch (error) {
+      Toast({ title: "获取手机号失败:" + error });
+      console.error('获取手机号失败:', error);
+      return null;
+    } finally {
+
+    }
+  } else {
+    // 授权失败
+    Toast({ title: e.detail?.errorMessage || "请允许授权以获取手机号" });
+    return null;
+  }
+};