mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-08-27 14:31:41 +08:00
perf: optimize settingDrawer code
This commit is contained in:
@@ -89,7 +89,6 @@ export type ComponentType =
|
||||
| 'InputNumber'
|
||||
| 'InputCountDown'
|
||||
| 'Select'
|
||||
| 'DictSelect'
|
||||
| 'SelectOptGroup'
|
||||
| 'SelectOption'
|
||||
| 'TreeSelect'
|
||||
|
@@ -52,7 +52,8 @@ export default defineComponent({
|
||||
toRef(props, 'items'),
|
||||
toRef(props, 'flatItems'),
|
||||
toRef(props, 'isAppMenu'),
|
||||
toRef(props, 'mode')
|
||||
toRef(props, 'mode'),
|
||||
toRef(props, 'accordion')
|
||||
);
|
||||
|
||||
const getOpenKeys = computed(() => {
|
||||
|
@@ -58,6 +58,10 @@ export const basicProps = {
|
||||
type: Boolean as PropType<boolean>,
|
||||
default: false,
|
||||
},
|
||||
accordion: {
|
||||
type: Boolean as PropType<boolean>,
|
||||
default: true,
|
||||
},
|
||||
beforeClickFn: {
|
||||
type: Function as PropType<Fn>,
|
||||
default: null,
|
||||
|
@@ -6,21 +6,31 @@ import type { Ref } from 'vue';
|
||||
import { unref } from 'vue';
|
||||
import { menuStore } from '/@/store/modules/menu';
|
||||
import { getAllParentPath } from '/@/utils/helper/menuHelper';
|
||||
import { es6Unique } from '/@/utils';
|
||||
|
||||
export function useOpenKeys(
|
||||
menuState: MenuState,
|
||||
menus: Ref<MenuType[]>,
|
||||
flatMenusRef: Ref<MenuType[]>,
|
||||
isAppMenu: Ref<boolean>,
|
||||
mode: Ref<MenuModeEnum>
|
||||
mode: Ref<MenuModeEnum>,
|
||||
accordion: Ref<boolean>
|
||||
) {
|
||||
/**
|
||||
* @description:设置展开
|
||||
*/
|
||||
function setOpenKeys(menu: MenuType) {
|
||||
const flatMenus = unref(flatMenusRef);
|
||||
menuState.openKeys = getAllParentPath(flatMenus, menu.path);
|
||||
if (!unref(accordion)) {
|
||||
menuState.openKeys = es6Unique([
|
||||
...menuState.openKeys,
|
||||
...getAllParentPath(flatMenus, menu.path),
|
||||
]);
|
||||
} else {
|
||||
menuState.openKeys = getAllParentPath(flatMenus, menu.path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 重置值
|
||||
*/
|
||||
@@ -30,7 +40,7 @@ export function useOpenKeys(
|
||||
}
|
||||
|
||||
function handleOpenChange(openKeys: string[]) {
|
||||
if (unref(mode) === MenuModeEnum.HORIZONTAL) {
|
||||
if (unref(mode) === MenuModeEnum.HORIZONTAL || !unref(accordion)) {
|
||||
menuState.openKeys = openKeys;
|
||||
} else {
|
||||
const rootSubMenuKeys: string[] = [];
|
||||
|
Reference in New Issue
Block a user