This commit is contained in:
kk
2026-07-08 18:00:33 +08:00
commit e66b4a3680
312 changed files with 54718 additions and 0 deletions

37
src/store/getters.js Normal file
View File

@@ -0,0 +1,37 @@
const getters = {
tag: state => state.tags.tag,
language: state => state.common.language,
setting: state => state.common.setting,
userInfo: state => state.user.userInfo,
colorName: state => state.common.colorName,
themeName: state => state.common.themeName,
isMacOs: (state, getters) => getters.themeName === 'mac-os',
isRefresh: state => state.common.isRefresh,
isSearch: state => state.common.isSearch,
isHorizontal: state => state.common.setting.sidebar === 'horizontal',
isCollapse: state => state.common.isCollapse,
isLock: state => state.common.isLock,
isFullScren: state => state.common.isFullScren,
isMenu: state => state.common.isMenu,
lockPasswd: state => state.common.lockPasswd,
tagList: state => state.tags.tagList,
tagsKeep: (state, getters) => {
return getters.tagList
.filter(ele => {
return (ele.meta || {}).keepAlive;
})
.map(ele => ele.fullPath);
},
tagWel: state => state.tags.tagWel,
token: state => state.user.token,
roles: state => state.user.roles,
permission: state => state.user.permission,
menuId: state => state.user.menuId,
menu: state => state.user.menu,
menuAll: state => state.user.menuAll,
logsList: state => state.logs.logsList,
logsLen: state => state.logs.logsList.length || 0,
logsFlag: (state, getters) => getters.logsLen === 0,
flowRoutes: state => state.dict.flowRoutes,
};
export default getters;

20
src/store/index.js Normal file
View File

@@ -0,0 +1,20 @@
import { createStore } from 'vuex';
import user from './modules/user';
import common from './modules/common';
import tags from './modules/tags';
import logs from './modules/logs';
import dict from './modules/dict';
import getters from './getters';
const store = createStore({
modules: {
user,
common,
logs,
tags,
dict,
},
getters,
});
export default store;

View File

@@ -0,0 +1,86 @@
import { setStore, getStore, removeStore } from 'utils/store';
import website from '@/config/website';
const common = {
state: {
language: getStore({ name: 'language' }) || 'zh-cn',
isCollapse: false,
isFullScren: false,
isMenu: true,
isSearch: false,
isRefresh: true,
isLock: getStore({ name: 'isLock' }),
colorName: getStore({ name: 'colorName' }) || '#2C77F1',
themeName: getStore({ name: 'themeName' }) || 'theme-go',
lockPasswd: getStore({ name: 'lockPasswd' }) || '',
website: website,
setting: website.setting,
},
mutations: {
SET_LANGUAGE: (state, language) => {
state.language = language;
setStore({
name: 'language',
content: state.language,
});
},
SET_COLLAPSE: state => {
state.isCollapse = !state.isCollapse;
},
SET_IS_MENU: (state, menu) => {
state.isMenu = menu;
},
SET_IS_REFRESH: (state, refresh) => {
state.isRefresh = refresh;
},
SET_IS_SEARCH: (state, search) => {
state.isSearch = search;
},
SET_FULLSCREN: state => {
state.isFullScren = !state.isFullScren;
},
SET_LOCK: state => {
state.isLock = true;
setStore({
name: 'isLock',
content: state.isLock,
type: 'session',
});
},
SET_COLOR_NAME: (state, colorName) => {
state.colorName = colorName;
setStore({
name: 'colorName',
content: state.colorName,
});
},
SET_THEME_NAME: (state, themeName) => {
state.themeName = themeName;
setStore({
name: 'themeName',
content: state.themeName,
});
},
SET_LOCK_PASSWD: (state, lockPasswd) => {
state.lockPasswd = lockPasswd;
setStore({
name: 'lockPasswd',
content: state.lockPasswd,
type: 'session',
});
},
CLEAR_LOCK: state => {
state.isLock = false;
state.lockPasswd = '';
removeStore({
name: 'lockPasswd',
type: 'session',
});
removeStore({
name: 'isLock',
type: 'session',
});
},
},
};
export default common;

36
src/store/modules/dict.js Normal file
View File

@@ -0,0 +1,36 @@
import { getStore, setStore } from '@/utils/store';
import { getDictionary } from '@/api/system/dict';
const dict = {
state: {
flowRoutes: getStore({ name: 'flowRoutes' }) || {},
},
actions: {
FlowRoutes({ commit }) {
return new Promise((resolve, reject) => {
getDictionary({ code: 'flow' })
.then(res => {
commit('SET_FLOW_ROUTES', res.data.data);
resolve();
})
.catch(error => {
reject(error);
});
});
},
},
mutations: {
SET_FLOW_ROUTES: (state, data) => {
state.flowRoutes = data.map(item => {
return {
routeKey: `${item.code}_${item.dictKey}`,
routeValue: item.remark,
};
});
setStore({ name: 'flowRoutes', content: state.flowRoutes });
},
},
};
export default dict;

