Kaynağa Gözat

花卉宝 分销绑定失效bug处理

ouyang 2 gün önce
ebeveyn
işleme
82d108b95b

+ 8 - 4
mallApp/src/components/wangCg.vue

@@ -50,6 +50,7 @@ import { getMiniMobile } from "@/api/mini"
 import { create } from "@/api/user"
 import store from '@/store'
 import { TOKEN_STORAGE_KEY } from "@/constant/storageKeys";
+import { refreshShopInfoAfterLogin } from "@/api/shop"
 
 export default {
   props: {
@@ -95,10 +96,13 @@ export default {
           uni.setStorageSync(TOKEN_STORAGE_KEY, res.data.token)
           if (res.data.user && !that.$util.isEmpty(res.data.user)) {
             store.commit('setLoginInfo', res.data.user)
-            that.$msg('登录成功')
-            // 登录成功后关闭弹层并通知父组件
-            this.$emit('update:loginStyle', 1)
-            this.$emit('loginSuccess', res.data.user)
+            // 弹层登录也绑定分享邀请:读 shareInviter_{account} 后调 shop/info
+            const account = uni.getStorageSync('account') || ''
+            refreshShopInfoAfterLogin(account).finally(() => {
+              that.$msg('登录成功')
+              that.$emit('update:loginStyle', 1)
+              that.$emit('loginSuccess', res.data.user)
+            })
           }
         }
       })

+ 2 - 1
mallApp/src/pages/home/category.vue

