|
@@ -1,4 +1,11 @@
|
|
|
-import { login, logout, userinfo, menuList, dingdingdetail, logoutx } from '@/apis/user'
|
|
|
+import {
|
|
|
+ login,
|
|
|
+ logout,
|
|
|
+ userinfo,
|
|
|
+ menuList,
|
|
|
+ dingdingdetail,
|
|
|
+ logoutx,
|
|
|
+} from "@/apis/user";
|
|
|
import {
|
|
|
getToken,
|
|
|
setToken,
|
|
@@ -12,162 +19,159 @@ import {
|
|
|
getRoles,
|
|
|
setRoles,
|
|
|
removeRoles,
|
|
|
-} from '@/utils/auth'
|
|
|
+} from "@/utils/auth";
|
|
|
|
|
|
const state = {
|
|
|
token: getToken(),
|
|
|
- name: '',
|
|
|
- avatar: require('@/assets/sheji/user.png'),
|
|
|
- introduction: '',
|
|
|
- roles: getRoles() ? getRoles() : 'edit',
|
|
|
+ name: "",
|
|
|
+ avatar: require("@/assets/sheji/user.png"),
|
|
|
+ introduction: "",
|
|
|
+ roles: getRoles() ? getRoles() : "edit",
|
|
|
btnList: getBtn(),
|
|
|
navList: getMenu(),
|
|
|
-}
|
|
|
+};
|
|
|
|
|
|
const mutations = {
|
|
|
SET_TOKEN: (state, token) => {
|
|
|
- state.token = token
|
|
|
+ state.token = token;
|
|
|
},
|
|
|
SET_MENU: (state, menu) => {
|
|
|
- state.menu = menu
|
|
|
+ state.menu = menu;
|
|
|
},
|
|
|
SET_HAS: (state, has) => {
|
|
|
- state.has = has
|
|
|
+ state.has = has;
|
|
|
},
|
|
|
SET_INTRODUCTION: (state, introduction) => {
|
|
|
- state.introduction = introduction
|
|
|
+ state.introduction = introduction;
|
|
|
},
|
|
|
SET_NAME: (state, name) => {
|
|
|
- state.name = name
|
|
|
+ state.name = name;
|
|
|
},
|
|
|
SET_AVATAR: (state, avatar) => {
|
|
|
- state.avatar = avatar
|
|
|
+ state.avatar = avatar;
|
|
|
},
|
|
|
SET_ROLES: (state, roles) => {
|
|
|
- state.roles = roles
|
|
|
+ state.roles = roles;
|
|
|
},
|
|
|
navListFn(state, val) {
|
|
|
if (!val) {
|
|
|
val = [];
|
|
|
}
|
|
|
state.navList = val;
|
|
|
- setMenu(val)
|
|
|
+ setMenu(val);
|
|
|
},
|
|
|
btnListFn(state, val) {
|
|
|
if (!val) {
|
|
|
val = [];
|
|
|
}
|
|
|
- state.btnList = val
|
|
|
- setBtn(val)
|
|
|
-
|
|
|
+ state.btnList = val;
|
|
|
+ setBtn(val);
|
|
|
},
|
|
|
-}
|
|
|
+};
|
|
|
|
|
|
const actions = {
|
|
|
// user login
|
|
|
login({ commit }, userInfo) {
|
|
|
- const { username, password } = userInfo
|
|
|
+ const { username, password } = userInfo;
|
|
|
return new Promise((resolve, reject) => {
|
|
|
login({ username: username.trim(), password: password })
|
|
|
- .then(response => {
|
|
|
- const { data } = response
|
|
|
+ .then((response) => {
|
|
|
+ const { data } = response;
|
|
|
if (response.code === 0) {
|
|
|
- let ROLES = username === 'admin' ? 'admin' : "edit"
|
|
|
- commit('SET_TOKEN', data.token)
|
|
|
- commit('SET_ROLES', ROLES)
|
|
|
- setRoles(ROLES)
|
|
|
- setToken(data.token)
|
|
|
+ let ROLES = username === "admin" ? "admin" : "edit";
|
|
|
+ commit("SET_TOKEN", data.token);
|
|
|
+ commit("SET_ROLES", ROLES);
|
|
|
+ setRoles(ROLES);
|
|
|
+ setToken(data.token);
|
|
|
}
|
|
|
- resolve(response)
|
|
|
- })
|
|
|
- .catch(error => {
|
|
|
- reject(error)
|
|
|
+ resolve(response);
|
|
|
})
|
|
|
- })
|
|
|
+ .catch((error) => {
|
|
|
+ reject(error);
|
|
|
+ });
|
|
|
+ });
|
|
|
},
|
|
|
|
|
|
dingUserInfor({ commit }, code) {
|
|
|
return new Promise(async (resolve, reject) => {
|
|
|
dingdingdetail(code)
|
|
|
- .then(response => {
|
|
|
- const { data } = response
|
|
|
+ .then((response) => {
|
|
|
+ const { data } = response;
|
|
|
if (response.code === 0) {
|
|
|
- commit('SET_TOKEN', data.token)
|
|
|
- setToken(data.token)
|
|
|
- resolve("success")
|
|
|
+ commit("SET_TOKEN", data.token);
|
|
|
+ setToken(data.token);
|
|
|
+ resolve("success");
|
|
|
} else {
|
|
|
- resolve("error")
|
|
|
+ resolve("error");
|
|
|
}
|
|
|
})
|
|
|
- .catch(error => {
|
|
|
- reject(error)
|
|
|
- })
|
|
|
- })
|
|
|
+ .catch((error) => {
|
|
|
+ reject(error);
|
|
|
+ });
|
|
|
+ });
|
|
|
},
|
|
|
async getMenuList({ commit, that }) {
|
|
|
return new Promise(async (resolve, reject) => {
|
|
|
if (!getToken()) {
|
|
|
- resolve("noToken")
|
|
|
+ resolve("noToken");
|
|
|
} else {
|
|
|
- let res = await menuList({})
|
|
|
- if (res.code === 0) {
|
|
|
- let list = res.data
|
|
|
- list = list.filter((item) => item.child && item.child.length > 0)
|
|
|
- let arrag = []
|
|
|
- let btnList = []
|
|
|
- console.log(list)
|
|
|
- list.forEach(v1 => {
|
|
|
+ const { code, data, message } = await menuList({});
|
|
|
+ if (code === 0) {
|
|
|
+ let list = data;
|
|
|
+ list = list.filter((item) => item.child && item.child.length > 0);
|
|
|
+ let arrag = [];
|
|
|
+ let btnList = [];
|
|
|
+ console.log(list);
|
|
|
+ list.forEach((v1) => {
|
|
|
// if(v1.menu_route!=="system" )
|
|
|
let pItem = {
|
|
|
name: v1.menu_route,
|
|
|
path: `/${v1.menu_route}`,
|
|
|
meta: {
|
|
|
title: v1.menu_name,
|
|
|
- icon: v1.menu_img
|
|
|
+ icon: v1.menu_img,
|
|
|
},
|
|
|
- children: []
|
|
|
- }
|
|
|
- v1.child.forEach(v2 => {
|
|
|
- if (v2.menu_route === 'menuOperator') {
|
|
|
+ children: [],
|
|
|
+ };
|
|
|
+ v1.child.forEach((v2) => {
|
|
|
+ if (v2.menu_route === "menuOperator") {
|
|
|
if (getRoles() === "admin") {
|
|
|
let item = {
|
|
|
path: v2.menu_route,
|
|
|
name: v2.menu_route,
|
|
|
meta: {
|
|
|
title: v2.menu_name,
|
|
|
- icon: v2.menu_img
|
|
|
+ icon: v2.menu_img,
|
|
|
},
|
|
|
- url: v2.menu_url
|
|
|
- }
|
|
|
+ url: v2.menu_url,
|
|
|
+ };
|
|
|
let model = {
|
|
|
menu_route: v2.menu_route,
|
|
|
- action: v2.action
|
|
|
- }
|
|
|
- btnList.push(model)
|
|
|
- pItem.children.push(item)
|
|
|
+ action: v2.action,
|
|
|
+ };
|
|
|
+ btnList.push(model);
|
|
|
+ pItem.children.push(item);
|
|
|
}
|
|
|
} else {
|
|
|
-
|
|
|
let item = {
|
|
|
path: v2.menu_route,
|
|
|
name: v2.menu_route,
|
|
|
meta: {
|
|
|
title: v2.menu_name,
|
|
|
- icon: v2.menu_img
|
|
|
+ icon: v2.menu_img,
|
|
|
},
|
|
|
- url: v2.menu_url
|
|
|
- }
|
|
|
+ url: v2.menu_url,
|
|
|
+ };
|
|
|
let model = {
|
|
|
menu_route: v2.menu_route,
|
|
|
- action: v2.action
|
|
|
- }
|
|
|
- btnList.push(model)
|
|
|
- pItem.children.push(item)
|
|
|
+ action: v2.action,
|
|
|
+ };
|
|
|
+ btnList.push(model);
|
|
|
+ pItem.children.push(item);
|
|
|
}
|
|
|
-
|
|
|
- })
|
|
|
- arrag.push(pItem)
|
|
|
- })
|
|
|
+ });
|
|
|
+ arrag.push(pItem);
|
|
|
+ });
|
|
|
console.log(arrag);
|
|
|
|
|
|
// 生成页面权限
|
|
@@ -177,115 +181,106 @@ const actions = {
|
|
|
// 生成路由
|
|
|
initRouter(arrag, that);
|
|
|
// state.commit("loginInfoCommit", res.data);
|
|
|
- resolve("success")
|
|
|
- } else if (res.code === 101 || res.code === 102) {
|
|
|
- resolve("noToken")
|
|
|
+ resolve("success");
|
|
|
+ } else if (code === 101 || code === 102) {
|
|
|
+ resolve("noToken");
|
|
|
} else {
|
|
|
- resolve(res)
|
|
|
+ resolve({ code, data, message });
|
|
|
}
|
|
|
}
|
|
|
- })
|
|
|
+ });
|
|
|
},
|
|
|
|
|
|
-
|
|
|
-
|
|
|
// user logout
|
|
|
async logout({ commit, state, dispatch }) {
|
|
|
-
|
|
|
return new Promise(async (resolve, reject) => {
|
|
|
if (!getToken()) {
|
|
|
- await resetAll({ commit, dispatch })
|
|
|
- resolve()
|
|
|
+ await resetAll({ commit, dispatch });
|
|
|
+ resolve();
|
|
|
} else {
|
|
|
- let res = await logoutx({ token: getToken() })
|
|
|
- if (res.code === 0) {
|
|
|
- await resetAll({ commit, dispatch })
|
|
|
- resolve()
|
|
|
+ const { code, data, message } = await logoutx({ token: getToken() });
|
|
|
+ if (code === 0) {
|
|
|
+ await resetAll({ commit, dispatch });
|
|
|
+ resolve();
|
|
|
} else {
|
|
|
- await resetAll({ commit, dispatch })
|
|
|
- resolve()
|
|
|
+ await resetAll({ commit, dispatch });
|
|
|
+ resolve();
|
|
|
}
|
|
|
}
|
|
|
- })
|
|
|
-
|
|
|
-
|
|
|
+ });
|
|
|
},
|
|
|
|
|
|
-
|
|
|
-
|
|
|
// remove token
|
|
|
resetToken({ commit }) {
|
|
|
- return new Promise(resolve => {
|
|
|
- commit('SET_TOKEN', '')
|
|
|
- commit('SET_ROLES', "")
|
|
|
- removeToken()
|
|
|
- resolve()
|
|
|
- removeRoles()
|
|
|
- })
|
|
|
+ return new Promise((resolve) => {
|
|
|
+ commit("SET_TOKEN", "");
|
|
|
+ commit("SET_ROLES", "");
|
|
|
+ removeToken();
|
|
|
+ resolve();
|
|
|
+ removeRoles();
|
|
|
+ });
|
|
|
},
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
+};
|
|
|
|
|
|
async function resetAll({ commit, dispatch }) {
|
|
|
- return new Promise(resolve => {
|
|
|
- commit('SET_TOKEN', '')
|
|
|
- commit('SET_ROLES', "")
|
|
|
- commit('SET_MENU', '')
|
|
|
- commit('SET_HAS', '')
|
|
|
+ return new Promise((resolve) => {
|
|
|
+ commit("SET_TOKEN", "");
|
|
|
+ commit("SET_ROLES", "");
|
|
|
+ commit("SET_MENU", "");
|
|
|
+ commit("SET_HAS", "");
|
|
|
|
|
|
- removeMenu()
|
|
|
- removeBtn()
|
|
|
- removeToken()
|
|
|
- removeRoles()
|
|
|
+ removeMenu();
|
|
|
+ removeBtn();
|
|
|
+ removeToken();
|
|
|
+ removeRoles();
|
|
|
// reset visited views and cached views
|
|
|
// to fixed https://github.com/PanJiaChen/vue-element-admin/issues/2485
|
|
|
- dispatch('tagsView/delAllViews', null, { root: true })
|
|
|
- resolve()
|
|
|
- })
|
|
|
+ dispatch("tagsView/delAllViews", null, { root: true });
|
|
|
+ resolve();
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
function initRouter(arr) {
|
|
|
const IndexRoute = [
|
|
|
//欢迎页
|
|
|
{
|
|
|
- path: '/welcome',
|
|
|
- component: () => import('@/layout/index'),
|
|
|
- redirect: '/welcome/dashboard',
|
|
|
+ path: "/welcome",
|
|
|
+ component: () => import("@/layout/index"),
|
|
|
+ redirect: "/welcome/dashboard",
|
|
|
children: [
|
|
|
{
|
|
|
- path: 'dashboard',
|
|
|
- component: () => import('@/views/dashboard/index'),
|
|
|
- name: 'Dashboard',
|
|
|
- meta: { title: '首页', icon: 'dashboard', affix: true }
|
|
|
+ path: "dashboard",
|
|
|
+ component: () => import("@/views/dashboard/index"),
|
|
|
+ name: "Dashboard",
|
|
|
+ meta: { title: "首页", icon: "dashboard", affix: true },
|
|
|
},
|
|
|
- ]
|
|
|
+ ],
|
|
|
},
|
|
|
];
|
|
|
|
|
|
- arr.map(v1 => {
|
|
|
- v1.component = (resolve) => require([`@/layout/index.vue`], resolve)
|
|
|
+ arr.map((v1) => {
|
|
|
+ v1.component = (resolve) => require([`@/layout/index.vue`], resolve);
|
|
|
if (v1.children && v1.children.length > 0) {
|
|
|
- v1.redirect = `/${v1.name}/${v1.children[0].name}`
|
|
|
- v1.children.map(v2 => {
|
|
|
- v2.component = (resolve) => require([`@/views/${v2.url}.vue`], resolve)
|
|
|
- return v2
|
|
|
- })
|
|
|
+ v1.redirect = `/${v1.name}/${v1.children[0].name}`;
|
|
|
+ v1.children.map((v2) => {
|
|
|
+ v2.component = (resolve) => require([`@/views/${v2.url}.vue`], resolve);
|
|
|
+ return v2;
|
|
|
+ });
|
|
|
}
|
|
|
- return v1
|
|
|
- })
|
|
|
- IndexRoute.push(...arr)
|
|
|
+ return v1;
|
|
|
+ });
|
|
|
+ IndexRoute.push(...arr);
|
|
|
IndexRoute.push({
|
|
|
- path: '404',
|
|
|
- component: () => import('@/views/error-page/404'),
|
|
|
+ path: "404",
|
|
|
+ component: () => import("@/views/error-page/404"),
|
|
|
hidden: false,
|
|
|
- noCache: true
|
|
|
- })
|
|
|
+ noCache: true,
|
|
|
+ });
|
|
|
|
|
|
IndexRoute.push({
|
|
|
path: "*",
|
|
|
- redirect: '/404',
|
|
|
- })
|
|
|
+ redirect: "/404",
|
|
|
+ });
|
|
|
window.vm.$router.addRoutes(IndexRoute);
|
|
|
}
|
|
|
|
|
@@ -293,5 +288,5 @@ export default {
|
|
|
namespaced: true,
|
|
|
state,
|
|
|
mutations,
|
|
|
- actions
|
|
|
-}
|
|
|
+ actions,
|
|
|
+};
|