shish 2 miesięcy temu
rodzic
commit
c8c6dada15

+ 54 - 54
mallApp/src/mixins/globalMixins.js

@@ -1,55 +1,55 @@
-import { pageTo } from '@/utils/util.js'

-import { wxLoginFn } from '@/utils/auth'

-import { mapGetters } from 'vuex'

-import { TOKEN_STORAGE_KEY } from '@/constant/storageKeys'

-import { applyLaunchQuery, persistLaunchStorage } from '@/utils/launchScene'

-

-export default {

-	data() {

-		return {

-			option: null,

-			constant: this.$constant,

-			$util: this.$util,

-			pageTo: pageTo,

-			//0没有登录 1有登录

-			globalLoginStyle :0

-		}

-	},

-	computed: {

-		...mapGetters({ loginInfo: "getLoginInfo" })

-	},

-	// 页面生命周期才触发

-	onLoad: function (option) {

-		let that = this

-		option = applyLaunchQuery(option || {})

-		this.option = option

-

-		if (option.token) {

-			uni.setStorageSync(TOKEN_STORAGE_KEY, option.token)

-		}

-

-		persistLaunchStorage(option)

-

-		//线上检查小程序的登录态是否有效 checkSession

-		//checkSession开发环境无效,在真机调试有效

-		if (process.env.NODE_ENV == "production") {

-			uni.checkSession({

-				success() {

-					console.log('checkSession success')

-				},

-				fail() {

-					uni.removeStorageSync(TOKEN_STORAGE_KEY);

-				}

-			})

-		}

-		if (that.$util.isEmpty(that.getLoginInfo)) {

-			wxLoginFn().then(wxRes=>{

-				that.init()

-			})

-		}else{

-			that.init()

-		}

-	}

-

-}

+import { pageTo } from '@/utils/util.js'
+import { wxLoginFn } from '@/utils/auth'
+import { mapGetters } from 'vuex'
+import { TOKEN_STORAGE_KEY } from '@/constant/storageKeys'
+import { applyLaunchQuery, persistLaunchStorage } from '@/utils/launchScene'
+
+export default {
+	data() {
+		return {
+			option: null,
+			constant: this.$constant,
+			$util: this.$util,
+			pageTo: pageTo,
+			//0没有登录 1有登录
+			globalLoginStyle :0
+		}
+	},
+	computed: {
+		...mapGetters({ loginInfo: "getLoginInfo" })
+	},
+	// 页面生命周期才触发
+	onLoad: function (option) {
+		let that = this
+		option = applyLaunchQuery(option || {})
+		this.option = option
+
+		if (option.token) {
+			uni.setStorageSync(TOKEN_STORAGE_KEY, option.token)
+		}
+
+		persistLaunchStorage(option)
+
+		//线上检查小程序的登录态是否有效 checkSession
+		//checkSession开发环境无效,在真机调试有效
+		if (process.env.NODE_ENV == "production") {
+			uni.checkSession({
+				success() {
+					console.log('checkSession success')
+				},
+				fail() {
+					uni.removeStorageSync(TOKEN_STORAGE_KEY);
+				}
+			})
+		}
+		if (that.$util.isEmpty(that.loginInfo)) {
+			wxLoginFn().then(wxRes=>{
+				that.init()
+			})
+		}else{
+			that.init()
+		}
+	}
+
+}
 

+ 8 - 1
mallApp/src/pages/home/recent.vue

@@ -321,7 +321,14 @@ export default {
     getLoginInfo() {
       currentInfo().then((res) => {
         if (res.code == 1) {
-          this.user = res.data.info ? res.data.info : [];
+          if (res.data.info) {
+            this.user = res.data.info;
+          } else {
+            this.user = { name: "", smallAvatar: "", id: 0 };
+            this.loginStyle = 0;
+            this.$store.commit("setLoginInfo", {});
+            uni.removeStorageSync(TOKEN_STORAGE_KEY);
+          }
         }
       });
     },