88 lines
1.6 KiB
JavaScript
88 lines
1.6 KiB
JavaScript
import Vue from 'vue'
|
|
import Vuex from 'vuex'
|
|
|
|
Vue.use(Vuex)
|
|
|
|
const store = new Vuex.Store({
|
|
state: {
|
|
hasLogin: false,
|
|
userInfo: {},
|
|
clientId:'',
|
|
authUrl:[]
|
|
},
|
|
mutations: {
|
|
login(state, provider) {
|
|
|
|
state.hasLogin = true;
|
|
state.userInfo = provider;
|
|
uni.setStorage({ //缓存用户登陆状态
|
|
key: 'haslog',
|
|
data: true
|
|
})
|
|
uni.setStorage({ //缓存用户登陆状态
|
|
key: 'userInfo',
|
|
data: provider
|
|
})
|
|
// console.log(state.userInfo);
|
|
},
|
|
login2(state, provider) {
|
|
|
|
state.hasLogin = true;
|
|
state.userInfo = provider;
|
|
uni.setStorage({ //缓存用户登陆状态
|
|
key: 'haslog',
|
|
data: true
|
|
})
|
|
uni.setStorage({ //缓存用户登陆状态
|
|
key: 'userInfo',
|
|
data: provider
|
|
})
|
|
uni.switchTab({
|
|
url: '/pages/index/index'
|
|
})
|
|
// console.log(state.userInfo);
|
|
},
|
|
updateAuthUrl(state, provider){
|
|
let arr = provider;
|
|
let authUrl = [];
|
|
for(var i=0;i<arr.length;i++){
|
|
var url = arr[i].pageUrl||"";
|
|
var urls = url.split("?");
|
|
authUrl.push(urls[0]);
|
|
var childArr = arr[i].children;
|
|
for(var j=0;j<childArr.length;j++){
|
|
url = childArr[j].pageUrl;
|
|
if(url==null){continue;}
|
|
urls = url.split("?");
|
|
authUrl.push(urls[0]);
|
|
}
|
|
}
|
|
state.authUrl=authUrl;
|
|
},
|
|
logout(state) {
|
|
state.hasLogin = false;
|
|
state.userInfo = {};
|
|
uni.removeStorage({
|
|
key: 'userInfo'
|
|
})
|
|
uni.removeStorage({
|
|
key: 'haslog'
|
|
})
|
|
uni.removeStorage({
|
|
key: 'todaychin'
|
|
})
|
|
uni.removeStorage({
|
|
key: 'levelName'
|
|
})
|
|
uni.reLaunch({
|
|
url: '/pages/login/login'
|
|
})
|
|
}
|
|
},
|
|
actions: {
|
|
|
|
}
|
|
})
|
|
|
|
export default store
|