You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
// 用户数据模块
import {router} from '@/nxTemp/router/index.js' const TOKEN = uni.getStorageSync("token") || ""; const OPENID = uni.getStorageSync("openId") || ""; const USER_INFO = uni.getStorageSync("userInfo") || {};
export const state = { // 前端token
token: TOKEN, // 用户openid
openId: OPENID, // 用户信息 头像 昵称
userInfo: USER_INFO }
export const actions = { async setUserData({ state, commit }, data) { commit('setStateAttr', { key: 'userInfo', val: data }) uni.setStorageSync('userInfo', data); }, // 登录过期 重新登录
reLogin({ commit }, info) { commit('setStateAttr', { key: 'token', val: '' }) uni.setStorageSync("token", ''); //过期跳转登录页重新登录
router.push({ path: '/pages/login/login' }); } }
export const mutations = { //更新state数据
setStateAttr(state, param) { if (param instanceof Array) { for (let item of param) { state[item.key] = item.val; } } else { state[param.key] = param.val; } }
}
export const getters = { // 用户是否登录
hasLogin: state => { if (state.token) { return true; } else { return false } } }
|