فهرست منبع

fix(登录): 持久化 crossProgramMerge(store 补 state/storage/登出清理,合并提示不丢失)

liaoxg 1 ماه پیش
والد
کامیت
f5f20c570a
2فایلهای تغییر یافته به همراه10 افزوده شده و 2 حذف شده
  1. 9 2
      train-frontend/store/index.js
  2. 1 0
      train-frontend/utils/api.js

+ 9 - 2
train-frontend/store/index.js

@@ -13,7 +13,8 @@ const store = new Vuex.Store({
     name: '',
     nickname: '',
     phone: '',
-    newUser: false
+    newUser: false,
+    crossProgramMerge: false
   },
   getters: {
     // 单一可信源:优先 store,store 空时兜底读 storage(热启动/HBuilderX 热更新场景 store 可能未恢复)
@@ -42,6 +43,9 @@ const store = new Vuex.Store({
       state.nickname = userInfo.nickname || ''
       state.phone = userInfo.phone || ''
       state.newUser = userInfo.newUser || false
+      // 跨小程序合并标识:mine 页从 storage 读取,登录后需持久化,避免合并提示丢失
+      state.crossProgramMerge = !!userInfo.crossProgramMerge
+      uni.setStorageSync('crossProgramMerge', state.crossProgramMerge)
       uni.setStorageSync('userId', userInfo.userId)
       uni.setStorageSync('role', state.role)
       uni.setStorageSync('alumniVerify', state.alumniVerify)
@@ -53,7 +57,8 @@ const store = new Vuex.Store({
         classId: state.classId,
         name: state.name,
         nickname: state.nickname,
-        phone: state.phone
+        phone: state.phone,
+        crossProgramMerge: state.crossProgramMerge
       })
     },
     setClassId(state, classId) {
@@ -77,12 +82,14 @@ const store = new Vuex.Store({
       state.nickname = ''
       state.phone = ''
       state.newUser = false
+      state.crossProgramMerge = false
       uni.removeStorageSync('token')
       uni.removeStorageSync('userId')
       uni.removeStorageSync('role')
       uni.removeStorageSync('alumniVerify')
       uni.removeStorageSync('classId')
       uni.removeStorageSync('userInfo')
+      uni.removeStorageSync('crossProgramMerge')
     }
   },
   actions: {

+ 1 - 0
train-frontend/utils/api.js

@@ -13,6 +13,7 @@ function _clearAuthAndRedirect() {
   uni.removeStorageSync('alumniVerify')
   uni.removeStorageSync('classId')
   uni.removeStorageSync('userInfo')
+  uni.removeStorageSync('crossProgramMerge')
   try {
     var app = typeof getApp === 'function' ? getApp() : null
     if (app && app.$store) {