49
src/store/modules/logs.js Normal file
View File

@@ -0,0 +1,49 @@
import { setStore, getStore } from 'utils/store';
import dayjs from 'dayjs';
import { sendLogs } from '@/api/user';
const logs = {
state: {
logsList: getStore({ name: 'logsList' }) || [],
},
actions: {
//发送错误日志
SendLogs({ state, commit }) {
return new Promise((resolve, reject) => {
sendLogs(state.logsList)
.then(() => {
commit('CLEAR_LOGS');
resolve();
})
.catch(error => {
reject(error);
});
});
},
},
mutations: {
ADD_LOGS: (state, { type, message, stack, info }) => {
state.logsList.push(
Object.assign(
{
url: window.location.href,
time: dayjs().format('YYYY-MM-DD HH:mm:ss'),
},
{
type,
message,
stack,
info: info.toString(),
}
)
);
setStore({ name: 'logsList', content: state.logsList });
},
CLEAR_LOGS: state => {
state.logsList = [];
setStore({ name: 'logsList', content: state.logsList });
},
},
};
export default logs;

57
src/store/modules/tags.js Normal file
View File

@@ -0,0 +1,57 @@
import { setStore, getStore } from 'utils/store';
import website from '@/config/website';
const tagWel = website.fistPage;
const navs = {
state: {
tagList: getStore({ name: 'tagList' }) || [],
tag: getStore({ name: 'tag' }) || {},
tagWel: tagWel,
},
mutations: {
ADD_TAG: (state, action) => {
if (typeof action.name == 'function') action.name = action.name(action.query);
state.tag = action;
setStore({ name: 'tag', content: state.tag });
const tagItem = state.tagList.find(ele => ele.fullPath == action.fullPath);
if (tagItem) {
// 同键标签允许以新参数再次进入,原位刷新避免参数固化在首次值
tagItem.query = action.query;
tagItem.params = action.params;
tagItem.meta = action.meta;
setStore({ name: 'tagList', content: state.tagList });
return;
}
state.tagList.push(action);
setStore({ name: 'tagList', content: state.tagList });
},
SET_TAG: (state, action) => {
const idx = state.tagList.findIndex(item => item.fullPath === action.fullPath);
if (idx === -1) return;
const updated = { ...state.tagList[idx], ...action };
state.tagList.splice(idx, 1, updated);
if (state.tag?.fullPath === action.fullPath) {
state.tag = updated;
setStore({ name: 'tag', content: state.tag });
}
setStore({ name: 'tagList', content: state.tagList });
},
DEL_TAG: (state, action) => {
state.tagList = state.tagList.filter(item => {
return item.fullPath !== action.fullPath;
});
setStore({ name: 'tagList', content: state.tagList });
},
DEL_ALL_TAG: (state, tagList = []) => {
state.tagList = tagList;
setStore({ name: 'tagList', content: state.tagList });
},
DEL_TAG_OTHER: state => {
state.tagList = state.tagList.filter(item => {
return [state.tag.fullPath, website.fistPage.path].includes(item.fullPath);
});
setStore({ name: 'tagList', content: state.tagList });
},
},
};
export default navs;

388
src/store/modules/user.js Normal file
View File

