@shwfed/nuxt 0.1.70 → 0.1.72
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/module.d.mts
CHANGED
|
@@ -15,6 +15,9 @@ interface ModuleOptions {
|
|
|
15
15
|
*
|
|
16
16
|
* 这个表达式可以访问到 `token` 变量,其通过 `token` 配置的表达式计算得到。
|
|
17
17
|
*
|
|
18
|
+
* 仅当 `token` 与 `headers` 都配置为字符串时才会执行该表达式;
|
|
19
|
+
* 若 `token` 表达式结果不是字符串或表达式执行失败,则不会注入任何请求头。
|
|
20
|
+
*
|
|
18
21
|
* @type DSL
|
|
19
22
|
*/
|
|
20
23
|
headers?: string;
|
|
@@ -30,6 +33,8 @@ interface ModuleOptions {
|
|
|
30
33
|
* DSL 应当返回一个布尔值,表示是否需要重定向到登陆页。该表达式可以访问到**每一个 API 响应**的响应数据,
|
|
31
34
|
* 可以通过 `response` 变量访问。
|
|
32
35
|
*
|
|
36
|
+
* 仅当 `expired` 与 `logoutUri` 都配置为字符串时才会执行该表达式。
|
|
37
|
+
*
|
|
33
38
|
* @type DSL
|
|
34
39
|
*/
|
|
35
40
|
expired?: string;
|
|
@@ -54,21 +59,27 @@ interface ModuleOptions {
|
|
|
54
59
|
/**
|
|
55
60
|
* 侧边栏的菜单
|
|
56
61
|
*
|
|
57
|
-
* DSL
|
|
62
|
+
* DSL 应当返回一个数组,每个元素是一个分组或路由项:
|
|
58
63
|
*
|
|
59
64
|
* ```ts
|
|
60
|
-
* type
|
|
61
|
-
* id: string
|
|
65
|
+
* type RouteItem = {
|
|
66
|
+
* id: string | number
|
|
62
67
|
* title: string
|
|
63
|
-
*
|
|
64
|
-
* disabled?: string
|
|
65
|
-
* hidden?: string
|
|
68
|
+
* route: string
|
|
66
69
|
* icon?: string
|
|
67
70
|
* keywords?: string[]
|
|
68
|
-
*
|
|
71
|
+
* }
|
|
72
|
+
*
|
|
73
|
+
* type GroupItem = {
|
|
74
|
+
* id: string | number
|
|
75
|
+
* title: string
|
|
76
|
+
* icon?: string
|
|
77
|
+
* children: RouteItem[]
|
|
69
78
|
* }
|
|
70
79
|
* ```
|
|
71
80
|
*
|
|
81
|
+
* `RouteItem` 不支持 `hidden` / `disabled`,且 `children` 仅支持一层(`GroupItem -> RouteItem[]`)。
|
|
82
|
+
*
|
|
72
83
|
* @type DSL
|
|
73
84
|
*/
|
|
74
85
|
menus?: string;
|
|
@@ -108,6 +119,8 @@ interface ModuleOptions {
|
|
|
108
119
|
* - 清理缓存:`{ type: 'request', url: '/cache/clear', method: 'POST', body: { scope: 'all' } }`
|
|
109
120
|
* - 重建索引:`{ type: 'request', url: '/search/reindex', method: 'POST', query: { async: true }, headers: { 'X-Command-Source': 'palette' } }`
|
|
110
121
|
*
|
|
122
|
+
* 当前模块实现会将 `commands: null` 规范化为 `undefined`,等价于不配置。
|
|
123
|
+
*
|
|
111
124
|
* @type DSL
|
|
112
125
|
*/
|
|
113
126
|
commands?: string | null;
|
package/dist/module.json
CHANGED
|
@@ -18,7 +18,8 @@ import { useFavorite } from "../composables/useFavorite";
|
|
|
18
18
|
import { useNavigationTabs } from "../composables/useNavigationTabs";
|
|
19
19
|
import { commandActionSchema, executeCommandAction } from "../utils/command";
|
|
20
20
|
import { createPaletteItemValue, normalizeCommandsForPalette, splitNavigationForPalette } from "../utils/command-palette";
|
|
21
|
-
import {
|
|
21
|
+
import { resolveNavigationTitle } from "../utils/navigation-title";
|
|
22
|
+
import { isRouteActive } from "../utils/route";
|
|
22
23
|
import { applyRootNavigationFallback } from "../utils/sidebar-fallback";
|
|
23
24
|
const { $dsl, $logout, $md, $api, $toast } = useNuxtApp();
|
|
24
25
|
const { t } = useI18n();
|
|
@@ -79,22 +80,7 @@ const {
|
|
|
79
80
|
} = useFavorite("navigation", navigationItems);
|
|
80
81
|
const isNavigationItemActive = (itemRoute) => isRouteActive(route.path, itemRoute);
|
|
81
82
|
const getTabLabel = (tab) => {
|
|
82
|
-
|
|
83
|
-
for (const group of navigations.value) {
|
|
84
|
-
if ("children" in group) {
|
|
85
|
-
const matchedChild = group.children.find((child) => {
|
|
86
|
-
if (!("route" in child))
|
|
87
|
-
return false;
|
|
88
|
-
return normalizeRoutePath(child.route) === normalizedTab;
|
|
89
|
-
});
|
|
90
|
-
if (matchedChild)
|
|
91
|
-
return matchedChild.title;
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
if (normalizeRoutePath(group.route) === normalizedTab)
|
|
95
|
-
return group.title;
|
|
96
|
-
}
|
|
97
|
-
return normalizedTab;
|
|
83
|
+
return resolveNavigationTitle(navigations.value, tab);
|
|
98
84
|
};
|
|
99
85
|
const activeTabLabel = computed(() => {
|
|
100
86
|
if (active.value === void 0)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type NavigationLeaf = Readonly<{
|
|
2
|
+
title: string;
|
|
3
|
+
route: string;
|
|
4
|
+
}>;
|
|
5
|
+
type NavigationGroup = Readonly<{
|
|
6
|
+
children: Array<NavigationLeaf>;
|
|
7
|
+
}>;
|
|
8
|
+
type NavigationEntry = NavigationLeaf | NavigationGroup;
|
|
9
|
+
export declare function resolveNavigationTitle(entries: Array<NavigationEntry>, path: string): string;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { isRouteActive, normalizeRoutePath } from "./route.js";
|
|
2
|
+
export function resolveNavigationTitle(entries, path) {
|
|
3
|
+
const normalizedPath = normalizeRoutePath(path);
|
|
4
|
+
let bestTitle;
|
|
5
|
+
let bestRouteLength = -1;
|
|
6
|
+
for (const entry of entries) {
|
|
7
|
+
if ("children" in entry) {
|
|
8
|
+
for (const child of entry.children) {
|
|
9
|
+
const normalizedRoute2 = normalizeRoutePath(child.route);
|
|
10
|
+
if (!isRouteActive(normalizedPath, normalizedRoute2))
|
|
11
|
+
continue;
|
|
12
|
+
if (normalizedRoute2.length <= bestRouteLength)
|
|
13
|
+
continue;
|
|
14
|
+
bestRouteLength = normalizedRoute2.length;
|
|
15
|
+
bestTitle = child.title;
|
|
16
|
+
}
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const normalizedRoute = normalizeRoutePath(entry.route);
|
|
20
|
+
if (!isRouteActive(normalizedPath, normalizedRoute))
|
|
21
|
+
continue;
|
|
22
|
+
if (normalizedRoute.length <= bestRouteLength)
|
|
23
|
+
continue;
|
|
24
|
+
bestRouteLength = normalizedRoute.length;
|
|
25
|
+
bestTitle = entry.title;
|
|
26
|
+
}
|
|
27
|
+
return bestTitle ?? normalizedPath;
|
|
28
|
+
}
|