@@ -196,7 +196,8 @@ export default {
       this.$util.pageTo({url:"/pages/item/item?account="+account+'&hdId='+this.hdId,type:2})
     },
     loginTo() {
-      let account = this.option.account?this.option.account:0
+      // 优先 option,否则用本地缓存,保证邀请缓存 key 与门店一致
+      const account = (this.option && this.option.account) || uni.getStorageSync('account') || ''
       this.$util.pageTo({url:"/pages/login/index?needBack=1&account="+account})
     },
     loginSuccess(){

+ 5 - 1
mallApp/src/pages/home/order.vue

@@ -146,7 +146,11 @@ export default {
      * 未登录点击任意区域:跳转登录页(needBack 便于登录后返回订单 Tab)
      */
     goLoginFromGuest() {
-      this.pageTo({ url: "/pages/login/index?needBack=1" });
+      // 带上本地 account,避免登录页 onLoad 时门店上下文丢失
+      const account = uni.getStorageSync("account") || "";
+      this.pageTo({
+        url: "/pages/login/index?needBack=1" + (account ? "&account=" + account : "")
+      });
     },
     /** 合并 switchTab / 路由 query */
     applyPageQuery(query) {

+ 6 - 1
mallApp/src/pages/login/account.vue

@@ -25,6 +25,7 @@ const form = require("@/utils/formValidation.js")
 import { accountLogin } from "@/api/user"
 import store from '@/store'
 import { TOKEN_STORAGE_KEY } from "@/constant/storageKeys";
+import { refreshShopInfoAfterLogin } from "@/api/shop"
 export default {
   name: "account",
   components: {
@@ -54,7 +55,11 @@ export default {
           uni.setStorageSync(TOKEN_STORAGE_KEY, res.data.token)
           if(res.data.user && !that.$util.isEmpty(res.data.user)){
             store.commit('setLoginInfo', res.data.user)
-            uni.navigateBack()
+            // 账号登录同样走 shop/info,绑定分享邀请人
+            const account = uni.getStorageSync('account') || ''
+            refreshShopInfoAfterLogin(account).finally(() => {
+              uni.navigateBack()
+            })
           }
         } else {
           this.$msg(res.msg)

+ 28 - 12
mallApp/src/pages/login/index.vue

@@ -41,6 +41,7 @@ import { getWxInfo, getMiniMobile } from "@/api/mini"
 import { create } from "@/api/user"
 import store from '@/store'
 import { TOKEN_STORAGE_KEY } from "@/constant/storageKeys";
+import { refreshShopInfoAfterLogin } from "@/api/shop"
 
 export default {
   name: "index",
@@ -63,10 +64,21 @@ export default {
       if (this.option && this.option.needBack) {
         this.needBack = this.option.needBack
       }
+      // 登录页带 account 时写回,保证邀请缓存 key 与门店一致
+      if (this.option && this.option.account) {
+        uni.setStorageSync('account', this.option.account)
+      }
     },
     accountLogin() {
       this.$util.pageTo({ url: "/pages/login/account", type: 2 })
     },
+    /**
+     * 登录成功后重拉 shop/info:新建客户并绑定分享 inviterCustomId(读本地 shareInviter_{account})
+     */
+    afterLoginSuccess() {
+      const account = (this.option && this.option.account) || uni.getStorageSync('account') || ''
+      return refreshShopInfoAfterLogin(account)
+    },
     confirmFn() {
       let currentMiniOpenId = uni.getStorageSync('miniOpenId')
       let that = this
@@ -75,18 +87,22 @@ export default {
           uni.setStorageSync(TOKEN_STORAGE_KEY, res.data.token)
           if (res.data.user && !that.$util.isEmpty(res.data.user)) {
             store.commit('setLoginInfo', res.data.user)
-            if (this.needBack == 1) {
-              that.$msg('登录成功')
-              setTimeout(function () {
-                let pages = getCurrentPages();
-                let prevPage = pages[pages.length - 2];
-                prevPage.$vm.loginComeBack = 1
-                prevPage.$vm.pageAction = { refresh: 1 }
-                uni.navigateBack({})
-              }, 1100)
-            } else {
-              that.$util.pageTo({ url: "/pages/login/result", type: 2 })
-            }
+            that.afterLoginSuccess().finally(() => {
+              if (that.needBack == 1) {
+                that.$msg('登录成功')
+                setTimeout(function () {
+                  let pages = getCurrentPages();
+                  let prevPage = pages[pages.length - 2];
+                  if (prevPage && prevPage.$vm) {
+                    prevPage.$vm.loginComeBack = 1
+                    prevPage.$vm.pageAction = { refresh: 1 }
+                  }
+                  uni.navigateBack({})
+                }, 1100)
+              } else {
+                that.$util.pageTo({ url: "/pages/login/result", type: 2 })
+              }
+            })
           }
         }
       })

+ 9 - 9
mallApp/src/utils/launchScene.js

@@ -122,20 +122,20 @@ export function redirectToShopHome(option) {
 
 /**
  * 写入 account / hdId / currentQuery(与原 globalMixins 一致)
- * hdId:仅当本次入参带有效值时写入;缺省不覆盖本地已有绑定,
- * 避免分享进页(故意不带 hdId)或跳转漏参时把接口回填的 hdId 冲成 0
+ * account、hdId:仅当本次入参带有效值时写入;缺省不覆盖本地已有值,
+ * 避免 Tab 页(订单/分类/购物车)onLoad 无参时把分享进店的 account 冲成 0,
+ * 导致 shareInviter_{account} 读不到、登录后无法绑定拉新关系。
  */
 export function persistLaunchStorage(option) {
-	if (option.account) {
-		uni.setStorageSync('account', option.account)
-	} else {
-		uni.setStorageSync('account', 0)
+	const opt = option || {}
+	if (opt.account) {
+		uni.setStorageSync('account', opt.account)
 	}
 	// 无有效 hdId 时保留 storage,防止全局 onLoad 误清空门店绑定
-	if (option.hdId) {
-		uni.setStorageSync('hdId', option.hdId)
+	if (opt.hdId) {
+		uni.setStorageSync('hdId', opt.hdId)
 	}
-	uni.setStorageSync('currentQuery', JSON.stringify(option))
+	uni.setStorageSync('currentQuery', JSON.stringify(opt))
 }
 
 /** 分享邀请人 customId 的 storage key(按门店隔离) */