|
@@ -1,112 +1,141 @@
|
|
|
-import Vue from 'vue'
|
|
|
|
|
-import Vuex from 'vuex'
|
|
|
|
|
-import api from "@/api/api"
|
|
|
|
|
-import MinCache from '@/common/util/MinCache.js'
|
|
|
|
|
-import { ACCESS_TOKEN, USER_NAME, USER_INFO } from "@/common/util/constants"
|
|
|
|
|
|
|
+import Vue from "vue";
|
|
|
|
|
+import Vuex from "vuex";
|
|
|
|
|
+import api from "@/api/api";
|
|
|
|
|
+import MinCache from "@/common/util/MinCache.js";
|
|
|
|
|
+import { ACCESS_TOKEN, USER_NAME, USER_INFO } from "@/common/util/constants";
|
|
|
|
|
|
|
|
-Vue.use(Vuex)
|
|
|
|
|
|
|
+Vue.use(Vuex);
|
|
|
|
|
|
|
|
export default new Vuex.Store({
|
|
export default new Vuex.Store({
|
|
|
state: {
|
|
state: {
|
|
|
- token: '',
|
|
|
|
|
- userid: '',
|
|
|
|
|
- username: '',
|
|
|
|
|
- realname: '',
|
|
|
|
|
- welcome: '',
|
|
|
|
|
- avatar: '',
|
|
|
|
|
- dicts: '',
|
|
|
|
|
|
|
+ token: "",
|
|
|
|
|
+ userid: "",
|
|
|
|
|
+ username: "",
|
|
|
|
|
+ realname: "",
|
|
|
|
|
+ welcome: "",
|
|
|
|
|
+ avatar: "",
|
|
|
|
|
+ dicts: "",
|
|
|
showColum: {},
|
|
showColum: {},
|
|
|
- nfcreadtxt:'',
|
|
|
|
|
|
|
+ nfcreadtxt: "",
|
|
|
},
|
|
},
|
|
|
mutations: {
|
|
mutations: {
|
|
|
- setNfcReadTxt(state,nfcreadtxt){
|
|
|
|
|
- state.nfcreadtxt = nfcreadtxt
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ setNfcReadTxt(state, nfcreadtxt) {
|
|
|
|
|
+ state.nfcreadtxt = nfcreadtxt;
|
|
|
|
|
+ },
|
|
|
SET_TOKEN: (state, token) => {
|
|
SET_TOKEN: (state, token) => {
|
|
|
- state.token = token
|
|
|
|
|
|
|
+ state.token = token;
|
|
|
},
|
|
},
|
|
|
SET_NAME: (state, { username, realname, welcome }) => {
|
|
SET_NAME: (state, { username, realname, welcome }) => {
|
|
|
- state.username = username
|
|
|
|
|
- state.realname = realname
|
|
|
|
|
- state.welcome = welcome
|
|
|
|
|
|
|
+ state.username = username;
|
|
|
|
|
+ state.realname = realname;
|
|
|
|
|
+ state.welcome = welcome;
|
|
|
},
|
|
},
|
|
|
SET_AVATAR: (state, avatar) => {
|
|
SET_AVATAR: (state, avatar) => {
|
|
|
- state.avatar = avatar
|
|
|
|
|
|
|
+ state.avatar = avatar;
|
|
|
},
|
|
},
|
|
|
SET_SHOWCOLUM: (state, showColum) => {
|
|
SET_SHOWCOLUM: (state, showColum) => {
|
|
|
- state.showColum = showColum
|
|
|
|
|
|
|
+ state.showColum = showColum;
|
|
|
},
|
|
},
|
|
|
SET_DICT: (state, dicts) => {
|
|
SET_DICT: (state, dicts) => {
|
|
|
- state.dicts = dicts
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ state.dicts = dicts;
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
actions: {
|
|
actions: {
|
|
|
// 登录
|
|
// 登录
|
|
|
mLogin({ commit }, userInfo) {
|
|
mLogin({ commit }, userInfo) {
|
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
|
- api.login(userInfo).then(response => {
|
|
|
|
|
- if (response.data.code == 200) {
|
|
|
|
|
- const result = response.data.result
|
|
|
|
|
- const userInfo = result.userInfo
|
|
|
|
|
- uni.setStorageSync(ACCESS_TOKEN, result.token);
|
|
|
|
|
- uni.setStorageSync(USER_INFO, userInfo);
|
|
|
|
|
- commit('SET_TOKEN', result.token)
|
|
|
|
|
- commit('SET_DICT', result.sysAllDictItems)
|
|
|
|
|
- commit('SET_AVATAR', userInfo.avatar)
|
|
|
|
|
- commit('SET_NAME', { username: userInfo.username, realname: userInfo.realname })
|
|
|
|
|
- resolve(response)
|
|
|
|
|
- } else {
|
|
|
|
|
- resolve(response)
|
|
|
|
|
- }
|
|
|
|
|
- }).catch(error => {
|
|
|
|
|
- console.log("catch===>response", response)
|
|
|
|
|
- reject(error)
|
|
|
|
|
- })
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ api
|
|
|
|
|
+ .login(userInfo)
|
|
|
|
|
+ .then((response) => {
|
|
|
|
|
+ if (response.data?.code == 200) {
|
|
|
|
|
+ const result = response.data.result;
|
|
|
|
|
+ const userInfo = result.userInfo;
|
|
|
|
|
+ uni.setStorageSync(ACCESS_TOKEN, result.token);
|
|
|
|
|
+ uni.setStorageSync(USER_INFO, userInfo);
|
|
|
|
|
+ commit("SET_TOKEN", result.token);
|
|
|
|
|
+ commit("SET_DICT", result.sysAllDictItems);
|
|
|
|
|
+ commit("SET_AVATAR", userInfo.avatar);
|
|
|
|
|
+ commit("SET_NAME", {
|
|
|
|
|
+ username: userInfo.username,
|
|
|
|
|
+ realname: userInfo.realname,
|
|
|
|
|
+ });
|
|
|
|
|
+ resolve(response);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ resolve(response);
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch((error) => {
|
|
|
|
|
+ console.log("catch===>response", response);
|
|
|
|
|
+ reject(error);
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
},
|
|
},
|
|
|
//手机号登录
|
|
//手机号登录
|
|
|
PhoneLogin({ commit }, userInfo) {
|
|
PhoneLogin({ commit }, userInfo) {
|
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
|
- api.phoneNoLogin(userInfo).then(response => {
|
|
|
|
|
- if (response.data.code == 200) {
|
|
|
|
|
- const result = response.data.result
|
|
|
|
|
- const userInfo = result.userInfo
|
|
|
|
|
- uni.setStorageSync(ACCESS_TOKEN, result.token);
|
|
|
|
|
- uni.setStorageSync(USER_INFO, userInfo);
|
|
|
|
|
- commit('SET_TOKEN', result.token)
|
|
|
|
|
- commit('SET_NAME', { username: userInfo.username, realname: userInfo.realname })
|
|
|
|
|
- commit('SET_AVATAR', userInfo.avatar)
|
|
|
|
|
- resolve(response)
|
|
|
|
|
- } else {
|
|
|
|
|
- reject(response)
|
|
|
|
|
- }
|
|
|
|
|
- }).catch(error => {
|
|
|
|
|
- reject(error)
|
|
|
|
|
- })
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ api
|
|
|
|
|
+ .phoneNoLogin(userInfo)
|
|
|
|
|
+ .then((response) => {
|
|
|
|
|
+ if (response.data.code == 200) {
|
|
|
|
|
+ const result = response.data.result;
|
|
|
|
|
+ const userInfo = result.userInfo;
|
|
|
|
|
+ uni.setStorageSync(ACCESS_TOKEN, result.token);
|
|
|
|
|
+ uni.setStorageSync(USER_INFO, userInfo);
|
|
|
|
|
+ commit("SET_TOKEN", result.token);
|
|
|
|
|
+ commit("SET_NAME", {
|
|
|
|
|
+ username: userInfo.username,
|
|
|
|
|
+ realname: userInfo.realname,
|
|
|
|
|
+ });
|
|
|
|
|
+ commit("SET_AVATAR", userInfo.avatar);
|
|
|
|
|
+ resolve(response);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ reject(response);
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch((error) => {
|
|
|
|
|
+ reject(error);
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
},
|
|
},
|
|
|
// 登出
|
|
// 登出
|
|
|
Logout({ commit, state }) {
|
|
Logout({ commit, state }) {
|
|
|
return new Promise((resolve) => {
|
|
return new Promise((resolve) => {
|
|
|
let logoutToken = state.token;
|
|
let logoutToken = state.token;
|
|
|
- commit('SET_TOKEN', '')
|
|
|
|
|
- uni.removeStorageSync(ACCESS_TOKEN)
|
|
|
|
|
- api.logout(logoutToken).then(() => {
|
|
|
|
|
- resolve()
|
|
|
|
|
- }).catch(() => {
|
|
|
|
|
- resolve()
|
|
|
|
|
- })
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ commit("SET_TOKEN", "");
|
|
|
|
|
+ uni.removeStorageSync(ACCESS_TOKEN);
|
|
|
|
|
+ api
|
|
|
|
|
+ .logout(logoutToken)
|
|
|
|
|
+ .then(() => {
|
|
|
|
|
+ resolve();
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch(() => {
|
|
|
|
|
+ resolve();
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
},
|
|
},
|
|
|
-
|
|
|
|
|
},
|
|
},
|
|
|
getters: {
|
|
getters: {
|
|
|
- token: state => state.token,
|
|
|
|
|
- username: state => { state.userid = uni.getStorageSync(USER_INFO).username; return state.username },
|
|
|
|
|
- nickname: state => { state.userid = uni.getStorageSync(USER_INFO).realname; return state.user.realname },
|
|
|
|
|
- avatar: state => { state.userid = uni.getStorageSync(USER_INFO).avatar; return state.user.avatar },
|
|
|
|
|
- userid: state => { state.userid = uni.getStorageSync(USER_INFO).id; return state.userid },
|
|
|
|
|
- showColum: state => { state.userid = uni.getStorageSync(USER_INFO).showColum; return state.showColum },
|
|
|
|
|
- nfcreadtxt: state => state.nfcreadtxt
|
|
|
|
|
- }
|
|
|
|
|
-})
|
|
|
|
|
|
|
+ token: (state) => state.token,
|
|
|
|
|
+ username: (state) => {
|
|
|
|
|
+ state.userid = uni.getStorageSync(USER_INFO).username;
|
|
|
|
|
+ return state.username;
|
|
|
|
|
+ },
|
|
|
|
|
+ nickname: (state) => {
|
|
|
|
|
+ state.userid = uni.getStorageSync(USER_INFO).realname;
|
|
|
|
|
+ return state.user.realname;
|
|
|
|
|
+ },
|
|
|
|
|
+ avatar: (state) => {
|
|
|
|
|
+ state.userid = uni.getStorageSync(USER_INFO).avatar;
|
|
|
|
|
+ return state.user.avatar;
|
|
|
|
|
+ },
|
|
|
|
|
+ userid: (state) => {
|
|
|
|
|
+ state.userid = uni.getStorageSync(USER_INFO).id;
|
|
|
|
|
+ return state.userid;
|
|
|
|
|
+ },
|
|
|
|
|
+ showColum: (state) => {
|
|
|
|
|
+ state.userid = uni.getStorageSync(USER_INFO).showColum;
|
|
|
|
|
+ return state.showColum;
|
|
|
|
|
+ },
|
|
|
|
|
+ nfcreadtxt: (state) => state.nfcreadtxt,
|
|
|
|
|
+ },
|
|
|
|
|
+});
|