imean-service-engine-htmx-plugin 1.0.1 → 1.2.0
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/README.md +66 -32
- package/dist/index.d.mts +133 -3
- package/dist/index.d.ts +133 -3
- package/dist/index.js +1398 -589
- package/dist/index.mjs +1399 -590
- package/docs/architecture.md +57 -11
- package/docs/quick-reference.md +12 -8
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,732 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsxs, jsx, Fragment } from 'hono/jsx/jsx-runtime';
|
|
2
2
|
import { PluginPriority, logger } from 'imean-service-engine';
|
|
3
|
+
import { getCookie } from 'hono/cookie';
|
|
3
4
|
|
|
4
5
|
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __esm = (fn, res) => function __init() {
|
|
8
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
9
|
+
};
|
|
5
10
|
var __export = (target, all) => {
|
|
6
11
|
for (var name in all)
|
|
7
12
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
13
|
};
|
|
14
|
+
var Button;
|
|
15
|
+
var init_Button = __esm({
|
|
16
|
+
"src/components/Button.tsx"() {
|
|
17
|
+
Button = (props) => {
|
|
18
|
+
const {
|
|
19
|
+
children,
|
|
20
|
+
variant = "primary",
|
|
21
|
+
size = "md",
|
|
22
|
+
disabled = false,
|
|
23
|
+
className = "",
|
|
24
|
+
hxGet,
|
|
25
|
+
hxPost,
|
|
26
|
+
hxPut,
|
|
27
|
+
hxDelete,
|
|
28
|
+
hxTarget,
|
|
29
|
+
hxSwap,
|
|
30
|
+
hxPushUrl,
|
|
31
|
+
hxIndicator,
|
|
32
|
+
hxConfirm,
|
|
33
|
+
hxHeaders,
|
|
34
|
+
...rest
|
|
35
|
+
} = props;
|
|
36
|
+
const baseClasses = "inline-flex items-center justify-center font-medium rounded-lg transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2";
|
|
37
|
+
const variantClasses = {
|
|
38
|
+
primary: "bg-blue-600 text-white hover:bg-blue-700 focus:ring-blue-500",
|
|
39
|
+
secondary: "bg-gray-200 text-gray-800 hover:bg-gray-300 focus:ring-gray-500",
|
|
40
|
+
danger: "bg-red-600 text-white hover:bg-red-700 focus:ring-red-500",
|
|
41
|
+
ghost: "bg-transparent text-gray-700 hover:bg-gray-100 focus:ring-gray-500"
|
|
42
|
+
};
|
|
43
|
+
const sizeClasses = {
|
|
44
|
+
sm: "px-3 py-1.5 text-sm",
|
|
45
|
+
md: "px-4 py-2 text-sm",
|
|
46
|
+
lg: "px-6 py-3 text-base"
|
|
47
|
+
};
|
|
48
|
+
const classes = `${baseClasses} ${variantClasses[variant]} ${sizeClasses[size]} ${disabled ? "opacity-50 cursor-not-allowed" : ""} ${className}`;
|
|
49
|
+
const htmxAttrs = {};
|
|
50
|
+
if (hxGet) htmxAttrs["hx-get"] = hxGet;
|
|
51
|
+
if (hxPost) htmxAttrs["hx-post"] = hxPost;
|
|
52
|
+
if (hxPut) htmxAttrs["hx-put"] = hxPut;
|
|
53
|
+
if (hxDelete) htmxAttrs["hx-delete"] = hxDelete;
|
|
54
|
+
if (hxTarget) htmxAttrs["hx-target"] = hxTarget;
|
|
55
|
+
if (hxSwap) htmxAttrs["hx-swap"] = hxSwap;
|
|
56
|
+
if (hxPushUrl !== void 0)
|
|
57
|
+
htmxAttrs["hx-push-url"] = hxPushUrl === true ? "true" : hxPushUrl;
|
|
58
|
+
if (hxIndicator) htmxAttrs["hx-indicator"] = hxIndicator;
|
|
59
|
+
if (hxConfirm) htmxAttrs["hx-confirm"] = hxConfirm;
|
|
60
|
+
if (hxHeaders) htmxAttrs["hx-headers"] = hxHeaders;
|
|
61
|
+
const Tag = hxGet || hxPost || hxPut || hxDelete ? "a" : "button";
|
|
62
|
+
const href = rest.href ?? hxGet ?? "#";
|
|
63
|
+
return /* @__PURE__ */ jsx(
|
|
64
|
+
Tag,
|
|
65
|
+
{
|
|
66
|
+
className: classes,
|
|
67
|
+
disabled,
|
|
68
|
+
href,
|
|
69
|
+
...htmxAttrs,
|
|
70
|
+
...rest,
|
|
71
|
+
children
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
var Card;
|
|
78
|
+
var init_Card = __esm({
|
|
79
|
+
"src/components/Card.tsx"() {
|
|
80
|
+
Card = (props) => {
|
|
81
|
+
const {
|
|
82
|
+
children,
|
|
83
|
+
title,
|
|
84
|
+
className = "",
|
|
85
|
+
shadow = true,
|
|
86
|
+
bordered = false,
|
|
87
|
+
noPadding = false
|
|
88
|
+
} = props;
|
|
89
|
+
const baseClasses = "bg-white rounded-lg";
|
|
90
|
+
const shadowClass = shadow ? "shadow-sm hover:shadow-md transition-shadow" : "";
|
|
91
|
+
const borderClass = bordered ? "border border-gray-200" : "";
|
|
92
|
+
const paddingClass = noPadding ? "" : "p-6";
|
|
93
|
+
return /* @__PURE__ */ jsxs(
|
|
94
|
+
"div",
|
|
95
|
+
{
|
|
96
|
+
className: `${baseClasses} ${shadowClass} ${borderClass} ${className}`,
|
|
97
|
+
children: [
|
|
98
|
+
title && /* @__PURE__ */ jsx("div", { className: "px-6 py-4 border-b border-gray-200", children: /* @__PURE__ */ jsx("h3", { className: "text-lg font-semibold text-gray-900", children: title }) }),
|
|
99
|
+
/* @__PURE__ */ jsx("div", { className: noPadding ? "" : paddingClass, children })
|
|
100
|
+
]
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
var Breadcrumb;
|
|
107
|
+
var init_Breadcrumb = __esm({
|
|
108
|
+
"src/components/Breadcrumb.tsx"() {
|
|
109
|
+
Breadcrumb = (props) => {
|
|
110
|
+
const { items } = props;
|
|
111
|
+
if (items.length === 0) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
return /* @__PURE__ */ jsx("nav", { className: "flex", "aria-label": "Breadcrumb", children: /* @__PURE__ */ jsx("ol", { className: "flex items-center space-x-2", children: items.map((item, index) => /* @__PURE__ */ jsxs("li", { className: "flex items-center", children: [
|
|
115
|
+
index > 0 && /* @__PURE__ */ jsx(
|
|
116
|
+
"svg",
|
|
117
|
+
{
|
|
118
|
+
className: "w-5 h-5 text-gray-400 mx-2",
|
|
119
|
+
fill: "currentColor",
|
|
120
|
+
viewBox: "0 0 20 20",
|
|
121
|
+
children: /* @__PURE__ */ jsx(
|
|
122
|
+
"path",
|
|
123
|
+
{
|
|
124
|
+
fillRule: "evenodd",
|
|
125
|
+
d: "M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z",
|
|
126
|
+
clipRule: "evenodd"
|
|
127
|
+
}
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
),
|
|
131
|
+
item.href ? /* @__PURE__ */ jsx(
|
|
132
|
+
"a",
|
|
133
|
+
{
|
|
134
|
+
href: item.href,
|
|
135
|
+
className: "text-sm font-medium text-gray-500 hover:text-gray-700",
|
|
136
|
+
"hx-get": item.href,
|
|
137
|
+
"hx-push-url": "true",
|
|
138
|
+
children: item.label
|
|
139
|
+
}
|
|
140
|
+
) : /* @__PURE__ */ jsx("span", { className: "text-sm font-medium text-gray-900", children: item.label })
|
|
141
|
+
] }, index)) }) });
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
var Header;
|
|
146
|
+
var init_Header = __esm({
|
|
147
|
+
"src/components/Header.tsx"() {
|
|
148
|
+
init_Breadcrumb();
|
|
149
|
+
Header = (props) => {
|
|
150
|
+
const { breadcrumbs = [], userInfo, sidebarCollapsed = false, logoutUrl } = props;
|
|
151
|
+
return /* @__PURE__ */ jsx("header", { className: "bg-white border-b border-gray-200 shadow-sm sticky top-0 z-40", children: /* @__PURE__ */ jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
152
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-4 flex-1 min-w-0", children: [
|
|
153
|
+
/* @__PURE__ */ jsx(
|
|
154
|
+
"a",
|
|
155
|
+
{
|
|
156
|
+
className: "p-2 rounded-lg hover:bg-gray-100 transition-colors inline-block flex-shrink-0",
|
|
157
|
+
title: sidebarCollapsed ? "\u5C55\u5F00\u4FA7\u8FB9\u680F" : "\u6298\u53E0\u4FA7\u8FB9\u680F",
|
|
158
|
+
"hx-get": "",
|
|
159
|
+
children: sidebarCollapsed ? (
|
|
160
|
+
// 展开图标(向右箭头)
|
|
161
|
+
/* @__PURE__ */ jsx(
|
|
162
|
+
"svg",
|
|
163
|
+
{
|
|
164
|
+
className: "w-5 h-5 text-gray-600",
|
|
165
|
+
fill: "none",
|
|
166
|
+
stroke: "currentColor",
|
|
167
|
+
viewBox: "0 0 24 24",
|
|
168
|
+
children: /* @__PURE__ */ jsx(
|
|
169
|
+
"path",
|
|
170
|
+
{
|
|
171
|
+
strokeLinecap: "round",
|
|
172
|
+
strokeLinejoin: "round",
|
|
173
|
+
strokeWidth: 2,
|
|
174
|
+
d: "M9 5l7 7-7 7"
|
|
175
|
+
}
|
|
176
|
+
)
|
|
177
|
+
}
|
|
178
|
+
)
|
|
179
|
+
) : (
|
|
180
|
+
// 折叠图标(三条横线)
|
|
181
|
+
/* @__PURE__ */ jsx(
|
|
182
|
+
"svg",
|
|
183
|
+
{
|
|
184
|
+
className: "w-5 h-5 text-gray-600",
|
|
185
|
+
fill: "none",
|
|
186
|
+
stroke: "currentColor",
|
|
187
|
+
viewBox: "0 0 24 24",
|
|
188
|
+
children: /* @__PURE__ */ jsx(
|
|
189
|
+
"path",
|
|
190
|
+
{
|
|
191
|
+
strokeLinecap: "round",
|
|
192
|
+
strokeLinejoin: "round",
|
|
193
|
+
strokeWidth: 2,
|
|
194
|
+
d: "M4 6h16M4 12h16M4 18h16"
|
|
195
|
+
}
|
|
196
|
+
)
|
|
197
|
+
}
|
|
198
|
+
)
|
|
199
|
+
)
|
|
200
|
+
}
|
|
201
|
+
),
|
|
202
|
+
breadcrumbs.length > 0 && /* @__PURE__ */ jsx(Breadcrumb, { items: breadcrumbs })
|
|
203
|
+
] }),
|
|
204
|
+
userInfo && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 flex-shrink-0", children: [
|
|
205
|
+
/* @__PURE__ */ jsxs("div", { className: "text-right hidden sm:block", children: [
|
|
206
|
+
userInfo.name && /* @__PURE__ */ jsx("div", { className: "text-sm font-medium text-gray-900", children: userInfo.name }),
|
|
207
|
+
userInfo.email && /* @__PURE__ */ jsx("div", { className: "text-xs text-gray-500", children: userInfo.email })
|
|
208
|
+
] }),
|
|
209
|
+
userInfo.avatar ? /* @__PURE__ */ jsx(
|
|
210
|
+
"img",
|
|
211
|
+
{
|
|
212
|
+
src: userInfo.avatar,
|
|
213
|
+
alt: userInfo.name || "\u7528\u6237",
|
|
214
|
+
className: "w-8 h-8 rounded-full"
|
|
215
|
+
}
|
|
216
|
+
) : /* @__PURE__ */ jsx("div", { className: "w-8 h-8 rounded-full bg-blue-600 flex items-center justify-center text-white text-sm font-medium", children: (userInfo.name || userInfo.email || "U").charAt(0).toUpperCase() }),
|
|
217
|
+
logoutUrl && /* @__PURE__ */ jsx(
|
|
218
|
+
"a",
|
|
219
|
+
{
|
|
220
|
+
href: logoutUrl,
|
|
221
|
+
"hx-get": logoutUrl,
|
|
222
|
+
"hx-target": "body",
|
|
223
|
+
"hx-swap": "outerHTML",
|
|
224
|
+
className: "p-2 rounded-lg hover:bg-gray-100 transition-colors",
|
|
225
|
+
title: "\u9000\u51FA\u767B\u5F55",
|
|
226
|
+
children: /* @__PURE__ */ jsx(
|
|
227
|
+
"svg",
|
|
228
|
+
{
|
|
229
|
+
className: "w-5 h-5 text-gray-600",
|
|
230
|
+
fill: "none",
|
|
231
|
+
stroke: "currentColor",
|
|
232
|
+
viewBox: "0 0 24 24",
|
|
233
|
+
children: /* @__PURE__ */ jsx(
|
|
234
|
+
"path",
|
|
235
|
+
{
|
|
236
|
+
strokeLinecap: "round",
|
|
237
|
+
strokeLinejoin: "round",
|
|
238
|
+
strokeWidth: 2,
|
|
239
|
+
d: "M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"
|
|
240
|
+
}
|
|
241
|
+
)
|
|
242
|
+
}
|
|
243
|
+
)
|
|
244
|
+
}
|
|
245
|
+
)
|
|
246
|
+
] })
|
|
247
|
+
] }) }) });
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
var LoadingBar;
|
|
252
|
+
var init_LoadingBar = __esm({
|
|
253
|
+
"src/components/LoadingBar.tsx"() {
|
|
254
|
+
LoadingBar = () => {
|
|
255
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
256
|
+
/* @__PURE__ */ jsx(
|
|
257
|
+
"div",
|
|
258
|
+
{
|
|
259
|
+
id: "loading-bar",
|
|
260
|
+
className: "fixed top-0 left-0 right-0 h-1 bg-transparent z-50 opacity-0 transition-opacity duration-200",
|
|
261
|
+
children: /* @__PURE__ */ jsx("div", { className: "h-full bg-gradient-to-r from-blue-500 via-blue-600 to-blue-500 loading-bar-progress" })
|
|
262
|
+
}
|
|
263
|
+
),
|
|
264
|
+
/* @__PURE__ */ jsx("style", { children: `
|
|
265
|
+
@keyframes loading-progress {
|
|
266
|
+
0% { transform: translateX(-100%); width: 0%; }
|
|
267
|
+
50% { width: 70%; }
|
|
268
|
+
100% { transform: translateX(100%); width: 100%; }
|
|
269
|
+
}
|
|
270
|
+
#loading-bar.htmx-request {
|
|
271
|
+
opacity: 1 !important;
|
|
272
|
+
}
|
|
273
|
+
#loading-bar.htmx-request .loading-bar-progress {
|
|
274
|
+
animation: loading-progress 1.5s ease-in-out infinite;
|
|
275
|
+
}
|
|
276
|
+
` })
|
|
277
|
+
] });
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
function renderNavItem(item, currentPath, collapsed = false, isChild = false) {
|
|
282
|
+
const isActive = currentPath === item.href || currentPath && currentPath.startsWith(item.href + "/");
|
|
283
|
+
const hasActiveChild = item.children?.some(
|
|
284
|
+
(child) => currentPath === child.href || currentPath && currentPath.startsWith(child.href + "/")
|
|
285
|
+
);
|
|
286
|
+
const navItemId = `nav-item-${item.href.replace(/[^a-zA-Z0-9]/g, "-")}`;
|
|
287
|
+
return /* @__PURE__ */ jsxs("li", { id: navItemId, className: "relative group", children: [
|
|
288
|
+
/* @__PURE__ */ jsxs(
|
|
289
|
+
"a",
|
|
290
|
+
{
|
|
291
|
+
href: item.href,
|
|
292
|
+
className: `flex items-center ${collapsed ? "justify-center px-2" : "px-4"} py-2 rounded-lg transition-colors ${isActive || hasActiveChild ? "bg-blue-600 text-white shadow-md" : "text-gray-300 hover:bg-gray-700 hover:text-white"}`,
|
|
293
|
+
"hx-get": item.href,
|
|
294
|
+
"hx-push-url": "true",
|
|
295
|
+
title: collapsed ? item.label : void 0,
|
|
296
|
+
children: [
|
|
297
|
+
item.icon && /* @__PURE__ */ jsx("span", { className: collapsed ? "" : "mr-2", children: item.icon }),
|
|
298
|
+
!collapsed && /* @__PURE__ */ jsx("span", { className: "whitespace-nowrap overflow-hidden text-ellipsis", children: item.label })
|
|
299
|
+
]
|
|
300
|
+
}
|
|
301
|
+
),
|
|
302
|
+
collapsed && /* @__PURE__ */ jsxs("div", { className: "absolute left-full ml-2 px-3 py-2 bg-gray-900 text-white text-sm rounded-lg shadow-lg opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all duration-200 pointer-events-none z-50 whitespace-nowrap", children: [
|
|
303
|
+
item.label,
|
|
304
|
+
/* @__PURE__ */ jsx("div", { className: "absolute right-full top-1/2 -translate-y-1/2 border-4 border-transparent border-r-gray-900" })
|
|
305
|
+
] }),
|
|
306
|
+
!collapsed && item.children && item.children.length > 0 && /* @__PURE__ */ jsx("ul", { className: "ml-4 mt-1 space-y-1", children: item.children.map((child) => {
|
|
307
|
+
const isChildActive = currentPath === child.href || currentPath && currentPath.startsWith(child.href + "/");
|
|
308
|
+
const childNavItemId = `nav-item-${child.href.replace(/[^a-zA-Z0-9]/g, "-")}`;
|
|
309
|
+
return /* @__PURE__ */ jsx(
|
|
310
|
+
"li",
|
|
311
|
+
{
|
|
312
|
+
id: childNavItemId,
|
|
313
|
+
className: "relative group",
|
|
314
|
+
children: /* @__PURE__ */ jsxs(
|
|
315
|
+
"a",
|
|
316
|
+
{
|
|
317
|
+
href: child.href,
|
|
318
|
+
className: `flex items-center px-4 py-2 rounded-lg text-sm transition-colors ${isChildActive ? "bg-blue-500 text-white" : "text-gray-400 hover:bg-gray-700 hover:text-white"}`,
|
|
319
|
+
"hx-get": child.href,
|
|
320
|
+
"hx-push-url": "true",
|
|
321
|
+
children: [
|
|
322
|
+
child.icon && /* @__PURE__ */ jsx("span", { className: "mr-2", children: child.icon }),
|
|
323
|
+
/* @__PURE__ */ jsx("span", { className: "whitespace-nowrap overflow-hidden text-ellipsis", children: child.label })
|
|
324
|
+
]
|
|
325
|
+
}
|
|
326
|
+
)
|
|
327
|
+
},
|
|
328
|
+
child.href
|
|
329
|
+
);
|
|
330
|
+
}) })
|
|
331
|
+
] }, item.href);
|
|
332
|
+
}
|
|
333
|
+
var init_NavItem = __esm({
|
|
334
|
+
"src/components/NavItem.tsx"() {
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
var BaseLayout, AdminLayout;
|
|
338
|
+
var init_Layout = __esm({
|
|
339
|
+
"src/components/Layout.tsx"() {
|
|
340
|
+
init_Header();
|
|
341
|
+
init_LoadingBar();
|
|
342
|
+
init_NavItem();
|
|
343
|
+
BaseLayout = (props) => {
|
|
344
|
+
return /* @__PURE__ */ jsxs("html", { children: [
|
|
345
|
+
/* @__PURE__ */ jsxs("head", { children: [
|
|
346
|
+
/* @__PURE__ */ jsx("meta", { charset: "UTF-8" }),
|
|
347
|
+
/* @__PURE__ */ jsx("meta", { name: "viewport", content: "width=device-width, initial-scale=1.0" }),
|
|
348
|
+
/* @__PURE__ */ jsx("title", { children: props.title }),
|
|
349
|
+
props.description && /* @__PURE__ */ jsx("meta", { name: "description", content: props.description }),
|
|
350
|
+
/* @__PURE__ */ jsx("script", { src: "https://unpkg.com/htmx.org@latest" }),
|
|
351
|
+
/* @__PURE__ */ jsx("script", { src: "https://unpkg.com/hyperscript.org@latest" }),
|
|
352
|
+
/* @__PURE__ */ jsx("script", { src: "https://cdn.tailwindcss.com" }),
|
|
353
|
+
/* @__PURE__ */ jsx(
|
|
354
|
+
"style",
|
|
355
|
+
{
|
|
356
|
+
dangerouslySetInnerHTML: {
|
|
357
|
+
__html: `
|
|
358
|
+
@keyframes fadeIn {
|
|
359
|
+
from { opacity: 0;}
|
|
360
|
+
to { opacity: 1;}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
@keyframes slideIn {
|
|
364
|
+
from { opacity: 0; transform: scale(0.95) translateY(-10px); }
|
|
365
|
+
to { opacity: 1; transform: scale(1) translateY(0); }
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
@keyframes slideInRight {
|
|
369
|
+
from { opacity: 0; transform: translateX(100%); }
|
|
370
|
+
to { opacity: 1; transform: translateX(0); }
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
@keyframes slideOutRight {
|
|
374
|
+
from { opacity: 1; transform: translateX(0); }
|
|
375
|
+
to { opacity: 0; transform: translateX(100%); }
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
@keyframes fadeOut {
|
|
379
|
+
from { opacity: 1; }
|
|
380
|
+
to { opacity: 0; }
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
@keyframes scaleOut {
|
|
384
|
+
from { opacity: 1; transform: scale(1) translateY(0); }
|
|
385
|
+
to { opacity: 0; transform: scale(0.95) translateY(-10px); }
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/* Dialog \u9000\u51FA\u52A8\u753B */
|
|
389
|
+
.dialog-exit {
|
|
390
|
+
animation: fadeOut 0.2s ease-in forwards !important;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
.dialog-content-exit {
|
|
394
|
+
animation: scaleOut 0.2s ease-in forwards !important;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/* ErrorAlert \u9000\u51FA\u52A8\u753B */
|
|
398
|
+
.error-alert-exit {
|
|
399
|
+
animation: slideOutRight 0.3s ease-in forwards, fadeOut 0.3s ease-in forwards;
|
|
400
|
+
}
|
|
401
|
+
`
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
)
|
|
405
|
+
] }),
|
|
406
|
+
/* @__PURE__ */ jsxs(
|
|
407
|
+
"body",
|
|
408
|
+
{
|
|
409
|
+
className: "bg-gray-50",
|
|
410
|
+
"hx-indicator": "#loading-bar",
|
|
411
|
+
"hx-target": "#main-content",
|
|
412
|
+
"hx-swap": "outerHTML",
|
|
413
|
+
children: [
|
|
414
|
+
/* @__PURE__ */ jsx(LoadingBar, {}),
|
|
415
|
+
props.children,
|
|
416
|
+
/* @__PURE__ */ jsx(
|
|
417
|
+
"div",
|
|
418
|
+
{
|
|
419
|
+
id: "error-container",
|
|
420
|
+
className: "fixed top-4 right-4 z-[200] w-full max-w-2xl px-4"
|
|
421
|
+
}
|
|
422
|
+
),
|
|
423
|
+
/* @__PURE__ */ jsx("div", { id: "dialog-container" })
|
|
424
|
+
]
|
|
425
|
+
}
|
|
426
|
+
)
|
|
427
|
+
] });
|
|
428
|
+
};
|
|
429
|
+
AdminLayout = (props) => {
|
|
430
|
+
const logo = props.adminContext.pluginOptions.logo;
|
|
431
|
+
const navItems = props.adminContext.pluginOptions.navigation;
|
|
432
|
+
const referer = props.adminContext.ctx.req.header("Referer");
|
|
433
|
+
let currentPath = props.adminContext.ctx.req.path;
|
|
434
|
+
if (referer) {
|
|
435
|
+
try {
|
|
436
|
+
const refererUrl = new URL(referer);
|
|
437
|
+
const method = props.adminContext.ctx.req.method;
|
|
438
|
+
if (["POST", "PUT", "DELETE"].includes(method)) {
|
|
439
|
+
currentPath = refererUrl.pathname;
|
|
440
|
+
}
|
|
441
|
+
} catch (e) {
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
const sidebarCollapsed = props.sidebarCollapsed || false;
|
|
445
|
+
const breadcrumbs = props.adminContext.breadcrumbs;
|
|
446
|
+
const userInfo = props.adminContext.userInfo;
|
|
447
|
+
const logoutUrl = props.adminContext.pluginOptions.authProvider?.logoutUrl;
|
|
448
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex h-screen", id: "main-content", children: [
|
|
449
|
+
/* @__PURE__ */ jsx(
|
|
450
|
+
"aside",
|
|
451
|
+
{
|
|
452
|
+
className: `${props.sidebarCollapsed ? "w-16" : "w-64"} bg-gradient-to-b from-gray-900 to-gray-800 text-white shadow-lg transition-all duration-300 ease-in-out overflow-hidden`,
|
|
453
|
+
children: /* @__PURE__ */ jsxs("div", { className: `${props.sidebarCollapsed ? "p-2" : "p-6"}`, children: [
|
|
454
|
+
!props.sidebarCollapsed && /* @__PURE__ */ jsx(Fragment, { children: logo ? /* @__PURE__ */ jsx("img", { src: logo, alt: "Logo", className: "h-10 mb-6" }) : /* @__PURE__ */ jsx("h1", { className: "text-xl font-bold mb-6 text-white whitespace-nowrap overflow-hidden text-ellipsis", children: props.adminContext.pluginOptions.title }) }),
|
|
455
|
+
/* @__PURE__ */ jsx("nav", { children: /* @__PURE__ */ jsx("ul", { className: "space-y-1", children: navItems && navItems.length > 0 ? navItems.map(
|
|
456
|
+
(item) => renderNavItem(
|
|
457
|
+
item,
|
|
458
|
+
currentPath,
|
|
459
|
+
props.sidebarCollapsed || false
|
|
460
|
+
)
|
|
461
|
+
) : /* @__PURE__ */ jsx(
|
|
462
|
+
"li",
|
|
463
|
+
{
|
|
464
|
+
className: `${props.sidebarCollapsed ? "px-2" : "px-4"} py-2 text-gray-400 text-sm`,
|
|
465
|
+
children: "\u6682\u65E0\u5BFC\u822A\u9879"
|
|
466
|
+
}
|
|
467
|
+
) }) })
|
|
468
|
+
] })
|
|
469
|
+
}
|
|
470
|
+
),
|
|
471
|
+
/* @__PURE__ */ jsxs("div", { className: "flex-1 flex flex-col overflow-hidden", children: [
|
|
472
|
+
/* @__PURE__ */ jsx(
|
|
473
|
+
Header,
|
|
474
|
+
{
|
|
475
|
+
breadcrumbs,
|
|
476
|
+
userInfo,
|
|
477
|
+
sidebarCollapsed: sidebarCollapsed || false,
|
|
478
|
+
logoutUrl
|
|
479
|
+
}
|
|
480
|
+
),
|
|
481
|
+
/* @__PURE__ */ jsx("main", { className: "flex-1 overflow-auto bg-gray-50", children: /* @__PURE__ */ jsx("div", { className: "p-6", children: props.children }) })
|
|
482
|
+
] })
|
|
483
|
+
] });
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
// src/utils/context.tsx
|
|
489
|
+
var context_exports = {};
|
|
490
|
+
__export(context_exports, {
|
|
491
|
+
HtmxAdminContext: () => HtmxAdminContext
|
|
492
|
+
});
|
|
493
|
+
var HtmxAdminContext;
|
|
494
|
+
var init_context = __esm({
|
|
495
|
+
"src/utils/context.tsx"() {
|
|
496
|
+
HtmxAdminContext = class {
|
|
497
|
+
/** 模块元数据 */
|
|
498
|
+
moduleMetadata;
|
|
499
|
+
/** 插件选项 */
|
|
500
|
+
pluginOptions;
|
|
501
|
+
/** 服务名(用于生成权限ID) */
|
|
502
|
+
serviceName;
|
|
503
|
+
/** Hono Context */
|
|
504
|
+
ctx;
|
|
505
|
+
/** 之前的模块名 */
|
|
506
|
+
previousModuleName;
|
|
507
|
+
/** 是否是片段请求(HTMX 请求) */
|
|
508
|
+
isFragment;
|
|
509
|
+
/** 是否是对话框请求 */
|
|
510
|
+
isDialog;
|
|
511
|
+
/** 用户信息 */
|
|
512
|
+
userInfo;
|
|
513
|
+
/** 通知队列 */
|
|
514
|
+
notifications = [];
|
|
515
|
+
/** 页面标题(用于 HX-Title 和页面展示) */
|
|
516
|
+
title = "";
|
|
517
|
+
/** 页面描述(用于SEO和页面展示) */
|
|
518
|
+
description = "";
|
|
519
|
+
/** 面包屑项 */
|
|
520
|
+
breadcrumbs = [];
|
|
521
|
+
/** 主要内容 */
|
|
522
|
+
content = null;
|
|
523
|
+
/** 需要重定向的 URL */
|
|
524
|
+
redirectUrl;
|
|
525
|
+
/** 是否需要刷新页面(用于 HX-Refresh) */
|
|
526
|
+
refresh = false;
|
|
527
|
+
constructor(ctx, userInfo, moduleMetadata, pluginOptions, serviceName = "") {
|
|
528
|
+
this.ctx = ctx;
|
|
529
|
+
this.userInfo = userInfo;
|
|
530
|
+
this.moduleMetadata = moduleMetadata;
|
|
531
|
+
this.pluginOptions = pluginOptions;
|
|
532
|
+
this.serviceName = serviceName;
|
|
533
|
+
const url = new URL(ctx.req.url);
|
|
534
|
+
this.isFragment = ctx.req.header("HX-Request") === "true";
|
|
535
|
+
this.isDialog = url.searchParams.get("dialog") === "true" || ctx.req.header("HX-Target") === "#dialog-container" || (ctx.req.header("Referer") || "").includes("dialog=true");
|
|
536
|
+
const referer = ctx.req.header("Referer");
|
|
537
|
+
this.previousModuleName = referer ? new URL(referer).pathname.replace(pluginOptions.prefix, "").split("/").pop() : void 0;
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* 发送通知
|
|
541
|
+
* 通知将在响应时通过 OOB 更新到错误容器
|
|
542
|
+
*/
|
|
543
|
+
sendNotification(type, title, message) {
|
|
544
|
+
this.notifications.push({ type, title, message });
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* 发送错误通知(便捷方法)
|
|
548
|
+
*/
|
|
549
|
+
sendError(title, message) {
|
|
550
|
+
this.sendNotification("error", title, message);
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* 发送警告通知(便捷方法)
|
|
554
|
+
*/
|
|
555
|
+
sendWarning(title, message) {
|
|
556
|
+
this.sendNotification("warning", title, message);
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* 发送信息通知(便捷方法)
|
|
560
|
+
*/
|
|
561
|
+
sendInfo(title, message) {
|
|
562
|
+
this.sendNotification("info", title, message);
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* 发送成功通知(便捷方法)
|
|
566
|
+
*/
|
|
567
|
+
sendSuccess(title, message) {
|
|
568
|
+
this.sendNotification("success", title, message);
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* 设置需要推送的 URL
|
|
572
|
+
* 用于 HX-Push-Url 响应头
|
|
573
|
+
*/
|
|
574
|
+
redirect(url) {
|
|
575
|
+
this.redirectUrl = url;
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* 设置需要刷新页面
|
|
579
|
+
* 用于 HX-Refresh 响应头
|
|
580
|
+
*/
|
|
581
|
+
setRefresh(refresh = true) {
|
|
582
|
+
this.refresh = refresh;
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* 检查是否有列表页面
|
|
586
|
+
* 封装 moduleMetadata 访问,避免直接访问内部属性
|
|
587
|
+
*/
|
|
588
|
+
hasList() {
|
|
589
|
+
return this.moduleMetadata.hasList;
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* 检查是否有详情页面
|
|
593
|
+
* 封装 moduleMetadata 访问,避免直接访问内部属性
|
|
594
|
+
*/
|
|
595
|
+
hasDetail() {
|
|
596
|
+
return this.moduleMetadata.hasDetail;
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* 检查是否有表单页面
|
|
600
|
+
* 封装 moduleMetadata 访问,避免直接访问内部属性
|
|
601
|
+
*/
|
|
602
|
+
hasForm() {
|
|
603
|
+
return this.moduleMetadata.hasForm;
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* 检查是否有自定义页面
|
|
607
|
+
* 封装 moduleMetadata 访问,避免直接访问内部属性
|
|
608
|
+
*/
|
|
609
|
+
hasCustom() {
|
|
610
|
+
return this.moduleMetadata.hasCustom;
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
// src/components/PermissionDenied.tsx
|
|
617
|
+
var PermissionDenied_exports = {};
|
|
618
|
+
__export(PermissionDenied_exports, {
|
|
619
|
+
PermissionDeniedContent: () => PermissionDeniedContent,
|
|
620
|
+
PermissionDeniedPage: () => PermissionDeniedPage
|
|
621
|
+
});
|
|
622
|
+
function PermissionDeniedContent(adminContext, operationId, fromPath, registeredOperations) {
|
|
623
|
+
let operationInfo = null;
|
|
624
|
+
if (operationId && registeredOperations) {
|
|
625
|
+
operationInfo = registeredOperations.find(
|
|
626
|
+
(op) => op.operationId === operationId
|
|
627
|
+
) || null;
|
|
628
|
+
}
|
|
629
|
+
const parts = operationId?.split(".") || [];
|
|
630
|
+
const operationType = parts[parts.length - 1] || "";
|
|
631
|
+
const moduleName = parts.length >= 2 ? parts[parts.length - 2] : "";
|
|
632
|
+
return /* @__PURE__ */ jsxs("div", { className: "text-center", children: [
|
|
633
|
+
/* @__PURE__ */ jsx("div", { className: "text-6xl mb-4", children: "\u{1F512}" }),
|
|
634
|
+
/* @__PURE__ */ jsx("h1", { className: "text-3xl font-bold text-gray-900 mb-2", children: "\u6743\u9650\u4E0D\u8DB3" }),
|
|
635
|
+
/* @__PURE__ */ jsx("p", { className: "text-gray-600 mb-8", children: "\u60A8\u5F53\u524D\u6CA1\u6709\u6743\u9650\u8BBF\u95EE\u6B64\u8D44\u6E90\u3002\u8BF7\u8054\u7CFB\u7BA1\u7406\u5458\u83B7\u53D6\u76F8\u5E94\u6743\u9650\u3002" }),
|
|
636
|
+
operationId && /* @__PURE__ */ jsxs("div", { className: "mb-8 p-4 bg-red-50 border border-red-200 rounded-lg text-left", children: [
|
|
637
|
+
/* @__PURE__ */ jsx("h3", { className: "text-lg font-semibold text-red-900 mb-2", children: "\u88AB\u62D2\u7EDD\u7684\u64CD\u4F5C" }),
|
|
638
|
+
/* @__PURE__ */ jsxs("div", { className: "space-y-2 text-sm", children: [
|
|
639
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
640
|
+
/* @__PURE__ */ jsx("span", { className: "font-medium text-gray-700", children: "\u64CD\u4F5CID:" }),
|
|
641
|
+
" ",
|
|
642
|
+
/* @__PURE__ */ jsx("code", { className: "px-2 py-1 bg-gray-100 rounded text-blue-600 font-mono", children: operationId })
|
|
643
|
+
] }),
|
|
644
|
+
operationInfo && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
645
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
646
|
+
/* @__PURE__ */ jsx("span", { className: "font-medium text-gray-700", children: "\u6A21\u5757:" }),
|
|
647
|
+
" ",
|
|
648
|
+
/* @__PURE__ */ jsx("span", { className: "text-gray-900", children: operationInfo.moduleTitle || moduleName })
|
|
649
|
+
] }),
|
|
650
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
651
|
+
/* @__PURE__ */ jsx("span", { className: "font-medium text-gray-700", children: "\u64CD\u4F5C\u7C7B\u578B:" }),
|
|
652
|
+
" ",
|
|
653
|
+
/* @__PURE__ */ jsx("span", { className: "px-2 py-1 bg-blue-100 text-blue-800 rounded-full text-xs font-semibold", children: getOperationTypeLabel(operationType) })
|
|
654
|
+
] }),
|
|
655
|
+
operationInfo.moduleDescription && /* @__PURE__ */ jsxs("div", { children: [
|
|
656
|
+
/* @__PURE__ */ jsx("span", { className: "font-medium text-gray-700", children: "\u6A21\u5757\u63CF\u8FF0:" }),
|
|
657
|
+
" ",
|
|
658
|
+
/* @__PURE__ */ jsx("span", { className: "text-gray-600", children: operationInfo.moduleDescription })
|
|
659
|
+
] }),
|
|
660
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
661
|
+
/* @__PURE__ */ jsx("span", { className: "font-medium text-gray-700", children: "\u8DEF\u7531\u8DEF\u5F84:" }),
|
|
662
|
+
" ",
|
|
663
|
+
/* @__PURE__ */ jsx("code", { className: "px-2 py-1 bg-gray-100 rounded text-gray-700 font-mono text-xs", children: operationInfo.routePath })
|
|
664
|
+
] })
|
|
665
|
+
] }),
|
|
666
|
+
fromPath && /* @__PURE__ */ jsxs("div", { children: [
|
|
667
|
+
/* @__PURE__ */ jsx("span", { className: "font-medium text-gray-700", children: "\u8BF7\u6C42\u8DEF\u5F84:" }),
|
|
668
|
+
" ",
|
|
669
|
+
/* @__PURE__ */ jsx("code", { className: "px-2 py-1 bg-gray-100 rounded text-gray-700 font-mono text-xs", children: fromPath })
|
|
670
|
+
] })
|
|
671
|
+
] })
|
|
672
|
+
] }),
|
|
673
|
+
/* @__PURE__ */ jsx("div", { className: "mt-8", children: /* @__PURE__ */ jsx(
|
|
674
|
+
Button,
|
|
675
|
+
{
|
|
676
|
+
variant: "secondary",
|
|
677
|
+
_: "on click set #dialog-container's innerHTML to ''",
|
|
678
|
+
children: "\u5173\u95ED"
|
|
679
|
+
}
|
|
680
|
+
) })
|
|
681
|
+
] });
|
|
682
|
+
}
|
|
683
|
+
function PermissionDeniedPage(adminContext, operationId, fromPath, registeredOperations) {
|
|
684
|
+
return /* @__PURE__ */ jsx(
|
|
685
|
+
BaseLayout,
|
|
686
|
+
{
|
|
687
|
+
title: `\u6743\u9650\u4E0D\u8DB3 - ${adminContext.pluginOptions.title}`,
|
|
688
|
+
description: "\u60A8\u6CA1\u6709\u6743\u9650\u8BBF\u95EE\u6B64\u8D44\u6E90",
|
|
689
|
+
children: /* @__PURE__ */ jsx("div", { id: "main-content", className: "min-h-screen flex items-center justify-center px-4", children: /* @__PURE__ */ jsxs(Card, { className: "max-w-2xl w-full p-8", children: [
|
|
690
|
+
/* @__PURE__ */ jsx(
|
|
691
|
+
PermissionDeniedContent,
|
|
692
|
+
{
|
|
693
|
+
adminContext,
|
|
694
|
+
operationId,
|
|
695
|
+
fromPath,
|
|
696
|
+
registeredOperations
|
|
697
|
+
}
|
|
698
|
+
),
|
|
699
|
+
adminContext.pluginOptions.authProvider?.loginUrl && !adminContext.userInfo && /* @__PURE__ */ jsx("div", { className: "mt-8 text-center", children: /* @__PURE__ */ jsx(
|
|
700
|
+
Button,
|
|
701
|
+
{
|
|
702
|
+
variant: "primary",
|
|
703
|
+
href: adminContext.pluginOptions.authProvider.loginUrl,
|
|
704
|
+
hxGet: adminContext.pluginOptions.authProvider.loginUrl,
|
|
705
|
+
hxTarget: "body",
|
|
706
|
+
hxSwap: "outerHTML",
|
|
707
|
+
children: "\u524D\u5F80\u767B\u5F55"
|
|
708
|
+
}
|
|
709
|
+
) })
|
|
710
|
+
] }) })
|
|
711
|
+
}
|
|
712
|
+
);
|
|
713
|
+
}
|
|
714
|
+
function getOperationTypeLabel(operationType) {
|
|
715
|
+
const labels = {
|
|
716
|
+
read: "\u67E5\u770B",
|
|
717
|
+
create: "\u521B\u5EFA",
|
|
718
|
+
edit: "\u7F16\u8F91",
|
|
719
|
+
delete: "\u5220\u9664"
|
|
720
|
+
};
|
|
721
|
+
return labels[operationType] || operationType;
|
|
722
|
+
}
|
|
723
|
+
var init_PermissionDenied = __esm({
|
|
724
|
+
"src/components/PermissionDenied.tsx"() {
|
|
725
|
+
init_Card();
|
|
726
|
+
init_Button();
|
|
727
|
+
init_Layout();
|
|
728
|
+
}
|
|
729
|
+
});
|
|
9
730
|
function safeRender(value) {
|
|
10
731
|
if (value === null || value === void 0) {
|
|
11
732
|
return null;
|
|
@@ -21,88 +742,10 @@ function safeRender(value) {
|
|
|
21
742
|
}
|
|
22
743
|
return value;
|
|
23
744
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
size = "md",
|
|
29
|
-
disabled = false,
|
|
30
|
-
className = "",
|
|
31
|
-
hxGet,
|
|
32
|
-
hxPost,
|
|
33
|
-
hxPut,
|
|
34
|
-
hxDelete,
|
|
35
|
-
hxTarget,
|
|
36
|
-
hxSwap,
|
|
37
|
-
hxPushUrl,
|
|
38
|
-
hxIndicator,
|
|
39
|
-
hxConfirm,
|
|
40
|
-
hxHeaders,
|
|
41
|
-
...rest
|
|
42
|
-
} = props;
|
|
43
|
-
const baseClasses = "inline-flex items-center justify-center font-medium rounded-lg transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2";
|
|
44
|
-
const variantClasses = {
|
|
45
|
-
primary: "bg-blue-600 text-white hover:bg-blue-700 focus:ring-blue-500",
|
|
46
|
-
secondary: "bg-gray-200 text-gray-800 hover:bg-gray-300 focus:ring-gray-500",
|
|
47
|
-
danger: "bg-red-600 text-white hover:bg-red-700 focus:ring-red-500",
|
|
48
|
-
ghost: "bg-transparent text-gray-700 hover:bg-gray-100 focus:ring-gray-500"
|
|
49
|
-
};
|
|
50
|
-
const sizeClasses = {
|
|
51
|
-
sm: "px-3 py-1.5 text-sm",
|
|
52
|
-
md: "px-4 py-2 text-sm",
|
|
53
|
-
lg: "px-6 py-3 text-base"
|
|
54
|
-
};
|
|
55
|
-
const classes = `${baseClasses} ${variantClasses[variant]} ${sizeClasses[size]} ${disabled ? "opacity-50 cursor-not-allowed" : ""} ${className}`;
|
|
56
|
-
const htmxAttrs = {};
|
|
57
|
-
if (hxGet) htmxAttrs["hx-get"] = hxGet;
|
|
58
|
-
if (hxPost) htmxAttrs["hx-post"] = hxPost;
|
|
59
|
-
if (hxPut) htmxAttrs["hx-put"] = hxPut;
|
|
60
|
-
if (hxDelete) htmxAttrs["hx-delete"] = hxDelete;
|
|
61
|
-
if (hxTarget) htmxAttrs["hx-target"] = hxTarget;
|
|
62
|
-
if (hxSwap) htmxAttrs["hx-swap"] = hxSwap;
|
|
63
|
-
if (hxPushUrl !== void 0)
|
|
64
|
-
htmxAttrs["hx-push-url"] = hxPushUrl === true ? "true" : hxPushUrl;
|
|
65
|
-
if (hxIndicator) htmxAttrs["hx-indicator"] = hxIndicator;
|
|
66
|
-
if (hxConfirm) htmxAttrs["hx-confirm"] = hxConfirm;
|
|
67
|
-
if (hxHeaders) htmxAttrs["hx-headers"] = hxHeaders;
|
|
68
|
-
const Tag = hxGet || hxPost || hxPut || hxDelete ? "a" : "button";
|
|
69
|
-
const href = rest.href ?? hxGet ?? "#";
|
|
70
|
-
return /* @__PURE__ */ jsx(
|
|
71
|
-
Tag,
|
|
72
|
-
{
|
|
73
|
-
className: classes,
|
|
74
|
-
disabled,
|
|
75
|
-
href,
|
|
76
|
-
...htmxAttrs,
|
|
77
|
-
...rest,
|
|
78
|
-
children
|
|
79
|
-
}
|
|
80
|
-
);
|
|
81
|
-
};
|
|
82
|
-
var Card = (props) => {
|
|
83
|
-
const {
|
|
84
|
-
children,
|
|
85
|
-
title,
|
|
86
|
-
className = "",
|
|
87
|
-
shadow = true,
|
|
88
|
-
bordered = false,
|
|
89
|
-
noPadding = false
|
|
90
|
-
} = props;
|
|
91
|
-
const baseClasses = "bg-white rounded-lg";
|
|
92
|
-
const shadowClass = shadow ? "shadow-sm hover:shadow-md transition-shadow" : "";
|
|
93
|
-
const borderClass = bordered ? "border border-gray-200" : "";
|
|
94
|
-
const paddingClass = noPadding ? "" : "p-6";
|
|
95
|
-
return /* @__PURE__ */ jsxs(
|
|
96
|
-
"div",
|
|
97
|
-
{
|
|
98
|
-
className: `${baseClasses} ${shadowClass} ${borderClass} ${className}`,
|
|
99
|
-
children: [
|
|
100
|
-
title && /* @__PURE__ */ jsx("div", { className: "px-6 py-4 border-b border-gray-200", children: /* @__PURE__ */ jsx("h3", { className: "text-lg font-semibold text-gray-900", children: title }) }),
|
|
101
|
-
/* @__PURE__ */ jsx("div", { className: noPadding ? "" : paddingClass, children })
|
|
102
|
-
]
|
|
103
|
-
}
|
|
104
|
-
);
|
|
105
|
-
};
|
|
745
|
+
|
|
746
|
+
// src/components/Detail.tsx
|
|
747
|
+
init_Button();
|
|
748
|
+
init_Card();
|
|
106
749
|
var PageHeader = (props) => {
|
|
107
750
|
const { title, description, actions, className = "" } = props;
|
|
108
751
|
return /* @__PURE__ */ jsx("div", { className: `mb-6 ${className}`, children: /* @__PURE__ */ jsxs("div", { className: "flex justify-between items-start", children: [
|
|
@@ -230,6 +873,14 @@ function DetailContent(props) {
|
|
|
230
873
|
);
|
|
231
874
|
}
|
|
232
875
|
|
|
876
|
+
// src/utils/module-name.ts
|
|
877
|
+
function extractModuleNameFromPath(basePath, prefix) {
|
|
878
|
+
const pathWithoutPrefix = basePath.replace(prefix, "");
|
|
879
|
+
const pathSegments = pathWithoutPrefix.split("/").filter(Boolean);
|
|
880
|
+
const modulePath = pathSegments[0] || "";
|
|
881
|
+
return modulePath.toLowerCase();
|
|
882
|
+
}
|
|
883
|
+
|
|
233
884
|
// src/utils/path.ts
|
|
234
885
|
var PathHelper = class {
|
|
235
886
|
basePath;
|
|
@@ -333,6 +984,22 @@ var PageModule = class {
|
|
|
333
984
|
];
|
|
334
985
|
return breadcrumbs;
|
|
335
986
|
}
|
|
987
|
+
/**
|
|
988
|
+
* 获取所需权限
|
|
989
|
+
* 子类可以重写此方法来声明页面所需的权限
|
|
990
|
+
*
|
|
991
|
+
* 返回值说明:
|
|
992
|
+
* - 返回空字符串 "" 或 null 或 undefined:表示开放访问(无需权限)
|
|
993
|
+
* - 返回权限字符串:表示需要该权限,如 "users.read", "users.*"
|
|
994
|
+
*
|
|
995
|
+
* 默认实现:返回空字符串(开放访问)
|
|
996
|
+
*
|
|
997
|
+
* @param ctx Hono Context(可选,用于根据请求动态决定权限)
|
|
998
|
+
* @returns 所需权限字符串,或空字符串/null/undefined 表示开放
|
|
999
|
+
*/
|
|
1000
|
+
getRequiredPermission(ctx) {
|
|
1001
|
+
return "";
|
|
1002
|
+
}
|
|
336
1003
|
/**
|
|
337
1004
|
* 处理请求的统一入口(由 RouteHandler 调用)
|
|
338
1005
|
* 默认实现:直接调用 render 方法
|
|
@@ -348,6 +1015,22 @@ var PageModule = class {
|
|
|
348
1015
|
var DetailPageModule = class extends PageModule {
|
|
349
1016
|
/** ID 字段名(默认 "id") */
|
|
350
1017
|
idField = "id";
|
|
1018
|
+
/**
|
|
1019
|
+
* 获取所需权限
|
|
1020
|
+
* 默认实现:返回 "{serviceName}.{moduleName}.read"
|
|
1021
|
+
* 子类可以重写此方法来自定义权限要求
|
|
1022
|
+
*
|
|
1023
|
+
* @param ctx Hono Context(可选)
|
|
1024
|
+
* @returns 所需权限字符串,或空字符串/null/undefined 表示开放
|
|
1025
|
+
*/
|
|
1026
|
+
getRequiredPermission(ctx) {
|
|
1027
|
+
const moduleName = extractModuleNameFromPath(
|
|
1028
|
+
this.context.moduleMetadata.basePath,
|
|
1029
|
+
this.context.pluginOptions.prefix
|
|
1030
|
+
);
|
|
1031
|
+
const servicePrefix = this.context.serviceName ? `${this.context.serviceName}.` : "";
|
|
1032
|
+
return `${servicePrefix}${moduleName}.read`;
|
|
1033
|
+
}
|
|
351
1034
|
/**
|
|
352
1035
|
* 获取字段标签(可选)
|
|
353
1036
|
* 子类可以重写此方法来自定义字段的中文标签
|
|
@@ -451,6 +1134,10 @@ var DetailPageModule = class extends PageModule {
|
|
|
451
1134
|
);
|
|
452
1135
|
}
|
|
453
1136
|
};
|
|
1137
|
+
|
|
1138
|
+
// src/components/Form.tsx
|
|
1139
|
+
init_Button();
|
|
1140
|
+
init_Card();
|
|
454
1141
|
var DateInput = (props) => {
|
|
455
1142
|
const {
|
|
456
1143
|
id,
|
|
@@ -952,6 +1639,33 @@ var FormPageModule = class extends PageModule {
|
|
|
952
1639
|
super();
|
|
953
1640
|
this.schema = schema;
|
|
954
1641
|
}
|
|
1642
|
+
/**
|
|
1643
|
+
* 获取所需权限
|
|
1644
|
+
* 根据是新建还是编辑返回不同的权限要求
|
|
1645
|
+
* - 新建:{serviceName}.{moduleName}.create
|
|
1646
|
+
* - 编辑:{serviceName}.{moduleName}.edit
|
|
1647
|
+
* 子类可以重写此方法来自定义权限要求
|
|
1648
|
+
*
|
|
1649
|
+
* @param ctx Hono Context(可选)
|
|
1650
|
+
* @returns 所需权限字符串,或空字符串/null/undefined 表示开放
|
|
1651
|
+
*/
|
|
1652
|
+
getRequiredPermission(ctx) {
|
|
1653
|
+
const moduleName = extractModuleNameFromPath(
|
|
1654
|
+
this.context.moduleMetadata.basePath,
|
|
1655
|
+
this.context.pluginOptions.prefix
|
|
1656
|
+
);
|
|
1657
|
+
const servicePrefix = this.context.serviceName ? `${this.context.serviceName}.` : "";
|
|
1658
|
+
if (ctx) {
|
|
1659
|
+
const url = new URL(ctx.req.url);
|
|
1660
|
+
const path = url.pathname;
|
|
1661
|
+
if (path.includes("/new")) {
|
|
1662
|
+
return `${servicePrefix}${moduleName}.create`;
|
|
1663
|
+
} else if (path.includes("/edit/")) {
|
|
1664
|
+
return `${servicePrefix}${moduleName}.edit`;
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
return `${servicePrefix}${moduleName}.edit`;
|
|
1668
|
+
}
|
|
955
1669
|
/**
|
|
956
1670
|
* 获取单条数据(编辑时使用)
|
|
957
1671
|
*/
|
|
@@ -1216,6 +1930,13 @@ var FormPageModule = class extends PageModule {
|
|
|
1216
1930
|
return await this.render(formData);
|
|
1217
1931
|
}
|
|
1218
1932
|
};
|
|
1933
|
+
|
|
1934
|
+
// src/components/ListContent.tsx
|
|
1935
|
+
init_Button();
|
|
1936
|
+
|
|
1937
|
+
// src/components/FilterCard.tsx
|
|
1938
|
+
init_Button();
|
|
1939
|
+
init_Card();
|
|
1219
1940
|
var FilterCard = (props) => {
|
|
1220
1941
|
const {
|
|
1221
1942
|
title,
|
|
@@ -1360,6 +2081,9 @@ var StatCard = (props) => {
|
|
|
1360
2081
|
}
|
|
1361
2082
|
);
|
|
1362
2083
|
};
|
|
2084
|
+
|
|
2085
|
+
// src/components/ActionButton.tsx
|
|
2086
|
+
init_Button();
|
|
1363
2087
|
var ActionButton = (props) => {
|
|
1364
2088
|
const { label, href, method, className = "", item } = props;
|
|
1365
2089
|
const hrefValue = typeof href === "function" ? href(item || {}) : href;
|
|
@@ -1382,10 +2106,17 @@ var ActionButton = (props) => {
|
|
|
1382
2106
|
}
|
|
1383
2107
|
);
|
|
1384
2108
|
};
|
|
2109
|
+
|
|
2110
|
+
// src/components/Table.tsx
|
|
2111
|
+
init_Button();
|
|
2112
|
+
init_Card();
|
|
1385
2113
|
var EmptyState = (props) => {
|
|
1386
2114
|
const { message = "\u6682\u65E0\u6570\u636E", children } = props;
|
|
1387
2115
|
return /* @__PURE__ */ jsx("div", { className: "text-center py-12", children: children || /* @__PURE__ */ jsx("p", { className: "text-gray-500 text-sm", children: message }) });
|
|
1388
2116
|
};
|
|
2117
|
+
|
|
2118
|
+
// src/components/Pagination.tsx
|
|
2119
|
+
init_Button();
|
|
1389
2120
|
var Pagination = (props) => {
|
|
1390
2121
|
const {
|
|
1391
2122
|
page,
|
|
@@ -1716,6 +2447,22 @@ function parseListParams(ctx) {
|
|
|
1716
2447
|
var ListPageModule = class extends PageModule {
|
|
1717
2448
|
/** ID 字段名(默认 "id") */
|
|
1718
2449
|
idField = "id";
|
|
2450
|
+
/**
|
|
2451
|
+
* 获取所需权限
|
|
2452
|
+
* 默认实现:返回 "{serviceName}.{moduleName}.read"
|
|
2453
|
+
* 子类可以重写此方法来自定义权限要求
|
|
2454
|
+
*
|
|
2455
|
+
* @param ctx Hono Context(可选)
|
|
2456
|
+
* @returns 所需权限字符串,或空字符串/null/undefined 表示开放
|
|
2457
|
+
*/
|
|
2458
|
+
getRequiredPermission(ctx) {
|
|
2459
|
+
const moduleName = extractModuleNameFromPath(
|
|
2460
|
+
this.context.moduleMetadata.basePath,
|
|
2461
|
+
this.context.pluginOptions.prefix
|
|
2462
|
+
);
|
|
2463
|
+
const servicePrefix = this.context.serviceName ? `${this.context.serviceName}.` : "";
|
|
2464
|
+
return `${servicePrefix}${moduleName}.read`;
|
|
2465
|
+
}
|
|
1719
2466
|
/**
|
|
1720
2467
|
* 获取列表数据
|
|
1721
2468
|
*/
|
|
@@ -1965,74 +2712,6 @@ var MemoryListDatasource = class {
|
|
|
1965
2712
|
return newItem;
|
|
1966
2713
|
}
|
|
1967
2714
|
};
|
|
1968
|
-
var Dialog = (props) => {
|
|
1969
|
-
const {
|
|
1970
|
-
title,
|
|
1971
|
-
children,
|
|
1972
|
-
showClose = true,
|
|
1973
|
-
closeUrl,
|
|
1974
|
-
className = "",
|
|
1975
|
-
size = "lg"
|
|
1976
|
-
} = props;
|
|
1977
|
-
const sizeClasses = {
|
|
1978
|
-
sm: "max-w-md",
|
|
1979
|
-
md: "max-w-lg",
|
|
1980
|
-
lg: "max-w-2xl",
|
|
1981
|
-
xl: "max-w-4xl",
|
|
1982
|
-
full: "max-w-7xl"
|
|
1983
|
-
};
|
|
1984
|
-
return /* @__PURE__ */ jsx(
|
|
1985
|
-
"div",
|
|
1986
|
-
{
|
|
1987
|
-
className: "fixed inset-0 bg-black bg-opacity-50 z-[100] flex items-center justify-center p-4 dialog-backdrop",
|
|
1988
|
-
style: {
|
|
1989
|
-
animation: "fadeIn 0.2s ease-out"
|
|
1990
|
-
},
|
|
1991
|
-
_: "on click if event.target is me \r\n add .dialog-exit to me\r\n add .dialog-content-exit to .dialog-content\r\n wait 200ms\r\n set #dialog-container's innerHTML to '' end",
|
|
1992
|
-
children: /* @__PURE__ */ jsxs(
|
|
1993
|
-
"div",
|
|
1994
|
-
{
|
|
1995
|
-
className: `bg-gray-50 rounded-lg shadow-xl ${sizeClasses[size]} w-full max-h-[90vh] overflow-hidden flex flex-col dialog-content ${className}`,
|
|
1996
|
-
style: {
|
|
1997
|
-
animation: "slideIn 0.3s ease-out"
|
|
1998
|
-
},
|
|
1999
|
-
_: "on click call event.stopPropagation()",
|
|
2000
|
-
children: [
|
|
2001
|
-
(title || showClose) && /* @__PURE__ */ jsxs("div", { className: "px-6 py-4 border-b border-gray-200 bg-white flex items-center justify-between", children: [
|
|
2002
|
-
title && /* @__PURE__ */ jsx("h3", { className: "text-lg font-semibold text-gray-900", children: title }),
|
|
2003
|
-
showClose && /* @__PURE__ */ jsx(
|
|
2004
|
-
"button",
|
|
2005
|
-
{
|
|
2006
|
-
className: "text-gray-400 hover:text-gray-600 transition-colors",
|
|
2007
|
-
_: "on click \r\n add .dialog-exit to .dialog-backdrop\r\n add .dialog-content-exit to .dialog-content\r\n wait 200ms\r\n set #dialog-container's innerHTML to '' end",
|
|
2008
|
-
children: /* @__PURE__ */ jsx(
|
|
2009
|
-
"svg",
|
|
2010
|
-
{
|
|
2011
|
-
className: "w-6 h-6",
|
|
2012
|
-
fill: "none",
|
|
2013
|
-
stroke: "currentColor",
|
|
2014
|
-
viewBox: "0 0 24 24",
|
|
2015
|
-
children: /* @__PURE__ */ jsx(
|
|
2016
|
-
"path",
|
|
2017
|
-
{
|
|
2018
|
-
strokeLinecap: "round",
|
|
2019
|
-
strokeLinejoin: "round",
|
|
2020
|
-
strokeWidth: 2,
|
|
2021
|
-
d: "M6 18L18 6M6 6l12 12"
|
|
2022
|
-
}
|
|
2023
|
-
)
|
|
2024
|
-
}
|
|
2025
|
-
)
|
|
2026
|
-
}
|
|
2027
|
-
)
|
|
2028
|
-
] }),
|
|
2029
|
-
/* @__PURE__ */ jsx("div", { className: "flex-1 overflow-y-auto p-6 bg-gray-50", children })
|
|
2030
|
-
]
|
|
2031
|
-
}
|
|
2032
|
-
)
|
|
2033
|
-
}
|
|
2034
|
-
);
|
|
2035
|
-
};
|
|
2036
2715
|
var ErrorAlert = (props) => {
|
|
2037
2716
|
const {
|
|
2038
2717
|
title,
|
|
@@ -2119,466 +2798,343 @@ var ErrorAlert = (props) => {
|
|
|
2119
2798
|
{
|
|
2120
2799
|
strokeLinecap: "round",
|
|
2121
2800
|
strokeLinejoin: "round",
|
|
2122
|
-
strokeWidth: 2,
|
|
2123
|
-
d: "M6 18L18 6M6 6l12 12"
|
|
2124
|
-
}
|
|
2125
|
-
)
|
|
2126
|
-
}
|
|
2127
|
-
)
|
|
2128
|
-
}
|
|
2129
|
-
)
|
|
2130
|
-
] })
|
|
2131
|
-
}
|
|
2132
|
-
);
|
|
2133
|
-
};
|
|
2134
|
-
var Breadcrumb = (props) => {
|
|
2135
|
-
const { items } = props;
|
|
2136
|
-
if (items.length === 0) {
|
|
2137
|
-
return null;
|
|
2138
|
-
}
|
|
2139
|
-
return /* @__PURE__ */ jsx("nav", { className: "flex", "aria-label": "Breadcrumb", children: /* @__PURE__ */ jsx("ol", { className: "flex items-center space-x-2", children: items.map((item, index) => /* @__PURE__ */ jsxs("li", { className: "flex items-center", children: [
|
|
2140
|
-
index > 0 && /* @__PURE__ */ jsx(
|
|
2141
|
-
"svg",
|
|
2142
|
-
{
|
|
2143
|
-
className: "w-5 h-5 text-gray-400 mx-2",
|
|
2144
|
-
fill: "currentColor",
|
|
2145
|
-
viewBox: "0 0 20 20",
|
|
2146
|
-
children: /* @__PURE__ */ jsx(
|
|
2147
|
-
"path",
|
|
2148
|
-
{
|
|
2149
|
-
fillRule: "evenodd",
|
|
2150
|
-
d: "M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z",
|
|
2151
|
-
clipRule: "evenodd"
|
|
2152
|
-
}
|
|
2153
|
-
)
|
|
2154
|
-
}
|
|
2155
|
-
),
|
|
2156
|
-
item.href ? /* @__PURE__ */ jsx(
|
|
2157
|
-
"a",
|
|
2158
|
-
{
|
|
2159
|
-
href: item.href,
|
|
2160
|
-
className: "text-sm font-medium text-gray-500 hover:text-gray-700",
|
|
2161
|
-
"hx-get": item.href,
|
|
2162
|
-
"hx-push-url": "true",
|
|
2163
|
-
children: item.label
|
|
2164
|
-
}
|
|
2165
|
-
) : /* @__PURE__ */ jsx("span", { className: "text-sm font-medium text-gray-900", children: item.label })
|
|
2166
|
-
] }, index)) }) });
|
|
2167
|
-
};
|
|
2168
|
-
var Header = (props) => {
|
|
2169
|
-
const { breadcrumbs = [], userInfo, sidebarCollapsed = false } = props;
|
|
2170
|
-
return /* @__PURE__ */ jsx("header", { className: "bg-white border-b border-gray-200 shadow-sm sticky top-0 z-40", children: /* @__PURE__ */ jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
2171
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-4 flex-1 min-w-0", children: [
|
|
2172
|
-
/* @__PURE__ */ jsx(
|
|
2173
|
-
"a",
|
|
2174
|
-
{
|
|
2175
|
-
className: "p-2 rounded-lg hover:bg-gray-100 transition-colors inline-block flex-shrink-0",
|
|
2176
|
-
title: sidebarCollapsed ? "\u5C55\u5F00\u4FA7\u8FB9\u680F" : "\u6298\u53E0\u4FA7\u8FB9\u680F",
|
|
2177
|
-
"hx-get": "",
|
|
2178
|
-
children: sidebarCollapsed ? (
|
|
2179
|
-
// 展开图标(向右箭头)
|
|
2180
|
-
/* @__PURE__ */ jsx(
|
|
2181
|
-
"svg",
|
|
2182
|
-
{
|
|
2183
|
-
className: "w-5 h-5 text-gray-600",
|
|
2184
|
-
fill: "none",
|
|
2185
|
-
stroke: "currentColor",
|
|
2186
|
-
viewBox: "0 0 24 24",
|
|
2187
|
-
children: /* @__PURE__ */ jsx(
|
|
2188
|
-
"path",
|
|
2189
|
-
{
|
|
2190
|
-
strokeLinecap: "round",
|
|
2191
|
-
strokeLinejoin: "round",
|
|
2192
|
-
strokeWidth: 2,
|
|
2193
|
-
d: "M9 5l7 7-7 7"
|
|
2194
|
-
}
|
|
2195
|
-
)
|
|
2196
|
-
}
|
|
2197
|
-
)
|
|
2198
|
-
) : (
|
|
2199
|
-
// 折叠图标(三条横线)
|
|
2200
|
-
/* @__PURE__ */ jsx(
|
|
2201
|
-
"svg",
|
|
2202
|
-
{
|
|
2203
|
-
className: "w-5 h-5 text-gray-600",
|
|
2204
|
-
fill: "none",
|
|
2205
|
-
stroke: "currentColor",
|
|
2206
|
-
viewBox: "0 0 24 24",
|
|
2207
|
-
children: /* @__PURE__ */ jsx(
|
|
2208
|
-
"path",
|
|
2209
|
-
{
|
|
2210
|
-
strokeLinecap: "round",
|
|
2211
|
-
strokeLinejoin: "round",
|
|
2212
|
-
strokeWidth: 2,
|
|
2213
|
-
d: "M4 6h16M4 12h16M4 18h16"
|
|
2214
|
-
}
|
|
2215
|
-
)
|
|
2216
|
-
}
|
|
2217
|
-
)
|
|
2218
|
-
)
|
|
2219
|
-
}
|
|
2220
|
-
),
|
|
2221
|
-
breadcrumbs.length > 0 && /* @__PURE__ */ jsx(Breadcrumb, { items: breadcrumbs })
|
|
2222
|
-
] }),
|
|
2223
|
-
userInfo && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 flex-shrink-0", children: [
|
|
2224
|
-
/* @__PURE__ */ jsxs("div", { className: "text-right hidden sm:block", children: [
|
|
2225
|
-
userInfo.name && /* @__PURE__ */ jsx("div", { className: "text-sm font-medium text-gray-900", children: userInfo.name }),
|
|
2226
|
-
userInfo.email && /* @__PURE__ */ jsx("div", { className: "text-xs text-gray-500", children: userInfo.email })
|
|
2227
|
-
] }),
|
|
2228
|
-
userInfo.avatar ? /* @__PURE__ */ jsx(
|
|
2229
|
-
"img",
|
|
2230
|
-
{
|
|
2231
|
-
src: userInfo.avatar,
|
|
2232
|
-
alt: userInfo.name || "\u7528\u6237",
|
|
2233
|
-
className: "w-8 h-8 rounded-full"
|
|
2234
|
-
}
|
|
2235
|
-
) : /* @__PURE__ */ jsx("div", { className: "w-8 h-8 rounded-full bg-blue-600 flex items-center justify-center text-white text-sm font-medium", children: (userInfo.name || userInfo.email || "U").charAt(0).toUpperCase() })
|
|
2236
|
-
] })
|
|
2237
|
-
] }) }) });
|
|
2238
|
-
};
|
|
2239
|
-
var LoadingBar = () => {
|
|
2240
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2241
|
-
/* @__PURE__ */ jsx(
|
|
2242
|
-
"div",
|
|
2243
|
-
{
|
|
2244
|
-
id: "loading-bar",
|
|
2245
|
-
className: "fixed top-0 left-0 right-0 h-1 bg-transparent z-50 opacity-0 transition-opacity duration-200",
|
|
2246
|
-
children: /* @__PURE__ */ jsx("div", { className: "h-full bg-gradient-to-r from-blue-500 via-blue-600 to-blue-500 loading-bar-progress" })
|
|
2247
|
-
}
|
|
2248
|
-
),
|
|
2249
|
-
/* @__PURE__ */ jsx("style", { children: `
|
|
2250
|
-
@keyframes loading-progress {
|
|
2251
|
-
0% { transform: translateX(-100%); width: 0%; }
|
|
2252
|
-
50% { width: 70%; }
|
|
2253
|
-
100% { transform: translateX(100%); width: 100%; }
|
|
2254
|
-
}
|
|
2255
|
-
#loading-bar.htmx-request {
|
|
2256
|
-
opacity: 1 !important;
|
|
2257
|
-
}
|
|
2258
|
-
#loading-bar.htmx-request .loading-bar-progress {
|
|
2259
|
-
animation: loading-progress 1.5s ease-in-out infinite;
|
|
2260
|
-
}
|
|
2261
|
-
` })
|
|
2262
|
-
] });
|
|
2263
|
-
};
|
|
2264
|
-
function renderNavItem(item, currentPath, collapsed = false, isChild = false) {
|
|
2265
|
-
const isActive = currentPath === item.href || currentPath && currentPath.startsWith(item.href + "/");
|
|
2266
|
-
const hasActiveChild = item.children?.some(
|
|
2267
|
-
(child) => currentPath === child.href || currentPath && currentPath.startsWith(child.href + "/")
|
|
2268
|
-
);
|
|
2269
|
-
const navItemId = `nav-item-${item.href.replace(/[^a-zA-Z0-9]/g, "-")}`;
|
|
2270
|
-
return /* @__PURE__ */ jsxs("li", { id: navItemId, className: "relative group", children: [
|
|
2271
|
-
/* @__PURE__ */ jsxs(
|
|
2272
|
-
"a",
|
|
2273
|
-
{
|
|
2274
|
-
href: item.href,
|
|
2275
|
-
className: `flex items-center ${collapsed ? "justify-center px-2" : "px-4"} py-2 rounded-lg transition-colors ${isActive || hasActiveChild ? "bg-blue-600 text-white shadow-md" : "text-gray-300 hover:bg-gray-700 hover:text-white"}`,
|
|
2276
|
-
"hx-get": item.href,
|
|
2277
|
-
"hx-push-url": "true",
|
|
2278
|
-
title: collapsed ? item.label : void 0,
|
|
2279
|
-
children: [
|
|
2280
|
-
item.icon && /* @__PURE__ */ jsx("span", { className: collapsed ? "" : "mr-2", children: item.icon }),
|
|
2281
|
-
!collapsed && /* @__PURE__ */ jsx("span", { className: "whitespace-nowrap overflow-hidden text-ellipsis", children: item.label })
|
|
2282
|
-
]
|
|
2283
|
-
}
|
|
2284
|
-
),
|
|
2285
|
-
collapsed && /* @__PURE__ */ jsxs("div", { className: "absolute left-full ml-2 px-3 py-2 bg-gray-900 text-white text-sm rounded-lg shadow-lg opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all duration-200 pointer-events-none z-50 whitespace-nowrap", children: [
|
|
2286
|
-
item.label,
|
|
2287
|
-
/* @__PURE__ */ jsx("div", { className: "absolute right-full top-1/2 -translate-y-1/2 border-4 border-transparent border-r-gray-900" })
|
|
2288
|
-
] }),
|
|
2289
|
-
!collapsed && item.children && item.children.length > 0 && /* @__PURE__ */ jsx("ul", { className: "ml-4 mt-1 space-y-1", children: item.children.map((child) => {
|
|
2290
|
-
const isChildActive = currentPath === child.href || currentPath && currentPath.startsWith(child.href + "/");
|
|
2291
|
-
const childNavItemId = `nav-item-${child.href.replace(/[^a-zA-Z0-9]/g, "-")}`;
|
|
2292
|
-
return /* @__PURE__ */ jsx(
|
|
2293
|
-
"li",
|
|
2294
|
-
{
|
|
2295
|
-
id: childNavItemId,
|
|
2296
|
-
className: "relative group",
|
|
2297
|
-
children: /* @__PURE__ */ jsxs(
|
|
2298
|
-
"a",
|
|
2299
|
-
{
|
|
2300
|
-
href: child.href,
|
|
2301
|
-
className: `flex items-center px-4 py-2 rounded-lg text-sm transition-colors ${isChildActive ? "bg-blue-500 text-white" : "text-gray-400 hover:bg-gray-700 hover:text-white"}`,
|
|
2302
|
-
"hx-get": child.href,
|
|
2303
|
-
"hx-push-url": "true",
|
|
2304
|
-
children: [
|
|
2305
|
-
child.icon && /* @__PURE__ */ jsx("span", { className: "mr-2", children: child.icon }),
|
|
2306
|
-
/* @__PURE__ */ jsx("span", { className: "whitespace-nowrap overflow-hidden text-ellipsis", children: child.label })
|
|
2307
|
-
]
|
|
2308
|
-
}
|
|
2309
|
-
)
|
|
2310
|
-
},
|
|
2311
|
-
child.href
|
|
2312
|
-
);
|
|
2313
|
-
}) })
|
|
2314
|
-
] }, item.href);
|
|
2315
|
-
}
|
|
2316
|
-
var BaseLayout = (props) => {
|
|
2317
|
-
return /* @__PURE__ */ jsxs("html", { children: [
|
|
2318
|
-
/* @__PURE__ */ jsxs("head", { children: [
|
|
2319
|
-
/* @__PURE__ */ jsx("meta", { charset: "UTF-8" }),
|
|
2320
|
-
/* @__PURE__ */ jsx("meta", { name: "viewport", content: "width=device-width, initial-scale=1.0" }),
|
|
2321
|
-
/* @__PURE__ */ jsx("title", { children: props.title }),
|
|
2322
|
-
props.description && /* @__PURE__ */ jsx("meta", { name: "description", content: props.description }),
|
|
2323
|
-
/* @__PURE__ */ jsx("script", { src: "https://unpkg.com/htmx.org@latest" }),
|
|
2324
|
-
/* @__PURE__ */ jsx("script", { src: "https://unpkg.com/hyperscript.org@latest" }),
|
|
2325
|
-
/* @__PURE__ */ jsx("script", { src: "https://cdn.tailwindcss.com" }),
|
|
2326
|
-
/* @__PURE__ */ jsx(
|
|
2327
|
-
"style",
|
|
2328
|
-
{
|
|
2329
|
-
dangerouslySetInnerHTML: {
|
|
2330
|
-
__html: `
|
|
2331
|
-
@keyframes fadeIn {
|
|
2332
|
-
from { opacity: 0;}
|
|
2333
|
-
to { opacity: 1;}
|
|
2334
|
-
}
|
|
2335
|
-
|
|
2336
|
-
@keyframes slideIn {
|
|
2337
|
-
from { opacity: 0; transform: scale(0.95) translateY(-10px); }
|
|
2338
|
-
to { opacity: 1; transform: scale(1) translateY(0); }
|
|
2339
|
-
}
|
|
2340
|
-
|
|
2341
|
-
@keyframes slideInRight {
|
|
2342
|
-
from { opacity: 0; transform: translateX(100%); }
|
|
2343
|
-
to { opacity: 1; transform: translateX(0); }
|
|
2344
|
-
}
|
|
2345
|
-
|
|
2346
|
-
@keyframes slideOutRight {
|
|
2347
|
-
from { opacity: 1; transform: translateX(0); }
|
|
2348
|
-
to { opacity: 0; transform: translateX(100%); }
|
|
2349
|
-
}
|
|
2350
|
-
|
|
2351
|
-
@keyframes fadeOut {
|
|
2352
|
-
from { opacity: 1; }
|
|
2353
|
-
to { opacity: 0; }
|
|
2354
|
-
}
|
|
2355
|
-
|
|
2356
|
-
@keyframes scaleOut {
|
|
2357
|
-
from { opacity: 1; transform: scale(1) translateY(0); }
|
|
2358
|
-
to { opacity: 0; transform: scale(0.95) translateY(-10px); }
|
|
2359
|
-
}
|
|
2360
|
-
|
|
2361
|
-
/* Dialog \u9000\u51FA\u52A8\u753B */
|
|
2362
|
-
.dialog-exit {
|
|
2363
|
-
animation: fadeOut 0.2s ease-in forwards !important;
|
|
2364
|
-
}
|
|
2365
|
-
|
|
2366
|
-
.dialog-content-exit {
|
|
2367
|
-
animation: scaleOut 0.2s ease-in forwards !important;
|
|
2368
|
-
}
|
|
2369
|
-
|
|
2370
|
-
/* ErrorAlert \u9000\u51FA\u52A8\u753B */
|
|
2371
|
-
.error-alert-exit {
|
|
2372
|
-
animation: slideOutRight 0.3s ease-in forwards, fadeOut 0.3s ease-in forwards;
|
|
2373
|
-
}
|
|
2374
|
-
`
|
|
2801
|
+
strokeWidth: 2,
|
|
2802
|
+
d: "M6 18L18 6M6 6l12 12"
|
|
2803
|
+
}
|
|
2804
|
+
)
|
|
2805
|
+
}
|
|
2806
|
+
)
|
|
2375
2807
|
}
|
|
2376
|
-
|
|
2377
|
-
)
|
|
2378
|
-
] }),
|
|
2379
|
-
/* @__PURE__ */ jsxs(
|
|
2380
|
-
"body",
|
|
2381
|
-
{
|
|
2382
|
-
className: "bg-gray-50",
|
|
2383
|
-
"hx-indicator": "#loading-bar",
|
|
2384
|
-
"hx-target": "#main-content",
|
|
2385
|
-
"hx-swap": "outerHTML",
|
|
2386
|
-
children: [
|
|
2387
|
-
/* @__PURE__ */ jsx(LoadingBar, {}),
|
|
2388
|
-
props.children,
|
|
2389
|
-
/* @__PURE__ */ jsx(
|
|
2390
|
-
"div",
|
|
2391
|
-
{
|
|
2392
|
-
id: "error-container",
|
|
2393
|
-
className: "fixed top-4 right-4 z-[200] w-full max-w-2xl px-4"
|
|
2394
|
-
}
|
|
2395
|
-
),
|
|
2396
|
-
/* @__PURE__ */ jsx("div", { id: "dialog-container" })
|
|
2397
|
-
]
|
|
2398
|
-
}
|
|
2399
|
-
)
|
|
2400
|
-
] });
|
|
2401
|
-
};
|
|
2402
|
-
var AdminLayout = (props) => {
|
|
2403
|
-
const logo = props.adminContext.pluginOptions.logo;
|
|
2404
|
-
const navItems = props.adminContext.pluginOptions.navigation;
|
|
2405
|
-
const referer = props.adminContext.ctx.req.header("Referer");
|
|
2406
|
-
let currentPath = props.adminContext.ctx.req.path;
|
|
2407
|
-
if (referer) {
|
|
2408
|
-
try {
|
|
2409
|
-
const refererUrl = new URL(referer);
|
|
2410
|
-
const method = props.adminContext.ctx.req.method;
|
|
2411
|
-
if (["POST", "PUT", "DELETE"].includes(method)) {
|
|
2412
|
-
currentPath = refererUrl.pathname;
|
|
2413
|
-
}
|
|
2414
|
-
} catch (e) {
|
|
2808
|
+
)
|
|
2809
|
+
] })
|
|
2415
2810
|
}
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2811
|
+
);
|
|
2812
|
+
};
|
|
2813
|
+
|
|
2814
|
+
// src/handler.tsx
|
|
2815
|
+
init_Layout();
|
|
2816
|
+
var Dialog = (props) => {
|
|
2817
|
+
const {
|
|
2818
|
+
title,
|
|
2819
|
+
children,
|
|
2820
|
+
showClose = true,
|
|
2821
|
+
closeUrl,
|
|
2822
|
+
className = "",
|
|
2823
|
+
size = "lg"
|
|
2824
|
+
} = props;
|
|
2825
|
+
const sizeClasses = {
|
|
2826
|
+
sm: "max-w-md",
|
|
2827
|
+
md: "max-w-lg",
|
|
2828
|
+
lg: "max-w-2xl",
|
|
2829
|
+
xl: "max-w-4xl",
|
|
2830
|
+
full: "max-w-7xl"
|
|
2831
|
+
};
|
|
2832
|
+
return /* @__PURE__ */ jsx(
|
|
2833
|
+
"div",
|
|
2834
|
+
{
|
|
2835
|
+
className: "fixed inset-0 bg-black bg-opacity-50 z-[100] flex items-center justify-center p-4 dialog-backdrop",
|
|
2836
|
+
style: {
|
|
2837
|
+
animation: "fadeIn 0.2s ease-out"
|
|
2838
|
+
},
|
|
2839
|
+
_: "on click if event.target is me \r\n add .dialog-exit to me\r\n add .dialog-content-exit to .dialog-content\r\n wait 200ms\r\n set #dialog-container's innerHTML to '' end",
|
|
2840
|
+
children: /* @__PURE__ */ jsxs(
|
|
2841
|
+
"div",
|
|
2446
2842
|
{
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2843
|
+
className: `bg-gray-50 rounded-lg shadow-xl ${sizeClasses[size]} w-full max-h-[90vh] overflow-hidden flex flex-col dialog-content ${className}`,
|
|
2844
|
+
style: {
|
|
2845
|
+
animation: "slideIn 0.3s ease-out"
|
|
2846
|
+
},
|
|
2847
|
+
_: "on click call event.stopPropagation()",
|
|
2848
|
+
children: [
|
|
2849
|
+
(title || showClose) && /* @__PURE__ */ jsxs("div", { className: "px-6 py-4 border-b border-gray-200 bg-white flex items-center justify-between", children: [
|
|
2850
|
+
title && /* @__PURE__ */ jsx("h3", { className: "text-lg font-semibold text-gray-900", children: title }),
|
|
2851
|
+
showClose && /* @__PURE__ */ jsx(
|
|
2852
|
+
"button",
|
|
2853
|
+
{
|
|
2854
|
+
className: "text-gray-400 hover:text-gray-600 transition-colors",
|
|
2855
|
+
_: "on click \r\n add .dialog-exit to .dialog-backdrop\r\n add .dialog-content-exit to .dialog-content\r\n wait 200ms\r\n set #dialog-container's innerHTML to '' end",
|
|
2856
|
+
children: /* @__PURE__ */ jsx(
|
|
2857
|
+
"svg",
|
|
2858
|
+
{
|
|
2859
|
+
className: "w-6 h-6",
|
|
2860
|
+
fill: "none",
|
|
2861
|
+
stroke: "currentColor",
|
|
2862
|
+
viewBox: "0 0 24 24",
|
|
2863
|
+
children: /* @__PURE__ */ jsx(
|
|
2864
|
+
"path",
|
|
2865
|
+
{
|
|
2866
|
+
strokeLinecap: "round",
|
|
2867
|
+
strokeLinejoin: "round",
|
|
2868
|
+
strokeWidth: 2,
|
|
2869
|
+
d: "M6 18L18 6M6 6l12 12"
|
|
2870
|
+
}
|
|
2871
|
+
)
|
|
2872
|
+
}
|
|
2873
|
+
)
|
|
2874
|
+
}
|
|
2875
|
+
)
|
|
2876
|
+
] }),
|
|
2877
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1 overflow-y-auto p-6 bg-gray-50", children })
|
|
2878
|
+
]
|
|
2450
2879
|
}
|
|
2451
|
-
)
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
] });
|
|
2880
|
+
)
|
|
2881
|
+
}
|
|
2882
|
+
);
|
|
2455
2883
|
};
|
|
2456
2884
|
|
|
2457
|
-
// src/
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
ctx;
|
|
2465
|
-
/** 之前的模块名 */
|
|
2466
|
-
previousModuleName;
|
|
2467
|
-
/** 是否是片段请求(HTMX 请求) */
|
|
2468
|
-
isFragment;
|
|
2469
|
-
/** 是否是对话框请求 */
|
|
2470
|
-
isDialog;
|
|
2471
|
-
/** 用户信息 */
|
|
2472
|
-
userInfo;
|
|
2473
|
-
/** 通知队列 */
|
|
2474
|
-
notifications = [];
|
|
2475
|
-
/** 页面标题(用于 HX-Title 和页面展示) */
|
|
2476
|
-
title = "";
|
|
2477
|
-
/** 页面描述(用于SEO和页面展示) */
|
|
2478
|
-
description = "";
|
|
2479
|
-
/** 面包屑项 */
|
|
2480
|
-
breadcrumbs = [];
|
|
2481
|
-
/** 主要内容 */
|
|
2482
|
-
content = null;
|
|
2483
|
-
/** 需要重定向的 URL */
|
|
2484
|
-
redirectUrl;
|
|
2485
|
-
/** 是否需要刷新页面(用于 HX-Refresh) */
|
|
2486
|
-
refresh = false;
|
|
2487
|
-
constructor(ctx, userInfo, moduleMetadata, pluginOptions) {
|
|
2488
|
-
this.ctx = ctx;
|
|
2489
|
-
this.userInfo = userInfo;
|
|
2490
|
-
this.moduleMetadata = moduleMetadata;
|
|
2491
|
-
this.pluginOptions = pluginOptions;
|
|
2492
|
-
const url = new URL(ctx.req.url);
|
|
2493
|
-
this.isFragment = ctx.req.header("HX-Request") === "true";
|
|
2494
|
-
this.isDialog = url.searchParams.get("dialog") === "true" || ctx.req.header("HX-Target") === "#dialog-container" || (ctx.req.header("Referer") || "").includes("dialog=true");
|
|
2495
|
-
const referer = ctx.req.header("Referer");
|
|
2496
|
-
this.previousModuleName = referer ? new URL(referer).pathname.replace(pluginOptions.prefix, "").split("/").pop() : void 0;
|
|
2885
|
+
// src/handler.tsx
|
|
2886
|
+
init_context();
|
|
2887
|
+
|
|
2888
|
+
// src/utils/permissions.ts
|
|
2889
|
+
function checkUserPermission(requiredPermission, userPermissions) {
|
|
2890
|
+
if (!requiredPermission) {
|
|
2891
|
+
return { allowed: true, reason: "\u65E0\u9700\u6743\u9650" };
|
|
2497
2892
|
}
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2893
|
+
if (!userPermissions || userPermissions.length === 0) {
|
|
2894
|
+
return {
|
|
2895
|
+
allowed: false,
|
|
2896
|
+
reason: "\u7528\u6237\u65E0\u4EFB\u4F55\u6743\u9650",
|
|
2897
|
+
matchedPermission: "none"
|
|
2898
|
+
};
|
|
2504
2899
|
}
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
sendError(title, message) {
|
|
2509
|
-
this.sendNotification("error", title, message);
|
|
2900
|
+
const denyResult = checkDenyPermissions(requiredPermission, userPermissions);
|
|
2901
|
+
if (!denyResult.allowed) {
|
|
2902
|
+
return denyResult;
|
|
2510
2903
|
}
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2904
|
+
const allowResult = checkAllowPermissions(
|
|
2905
|
+
requiredPermission,
|
|
2906
|
+
userPermissions
|
|
2907
|
+
);
|
|
2908
|
+
return allowResult;
|
|
2909
|
+
}
|
|
2910
|
+
function checkDenyPermissions(requiredPermission, userPermissions) {
|
|
2911
|
+
const denyPermissions = userPermissions.filter((p) => p.startsWith("deny:"));
|
|
2912
|
+
for (const denyPermission of denyPermissions) {
|
|
2913
|
+
const denyPattern = denyPermission.substring(5);
|
|
2914
|
+
if (matchPermission(requiredPermission, denyPattern)) {
|
|
2915
|
+
return {
|
|
2916
|
+
allowed: false,
|
|
2917
|
+
reason: `\u6743\u9650\u88AB\u7981\u6B62: ${denyPermission}`,
|
|
2918
|
+
matchedPermission: denyPermission
|
|
2919
|
+
};
|
|
2920
|
+
}
|
|
2921
|
+
}
|
|
2922
|
+
return { allowed: true };
|
|
2923
|
+
}
|
|
2924
|
+
function checkAllowPermissions(requiredPermission, userPermissions) {
|
|
2925
|
+
const allowPermissions = userPermissions.filter(
|
|
2926
|
+
(p) => !p.startsWith("deny:")
|
|
2927
|
+
);
|
|
2928
|
+
if (allowPermissions.length === 0) {
|
|
2929
|
+
return {
|
|
2930
|
+
allowed: false,
|
|
2931
|
+
reason: "\u7528\u6237\u65E0\u5141\u8BB8\u6743\u9650",
|
|
2932
|
+
matchedPermission: "none"
|
|
2933
|
+
};
|
|
2516
2934
|
}
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2935
|
+
for (const allowPermission of allowPermissions) {
|
|
2936
|
+
const allowPattern = allowPermission.startsWith("allow:") ? allowPermission.substring(6) : allowPermission;
|
|
2937
|
+
if (matchPermission(requiredPermission, allowPattern)) {
|
|
2938
|
+
return {
|
|
2939
|
+
allowed: true,
|
|
2940
|
+
reason: `\u6743\u9650\u5339\u914D: ${allowPermission}`,
|
|
2941
|
+
matchedPermission: allowPermission
|
|
2942
|
+
};
|
|
2943
|
+
}
|
|
2522
2944
|
}
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2945
|
+
return {
|
|
2946
|
+
allowed: false,
|
|
2947
|
+
reason: "\u65E0\u5339\u914D\u7684\u5141\u8BB8\u6743\u9650",
|
|
2948
|
+
matchedPermission: "none"
|
|
2949
|
+
};
|
|
2950
|
+
}
|
|
2951
|
+
function matchPermission(requiredPermission, pattern) {
|
|
2952
|
+
const required = requiredPermission.startsWith("allow:") ? requiredPermission.substring(6) : requiredPermission;
|
|
2953
|
+
if (pattern.includes("*")) {
|
|
2954
|
+
return matchWithWildcard(required, pattern);
|
|
2528
2955
|
}
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2956
|
+
return required === pattern;
|
|
2957
|
+
}
|
|
2958
|
+
function matchWithWildcard(required, pattern) {
|
|
2959
|
+
const requiredParts = required.split(".");
|
|
2960
|
+
const patternParts = pattern.split(".");
|
|
2961
|
+
if (requiredParts.length !== patternParts.length && !pattern.endsWith("*")) {
|
|
2962
|
+
return false;
|
|
2535
2963
|
}
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2964
|
+
const maxLength = Math.max(requiredParts.length, patternParts.length);
|
|
2965
|
+
for (let i = 0; i < maxLength; i++) {
|
|
2966
|
+
const requiredPart = requiredParts[i];
|
|
2967
|
+
const patternPart = patternParts[i];
|
|
2968
|
+
if (patternPart === "*") {
|
|
2969
|
+
continue;
|
|
2970
|
+
}
|
|
2971
|
+
if (!patternPart && pattern.endsWith("*")) {
|
|
2972
|
+
return true;
|
|
2973
|
+
}
|
|
2974
|
+
if (!requiredPart) {
|
|
2975
|
+
return false;
|
|
2976
|
+
}
|
|
2977
|
+
if (requiredPart !== patternPart) {
|
|
2978
|
+
return false;
|
|
2979
|
+
}
|
|
2542
2980
|
}
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2981
|
+
return true;
|
|
2982
|
+
}
|
|
2983
|
+
|
|
2984
|
+
// src/utils/auth.ts
|
|
2985
|
+
async function getUserInfo(ctx, authProvider) {
|
|
2986
|
+
if (!authProvider) {
|
|
2987
|
+
return null;
|
|
2549
2988
|
}
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
hasDetail() {
|
|
2555
|
-
return this.moduleMetadata.hasDetail;
|
|
2989
|
+
const cookieKey = authProvider.cookieKey || "auth_token";
|
|
2990
|
+
const token = getCookie(ctx, cookieKey);
|
|
2991
|
+
if (!token) {
|
|
2992
|
+
return null;
|
|
2556
2993
|
}
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
return this.moduleMetadata.hasForm;
|
|
2994
|
+
return await authProvider.tokenToUser(token, ctx);
|
|
2995
|
+
}
|
|
2996
|
+
function checkPermissionDefault(userInfo, operation, loginUrl) {
|
|
2997
|
+
if (!operation) {
|
|
2998
|
+
return { allowed: true };
|
|
2563
2999
|
}
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
3000
|
+
if (!userInfo) {
|
|
3001
|
+
return {
|
|
3002
|
+
allowed: false,
|
|
3003
|
+
message: "\u672A\u767B\u5F55\uFF0C\u65E0\u6CD5\u8BBF\u95EE\u6B64\u8D44\u6E90",
|
|
3004
|
+
operationId: operation,
|
|
3005
|
+
redirectUrl: loginUrl
|
|
3006
|
+
// 如果提供了 loginUrl,则重定向到登录页面
|
|
3007
|
+
};
|
|
2570
3008
|
}
|
|
2571
|
-
|
|
3009
|
+
const userPermissions = userInfo.permissions || [];
|
|
3010
|
+
const result = checkUserPermission(operation, userPermissions);
|
|
3011
|
+
if (result.allowed) {
|
|
3012
|
+
return { allowed: true };
|
|
3013
|
+
} else {
|
|
3014
|
+
return {
|
|
3015
|
+
allowed: false,
|
|
3016
|
+
message: result.reason || "\u60A8\u6CA1\u6709\u6743\u9650\u8BBF\u95EE\u6B64\u8D44\u6E90",
|
|
3017
|
+
operationId: operation
|
|
3018
|
+
};
|
|
3019
|
+
}
|
|
3020
|
+
}
|
|
3021
|
+
|
|
3022
|
+
// src/utils/operation.ts
|
|
3023
|
+
function generateOperationId(ctx, moduleName, moduleOptions, serviceName) {
|
|
3024
|
+
const method = ctx.req.method.toLowerCase();
|
|
3025
|
+
const url = new URL(ctx.req.url);
|
|
3026
|
+
const path = url.pathname;
|
|
3027
|
+
const lowerModuleName = moduleName.toLowerCase();
|
|
3028
|
+
const servicePrefix = serviceName ? `${serviceName}.` : "";
|
|
3029
|
+
if (moduleOptions.type === "list") {
|
|
3030
|
+
return `${servicePrefix}${lowerModuleName}.read`;
|
|
3031
|
+
} else if (moduleOptions.type === "detail") {
|
|
3032
|
+
if (method === "delete") {
|
|
3033
|
+
return `${servicePrefix}${lowerModuleName}.delete`;
|
|
3034
|
+
}
|
|
3035
|
+
return `${servicePrefix}${lowerModuleName}.read`;
|
|
3036
|
+
} else if (moduleOptions.type === "form") {
|
|
3037
|
+
if (path.includes("/new")) {
|
|
3038
|
+
if (method === "get") {
|
|
3039
|
+
return `${servicePrefix}${lowerModuleName}.create`;
|
|
3040
|
+
}
|
|
3041
|
+
return `${servicePrefix}${lowerModuleName}.create`;
|
|
3042
|
+
} else if (path.includes("/edit/")) {
|
|
3043
|
+
if (method === "get") {
|
|
3044
|
+
return `${servicePrefix}${lowerModuleName}.edit`;
|
|
3045
|
+
}
|
|
3046
|
+
return `${servicePrefix}${lowerModuleName}.edit`;
|
|
3047
|
+
} else if (method === "post") {
|
|
3048
|
+
return `${servicePrefix}${lowerModuleName}.create`;
|
|
3049
|
+
} else if (method === "put") {
|
|
3050
|
+
return `${servicePrefix}${lowerModuleName}.edit`;
|
|
3051
|
+
} else if (method === "delete") {
|
|
3052
|
+
return `${servicePrefix}${lowerModuleName}.delete`;
|
|
3053
|
+
}
|
|
3054
|
+
return `${servicePrefix}${lowerModuleName}.read`;
|
|
3055
|
+
} else if (moduleOptions.type === "custom") {
|
|
3056
|
+
if (method === "post") {
|
|
3057
|
+
return `${servicePrefix}${lowerModuleName}.create`;
|
|
3058
|
+
} else if (method === "put") {
|
|
3059
|
+
return `${servicePrefix}${lowerModuleName}.edit`;
|
|
3060
|
+
} else if (method === "delete") {
|
|
3061
|
+
return `${servicePrefix}${lowerModuleName}.delete`;
|
|
3062
|
+
}
|
|
3063
|
+
return `${servicePrefix}${lowerModuleName}.read`;
|
|
3064
|
+
}
|
|
3065
|
+
return `${servicePrefix}${lowerModuleName}.read`;
|
|
3066
|
+
}
|
|
3067
|
+
|
|
3068
|
+
// src/utils/permission-handler.tsx
|
|
3069
|
+
init_PermissionDenied();
|
|
3070
|
+
async function handlePermissionDenied(ctx, adminContext, permissionResult, getOperationId, pluginPrefix, getRegisteredOperations) {
|
|
3071
|
+
const operationId = permissionResult.operationId || getOperationId();
|
|
3072
|
+
const fromPath = ctx.req.path;
|
|
3073
|
+
if (adminContext.isFragment) {
|
|
3074
|
+
return renderPermissionDeniedDialog(
|
|
3075
|
+
ctx,
|
|
3076
|
+
adminContext,
|
|
3077
|
+
operationId,
|
|
3078
|
+
fromPath,
|
|
3079
|
+
getRegisteredOperations
|
|
3080
|
+
);
|
|
3081
|
+
} else {
|
|
3082
|
+
if (permissionResult.redirectUrl) {
|
|
3083
|
+
return ctx.redirect(permissionResult.redirectUrl);
|
|
3084
|
+
}
|
|
3085
|
+
return redirectToPermissionDeniedPage(
|
|
3086
|
+
ctx,
|
|
3087
|
+
operationId,
|
|
3088
|
+
fromPath,
|
|
3089
|
+
pluginPrefix,
|
|
3090
|
+
permissionResult.redirectUrl
|
|
3091
|
+
);
|
|
3092
|
+
}
|
|
3093
|
+
}
|
|
3094
|
+
function renderPermissionDeniedDialog(ctx, adminContext, operationId, fromPath, getRegisteredOperations) {
|
|
3095
|
+
const registeredOperations = getRegisteredOperations ? getRegisteredOperations() : [];
|
|
3096
|
+
const permissionContent = PermissionDeniedContent(
|
|
3097
|
+
adminContext,
|
|
3098
|
+
operationId,
|
|
3099
|
+
fromPath,
|
|
3100
|
+
registeredOperations
|
|
3101
|
+
);
|
|
3102
|
+
return ctx.html(
|
|
3103
|
+
/* @__PURE__ */ jsx(Dialog, { title: "\u6743\u9650\u4E0D\u8DB3", size: "lg", children: permissionContent }),
|
|
3104
|
+
200,
|
|
3105
|
+
{
|
|
3106
|
+
"HX-Retarget": "#dialog-container",
|
|
3107
|
+
"HX-Reswap": "innerHTML"
|
|
3108
|
+
}
|
|
3109
|
+
);
|
|
3110
|
+
}
|
|
3111
|
+
function redirectToPermissionDeniedPage(ctx, operationId, fromPath, pluginPrefix, customRedirectUrl) {
|
|
3112
|
+
const permissionDeniedUrl = `${pluginPrefix}/permission-denied`;
|
|
3113
|
+
const url = new URL(permissionDeniedUrl, ctx.req.url);
|
|
3114
|
+
url.searchParams.set("operation", operationId);
|
|
3115
|
+
url.searchParams.set("from", fromPath);
|
|
3116
|
+
const redirectUrl = url.pathname + url.search;
|
|
3117
|
+
const finalRedirectUrl = customRedirectUrl || redirectUrl;
|
|
3118
|
+
return ctx.redirect(finalRedirectUrl);
|
|
3119
|
+
}
|
|
2572
3120
|
var RouteHandler = class {
|
|
2573
3121
|
moduleClass;
|
|
2574
3122
|
pluginOptions;
|
|
2575
3123
|
moduleMetadata;
|
|
2576
3124
|
moduleOptions;
|
|
3125
|
+
moduleName;
|
|
3126
|
+
basePath;
|
|
3127
|
+
serviceName;
|
|
3128
|
+
getRegisteredOperations;
|
|
2577
3129
|
constructor(options) {
|
|
2578
3130
|
this.moduleClass = options.moduleClass;
|
|
2579
3131
|
this.pluginOptions = options.pluginOptions;
|
|
2580
3132
|
this.moduleMetadata = options.moduleMetadata;
|
|
2581
3133
|
this.moduleOptions = options.moduleOptions;
|
|
3134
|
+
this.moduleName = options.moduleName;
|
|
3135
|
+
this.basePath = options.basePath;
|
|
3136
|
+
this.serviceName = options.serviceName;
|
|
3137
|
+
this.getRegisteredOperations = options.getRegisteredOperations;
|
|
2582
3138
|
}
|
|
2583
3139
|
/**
|
|
2584
3140
|
* 更新模块元数据
|
|
@@ -2591,10 +3147,41 @@ var RouteHandler = class {
|
|
|
2591
3147
|
*/
|
|
2592
3148
|
async handle(ctx) {
|
|
2593
3149
|
try {
|
|
2594
|
-
const userInfo = await this.pluginOptions.
|
|
3150
|
+
const userInfo = await getUserInfo(ctx, this.pluginOptions.authProvider);
|
|
2595
3151
|
const adminContext = this.createAdminContext(ctx, userInfo);
|
|
2596
3152
|
const moduleInstance = new this.moduleClass();
|
|
2597
3153
|
moduleInstance.__init(adminContext);
|
|
3154
|
+
const requiredPermission = moduleInstance.getRequiredPermission?.(ctx);
|
|
3155
|
+
const operation = this.getOperationId(ctx);
|
|
3156
|
+
if (this.pluginOptions.authProvider && requiredPermission !== void 0 && requiredPermission !== null && requiredPermission !== "") {
|
|
3157
|
+
let permissionResult;
|
|
3158
|
+
if (this.pluginOptions.authProvider.checkPermission) {
|
|
3159
|
+
permissionResult = await this.pluginOptions.authProvider.checkPermission(
|
|
3160
|
+
userInfo,
|
|
3161
|
+
operation,
|
|
3162
|
+
adminContext
|
|
3163
|
+
);
|
|
3164
|
+
} else {
|
|
3165
|
+
permissionResult = checkPermissionDefault(
|
|
3166
|
+
userInfo,
|
|
3167
|
+
operation,
|
|
3168
|
+
this.pluginOptions.authProvider?.loginUrl
|
|
3169
|
+
);
|
|
3170
|
+
}
|
|
3171
|
+
if (!permissionResult.allowed) {
|
|
3172
|
+
if (!permissionResult.operationId) {
|
|
3173
|
+
permissionResult.operationId = operation;
|
|
3174
|
+
}
|
|
3175
|
+
return await handlePermissionDenied(
|
|
3176
|
+
ctx,
|
|
3177
|
+
adminContext,
|
|
3178
|
+
permissionResult,
|
|
3179
|
+
() => this.getOperationId(ctx),
|
|
3180
|
+
this.pluginOptions.prefix,
|
|
3181
|
+
this.getRegisteredOperations
|
|
3182
|
+
);
|
|
3183
|
+
}
|
|
3184
|
+
}
|
|
2598
3185
|
try {
|
|
2599
3186
|
adminContext.content = await moduleInstance.__handle();
|
|
2600
3187
|
adminContext.title = moduleInstance.getTitle();
|
|
@@ -2618,6 +3205,17 @@ var RouteHandler = class {
|
|
|
2618
3205
|
);
|
|
2619
3206
|
}
|
|
2620
3207
|
}
|
|
3208
|
+
/**
|
|
3209
|
+
* 获取操作ID(内部方法,用于传递给工具函数)
|
|
3210
|
+
*/
|
|
3211
|
+
getOperationId(ctx) {
|
|
3212
|
+
return generateOperationId(
|
|
3213
|
+
ctx,
|
|
3214
|
+
this.moduleName,
|
|
3215
|
+
this.moduleOptions,
|
|
3216
|
+
this.serviceName
|
|
3217
|
+
);
|
|
3218
|
+
}
|
|
2621
3219
|
renderFullPage(ctx, adminContext) {
|
|
2622
3220
|
if (adminContext.redirectUrl) {
|
|
2623
3221
|
return ctx.redirect(adminContext.redirectUrl);
|
|
@@ -2723,7 +3321,8 @@ var RouteHandler = class {
|
|
|
2723
3321
|
ctx,
|
|
2724
3322
|
userInfo,
|
|
2725
3323
|
this.moduleMetadata,
|
|
2726
|
-
this.pluginOptions
|
|
3324
|
+
this.pluginOptions,
|
|
3325
|
+
this.serviceName
|
|
2727
3326
|
);
|
|
2728
3327
|
}
|
|
2729
3328
|
/**
|
|
@@ -2816,8 +3415,12 @@ var HtmxAdminPlugin = class {
|
|
|
2816
3415
|
engine;
|
|
2817
3416
|
hono;
|
|
2818
3417
|
options;
|
|
3418
|
+
// 服务名(从引擎中获取)
|
|
3419
|
+
serviceName = "";
|
|
2819
3420
|
// 模块类映射(记录每个模块的类)
|
|
2820
3421
|
moduleTypeMap = /* @__PURE__ */ new Map();
|
|
3422
|
+
// 注册的操作列表(权限列表)
|
|
3423
|
+
registeredOperations = [];
|
|
2821
3424
|
constructor(options) {
|
|
2822
3425
|
this.options = {
|
|
2823
3426
|
title: options?.title || "\u7BA1\u7406\u540E\u53F0",
|
|
@@ -2825,7 +3428,7 @@ var HtmxAdminPlugin = class {
|
|
|
2825
3428
|
prefix: options?.prefix || "/admin",
|
|
2826
3429
|
homePath: options?.homePath || "",
|
|
2827
3430
|
navigation: options?.navigation ?? [],
|
|
2828
|
-
|
|
3431
|
+
authProvider: options?.authProvider
|
|
2829
3432
|
};
|
|
2830
3433
|
}
|
|
2831
3434
|
/**
|
|
@@ -2848,7 +3451,8 @@ var HtmxAdminPlugin = class {
|
|
|
2848
3451
|
onInit(engine) {
|
|
2849
3452
|
this.engine = engine;
|
|
2850
3453
|
this.hono = engine.getHono();
|
|
2851
|
-
|
|
3454
|
+
this.serviceName = engine.options.name;
|
|
3455
|
+
logger.info(`HtmxAdminPlugin initialized${this.serviceName ? ` (service: ${this.serviceName})` : ""}`);
|
|
2852
3456
|
}
|
|
2853
3457
|
/**
|
|
2854
3458
|
* 检查并注册模块
|
|
@@ -2909,10 +3513,144 @@ var HtmxAdminPlugin = class {
|
|
|
2909
3513
|
}
|
|
2910
3514
|
}
|
|
2911
3515
|
}
|
|
3516
|
+
/**
|
|
3517
|
+
* 根据模块类型和路由信息生成操作ID
|
|
3518
|
+
*/
|
|
3519
|
+
generateOperationId(moduleName, moduleType, method, path) {
|
|
3520
|
+
const lowerModuleName = moduleName.toLowerCase();
|
|
3521
|
+
const lowerMethod = method.toLowerCase();
|
|
3522
|
+
const servicePrefix = this.serviceName ? `${this.serviceName}.` : "";
|
|
3523
|
+
if (moduleType === "list") {
|
|
3524
|
+
return {
|
|
3525
|
+
operationId: `${servicePrefix}${lowerModuleName}.read`,
|
|
3526
|
+
operationType: "read"
|
|
3527
|
+
};
|
|
3528
|
+
} else if (moduleType === "detail") {
|
|
3529
|
+
if (lowerMethod === "delete") {
|
|
3530
|
+
return {
|
|
3531
|
+
operationId: `${servicePrefix}${lowerModuleName}.delete`,
|
|
3532
|
+
operationType: "delete"
|
|
3533
|
+
};
|
|
3534
|
+
}
|
|
3535
|
+
return {
|
|
3536
|
+
operationId: `${servicePrefix}${lowerModuleName}.read`,
|
|
3537
|
+
operationType: "read"
|
|
3538
|
+
};
|
|
3539
|
+
} else if (moduleType === "form") {
|
|
3540
|
+
if (path.includes("/new")) {
|
|
3541
|
+
if (lowerMethod === "get") {
|
|
3542
|
+
return {
|
|
3543
|
+
operationId: `${servicePrefix}${lowerModuleName}.create`,
|
|
3544
|
+
operationType: "create"
|
|
3545
|
+
};
|
|
3546
|
+
}
|
|
3547
|
+
return {
|
|
3548
|
+
operationId: `${servicePrefix}${lowerModuleName}.create`,
|
|
3549
|
+
operationType: "create"
|
|
3550
|
+
};
|
|
3551
|
+
} else if (path.includes("/edit/")) {
|
|
3552
|
+
if (lowerMethod === "get") {
|
|
3553
|
+
return {
|
|
3554
|
+
operationId: `${servicePrefix}${lowerModuleName}.edit`,
|
|
3555
|
+
operationType: "edit"
|
|
3556
|
+
};
|
|
3557
|
+
}
|
|
3558
|
+
return {
|
|
3559
|
+
operationId: `${servicePrefix}${lowerModuleName}.edit`,
|
|
3560
|
+
operationType: "edit"
|
|
3561
|
+
};
|
|
3562
|
+
} else if (lowerMethod === "post") {
|
|
3563
|
+
return {
|
|
3564
|
+
operationId: `${servicePrefix}${lowerModuleName}.create`,
|
|
3565
|
+
operationType: "create"
|
|
3566
|
+
};
|
|
3567
|
+
} else if (lowerMethod === "put") {
|
|
3568
|
+
return {
|
|
3569
|
+
operationId: `${servicePrefix}${lowerModuleName}.edit`,
|
|
3570
|
+
operationType: "edit"
|
|
3571
|
+
};
|
|
3572
|
+
} else if (lowerMethod === "delete") {
|
|
3573
|
+
return {
|
|
3574
|
+
operationId: `${servicePrefix}${lowerModuleName}.delete`,
|
|
3575
|
+
operationType: "delete"
|
|
3576
|
+
};
|
|
3577
|
+
}
|
|
3578
|
+
return {
|
|
3579
|
+
operationId: `${servicePrefix}${lowerModuleName}.read`,
|
|
3580
|
+
operationType: "read"
|
|
3581
|
+
};
|
|
3582
|
+
} else if (moduleType === "custom") {
|
|
3583
|
+
if (lowerMethod === "post") {
|
|
3584
|
+
return {
|
|
3585
|
+
operationId: `${servicePrefix}${lowerModuleName}.create`,
|
|
3586
|
+
operationType: "create"
|
|
3587
|
+
};
|
|
3588
|
+
} else if (lowerMethod === "put") {
|
|
3589
|
+
return {
|
|
3590
|
+
operationId: `${servicePrefix}${lowerModuleName}.edit`,
|
|
3591
|
+
operationType: "edit"
|
|
3592
|
+
};
|
|
3593
|
+
} else if (lowerMethod === "delete") {
|
|
3594
|
+
return {
|
|
3595
|
+
operationId: `${servicePrefix}${lowerModuleName}.delete`,
|
|
3596
|
+
operationType: "delete"
|
|
3597
|
+
};
|
|
3598
|
+
}
|
|
3599
|
+
return {
|
|
3600
|
+
operationId: `${servicePrefix}${lowerModuleName}.read`,
|
|
3601
|
+
operationType: "read"
|
|
3602
|
+
};
|
|
3603
|
+
}
|
|
3604
|
+
return {
|
|
3605
|
+
operationId: `${servicePrefix}${lowerModuleName}.read`,
|
|
3606
|
+
operationType: "read"
|
|
3607
|
+
};
|
|
3608
|
+
}
|
|
3609
|
+
/**
|
|
3610
|
+
* 注册内置路由(权限提示页面)
|
|
3611
|
+
*/
|
|
3612
|
+
registerBuiltinRoutes() {
|
|
3613
|
+
const permissionDeniedPath = `${this.options.prefix}/permission-denied`;
|
|
3614
|
+
this.hono.get(permissionDeniedPath, async (ctx) => {
|
|
3615
|
+
const url = new URL(ctx.req.url);
|
|
3616
|
+
const operationId = url.searchParams.get("operation") || "";
|
|
3617
|
+
const fromPath = url.searchParams.get("from") || "";
|
|
3618
|
+
const { PermissionDeniedPage: PermissionDeniedPage2 } = await Promise.resolve().then(() => (init_PermissionDenied(), PermissionDenied_exports));
|
|
3619
|
+
const { HtmxAdminContext: HtmxAdminContext2 } = await Promise.resolve().then(() => (init_context(), context_exports));
|
|
3620
|
+
const adminContext = new HtmxAdminContext2(
|
|
3621
|
+
ctx,
|
|
3622
|
+
null,
|
|
3623
|
+
// 不需要用户信息
|
|
3624
|
+
{
|
|
3625
|
+
hasList: false,
|
|
3626
|
+
hasDetail: false,
|
|
3627
|
+
hasForm: false,
|
|
3628
|
+
hasCustom: true,
|
|
3629
|
+
basePath: permissionDeniedPath,
|
|
3630
|
+
title: "\u6743\u9650\u4E0D\u8DB3",
|
|
3631
|
+
description: "\u60A8\u6CA1\u6709\u6743\u9650\u8BBF\u95EE\u6B64\u8D44\u6E90"
|
|
3632
|
+
},
|
|
3633
|
+
this.options,
|
|
3634
|
+
this.serviceName
|
|
3635
|
+
);
|
|
3636
|
+
return ctx.html(
|
|
3637
|
+
PermissionDeniedPage2(
|
|
3638
|
+
adminContext,
|
|
3639
|
+
operationId,
|
|
3640
|
+
fromPath,
|
|
3641
|
+
this.registeredOperations
|
|
3642
|
+
)
|
|
3643
|
+
);
|
|
3644
|
+
});
|
|
3645
|
+
logger.info(
|
|
3646
|
+
`[HtmxAdminPlugin] Registered builtin route: GET ${permissionDeniedPath}`
|
|
3647
|
+
);
|
|
3648
|
+
}
|
|
2912
3649
|
/**
|
|
2913
3650
|
* 注册路由
|
|
2914
3651
|
*/
|
|
2915
3652
|
registerRoutes() {
|
|
3653
|
+
this.registerBuiltinRoutes();
|
|
2916
3654
|
const moduleNames = Array.from(this.moduleTypeMap.keys());
|
|
2917
3655
|
for (const moduleName of moduleNames) {
|
|
2918
3656
|
const moduleTypes = this.moduleTypeMap.get(moduleName);
|
|
@@ -2925,6 +3663,8 @@ var HtmxAdminPlugin = class {
|
|
|
2925
3663
|
basePath,
|
|
2926
3664
|
moduleOptions: moduleInfo.options,
|
|
2927
3665
|
pluginOptions: this.options,
|
|
3666
|
+
serviceName: this.serviceName,
|
|
3667
|
+
// 传递服务名
|
|
2928
3668
|
moduleMetadata: {
|
|
2929
3669
|
hasList: !!moduleTypes["list"],
|
|
2930
3670
|
hasDetail: !!moduleTypes["detail"],
|
|
@@ -2933,7 +3673,9 @@ var HtmxAdminPlugin = class {
|
|
|
2933
3673
|
basePath,
|
|
2934
3674
|
title: moduleInfo.options.title ?? moduleName,
|
|
2935
3675
|
description: moduleInfo.options.description ?? ""
|
|
2936
|
-
}
|
|
3676
|
+
},
|
|
3677
|
+
getRegisteredOperations: () => this.registeredOperations
|
|
3678
|
+
// 传递获取操作列表的方法
|
|
2937
3679
|
});
|
|
2938
3680
|
const routeConfig = {
|
|
2939
3681
|
list: [{ method: "get", path: `${basePath}/list` }],
|
|
@@ -2945,24 +3687,87 @@ var HtmxAdminPlugin = class {
|
|
|
2945
3687
|
{ method: "put", path: `${basePath}/:id` },
|
|
2946
3688
|
{ method: "delete", path: `${basePath}/:id` }
|
|
2947
3689
|
],
|
|
2948
|
-
custom
|
|
3690
|
+
// custom 类型注册所有 HTTP 方法,允许模块在 render 方法中根据请求方法进行扩展
|
|
3691
|
+
custom: [
|
|
3692
|
+
{ method: "get", path: basePath },
|
|
3693
|
+
{ method: "post", path: basePath },
|
|
3694
|
+
{ method: "put", path: basePath },
|
|
3695
|
+
{ method: "delete", path: basePath }
|
|
3696
|
+
]
|
|
2949
3697
|
};
|
|
2950
3698
|
const routes = routeConfig[type];
|
|
2951
3699
|
for (const route of routes) {
|
|
2952
3700
|
logger.info(
|
|
2953
3701
|
`[HtmxAdminPlugin] Registering ${type} route: ${route.method.toUpperCase()} ${route.path}`
|
|
2954
3702
|
);
|
|
2955
|
-
const
|
|
3703
|
+
const { operationId, operationType } = this.generateOperationId(
|
|
3704
|
+
moduleName,
|
|
3705
|
+
type,
|
|
3706
|
+
route.method,
|
|
3707
|
+
route.path
|
|
3708
|
+
);
|
|
3709
|
+
const existingOperation = this.registeredOperations.find(
|
|
3710
|
+
(op) => op.operationId === operationId && op.httpMethod === route.method.toUpperCase()
|
|
3711
|
+
);
|
|
3712
|
+
if (!existingOperation) {
|
|
3713
|
+
this.registeredOperations.push({
|
|
3714
|
+
operationId,
|
|
3715
|
+
moduleName: moduleName.toLowerCase(),
|
|
3716
|
+
operationType,
|
|
3717
|
+
moduleType: type,
|
|
3718
|
+
moduleTitle: moduleInfo.options.title,
|
|
3719
|
+
moduleDescription: moduleInfo.options.description,
|
|
3720
|
+
httpMethod: route.method.toUpperCase(),
|
|
3721
|
+
routePath: route.path
|
|
3722
|
+
});
|
|
3723
|
+
}
|
|
3724
|
+
const handler = async (ctx) => {
|
|
3725
|
+
return routeHandler.handle(ctx);
|
|
3726
|
+
};
|
|
2956
3727
|
this.hono[route.method](route.path, handler);
|
|
2957
3728
|
}
|
|
2958
3729
|
}
|
|
2959
3730
|
}
|
|
2960
3731
|
}
|
|
3732
|
+
/**
|
|
3733
|
+
* 获取所有注册的操作(权限)列表
|
|
3734
|
+
* 可用于权限管理模块作为数据源,或用于确定管理员的权限
|
|
3735
|
+
*
|
|
3736
|
+
* @returns 所有注册的操作信息列表
|
|
3737
|
+
*/
|
|
3738
|
+
getRegisteredOperations() {
|
|
3739
|
+
return [...this.registeredOperations];
|
|
3740
|
+
}
|
|
3741
|
+
/**
|
|
3742
|
+
* 获取指定模块的所有操作
|
|
3743
|
+
*
|
|
3744
|
+
* @param moduleName 模块名
|
|
3745
|
+
* @returns 该模块的所有操作信息列表
|
|
3746
|
+
*/
|
|
3747
|
+
getModuleOperations(moduleName) {
|
|
3748
|
+
const lowerModuleName = moduleName.toLowerCase();
|
|
3749
|
+
return this.registeredOperations.filter(
|
|
3750
|
+
(op) => op.moduleName === lowerModuleName
|
|
3751
|
+
);
|
|
3752
|
+
}
|
|
3753
|
+
/**
|
|
3754
|
+
* 获取所有唯一的操作ID列表(去重)
|
|
3755
|
+
*
|
|
3756
|
+
* @returns 所有唯一的操作ID列表
|
|
3757
|
+
*/
|
|
3758
|
+
getOperationIds() {
|
|
3759
|
+
const uniqueIds = /* @__PURE__ */ new Set();
|
|
3760
|
+
for (const op of this.registeredOperations) {
|
|
3761
|
+
uniqueIds.add(op.operationId);
|
|
3762
|
+
}
|
|
3763
|
+
return Array.from(uniqueIds).sort();
|
|
3764
|
+
}
|
|
2961
3765
|
/**
|
|
2962
3766
|
* 模块加载钩子:检查模块类型约束并注册路由
|
|
2963
3767
|
*/
|
|
2964
3768
|
onModuleLoad(modules) {
|
|
2965
3769
|
this.checkAndRegisterModules(modules);
|
|
3770
|
+
this.registerBuiltinRoutes();
|
|
2966
3771
|
this.registerRoutes();
|
|
2967
3772
|
this.engine.getHono().get(this.options.prefix, async (ctx) => {
|
|
2968
3773
|
return ctx.redirect(this.options.homePath);
|
|
@@ -3047,6 +3852,10 @@ var Badge = (props) => {
|
|
|
3047
3852
|
}
|
|
3048
3853
|
);
|
|
3049
3854
|
};
|
|
3855
|
+
|
|
3856
|
+
// src/components/index.ts
|
|
3857
|
+
init_Button();
|
|
3858
|
+
init_Card();
|
|
3050
3859
|
var SystemStatusCard = (props) => {
|
|
3051
3860
|
const { title, statusItems, className = "" } = props;
|
|
3052
3861
|
const progressColorClasses = {
|