@@ -0,0 +1,388 @@
import {
setToken,
setRefreshToken,
removeToken,
removeRefreshToken,
getRefreshToken,
} from '@/utils/auth';
import { setStore, getStore } from '@/utils/store';
import { validatenull } from '@/utils/validate';
import { deepClone } from '@/utils/util';
import {
loginByUsername,
loginBySocial,
loginBySso,
loginByPhone,
getUserInfo,
logout,
refreshToken,
getButtons,
registerUser,
} from '@/api/user';
import { getRoutes, getTopMenu } from '@/api/system/menu';
import { formatMenu } from '@/router/tab';
import { ElMessage } from 'element-plus';
import { encrypt } from '@/utils/sm2';
const user = {
state: {
tenantId: getStore({ name: 'tenantId' }) || '',
userInfo: getStore({ name: 'userInfo' }) || [],
permission: getStore({ name: 'permission' }) || {},
roles: [],
menuId: {},
menu: getStore({ name: 'menu' }) || [],
menuAll: getStore({ name: 'menuAll' }) || [],
token: getStore({ name: 'token' }) || '',
refreshToken: getStore({ name: 'refreshToken' }) || '',
},
actions: {
//根据用户名登录
LoginByUsername({ commit }, userInfo = {}) {
return new Promise((resolve, reject) => {
loginByUsername(
userInfo.tenantId,
userInfo.deptId,
userInfo.roleId,
userInfo.username,
encrypt(userInfo.password),
userInfo.type,
userInfo.key,
userInfo.code
)
.then(res => {
const data = res.data;
if (data.error_description) {
ElMessage({
message: data.error_description,
type: 'error',
});
} else {
commit('SET_TOKEN', data.access_token);
commit('SET_REFRESH_TOKEN', data.refresh_token);
commit('SET_TENANT_ID', data.tenant_id);
commit('SET_USER_INFO', data);
commit('DEL_ALL_TAG');
commit('CLEAR_LOCK');
}
resolve();
})
.catch(err => {
reject(err);
});
});
},
//根据第三方信息登录
LoginBySocial({ commit }, userInfo) {
return new Promise((resolve, reject) => {
loginBySocial(userInfo.tenantId, userInfo.source, userInfo.code, userInfo.state)
.then(res => {
const data = res.data;
if (data.error_description) {
ElMessage({
message: data.error_description,
type: 'error',
});
} else {
commit('SET_TOKEN', data.access_token);
commit('SET_REFRESH_TOKEN', data.refresh_token);
commit('SET_USER_INFO', data);
commit('SET_TENANT_ID', data.tenant_id);
commit('DEL_ALL_TAG');
commit('CLEAR_LOCK');
}
resolve();
})
.catch(err => {
reject(err);
});
});
},
//根据单点信息登录
LoginBySso({ commit }, userInfo) {
return new Promise((resolve, reject) => {
loginBySso(userInfo.state, userInfo.code)
.then(res => {
const data = res.data;
if (data.error_description) {
ElMessage({
message: data.error_description,
type: 'error',
});
} else {
commit('SET_TOKEN', data.access_token);
commit('SET_REFRESH_TOKEN', data.refresh_token);
commit('SET_USER_INFO', data);
commit('SET_TENANT_ID', data.tenant_id);
commit('DEL_ALL_TAG');
commit('CLEAR_LOCK');
}
resolve();
})
.catch(err => {
reject(err);
});
});
},
//根据手机信息登录
LoginByPhone({ commit }, userInfo) {
return new Promise((resolve, reject) => {
loginByPhone(
userInfo.tenantId,
encrypt(userInfo.phone),
userInfo.codeId,
userInfo.codeValue
)
.then(res => {
const data = res.data;
if (data.error_description) {
ElMessage({
message: data.error_description,
type: 'error',
});
} else {
commit('SET_TOKEN', data.access_token);
commit('SET_REFRESH_TOKEN', data.refresh_token);
commit('SET_USER_INFO', data);
commit('SET_TENANT_ID', data.tenant_id);
commit('DEL_ALL_TAG');
commit('CLEAR_LOCK');
}
resolve();
})
.catch(err => {
reject(err);
});
});
},
//用户注册
RegisterUser({ commit }, userInfo = {}) {
return new Promise((resolve, reject) => {
registerUser(
userInfo.tenantId,
userInfo.name,
userInfo.account,
encrypt(userInfo.password),
userInfo.phone,
userInfo.email
).then(res => {
const data = res.data;
if (data.error_description) {
ElMessage({
message: data.error_description,
type: 'error',
});
reject(data.error_description);
} else {
commit('SET_TOKEN', data.access_token);
commit('SET_REFRESH_TOKEN', data.refresh_token);
commit('SET_USER_INFO', data);
commit('SET_TENANT_ID', data.tenant_id);
commit('DEL_ALL_TAG');
commit('CLEAR_LOCK');
}
resolve();
});
});
},
GetUserInfo({ commit }) {
return new Promise((resolve, reject) => {
getUserInfo()
.then(res => {
const data = res.data.data;
commit('SET_ROLES', data.roles);
resolve(data);
})
.catch(err => {
reject(err);
});
});
},
//刷新token
RefreshToken({ state, commit }, userInfo) {
return new Promise((resolve, reject) => {
refreshToken(
getRefreshToken(),
state.tenantId,
!validatenull(userInfo) ? userInfo.deptId : state.userInfo.dept_id,
!validatenull(userInfo) ? userInfo.roleId : state.userInfo.role_id
)
.then(res => {
const data = res.data;
commit('SET_TOKEN', data.access_token);
commit('SET_REFRESH_TOKEN', data.refresh_token);
commit('SET_USER_INFO', data);
resolve();
})
.catch(error => {
reject(error);
});
});
},
// 登出
LogOut({ commit }) {
return new Promise((resolve, reject) => {
logout()
.then(() => {
commit('SET_TOKEN', '');
commit('SET_MENU_ALL_NULL', []);
commit('SET_MENU', []);
commit('SET_ROLES', []);
commit('CLEAR_LOCK');
removeToken();
removeRefreshToken();
removeToken();
resolve();
})
.catch(error => {
reject(error);
});
});
},
//注销session
FedLogOut({ commit }) {
return new Promise(resolve => {
commit('SET_TOKEN', '');
commit('SET_MENU_ALL_NULL', []);
commit('SET_MENU', []);
commit('SET_ROLES', []);
commit('CLEAR_LOCK');
removeToken();
removeRefreshToken();
removeToken();
resolve();
});
},
GetTopMenu() {
return new Promise(resolve => {
getTopMenu().then(res => {
const data = res.data.data || [];
resolve(data);
});
});
},
GetMenu({ commit, dispatch }, topMenuId) {
return new Promise(resolve => {
getRoutes(topMenuId).then(res => {
const data = res.data.data;
let menu = deepClone(data);
formatMenu(menu);
commit('SET_MENU', menu);
commit('SET_MENU_ALL', menu);
dispatch('GetButtons');
resolve(menu);
});
});
},
GetButtons({ commit }) {
return new Promise(resolve => {
getButtons().then(res => {
const data = res.data.data;
commit('SET_PERMISSION', data);
resolve();
});
});
},
},
mutations: {
SET_TOKEN: (state, token) => {
setToken(token);
state.token = token;
setStore({ name: 'token', content: state.token });
},
SET_REFRESH_TOKEN: (state, refreshToken) => {
setRefreshToken(refreshToken);
state.refreshToken = refreshToken;
setStore({ name: 'refreshToken', content: state.refreshToken });
},
SET_MENU_ID(state, menuId) {
state.menuId = menuId;
},
SET_TENANT_ID: (state, tenantId) => {
state.tenantId = tenantId;
setStore({ name: 'tenantId', content: state.tenantId });
},
SET_USER_INFO: (state, userInfo) => {
if (validatenull(userInfo.user_id) && validatenull(userInfo.account)) {
state.userInfo = { user_name: 'unauth', role_name: 'unauth', authority: 'unauth' };
} else {
if (validatenull(userInfo.avatar)) {
userInfo.avatar = '/img/bg/img-logo.png';
}
if (!validatenull(userInfo.role_name)) {
userInfo.roleName = userInfo.role_name;
userInfo.authority = userInfo.role_name;
}
if (!validatenull(userInfo.user_id)) {
userInfo.userId = userInfo.user_id;
}
if (!validatenull(userInfo.user_name)) {
userInfo.userName = userInfo.user_name;
}
if (!validatenull(userInfo.tenant_id)) {
userInfo.tenantId = userInfo.tenant_id;
}
if (!validatenull(userInfo.dept_id)) {
userInfo.deptId = userInfo.dept_id;
}
if (!validatenull(userInfo.role_id)) {
userInfo.roleId = userInfo.role_id;
}
if (!validatenull(userInfo.oauth_id)) {
userInfo.oauthId = userInfo.oauth_id;
}
state.userInfo = userInfo;
}
setStore({ name: 'userInfo', content: state.userInfo });
},
SET_MENU_ALL: (state, menuAll) => {
let menu = state.menuAll;
menuAll.forEach(ele => {
let index = menu.findIndex(item => item.path === ele.path);
if (index === -1) {
menu.push(ele);
} else {
menu[index] = ele;
}
});
state.menuAll = menu;
setStore({ name: 'menuAll', content: state.menuAll });
},
SET_MENU_ALL_NULL: state => {
state.menuAll = [];
setStore({ name: 'menuAll', content: state.menuAll });
},
SET_MENU: (state, menu) => {
state.menu = menu;
setStore({ name: 'menu', content: state.menu });
},
SET_ROLES: (state, roles) => {
state.roles = roles;
},
SET_PERMISSION: (state, permission) => {
let result = [];
function getCode(list) {
list.forEach(ele => {
if (typeof ele === 'object') {
const children = ele.children;
const code = ele.code;
if (children && children.length > 0) {
getCode(children);
} else {
result.push(code);
}
}
});
}
getCode(permission);
state.permission = {};
result.forEach(ele => {
state.permission[ele] = true;
});
setStore({ name: 'permission', content: state.permission, type: 'session' });
},
},
};
export default user;