Skip to content

Commit b67cf22

Browse files
committed
feat(route): add hideChildrenInMenu option close #346
1 parent f55ad2f commit b67cf22

File tree

11 files changed

+43
-70
lines changed

11 files changed

+43
-70
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,15 @@
118118
"vite-plugin-style-import": "^0.8.1",
119119
"vite-plugin-svg-icons": "^0.3.5",
120120
"vite-plugin-theme": "^0.5.0",
121-
"vite-plugin-windicss": "0.9.1",
121+
"vite-plugin-windicss": "0.9.2",
122122
"vue-eslint-parser": "^7.6.0",
123123
"yargs": "^16.2.0"
124124
},
125125
"resolutions": {
126126
"//": "Used to install imagemin dependencies, because imagemin may not be installed in China.If it is abroad, you can delete it",
127127
"bin-wrapper": "npm:bin-wrapper-china",
128-
"rollup": "2.41.4"
128+
"rollup": "2.41.5",
129+
"vite": "2.0.5"
129130
},
130131
"repository": {
131132
"type": "git",

src/components/Authority/src/index.vue

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
-->
44
<script lang="ts">
55
import type { PropType } from 'vue';
6-
import { defineComponent, unref } from 'vue';
6+
import { defineComponent } from 'vue';
77
8-
import { PermissionModeEnum } from '/@/enums/appEnum';
98
import { RoleEnum } from '/@/enums/roleEnum';
109
11-
import { useRootSetting } from '/@/hooks/setting/useRootSetting';
1210
import { usePermission } from '/@/hooks/web/usePermission';
1311
1412
import { getSlot } from '/@/utils/helper/tsxHelper';
@@ -28,23 +26,12 @@
2826
},
2927
},
3028
setup(props, { slots }) {
31-
const { getPermissionMode } = useRootSetting();
3229
const { hasPermission } = usePermission();
3330
3431
/**
3532
* Render role button
3633
*/
37-
function renderRoleAuth() {
38-
const { value } = props;
39-
if (!value) {
40-
return getSlot(slots);
41-
}
42-
return hasPermission(value) ? getSlot(slots) : null;
43-
}
44-
45-
// Render coding button
46-
// Here only judge whether it is included, the specific implementation can be written according to the project logic
47-
function renderCodeAuth() {
34+
function renderAuth() {
4835
const { value } = props;
4936
if (!value) {
5037
return getSlot(slots);
@@ -53,18 +40,8 @@
5340
}
5441
5542
return () => {
56-
const mode = unref(getPermissionMode);
5743
// Role-based value control
58-
if (mode === PermissionModeEnum.ROLE) {
59-
return renderRoleAuth();
60-
}
61-
62-
// Based on background role permission control
63-
if (mode === PermissionModeEnum.BACK) {
64-
return renderCodeAuth();
65-
}
66-
67-
return getSlot(slots);
44+
return renderAuth();
6845
};
6946
},
7047
});

