소스 검색

fix: userBindMember 中 memberId 时有时无的问题

- 改用 uni.getStorageSync('userInfo') 直接获取 memberId,避免依赖 this.userInfo 响应式数据
- 增加 memberId 空值校验,为空时提示用户重新登录
- 修复 closeStrategyListPoup 中 expandParam 和 that 未定义的 bug

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
xuyunhui 2 일 전
부모
커밋
0e004fd59d
1개의 변경된 파일19개의 추가작업 그리고 1개의 파일을 삭제
  1. 19 1
      pages/index/index.vue

+ 19 - 1
pages/index/index.vue

@@ -638,6 +638,8 @@ export default {
     closeStrategyListPoup() {
       this.$refs.strategyListPoup.close()
       //关闭弹窗
+      let expandParam = uni.getStorageSync('expandParam')
+      let that = this
       console.log('拓客端推广用户绑定失败!')
       console.log('+++++++++++++++expandParam+++++++++++++++++++++++', expandParam)
       that.$api.addRecordForAttach({
@@ -655,6 +657,22 @@ export default {
     userBindMember() {
       let expandParam = uni.getStorageSync('expandParam')
       let that = this
+
+      // 直接从 Storage 获取最新的 userInfo,避免 this.userInfo 未正确赋值
+      const userInfo = uni.getStorageSync('userInfo') || {}
+      const memberId = userInfo.id
+      console.log('========userBindMember memberId=======', memberId)
+      console.log('========userBindMember userInfo=======', userInfo)
+
+      if (!memberId) {
+        uni.showToast({
+          title: '用户信息获取失败,请重新登录',
+          duration: 2000,
+          icon: "error"
+        });
+        return
+      }
+
       this.$refs.form1.validate().then(res => {
         let couponIds = []
         for (const strategy of this.rule.strategyList) {
@@ -676,7 +694,7 @@ export default {
         that.$api.userBindMember(
             {
               ...expandParam,
-              memberId: this.userInfo.id,
+              memberId: memberId,
               memberPhone: this.phoneParam.phonenumber,
               smsCode: this.phoneParam.smsCode,
               couponIds: couponIds