This commit is contained in:
xuziqiang
2024-05-15 17:29:42 +08:00
commit d0155dbe3c
7296 changed files with 1832517 additions and 0 deletions

View File

@@ -0,0 +1,136 @@
import { defineStore } from 'pinia';
import { http } from '/nerv-lib/saas';
interface AppConfig {
projectType: string;
baseApi: string;
timeout: number;
pagePermission: boolean;
actionPermission: boolean;
showProject: boolean;
resourceName: string;
useHistoryTag: boolean;
siderPosition: string; //菜单位置
userLoginApi: string; //登录接口
userCustomRouterGuard?: Function; //使用自己的路由守卫
userResourceApi: string; //获取资源接口
userInfoApi: string; //登录详情接口
enablePermissions: boolean; //是否开启权限
updatePassWordInfo?: object; //修改密码配置
headerBellInfo?: object;
customInitMessageCount?: Function; // 自定义消息数量获取事件
iframe?: false;
dropOut?: Function; //退出登录
defaultResource?: object; //默认权限
resourceInfo?: resourceInfoModul; //权限提交配置
strategyInfoApi?: string; // 获取系统密码策略
themeConfig?: object;
initThemeCoinfig?: boolean;
}
interface loginData {
userName: string;
password: string;
}
interface resourceInfoModul {
application: object;
token: string;
api: string;
dealReosurceList?: Function;
}
export const appConfigStore = defineStore({
id: 'appConfig',
state(): AppConfig {
return {
projectType: 'web',
baseApi: '/api',
timeout: 15 * 1000,
pagePermission: true,
actionPermission: true,
userLoginApi: '',
siderPosition: 'top',
userResourceApi: '',
userInfoApi: '',
resourceName: '',
showProject: false,
useHistoryTag: false,
enablePermissions: false,
updatePassWordInfo: {},
dropOut: undefined,
iframe: false,
userCustomRouterGuard: undefined,
defaultResource: undefined,
headerBellInfo: {
isShow: false,
api: '',
toRouterName: '',
},
themeConfig: {},
initThemeCoinfig: false,
resourceInfo: {
application: {},
api: '',
token: '',
},
};
},
getters: {
getThemeConfig: (state: any) => state.themeConfig,
getHeaderBellInfo: (state: any) => state.headerBellInfo,
getInitThemeCoinfig: (state: any) => state.initThemeCoinfig,
},
actions: {
setInitThemeCoinfig(val: boolean) {
this.initThemeCoinfig = val;
},
setUserInfo(val: any) {
this.userBasicInfo = val;
},
setThemeConfig(val: any) {
this.themeConfig = val;
},
setConfig(config: AppConfig) {
Object.keys(config).forEach((key) => {
this[key] = config[key];
});
},
initDefaultResource(data: any) {
this.defaultResource = data;
},
setParams(config: Object) {
Object.keys(config).forEach((key) => {
this[key] = config[key];
});
},
userLogin(data: loginData) {
if (this.userLoginApi) {
return http.post(this.userLoginApi, data, {
transformRequest: [
(mode, headers) => {
if (headers.qsToken) {
delete headers.qsToken;
}
return JSON.stringify(mode);
},
],
});
} else {
return null;
}
},
userInfo() {
if (this.userInfoApi) {
return http.get(this.userInfoApi);
} else {
return null;
}
},
userResource() {
if (this.userResourceApi) {
return http.get(this.userResourceApi);
} else {
return null;
}
},
},
});

View File

