|
@@ -5,10 +5,12 @@ import {
|
|
|
menuList,
|
|
|
dingdingdetail,
|
|
|
usergetinfo,
|
|
|
- roleProcessInfo,
|
|
|
- requsetSupertubeCompany,
|
|
|
- requsetBindCompany
|
|
|
+ roleProcessInfo,
|
|
|
+ requsetSupertubeCompany,
|
|
|
+ requsetUserBindingCompany,
|
|
|
+ reuqsetRoleInfo
|
|
|
} from "@/apis/user";
|
|
|
+import router from "@/router";
|
|
|
|
|
|
import {
|
|
|
getToken,
|
|
@@ -36,7 +38,12 @@ import {
|
|
|
set_role_level,
|
|
|
remove_role_level,
|
|
|
getUserCompany,
|
|
|
+ setUserCompany,
|
|
|
+ removeUserCompany,
|
|
|
} from "@/utils/auth";
|
|
|
+import { MessageBox } from "element-ui";
|
|
|
+
|
|
|
+import { convertCompanylist } from "@/utils";
|
|
|
import store from "..";
|
|
|
|
|
|
const state = {
|
|
@@ -52,7 +59,7 @@ const state = {
|
|
|
business_companyNo: get_business_companyNo() || "",
|
|
|
private_field: get_private_field() || [],
|
|
|
roleProcess: get_action_data() || [],
|
|
|
- currentCompany: getUserCompany(),
|
|
|
+ currentCompany: getUserCompany() ? getUserCompany().code : '',
|
|
|
isSupertube: false,
|
|
|
companylist:[]
|
|
|
};
|
|
@@ -110,6 +117,9 @@ const mutations = {
|
|
|
set_private_field(val);
|
|
|
},
|
|
|
setCurrentCompany(state,val){
|
|
|
+ //获取当前公司详细信息
|
|
|
+ const company = state.companylist.find(({code}) => code === val)
|
|
|
+ setUserCompany(company)
|
|
|
state.currentCompany = val;
|
|
|
},
|
|
|
setCompanylist(state,val){
|
|
@@ -118,7 +128,7 @@ const mutations = {
|
|
|
setSupertube(state, val) {
|
|
|
state.isSupertube = val;
|
|
|
}
|
|
|
-};
|
|
|
+}
|
|
|
|
|
|
const actions = {
|
|
|
// user login
|
|
@@ -142,11 +152,25 @@ const actions = {
|
|
|
});
|
|
|
},
|
|
|
|
|
|
+ //公司角色异常
|
|
|
+ disabledCompany({commit, that}){
|
|
|
+ commit("navListFn", []);
|
|
|
+ commit("btnListFn", []);
|
|
|
+ initRouter([], that);
|
|
|
+
|
|
|
+ const company = getUserCompany()
|
|
|
+
|
|
|
+ MessageBox
|
|
|
+ .alert(`公司 ${company.name} 角色异常或该公司禁用,请检查账号或者角色设置`, '公司角色异常')
|
|
|
+ .then(() => router.push("/reload?redirect=welcome/dashboard"))
|
|
|
+ .catch(() => router.push("/reload?redirect=welcome/dashboard"))
|
|
|
+ },
|
|
|
+
|
|
|
dingUserInfor({ commit }, code) {
|
|
|
return new Promise(async (resolve, reject) => {
|
|
|
dingdingdetail(code)
|
|
|
.then((response) => {
|
|
|
- const { data } = response;
|
|
|
+ const { data } = response;P
|
|
|
if (response.code === 0) {
|
|
|
commit("SET_TOKEN", data.token);
|
|
|
setToken(data.token);
|
|
@@ -161,7 +185,73 @@ const actions = {
|
|
|
});
|
|
|
},
|
|
|
|
|
|
- async getMenuList({ commit, that }) {
|
|
|
+ async reloadMenulist({commit, dispatch ,that}){
|
|
|
+ return new Promise(async resolve => {
|
|
|
+ const company = getUserCompany()
|
|
|
+
|
|
|
+ dispatch('getRoleInfo', company)
|
|
|
+
|
|
|
+
|
|
|
+ //获取菜单
|
|
|
+ const { mcode, mdata, message: mmsg } = await getRoleMenuList();
|
|
|
+
|
|
|
+ //账号禁用
|
|
|
+ if(mcode === 10001){
|
|
|
+ commit("navListFn", []);
|
|
|
+ commit("btnListFn", []);
|
|
|
+ initRouter([], that);
|
|
|
+ resolve('disabled')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (mcode >= 100 && mcode <= 104) {
|
|
|
+ resolve("noToken");
|
|
|
+ } else if (mcode !== 0) {
|
|
|
+ resolve({ code: mcode, data: {}, massage: mmsg });
|
|
|
+ } else {
|
|
|
+ const { arrag, isok, btnList } = mdata;
|
|
|
+ // 生成页面权限
|
|
|
+ commit("navListFn", arrag);
|
|
|
+ // 生成按钮权限
|
|
|
+ commit("btnListFn", btnList);
|
|
|
+ // 生成路由
|
|
|
+ initRouter(arrag, that);
|
|
|
+ resolve(isok ? "success-dataV" : "success");
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ async getRoleInfo({commit, that, dispatch}, _current_company_){
|
|
|
+ return new Promise(async resolve => {
|
|
|
+ //查找默认的业务公司 设置到全局的currentCompany
|
|
|
+ const { roleid } = _current_company_;
|
|
|
+
|
|
|
+ //根据角色获取流程节点权限
|
|
|
+ const { pcode, pdata, pmsg } = await getRoleProcess(roleid);
|
|
|
+ if (pcode === 0) {
|
|
|
+ commit("roleProcess", pdata ?? []);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (pcode >= 100 && pcode <= 104) {
|
|
|
+ resolve("noToken");
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据角色获取角色详情 获取关键字字段
|
|
|
+ const {code: rcode, data: rdata, message: rmsg} = await reuqsetRoleInfo({ roleid })
|
|
|
+
|
|
|
+ if(rcode === 0){
|
|
|
+ commit("private_field", rdata.private_field ? rdata.private_field.split(',') : []);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rcode >= 100 && rcode <= 104) {
|
|
|
+ resolve("noToken");
|
|
|
+ return
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ async getMenuList({ commit, that, dispatch }) {
|
|
|
return new Promise(async (resolve, reject) => {
|
|
|
if (!getToken()) {
|
|
|
resolve("noToken");
|
|
@@ -174,17 +264,23 @@ const actions = {
|
|
|
} else {
|
|
|
const { level } = udata;
|
|
|
const isSupertube = level === '1';
|
|
|
+
|
|
|
//保存是否超管用户
|
|
|
commit("setSupertube", isSupertube);
|
|
|
-
|
|
|
+
|
|
|
//获取公司列表(区分超管和普通账户api)
|
|
|
- const api = isSupertube ? requsetSupertubeCompany : requsetBindCompany;
|
|
|
- const { data: companyData, code: companyCode } = await api({})
|
|
|
-
|
|
|
+ const api = isSupertube
|
|
|
+ ? requsetSupertubeCompany
|
|
|
+ : requsetUserBindingCompany
|
|
|
+
|
|
|
+ //获取缓存里的业务公司 =》 公司名称搜索 =》 存在设置为默认公司
|
|
|
+ const company = getUserCompany();
|
|
|
+ const { data: companyData, code: companyCode } = await api({[isSupertube ? 'code' : 'companyCode'] :company ? company.code : ""})
|
|
|
+
|
|
|
+ //保存公司列表 普通用户和超管使用两个列表需要转换
|
|
|
let _companylist = []
|
|
|
- //保存公司列表:todo 两个接口返回值可能不同 需要转换
|
|
|
if(companyCode === 0) {
|
|
|
- _companylist = isSupertube ? companyData.list : companyData.list
|
|
|
+ _companylist = isSupertube ? companyData.list : convertCompanylist(companyData.list);
|
|
|
commit('setCompanylist', _companylist)
|
|
|
}
|
|
|
|
|
@@ -193,47 +289,44 @@ const actions = {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- let _current_company_ = ''
|
|
|
//非超管用户获取保存 流程权限 & 关键字字段 & 设置默认业务公司
|
|
|
+ let _current_company_ = ''
|
|
|
if(!isSupertube){
|
|
|
//查找默认的业务公司 设置到全局的currentCompany
|
|
|
- const _mainCompany = _companylist.find(({is_main}) => String(is_main) === '1')
|
|
|
- _current_company_ = _mainCompany ? _mainCompany : _companylist[0];
|
|
|
-
|
|
|
- const { roleid } = _current_company_;
|
|
|
-
|
|
|
- //根据角色获取流程节点权限
|
|
|
- const { pcode, pdata, pmsg } = await getRoleProcess({ roleid });
|
|
|
- if (pcode >= 100 && pcode <= 104) {
|
|
|
- resolve("noToken");
|
|
|
- } else if (pcode !== 0) {
|
|
|
- resolve({ code: pcode, data: {}, massage: pmsg });
|
|
|
- } else {
|
|
|
- commit("roleProcess", pdata ?? []);
|
|
|
- }
|
|
|
-
|
|
|
- //根据角色获取角色详情 获取关键字字段
|
|
|
+ _current_company_ = _companylist[0];
|
|
|
+ const result = dispatch('getRoleInfo', _current_company_)
|
|
|
+
|
|
|
+ if(result === 'noToken') {
|
|
|
+ resolve('noToken')
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//保存默认公司
|
|
|
- commit('setCurrentCompany', _current_company_ ? _current_company_.companyCode : '')
|
|
|
-
|
|
|
+ commit('setCurrentCompany', _current_company_ ? _current_company_.code : '')
|
|
|
//获取菜单
|
|
|
const { mcode, mdata, mmsg } = await getRoleMenuList();
|
|
|
- if (mcode >= 100 && mcode <= 104) {
|
|
|
- resolve("noToken");
|
|
|
- } else if (mcode !== 0) {
|
|
|
- resolve({ code: mcodd, data: {}, massage: mmsg });
|
|
|
- } else {
|
|
|
- const { arrag, isok, btnList } = mdata;
|
|
|
- // 生成页面权限
|
|
|
- commit("navListFn", arrag);
|
|
|
- // 生成按钮权限
|
|
|
- commit("btnListFn", btnList);
|
|
|
- // 生成路由
|
|
|
- initRouter(arrag, that);
|
|
|
- resolve(isok ? "success-dataV" : "success");
|
|
|
- }
|
|
|
+
|
|
|
+ //拦截账号异常: 禁用
|
|
|
+ if(mcode === 10001) {
|
|
|
+ dispatch('disabledCompany');
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (mcode >= 100 && mcode <= 104) {
|
|
|
+ resolve("noToken");
|
|
|
+ } else if (mcode !== 0) {
|
|
|
+ resolve({ code: mcode, data: {}, massage: mmsg });
|
|
|
+ } else {
|
|
|
+ const { arrag, isok, btnList } = mdata;
|
|
|
+ // 生成页面权限
|
|
|
+ commit("navListFn", arrag);
|
|
|
+ // 生成按钮权限
|
|
|
+ commit("btnListFn", btnList);
|
|
|
+ // 生成路由
|
|
|
+ initRouter(arrag, that);
|
|
|
+ resolve(isok ? "success-dataV" : "success");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -258,6 +351,8 @@ const actions = {
|
|
|
commit("private_field", []);
|
|
|
remove_action_data();
|
|
|
commit("action_data", []);
|
|
|
+ removeUserCompany()
|
|
|
+ commit("action_data", []);
|
|
|
// removeMainList()
|
|
|
// reset visited views and cached views
|
|
|
// to fixed https://github.com/PanJiaChen/vue-element-admin/issues/2485
|
|
@@ -314,7 +409,17 @@ async function getRoleProcess(roleid) {
|
|
|
};
|
|
|
}
|
|
|
async function getRoleMenuList() {
|
|
|
- const { code, data, meaasge } = await menuList({});
|
|
|
+ const { code, data, meaasge, message } = await menuList({});
|
|
|
+
|
|
|
+ //menu接受账户异常:禁用 并返回
|
|
|
+ if(message === '账户已禁用'){
|
|
|
+ return {
|
|
|
+ mdata:{},
|
|
|
+ mmsg:'账号被禁用',
|
|
|
+ mcode:10001
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
let arrag = [];
|
|
|
let btnList = [];
|
|
|
let list = [];
|
|
@@ -451,10 +556,6 @@ function initRouter(arr) {
|
|
|
window.vm.$router.addRoutes(IndexRoute);
|
|
|
}
|
|
|
|
|
|
-function getCompanylist(){
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
initalUserInfo();
|
|
|
|
|
|
export default {
|