@shwfed/nuxt 0.1.68 → 0.1.70
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
|
@@ -101,6 +101,12 @@ interface ModuleOptions {
|
|
|
101
101
|
* - `{ type: 'route', to: string }`
|
|
102
102
|
* - `{ type: 'external', href: string }`
|
|
103
103
|
* - `{ type: 'logout' }`
|
|
104
|
+
* - `{ type: 'request', url: string, method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE', body?: unknown, query?: Record<string, unknown>, headers?: Record<string, string> }`
|
|
105
|
+
*
|
|
106
|
+
* 示例:
|
|
107
|
+
* - 维护任务:`{ type: 'request', url: '/maintenance/run', method: 'POST' }`
|
|
108
|
+
* - 清理缓存:`{ type: 'request', url: '/cache/clear', method: 'POST', body: { scope: 'all' } }`
|
|
109
|
+
* - 重建索引:`{ type: 'request', url: '/search/reindex', method: 'POST', query: { async: true }, headers: { 'X-Command-Source': 'palette' } }`
|
|
104
110
|
*
|
|
105
111
|
* @type DSL
|
|
106
112
|
*/
|
package/dist/module.json
CHANGED
|
@@ -20,7 +20,7 @@ import { commandActionSchema, executeCommandAction } from "../utils/command";
|
|
|
20
20
|
import { createPaletteItemValue, normalizeCommandsForPalette, splitNavigationForPalette } from "../utils/command-palette";
|
|
21
21
|
import { isRouteActive, normalizeRoutePath } from "../utils/route";
|
|
22
22
|
import { applyRootNavigationFallback } from "../utils/sidebar-fallback";
|
|
23
|
-
const { $dsl, $logout, $md } = useNuxtApp();
|
|
23
|
+
const { $dsl, $logout, $md, $api, $toast } = useNuxtApp();
|
|
24
24
|
const { t } = useI18n();
|
|
25
25
|
const route = useRoute();
|
|
26
26
|
const { tabs, active, tabList, activateTab, closeTab } = useNavigationTabs();
|
|
@@ -96,6 +96,14 @@ const getTabLabel = (tab) => {
|
|
|
96
96
|
}
|
|
97
97
|
return normalizedTab;
|
|
98
98
|
};
|
|
99
|
+
const activeTabLabel = computed(() => {
|
|
100
|
+
if (active.value === void 0)
|
|
101
|
+
return void 0;
|
|
102
|
+
return getTabLabel(active.value);
|
|
103
|
+
});
|
|
104
|
+
useHead(() => ({
|
|
105
|
+
title: activeTabLabel.value
|
|
106
|
+
}));
|
|
99
107
|
const profileName = computed(() => {
|
|
100
108
|
if (config.profile.name === void 0)
|
|
101
109
|
return t("profile");
|
|
@@ -179,9 +187,10 @@ const profileCommands = computed(() => {
|
|
|
179
187
|
return [];
|
|
180
188
|
}
|
|
181
189
|
});
|
|
182
|
-
const executeCommandEffect = (effect) => {
|
|
190
|
+
const executeCommandEffect = async (effect) => {
|
|
183
191
|
if (effect === void 0)
|
|
184
192
|
return false;
|
|
193
|
+
let action;
|
|
185
194
|
try {
|
|
186
195
|
let result;
|
|
187
196
|
try {
|
|
@@ -189,30 +198,40 @@ const executeCommandEffect = (effect) => {
|
|
|
189
198
|
} catch {
|
|
190
199
|
result = $dsl.evaluate`${normalizeEffectExpression(effect)}`();
|
|
191
200
|
}
|
|
192
|
-
|
|
193
|
-
executeCommandAction(action, {
|
|
194
|
-
logout: $logout
|
|
201
|
+
action = commandActionSchema.parse(result);
|
|
202
|
+
await executeCommandAction(action, {
|
|
203
|
+
logout: $logout,
|
|
204
|
+
request: async (requestAction) => $api(requestAction.url, {
|
|
205
|
+
method: requestAction.method,
|
|
206
|
+
body: requestAction.body,
|
|
207
|
+
query: requestAction.query,
|
|
208
|
+
headers: requestAction.headers
|
|
209
|
+
})
|
|
195
210
|
});
|
|
196
211
|
return true;
|
|
197
|
-
} catch {
|
|
212
|
+
} catch (error) {
|
|
213
|
+
if (action?.type === "request") {
|
|
214
|
+
const message = error instanceof Error && error.message.length > 0 ? error.message : "Request failed";
|
|
215
|
+
$toast.error(message);
|
|
216
|
+
}
|
|
198
217
|
return false;
|
|
199
218
|
}
|
|
200
219
|
};
|
|
201
|
-
const executeProfileCommand = (effect) => {
|
|
202
|
-
if (effect === void 0 || executeCommandEffect(effect))
|
|
220
|
+
const executeProfileCommand = async (effect) => {
|
|
221
|
+
if (effect === void 0 || await executeCommandEffect(effect))
|
|
203
222
|
ui.isProfileDropdownOpen = false;
|
|
204
223
|
};
|
|
205
224
|
const paletteNavigation = computed(() => splitNavigationForPalette(navigations.value));
|
|
206
225
|
const favoriteRoutesForPalette = computed(() => paletteNavigation.value.favoriteRoutes);
|
|
207
226
|
const navigationForPalette = computed(() => paletteNavigation.value.navigationEntries);
|
|
208
227
|
const commandForPalette = computed(() => normalizeCommandsForPalette(profileCommands.value));
|
|
209
|
-
const executePaletteItem = (item) => {
|
|
228
|
+
const executePaletteItem = async (item) => {
|
|
210
229
|
if (item.type === "route") {
|
|
211
230
|
activateTab(item.route);
|
|
212
231
|
ui.isCommandPaletteOpen = false;
|
|
213
232
|
return;
|
|
214
233
|
}
|
|
215
|
-
if (item.effect !== void 0 && !executeCommandEffect(item.effect))
|
|
234
|
+
if (item.effect !== void 0 && !await executeCommandEffect(item.effect))
|
|
216
235
|
return;
|
|
217
236
|
ui.isCommandPaletteOpen = false;
|
|
218
237
|
};
|
|
@@ -7,9 +7,25 @@ export declare const commandActionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
7
7
|
href: z.ZodString;
|
|
8
8
|
}, z.core.$strip>, z.ZodObject<{
|
|
9
9
|
type: z.ZodLiteral<"logout">;
|
|
10
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
11
|
+
type: z.ZodLiteral<"request">;
|
|
12
|
+
url: z.ZodString;
|
|
13
|
+
method: z.ZodOptional<z.ZodEnum<{
|
|
14
|
+
GET: "GET";
|
|
15
|
+
POST: "POST";
|
|
16
|
+
PUT: "PUT";
|
|
17
|
+
PATCH: "PATCH";
|
|
18
|
+
DELETE: "DELETE";
|
|
19
|
+
}>>;
|
|
20
|
+
body: z.ZodOptional<z.ZodUnknown>;
|
|
21
|
+
query: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
22
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
10
23
|
}, z.core.$strip>], "type">;
|
|
11
24
|
export type CommandAction = z.infer<typeof commandActionSchema>;
|
|
12
25
|
export type ExecuteCommandActionOptions = {
|
|
13
26
|
logout: () => void;
|
|
27
|
+
request: (action: Extract<CommandAction, {
|
|
28
|
+
type: 'request';
|
|
29
|
+
}>) => Promise<unknown>;
|
|
14
30
|
};
|
|
15
|
-
export declare const executeCommandAction: (action: CommandAction, options: ExecuteCommandActionOptions) => void
|
|
31
|
+
export declare const executeCommandAction: (action: CommandAction, options: ExecuteCommandActionOptions) => Promise<void>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { navigateTo } from "#app";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
const requestMethodSchema = z.enum(["GET", "POST", "PUT", "PATCH", "DELETE"]);
|
|
3
4
|
export const commandActionSchema = z.discriminatedUnion("type", [
|
|
4
5
|
z.object({
|
|
5
6
|
type: z.literal("route"),
|
|
@@ -11,9 +12,17 @@ export const commandActionSchema = z.discriminatedUnion("type", [
|
|
|
11
12
|
}),
|
|
12
13
|
z.object({
|
|
13
14
|
type: z.literal("logout")
|
|
15
|
+
}),
|
|
16
|
+
z.object({
|
|
17
|
+
type: z.literal("request"),
|
|
18
|
+
url: z.string(),
|
|
19
|
+
method: requestMethodSchema.optional(),
|
|
20
|
+
body: z.unknown().optional(),
|
|
21
|
+
query: z.record(z.string(), z.unknown()).optional(),
|
|
22
|
+
headers: z.record(z.string(), z.string()).optional()
|
|
14
23
|
})
|
|
15
24
|
]);
|
|
16
|
-
export const executeCommandAction = (action, options) => {
|
|
25
|
+
export const executeCommandAction = async (action, options) => {
|
|
17
26
|
switch (action.type) {
|
|
18
27
|
case "route":
|
|
19
28
|
navigateTo(action.to);
|
|
@@ -24,5 +33,8 @@ export const executeCommandAction = (action, options) => {
|
|
|
24
33
|
case "logout":
|
|
25
34
|
options.logout();
|
|
26
35
|
return;
|
|
36
|
+
case "request":
|
|
37
|
+
await options.request(action);
|
|
38
|
+
return;
|
|
27
39
|
}
|
|
28
40
|
};
|