我们发布啦
This commit is contained in:
15
app/store/getters.js
Normal file
15
app/store/getters.js
Normal file
@@ -0,0 +1,15 @@
|
||||
export default {
|
||||
token: state => state.app.token,
|
||||
isLogin: state => !!state.app.token,
|
||||
backgroundColor: state => state.app.backgroundColor,
|
||||
userInfo: state => state.app.userInfo || {},
|
||||
uid:state => state.app.uid,
|
||||
homeActive: state => state.app.homeActive,
|
||||
home: state => state.app.home,
|
||||
};
|
||||
// export default {
|
||||
// token: state => 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJrYWlmYS5jcm1lYi5uZXQiLCJhdWQiOiJrYWlmYS5jcm1lYi5uZXQiLCJpYXQiOjE1NzcwODM1MzQsIm5iZiI6MTU3NzA4MzUzNCwiZXhwIjoxNTc3MDk0MzM0LCJqdGkiOnsiaWQiOjExMCwidHlwZSI6InVzZXIifX0.U-i1pbdRjyXI1gr79Uq2XBPZ89T8f5Ai9jwrR8woTwE',
|
||||
// isLogin: state => true,
|
||||
// backgroundColor: state => state.app.backgroundColor,
|
||||
// userInfo: state => state.app.userInfo || {}
|
||||
// };
|
||||
13
app/store/index.js
Normal file
13
app/store/index.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import Vue from "vue";
|
||||
import Vuex from "vuex";
|
||||
import modules from "./modules";
|
||||
import getters from "./getters";
|
||||
|
||||
Vue.use(Vuex);
|
||||
const debug = process.env.NODE_ENV !== "production";
|
||||
|
||||
export default new Vuex.Store({
|
||||
modules,
|
||||
getters,
|
||||
strict: debug
|
||||
});
|
||||
78
app/store/modules/app.js
Normal file
78
app/store/modules/app.js
Normal file
@@ -0,0 +1,78 @@
|
||||
import {
|
||||
getUserInfo
|
||||
} from "../../api/user.js";
|
||||
import {
|
||||
LOGIN_STATUS,
|
||||
UID
|
||||
} from '../../config/cache';
|
||||
import Cache from '../../utils/cache';
|
||||
import {
|
||||
USER_INFO
|
||||
} from '../../config/cache';
|
||||
|
||||
const state = {
|
||||
token: Cache.get(LOGIN_STATUS) || null,
|
||||
backgroundColor: "#fff",
|
||||
userInfo: null,
|
||||
uid: Cache.get(UID) || null,
|
||||
homeActive: false,
|
||||
};
|
||||
|
||||
const mutations = {
|
||||
LOGIN(state, opt) {
|
||||
state.token = opt.token;
|
||||
Cache.set(LOGIN_STATUS, opt.token, opt.time);
|
||||
},
|
||||
SETUID(state,val){
|
||||
state.uid = val;
|
||||
Cache.set(UID, val);
|
||||
},
|
||||
UPDATE_LOGIN(state, token) {
|
||||
state.token = token;
|
||||
},
|
||||
LOGOUT(state) {
|
||||
state.token = undefined;
|
||||
state.uid = undefined
|
||||
Cache.clear(LOGIN_STATUS);
|
||||
Cache.clear(UID);
|
||||
},
|
||||
BACKGROUND_COLOR(state, color) {
|
||||
state.color = color;
|
||||
document.body.style.backgroundColor = color;
|
||||
},
|
||||
UPDATE_USERINFO(state, userInfo) {
|
||||
state.userInfo = userInfo;
|
||||
},
|
||||
OPEN_HOME(state) {
|
||||
state.homeActive = true;
|
||||
},
|
||||
CLOSE_HOME(state) {
|
||||
state.homeActive = false;
|
||||
},
|
||||
};
|
||||
|
||||
const actions = {
|
||||
USERINFO({
|
||||
state,
|
||||
commit
|
||||
}, force) {
|
||||
if (state.userInfo !== null && !force)
|
||||
return Promise.resolve(state.userInfo);
|
||||
else
|
||||
return new Promise(reslove => {
|
||||
getUserInfo().then(res => {
|
||||
commit("UPDATE_USERINFO", res.data);
|
||||
Cache.set(USER_INFO, res.data);
|
||||
reslove(res.data);
|
||||
});
|
||||
}).catch(() => {
|
||||
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export default {
|
||||
state,
|
||||
mutations,
|
||||
actions
|
||||
};
|
||||
5
app/store/modules/index.js
Normal file
5
app/store/modules/index.js
Normal file
@@ -0,0 +1,5 @@
|
||||
import app from "./app";
|
||||
|
||||
export default {
|
||||
app
|
||||
};
|
||||
Reference in New Issue
Block a user