src/components/CountDown/src/CountdownInput.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
1919
export default defineComponent({
2020
name: 'CountDownInput',
21-
inheritAttrs: false,
2221
components: { [Input.name]: Input, CountButton },
22+
inheritAttrs: false,
2323
props: {
2424
value: propTypes.string,
2525
size: propTypes.oneOf(['default', 'large', 'small']),

src/components/Form/src/components/ApiSelect.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
3131
export default defineComponent({
3232
name: 'ApiSelect',
33-
inheritAttrs: false,
3433
components: {
3534
Select,
3635
LoadingOutlined,
3736
},
37+
inheritAttrs: false,
3838
props: {
3939
value: propTypes.string,
4040
numberToString: propTypes.bool,

src/components/Table/src/components/settings/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div class="table-settings">
3-
<RedoSetting v-if="getSetting.size" />
4-
<SizeSetting v-if="getSetting.redo" />
3+
<RedoSetting v-if="getSetting.redo" />
4+
<SizeSetting v-if="getSetting.size" />
55
<ColumnSetting v-if="getSetting.setting" />
66
<FullScreenSetting v-if="getSetting.fullScreen" />
77
</div>

src/layouts/default/header/components/Breadcrumb.vue

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
watchEffect(async () => {
5555
if (currentRoute.value.name === REDIRECT_NAME) return;
5656
const menus = await getMenus();
57+
5758
const routeMatched = currentRoute.value.matched;
5859
const cur = routeMatched?.[routeMatched.length - 1];
5960
let path = currentRoute.value.path;
@@ -63,26 +64,20 @@
6364
}
6465
6566
const parent = getAllParentPath(menus, path);
66-
6767
const filterMenus = menus.filter((item) => item.path === parent[0]);
68-
6968
const matched = getMatched(filterMenus, parent) as any;
7069
7170
if (!matched || matched.length === 0) return;
7271
73-
let breadcrumbList = filterItem(matched);
74-
75-
const filterBreadcrumbList = breadcrumbList.filter(
76-
(item) => item.path !== PageEnum.BASE_HOME
77-
);
72+
const breadcrumbList = filterItem(matched);
7873
7974
if (currentRoute.value.meta?.currentActiveMenu) {
80-
filterBreadcrumbList.push(({
75+
breadcrumbList.push(({
8176
...currentRoute.value,
8277
name: currentRoute.value.meta?.title || currentRoute.value.name,
8378
} as unknown) as RouteLocationMatched);
8479
}
85-
routes.value = filterBreadcrumbList;
80+
routes.value = breadcrumbList;
8681
});
8782
8883
function getMatched(menus: Menu[], parent: string[]) {
@@ -103,12 +98,10 @@
10398
10499
function filterItem(list: RouteLocationMatched[]) {
105100
let resultList = filter(list, (item) => {
106-
const { meta } = item;
107-
101+
const { meta, name } = item;
108102
if (!meta) {
109-
return false;
103+
return !!name;
110104
}
111-
112105
const { title, hideBreadcrumb, hideMenu } = meta;
113106
if (!title || hideBreadcrumb || hideMenu) {
114107
return false;

src/router/helper/menuHelper.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ export function getAllParentPath<T = Recordable>(treeData: T[], path: string) {
1313
function joinParentPath(menus: Menu[], parentPath = '') {
1414
for (let index = 0; index < menus.length; index++) {
1515
const menu = menus[index];
16-
const p = menu.path.startsWith('/') ? menu.path : `/${menu.path}`;
17-
const parent = isUrl(menu.path) ? menu.path : `${parentPath}${p}`;
18-
menus[index].path = parent;
16+
// https://next.router.vuejs.org/guide/essentials/nested-routes.html
17+
// Note that nested paths that start with / will be treated as a root path.
18+
// This allows you to leverage the component nesting without having to use a nested URL.
19+
if (!(menu.path.startsWith('/') || isUrl(menu.path))) {
20+
// path doesn't start with /, nor is it a url, join parent path
21+
menu.path = `${parentPath}/${menu.path}`;
22+
}
1923
if (menu?.children?.length) {
20-
joinParentPath(menu.children, parent);
24+
joinParentPath(menu.children, menu.path);
2125
}
2226
}
2327
}

src/router/menus/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ export async function getShallowMenus(): Promise<Menu[]> {
6666

6767
// Get the children of the menu
6868
export async function getChildrenMenus(parentPath: string) {
69-
const menus = await getAsyncMenus();
69+
const menus = await getMenus();
7070
const parent = menus.find((item) => item.path === parentPath);
71-
if (!parent || !parent.children) return [] as Menu[];
71+
if (!parent || !parent.children || !!parent?.meta?.hideChildrenInMenu) return [] as Menu[];
7272
const routes = router.getRoutes();
7373

7474
return !isBackMode() ? filter(parent.children, basicFilter(routes)) : parent.children;

src/router/routes/modules/dashboard.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const dashboard: AppRouteModule = {
1111
meta: {
1212
icon: 'ion:grid-outline',
1313
title: t('routes.dashboard.dashboard'),
14-
hideChildrenInMenu: true,
1514
},
1615
children: [
1716
{

vite.config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
1818
// The boolean type read by loadEnv is a string. This function can be converted to boolean type
1919
const viteEnv = wrapperEnv(env);
2020

21-
const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY, VITE_DROP_CONSOLE, VITE_LEGACY } = viteEnv;
21+
const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY, VITE_DROP_CONSOLE } = viteEnv;
2222

2323
const isBuild = command === 'build';
2424

@@ -45,7 +45,6 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
4545
build: {
4646
// minify: 'esbuild',
4747
outDir: OUTPUT_DIR,
48-
polyfillDynamicImport: VITE_LEGACY,
4948
terserOptions: {
5049
compress: {
5150
keep_infinity: true,

0 commit comments

Comments
 (0)