|
@@ -1,4 +1,11 @@
|
|
|
-import { login, logout, userinfo, menuList, dingdingdetail } from "@/apis/user";
|
|
|
+import {
|
|
|
+ login,
|
|
|
+ logout,
|
|
|
+ userinfo,
|
|
|
+ dingdingdetail,
|
|
|
+ aoldMenuList,
|
|
|
+ caixiaoMenuList,
|
|
|
+} from "@/apis/user";
|
|
|
import {
|
|
|
getToken,
|
|
|
setToken,
|
|
@@ -12,6 +19,9 @@ import {
|
|
|
getBtn,
|
|
|
setBtn,
|
|
|
removeBtn,
|
|
|
+ get_business_companyNo,
|
|
|
+ set_business_companyNo,
|
|
|
+ remove_business_companyNo,
|
|
|
} from "@/utils/auth";
|
|
|
|
|
|
const state = {
|
|
@@ -23,14 +33,25 @@ const state = {
|
|
|
roles: ["admin"],
|
|
|
btnList: getBtn(),
|
|
|
navList: getMenu(),
|
|
|
+ business_companyNo: get_business_companyNo() || "",
|
|
|
};
|
|
|
|
|
|
const mutations = {
|
|
|
SET_TOKEN: (state, token) => {
|
|
|
state.token = token;
|
|
|
+ if (token === "") {
|
|
|
+ removeToken();
|
|
|
+ } else {
|
|
|
+ setToken(token);
|
|
|
+ }
|
|
|
},
|
|
|
SET_USER_ID: (state, userid) => {
|
|
|
state.userid = userid;
|
|
|
+ if (userid === "") {
|
|
|
+ removeUserId();
|
|
|
+ } else {
|
|
|
+ setUserId(userid);
|
|
|
+ }
|
|
|
},
|
|
|
SET_MENU: (state, menu) => {
|
|
|
state.menu = menu;
|
|
@@ -64,9 +85,23 @@ const mutations = {
|
|
|
state.btnList = val;
|
|
|
setBtn(val);
|
|
|
},
|
|
|
+ business_companyNo(state, val) {
|
|
|
+ state.business_companyNo = val;
|
|
|
+ if (val === "") {
|
|
|
+ remove_business_companyNo();
|
|
|
+ } else {
|
|
|
+ set_business_companyNo(val);
|
|
|
+ }
|
|
|
+ },
|
|
|
};
|
|
|
|
|
|
const actions = {
|
|
|
+ change_company({ commit }, supplierNo) {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ commit("business_companyNo", supplierNo);
|
|
|
+ resolve("ok");
|
|
|
+ });
|
|
|
+ },
|
|
|
// user login
|
|
|
login({ commit }, userInfo) {
|
|
|
const { username, password } = userInfo;
|
|
@@ -77,11 +112,9 @@ const actions = {
|
|
|
if (code === 0) {
|
|
|
const { token, userinfo } = data;
|
|
|
const { id } = userinfo;
|
|
|
- console.log(id);
|
|
|
commit("SET_TOKEN", token);
|
|
|
commit("SET_USER_ID", id);
|
|
|
- setUserId(id);
|
|
|
- setToken(token);
|
|
|
+ commit("business_companyNo", "1");
|
|
|
}
|
|
|
resolve(response);
|
|
|
})
|
|
@@ -97,13 +130,10 @@ const actions = {
|
|
|
.then((response) => {
|
|
|
const { code, data } = response;
|
|
|
if (code === 0) {
|
|
|
- // alert(JSON.stringify(data))
|
|
|
const { token, id } = data;
|
|
|
- // const { id } = userinfo;
|
|
|
commit("SET_TOKEN", token);
|
|
|
- setToken(token);
|
|
|
commit("SET_USER_ID", id);
|
|
|
- setUserId(id);
|
|
|
+ commit("business_companyNo", "1");
|
|
|
resolve("success");
|
|
|
} else {
|
|
|
resolve("error");
|
|
@@ -119,17 +149,28 @@ const actions = {
|
|
|
if (!getToken()) {
|
|
|
resolve("noToken");
|
|
|
} else {
|
|
|
- let res = await menuList({});
|
|
|
- if (res.code === 0) {
|
|
|
- let list = res.data;
|
|
|
+ let res = {};
|
|
|
+ const { business_companyNo } = state;
|
|
|
+ if (business_companyNo === "1") {
|
|
|
+ res = await caixiaoMenuList({});
|
|
|
+ } else if (business_companyNo === "2") {
|
|
|
+ res = await aoldMenuList({});
|
|
|
+ } else {
|
|
|
+ res = { code: 0, data: [], massage: "" };
|
|
|
+ }
|
|
|
+
|
|
|
+ const { code, data } = res;
|
|
|
+ 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) => {
|
|
|
let pItem = {
|
|
|
name: v1.menu_route,
|
|
|
- path: `/${v1.menu_route}`,
|
|
|
+ path: `/${business_companyNo === "1" ? "caixiao" : "aold"}${
|
|
|
+ v1.menu_route
|
|
|
+ }`,
|
|
|
meta: {
|
|
|
title: v1.menu_name,
|
|
|
icon: v1.menu_img,
|
|
@@ -155,17 +196,14 @@ const actions = {
|
|
|
});
|
|
|
arrag.push(pItem);
|
|
|
});
|
|
|
- console.log(arrag);
|
|
|
-
|
|
|
// 生成页面权限
|
|
|
commit("navListFn", arrag);
|
|
|
// 生成按钮权限
|
|
|
commit("btnListFn", btnList);
|
|
|
// 生成路由
|
|
|
initRouter(arrag, that);
|
|
|
- // state.commit("loginInfoCommit", res.data);
|
|
|
resolve("success");
|
|
|
- } else if (res.code === 101 || res.code === 102) {
|
|
|
+ } else if (code === 101 || code === 102) {
|
|
|
resolve("noToken");
|
|
|
} else {
|
|
|
resolve(res);
|
|
@@ -180,11 +218,9 @@ const actions = {
|
|
|
commit("SET_TOKEN", "");
|
|
|
commit("SET_USER_ID", "");
|
|
|
commit("SET_ROLES", []);
|
|
|
- removeToken();
|
|
|
- removeUserId();
|
|
|
commit("SET_MENU", "");
|
|
|
commit("SET_HAS", "");
|
|
|
-
|
|
|
+ commit("business_companyNo", "");
|
|
|
removeMenu();
|
|
|
removeBtn();
|
|
|
// reset visited views and cached views
|
|
@@ -200,7 +236,7 @@ const actions = {
|
|
|
commit("SET_TOKEN", "");
|
|
|
commit("SET_USER_ID", "");
|
|
|
commit("SET_ROLES", []);
|
|
|
- removeToken();
|
|
|
+
|
|
|
removeUserId();
|
|
|
resolve();
|
|
|
});
|
|
@@ -259,30 +295,25 @@ function initRouter(arr) {
|
|
|
],
|
|
|
},
|
|
|
];
|
|
|
-
|
|
|
+ const { business_companyNo } = state;
|
|
|
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/caixiao/${v2.url}.vue`], resolve);
|
|
|
+ v2.component = (resolve) =>
|
|
|
+ require([
|
|
|
+ `@/views/${business_companyNo === "1" ? "caixiao" : "aold"}/${
|
|
|
+ v2.url
|
|
|
+ }.vue`,
|
|
|
+ ], resolve);
|
|
|
return v2;
|
|
|
});
|
|
|
}
|
|
|
return v1;
|
|
|
});
|
|
|
IndexRoute.push(...arr);
|
|
|
- IndexRoute.push({
|
|
|
- path: "404",
|
|
|
- component: () => import("@/views/error-page/404"),
|
|
|
- hidden: false,
|
|
|
- noCache: true,
|
|
|
- });
|
|
|
|
|
|
- IndexRoute.push({
|
|
|
- path: "*",
|
|
|
- redirect: "/404",
|
|
|
- });
|
|
|
window.vm.$router.addRoutes(IndexRoute);
|
|
|
}
|
|
|
|