user.js
3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import { userLogin, logout } from "@/api/login";
import { getInfo } from "@/api/system/user.js"
import { getToken, setToken, removeToken } from "@/utils/auth";
import { MessageBox } from "element-ui";
import { getcountryData } from "@/api/system/dictionary.js";
const user = {
state: {
token: getToken(),
userData: {},
name: "",
avatar: "",
activePortName: "",
appLoading: false,
tableHeader: [],
dictData: {
country: []
},
},
mutations: {
SET_TOKEN: (state, token) => {
state.token = token;
},
SET_USERDATA: (state, data) => {
state.userData = data;
},
SET_NAME: (state, name) => {
state.name = name;
},
SET_AVATAR: (state, avatar) => {
state.avatar = avatar;
},
SET_ACTIVEPORTNAME: (state, activePortName) => {
state.activePortName = activePortName;
sessionStorage.setItem("portName", activePortName);
},
SET_APP_LOADING(state, newValue) {
state.appLoading = newValue;
},
SET_DICT(state, data) {
state.dictData = data
}
},
actions: {
// 登录
Login({ commit }, userInfo) {
const accNo = userInfo.accNo.trim();
const password = userInfo.password;
const rememberMe = userInfo.rememberMe;
return new Promise((resolve, reject) => {
userLogin(accNo, password, rememberMe)
.then((res) => {
if (res.code == 200) {
setToken(res.data);
commit("SET_TOKEN", res.data);
resolve();
} else {
MessageBox.alert(res.msg, "Tip", {
dangerouslyUseHTMLString: true,
});
return Promise.reject(new Error(msg));
}
})
.catch((error) => {
reject(error);
});
});
},
// 获取用户信息
GetInfo({ commit, state }) {
return new Promise((resolve, reject) => {
getInfo()
.then((res) => {
if (res.code === 200) {
const user = res.data;
commit("SET_USERDATA", res.data);
if (state.dictData.country.length == 0) {
getCoundtry().then(countryList => {
let dict = state.dictData
dict.country = countryList
commit("SET_DICT", dict);
})
}
resolve(res);
}
})
.catch((error) => {
reject(error);
});
});
},
// 退出系统
LogOut({ commit, state }) {
return new Promise((resolve, reject) => {
logout(state.token)
.then(() => {
commit("SET_TOKEN", "");
commit("SET_USERDATA", {});
removeToken();
resolve();
})
.catch((error) => {
reject(error);
});
});
},
RemoveInfo({ commit }) {
return new Promise((resolve, reject) => {
commit("SET_USERDATA", { user: {} });
commit("SET_NAME", "");
commit("SET_AVATAR", "");
resolve();
}).catch(() => {
reject();
});
},
// 前端 登出
FedLogOut({ commit }) {
return new Promise((resolve) => {
// window.location.href = "https://test-myapps.secure.fedex.com/purpleid/signout";//wsso系统跳转
commit("SET_TOKEN", "");
commit("SET_USERDATA", {});
removeToken();
resolve();
});
},
AppLoading({ commit }, newValue) {
commit('SET_APP_LOADING', newValue)
},
},
};
export default user;
function getCoundtry() {
return new Promise((resolve, reject) => {
getcountryData().then(res => {
if (res.code === 200) {
resolve(res.data)
}
}).catch(err => {
console.log(err);
})
})
}