!64 版本升级
* Merge branch 'dev' of gitee.com:JavaLionLi/plus-ui into ts * 升级依赖 * !61 fix: 删除重复环境变量ElUploadInstance * fix: 删除重复环境变量ElUploadInstance
This commit is contained in:
@ -22,7 +22,7 @@ export const useNoticeStore = defineStore('notice', () => {
|
||||
|
||||
//实现全部已读
|
||||
const readAll = () => {
|
||||
state.notices.forEach((item) => {
|
||||
state.notices.forEach((item: any) => {
|
||||
item.read = true;
|
||||
});
|
||||
};
|
||||
|
@ -2,35 +2,36 @@ import { defineStore } from 'pinia';
|
||||
import router, { constantRoutes, dynamicRoutes } from '@/router';
|
||||
import store from '@/store';
|
||||
import { getRouters } from '@/api/menu';
|
||||
import auth from '@/plugins/auth';
|
||||
import { RouteRecordRaw } from 'vue-router';
|
||||
|
||||
import Layout from '@/layout/index.vue';
|
||||
import ParentView from '@/components/ParentView/index.vue';
|
||||
import InnerLink from '@/layout/components/InnerLink/index.vue';
|
||||
import auth from '@/plugins/auth';
|
||||
import { RouteOption } from 'vue-router';
|
||||
|
||||
// 匹配views里面所有的.vue文件
|
||||
const modules = import.meta.glob('./../../views/**/*.vue');
|
||||
|
||||
export const usePermissionStore = defineStore('permission', () => {
|
||||
const routes = ref<RouteOption[]>([]);
|
||||
const addRoutes = ref<RouteOption[]>([]);
|
||||
const defaultRoutes = ref<RouteOption[]>([]);
|
||||
const topbarRouters = ref<RouteOption[]>([]);
|
||||
const sidebarRouters = ref<RouteOption[]>([]);
|
||||
const routes = ref<RouteRecordRaw[]>([]);
|
||||
const addRoutes = ref<RouteRecordRaw[]>([]);
|
||||
const defaultRoutes = ref<RouteRecordRaw[]>([]);
|
||||
const topbarRouters = ref<RouteRecordRaw[]>([]);
|
||||
const sidebarRouters = ref<RouteRecordRaw[]>([]);
|
||||
|
||||
const setRoutes = (newRoutes: RouteOption[]): void => {
|
||||
const setRoutes = (newRoutes: RouteRecordRaw[]): void => {
|
||||
addRoutes.value = newRoutes;
|
||||
routes.value = constantRoutes.concat(newRoutes);
|
||||
};
|
||||
const setDefaultRoutes = (routes: RouteOption[]): void => {
|
||||
const setDefaultRoutes = (routes: RouteRecordRaw[]): void => {
|
||||
defaultRoutes.value = constantRoutes.concat(routes);
|
||||
};
|
||||
const setTopbarRoutes = (routes: RouteOption[]): void => {
|
||||
const setTopbarRoutes = (routes: RouteRecordRaw[]): void => {
|
||||
topbarRouters.value = routes;
|
||||
};
|
||||
const setSidebarRouters = (routes: RouteOption[]): void => {
|
||||
const setSidebarRouters = (routes: RouteRecordRaw[]): void => {
|
||||
sidebarRouters.value = routes;
|
||||
};
|
||||
const generateRoutes = async (): Promise<RouteOption[]> => {
|
||||
const generateRoutes = async (): Promise<RouteRecordRaw[]> => {
|
||||
const res = await getRouters();
|
||||
const { data } = res;
|
||||
const sdata = JSON.parse(JSON.stringify(data));
|
||||
@ -47,7 +48,7 @@ export const usePermissionStore = defineStore('permission', () => {
|
||||
setSidebarRouters(constantRoutes.concat(sidebarRoutes));
|
||||
setDefaultRoutes(sidebarRoutes);
|
||||
setTopbarRoutes(defaultRoutes);
|
||||
return new Promise<RouteOption[]>((resolve) => resolve(rewriteRoutes));
|
||||
return new Promise<RouteRecordRaw[]>((resolve) => resolve(rewriteRoutes));
|
||||
};
|
||||
|
||||
/**
|
||||
@ -56,22 +57,20 @@ export const usePermissionStore = defineStore('permission', () => {
|
||||
* @param lastRouter 上一级路由
|
||||
* @param type 是否是重写路由
|
||||
*/
|
||||
const filterAsyncRouter = (asyncRouterMap: RouteOption[], lastRouter?: RouteOption, type = false): RouteOption[] => {
|
||||
const filterAsyncRouter = (asyncRouterMap: RouteRecordRaw[], lastRouter?: RouteRecordRaw, type = false): RouteRecordRaw[] => {
|
||||
return asyncRouterMap.filter((route) => {
|
||||
if (type && route.children) {
|
||||
route.children = filterChildren(route.children, undefined);
|
||||
}
|
||||
if (route.component) {
|
||||
// Layout ParentView 组件特殊处理
|
||||
if (route.component === 'Layout') {
|
||||
route.component = Layout;
|
||||
} else if (route.component === 'ParentView') {
|
||||
route.component = ParentView;
|
||||
} else if (route.component === 'InnerLink') {
|
||||
route.component = InnerLink;
|
||||
} else {
|
||||
route.component = loadView(route.component);
|
||||
}
|
||||
// Layout ParentView 组件特殊处理
|
||||
if (route.component?.toString() === 'Layout') {
|
||||
route.component = Layout;
|
||||
} else if (route.component?.toString() === 'ParentView') {
|
||||
route.component = ParentView;
|
||||
} else if (route.component?.toString() === 'InnerLink') {
|
||||
route.component = InnerLink;
|
||||
} else {
|
||||
route.component = loadView(route.component);
|
||||
}
|
||||
if (route.children != null && route.children && route.children.length) {
|
||||
route.children = filterAsyncRouter(route.children, route, type);
|
||||
@ -82,11 +81,11 @@ export const usePermissionStore = defineStore('permission', () => {
|
||||
return true;
|
||||
});
|
||||
};
|
||||
const filterChildren = (childrenMap: RouteOption[], lastRouter?: RouteOption): RouteOption[] => {
|
||||
let children: RouteOption[] = [];
|
||||
const filterChildren = (childrenMap: RouteRecordRaw[], lastRouter?: RouteRecordRaw): RouteRecordRaw[] => {
|
||||
let children: RouteRecordRaw[] = [];
|
||||
childrenMap.forEach((el) => {
|
||||
if (el.children && el.children.length) {
|
||||
if (el.component === 'ParentView' && !lastRouter) {
|
||||
if (el.component?.toString() === 'ParentView' && !lastRouter) {
|
||||
el.children.forEach((c) => {
|
||||
c.path = el.path + '/' + c.path;
|
||||
if (c.children && c.children.length) {
|
||||
@ -101,8 +100,8 @@ export const usePermissionStore = defineStore('permission', () => {
|
||||
if (lastRouter) {
|
||||
el.path = lastRouter.path + '/' + el.path;
|
||||
if (el.children && el.children.length) {
|
||||
children = children.concat(filterChildren(el.children, el))
|
||||
return
|
||||
children = children.concat(filterChildren(el.children, el));
|
||||
return;
|
||||
}
|
||||
}
|
||||
children = children.concat(el);
|
||||
@ -113,8 +112,8 @@ export const usePermissionStore = defineStore('permission', () => {
|
||||
});
|
||||
|
||||
// 动态路由遍历,验证是否具备权限
|
||||
export const filterDynamicRoutes = (routes: RouteOption[]) => {
|
||||
const res: RouteOption[] = [];
|
||||
export const filterDynamicRoutes = (routes: RouteRecordRaw[]) => {
|
||||
const res: RouteRecordRaw[] = [];
|
||||
routes.forEach((route) => {
|
||||
if (route.permissions) {
|
||||
if (auth.hasPermiOr(route.permissions)) {
|
||||
|
@ -2,27 +2,35 @@ import { defineStore } from 'pinia';
|
||||
import defaultSettings from '@/settings';
|
||||
import { SettingTypeEnum } from '@/enums/SettingTypeEnum';
|
||||
import { useDynamicTitle } from '@/utils/dynamicTitle';
|
||||
import { Ref } from 'vue';
|
||||
|
||||
export const useSettingsStore = defineStore('setting', () => {
|
||||
const storageSetting = JSON.parse(localStorage.getItem('layout-setting') || '{}');
|
||||
const title = ref<string>(defaultSettings.title);
|
||||
const theme = ref<string>(storageSetting.theme || defaultSettings.theme);
|
||||
const sideTheme = ref<string>(storageSetting.sideTheme || defaultSettings.sideTheme);
|
||||
const showSettings = ref<boolean>(storageSetting.showSettings || defaultSettings.showSettings);
|
||||
const topNav = ref<boolean>(storageSetting.topNav === undefined ? defaultSettings.topNav : storageSetting.topNav);
|
||||
const tagsView = ref<boolean>(storageSetting.tagsView === undefined ? defaultSettings.tagsView : storageSetting.tagsView);
|
||||
const fixedHeader = ref<boolean>(storageSetting.fixedHeader === undefined ? defaultSettings.fixedHeader : storageSetting.fixedHeader);
|
||||
const sidebarLogo = ref<boolean>(storageSetting.sidebarLogo === undefined ? defaultSettings.sidebarLogo : storageSetting.sidebarLogo);
|
||||
const dynamicTitle = ref<boolean>(storageSetting.dynamicTitle === undefined ? defaultSettings.dynamicTitle : storageSetting.dynamicTitle);
|
||||
const animationEnable = ref<boolean>(
|
||||
storageSetting.animationEnable === undefined ? defaultSettings.animationEnable : storageSetting.animationEnable
|
||||
);
|
||||
const dark = ref<boolean>(storageSetting.dark || defaultSettings.dark);
|
||||
|
||||
const prop: { [key: string]: Ref<any> } = {
|
||||
title: ref<string>(''),
|
||||
theme: ref<string>(storageSetting.theme || defaultSettings.theme),
|
||||
sideTheme: ref<string>(storageSetting.sideTheme || defaultSettings.sideTheme),
|
||||
showSettings: ref<boolean>(storageSetting.showSettings || defaultSettings.showSettings),
|
||||
topNav: ref<boolean>(storageSetting.topNav === undefined ? defaultSettings.topNav : storageSetting.topNav),
|
||||
tagsView: ref<boolean>(storageSetting.tagsView === undefined ? defaultSettings.tagsView : storageSetting.tagsView),
|
||||
fixedHeader: ref<boolean>(storageSetting.fixedHeader === undefined ? defaultSettings.fixedHeader : storageSetting.fixedHeader),
|
||||
sidebarLogo: ref<boolean>(storageSetting.sidebarLogo === undefined ? defaultSettings.sidebarLogo : storageSetting.sidebarLogo),
|
||||
dynamicTitle: ref<boolean>(storageSetting.dynamicTitle === undefined ? defaultSettings.dynamicTitle : storageSetting.dynamicTitle),
|
||||
animationEnable: ref<boolean>(storageSetting.animationEnable === undefined ? defaultSettings.animationEnable : storageSetting.animationEnable),
|
||||
dark: ref<boolean>(storageSetting.dark || defaultSettings.dark)
|
||||
theme,
|
||||
sideTheme,
|
||||
showSettings,
|
||||
topNav,
|
||||
tagsView,
|
||||
fixedHeader,
|
||||
sidebarLogo,
|
||||
dynamicTitle,
|
||||
animationEnable,
|
||||
dark
|
||||
};
|
||||
|
||||
const { title, theme, sideTheme, showSettings, topNav, tagsView, fixedHeader, sidebarLogo, dynamicTitle, animationEnable, dark } = prop;
|
||||
|
||||
// actions
|
||||
const changeSetting = (param: { key: SettingTypeEnum; value: any }) => {
|
||||
const { key, value } = param;
|
||||
|
@ -11,7 +11,7 @@ export const useTagsViewStore = defineStore('tagsView', () => {
|
||||
};
|
||||
|
||||
const addIframeView = (view: TagView): void => {
|
||||
if (iframeViews.value.some((v) => v.path === view.path)) return;
|
||||
if (iframeViews.value.some((v: TagView) => v.path === view.path)) return;
|
||||
iframeViews.value.push(
|
||||
Object.assign({}, view, {
|
||||
title: view.meta?.title || 'no-name'
|
||||
@ -20,12 +20,12 @@ export const useTagsViewStore = defineStore('tagsView', () => {
|
||||
};
|
||||
const delIframeView = (view: TagView): Promise<TagView[]> => {
|
||||
return new Promise((resolve) => {
|
||||
iframeViews.value = iframeViews.value.filter((item) => item.path !== view.path);
|
||||
iframeViews.value = iframeViews.value.filter((item: TagView) => item.path !== view.path);
|
||||
resolve([...iframeViews.value]);
|
||||
});
|
||||
};
|
||||
const addVisitedView = (view: TagView): void => {
|
||||
if (visitedViews.value.some((v) => v.path === view.path)) return;
|
||||
if (visitedViews.value.some((v: TagView) => v.path === view.path)) return;
|
||||
visitedViews.value.push(
|
||||
Object.assign({}, view, {
|
||||
title: view.meta?.title || 'no-name'
|
||||
@ -80,7 +80,7 @@ export const useTagsViewStore = defineStore('tagsView', () => {
|
||||
|
||||
const delOthersVisitedViews = (view: TagView): Promise<TagView[]> => {
|
||||
return new Promise((resolve) => {
|
||||
visitedViews.value = visitedViews.value.filter((v) => {
|
||||
visitedViews.value = visitedViews.value.filter((v: TagView) => {
|
||||
return v.meta?.affix || v.path === view.path;
|
||||
});
|
||||
resolve([...visitedViews.value]);
|
||||
@ -111,7 +111,7 @@ export const useTagsViewStore = defineStore('tagsView', () => {
|
||||
};
|
||||
const delAllVisitedViews = (): Promise<TagView[]> => {
|
||||
return new Promise((resolve) => {
|
||||
visitedViews.value = visitedViews.value.filter((tag) => tag.meta?.affix);
|
||||
visitedViews.value = visitedViews.value.filter((tag: TagView) => tag.meta?.affix);
|
||||
resolve([...visitedViews.value]);
|
||||
});
|
||||
};
|
||||
@ -123,7 +123,7 @@ export const useTagsViewStore = defineStore('tagsView', () => {
|
||||
});
|
||||
};
|
||||
|
||||
const updateVisitedView = (view: TagView): void => {
|
||||
const updateVisitedView = (view: TagView | RouteLocationNormalized): void => {
|
||||
for (let v of visitedViews.value) {
|
||||
if (v.path === view.path) {
|
||||
v = Object.assign(v, view);
|
||||
@ -133,11 +133,11 @@ export const useTagsViewStore = defineStore('tagsView', () => {
|
||||
};
|
||||
const delRightTags = (view: TagView): Promise<TagView[]> => {
|
||||
return new Promise((resolve) => {
|
||||
const index = visitedViews.value.findIndex((v) => v.path === view.path);
|
||||
const index = visitedViews.value.findIndex((v: TagView) => v.path === view.path);
|
||||
if (index === -1) {
|
||||
return;
|
||||
}
|
||||
visitedViews.value = visitedViews.value.filter((item, idx) => {
|
||||
visitedViews.value = visitedViews.value.filter((item: TagView, idx: number) => {
|
||||
if (idx <= index || (item.meta && item.meta.affix)) {
|
||||
return true;
|
||||
}
|
||||
@ -152,11 +152,11 @@ export const useTagsViewStore = defineStore('tagsView', () => {
|
||||
};
|
||||
const delLeftTags = (view: TagView): Promise<TagView[]> => {
|
||||
return new Promise((resolve) => {
|
||||
const index = visitedViews.value.findIndex((v) => v.path === view.path);
|
||||
const index = visitedViews.value.findIndex((v: TagView) => v.path === view.path);
|
||||
if (index === -1) {
|
||||
return;
|
||||
}
|
||||
visitedViews.value = visitedViews.value.filter((item, idx) => {
|
||||
visitedViews.value = visitedViews.value.filter((item: TagView, idx: number) => {
|
||||
if (idx >= index || (item.meta && item.meta.affix)) {
|
||||
return true;
|
||||
}
|
||||
@ -170,7 +170,7 @@ export const useTagsViewStore = defineStore('tagsView', () => {
|
||||
});
|
||||
};
|
||||
|
||||
const addCachedView = (view: TagView): void => {
|
||||
const addCachedView = (view: TagView | RouteLocationNormalized): void => {
|
||||
const viewName = view.name as string;
|
||||
if (!viewName) return;
|
||||
if (cachedViews.value.includes(viewName)) return;
|
||||
|
Reference in New Issue
Block a user