超市商品管理的修改

This commit is contained in:
weiwei committed 2025-05-27 18:37:32 +08:00
1 parent 3a38bd19ee
commit 4e02c9bbea
6 files changed
+197 -159

No files matched your search

+56 -55
View File
@@ -1,28 +1,28 @@
import { RouteRecordRaw } from 'vue-router';
import pinia from '/@/stores/index';
import { useUserInfo } from '/@/stores/userInfo';
import { useRequestOldRoutes } from '/@/stores/requestOldRoutes';
import { Session } from '/@/utils/storage';
import { NextLoading } from '/@/utils/loading';
import { baseRoutes, notFoundAndNoPower, dynamicRoutes } from '/@/router/route';
import { formatTwoStageRoutes, formatFlatteningRoutes, router } from '/@/router/index';
import { useRoutesList } from '/@/stores/routesList';
import { useTagsViewRoutes } from '/@/stores/tagsViewRoutes';
import { useMenuApi } from '/@/api/admin/menu';
import { RouteRecordRaw } from "vue-router"
import pinia from "/@/stores/index"
import { useUserInfo } from "/@/stores/userInfo"
import { useRequestOldRoutes } from "/@/stores/requestOldRoutes"
import { Session } from "/@/utils/storage"
import { NextLoading } from "/@/utils/loading"
import { baseRoutes, notFoundAndNoPower, dynamicRoutes } from "/@/router/route"
import { formatTwoStageRoutes, formatFlatteningRoutes, router } from "/@/router/index"
import { useRoutesList } from "/@/stores/routesList"
import { useTagsViewRoutes } from "/@/stores/tagsViewRoutes"
import { useMenuApi } from "/@/api/admin/menu"
// 后端控制路由
// 引入 api 请求接口
const menuApi = useMenuApi();
const menuApi = useMenuApi()
/**
* 获取目录下的 .vue、.tsx 全部文件
* @method import.meta.glob
* @link 参考:https://cn.vitejs.dev/guide/features.html#json
*/
const layouModules: any = import.meta.glob('../layout/routerView/*.{vue,tsx}');
const viewsModules: any = import.meta.glob('../views/**/*.{vue,tsx}');
const dynamicViewsModules: Record<string, Function> = Object.assign({}, { ...layouModules }, { ...viewsModules });
const layouModules: any = import.meta.glob("../layout/routerView/*.{vue,tsx}")
const viewsModules: any = import.meta.glob("../views/**/*.{vue,tsx}")
const dynamicViewsModules: Record<string, Function> = Object.assign({}, { ...layouModules }, { ...viewsModules })
/**
* 后端控制路由:初始化方法,防止刷新时路由丢失
@@ -34,24 +34,24 @@ const dynamicViewsModules: Record<string, Function> = Object.assign({}, { ...lay
*/
export async function initBackEndControlRoutes() {
// 界面 loading 动画开始执行
if (window.nextLoading === undefined) NextLoading.start();
if (window.nextLoading === undefined) NextLoading.start()
// 无 token 停止执行下一步
if (!Session.getToken()) return false;
if (!Session.getToken()) return false
// 触发初始化用户信息 pinia
await useUserInfo().setUserInfos();
await useUserInfo().setUserInfos()
// 获取路由菜单数据
const res = await getBackEndControlRoutes();
const res = await getBackEndControlRoutes()
// 无登录权限时,添加判断
// https://gitee.com/lyt-top/vue-next-admin/issues/I64HVO
if ((res.data || []).length <= 0) return Promise.resolve(true);
if ((res.data || []).length <= 0) return Promise.resolve(true)
// 存储接口原始路由(未处理component),根据需求选择使用
useRequestOldRoutes().setRequestOldRoutes(JSON.parse(JSON.stringify(res.data)));
useRequestOldRoutes().setRequestOldRoutes(JSON.parse(JSON.stringify(res.data)))
// 处理路由(component),替换 baseRoutes(/@/router/route)第一个顶级 children 的路由
baseRoutes[0].children = [...dynamicRoutes, ...(await backEndComponent(res.data))];
baseRoutes[0].children = [...dynamicRoutes, ...(await backEndComponent(res.data))]
// 添加动态路由
await setAddRoute();
await setAddRoute()
// 设置路由到 pinia routesList 中(已处理成多级嵌套路由)及缓存多级嵌套数组处理后的一维数组
await setFilterMenuAndCacheTagsViewRoutes();
await setFilterMenuAndCacheTagsViewRoutes()
}
/**
@@ -60,9 +60,9 @@ export async function initBackEndControlRoutes() {
* @description 用于 tagsView、菜单搜索中:未过滤隐藏的(isHide)
*/
export async function setFilterMenuAndCacheTagsViewRoutes() {
const storesRoutesList = useRoutesList(pinia);
storesRoutesList.setRoutesList(baseRoutes[0].children as any);
setCacheTagsViewRoutes();
const storesRoutesList = useRoutesList(pinia)
storesRoutesList.setRoutesList(baseRoutes[0].children as any)
setCacheTagsViewRoutes()
}
/**
@@ -70,8 +70,8 @@ export async function setFilterMenuAndCacheTagsViewRoutes() {
* @description 用于 tagsView、菜单搜索中:未过滤隐藏的(isHide)
*/
export function setCacheTagsViewRoutes() {
const storesTagsView = useTagsViewRoutes(pinia);
storesTagsView.setTagsViewRoutes(formatTwoStageRoutes(formatFlatteningRoutes(baseRoutes))[0].children);
const storesTagsView = useTagsViewRoutes(pinia)
storesTagsView.setTagsViewRoutes(formatTwoStageRoutes(formatFlatteningRoutes(baseRoutes))[0].children)
}
/**
@@ -80,11 +80,11 @@ export function setCacheTagsViewRoutes() {
* @returns 返回替换后的路由数组
*/
export function setFilterRouteEnd() {
let filterRouteEnd: any = formatTwoStageRoutes(formatFlatteningRoutes(baseRoutes));
let filterRouteEnd: any = formatTwoStageRoutes(formatFlatteningRoutes(baseRoutes))
// notFoundAndNoPower 防止 404、401 不在 layout 布局中,不设置的话,404、401 界面将全屏显示
// 关联问题 No match found for location with path 'xxx'
filterRouteEnd[0].children = [...filterRouteEnd[0].children, ...notFoundAndNoPower];
return filterRouteEnd;
filterRouteEnd[0].children = [...filterRouteEnd[0].children, ...notFoundAndNoPower]
return filterRouteEnd
}
/**
@@ -95,8 +95,8 @@ export function setFilterRouteEnd() {
*/
export async function setAddRoute() {
await setFilterRouteEnd().forEach((route: RouteRecordRaw) => {
router.addRoute(route);
});
router.addRoute(route)
})
}
/**
@@ -105,7 +105,7 @@ export async function setAddRoute() {
* @returns 返回后端路由菜单数据
*/
export function getBackEndControlRoutes() {
return menuApi.getAdminMenu();
return menuApi.getAdminMenu()
}
/**
@@ -114,7 +114,7 @@ export function getBackEndControlRoutes() {
* @description 路径:/src/views/admin/menu/component/addMenu.vue
*/
export async function setBackEndControlRefreshRoutes() {
await getBackEndControlRoutes();
await getBackEndControlRoutes()
}
/**
@@ -123,26 +123,27 @@ export async function setBackEndControlRefreshRoutes() {
* @returns 返回处理成函数后的 component
*/
export function backEndComponent(routes: any) {
if (!routes) return;
if (!routes) return
return routes.map((item: any) => {
if (item.path && item.path.startsWith('http')) {
if (item.path && item.path.startsWith("http")) {
if (item.meta.isIframe) {
item.component = () => import('/@/layout/routerView/iframes.vue');
item.component = () => import("/@/layout/routerView/iframes.vue")
} else {
item.component = () => import('/@/layout/routerView/link.vue');
item.component = () => import("/@/layout/routerView/link.vue")
}
item.path = '/iframes/' + window.btoa(item.path);
} else if (item.componentPath) { // 支持动态路径 /a/1 ==> /a ; /b/1 ==> /b
item.component = dynamicImport(dynamicViewsModules, item.componentPath);
item.path = "/iframes/" + window.btoa(item.path)
} else if (item.componentPath) {
// 支持动态路径 /a/1 ==> /a ; /b/1 ==> /b
item.component = dynamicImport(dynamicViewsModules, item.componentPath)
} else {
item.component = dynamicImport(dynamicViewsModules, item.path);
item.component = dynamicImport(dynamicViewsModules, item.path)
}
item.children && backEndComponent(item.children);
item.children && backEndComponent(item.children)
if (item.children) {
item.redirect = item.children[0].path;
item.redirect = item.children[0].path
}
return item;
});
return item
})
}
/**
@@ -152,17 +153,17 @@ export function backEndComponent(routes: any) {
* @returns 返回处理成函数后的 component
*/
export function dynamicImport(dynamicViewsModules: Record<string, Function>, component: string) {
const keys = Object.keys(dynamicViewsModules);
const keys = Object.keys(dynamicViewsModules)
const matchKeys = keys.filter((key) => {
const k = key.replace(/..\/views|../, '');
return k.startsWith(`${component}.vue`);
});
const k = key.replace(/..\/views|../, "")
return k.startsWith(`${component}.vue`)
})
if (matchKeys?.length === 1) {
const matchKey = matchKeys[0];
return dynamicViewsModules[matchKey];
const matchKey = matchKeys[0]
return dynamicViewsModules[matchKey]
}
if (matchKeys?.length > 1) {
return false;
return false
}
}