shish 2 месяцев назад
Родитель
Сommit
1b09944e7d
1 измененных файлов с 33 добавлено и 23 удалено
  1. 33 23
      hdApp/src/admin/home/me.vue

+ 33 - 23
hdApp/src/admin/home/me.vue

@@ -196,6 +196,21 @@ import { clearLogin } from "@/api/admin";
 import { APP_VERSION } from "@/config";
 import { iconSrc } from "@/utils/iconSrc";
 
+function isValidLoginSession (loginInfo) {
+  const token = uni.getStorageSync("token");
+  if (!token) {
+    return false;
+  }
+  const info = loginInfo || {};
+  const shopId = Number(
+    uni.getStorageSync("shopId") ||
+    (info.admin && info.admin.currentShopId) ||
+    info.currentShopId ||
+    0
+  );
+  return shopId > 0;
+}
+
 export default {
   name: "me",
   components: {
@@ -204,20 +219,7 @@ export default {
   computed: {
     ...mapGetters(["getLoginInfo"]),
     isLoggedIn () {
-      if (uni.getStorageSync("manualLogout") === "1") {
-        return false;
-      }
-      const token = uni.getStorageSync("token");
-      if (this.$util.isEmpty(token)) {
-        return false;
-      }
-      const loginInfo = this.getLoginInfo || {};
-      const currentShopId = Number(
-        (loginInfo.admin && loginInfo.admin.currentShopId) ||
-        loginInfo.currentShopId ||
-        0
-      );
-      return currentShopId > 0;
+      return isValidLoginSession(this.getLoginInfo);
     },
     shopTitle () {
       const sjName = this.myInfo.sjName || "";
@@ -280,17 +282,25 @@ export default {
     }
   },
   onShow () {
-    if (uni.getStorageSync("manualLogout") === "1") {
-      this.$store.commit("setLoginInfo", {});
-      this.$store.commit("setMyShopInfo", {});
-      this.resetGuestState();
+    if (isValidLoginSession(this.getLoginInfo)) {
+      uni.removeStorageSync("manualLogout");
+      this.getMyInfo();
       return;
     }
-    if (!this.isLoggedIn) {
-      this.resetGuestState();
-      return;
+    this.resetGuestState();
+  },
+  watch: {
+    getLoginInfo: {
+      handler (val) {
+        if (isValidLoginSession(val)) {
+          uni.removeStorageSync("manualLogout");
+          this.getMyInfo();
+        } else if (uni.getStorageSync("manualLogout") === "1") {
+          this.resetGuestState();
+        }
+      },
+      deep: true
     }
-    this.getMyInfo();
   },
   onLoad () {
     this.setStatusBarHeight();
@@ -441,7 +451,7 @@ export default {
       });
     },
     getMyInfo () {
-      if (!this.isLoggedIn) {
+      if (!isValidLoginSession(this.getLoginInfo)) {
         this.resetGuestState();
         uni.stopPullDownRefresh();
         return Promise.resolve();