@gx-design-vue/pro-layout 0.1.0-alpha.2 → 0.1.0-alpha.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ProLayout.d.ts +4 -536
- package/dist/ProLayout.js +489 -358
- package/dist/components/AppPage/context.d.ts +4 -3
- package/dist/components/AppPage/context.js +3 -5
- package/dist/components/AppPage/index.d.ts +29 -52
- package/dist/components/AppPage/index.js +71 -54
- package/dist/components/AppPage/style.d.ts +8 -7
- package/dist/components/AppPage/style.js +16 -17
- package/dist/components/Breadcrumb/index.d.ts +19 -0
- package/dist/components/Breadcrumb/index.js +129 -0
- package/dist/components/Breadcrumb/interface.d.ts +33 -0
- package/dist/components/Breadcrumb/interface.js +1 -0
- package/dist/components/CollapseButton/Arrow.d.ts +4 -0
- package/dist/components/{SiderMenu → CollapseButton}/Arrow.js +2 -4
- package/dist/components/CollapseButton/index.d.ts +7 -0
- package/dist/components/CollapseButton/index.js +45 -0
- package/dist/components/CollapseButton/interface.d.ts +19 -0
- package/dist/components/CollapseButton/interface.js +1 -0
- package/dist/components/Footer/index.d.ts +10 -0
- package/dist/components/Footer/index.js +69 -0
- package/dist/components/Footer/interface.d.ts +22 -0
- package/dist/components/Footer/interface.js +1 -0
- package/dist/components/FooterToolbar/index.d.ts +5 -72
- package/dist/components/FooterToolbar/index.js +77 -90
- package/dist/components/FooterToolbar/style.d.ts +10 -0
- package/dist/components/FooterToolbar/style.js +34 -0
- package/dist/components/Header/index.d.ts +7 -0
- package/dist/components/Header/index.js +140 -0
- package/dist/components/Header/interface.d.ts +41 -0
- package/dist/components/Header/interface.js +1 -0
- package/dist/components/Logo/index.d.ts +9 -0
- package/dist/components/Logo/index.js +63 -0
- package/dist/components/Logo/interface.d.ts +13 -0
- package/dist/components/Logo/interface.js +1 -0
- package/dist/components/Menu/iconRender.d.ts +10 -0
- package/dist/components/Menu/iconRender.js +23 -0
- package/dist/components/Menu/index.d.ts +13 -0
- package/dist/components/Menu/index.js +778 -0
- package/dist/components/Menu/interface.d.ts +50 -0
- package/dist/components/Menu/interface.js +9 -0
- package/dist/components/Menu/overflow.d.ts +39 -0
- package/dist/components/Menu/overflow.js +81 -0
- package/dist/components/Menu/style/base.d.ts +12 -0
- package/dist/components/Menu/style/base.js +36 -0
- package/dist/components/Menu/style/horizontal.d.ts +19 -0
- package/dist/components/Menu/style/horizontal.js +303 -0
- package/dist/components/Menu/style/index.d.ts +356 -0
- package/dist/components/Menu/style/index.js +147 -0
- package/dist/components/Menu/style/inline.d.ts +13 -0
- package/dist/components/Menu/style/inline.js +292 -0
- package/dist/components/PageContainer/PageHeader.d.ts +30 -36
- package/dist/components/PageContainer/PageHeader.js +80 -46
- package/dist/components/PageContainer/index.d.ts +8 -194
- package/dist/components/PageContainer/index.js +297 -209
- package/dist/components/PageContainer/style.d.ts +5 -0
- package/dist/components/PageContainer/style.js +142 -0
- package/dist/components/PageTransition/animate.d.ts +41 -0
- package/dist/components/PageTransition/animate.js +106 -0
- package/dist/components/PageTransition/index.d.ts +57 -0
- package/dist/components/PageTransition/index.js +66 -0
- package/dist/components/{PageTranstion → PageTransition}/keyFrame/back.d.ts +4 -4
- package/dist/components/{PageTranstion → PageTransition}/keyFrame/back.js +2 -4
- package/dist/components/{PageTranstion → PageTransition}/keyFrame/bounce.d.ts +4 -4
- package/dist/components/{PageTranstion → PageTransition}/keyFrame/bounce.js +2 -4
- package/dist/components/{PageTranstion → PageTransition}/keyFrame/fade.d.ts +4 -4
- package/dist/components/{PageTranstion → PageTransition}/keyFrame/fade.js +2 -4
- package/dist/components/{PageTranstion → PageTransition}/keyFrame/flip.d.ts +4 -4
- package/dist/components/{PageTranstion → PageTransition}/keyFrame/flip.js +2 -4
- package/dist/components/{PageTranstion → PageTransition}/keyFrame/lightSpeed.d.ts +4 -4
- package/dist/components/{PageTranstion → PageTransition}/keyFrame/lightSpeed.js +2 -4
- package/dist/components/PageTransition/keyFrame/roll.d.ts +10 -0
- package/dist/components/{PageTranstion → PageTransition}/keyFrame/roll.js +2 -4
- package/dist/components/{PageTranstion → PageTransition}/keyFrame/rotate.d.ts +4 -4
- package/dist/components/{PageTranstion → PageTransition}/keyFrame/rotate.js +2 -4
- package/dist/components/{PageTranstion → PageTransition}/keyFrame/slide.d.ts +4 -4
- package/dist/components/{PageTranstion → PageTransition}/keyFrame/slide.js +2 -4
- package/dist/components/{PageTranstion → PageTransition}/keyFrame/zoom.d.ts +4 -4
- package/dist/components/{PageTranstion → PageTransition}/keyFrame/zoom.js +2 -4
- package/dist/components/PageTransition/style.d.ts +11 -0
- package/dist/components/{PageTranstion → PageTransition}/style.js +9 -13
- package/dist/components/Sider/index.d.ts +7 -0
- package/dist/components/Sider/index.js +206 -0
- package/dist/components/Sider/interface.d.ts +39 -0
- package/dist/components/Sider/interface.js +1 -0
- package/dist/components/Tabs/InnerTabs.d.ts +7 -0
- package/dist/components/Tabs/InnerTabs.js +117 -0
- package/dist/components/Tabs/contextMenu.d.ts +41 -0
- package/dist/components/Tabs/contextMenu.js +89 -0
- package/dist/components/Tabs/hooks/flipAnimate.d.ts +24 -0
- package/dist/components/Tabs/hooks/flipAnimate.js +40 -0
- package/dist/components/Tabs/hooks/useAutoScroll.d.ts +27 -0
- package/dist/components/Tabs/hooks/useAutoScroll.js +122 -0
- package/dist/components/Tabs/hooks/useTabDrag.d.ts +31 -0
- package/dist/components/Tabs/hooks/useTabDrag.js +252 -0
- package/dist/components/Tabs/index.d.ts +13 -0
- package/dist/components/Tabs/index.js +181 -0
- package/dist/components/Tabs/interface.d.ts +74 -0
- package/dist/components/Tabs/interface.js +1 -0
- package/dist/components/Tabs/style/index.d.ts +35 -0
- package/dist/components/Tabs/style/index.js +161 -0
- package/dist/components/WrapContent/index.d.ts +9 -0
- package/dist/components/WrapContent/index.js +26 -0
- package/dist/components/WrapContent/interface.d.ts +15 -0
- package/dist/components/WrapContent/interface.js +1 -0
- package/dist/context/index.d.ts +53 -0
- package/dist/context/index.js +5 -0
- package/dist/defaultConfig.d.ts +10 -0
- package/dist/defaultConfig.js +38 -0
- package/dist/hooks/useLayoutBase.d.ts +78 -0
- package/dist/hooks/useLayoutBase.js +86 -0
- package/dist/hooks/useMenu.d.ts +77 -0
- package/dist/hooks/useMenu.js +166 -0
- package/dist/hooks/useTabs.d.ts +54 -0
- package/dist/hooks/useTabs.js +388 -0
- package/dist/index.d.ts +22 -27
- package/dist/index.js +15 -24
- package/dist/interface.d.ts +516 -0
- package/dist/interface.js +34 -0
- package/dist/pro-layout.esm.js +5848 -5075
- package/dist/pro-layout.js +16 -37
- package/dist/style/breadcrumb.d.ts +8 -0
- package/dist/style/breadcrumb.js +77 -0
- package/dist/style/collapseButton.d.ts +8 -0
- package/dist/style/collapseButton.js +57 -0
- package/dist/style/content.d.ts +8 -0
- package/dist/style/content.js +29 -0
- package/dist/style/footer.d.ts +8 -0
- package/dist/style/footer.js +33 -0
- package/dist/style/header.d.ts +8 -0
- package/dist/style/header.js +76 -0
- package/dist/style/index.d.ts +3 -22
- package/dist/style/index.js +51 -55
- package/dist/style/logo.d.ts +8 -0
- package/dist/style/logo.js +76 -0
- package/dist/style/menu.d.ts +15 -0
- package/dist/style/menu.js +49 -0
- package/dist/style/rightContent.d.ts +12 -0
- package/dist/style/rightContent.js +74 -0
- package/dist/style/search.d.ts +12 -0
- package/dist/style/search.js +94 -0
- package/dist/style/sider.d.ts +8 -0
- package/dist/style/sider.js +92 -0
- package/dist/style/tabs.d.ts +14 -0
- package/dist/style/tabs.js +97 -0
- package/dist/theme/augment.d.ts +20 -0
- package/dist/theme/augment.js +1 -0
- package/dist/theme/interface/components.d.ts +20 -0
- package/dist/theme/interface/components.js +1 -0
- package/dist/utils/config.d.ts +12 -0
- package/dist/utils/config.js +18 -0
- package/dist/utils/menu.d.ts +111 -20
- package/dist/utils/menu.js +263 -118
- package/dist/utils/style.d.ts +4 -0
- package/dist/utils/style.js +21 -0
- package/dist/utils/themeComponents.d.ts +28 -0
- package/dist/utils/themeComponents.js +89 -0
- package/package.json +24 -15
- package/dist/Context/expose.d.ts +0 -6
- package/dist/Context/expose.js +0 -7
- package/dist/Context/index.d.ts +0 -43
- package/dist/Context/index.js +0 -18
- package/dist/WrapContent.d.ts +0 -100
- package/dist/WrapContent.js +0 -45
- package/dist/components/BaseMenu/index.d.ts +0 -255
- package/dist/components/BaseMenu/index.js +0 -381
- package/dist/components/BaseMenu/props.d.ts +0 -105
- package/dist/components/BaseMenu/props.js +0 -94
- package/dist/components/BaseMenu/style.d.ts +0 -6
- package/dist/components/BaseMenu/style.js +0 -155
- package/dist/components/BreadCrumb/Breadcrumb.d.ts +0 -33
- package/dist/components/BreadCrumb/Breadcrumb.js +0 -75
- package/dist/components/BreadCrumb/index.d.ts +0 -7
- package/dist/components/BreadCrumb/index.js +0 -44
- package/dist/components/BreadCrumb/style.d.ts +0 -8
- package/dist/components/BreadCrumb/style.js +0 -87
- package/dist/components/CollapsedIcon/index.d.ts +0 -33
- package/dist/components/CollapsedIcon/index.js +0 -51
- package/dist/components/CollapsedIcon/style.d.ts +0 -9
- package/dist/components/CollapsedIcon/style.js +0 -34
- package/dist/components/FooterToolbar/props.d.ts +0 -47
- package/dist/components/FooterToolbar/props.js +0 -33
- package/dist/components/FooterToolbar/style/index.d.ts +0 -14
- package/dist/components/FooterToolbar/style/index.js +0 -48
- package/dist/components/FooterToolbar/style/stylish.d.ts +0 -18
- package/dist/components/FooterToolbar/style/stylish.js +0 -16
- package/dist/components/GlobalFooter/index.d.ts +0 -73
- package/dist/components/GlobalFooter/index.js +0 -77
- package/dist/components/GlobalFooter/style.d.ts +0 -6
- package/dist/components/GlobalFooter/style.js +0 -29
- package/dist/components/GlobalHeader/DefaultHeader.d.ts +0 -164
- package/dist/components/GlobalHeader/DefaultHeader.js +0 -149
- package/dist/components/GlobalHeader/index.d.ts +0 -164
- package/dist/components/GlobalHeader/index.js +0 -78
- package/dist/components/GlobalHeader/props.d.ts +0 -70
- package/dist/components/GlobalHeader/props.js +0 -56
- package/dist/components/GlobalHeader/style/defaultHeader.d.ts +0 -6
- package/dist/components/GlobalHeader/style/defaultHeader.js +0 -108
- package/dist/components/GlobalHeader/style/header.d.ts +0 -6
- package/dist/components/GlobalHeader/style/header.js +0 -41
- package/dist/components/LogoContent/index.d.ts +0 -80
- package/dist/components/LogoContent/index.js +0 -90
- package/dist/components/LogoContent/props.d.ts +0 -57
- package/dist/components/LogoContent/props.js +0 -37
- package/dist/components/LogoContent/style.d.ts +0 -6
- package/dist/components/LogoContent/style.js +0 -63
- package/dist/components/PageContainer/props.d.ts +0 -138
- package/dist/components/PageContainer/props.js +0 -103
- package/dist/components/PageContainer/style/index.d.ts +0 -14
- package/dist/components/PageContainer/style/index.js +0 -52
- package/dist/components/PageContainer/style/pageHeader.d.ts +0 -6
- package/dist/components/PageContainer/style/pageHeader.js +0 -44
- package/dist/components/PageTranstion/index.d.ts +0 -40
- package/dist/components/PageTranstion/index.js +0 -71
- package/dist/components/PageTranstion/keyFrame/roll.d.ts +0 -10
- package/dist/components/PageTranstion/style.d.ts +0 -10
- package/dist/components/SiderMenu/Arrow.d.ts +0 -6
- package/dist/components/SiderMenu/SiderMenu.d.ts +0 -180
- package/dist/components/SiderMenu/SiderMenu.js +0 -265
- package/dist/components/SiderMenu/index.d.ts +0 -193
- package/dist/components/SiderMenu/index.js +0 -51
- package/dist/components/SiderMenu/props.d.ts +0 -77
- package/dist/components/SiderMenu/props.js +0 -67
- package/dist/components/SiderMenu/style/index.d.ts +0 -12
- package/dist/components/SiderMenu/style/index.js +0 -162
- package/dist/components/SiderMenu/typings.d.ts +0 -38
- package/dist/components/SiderMenu/typings.js +0 -1
- package/dist/components/TabsRoute/index.d.ts +0 -95
- package/dist/components/TabsRoute/index.js +0 -405
- package/dist/components/TabsRoute/props.d.ts +0 -78
- package/dist/components/TabsRoute/props.js +0 -47
- package/dist/components/TabsRoute/style.d.ts +0 -15
- package/dist/components/TabsRoute/style.js +0 -133
- package/dist/components/TabsRoute/utils/config.d.ts +0 -18
- package/dist/components/TabsRoute/utils/config.js +0 -64
- package/dist/config/animate.d.ts +0 -11
- package/dist/config/animate.js +0 -76
- package/dist/config/index.d.ts +0 -34
- package/dist/config/index.js +0 -30
- package/dist/hooks/collapsed/index.d.ts +0 -15
- package/dist/hooks/collapsed/index.js +0 -50
- package/dist/hooks/layout/useLayoutExpose.d.ts +0 -15
- package/dist/hooks/layout/useLayoutExpose.js +0 -22
- package/dist/hooks/layout/usePageContent.d.ts +0 -6
- package/dist/hooks/layout/usePageContent.js +0 -28
- package/dist/hooks/menu/context.d.ts +0 -21
- package/dist/hooks/menu/context.js +0 -7
- package/dist/hooks/menu/index.d.ts +0 -29
- package/dist/hooks/menu/index.js +0 -118
- package/dist/hooks/theme/index.d.ts +0 -11
- package/dist/hooks/theme/index.js +0 -13
- package/dist/props/collapsedProps.d.ts +0 -39
- package/dist/props/collapsedProps.js +0 -45
- package/dist/props/defaultSettings.d.ts +0 -62
- package/dist/props/defaultSettings.js +0 -56
- package/dist/props/index.d.ts +0 -226
- package/dist/props/index.js +0 -109
- package/dist/props/themeProps.d.ts +0 -14
- package/dist/props/themeProps.js +0 -10
- package/dist/types/Breadcrumb.d.ts +0 -22
- package/dist/types/Breadcrumb.js +0 -1
- package/dist/types/MenuTypings.d.ts +0 -46
- package/dist/types/MenuTypings.js +0 -1
- package/dist/types/RouteTypings.d.ts +0 -96
- package/dist/types/RouteTypings.js +0 -1
- package/dist/types/SlotsTypings.d.ts +0 -124
- package/dist/types/SlotsTypings.js +0 -32
- package/dist/types/typings.d.ts +0 -73
- package/dist/types/typings.js +0 -3
- package/dist/utils/index.d.ts +0 -7
- package/dist/utils/index.js +0 -17
- package/dist/utils/style/index.d.ts +0 -44
- package/dist/utils/style/index.js +0 -103
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { buildBreadcrumbRoutes, buildMenuLookup, collectMenuNames, insertMenuAtPath, normalizeMenus, removeMenuAtPath, resolveMatchedChain, resolveRouteTarget, routesToMenus, selectMenuBranch, toBreadcrumbItems, updateMenuAtPath, updateMenuMetaAtPath } from "../utils/menu.js";
|
|
2
|
+
import { computed, onScopeDispose, shallowRef, toValue, watch } from "vue";
|
|
3
|
+
import { useRoute, useRouter } from "vue-router";
|
|
4
|
+
//#region src/hooks/useMenu.ts
|
|
5
|
+
/**
|
|
6
|
+
* 菜单组合式:以 shallowRef 菜单树为总状态,派生选中 / 展开 / 面包屑 / 查找索引。
|
|
7
|
+
*
|
|
8
|
+
* 关键响应式(根治旧实现卡顿 / 内存问题):
|
|
9
|
+
* - `menus` / `selectedKeys` / `openKeys` 均为 shallowRef,可由 context 主动控制;
|
|
10
|
+
* - `lookup` 内携带 path,深层菜单更新走 O(1) 查找 + O(depth) 局部克隆;
|
|
11
|
+
* - 派生索引仅在 `menus` 根引用变化时重建,无 deep watch、无全量 cloneDeep。
|
|
12
|
+
*/
|
|
13
|
+
function useMenu(options) {
|
|
14
|
+
const router = useRouter();
|
|
15
|
+
const route = useRoute();
|
|
16
|
+
const currentName = computed(() => options.currentName?.() ?? route.name);
|
|
17
|
+
const sourceMenus = computed(() => toValue(options.menus) ?? routesToMenus(router.getRoutes()));
|
|
18
|
+
const menus = shallowRef(normalizeMenus(sourceMenus.value));
|
|
19
|
+
const selectedKeys = shallowRef([...toValue(options.selectedKeys) ?? []]);
|
|
20
|
+
const openKeys = shallowRef([...toValue(options.openKeys) ?? []]);
|
|
21
|
+
const menuModel = computed(() => {
|
|
22
|
+
const { flatMenus, lookup } = buildMenuLookup(menus.value);
|
|
23
|
+
return {
|
|
24
|
+
menus: menus.value,
|
|
25
|
+
flatMenus,
|
|
26
|
+
lookup
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
const flatMenus = computed(() => menuModel.value.flatMenus);
|
|
30
|
+
const lookup = computed(() => menuModel.value.lookup);
|
|
31
|
+
const matchedChain = computed(() => resolveMatchedChain(lookup.value, currentName.value));
|
|
32
|
+
const activeChainKey = computed(() => matchedChain.value.map((item) => item.name).join("\0"));
|
|
33
|
+
const currentMeta = computed(() => lookup.value.get(currentName.value ?? "")?.route.meta ?? {});
|
|
34
|
+
const breadcrumbRoutes = computed(() => buildBreadcrumbRoutes(matchedChain.value, { current: lookup.value.get(currentName.value ?? "")?.route }));
|
|
35
|
+
const breadcrumbItems = computed(() => toBreadcrumbItems(breadcrumbRoutes.value));
|
|
36
|
+
const splitActive = computed(() => toValue(options.layout) === "mix" && !toValue(options.isMobile));
|
|
37
|
+
const topName = computed(() => matchedChain.value[0]?.name);
|
|
38
|
+
const headerMenus = computed(() => splitActive.value ? menus.value.map((menu) => ({
|
|
39
|
+
...menu,
|
|
40
|
+
children: void 0
|
|
41
|
+
})) : menus.value);
|
|
42
|
+
const siderMenus = computed(() => splitActive.value ? selectMenuBranch(menus.value, topName.value) : menus.value);
|
|
43
|
+
function commitMenus(nextMenus, options) {
|
|
44
|
+
menus.value = options?.normalize === false ? nextMenus : normalizeMenus(nextMenus);
|
|
45
|
+
pruneKeys();
|
|
46
|
+
}
|
|
47
|
+
function pruneKeys() {
|
|
48
|
+
const validNames = lookup.value;
|
|
49
|
+
selectedKeys.value = selectedKeys.value.filter((name) => validNames.has(name));
|
|
50
|
+
openKeys.value = openKeys.value.filter((name) => validNames.has(name));
|
|
51
|
+
}
|
|
52
|
+
function syncSelectedKeys() {
|
|
53
|
+
if (toValue(options.selectedKeys) !== void 0) return;
|
|
54
|
+
selectedKeys.value = matchedChain.value.map((item) => item.name);
|
|
55
|
+
}
|
|
56
|
+
function syncOpenKeys() {
|
|
57
|
+
if (toValue(options.openKeys) !== void 0) return;
|
|
58
|
+
const activeParents = matchedChain.value.map((item) => item.name).filter((name) => name !== currentName.value);
|
|
59
|
+
openKeys.value = toValue(options.config).autoClose ? activeParents : Array.from(/* @__PURE__ */ new Set([...openKeys.value, ...activeParents]));
|
|
60
|
+
}
|
|
61
|
+
function getMenuPath(name) {
|
|
62
|
+
return lookup.value.get(name)?.path;
|
|
63
|
+
}
|
|
64
|
+
function setMenus(nextMenus) {
|
|
65
|
+
commitMenus(nextMenus);
|
|
66
|
+
}
|
|
67
|
+
function refreshMenus() {
|
|
68
|
+
commitMenus([...menus.value]);
|
|
69
|
+
}
|
|
70
|
+
function batchMenus(updater, options) {
|
|
71
|
+
const nextMenus = updater(menus.value);
|
|
72
|
+
commitMenus(nextMenus === menus.value ? [...nextMenus] : nextMenus, options);
|
|
73
|
+
}
|
|
74
|
+
function addMenu(menu, parentName, index) {
|
|
75
|
+
const parentPath = parentName ? getMenuPath(parentName) : void 0;
|
|
76
|
+
if (parentName && !parentPath) return;
|
|
77
|
+
commitMenus(insertMenuAtPath(menus.value, parentPath, menu, index));
|
|
78
|
+
}
|
|
79
|
+
function updateMenu(name, updater, options) {
|
|
80
|
+
const path = getMenuPath(name);
|
|
81
|
+
if (!path) return;
|
|
82
|
+
commitMenus(updateMenuAtPath(menus.value, path, updater), options);
|
|
83
|
+
}
|
|
84
|
+
function setMenuMeta(name, updater, options) {
|
|
85
|
+
const entry = lookup.value.get(name);
|
|
86
|
+
if (!entry) return;
|
|
87
|
+
const currentMeta = entry.route.meta ?? {};
|
|
88
|
+
const nextMeta = typeof updater === "function" ? updater(currentMeta) : {
|
|
89
|
+
...currentMeta,
|
|
90
|
+
...updater
|
|
91
|
+
};
|
|
92
|
+
const shouldNormalize = options?.normalize ?? (currentMeta.order !== nextMeta.order || currentMeta.hideInMenu !== nextMeta.hideInMenu || currentMeta.hideChildrenInMenu !== nextMeta.hideChildrenInMenu);
|
|
93
|
+
commitMenus(updateMenuMetaAtPath(menus.value, entry.path, nextMeta), { normalize: shouldNormalize });
|
|
94
|
+
}
|
|
95
|
+
function showMenu(name) {
|
|
96
|
+
setMenuMeta(name, { hideInMenu: false }, { normalize: true });
|
|
97
|
+
}
|
|
98
|
+
function hideMenu(name) {
|
|
99
|
+
setMenuMeta(name, { hideInMenu: true }, { normalize: true });
|
|
100
|
+
}
|
|
101
|
+
function removeMenu(name) {
|
|
102
|
+
const entry = lookup.value.get(name);
|
|
103
|
+
if (!entry) return;
|
|
104
|
+
const removedNames = new Set(collectMenuNames(entry.route));
|
|
105
|
+
commitMenus(removeMenuAtPath(menus.value, entry.path), { normalize: false });
|
|
106
|
+
selectedKeys.value = selectedKeys.value.filter((key) => !removedNames.has(key));
|
|
107
|
+
openKeys.value = openKeys.value.filter((key) => !removedNames.has(key));
|
|
108
|
+
}
|
|
109
|
+
const stopSource = watch(sourceMenus, (nextMenus) => commitMenus(nextMenus), { flush: "sync" });
|
|
110
|
+
const stopControlledSelectedKeys = watch(() => toValue(options.selectedKeys), (nextKeys) => {
|
|
111
|
+
if (nextKeys !== void 0) {
|
|
112
|
+
selectedKeys.value = [...nextKeys];
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
syncSelectedKeys();
|
|
116
|
+
}, {
|
|
117
|
+
immediate: true,
|
|
118
|
+
flush: "sync"
|
|
119
|
+
});
|
|
120
|
+
const stopControlledOpenKeys = watch(() => toValue(options.openKeys), (nextKeys) => {
|
|
121
|
+
if (nextKeys !== void 0) {
|
|
122
|
+
openKeys.value = [...nextKeys];
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
syncOpenKeys();
|
|
126
|
+
}, {
|
|
127
|
+
immediate: true,
|
|
128
|
+
flush: "sync"
|
|
129
|
+
});
|
|
130
|
+
const stopSelected = watch(activeChainKey, syncSelectedKeys, { immediate: true });
|
|
131
|
+
const stopOpen = watch(activeChainKey, syncOpenKeys, { immediate: true });
|
|
132
|
+
onScopeDispose(() => {
|
|
133
|
+
stopSource();
|
|
134
|
+
stopControlledSelectedKeys();
|
|
135
|
+
stopControlledOpenKeys();
|
|
136
|
+
stopSelected();
|
|
137
|
+
stopOpen();
|
|
138
|
+
});
|
|
139
|
+
function resolveRoute(name) {
|
|
140
|
+
return resolveRouteTarget(lookup.value, name);
|
|
141
|
+
}
|
|
142
|
+
return { menuState: {
|
|
143
|
+
menus,
|
|
144
|
+
flatMenus,
|
|
145
|
+
selectedKeys,
|
|
146
|
+
openKeys,
|
|
147
|
+
breadcrumbRoutes,
|
|
148
|
+
breadcrumbItems,
|
|
149
|
+
currentMeta,
|
|
150
|
+
headerMenus,
|
|
151
|
+
siderMenus,
|
|
152
|
+
resolveRoute,
|
|
153
|
+
lookup,
|
|
154
|
+
setMenus,
|
|
155
|
+
refreshMenus,
|
|
156
|
+
batchMenus,
|
|
157
|
+
addMenu,
|
|
158
|
+
updateMenu,
|
|
159
|
+
setMenuMeta,
|
|
160
|
+
showMenu,
|
|
161
|
+
hideMenu,
|
|
162
|
+
removeMenu
|
|
163
|
+
} };
|
|
164
|
+
}
|
|
165
|
+
//#endregion
|
|
166
|
+
export { useMenu };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { TabGroup } from "../components/Tabs/interface.js";
|
|
2
|
+
import { LayoutMenuRoute, LayoutTabsConfig, LayoutTabsController } from "../interface.js";
|
|
3
|
+
import { TabsMenuType } from "../components/Tabs/contextMenu.js";
|
|
4
|
+
import { ComputedRef, Ref } from "vue";
|
|
5
|
+
|
|
6
|
+
//#region src/hooks/useTabs.d.ts
|
|
7
|
+
interface MenuDataState {
|
|
8
|
+
fixed: LayoutMenuRoute[];
|
|
9
|
+
normal: LayoutMenuRoute[];
|
|
10
|
+
}
|
|
11
|
+
interface UseTabsStateOptions {
|
|
12
|
+
/** 标签栏配置 */
|
|
13
|
+
config: ComputedRef<LayoutTabsConfig>;
|
|
14
|
+
/** 扁平菜单列表(用于固定标签扫描 & 过滤无效 fixed 标签) */
|
|
15
|
+
flatMenus: ComputedRef<LayoutMenuRoute[]>;
|
|
16
|
+
/** 侧边栏展开宽度(支持响应式 — 路由切换时 Sider 可见性可能变化) */
|
|
17
|
+
siderWidth: ComputedRef<number | string>;
|
|
18
|
+
/** 是否移动端 */
|
|
19
|
+
isMobile: ComputedRef<boolean>;
|
|
20
|
+
/** 内容是否全屏 */
|
|
21
|
+
contentFullscreen: Ref<boolean>;
|
|
22
|
+
/** 事件回调(单向通知,不再有 v-model 回流) */
|
|
23
|
+
onTabsChange: (tabs: LayoutMenuRoute[]) => void;
|
|
24
|
+
onReloadPage: () => void;
|
|
25
|
+
onContentFullscreenChange: (fullscreen: boolean) => void;
|
|
26
|
+
}
|
|
27
|
+
interface UseTabsStateReturn {
|
|
28
|
+
/** 标签原始状态(fixed + normal) — 单一真相源 */
|
|
29
|
+
menuDataState: MenuDataState;
|
|
30
|
+
/** 合并后的完整标签列表 */
|
|
31
|
+
dataSource: ComputedRef<LayoutMenuRoute[]>;
|
|
32
|
+
/** 当前激活的标签 key(route.name) */
|
|
33
|
+
activeKey: ComputedRef<string>;
|
|
34
|
+
/** 标签栏宽度 */
|
|
35
|
+
tabsWidth: ComputedRef<string>;
|
|
36
|
+
handleAddTabs: (record: LayoutMenuRoute) => void;
|
|
37
|
+
handleTabClick: (name: string) => void;
|
|
38
|
+
handleTabRemove: (name: string) => void;
|
|
39
|
+
handleContextMenuAction: (key: TabsMenuType, targetName: string) => void;
|
|
40
|
+
checkIsFixed: (route: LayoutMenuRoute) => boolean;
|
|
41
|
+
/** 同组内重排序(拖拽用);跨组或同位置忽略 */
|
|
42
|
+
reorderWithinGroup: (fromKey: string, toKey: string, group: TabGroup) => void;
|
|
43
|
+
tabsController: LayoutTabsController;
|
|
44
|
+
}
|
|
45
|
+
declare function useTabsState(options: UseTabsStateOptions): UseTabsStateReturn;
|
|
46
|
+
/**
|
|
47
|
+
* 命令式控制多标签(清空 / 关闭 / 增删改)。
|
|
48
|
+
* 通过 inject 获取 `GProLayout` 暴露的 tabs 控制器。
|
|
49
|
+
*/
|
|
50
|
+
declare function useTabs(): {
|
|
51
|
+
tabsRouter: LayoutTabsController;
|
|
52
|
+
};
|
|
53
|
+
//#endregion
|
|
54
|
+
export { MenuDataState, UseTabsStateOptions, UseTabsStateReturn, useTabs, useTabsState };
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import { useInjectLayoutContext } from "../context/index.js";
|
|
2
|
+
import { computed, reactive, ref, toRaw, watch } from "vue";
|
|
3
|
+
import { unit } from "@gx-design-vue/pro-provider";
|
|
4
|
+
import { isBoolean } from "@gx-design-vue/pro-utils";
|
|
5
|
+
import { useLocalStorage, useThrottleFn } from "@vueuse/core";
|
|
6
|
+
import { useRoute, useRouter } from "vue-router";
|
|
7
|
+
import { cloneDeep } from "es-toolkit";
|
|
8
|
+
//#region src/hooks/useTabs.ts
|
|
9
|
+
function getTabName(route) {
|
|
10
|
+
return route.name;
|
|
11
|
+
}
|
|
12
|
+
function cloneRouteValue(value) {
|
|
13
|
+
return value === void 0 ? void 0 : cloneDeep(toRaw(value));
|
|
14
|
+
}
|
|
15
|
+
function normalizeTabState(tabState) {
|
|
16
|
+
return tabState ? { ...toRaw(tabState) } : void 0;
|
|
17
|
+
}
|
|
18
|
+
function normalizeTabMeta(meta) {
|
|
19
|
+
if (!meta) return void 0;
|
|
20
|
+
const rawMeta = toRaw(meta);
|
|
21
|
+
return {
|
|
22
|
+
title: rawMeta.title,
|
|
23
|
+
tabState: normalizeTabState(rawMeta.tabState),
|
|
24
|
+
menuSelectKey: rawMeta.menuSelectKey
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function mergeTabMeta(target, patch) {
|
|
28
|
+
if (!target && !patch) return void 0;
|
|
29
|
+
const rawTarget = toRaw(target ?? {});
|
|
30
|
+
const rawPatch = toRaw(patch ?? {});
|
|
31
|
+
return {
|
|
32
|
+
title: rawPatch.title ?? rawTarget.title,
|
|
33
|
+
tabState: rawTarget.tabState || rawPatch.tabState ? {
|
|
34
|
+
...normalizeTabState(rawTarget.tabState),
|
|
35
|
+
...normalizeTabState(rawPatch.tabState)
|
|
36
|
+
} : void 0,
|
|
37
|
+
menuSelectKey: rawPatch.menuSelectKey ?? rawTarget.menuSelectKey
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function normalizeTabRoute(record) {
|
|
41
|
+
const rawRecord = toRaw(record);
|
|
42
|
+
return {
|
|
43
|
+
name: rawRecord.name,
|
|
44
|
+
path: rawRecord.path,
|
|
45
|
+
fullPath: rawRecord.fullPath,
|
|
46
|
+
query: cloneRouteValue(rawRecord.query),
|
|
47
|
+
params: cloneRouteValue(rawRecord.params),
|
|
48
|
+
redirect: rawRecord.redirect,
|
|
49
|
+
meta: normalizeTabMeta(rawRecord.meta)
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function mergeTabRoute(target, patch) {
|
|
53
|
+
const rawTarget = toRaw(target);
|
|
54
|
+
const rawPatch = toRaw(patch);
|
|
55
|
+
return normalizeTabRoute({
|
|
56
|
+
name: rawPatch.name ?? rawTarget.name,
|
|
57
|
+
path: rawPatch.path ?? rawTarget.path,
|
|
58
|
+
fullPath: rawPatch.fullPath ?? rawTarget.fullPath,
|
|
59
|
+
query: rawPatch.query === void 0 ? rawTarget.query : rawPatch.query,
|
|
60
|
+
params: rawPatch.params === void 0 ? rawTarget.params : rawPatch.params,
|
|
61
|
+
redirect: rawPatch.redirect ?? rawTarget.redirect,
|
|
62
|
+
meta: mergeTabMeta(rawTarget.meta, rawPatch.meta)
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function toStorageTabRoute(record) {
|
|
66
|
+
const rawRecord = toRaw(record);
|
|
67
|
+
const rawMeta = toRaw(rawRecord.meta ?? {});
|
|
68
|
+
return {
|
|
69
|
+
name: rawRecord.name,
|
|
70
|
+
path: rawRecord.path,
|
|
71
|
+
fullPath: rawRecord.fullPath,
|
|
72
|
+
query: cloneRouteValue(rawRecord.query),
|
|
73
|
+
params: cloneRouteValue(rawRecord.params),
|
|
74
|
+
redirect: rawRecord.redirect,
|
|
75
|
+
meta: {
|
|
76
|
+
title: rawMeta.title,
|
|
77
|
+
tabState: normalizeTabState(rawMeta.tabState),
|
|
78
|
+
menuSelectKey: rawMeta.menuSelectKey
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function toStorageMenuDataState(state) {
|
|
83
|
+
return {
|
|
84
|
+
fixed: state.fixed.map(toStorageTabRoute),
|
|
85
|
+
normal: state.normal.map(toStorageTabRoute)
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function isFixedTabRoute(route) {
|
|
89
|
+
const { fixed } = route?.meta?.tabState ?? {};
|
|
90
|
+
return isBoolean(fixed) ? fixed : false;
|
|
91
|
+
}
|
|
92
|
+
/** 初始状态:仅从 localStorage 恢复(单一外部源,不再有 v-model 优先级) */
|
|
93
|
+
function getInitialTabsState(storageTabs, persistent) {
|
|
94
|
+
if (persistent && storageTabs.value) return {
|
|
95
|
+
fixed: storageTabs.value.fixed?.map(normalizeTabRoute) ?? [],
|
|
96
|
+
normal: storageTabs.value.normal?.map(normalizeTabRoute) ?? []
|
|
97
|
+
};
|
|
98
|
+
return {
|
|
99
|
+
fixed: [],
|
|
100
|
+
normal: []
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function useTabsState(options) {
|
|
104
|
+
const { config, flatMenus, siderWidth, isMobile, contentFullscreen, onTabsChange, onReloadPage, onContentFullscreenChange } = options;
|
|
105
|
+
const router = useRouter();
|
|
106
|
+
const currentRoute = useRoute();
|
|
107
|
+
const isPersistent = computed(() => config.value.persistent !== false);
|
|
108
|
+
const storageTabs = useLocalStorage("pro-layout-tabs", {
|
|
109
|
+
fixed: [],
|
|
110
|
+
normal: []
|
|
111
|
+
});
|
|
112
|
+
const menuDataState = reactive(getInitialTabsState(storageTabs, isPersistent.value));
|
|
113
|
+
const menusReady = ref(flatMenus.value.length > 0);
|
|
114
|
+
const dataSource = computed(() => [...menuDataState.fixed, ...menuDataState.normal]);
|
|
115
|
+
const activeKey = computed(() => currentRoute.name);
|
|
116
|
+
const tabsWidth = computed(() => {
|
|
117
|
+
if (contentFullscreen.value || isMobile.value) return "100%";
|
|
118
|
+
const width = unit(siderWidth.value);
|
|
119
|
+
return siderWidth.value ? `calc(100% - ${width})` : "100%";
|
|
120
|
+
});
|
|
121
|
+
function checkIsFixed(route) {
|
|
122
|
+
return isFixedTabRoute(route);
|
|
123
|
+
}
|
|
124
|
+
function getCurrentRoute(name) {
|
|
125
|
+
return dataSource.value.find((item) => getTabName(item) === name);
|
|
126
|
+
}
|
|
127
|
+
/** 获取路由跳转 path */
|
|
128
|
+
function getRoutePath(route) {
|
|
129
|
+
return route.redirect || route.fullPath || route.path || "";
|
|
130
|
+
}
|
|
131
|
+
/** 构建路由跳转额外参数 */
|
|
132
|
+
function getExtraProps(route) {
|
|
133
|
+
const extra = {};
|
|
134
|
+
if (route.query) extra.query = route.query;
|
|
135
|
+
if (route.params) extra.params = route.params;
|
|
136
|
+
return extra;
|
|
137
|
+
}
|
|
138
|
+
function changeTabsList(record, operation) {
|
|
139
|
+
const targetArray = checkIsFixed(record) ? "fixed" : "normal";
|
|
140
|
+
const { type, addType, params } = operation;
|
|
141
|
+
if (type === "add" && addType) menuDataState[targetArray][addType](normalizeTabRoute(params));
|
|
142
|
+
else if (type === "merge") menuDataState[targetArray] = menuDataState[targetArray].map((item) => {
|
|
143
|
+
if (getTabName(item) === getTabName(record)) return mergeTabRoute(item, params);
|
|
144
|
+
return item;
|
|
145
|
+
});
|
|
146
|
+
else if (type === "remove") menuDataState[targetArray] = menuDataState[targetArray].filter((item) => getTabName(item) !== getTabName(record));
|
|
147
|
+
}
|
|
148
|
+
function handleAddTabs(record) {
|
|
149
|
+
const { hidden } = record?.meta?.tabState ?? {};
|
|
150
|
+
if (!record.name || !record.meta || hidden === true) return;
|
|
151
|
+
const fixed = checkIsFixed(record);
|
|
152
|
+
const name = getTabName(record);
|
|
153
|
+
const tabData = normalizeTabRoute(record);
|
|
154
|
+
const existing = dataSource.value.find((item) => getTabName(item) === name);
|
|
155
|
+
if (!existing) {
|
|
156
|
+
menuDataState[fixed ? "fixed" : "normal"].push(tabData);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (checkIsFixed(existing) !== fixed) {
|
|
160
|
+
changeTabsList(existing, {
|
|
161
|
+
type: "remove",
|
|
162
|
+
params: existing
|
|
163
|
+
});
|
|
164
|
+
menuDataState[fixed ? "fixed" : "normal"].push(mergeTabRoute(existing, tabData));
|
|
165
|
+
} else changeTabsList(record, {
|
|
166
|
+
type: "merge",
|
|
167
|
+
params: tabData
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/** 导航到最后一个标签 */
|
|
171
|
+
function navigateToLastTab() {
|
|
172
|
+
const lastTab = dataSource.value.slice(-1)[0];
|
|
173
|
+
if (lastTab) router.push({
|
|
174
|
+
path: getRoutePath(lastTab),
|
|
175
|
+
...getExtraProps(lastTab)
|
|
176
|
+
});
|
|
177
|
+
else router.push("/");
|
|
178
|
+
}
|
|
179
|
+
function handleTabRemove(name) {
|
|
180
|
+
const record = getCurrentRoute(name);
|
|
181
|
+
if (!record) return;
|
|
182
|
+
changeTabsList(record, {
|
|
183
|
+
type: "remove",
|
|
184
|
+
params: record
|
|
185
|
+
});
|
|
186
|
+
if (getTabName(record) === activeKey.value) navigateToLastTab();
|
|
187
|
+
}
|
|
188
|
+
function handleTabClick(name) {
|
|
189
|
+
const record = getCurrentRoute(name);
|
|
190
|
+
if (!record || name === activeKey.value) return;
|
|
191
|
+
router.push({
|
|
192
|
+
path: getRoutePath(record),
|
|
193
|
+
...getExtraProps(record)
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
function handleContextMenuAction(key, targetName) {
|
|
197
|
+
const targetRoute = getCurrentRoute(targetName);
|
|
198
|
+
if (!targetRoute) return;
|
|
199
|
+
const activeIndex = menuDataState.normal.findIndex((item) => getTabName(item) === targetName);
|
|
200
|
+
const isFixed = checkIsFixed(targetRoute);
|
|
201
|
+
switch (key) {
|
|
202
|
+
case "fixed":
|
|
203
|
+
if (isFixed) {
|
|
204
|
+
const fixedIndex = menuDataState.fixed.findIndex((item) => getTabName(item) === targetName);
|
|
205
|
+
menuDataState.normal.unshift(mergeTabRoute(targetRoute, { meta: { tabState: { fixed: false } } }));
|
|
206
|
+
menuDataState.fixed = menuDataState.fixed.filter((_, index) => index !== fixedIndex);
|
|
207
|
+
} else {
|
|
208
|
+
menuDataState.fixed.push(mergeTabRoute(targetRoute, { meta: { tabState: { fixed: true } } }));
|
|
209
|
+
menuDataState.normal = menuDataState.normal.filter((_, index) => index !== activeIndex);
|
|
210
|
+
}
|
|
211
|
+
break;
|
|
212
|
+
case "close":
|
|
213
|
+
handleTabRemove(targetName);
|
|
214
|
+
break;
|
|
215
|
+
case "closeOthersTabs":
|
|
216
|
+
menuDataState.normal = menuDataState.normal.filter((item) => getTabName(item) === targetName || checkIsFixed(item));
|
|
217
|
+
if (!dataSource.value.some((item) => getTabName(item) === activeKey.value)) router.push({
|
|
218
|
+
path: getRoutePath(targetRoute),
|
|
219
|
+
...getExtraProps(targetRoute)
|
|
220
|
+
});
|
|
221
|
+
break;
|
|
222
|
+
case "closeLeftTabs":
|
|
223
|
+
if (activeIndex >= 0) {
|
|
224
|
+
menuDataState.normal = menuDataState.normal.filter((_, index) => index >= activeIndex);
|
|
225
|
+
if (!dataSource.value.some((item) => getTabName(item) === activeKey.value)) router.push({
|
|
226
|
+
path: getRoutePath(targetRoute),
|
|
227
|
+
...getExtraProps(targetRoute)
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
break;
|
|
231
|
+
case "closeRightTabs":
|
|
232
|
+
if (activeIndex >= 0) menuDataState.normal = menuDataState.normal.filter((_, index) => index <= activeIndex);
|
|
233
|
+
if (!dataSource.value.some((item) => getTabName(item) === activeKey.value)) router.push({
|
|
234
|
+
path: getRoutePath(targetRoute),
|
|
235
|
+
...getExtraProps(targetRoute)
|
|
236
|
+
});
|
|
237
|
+
break;
|
|
238
|
+
case "closeAllTabs":
|
|
239
|
+
menuDataState.normal = menuDataState.normal.filter((item) => checkIsFixed(item));
|
|
240
|
+
navigateToLastTab();
|
|
241
|
+
break;
|
|
242
|
+
case "reloadPage":
|
|
243
|
+
if (targetName === activeKey.value) throttledReload();
|
|
244
|
+
break;
|
|
245
|
+
case "newBlank":
|
|
246
|
+
window.open(location.href);
|
|
247
|
+
break;
|
|
248
|
+
case "fullScreen":
|
|
249
|
+
contentFullscreen.value = !contentFullscreen.value;
|
|
250
|
+
onContentFullscreenChange(contentFullscreen.value);
|
|
251
|
+
break;
|
|
252
|
+
default: break;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
const throttledReload = useThrottleFn(() => {
|
|
256
|
+
onReloadPage();
|
|
257
|
+
}, 500);
|
|
258
|
+
watch(flatMenus, (menus) => {
|
|
259
|
+
if (!menus.length) return;
|
|
260
|
+
if (!menusReady.value) menusReady.value = true;
|
|
261
|
+
const menuNameSet = new Set(menus.map((menuItem) => menuItem.name));
|
|
262
|
+
if (menuDataState.fixed.length) menuDataState.fixed = menuDataState.fixed.filter((item) => menuNameSet.has(item.name));
|
|
263
|
+
const openedNames = new Set(dataSource.value.map((tab) => getTabName(tab)));
|
|
264
|
+
menus.forEach((item) => {
|
|
265
|
+
if (openedNames.has(getTabName(item)) || checkIsFixed(item)) handleAddTabs(item);
|
|
266
|
+
});
|
|
267
|
+
}, { immediate: true });
|
|
268
|
+
watch(() => {
|
|
269
|
+
const tabState = currentRoute.meta?.tabState;
|
|
270
|
+
return {
|
|
271
|
+
name: currentRoute.name,
|
|
272
|
+
fullPath: currentRoute.fullPath,
|
|
273
|
+
path: currentRoute.path,
|
|
274
|
+
query: currentRoute.query,
|
|
275
|
+
params: currentRoute.params,
|
|
276
|
+
title: currentRoute.meta?.title,
|
|
277
|
+
tabFixed: tabState?.fixed,
|
|
278
|
+
tabHidden: tabState?.hidden
|
|
279
|
+
};
|
|
280
|
+
}, () => {
|
|
281
|
+
if (currentRoute?.name) handleAddTabs(currentRoute);
|
|
282
|
+
}, { immediate: true });
|
|
283
|
+
watch(dataSource, (allTabs) => {
|
|
284
|
+
if (isPersistent.value && menusReady.value) storageTabs.value = toStorageMenuDataState(menuDataState);
|
|
285
|
+
onTabsChange(allTabs);
|
|
286
|
+
});
|
|
287
|
+
/** 同组内重排序(拖拽用);跨组或同位置直接忽略 */
|
|
288
|
+
function reorderWithinGroup(fromKey, toKey, group) {
|
|
289
|
+
const arr = menuDataState[group];
|
|
290
|
+
const fromIdx = arr.findIndex((item) => item.name === fromKey);
|
|
291
|
+
const toIdx = arr.findIndex((item) => item.name === toKey);
|
|
292
|
+
if (fromIdx < 0 || toIdx < 0 || fromIdx === toIdx) return;
|
|
293
|
+
const next = arr.slice();
|
|
294
|
+
const [moved] = next.splice(fromIdx, 1);
|
|
295
|
+
next.splice(toIdx, 0, moved);
|
|
296
|
+
menuDataState[group] = next;
|
|
297
|
+
}
|
|
298
|
+
return {
|
|
299
|
+
menuDataState,
|
|
300
|
+
dataSource,
|
|
301
|
+
activeKey,
|
|
302
|
+
tabsWidth,
|
|
303
|
+
handleAddTabs,
|
|
304
|
+
handleTabClick,
|
|
305
|
+
handleTabRemove,
|
|
306
|
+
handleContextMenuAction,
|
|
307
|
+
checkIsFixed,
|
|
308
|
+
reorderWithinGroup,
|
|
309
|
+
tabsController: {
|
|
310
|
+
getTabs: () => dataSource.value.map((item) => normalizeTabRoute(item)),
|
|
311
|
+
getActive: () => activeKey.value,
|
|
312
|
+
isActive: (name) => activeKey.value === name,
|
|
313
|
+
isFixed: (name) => {
|
|
314
|
+
const route = getCurrentRoute(name);
|
|
315
|
+
return route ? checkIsFixed(route) : false;
|
|
316
|
+
},
|
|
317
|
+
add: (record) => handleAddTabs(record),
|
|
318
|
+
close: (name) => handleTabRemove(name ?? activeKey.value),
|
|
319
|
+
closeOthers: (name) => handleContextMenuAction("closeOthersTabs", name ?? activeKey.value),
|
|
320
|
+
closeLeft: (name) => handleContextMenuAction("closeLeftTabs", name ?? activeKey.value),
|
|
321
|
+
closeRight: (name) => handleContextMenuAction("closeRightTabs", name ?? activeKey.value),
|
|
322
|
+
closeAll: () => handleContextMenuAction("closeAllTabs", activeKey.value),
|
|
323
|
+
clean: () => {
|
|
324
|
+
menuDataState.fixed = [];
|
|
325
|
+
menuDataState.normal = [];
|
|
326
|
+
},
|
|
327
|
+
switchTo: (name) => handleTabClick(name),
|
|
328
|
+
toggleFixed: (name, fixed) => {
|
|
329
|
+
const route = getCurrentRoute(name);
|
|
330
|
+
if (!route) return;
|
|
331
|
+
const currentFixed = checkIsFixed(route);
|
|
332
|
+
if ((fixed ?? !currentFixed) !== currentFixed) handleContextMenuAction("fixed", name);
|
|
333
|
+
},
|
|
334
|
+
reload: (name) => {
|
|
335
|
+
const target = name ?? activeKey.value;
|
|
336
|
+
const run = () => throttledReload();
|
|
337
|
+
if (target !== activeKey.value) {
|
|
338
|
+
const route = getCurrentRoute(target);
|
|
339
|
+
if (route) {
|
|
340
|
+
router.push({
|
|
341
|
+
path: getRoutePath(route),
|
|
342
|
+
...getExtraProps(route)
|
|
343
|
+
}).then(run);
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
run();
|
|
348
|
+
},
|
|
349
|
+
toggleFullscreen: () => handleContextMenuAction("fullScreen", activeKey.value),
|
|
350
|
+
update: (record, op) => changeTabsList(record, {
|
|
351
|
+
type: op.type,
|
|
352
|
+
addType: op.addType,
|
|
353
|
+
params: op.params ?? record
|
|
354
|
+
})
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* 命令式控制多标签(清空 / 关闭 / 增删改)。
|
|
360
|
+
* 通过 inject 获取 `GProLayout` 暴露的 tabs 控制器。
|
|
361
|
+
*/
|
|
362
|
+
const fallbackController = {
|
|
363
|
+
getTabs: () => [],
|
|
364
|
+
getActive: () => "",
|
|
365
|
+
isActive: () => false,
|
|
366
|
+
isFixed: () => false,
|
|
367
|
+
add: () => {},
|
|
368
|
+
close: () => {},
|
|
369
|
+
closeOthers: () => {},
|
|
370
|
+
closeLeft: () => {},
|
|
371
|
+
closeRight: () => {},
|
|
372
|
+
closeAll: () => {},
|
|
373
|
+
clean: () => {},
|
|
374
|
+
switchTo: () => {},
|
|
375
|
+
toggleFixed: () => {},
|
|
376
|
+
reload: () => {},
|
|
377
|
+
toggleFullscreen: () => {},
|
|
378
|
+
update: () => {}
|
|
379
|
+
};
|
|
380
|
+
/**
|
|
381
|
+
* 命令式控制多标签(清空 / 关闭 / 增删改)。
|
|
382
|
+
* 通过 inject 获取 `GProLayout` 暴露的 tabs 控制器。
|
|
383
|
+
*/
|
|
384
|
+
function useTabs() {
|
|
385
|
+
return { tabsRouter: useInjectLayoutContext()?.tabsState?.tabsController ?? fallbackController };
|
|
386
|
+
}
|
|
387
|
+
//#endregion
|
|
388
|
+
export { useTabs, useTabsState };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,28 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
import _default$2 from "./ProLayout.js";
|
|
14
|
-
import { iconStyle } from "./style/index.js";
|
|
1
|
+
import { LayoutBreadcrumbProps, LayoutBreadcrumbSlots } from "./components/Breadcrumb/interface.js";
|
|
2
|
+
import { LayoutCollapseButtonEmits, LayoutCollapseButtonEmitsProps, LayoutCollapseButtonProps, LayoutCollapseButtonSlots } from "./components/CollapseButton/interface.js";
|
|
3
|
+
import { LayoutFooterProps, LayoutFooterSlots } from "./components/Footer/interface.js";
|
|
4
|
+
import { LayoutHeaderEmits, LayoutHeaderEmitsProps, LayoutHeaderProps, LayoutHeaderSlots } from "./components/Header/interface.js";
|
|
5
|
+
import { LayoutLogoEmits, LayoutLogoEmitsProps, LayoutLogoProps, LayoutLogoSlots } from "./components/Logo/interface.js";
|
|
6
|
+
import { PRO_MENU_SLOT_KEYS, ProMenuEmits, ProMenuEmitsProps, ProMenuProps, ProMenuSlots } from "./components/Menu/interface.js";
|
|
7
|
+
import { LayoutSiderEmits, LayoutSiderEmitsProps, LayoutSiderProps, LayoutSiderSlots } from "./components/Sider/interface.js";
|
|
8
|
+
import { InnerTabItem, InnerTabsEmits, InnerTabsEmitsProps, InnerTabsProps, InnerTabsSlots, LayoutTabsEmits, LayoutTabsEmitsProps, LayoutTabsProps, LayoutTabsSlots, TabGroup } from "./components/Tabs/interface.js";
|
|
9
|
+
import { LayoutContentEmits, LayoutContentEmitsProps, LayoutContentProps, LayoutContentSlots } from "./components/WrapContent/interface.js";
|
|
10
|
+
import { APP_PAGE_SLOT_KEYS, AppPageSlotKey, AppPageSpinning, BreadcrumbItemType, CardProps, DeepPartial, EmptyEmits, FOOTER_TOOLBAR_SLOT_KEYS, FooterToolbarClassNamesType, FooterToolbarSemanticName, FooterToolbarSlotKey, FooterToolbarStylesType, GFooterToolbarProps, GFooterToolbarSlots, GPageContainerEmits, GPageContainerEmitsProps, GPageContainerProps, GPageContainerSlots, GPageTransitionProps, GPageTransitionSlots, GProAppPageProps, GProAppPageSlots, GProLayoutEmits, GProLayoutEmitsProps, GProLayoutProps, GProLayoutRef, GProLayoutSlots, LAYOUT_SLOT_KEYS, LayoutBreadcrumbConfig, LayoutBreadcrumbSlotProps, LayoutClassNamesType, LayoutCollapseConfig, LayoutFooterConfig, LayoutFooterLink, LayoutHeaderConfig, LayoutHeaderSlotProps, LayoutLogoConfig, LayoutMenuConfig, LayoutMenuItemSlotProps, LayoutMenuRoute, LayoutPageContainerConfig, LayoutSelectInfo, LayoutSemanticName, LayoutSiderConfig, LayoutSiderSlotProps, LayoutStylesType, LayoutTabsConfig, LayoutTabsController, LayoutTabsUpdateOp, MenuClassNamesType, MenuClickInfo, MenuProps, MenuRenderItem, MenuSelectInfo, MenuSemanticName, MenuStylesType, Meta, PAGE_CONTAINER_SLOT_KEYS, PageContainerClassNamesType, PageContainerLoading, PageContainerSemanticName, PageContainerSlotKey, PageContainerStylesType, SiderProps, SpinProps, Tab, TabsMeta, TabsProps, WatermarkProps } from "./interface.js";
|
|
11
|
+
import GProLayout from "./ProLayout.js";
|
|
12
|
+
import { ProAppPageContext, useAppPageContext } from "./components/AppPage/context.js";
|
|
15
13
|
import ProAppPage from "./components/AppPage/index.js";
|
|
16
|
-
import
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import
|
|
20
|
-
import
|
|
21
|
-
import
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
|
|
26
|
-
import { provideProLayoutExposeContext, useProLayoutExposeContext } from "./Context/expose.js";
|
|
27
|
-
import { MenuMode } from "ant-design-vue";
|
|
28
|
-
export { AnimateConfig, AppRouteModule, BasicLayoutProps, ClassNamesType, CollapsedProps, CommonLayoutProps, Component, _default as GBaseMenu, _default$1 as GPageTransition, ProAppPage as GProAppPage, _default$2 as GProLayout, GProPageContainer, _default$3 as GlobalFooter, type GlobalFooterProps, HeaderLayoutProps, LayoutClassNamesType, LayoutContext, LayoutSemanticName, LayoutStylesType, LazyIcon, MenuData, MenuDataItem, type MenuMode, Meta, type OpenEventHandler, type PageContainerProps, ProLayoutConfig, ProLayoutContextProps, ProLayoutExpose, ProLayoutInjextExpose, ProLayoutType, type ProSettingsProps, type SelectInfo, SemanticName, SiderLayoutProps, SiderMenuWrapper, StylesType, TabsMeta, TabsRouteExpose, type TabsRouteProps, animateSetting, baseMenuProps, calculateCss, clearMenuItem, convertCSSPropertiesToString, cssValueToNumber, defaultContextKey, defaultSettings, extractCSSVariableName, filterTree, flatMap, getCssVarOrUnit, getCssVarValue, getCssVariableValue, getLastPath, getMatchedList, getMenuData, getMenuFirstChildren, getParentKeys, getTokenLayoutTheme, handlePathKey, iconStyle, layout, provideProLayoutContext, provideProLayoutExposeContext, removeDuplicatesByName, useLayoutExpose, export_default as useLayoutMenu, usePageContent, useProLayoutContext, useProLayoutExposeContext, useProLayoutMenuContext, export_default$1 as useThemeState };
|
|
14
|
+
import GFooterToolbar from "./components/FooterToolbar/index.js";
|
|
15
|
+
import ProMenu from "./components/Menu/index.js";
|
|
16
|
+
import ProPageContainer from "./components/PageContainer/index.js";
|
|
17
|
+
import GPageTransition from "./components/PageTransition/index.js";
|
|
18
|
+
import InnerTabs from "./components/Tabs/InnerTabs.js";
|
|
19
|
+
import { MenuLookupEntry, MenuMetaPatch, MenuModel, MenuRoutePatch, MenuTreeMutationOptions, ResolveRouteResult, buildBreadcrumbRoutes, buildMenuLookup, cleanMenus, collectMenuNames, getLastPath, insertMenuAtPath, normalizeMenus, partitionFixedMenus, removeMenuAtPath, resolveMatchedChain, resolveRouteTarget, routesToMenus, selectMenuBranch, sortMenusByOrder, toBreadcrumbItems, updateMenuAtPath, updateMenuMetaAtPath } from "./utils/menu.js";
|
|
20
|
+
import { LayoutMenuState, UseLayoutMenuOptions, UseLayoutMenuReturn, useMenu } from "./hooks/useMenu.js";
|
|
21
|
+
import { useTabs } from "./hooks/useTabs.js";
|
|
22
|
+
import { LayoutContextProps, useInjectLayoutContext } from "./context/index.js";
|
|
23
|
+
export { APP_PAGE_SLOT_KEYS, AppPageSlotKey, AppPageSpinning, type BreadcrumbItemType, type CardProps, DeepPartial, EmptyEmits, FOOTER_TOOLBAR_SLOT_KEYS, FooterToolbarClassNamesType, FooterToolbarSemanticName, FooterToolbarSlotKey, FooterToolbarStylesType, GFooterToolbar, GFooterToolbarProps, GFooterToolbarSlots, InnerTabs as GInnerTabs, GPageContainerEmits, GPageContainerEmitsProps, GPageContainerProps, GPageContainerSlots, GPageTransition, GPageTransitionProps, GPageTransitionSlots, ProAppPage as GProAppPage, GProAppPageProps, GProAppPageSlots, GProLayout, GProLayoutEmits, GProLayoutEmitsProps, GProLayoutProps, GProLayoutRef, GProLayoutSlots, ProPageContainer as GProPageContainer, InnerTabItem, InnerTabsEmits, InnerTabsEmitsProps, InnerTabsProps, InnerTabsSlots, LAYOUT_SLOT_KEYS, LayoutBreadcrumbConfig, LayoutBreadcrumbProps, LayoutBreadcrumbSlotProps, LayoutBreadcrumbSlots, LayoutClassNamesType, LayoutCollapseButtonEmits, LayoutCollapseButtonEmitsProps, LayoutCollapseButtonProps, LayoutCollapseButtonSlots, LayoutCollapseConfig, LayoutContentEmits, LayoutContentEmitsProps, LayoutContentProps, LayoutContentSlots, type LayoutContextProps, LayoutFooterConfig, LayoutFooterLink, LayoutFooterProps, LayoutFooterSlots, LayoutHeaderConfig, LayoutHeaderEmits, LayoutHeaderEmitsProps, LayoutHeaderProps, LayoutHeaderSlotProps, LayoutHeaderSlots, LayoutLogoConfig, LayoutLogoEmits, LayoutLogoEmitsProps, LayoutLogoProps, LayoutLogoSlots, LayoutMenuConfig, LayoutMenuItemSlotProps, LayoutMenuRoute, type LayoutMenuState, LayoutPageContainerConfig, LayoutSelectInfo, LayoutSemanticName, LayoutSiderConfig, LayoutSiderEmits, LayoutSiderEmitsProps, LayoutSiderProps, LayoutSiderSlotProps, LayoutSiderSlots, LayoutStylesType, LayoutTabsConfig, LayoutTabsController, LayoutTabsEmits, LayoutTabsEmitsProps, LayoutTabsProps, LayoutTabsSlots, LayoutTabsUpdateOp, MenuClassNamesType, MenuClickInfo, MenuLookupEntry, MenuMetaPatch, MenuModel, type MenuProps, MenuRenderItem, MenuRoutePatch, MenuSelectInfo, MenuSemanticName, MenuStylesType, MenuTreeMutationOptions, Meta, PAGE_CONTAINER_SLOT_KEYS, PRO_MENU_SLOT_KEYS, PageContainerClassNamesType, PageContainerLoading, PageContainerSemanticName, PageContainerSlotKey, PageContainerStylesType, type ProAppPageContext, ProMenu, ProMenuEmits, ProMenuEmitsProps, ProMenuProps, ProMenuSlots, ResolveRouteResult, type SiderProps, type SpinProps, type Tab, TabGroup, TabsMeta, type TabsProps, type UseLayoutMenuOptions, type UseLayoutMenuReturn, type WatermarkProps, buildBreadcrumbRoutes, buildMenuLookup, cleanMenus, collectMenuNames, getLastPath, insertMenuAtPath, normalizeMenus, partitionFixedMenus, removeMenuAtPath, resolveMatchedChain, resolveRouteTarget, routesToMenus, selectMenuBranch, sortMenusByOrder, toBreadcrumbItems, updateMenuAtPath, updateMenuMetaAtPath, useAppPageContext, useInjectLayoutContext, useMenu, useTabs };
|