42056450
阿宝
权限修改
|
1
2
3
4
5
|
import Vue from "vue";
import Vuex from "vuex";
import Cookies from "js-cookie";
import layoutStore from "./modules/layout/index";
import { defaultRouter } from "@/router/index";
|
13b58a42
梁保满
备题组卷部分前端页面基本完成
|
6
|
import { encryptLoginPassword } from "@/utils";
|
aeac66d4
阿宝
飞书测试bug
|
7
|
import { Message } from "element-ui";
|
4c4f7640
梁保满
路由表,路由前端文件
|
8
|
|
42056450
阿宝
权限修改
|
9
10
|
import request from "@/api/index";
import router from "@/router/index";
|
77ebf04d
梁保满
个人版
|
11
|
import { addrouters,addRoutersAdmin ,addroutersPersonal} from "@/router/index";
|
42056450
阿宝
权限修改
|
12
|
Vue.use(Vuex);
|
c1b532ad
梁保满
权限配置,路由基础设置
|
13
14
15
|
const store = new Vuex.Store({
state: {
|
b769660c
梁保满
备课组题细节调整,随堂问列表页面开发完成
|
16
17
|
token: "",
csCode: localStorage.getItem("csCode") || "",
|
bbc51d4b
梁保满
组卷添加修改分数,打开新开页面跳转...
|
18
19
|
info: localStorage.getItem("info")
? JSON.parse(localStorage.getItem("info"))
|
42056450
阿宝
权限修改
|
20
21
22
|
: "", // 每次刷新都要通过token请求个人信息来筛选动态路由
routers: [], //左侧菜单
addRouters:
|
bbc51d4b
梁保满
组卷添加修改分数,打开新开页面跳转...
|
23
24
25
|
localStorage.getItem("addRouters") &&
localStorage.getItem("addRouters") != "undefined"
? JSON.parse(localStorage.getItem("addRouters"))
|
42056450
阿宝
权限修改
|
26
27
|
: [], //动态路由
tokenSources: new Map(), //正在请求接口(切换取消请求)
|
c1b532ad
梁保满
权限配置,路由基础设置
|
28
29
|
},
mutations: {
|
4c4f7640
梁保满
路由表,路由前端文件
|
30
|
setToken(state, token) {
|
42056450
阿宝
权限修改
|
31
|
state.token = token;
|
b769660c
梁保满
备课组题细节调整,随堂问列表页面开发完成
|
32
33
34
|
},
setCode(state, code) {
state.csCode = code;
|
42056450
阿宝
权限修改
|
35
|
localStorage.setItem("csCode", code);
|
4c4f7640
梁保满
路由表,路由前端文件
|
36
37
|
},
setInfo(state, data) {
|
42056450
阿宝
权限修改
|
38
|
state.info = { ...data };
|
bbc51d4b
梁保满
组卷添加修改分数,打开新开页面跳转...
|
39
|
localStorage.setItem("info", JSON.stringify(data));
|
4c4f7640
梁保满
路由表,路由前端文件
|
40
41
|
},
setRouters: (state, routers) => {
|
77ebf04d
梁保满
个人版
|
42
|
let addrouterList = []
|
21dfdeae
梁保满
平台管理员
|
43
|
if(state.info.showRole == 'ROLE_PERSONAL'){
|
77ebf04d
梁保满
个人版
|
44
|
addrouterList = [...addroutersPersonal]
|
21dfdeae
梁保满
平台管理员
|
45
|
}else if(state.info.showRole == 'ROLE_PINGTAI'){
|
77ebf04d
梁保满
个人版
|
46
47
48
49
50
|
addrouterList = [...addRoutersAdmin]
}else{
addrouterList = [...addrouters]
}
let aRouters = addrouterList.filter((item) => {
|
42056450
阿宝
权限修改
|
51
52
53
|
let path = item.children[0]?.path.replace("/", "");
return routers?.includes(path);
});
|
b769660c
梁保满
备课组题细节调整,随堂问列表页面开发完成
|
54
|
|
42056450
阿宝
权限修改
|
55
56
|
state.addRouters = aRouters; // 保存动态路由用来addRouter
state.routers = defaultRouter.concat(aRouters); // 所有有权限的路由表,用来生成菜单列表
|
bbc51d4b
梁保满
组卷添加修改分数,打开新开页面跳转...
|
57
|
localStorage.setItem("addRouters", JSON.stringify(routers));
|
4c4f7640
梁保满
路由表,路由前端文件
|
58
|
},
|
b769660c
梁保满
备课组题细节调整,随堂问列表页面开发完成
|
59
60
|
setTokenSources(state, data) {
if (data instanceof Array) {
|
42056450
阿宝
权限修改
|
61
|
state.tokenSources.set(data[0], data[1]);
|
b769660c
梁保满
备课组题细节调整,随堂问列表页面开发完成
|
62
|
} else {
|
42056450
阿宝
权限修改
|
63
|
state.tokenSources = new Map();
|
65f592b6
梁保满
答题卡列表页
|
64
65
|
}
},
|
b769660c
梁保满
备课组题细节调整,随堂问列表页面开发完成
|
66
|
delTokenSources(state, data) {
|
42056450
阿宝
权限修改
|
67
|
state.tokenSources.delete(data);
|
65f592b6
梁保满
答题卡列表页
|
68
|
},
|
c1b532ad
梁保满
权限配置,路由基础设置
|
69
70
|
},
actions: {
|
b769660c
梁保满
备课组题细节调整,随堂问列表页面开发完成
|
71
|
Login({ state, commit }, params) {
|
42056450
阿宝
权限修改
|
72
|
let loginForm = {};
|
13b58a42
梁保满
备题组卷部分前端页面基本完成
|
73
74
|
loginForm.username = params.username;
loginForm.password = encryptLoginPassword(params.password);
|
42056450
阿宝
权限修改
|
75
76
77
78
79
80
|
request
.login({ ...loginForm })
.then((res) => {
let response = res;
if (response.status == 0) {
const userInfo = { ...response.data };
|
aeac66d4
阿宝
飞书测试bug
|
81
82
|
if (userInfo.permissions && userInfo.permissions.length) {
userInfo.showRoleName = response.data.permissions[0]?.roleName;
|
21dfdeae
梁保满
平台管理员
|
83
|
userInfo.showRole = response.data.permissions[0]?.role;
|
77ebf04d
梁保满
个人版
|
84
|
// 开发用,测试删除
|
21dfdeae
梁保满
平台管理员
|
85
|
// userInfo.showRole = "ROLE_PERSONAL";
|
aeac66d4
阿宝
飞书测试bug
|
86
87
|
commit("setToken", "isLogin");
commit("setInfo", { ...userInfo });
|
21dfdeae
梁保满
平台管理员
|
88
89
90
|
commit("setRouters", [
...userInfo.permissions[0]?.authorityRouter,
]);
|
77ebf04d
梁保满
个人版
|
91
|
//start 开发用,测试删除
|
21dfdeae
梁保满
平台管理员
|
92
93
94
95
96
97
98
99
100
101
102
103
104
|
// commit("setRouters", [
// "setUpStudent",
// "examinationPaper",
// "examinationPaperAdd",
// "examinationPaperEdit",
// "examinationPaperRecycle",
// "ask",
// "askAnalysis",
// "test",
// "testAnalysis",
// "portrait",
// "dataSync",
// "down",
|
77ebf04d
梁保满
个人版
|
105
|
|
21dfdeae
梁保满
平台管理员
|
106
107
108
109
|
// "account",
// "device",
// "clientVersion"
// ]);
|
77ebf04d
梁保满
个人版
|
110
111
|
//end
|
aeac66d4
阿宝
飞书测试bug
|
112
113
114
115
116
117
118
119
120
|
state.addRouters.forEach((res) => {
router.addRoute(res);
});
router.addRoute({
path: "*",
redirect: "/404",
hidden: true,
children: [],
});
|
aeac66d4
阿宝
飞书测试bug
|
121
122
123
124
125
|
if (params.url) {
window.location.href = params.url;
} else {
router.push({ path: "/" });
}
|
42056450
阿宝
权限修改
|
126
|
} else {
|
aeac66d4
阿宝
飞书测试bug
|
127
128
129
130
131
|
Message({
message: "该账号暂无权限,请联系管理员~",
type: "error",
duration: 3 * 1000,
});
|
42056450
阿宝
权限修改
|
132
|
}
|
aeac66d4
阿宝
飞书测试bug
|
133
134
135
136
137
138
|
} else {
Message({
message: response.info,
type: "error",
duration: 3 * 1000,
});
|
b769660c
梁保满
备课组题细节调整,随堂问列表页面开发完成
|
139
|
}
|
42056450
阿宝
权限修改
|
140
141
|
})
.catch(() => {});
|
29f8fb90
梁保满
刷新浏览器重新动态添加路由
|
142
|
},
|
b21d90ef
梁保满
长水登录
|
143
144
145
146
147
148
149
150
151
|
CSLogin({ state, commit }, code) {
request
.ssoLogin({ code:code})
.then((res) => {
let response = res;
if (response.status == 0) {
const userInfo = { ...response.data };
if (userInfo.permissions && userInfo.permissions.length) {
userInfo.showRoleName = response.data.permissions[0]?.roleName;
|
77ebf04d
梁保满
个人版
|
152
|
userInfo.showRole = response.data.permissions[0]?.role;
|
b21d90ef
梁保满
长水登录
|
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
commit("setToken", "isLogin");
commit("setCode", code);
commit("setInfo", { ...userInfo });
commit("setRouters", [
...userInfo.permissions[0]?.authorityRouter,
]);
state.addRouters.forEach((res) => {
router.addRoute(res);
});
router.addRoute({
path: "*",
redirect: "/404",
hidden: true,
children: [],
});
router.push({ path: "/" });
} else {
Message({
message: "该账号暂无权限,请联系管理员~",
type: "error",
duration: 3 * 1000,
});
}
} else {
Message({
message: response.info,
type: "error",
duration: 3 * 1000,
});
}
})
.catch(() => {});
},
|
42056450
阿宝
权限修改
|
187
188
189
190
191
192
|
permissions({ state, commit }, role) {
commit("setToken", "isLogin");
let userInfo = state.info;
let authorityRouterObj = userInfo.permissions.filter((item) => {
return item.role == role;
});
|
aeac66d4
阿宝
飞书测试bug
|
193
|
userInfo.showRoleName = authorityRouterObj[0]?.roleName;
|
77ebf04d
梁保满
个人版
|
194
|
userInfo.showRole = authorityRouterObj[0]?.role;
|
bb778c90
阿宝
设备状态
|
195
|
commit("setInfo", userInfo);
|
42056450
阿宝
权限修改
|
196
|
commit("setRouters", [...authorityRouterObj[0]?.authorityRouter]);
|
13b58a42
梁保满
备题组卷部分前端页面基本完成
|
197
|
state.addRouters.forEach((res) => {
|
b769660c
梁保满
备课组题细节调整,随堂问列表页面开发完成
|
198
|
router.addRoute(res);
|
29f8fb90
梁保满
刷新浏览器重新动态添加路由
|
199
|
});
|
b769660c
梁保满
备课组题细节调整,随堂问列表页面开发完成
|
200
201
202
203
|
router.addRoute({
path: "*",
redirect: "/404",
hidden: true,
|
42056450
阿宝
权限修改
|
204
205
206
|
children: [],
});
router.push({ path: "/" });
|
11a4e518
梁保满
背题组卷修改答案设置,即使测随堂问...
|
207
|
window.location.reload()
|
42056450
阿宝
权限修改
|
208
|
},
|
c1b532ad
梁保满
权限配置,路由基础设置
|
209
210
|
},
getters: {
|
42056450
阿宝
权限修改
|
211
212
213
214
215
216
217
218
219
220
|
addRouters: (state) => state.addRouters,
token: (state) => state.token,
code: (state) => state.csCode,
info: (state) => state.info,
routers: (state) => state.routers,
logoShow: (state) => state.layoutStore.logoShow,
isCollapse: (state) => state.layoutStore.isCollapse,
uniquerouter: (state) => state.layoutStore.uniquerouter,
tabnavBox: (state) => state.layoutStore.tabnavBox,
rightNav: (state) => state.layoutStore.rightNav,
|
c1b532ad
梁保满
权限配置,路由基础设置
|
221
222
|
},
modules: {
|
42056450
阿宝
权限修改
|
223
224
225
|
layoutStore,
},
});
|
c1b532ad
梁保满
权限配置,路由基础设置
|
226
|
|
42056450
阿宝
权限修改
|
227
|
export default store;
|