@svadmin/ui 0.118.0 → 0.120.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/dist/app.css +201 -52
- package/dist/app.theme.css +201 -52
- package/dist/components/AboutSettings.svelte +1 -1
- package/dist/components/AuditLogDrawer.svelte +165 -55
- package/dist/components/AuditLogDrawer.svelte.d.ts +4 -2
- package/dist/components/Authenticated.svelte +2 -2
- package/dist/components/AutoSaveIndicator.svelte +2 -2
- package/dist/components/AutoTable.svelte +1 -1
- package/dist/components/Barcode.svelte +219 -0
- package/dist/components/Barcode.svelte.d.ts +15 -0
- package/dist/components/Breadcrumbs.svelte +1 -1
- package/dist/components/Breadcrumbs.svelte.d.ts +1 -1
- package/dist/components/CanAccess.svelte +2 -2
- package/dist/components/CancelTaskButton.svelte +2 -2
- package/dist/components/Cascader.svelte +19 -19
- package/dist/components/Cascader.svelte.d.ts +19 -19
- package/dist/components/ColorPicker.svelte +9 -9
- package/dist/components/ColorPicker.svelte.d.ts +9 -9
- package/dist/components/ComboboxField.svelte +15 -15
- package/dist/components/ComboboxField.svelte.d.ts +15 -15
- package/dist/components/ConcurrentConflictModal.svelte +292 -0
- package/dist/components/ConcurrentConflictModal.svelte.d.ts +24 -0
- package/dist/components/ConfigErrorScreen.svelte +2 -2
- package/dist/components/ConfirmDialog.svelte +6 -4
- package/dist/components/ConfirmDialog.svelte.d.ts +2 -2
- package/dist/components/CronExpressionBuilder.svelte +389 -0
- package/dist/components/CronExpressionBuilder.svelte.d.ts +20 -0
- package/dist/components/DateRangeInput.svelte +22 -22
- package/dist/components/DateRangeInput.svelte.d.ts +22 -22
- package/dist/components/DateTimeInput.svelte +2 -2
- package/dist/components/DateTimeInput.svelte.d.ts +2 -2
- package/dist/components/EmptyState.svelte +2 -2
- package/dist/components/ErrorComponent.svelte +2 -2
- package/dist/components/ErrorSummary.svelte +2 -2
- package/dist/components/FieldRenderer.svelte +3 -3
- package/dist/components/FileUpload.svelte +16 -16
- package/dist/components/FileUpload.svelte.d.ts +16 -16
- package/dist/components/FileUploadField.svelte +7 -7
- package/dist/components/FileUploadField.svelte.d.ts +7 -7
- package/dist/components/FilterDropdown.svelte.d.ts +1 -1
- package/dist/components/ForgotPasswordPage.svelte +2 -2
- package/dist/components/Header.svelte +2 -2
- package/dist/components/LiveIndicator.svelte +2 -2
- package/dist/components/LoginPage.svelte +2 -2
- package/dist/components/MetricGrid.svelte +163 -0
- package/dist/components/MetricGrid.svelte.d.ts +39 -0
- package/dist/components/MicroAppFrame.svelte +290 -0
- package/dist/components/MicroAppFrame.svelte.d.ts +36 -0
- package/dist/components/MoneyInput.svelte +15 -15
- package/dist/components/MoneyInput.svelte.d.ts +15 -15
- package/dist/components/NotificationCenter.svelte +16 -16
- package/dist/components/NotificationCenter.svelte.d.ts +16 -16
- package/dist/components/NumberInput.svelte +13 -13
- package/dist/components/NumberInput.svelte.d.ts +13 -13
- package/dist/components/NumberRoll.svelte +149 -0
- package/dist/components/NumberRoll.svelte.d.ts +17 -0
- package/dist/components/NumericInput.svelte +16 -16
- package/dist/components/NumericInput.svelte.d.ts +16 -16
- package/dist/components/OfflineGuard.svelte +65 -0
- package/dist/components/OfflineGuard.svelte.d.ts +15 -0
- package/dist/components/OrgChart.svelte +171 -0
- package/dist/components/OrgChart.svelte.d.ts +26 -0
- package/dist/components/PageSkeleton.svelte +2 -2
- package/dist/components/PercentInput.svelte +14 -14
- package/dist/components/PercentInput.svelte.d.ts +14 -14
- package/dist/components/PresenceAvatarGroup.svelte +78 -29
- package/dist/components/PresenceAvatarGroup.svelte.d.ts +14 -8
- package/dist/components/Rate.svelte +9 -9
- package/dist/components/Rate.svelte.d.ts +9 -9
- package/dist/components/RegisterPage.svelte +2 -2
- package/dist/components/ResizeBox.svelte.d.ts +1 -1
- package/dist/components/RetryTaskButton.svelte +2 -2
- package/dist/components/SafeDeleteConfirm.svelte +301 -0
- package/dist/components/SafeDeleteConfirm.svelte.d.ts +24 -0
- package/dist/components/SignaturePad.svelte +19 -3
- package/dist/components/SignaturePad.svelte.d.ts +3 -0
- package/dist/components/SliderCaptcha.svelte +448 -0
- package/dist/components/SliderCaptcha.svelte.d.ts +26 -0
- package/dist/components/TagsInput.svelte +10 -10
- package/dist/components/TagsInput.svelte.d.ts +10 -10
- package/dist/components/TaskCenter.svelte +450 -0
- package/dist/components/TaskCenter.svelte.d.ts +37 -0
- package/dist/components/TaskDetails.svelte +2 -2
- package/dist/components/TaskList.svelte +2 -2
- package/dist/components/TaskProgressBar.svelte +2 -2
- package/dist/components/TaskStatusBadge.svelte +2 -2
- package/dist/components/ThemedTitle.svelte +2 -2
- package/dist/components/Tour.svelte +9 -1
- package/dist/components/Tour.svelte.d.ts +2 -1
- package/dist/components/Transfer.svelte +11 -11
- package/dist/components/Transfer.svelte.d.ts +11 -11
- package/dist/components/TreeSelect.svelte +17 -17
- package/dist/components/TreeSelect.svelte.d.ts +17 -17
- package/dist/components/TreeTable.svelte.d.ts +1 -1
- package/dist/components/TrendIndicator.svelte +177 -0
- package/dist/components/TrendIndicator.svelte.d.ts +27 -0
- package/dist/components/UndoableNotification.svelte +2 -2
- package/dist/components/UpdatePasswordPage.svelte +2 -2
- package/dist/components/VirtualList.svelte +165 -0
- package/dist/components/VirtualList.svelte.d.ts +43 -0
- package/dist/components/VirtualTreeSelect.svelte +431 -0
- package/dist/components/VirtualTreeSelect.svelte.d.ts +34 -0
- package/dist/components/buttons/CreateButton.svelte +2 -2
- package/dist/components/buttons/ExportButton.svelte +2 -2
- package/dist/components/buttons/ListButton.svelte +2 -2
- package/dist/components/buttons/RefreshButton.svelte +2 -2
- package/dist/components/buttons/SaveButton.svelte +2 -2
- package/dist/components/charts/GaugeChart.svelte +452 -57
- package/dist/components/charts/GaugeChart.svelte.d.ts +61 -10
- package/dist/components/content/AuditTimeline.svelte +125 -28
- package/dist/components/content/AuditTimeline.svelte.d.ts +30 -16
- package/dist/components/fields/JsonField.svelte +2 -2
- package/dist/components/fields/MultiSelectField.svelte +2 -2
- package/dist/components/fields/RelationField.svelte +2 -2
- package/dist/components/fields/RichTextField.svelte +2 -2
- package/dist/components/fields/SelectField.svelte +2 -2
- package/dist/components/list-state.svelte.d.ts +1 -1
- package/dist/components/ui/checkbox/checkbox.svelte.d.ts +1 -1
- package/dist/components/ui/command/command-dialog.svelte.d.ts +1 -1
- package/dist/components/ui/command/index.d.ts +1 -1
- package/dist/components/ui/input/input.svelte.d.ts +1 -1
- package/dist/components/ui/switch/switch.svelte.d.ts +1 -1
- package/dist/components/useNetworkStatus.d.svelte.ts +1 -0
- package/dist/components/useNetworkStatus.svelte.d.ts +30 -0
- package/dist/components/useNetworkStatus.svelte.js +74 -0
- package/dist/design-system.d.ts +4 -4
- package/dist/index.d.ts +26 -5
- package/dist/index.js +27 -3
- package/dist/recipes.d.ts +91 -619
- package/package.json +30 -30
|
@@ -1,30 +1,106 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { definedOptions } from '@svadmin/core/options';
|
|
3
|
-
|
|
4
3
|
import { captureAdminContext, useTranslation, withValidatedAuditProvider } from '@svadmin/core';
|
|
5
|
-
|
|
6
4
|
import type { AuditEntry, AuditLogProvider, AuditQueryParams } from '@svadmin/core';
|
|
7
5
|
import * as Sheet from './ui/sheet/index.js';
|
|
8
|
-
import { History, Loader2 } from '@lucide/svelte';
|
|
6
|
+
import { History, Loader2, Search, RefreshCw } from '@lucide/svelte';
|
|
7
|
+
import AuditTimeline, { type TimelineItem, type AuditFieldChange } from './content/AuditTimeline.svelte';
|
|
9
8
|
|
|
10
9
|
export type AuditLogDrawerLoader = (params: AuditQueryParams) => Promise<AuditEntry[]>;
|
|
11
10
|
|
|
12
11
|
const i18n = useTranslation();
|
|
13
12
|
const adminContext = captureAdminContext();
|
|
14
13
|
|
|
15
|
-
let {
|
|
14
|
+
let {
|
|
15
|
+
open = $bindable(false),
|
|
16
|
+
resource,
|
|
17
|
+
recordId,
|
|
18
|
+
loadEntries,
|
|
19
|
+
title,
|
|
20
|
+
description,
|
|
21
|
+
}: {
|
|
16
22
|
open: boolean;
|
|
17
23
|
resource: string;
|
|
18
|
-
recordId?: string | number;
|
|
24
|
+
recordId?: string | number | undefined;
|
|
19
25
|
/** Optional loader; defaults to the AdminContext auditLogProvider. */
|
|
20
|
-
loadEntries?: AuditLogDrawerLoader;
|
|
21
|
-
|
|
26
|
+
loadEntries?: AuditLogDrawerLoader | undefined;
|
|
27
|
+
title?: string | undefined;
|
|
28
|
+
description?: string | undefined;
|
|
29
|
+
} = $props();
|
|
22
30
|
|
|
23
31
|
let logs = $state<AuditEntry[]>([]);
|
|
24
32
|
let isLoading = $state(false);
|
|
25
33
|
let loadFailed = $state(false);
|
|
26
34
|
let requestEpoch = 0;
|
|
27
35
|
|
|
36
|
+
// 过滤状态
|
|
37
|
+
let actionFilter = $state<string>('all');
|
|
38
|
+
let searchQuery = $state<string>('');
|
|
39
|
+
|
|
40
|
+
const resolvedTitle = $derived(title ?? i18n.t('common.history') ?? 'Audit Logs');
|
|
41
|
+
const resolvedDesc = $derived(description ?? `Audit log and revision history for ${resource}${recordId ? ` #${recordId}` : ''}.`);
|
|
42
|
+
|
|
43
|
+
// 从 previousData 与 data 计算字段变更
|
|
44
|
+
function computeChanges(prev?: Record<string, unknown>, curr?: Record<string, unknown>): AuditFieldChange[] {
|
|
45
|
+
if (!prev && !curr) return [];
|
|
46
|
+
const keys = new Set([...Object.keys(prev || {}), ...Object.keys(curr || {})]);
|
|
47
|
+
const diffs: AuditFieldChange[] = [];
|
|
48
|
+
|
|
49
|
+
for (const key of keys) {
|
|
50
|
+
if (key === 'id' || key === 'updatedAt' || key === 'updated_at') continue;
|
|
51
|
+
const oldVal = prev ? prev[key] : undefined;
|
|
52
|
+
const newVal = curr ? curr[key] : undefined;
|
|
53
|
+
if (JSON.stringify(oldVal) !== JSON.stringify(newVal)) {
|
|
54
|
+
diffs.push({
|
|
55
|
+
field: key,
|
|
56
|
+
oldValue: oldVal,
|
|
57
|
+
newValue: newVal,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return diffs;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// 将 AuditEntry[] 转换为 TimelineItem[]
|
|
65
|
+
const timelineItems = $derived.by<TimelineItem[]>(() => {
|
|
66
|
+
return logs
|
|
67
|
+
.filter((entry) => {
|
|
68
|
+
// 操作动作过滤
|
|
69
|
+
if (actionFilter !== 'all' && entry.action.toLowerCase() !== actionFilter.toLowerCase()) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
// 搜索关键词过滤
|
|
73
|
+
if (searchQuery.trim()) {
|
|
74
|
+
const q = searchQuery.toLowerCase();
|
|
75
|
+
const matchUser = entry.userId?.toLowerCase().includes(q);
|
|
76
|
+
const matchAction = entry.action.toLowerCase().includes(q);
|
|
77
|
+
const matchResource = entry.resource?.toLowerCase().includes(q);
|
|
78
|
+
const matchData = JSON.stringify(entry.data || {}).toLowerCase().includes(q);
|
|
79
|
+
if (!matchUser && !matchAction && !matchResource && !matchData) return false;
|
|
80
|
+
}
|
|
81
|
+
return true;
|
|
82
|
+
})
|
|
83
|
+
.map((entry) => {
|
|
84
|
+
const changes = computeChanges(entry.previousData, entry.data);
|
|
85
|
+
const metaValue = entry.meta?.['ip'];
|
|
86
|
+
const metaIp = typeof metaValue === 'string' ? metaValue : undefined;
|
|
87
|
+
const ip = entry.ipAddress || metaIp;
|
|
88
|
+
return {
|
|
89
|
+
id: String(entry.id ?? Math.random()),
|
|
90
|
+
title: `${entry.action.toUpperCase()} ${entry.resource ?? resource}`,
|
|
91
|
+
action: entry.action,
|
|
92
|
+
timestamp: entry.timestamp,
|
|
93
|
+
actor: {
|
|
94
|
+
id: entry.userId,
|
|
95
|
+
name: entry.userId,
|
|
96
|
+
ip,
|
|
97
|
+
},
|
|
98
|
+
changes: changes.length > 0 ? changes : undefined,
|
|
99
|
+
meta: entry.meta,
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
28
104
|
$effect(() => {
|
|
29
105
|
const scopedProvider = adminContext.auditLogProvider;
|
|
30
106
|
const scopedLoader = loadEntries;
|
|
@@ -41,7 +117,7 @@
|
|
|
41
117
|
if (scopedLoader) {
|
|
42
118
|
void loadAuditLogsWithLoader(scopedLoader, definedOptions({ resource: scopedResource, meta: providerMeta }));
|
|
43
119
|
} else if (scopedProvider) {
|
|
44
|
-
void loadAuditLogs(scopedProvider, scopedResource, providerMeta);
|
|
120
|
+
void loadAuditLogs(scopedProvider, scopedResource, scopedRecordId, providerMeta);
|
|
45
121
|
}
|
|
46
122
|
}
|
|
47
123
|
|
|
@@ -62,10 +138,11 @@
|
|
|
62
138
|
async function loadAuditLogs(
|
|
63
139
|
scopedProvider: AuditLogProvider,
|
|
64
140
|
scopedResource: string,
|
|
141
|
+
scopedRecordId: string | number | undefined,
|
|
65
142
|
providerMeta: Record<string, unknown> | undefined,
|
|
66
143
|
) {
|
|
67
144
|
return loadAuditLogsWithLoader(
|
|
68
|
-
params => withValidatedAuditProvider(scopedProvider).get(params),
|
|
145
|
+
(params) => withValidatedAuditProvider(scopedProvider).get(params),
|
|
69
146
|
definedOptions({ resource: scopedResource, meta: providerMeta }),
|
|
70
147
|
false,
|
|
71
148
|
);
|
|
@@ -81,9 +158,9 @@
|
|
|
81
158
|
try {
|
|
82
159
|
const entries = validateResponse
|
|
83
160
|
? await withValidatedAuditProvider({
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
161
|
+
create: async (createParams) => createParams,
|
|
162
|
+
get: loader,
|
|
163
|
+
}).get(params)
|
|
87
164
|
: await loader(params);
|
|
88
165
|
if (epoch === requestEpoch) logs = entries;
|
|
89
166
|
} catch (error) {
|
|
@@ -96,64 +173,97 @@
|
|
|
96
173
|
}
|
|
97
174
|
}
|
|
98
175
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
176
|
+
function refresh() {
|
|
177
|
+
const scopedProvider = adminContext.auditLogProvider;
|
|
178
|
+
const scopedLoader = loadEntries;
|
|
179
|
+
const scopedResource = resource;
|
|
180
|
+
const scopedRecordId = recordId;
|
|
181
|
+
const providerMeta = adminContext.getProviderMeta(
|
|
182
|
+
scopedResource,
|
|
183
|
+
scopedRecordId == null ? undefined : { recordId: scopedRecordId },
|
|
184
|
+
);
|
|
185
|
+
if (scopedLoader) {
|
|
186
|
+
void loadAuditLogsWithLoader(scopedLoader, definedOptions({ resource: scopedResource, meta: providerMeta }));
|
|
187
|
+
} else if (scopedProvider) {
|
|
188
|
+
void loadAuditLogs(scopedProvider, scopedResource, scopedRecordId, providerMeta);
|
|
106
189
|
}
|
|
107
190
|
}
|
|
108
191
|
</script>
|
|
109
192
|
|
|
110
193
|
<Sheet.Root bind:open>
|
|
111
|
-
<Sheet.Content class="w-full sm:max-w-
|
|
194
|
+
<Sheet.Content class="w-full sm:max-w-lg overflow-y-auto" data-svadmin-component="AuditLogDrawer">
|
|
112
195
|
<Sheet.Header>
|
|
113
|
-
<
|
|
114
|
-
<
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
196
|
+
<div class="flex items-center justify-between pr-6">
|
|
197
|
+
<Sheet.Title class="flex items-center gap-2 text-base font-semibold">
|
|
198
|
+
<History class="h-5 w-5 text-primary" />
|
|
199
|
+
<span>{resolvedTitle}</span>
|
|
200
|
+
</Sheet.Title>
|
|
201
|
+
<button
|
|
202
|
+
type="button"
|
|
203
|
+
class="rounded p-1 text-muted-foreground hover:bg-muted hover:text-foreground transition-colors disabled:opacity-40"
|
|
204
|
+
onclick={refresh}
|
|
205
|
+
disabled={isLoading}
|
|
206
|
+
title="Refresh"
|
|
207
|
+
aria-label="Refresh audit logs"
|
|
208
|
+
>
|
|
209
|
+
<RefreshCw class="h-4 w-4 {isLoading ? 'animate-spin' : ''}" />
|
|
210
|
+
</button>
|
|
211
|
+
</div>
|
|
212
|
+
<Sheet.Description class="text-xs text-muted-foreground">
|
|
213
|
+
{resolvedDesc}
|
|
119
214
|
</Sheet.Description>
|
|
120
215
|
</Sheet.Header>
|
|
121
216
|
|
|
122
|
-
|
|
217
|
+
<!-- Filter & Search Toolbar -->
|
|
218
|
+
<div class="mt-4 flex items-center gap-2 border-b pb-3">
|
|
219
|
+
<div class="relative flex-1">
|
|
220
|
+
<Search class="absolute left-2.5 top-2.5 h-3.5 w-3.5 text-muted-foreground" />
|
|
221
|
+
<input
|
|
222
|
+
type="text"
|
|
223
|
+
placeholder="Filter by user or action..."
|
|
224
|
+
class="w-full rounded-md border border-input bg-background pl-8 pr-3 py-1.5 text-xs text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary"
|
|
225
|
+
bind:value={searchQuery}
|
|
226
|
+
oninput={(e) => { searchQuery = e.currentTarget.value; }}
|
|
227
|
+
data-svadmin-field="audit-search"
|
|
228
|
+
/>
|
|
229
|
+
</div>
|
|
230
|
+
|
|
231
|
+
<div class="relative w-32">
|
|
232
|
+
<select
|
|
233
|
+
class="w-full rounded-md border border-input bg-background px-2.5 py-1.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-primary capitalize"
|
|
234
|
+
bind:value={actionFilter}
|
|
235
|
+
onchange={(e) => { actionFilter = e.currentTarget.value; }}
|
|
236
|
+
data-svadmin-field="audit-action-filter"
|
|
237
|
+
>
|
|
238
|
+
<option value="all">All Actions</option>
|
|
239
|
+
<option value="create">Create</option>
|
|
240
|
+
<option value="update">Update</option>
|
|
241
|
+
<option value="delete">Delete</option>
|
|
242
|
+
<option value="approve">Approve</option>
|
|
243
|
+
<option value="rollback">Rollback</option>
|
|
244
|
+
</select>
|
|
245
|
+
</div>
|
|
246
|
+
</div>
|
|
247
|
+
|
|
248
|
+
<!-- Content Area -->
|
|
249
|
+
<div class="mt-6">
|
|
123
250
|
{#if isLoading}
|
|
124
|
-
<div class="flex justify-center py-
|
|
125
|
-
<Loader2 class="h-6 w-6 animate-spin" />
|
|
251
|
+
<div class="flex justify-center py-12 text-muted-foreground">
|
|
252
|
+
<Loader2 class="h-6 w-6 animate-spin text-primary" />
|
|
126
253
|
</div>
|
|
127
254
|
{:else if loadFailed}
|
|
128
|
-
<p role="alert">
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
255
|
+
<div class="rounded-lg border border-destructive/30 bg-destructive/10 p-4 text-center text-xs text-destructive" role="alert">
|
|
256
|
+
{i18n.t('common.error') ?? 'Failed to load audit logs'}
|
|
257
|
+
</div>
|
|
258
|
+
{:else if timelineItems.length === 0}
|
|
259
|
+
<div class="text-center py-12">
|
|
260
|
+
<History class="h-8 w-8 mx-auto text-muted-foreground/30 mb-2" />
|
|
261
|
+
<p class="text-xs text-muted-foreground">
|
|
262
|
+
{searchQuery || actionFilter !== 'all' ? 'No matching audit records' : (i18n.t('common.noData') ?? 'No audit logs found')}
|
|
134
263
|
</p>
|
|
135
264
|
</div>
|
|
136
265
|
{:else}
|
|
137
|
-
<
|
|
138
|
-
{#each logs as log, _i (_i)}
|
|
139
|
-
<div class="relative">
|
|
140
|
-
<span class="absolute -left-7 top-1 flex h-2 w-2 items-center justify-center rounded-full ring-4 ring-background {getActionColor(log.action)}"></span>
|
|
141
|
-
<div class="flex flex-col gap-1.5">
|
|
142
|
-
<div class="flex items-center gap-2 justify-between">
|
|
143
|
-
<span class="text-sm font-semibold capitalize">{log.action}</span>
|
|
144
|
-
<span class="text-xs text-muted-foreground">
|
|
145
|
-
{new Date(log.timestamp).toLocaleString()}
|
|
146
|
-
</span>
|
|
147
|
-
</div>
|
|
148
|
-
{#if log.userId}
|
|
149
|
-
<span class="text-xs text-muted-foreground font-mono bg-muted inline-flex px-1.5 py-0.5 rounded w-fit">
|
|
150
|
-
User: {log.userId}
|
|
151
|
-
</span>
|
|
152
|
-
{/if}
|
|
153
|
-
</div>
|
|
154
|
-
</div>
|
|
155
|
-
{/each}
|
|
156
|
-
</div>
|
|
266
|
+
<AuditTimeline items={timelineItems} />
|
|
157
267
|
{/if}
|
|
158
268
|
</div>
|
|
159
269
|
</Sheet.Content>
|
|
@@ -3,9 +3,11 @@ export type AuditLogDrawerLoader = (params: AuditQueryParams) => Promise<AuditEn
|
|
|
3
3
|
type $$ComponentProps = {
|
|
4
4
|
open: boolean;
|
|
5
5
|
resource: string;
|
|
6
|
-
recordId?: string | number;
|
|
6
|
+
recordId?: string | number | undefined;
|
|
7
7
|
/** Optional loader; defaults to the AdminContext auditLogProvider. */
|
|
8
|
-
loadEntries?: AuditLogDrawerLoader;
|
|
8
|
+
loadEntries?: AuditLogDrawerLoader | undefined;
|
|
9
|
+
title?: string | undefined;
|
|
10
|
+
description?: string | undefined;
|
|
9
11
|
};
|
|
10
12
|
declare const AuditLogDrawer: import("svelte").Component<$$ComponentProps, {}, "open">;
|
|
11
13
|
type AuditLogDrawer = ReturnType<typeof AuditLogDrawer>;
|
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
loading,
|
|
9
9
|
redirectTo = '/login',
|
|
10
10
|
appendCurrentPathToQuery = true,
|
|
11
|
-
}
|
|
11
|
+
}: {
|
|
12
12
|
children?: Snippet;
|
|
13
13
|
fallback?: Snippet;
|
|
14
14
|
loading?: Snippet;
|
|
15
15
|
redirectTo?: string;
|
|
16
16
|
appendCurrentPathToQuery?: boolean;
|
|
17
|
-
}
|
|
17
|
+
} = $props();
|
|
18
18
|
|
|
19
19
|
const adminContext = captureAdminContext();
|
|
20
20
|
const isAuth = useIsAuthenticated();
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
let {
|
|
9
9
|
status = 'idle',
|
|
10
10
|
error,
|
|
11
|
-
}
|
|
11
|
+
}: {
|
|
12
12
|
/** The current auto-save status */
|
|
13
13
|
status?: 'idle' | 'loading' | 'success' | 'error';
|
|
14
14
|
/** Optional error message */
|
|
15
15
|
error?: string;
|
|
16
|
-
}
|
|
16
|
+
} = $props();
|
|
17
17
|
</script>
|
|
18
18
|
|
|
19
19
|
<div class="flex items-center gap-2 text-sm text-muted-foreground" role="status" aria-live="polite">
|
|
@@ -1469,7 +1469,7 @@
|
|
|
1469
1469
|
|
|
1470
1470
|
<!-- Table (TanStack-powered) -->
|
|
1471
1471
|
<div class="overflow-hidden rounded-lg border border-border bg-card shadow-sm" role="region" aria-label="{resource.label} {i18n.t('common.list')}" data-table-density={currentDensity}>
|
|
1472
|
-
{#if listPermission.isLoading || (query.isLoading && !query.isError)}
|
|
1472
|
+
{#if listPermission.isLoading || (canRead && query.isLoading && !query.isError)}
|
|
1473
1473
|
<Table.Root density={currentDensity}>
|
|
1474
1474
|
<Table.Header>
|
|
1475
1475
|
{#each tableView.headerGroups as headerGroup, _i (_i)}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { cn } from '../utils.js';
|
|
3
|
+
import { Copy, Check, Printer } from '@lucide/svelte';
|
|
4
|
+
|
|
5
|
+
export type BarcodeFormat = 'CODE128' | 'CODE39' | 'EAN13';
|
|
6
|
+
|
|
7
|
+
export interface BarcodeProps {
|
|
8
|
+
value: string;
|
|
9
|
+
format?: BarcodeFormat;
|
|
10
|
+
width?: number;
|
|
11
|
+
height?: number;
|
|
12
|
+
showText?: boolean;
|
|
13
|
+
text?: string;
|
|
14
|
+
showActions?: boolean;
|
|
15
|
+
margin?: number;
|
|
16
|
+
class?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let {
|
|
20
|
+
value,
|
|
21
|
+
format = 'CODE128',
|
|
22
|
+
width = 2,
|
|
23
|
+
height = 60,
|
|
24
|
+
showText = true,
|
|
25
|
+
text,
|
|
26
|
+
showActions = false,
|
|
27
|
+
margin = 8,
|
|
28
|
+
class: className = '',
|
|
29
|
+
}: BarcodeProps = $props();
|
|
30
|
+
|
|
31
|
+
let copied = $state(false);
|
|
32
|
+
|
|
33
|
+
// CODE39 模式表: 每个字符由 9 个单元组成(5条4空),其中3个为宽单元(值为1表示宽,0表示窄)
|
|
34
|
+
const CODE39_ENCODINGS: Record<string, string> = {
|
|
35
|
+
'0': '000110100', '1': '100100001', '2': '001100001', '3': '101100000',
|
|
36
|
+
'4': '000110001', '5': '100110000', '6': '001110000', '7': '000100101',
|
|
37
|
+
'8': '100100100', '9': '001100100', 'A': '100001001', 'B': '001001001',
|
|
38
|
+
'C': '101001000', 'D': '000011001', 'E': '100011000', 'F': '001011000',
|
|
39
|
+
'G': '000001101', 'H': '100001100', 'I': '001001100', 'J': '000011100',
|
|
40
|
+
'K': '100000011', 'L': '001000011', 'M': '101000010', 'N': '000010011',
|
|
41
|
+
'O': '100010010', 'P': '001010010', 'Q': '000000111', 'R': '100000110',
|
|
42
|
+
'S': '001000110', 'T': '000010110', 'U': '110000001', 'V': '011000001',
|
|
43
|
+
'W': '111000000', 'X': '010010001', 'Y': '110010000', 'Z': '011010000',
|
|
44
|
+
'-': '010000101', '.': '110000100', ' ': '011000100', '$': '010101000',
|
|
45
|
+
'/': '010100010', '+': '010001010', '%': '000101010', '*': '010010100'
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// CODE128 模式表 (常用模式)
|
|
49
|
+
const CODE128_PATTERNS: string[] = [
|
|
50
|
+
'212222', '222122', '222221', '121223', '121322', '131222', '122213', '122312', '132212', '221213',
|
|
51
|
+
'221312', '231212', '112232', '122132', '122231', '113222', '123122', '123221', '223211', '221132',
|
|
52
|
+
'221231', '213212', '223112', '312131', '311222', '321122', '321221', '312212', '322112', '322211',
|
|
53
|
+
'212123', '212321', '232121', '111323', '131123', '131321', '112313', '132113', '132311', '211313',
|
|
54
|
+
'231113', '231311', '112133', '112331', '132131', '113123', '113321', '133121', '313121', '211331',
|
|
55
|
+
'231131', '213113', '213311', '213131', '311123', '311321', '331121', '312113', '312311', '332111',
|
|
56
|
+
'314111', '221411', '431111', '111224', '111422', '121124', '121421', '141122', '141221', '112214',
|
|
57
|
+
'112412', '122114', '122411', '142112', '142211', '241211', '221114', '413111', '241112', '134111',
|
|
58
|
+
'111242', '121142', '121241', '114212', '124112', '124211', '411212', '421112', '421211', '212141',
|
|
59
|
+
'214121', '412121', '111143', '111341', '131141', '114113', '114311', '411113', '411311', '113141',
|
|
60
|
+
'114131', '311141', '411131', '211412', '211214', '211232', '2331112'
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
interface BarSegment {
|
|
64
|
+
x: number;
|
|
65
|
+
width: number;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const barcodeBars = $derived.by<BarSegment[]>(() => {
|
|
69
|
+
if (!value) return [];
|
|
70
|
+
const bars: BarSegment[] = [];
|
|
71
|
+
let currentX = margin;
|
|
72
|
+
|
|
73
|
+
if (format === 'CODE39') {
|
|
74
|
+
const cleanValue = `*${value.toUpperCase()}*`;
|
|
75
|
+
for (let i = 0; i < cleanValue.length; i++) {
|
|
76
|
+
const char = cleanValue[i] ?? '-';
|
|
77
|
+
const pattern = CODE39_ENCODINGS[char] ?? CODE39_ENCODINGS['-'] ?? '010000101';
|
|
78
|
+
// 9 个单元:偶数索引是条,奇数索引是空
|
|
79
|
+
for (let j = 0; j < 9; j++) {
|
|
80
|
+
const isBar = j % 2 === 0;
|
|
81
|
+
const isWide = pattern[j] === '1';
|
|
82
|
+
const segmentWidth = (isWide ? 3 : 1) * width;
|
|
83
|
+
if (isBar) {
|
|
84
|
+
bars.push({ x: currentX, width: segmentWidth });
|
|
85
|
+
}
|
|
86
|
+
currentX += segmentWidth;
|
|
87
|
+
}
|
|
88
|
+
// 字符间间隔
|
|
89
|
+
currentX += width;
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
// CODE128 (默认 Code B 模式)
|
|
93
|
+
const startBIndex = 104;
|
|
94
|
+
const stopIndex = 106;
|
|
95
|
+
let checksum = startBIndex;
|
|
96
|
+
const codes: number[] = [startBIndex];
|
|
97
|
+
|
|
98
|
+
for (let i = 0; i < value.length; i++) {
|
|
99
|
+
const charCode = value.charCodeAt(i);
|
|
100
|
+
const codeIndex = charCode >= 32 && charCode <= 126 ? charCode - 32 : 0;
|
|
101
|
+
codes.push(codeIndex);
|
|
102
|
+
checksum += codeIndex * (i + 1);
|
|
103
|
+
}
|
|
104
|
+
codes.push(checksum % 103);
|
|
105
|
+
codes.push(stopIndex);
|
|
106
|
+
|
|
107
|
+
for (const code of codes) {
|
|
108
|
+
const pattern = CODE128_PATTERNS[code] ?? CODE128_PATTERNS[0] ?? '212222';
|
|
109
|
+
let isBar = true;
|
|
110
|
+
for (let j = 0; j < pattern.length; j++) {
|
|
111
|
+
const char = pattern[j] ?? '1';
|
|
112
|
+
const runLength = parseInt(char, 10) * width;
|
|
113
|
+
if (isBar) {
|
|
114
|
+
bars.push({ x: currentX, width: runLength });
|
|
115
|
+
}
|
|
116
|
+
currentX += runLength;
|
|
117
|
+
isBar = !isBar;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return bars;
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
const totalWidth = $derived.by(() => {
|
|
126
|
+
if (barcodeBars.length === 0) return 200;
|
|
127
|
+
const lastBar = barcodeBars[barcodeBars.length - 1];
|
|
128
|
+
return lastBar ? lastBar.x + lastBar.width + margin : 200;
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const displayLabel = $derived(text ?? value);
|
|
132
|
+
|
|
133
|
+
async function copyValue() {
|
|
134
|
+
try {
|
|
135
|
+
await navigator.clipboard.writeText(value);
|
|
136
|
+
copied = true;
|
|
137
|
+
setTimeout(() => { copied = false; }, 2000);
|
|
138
|
+
} catch {
|
|
139
|
+
// ignore
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function handlePrint() {
|
|
144
|
+
window.print();
|
|
145
|
+
}
|
|
146
|
+
</script>
|
|
147
|
+
|
|
148
|
+
<div
|
|
149
|
+
data-svadmin-component="Barcode"
|
|
150
|
+
class={cn(
|
|
151
|
+
'inline-flex flex-col items-center justify-center rounded-lg border border-border bg-card p-4 shadow-xs select-none transition-all',
|
|
152
|
+
className
|
|
153
|
+
)}
|
|
154
|
+
>
|
|
155
|
+
<!-- 条形码 SVG 渲染 -->
|
|
156
|
+
<svg
|
|
157
|
+
width={totalWidth}
|
|
158
|
+
height={height + (showText ? 24 : 0)}
|
|
159
|
+
viewBox="0 0 {totalWidth} {height + (showText ? 24 : 0)}"
|
|
160
|
+
class="max-w-full overflow-visible"
|
|
161
|
+
aria-label="Barcode for {value}"
|
|
162
|
+
>
|
|
163
|
+
<!-- 背景填充 -->
|
|
164
|
+
<rect width={totalWidth} height={height + (showText ? 24 : 0)} fill="transparent" />
|
|
165
|
+
|
|
166
|
+
<!-- 条形码黑条 -->
|
|
167
|
+
{#each barcodeBars as bar, idx (`bar-${idx}`)}
|
|
168
|
+
<rect
|
|
169
|
+
x={bar.x}
|
|
170
|
+
y={margin}
|
|
171
|
+
width={bar.width}
|
|
172
|
+
height={height - margin * 0.5}
|
|
173
|
+
class="fill-foreground"
|
|
174
|
+
/>
|
|
175
|
+
{/each}
|
|
176
|
+
|
|
177
|
+
<!-- 下方文本 -->
|
|
178
|
+
{#if showText}
|
|
179
|
+
<text
|
|
180
|
+
x={totalWidth / 2}
|
|
181
|
+
y={height + 16}
|
|
182
|
+
text-anchor="middle"
|
|
183
|
+
class="fill-muted-foreground font-mono text-xs tracking-wider"
|
|
184
|
+
>
|
|
185
|
+
{displayLabel}
|
|
186
|
+
</text>
|
|
187
|
+
{/if}
|
|
188
|
+
</svg>
|
|
189
|
+
|
|
190
|
+
<!-- 快捷操作栏(复制、打印) -->
|
|
191
|
+
{#if showActions}
|
|
192
|
+
<div class="mt-3 flex items-center gap-2 border-t border-border pt-2.5 w-full justify-center">
|
|
193
|
+
<button
|
|
194
|
+
type="button"
|
|
195
|
+
onclick={copyValue}
|
|
196
|
+
class="inline-flex items-center gap-1.5 rounded-md px-2 py-1 text-xs font-medium text-muted-foreground hover:bg-muted hover:text-foreground transition-colors cursor-pointer"
|
|
197
|
+
title="复制条码内容"
|
|
198
|
+
>
|
|
199
|
+
{#if copied}
|
|
200
|
+
<Check class="h-3.5 w-3.5 text-primary" />
|
|
201
|
+
<span>已复制</span>
|
|
202
|
+
{:else}
|
|
203
|
+
<Copy class="h-3.5 w-3.5" />
|
|
204
|
+
<span>复制</span>
|
|
205
|
+
{/if}
|
|
206
|
+
</button>
|
|
207
|
+
|
|
208
|
+
<button
|
|
209
|
+
type="button"
|
|
210
|
+
onclick={handlePrint}
|
|
211
|
+
class="inline-flex items-center gap-1.5 rounded-md px-2 py-1 text-xs font-medium text-muted-foreground hover:bg-muted hover:text-foreground transition-colors cursor-pointer"
|
|
212
|
+
title="打印条形码"
|
|
213
|
+
>
|
|
214
|
+
<Printer class="h-3.5 w-3.5" />
|
|
215
|
+
<span>打印</span>
|
|
216
|
+
</button>
|
|
217
|
+
</div>
|
|
218
|
+
{/if}
|
|
219
|
+
</div>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type BarcodeFormat = 'CODE128' | 'CODE39' | 'EAN13';
|
|
2
|
+
export interface BarcodeProps {
|
|
3
|
+
value: string;
|
|
4
|
+
format?: BarcodeFormat;
|
|
5
|
+
width?: number;
|
|
6
|
+
height?: number;
|
|
7
|
+
showText?: boolean;
|
|
8
|
+
text?: string;
|
|
9
|
+
showActions?: boolean;
|
|
10
|
+
margin?: number;
|
|
11
|
+
class?: string;
|
|
12
|
+
}
|
|
13
|
+
declare const Barcode: import("svelte").Component<BarcodeProps, {}, "">;
|
|
14
|
+
type Barcode = ReturnType<typeof Barcode>;
|
|
15
|
+
export default Barcode;
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
menu,
|
|
19
19
|
maxItems = 0,
|
|
20
20
|
class: className = 'svadmin-breadcrumbs--spaced',
|
|
21
|
-
}: { menu?: MenuItem[]; maxItems?: number; class?: string } = $props();
|
|
21
|
+
}: { menu?: MenuItem[] | undefined; maxItems?: number; class?: string } = $props();
|
|
22
22
|
|
|
23
23
|
interface Crumb { label: string; href?: string; hidden?: boolean; children?: Crumb[]; }
|
|
24
24
|
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
import { useCan } from '@svadmin/core';
|
|
4
4
|
import type { Action } from '@svadmin/core';
|
|
5
5
|
|
|
6
|
-
let { resource, action, params, meta, children, fallback }
|
|
6
|
+
let { resource, action, params, meta, children, fallback }: {
|
|
7
7
|
resource: string;
|
|
8
8
|
action: Action;
|
|
9
9
|
params?: Record<string, unknown>;
|
|
10
10
|
meta?: Record<string, unknown>;
|
|
11
11
|
children: Snippet;
|
|
12
12
|
fallback?: Snippet;
|
|
13
|
-
}
|
|
13
|
+
} = $props();
|
|
14
14
|
|
|
15
15
|
const can = useCan(() => ({ resource, action, params, meta }));
|
|
16
16
|
</script>
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
variant = 'outline',
|
|
19
19
|
size = 'sm',
|
|
20
20
|
children,
|
|
21
|
-
}
|
|
21
|
+
}: {
|
|
22
22
|
taskId: string;
|
|
23
23
|
taskProvider?: import('@svadmin/core').TaskProvider;
|
|
24
24
|
onSuccess?: () => void;
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
variant?: import('./ui/button/index.js').ButtonVariant;
|
|
28
28
|
size?: import('./ui/button/index.js').ButtonSize;
|
|
29
29
|
children?: import('svelte').Snippet;
|
|
30
|
-
}
|
|
30
|
+
} = $props();
|
|
31
31
|
|
|
32
32
|
const action = createTaskAction({
|
|
33
33
|
action: 'cancel',
|