@@ -0,0 +1,243 @@
import { defineStore } from 'pinia';
import { appConfigStore } from '/nerv-base/store/modules/app-config';
export const authorizationService = defineStore({
id: 'authorizationService',
state(): {
userInfo: any;
projectId: any;
projectName: string;
enterpriseName: any;
userResourceList: any;
initAllResourceList: string[];
initRouterList: string[];
initOpList: string[];
appConfig: any;
initMenus?: object[];
allResourMenus?: object[];
} {
return {
appConfig: appConfigStore(),
projectId: null,
projectName: '',
enterpriseName: null,
userInfo: {},
userResourceList: [],
initAllResourceList: [],
initRouterList: [],
initOpList: [],
initMenus: [],
allResourMenus: [],
};
},
getters: {
getPrjectId: (state: any) => state.projectId,
getProjectName: (state: any) => state.projectName,
getEnterpriseName: (state: any) => state.enterpriseName,
getUserResource: (state: any) => state.userResource,
getInitRouterList: (state: any) => state.initRouterList,
getUserResourceList: (state: any) => state.userResourceList,
getInitMenus: (state: any) => state.initMenus,
getAllResourMenus: (state: any) => state.allResourMenus,
getInitAllResourceList: (state: any) => state.initAllResourceList,
},
actions: {
clearAuthorization() {
this.initMenus = [];
this.initRouterList = [];
this.initOpList = [];
this.userResourceList = [];
this.projectId = '';
this.projectName = '';
this.enterpriseName = '';
},
setProjectId(val: string) {
this.projectId = val;
},
clearProjectId() {
this.projectId = '';
},
setProjectName(val: string) {
this.projectName = val;
},
setEnterpriseName(val: string) {
this.enterpriseName = val;
},
async initUserResource() {
if (window.sessionStorage.getItem('checkResource') === 'false') {
this.userResourceList = [JSON.parse(window.sessionStorage.getItem('resource'))];
this.initRouterList = [];
this.dealResourceTree(this.userResourceList);
} else {
const res = await this.appConfig.userResource();
this.userResourceList = res.data ? res.data : [];
if (this.appConfig.defaultResource) {
this.userResourceList.push(this.appConfig.defaultResource);
}
this.initRouterList = [];
this.dealResourceTree(this.userResourceList);
}
},
dealMenuResource(menu: object) {
this.allResourMenus.push(menu);
if (menu.menus?.length) {
menu.menus.forEach((item) => {
this.dealMenuResource(item);
});
}
},
//初始化菜单树
async initMenuResource() {
const res = await this.appConfig.userResource();
this.initMenus = [];
if (this.appConfig.resourceName && res.data && res.data.length) {
res.data.forEach((item) => {
if (item.code.includes('Custom_')) {
this.initMenus.push(item);
}
if (item.code.includes(this.appConfig.resourceName)) {
this.initMenus.push(item);
}
});
} else {
this.initMenus = res.data ? res.data : [];
}
if (!res.data) {
return;
}
this.allResourMenus = [];
res.data.forEach((item) => {
this.dealMenuResource(item);
});
},
async initMenuResourceV2() {
if (window.sessionStorage.getItem('checkResource') === 'false') {
this.userResourceList = JSON.parse(window.sessionStorage.getItem('resource')).menus;
this.initMenus = this.userResourceList ? this.userResourceList : [];
this.allResourMenus = [];
this.userResourceList.forEach((item) => {
this.dealResourceTree(item);
});
}
},
addUserResource(val: any) {
this.userResourceList.push(val);
this.initRouterList = [];
this.dealResourceTree(this.userResourceList);
},
updateUserResource(res: any) {
if (Object.prototype.toString.call(res) !== '[object Array]') return;
if (!this.appConfig.resourceName) {
this.userResourceList = res;
this.initRouterList = [];
this.initAllResourceList = [];
this.dealResourceTree(res);
} else {
const initResource = [];
res.forEach((item) => {
if (item.code.includes('intelligent-cloud-')) {
initResource.push(item);
}
if (item.code.includes('Custom_')) {
initResource.push(item);
}
});
this.userResourceList = initResource;
this.initRouterList = [];
this.initAllResourceList = [];
this.dealResourceTree(initResource);
}
},
//检查是否有路由权限
checkPermissionRouter(routeName: string): boolean {
if (!this.appConfig.enablePermissions) {
return true;
} else {
if (this.appConfig.resourceName) {
const newName = `${this.appConfig.resourceName}${routeName}`;
return this.initRouterList.indexOf(newName) === -1 ? false : true;
} else {
return this.initRouterList.indexOf(routeName) === -1 ? false : true;
}
}
},
//检查是否有操作权限
checkPermission(actionName: string): boolean {
if (!this.appConfig.enablePermissions) {
return true;
} else {
if (this.appConfig.resourceName) {
const newName = `${this.appConfig.resourceName}${actionName}`;
return this.initOpList.indexOf(newName) === -1 ? false : true;
} else {
return this.initOpList.indexOf(actionName) === -1 ? false : true;
}
}
},
//检查是否有全部的操作
checkAllPermission(actionName: string): boolean {
if (!this.appConfig.enablePermissions) {
return true;
} else {
if (this.appConfig.resourceName) {
return this.initAllResourceList.indexOf(`${this.appConfig.resourceName}${actionName}`) ===
-1
? false
: true;
} else {
return this.initAllResourceList.indexOf(actionName) === -1 ? false : true;
}
}
},
getApp() {
return ((import.meta.env.VITE_PUBLIC_PATH || '') as string).replace(/\//g, '');
},
//判断是否为父节点
dealNoChildrenMenu(item: any) {
if (item.type === 'noChildrenMenu') {
return true;
} else {
if (
Object.prototype.toString.call(item.menus) === '[object Array]' &&
item.menus.length !== 0
) {
return true;
} else {
return false;
}
}
},
//处理资源树
dealResourceTree(res: any) {
if (Object.prototype.toString.call(res) !== '[object Array]') return;
res?.forEach((item) => {
if (item.type === 'menus' || item.type === 'noChildrenMenu') {
this.initRouterList.push(item.code);
this.initAllResourceList.push(item.code);
if (this.dealNoChildrenMenu(item)) {
this.initAllResourceList.push(item.code + 'Index');
this.initRouterList.push(item.code + 'Index');
}
}
if (item.type === 'op') {
if (item.code && this.initRouterList.indexOf(item.code) === -1) {
this.initRouterList.push(item.code);
}
this.initAllResourceList.push(item.code);
this.initOpList.push(item.code);
}
if (
Object.prototype.toString.call(item.menus) === '[object Array]' &&
item.menus.length !== 0
) {
this.dealResourceTree(item.menus);
}
});
},
},
});

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,25 @@
import { defineStore } from 'pinia';
export const useKeepAlive = defineStore({
id: 'keepAlive',
state() {
return { keepAlive: [] };
},
getters: {
getKeepAlive: (state: any) => state.keepAlive,
},
actions: {
clearKeepAlive() {
this.keepAlive = [];
},
removeKeepAlive(index: number) {
this.keepAlive.splice(index, 1);
},
addKeepAlive(val: String) {
if (val && this.keepAlive.findIndex((x) => x === val) === -1) {
this.keepAlive.push(val);
}
},
},
});

View File

@@ -0,0 +1,21 @@
import { defineStore } from 'pinia';
export const messagecount = defineStore({
id: 'messagecount',
state() {
return { count: 0 };
},
getters: {
getCount: (state: any) => state.count,
},
actions: {
updateCount(val: number | string) {
this.count = val;
},
},
// 开启数据缓存
// persist: {
// enabled: true,
// },
});

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,136 @@
import { defineStore } from 'pinia';
import { RouteMenu } from '/nerv-base/router/helper/menu-helper';
import { ModuleMenu } from '/nerv-base/router/types';
import { appConfigStore } from '/nerv-base/store/modules/app-config';
import { transformRouteToMenu } from '/nerv-base/router/helper/route-helper';
import { NSAxios } from '/nerv-lib/util/http/axios';
interface RouteState {
route: Recordable[];
routeModule: RouteMenu[];
routeModuleObject: Recordable;
}
export const useRouteStore = defineStore({
id: 'route',
state: (): RouteState => {
return { route: [], routeModule: [], routeModuleObject: {} };
},
getters: {},
actions: {
async getRouteModule() {
const initList = [];
this.route.forEach((item) => {
if (item.name !== 'root') {
initList.push(transformRouteToMenu(item));
}
});
this.dealNoChildrenMenu(initList);
this.routeModule = initList;
return this.routeModule;
},
async setRoute(route: Recordable[]) {
this.route = route;
await this.getRouteModule();
},
/**
* 判断菜单是否是noChildrenMenu
*
*/
dealNoChildrenMenu(item: any) {
item.forEach((sitem: any) => {
if (
Object.prototype.toString.call(sitem.menus) === '[object Array]' &&
sitem.menus.length !== 0
) {
if (sitem.menus.findIndex((x) => x.type === 'menus') === -1) {
sitem.type = 'noChildrenMenu';
} else {
this.dealNoChildrenMenu(sitem.menus);
}
} else {
if (sitem.route?.meta?.hideChildren) {
sitem.type = 'noChildrenMenu';
}
}
});
},
/**
* 同步菜单修改到路由
*/
syncRoute() {
const appConfig = appConfigStore();
const routeModuleObject: Recordable = {};
function loop(routeModule: ModuleMenu[]) {
for (let i = 0, j = routeModule.length; i < j; i++) {
routeModuleObject[routeModule[i].code] = routeModule[i];
routeModule[i].menus && loop(routeModule[i].menus);
}
}
loop(this.routeModule);
this.routeModuleObject = routeModuleObject;
function loopRoute(routeList) {
for (let i = 0, j = routeList.length; i < j; i++) {
const route = routeList[i];
!route.meta && (route.meta = {});
if (routeModuleObject[route.name] === undefined) {
console.error(`route ${route.name} is not in menu`);
return;
}
if (!route.meta.index || route.meta.index !== routeModuleObject[route.name].sort) {
route.meta.index = routeModuleObject[route.name].sort;
}
if (!route.meta.title || route.meta.title !== routeModuleObject[route.name].label) {
route.meta.title = routeModuleObject[route.name].label;
}
route.children && loopRoute(route.children);
}
}
loopRoute(this.route);
this.route.sort((a, b) => {
return a.meta?.index - b.meta?.index;
});
const initPcResource = { application: {}, menus: [] };
this.routeModule.sort((a, b) => {
return a.route?.meta?.index - b.route?.meta?.index;
});
const info = JSON.parse(JSON.stringify(this.routeModule));
initRouteMouleList(info);
function initRouteMouleList(info) {
info.forEach((item, index) => {
item.sort = index;
if (item.menus) {
initRouteMouleList(item.menus);
}
if (item.extend) {
let isNull = true;
Object.keys(item.extend).forEach((key) => {
if (item.extend[key]) {
isNull = false;
}
});
if (isNull) {
delete item.extend;
}
}
delete item.route;
});
}
initPcResource.application = appConfig.resourceInfo?.application as object;
initPcResource.menus = appConfig.resourceInfo?.dealReosurceList
? appConfig.resourceInfo?.dealReosurceList(info)
: info;
new NSAxios({
headers: {
'Content-Type': 'application/json;charset=UTF-8',
'QA-token': appConfig.resourceInfo?.token as string,
},
withCredentials: true,
timeout: 3 * 1000,
})
.post(appConfig.resourceInfo?.api as string, initPcResource)
.then((res) => {
console.log(res);
});
},
},
});

View File

@@ -0,0 +1,61 @@
import { defineStore } from 'pinia';
import { tagsClass } from '/nerv-lib/saas/view/system/application';
export const useTags = defineStore({
id: 'tags',
state() {
return { tagList: [] };
},
getters: {
getTags: (state: any) => state.tagList,
},
actions: {
addTags(val: tagsClass) {
if (val.check) {
const index = this.tagList.findIndex(
(x) => x.currentUrl && x.currentUrl === val.currentUrl,
);
if (index === -1) {
this.tagList.push(val as never);
}
} else {
const index = this.tagList.findIndex((x) => x.name === val.name);
if (index === -1) {
this.tagList.push(val as never);
}
}
sessionStorage.setItem('tagList', JSON.stringify(this.tagList));
},
initTags() {
const sessionTagList = sessionStorage.getItem('tagList');
if (sessionTagList) {
this.tagList = JSON.parse(sessionTagList);
}
},
clearTags() {
this.tagList = [];
sessionStorage.setItem('tagList', JSON.stringify(this.tagList));
},
unshiftTags(val: tagsClass) {
this.tagList.unshift(val as never);
sessionStorage.setItem('tagList', JSON.stringify(this.tagList));
},
sliceTags(index: number) {
this.tagList = this.tagList.slice(index, 1);
sessionStorage.setItem('tagList', JSON.stringify(this.tagList));
},
spliceTags(index: number) {
this.tagList.splice(index, 1);
sessionStorage.setItem('tagList', JSON.stringify(this.tagList));
},
updateTagTitle(index: number, val: String) {
this.tagList[index].title = val;
sessionStorage.setItem('tagList', JSON.stringify(this.tagList));
},
},
// 开启数据缓存
// persist: {
// enabled: true,
// },
});

View File

@@ -0,0 +1,25 @@
import { defineStore } from 'pinia';
import { router } from '/nerv-lib/saas/router';
export const user = defineStore<
string,
{ token: string; userName: string },
{},
{ login: Function; logout: Function }
>({
id: 'user',
state: () => {
return { token: '', userName: '111' };
},
getters: {
double(): string {
return this.userName;
},
},
actions: {
login() {},
logout() {
router.push('/login');
},
},
});