|
@@ -35,7 +35,6 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { getCookies } from '@/utils/auth'
|
|
|
import { mapGetters } from 'vuex'
|
|
|
import { isWeChat } from '~/utils/validator'
|
|
|
import { toAuthorization } from '~/utils'
|
|
@@ -43,11 +42,11 @@ export default {
|
|
|
computed: {
|
|
|
...mapGetters([
|
|
|
'userInfo',
|
|
|
- 'type',
|
|
|
'accessToken',
|
|
|
'authUserId',
|
|
|
'appId',
|
|
|
'accountType',
|
|
|
+ 'routePrefix',
|
|
|
]),
|
|
|
},
|
|
|
head() {
|
|
@@ -62,10 +61,10 @@ export default {
|
|
|
},
|
|
|
mounted() {
|
|
|
this.init()
|
|
|
+ console.log(1)
|
|
|
},
|
|
|
beforeDestroy() {
|
|
|
window.removeEventListener('resize', () => {})
|
|
|
- localStorage.removeItem('zp-locations')
|
|
|
},
|
|
|
methods: {
|
|
|
init() {
|
|
@@ -74,19 +73,18 @@ export default {
|
|
|
},
|
|
|
// 初始化数据页面公共数据
|
|
|
initPageData() {
|
|
|
- const id = parseInt(this.$route.params.template)
|
|
|
- // 保存页面入口
|
|
|
- this.$store.commit('user/SET_TYPE', `${id}/app`)
|
|
|
+ // 获取供应商id
|
|
|
+ const authUserId = parseInt(this.$route.params.template)
|
|
|
+ const routePrefix = `/${authUserId}/app`
|
|
|
+ // 保存页面路由前缀
|
|
|
+ this.$store.commit('app/SET_ROUTE_PREFIX', routePrefix)
|
|
|
// 保存用户AppId
|
|
|
- this.$store.commit('user/SET_AUTHUSERID', id)
|
|
|
+ this.$store.commit('user/SET_AUTH_USER_ID', authUserId)
|
|
|
|
|
|
// 获取用户信息
|
|
|
- let userInfo = getCookies('userInfo')
|
|
|
- if (userInfo) {
|
|
|
- userInfo = JSON.parse(userInfo)
|
|
|
- if (userInfo.authUserId === id) {
|
|
|
- this.$store.commit('user/SET_USERINFO', userInfo)
|
|
|
- }
|
|
|
+ let userInfo = this.$getStorage(routePrefix, 'userInfo')
|
|
|
+ if (userInfo && userInfo.authUserId === authUserId) {
|
|
|
+ this.$store.commit('user/SET_USER_INFO', userInfo)
|
|
|
}
|
|
|
// 初始化供应商信息
|
|
|
this.fetchSupplierInfo()
|
|
@@ -100,6 +98,7 @@ export default {
|
|
|
})
|
|
|
this.$store.commit('supplier/SET_SUPPLIER_INFO', res.data)
|
|
|
this.$store.commit('user/SET_APPID', res.data.appId)
|
|
|
+ // 如果appId存在
|
|
|
if (res.data.appId) {
|
|
|
this.checkAccountType(res.data.appId)
|
|
|
}
|
|
@@ -107,6 +106,8 @@ export default {
|
|
|
console.log(error)
|
|
|
} finally {
|
|
|
this.isMounted = true
|
|
|
+ // 清除缓存
|
|
|
+ this.refreshCacheData()
|
|
|
}
|
|
|
},
|
|
|
|
|
@@ -124,7 +125,10 @@ export default {
|
|
|
onLogin() {
|
|
|
// 在微信浏览器中使用微信授权登录
|
|
|
if (isWeChat() && this.appId && this.accountType === 2) {
|
|
|
- const payload = { authUserId: this.authUserId, type: this.type }
|
|
|
+ const payload = {
|
|
|
+ authUserId: this.authUserId,
|
|
|
+ routePrefix: this.routePrefix,
|
|
|
+ }
|
|
|
return toAuthorization(this.appId, payload)
|
|
|
}
|
|
|
this.$store.commit('app/SHOW_LOGIN')
|
|
@@ -133,13 +137,15 @@ export default {
|
|
|
// 退出登录
|
|
|
logout() {
|
|
|
this.$store.dispatch('user/logout')
|
|
|
+ console.log(this.routePrefix)
|
|
|
+ this.$removeStorage(this.routePrefix, 'userInfo')
|
|
|
+ this.backHome()
|
|
|
},
|
|
|
|
|
|
// 回到首页
|
|
|
backHome() {
|
|
|
- const url = '/' + this.type
|
|
|
- if (this.$route.path === url) return
|
|
|
- this.$router.replace(url)
|
|
|
+ if (this.$route.path === this.routePrefix) return
|
|
|
+ this.$router.replace(this.routePrefix)
|
|
|
},
|
|
|
|
|
|
// 响应页面宽度变化
|
|
@@ -149,6 +155,11 @@ export default {
|
|
|
this.$store.commit('app/SET_SCREEN', e.target.innerWidth)
|
|
|
})
|
|
|
},
|
|
|
+
|
|
|
+ // 数据初始化刷新浏览器
|
|
|
+ refreshCacheData() {
|
|
|
+ this.$removeStorage(this.routePrefix, 'club_list_data')
|
|
|
+ },
|
|
|
},
|
|
|
}
|
|
|
</script>
|