绿满眶商城微信小程序-uniapp
zxl
2025-09-26 d4314be4b57bd246d336b25c6ac78c66742e1eea
用户绑定商店
2个文件已修改
76 ■■■■■ 已修改文件
api/members.js 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/tabbar/user/my.vue 68 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
api/members.js
@@ -481,3 +481,11 @@
        data:params
    });
}
export function bindMemberAndStore(params){
    return http.request({
        url: '/lmk/member/bindMemberAndStore',
        method: Method.PUT,
        data:params
    });
}
pages/tabbar/user/my.vue
@@ -140,7 +140,7 @@
import '@/pages/subComponents/uview-components/uview-ui';
import tool from "@/pages/tabbar/user/utils/tool.vue";
import { getSTSToken } from "@/api/common.js";
import { getCouponsNum, getFootprintNum } from "@/api/members.js";
import { getCouponsNum, getFootprintNum,bindMemberAndStore } from "@/api/members.js";
import { getUserWallet } from "@/api/members";
import configs from '@/config/config'
import storage from '@/utils/storage.js'
@@ -162,7 +162,50 @@
      walletNum: "",
    };
  },
  onLoad() {
  onLoad(option) {
      console.log('-----------分享出的数据---------->', option)
      let shareStoreId = null;
      let shareTime = null;
      // 检查是否存在q参数
      if (option.q) {
          // 双重解码:微信对URL进行了两次编码
          const decodedUrl = decodeURIComponent(decodeURIComponent(option.q));
          console.log('原始URL:', decodedUrl);
          // 解析URL中的查询参数
          const params = this.parseUrlParams(decodedUrl);
          shareStoreId = params.shareStoreId;
        try {
        // 将数据存储到本地缓存
        uni.setStorageSync('shareStoreId', shareStoreId);
        //创建一个扫码的时间
        // 获取当前时间并格式化为 yyyy-MM-dd HH:mm:ss
        const now = new Date();
        const year = now.getFullYear();
        const month = String(now.getMonth() + 1).padStart(2, '0'); // 月份从0开始,需要+1
        const day = String(now.getDate()).padStart(2, '0');
        const hours = String(now.getHours()).padStart(2, '0');
        const minutes = String(now.getMinutes()).padStart(2, '0');
        const seconds = String(now.getSeconds()).padStart(2, '0');
        shareTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
        uni.setStorageSync('shareTime', shareTime);
        console.log('数据存储成功');
        } catch (e) {
        console.error('存储失败:', e);
        }
      }else{
        shareStoreId = uni.getStorageSync('shareStoreId');
        shareStoreId = uni.getStorageSync('shareTime');
        console.log('从缓存读取参数:', { shareStoreId, shareTime });
         // this.bindMemberAndStore(shareStoreId, shareTime)
        if (shareStoreId && shareTime) {
            console.log('检测到有效参数,调用后端接口');
            this.bindMemberAndStore(shareStoreId, shareTime);
          } else {
            console.log('无有效参数,执行正常逻辑');
          }
      }
      this.initCOS()
  },
  onShow() {
@@ -190,6 +233,27 @@
  mounted() { },
  methods: {
       async bindMemberAndStore(shareStoreId, shareTime){
          let form ={
              shareStoreId: shareStoreId,
              shareTime: shareTime
          }
          // let form ={
          //               shareStoreId: "1376433565247471616",
          //               shareTime: "2025-09-26 16:18:00"
          // }
          try {
              const res = await bindMemberAndStore(form);
              if(res.statusCode === 200){
                            //清除缓存
                uni.removeStorageSync('shareStoreId');
                uni.removeStorageSync('shareTime');
              }
          }
          catch(error) {
                console.error('出错:', error);
            };
        },
      // goTOSuccess(){
      //          uni.redirectTo({
      //             url:"/pages/cart/payment/success?paymentMethod=WECHAT" +