1234567891011121314151617181920212223242526272829303132333435363738394041 |
- import {
- mapState
- } from 'vuex'
- export default {
- computed: {
- ...mapState({
- userInfo: state => state.user.userInfo,
- })
- },
- async onReady() {
- const whiteList = ['pages/error/403/403'] // 路由白名单
- const pages = getCurrentPages() // 获取栈实例
- const page = pages[0] || {}
- // set code
- const code = page?.options?.code || ''
- if (code) {
- console.log('code: ', code)
- this.$store.commit('user/setCode', code)
- // code 重新登录
- await this.$store.dispatch('user/login', {
- test: 111
- })
- }
- // 白名单 无需登录
- if (whiteList.indexOf(page.route) >= 0) {
- return
- }
- setTimeout(function() {
- const token = uni.getStorageSync('TOKEN')
- // 获取用户信息
- token && !this.userInfo.studentName && this.$store.dispatch('user/updateUserInfo')
- // 获取token
- !token && this.$store.dispatch('user/login', {
- test: 222
- })
- }, 500);
- }
- }
|