@svadmin/ui 0.129.0 → 0.131.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 +403 -0
- package/dist/app.theme.css +403 -0
- package/dist/components/AboutSettings.svelte +1 -1
- package/dist/components/AccessRevocationMatrix.svelte +425 -0
- package/dist/components/AccessRevocationMatrix.svelte.d.ts +27 -0
- package/dist/components/AudioVisualInspector.svelte +458 -0
- package/dist/components/AudioVisualInspector.svelte.d.ts +53 -0
- package/dist/components/AuditSnapshotCapture.svelte +328 -0
- package/dist/components/AuditSnapshotCapture.svelte.d.ts +28 -0
- package/dist/components/CannedResponsePicker.svelte +257 -0
- package/dist/components/CannedResponsePicker.svelte.d.ts +22 -0
- package/dist/components/ContentModerationCenter.svelte +166 -0
- package/dist/components/ContentModerationCenter.svelte.d.ts +11 -0
- package/dist/components/ContractClauseDiffViewer.svelte +566 -0
- package/dist/components/ContractClauseDiffViewer.svelte.d.ts +53 -0
- package/dist/components/DataImportPipeline.svelte +577 -0
- package/dist/components/DataImportPipeline.svelte.d.ts +35 -0
- package/dist/components/DataRetentionPolicyEditor.svelte +455 -0
- package/dist/components/DataRetentionPolicyEditor.svelte.d.ts +10 -0
- package/dist/components/ElectronicSealInspector.svelte +450 -0
- package/dist/components/ElectronicSealInspector.svelte.d.ts +72 -0
- package/dist/components/EmployeeOffboardingAuditor.svelte +405 -0
- package/dist/components/EmployeeOffboardingAuditor.svelte.d.ts +39 -0
- package/dist/components/FeatureFlagStudio.svelte +583 -0
- package/dist/components/FeatureFlagStudio.svelte.d.ts +12 -0
- package/dist/components/FieldMappingBuilder.svelte +393 -0
- package/dist/components/FieldMappingBuilder.svelte.d.ts +39 -0
- package/dist/components/GatewayRouteEditor.svelte +493 -0
- package/dist/components/GatewayRouteEditor.svelte.d.ts +34 -0
- package/dist/components/HotkeysHelpModal.svelte +286 -0
- package/dist/components/HotkeysHelpModal.svelte.d.ts +21 -0
- package/dist/components/I18nStudio.svelte +635 -0
- package/dist/components/I18nStudio.svelte.d.ts +23 -0
- package/dist/components/IpAccessRuleEditor.svelte +290 -0
- package/dist/components/IpAccessRuleEditor.svelte.d.ts +19 -0
- package/dist/components/IpWhitelistDrawer.svelte +94 -0
- package/dist/components/IpWhitelistDrawer.svelte.d.ts +10 -0
- package/dist/components/MediaAuthenticityAuditCard.svelte +357 -0
- package/dist/components/MediaAuthenticityAuditCard.svelte.d.ts +64 -0
- package/dist/components/MediaGallery.svelte +575 -0
- package/dist/components/MediaGallery.svelte.d.ts +34 -0
- package/dist/components/NotificationCenter.svelte +20 -1
- package/dist/components/NotificationCenter.svelte.d.ts +2 -0
- package/dist/components/NotificationDrawer.svelte +242 -0
- package/dist/components/NotificationDrawer.svelte.d.ts +40 -0
- package/dist/components/PrintDocument.svelte +95 -0
- package/dist/components/PrintDocument.svelte.d.ts +10 -0
- package/dist/components/PrintPreviewModal.svelte +52 -0
- package/dist/components/PrintPreviewModal.svelte.d.ts +11 -0
- package/dist/components/PrintTemplateDesigner.svelte +280 -0
- package/dist/components/PrintTemplateDesigner.svelte.d.ts +11 -0
- package/dist/components/RateLimitPolicyPanel.svelte +369 -0
- package/dist/components/RateLimitPolicyPanel.svelte.d.ts +29 -0
- package/dist/components/ResizableSplitter.svelte +246 -0
- package/dist/components/ResizableSplitter.svelte.d.ts +18 -0
- package/dist/components/SensitiveWordAuditor.svelte +368 -0
- package/dist/components/SensitiveWordAuditor.svelte.d.ts +9 -0
- package/dist/components/ServiceDeskTicketCard.svelte +297 -0
- package/dist/components/ServiceDeskTicketCard.svelte.d.ts +52 -0
- package/dist/components/ShiftScheduler.svelte +490 -0
- package/dist/components/ShiftScheduler.svelte.d.ts +50 -0
- package/dist/components/SslCertificateMonitorCard.svelte +309 -0
- package/dist/components/SslCertificateMonitorCard.svelte.d.ts +30 -0
- package/dist/components/SsoConnectionStudio.svelte +784 -0
- package/dist/components/SsoConnectionStudio.svelte.d.ts +44 -0
- package/dist/components/SsoSpMetadataPanel.svelte +44 -0
- package/dist/components/SsoSpMetadataPanel.svelte.d.ts +8 -0
- package/dist/components/StepUpAuthModal.svelte +448 -0
- package/dist/components/StepUpAuthModal.svelte.d.ts +26 -0
- package/dist/components/TrafficTopologyInspector.svelte +361 -0
- package/dist/components/TrafficTopologyInspector.svelte.d.ts +43 -0
- package/dist/components/ip-access-rules.d.ts +24 -0
- package/dist/components/ip-access-rules.js +110 -0
- package/dist/components/moderation-utils.d.ts +45 -0
- package/dist/components/moderation-utils.js +74 -0
- package/dist/components/print-document.d.ts +3 -0
- package/dist/components/print-document.js +65 -0
- package/dist/components/print-utils.d.ts +44 -0
- package/dist/components/print-utils.js +68 -0
- package/dist/components/retention-utils.d.ts +31 -0
- package/dist/components/retention-utils.js +38 -0
- package/dist/components/sso-connection-presets.d.ts +2 -0
- package/dist/components/sso-connection-presets.js +59 -0
- package/dist/components/ui/sheet/sheet.svelte +3 -1
- package/dist/components/ui/sheet/sheet.svelte.d.ts +1 -0
- package/dist/components/useFeatureFlag.d.svelte.ts +1 -0
- package/dist/components/useFeatureFlag.svelte.d.ts +45 -0
- package/dist/components/useFeatureFlag.svelte.js +94 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +53 -0
- package/package.json +5 -4
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
|
|
4
|
+
export type NotificationCategory = 'TASKS' | 'ANNOUNCEMENTS' | 'SECURITY_ALERTS';
|
|
5
|
+
export interface NotificationAction {
|
|
6
|
+
id: string;
|
|
7
|
+
label: string;
|
|
8
|
+
variant?: 'primary' | 'destructive' | 'default';
|
|
9
|
+
onClick?: (item: NotificationItem) => void | Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export interface NotificationItem {
|
|
12
|
+
id: string;
|
|
13
|
+
title: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
category: NotificationCategory;
|
|
16
|
+
read: boolean;
|
|
17
|
+
createdAt: string;
|
|
18
|
+
avatar?: string;
|
|
19
|
+
badge?: string;
|
|
20
|
+
actions?: NotificationAction[];
|
|
21
|
+
meta?: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
export interface NotificationDrawerProps {
|
|
24
|
+
open?: boolean;
|
|
25
|
+
items?: NotificationItem[];
|
|
26
|
+
dndEnabled?: boolean;
|
|
27
|
+
class?: string;
|
|
28
|
+
onClose?: () => void | Promise<void>;
|
|
29
|
+
onItemClick?: (item: NotificationItem) => void | Promise<void>;
|
|
30
|
+
onMarkAllRead?: () => void | Promise<void>;
|
|
31
|
+
onClearRead?: () => void | Promise<void>;
|
|
32
|
+
onToggleDnd?: (enabled: boolean) => void | Promise<void>;
|
|
33
|
+
onAction?: (actionId: string, item: NotificationItem) => void | Promise<void>;
|
|
34
|
+
onError?: (error: unknown) => void;
|
|
35
|
+
customItem?: Snippet<[{ item: NotificationItem; index: number }]>;
|
|
36
|
+
}
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<script lang="ts">
|
|
40
|
+
import { Sheet } from './ui/sheet/index.js';
|
|
41
|
+
|
|
42
|
+
let {
|
|
43
|
+
open = $bindable(false), items = $bindable([]), dndEnabled = $bindable(false),
|
|
44
|
+
class: className = '', onClose, onItemClick, onMarkAllRead, onClearRead,
|
|
45
|
+
onToggleDnd, onAction, onError, customItem,
|
|
46
|
+
}: NotificationDrawerProps = $props();
|
|
47
|
+
|
|
48
|
+
type Filter = 'ALL' | 'UNREAD' | NotificationCategory;
|
|
49
|
+
const categories: { key: Filter; label: string }[] = [
|
|
50
|
+
{ key: 'ALL', label: 'All' }, { key: 'UNREAD', label: 'Unread' },
|
|
51
|
+
{ key: 'TASKS', label: 'Tasks' }, { key: 'ANNOUNCEMENTS', label: 'Notices' },
|
|
52
|
+
{ key: 'SECURITY_ALERTS', label: 'Security' },
|
|
53
|
+
];
|
|
54
|
+
let activeTab = $state<Filter>('ALL');
|
|
55
|
+
let pendingOperation = $state<string | null>(null);
|
|
56
|
+
let errorMessage = $state('');
|
|
57
|
+
const filteredItems = $derived(items.filter(item => activeTab === 'ALL'
|
|
58
|
+
|| (activeTab === 'UNREAD' ? !item.read : item.category === activeTab)));
|
|
59
|
+
const unreadCounts = $derived.by(() => {
|
|
60
|
+
const counts: Record<Filter, number> = { ALL: 0, UNREAD: 0, TASKS: 0, ANNOUNCEMENTS: 0, SECURITY_ALERTS: 0 };
|
|
61
|
+
for (const item of items) {
|
|
62
|
+
if (!item.read) { counts.ALL++; counts.UNREAD++; counts[item.category]++; }
|
|
63
|
+
}
|
|
64
|
+
return counts;
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
function reportError(error: unknown) {
|
|
68
|
+
errorMessage = error instanceof Error ? error.message : 'The notification operation failed. Please try again.';
|
|
69
|
+
try { void Promise.resolve(onError?.(error)).catch(() => {}); } catch { /* 错误观察者不能打断组件恢复。 */ }
|
|
70
|
+
}
|
|
71
|
+
async function runOperation(key: string, operation: () => void | Promise<void>) {
|
|
72
|
+
if (pendingOperation) return;
|
|
73
|
+
pendingOperation = key;
|
|
74
|
+
errorMessage = '';
|
|
75
|
+
try { await operation(); } catch (error) { reportError(error); }
|
|
76
|
+
finally { pendingOperation = null; }
|
|
77
|
+
}
|
|
78
|
+
function handleMarkAllAsRead() {
|
|
79
|
+
return runOperation('mark-all', async () => {
|
|
80
|
+
const ids = new Set(items.map(item => item.id));
|
|
81
|
+
await onMarkAllRead?.();
|
|
82
|
+
items = items.map(item => ids.has(item.id) ? { ...item, read: true } : item);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function handleClearRead() {
|
|
86
|
+
return runOperation('clear-read', async () => {
|
|
87
|
+
const ids = new Set(items.filter(item => item.read).map(item => item.id));
|
|
88
|
+
await onClearRead?.();
|
|
89
|
+
items = items.filter(item => !ids.has(item.id));
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function toggleDndMode() {
|
|
93
|
+
return runOperation('dnd', async () => {
|
|
94
|
+
const enabled = !dndEnabled;
|
|
95
|
+
await onToggleDnd?.(enabled);
|
|
96
|
+
dndEnabled = enabled;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
function markSingleRead(item: NotificationItem) {
|
|
100
|
+
return runOperation(`read:${item.id}`, async () => {
|
|
101
|
+
const updated = { ...item, read: true };
|
|
102
|
+
await onItemClick?.(updated);
|
|
103
|
+
// 不修改调用方传入对象,允许冻结快照和受控 props。
|
|
104
|
+
items = items.map(current => current.id === item.id ? { ...current, read: true } : current);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function handleActionClick(action: NotificationAction, item: NotificationItem) {
|
|
108
|
+
return runOperation(`action:${item.id}:${action.id}`, async () => {
|
|
109
|
+
if (action.onClick) await action.onClick(item);
|
|
110
|
+
else await onAction?.(action.id, item);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
function handleClose() {
|
|
114
|
+
try { void Promise.resolve(onClose?.()).catch(reportError); } catch (error) { reportError(error); }
|
|
115
|
+
}
|
|
116
|
+
</script>
|
|
117
|
+
|
|
118
|
+
<Sheet
|
|
119
|
+
bind:open
|
|
120
|
+
onClose={handleClose}
|
|
121
|
+
closeLabel="Close notification drawer"
|
|
122
|
+
class="svadmin-notification-drawer {className}"
|
|
123
|
+
data-svadmin-component="NotificationDrawer"
|
|
124
|
+
data-dnd-enabled={dndEnabled}
|
|
125
|
+
role="dialog"
|
|
126
|
+
aria-modal="true"
|
|
127
|
+
aria-label="Notification Center Drawer"
|
|
128
|
+
>
|
|
129
|
+
<header class="notification-header">
|
|
130
|
+
<div>
|
|
131
|
+
<h2>Notification Center</h2>
|
|
132
|
+
<p>{unreadCounts.ALL} unread notification{unreadCounts.ALL === 1 ? '' : 's'}</p>
|
|
133
|
+
</div>
|
|
134
|
+
<button class="notification-dnd" type="button" aria-pressed={dndEnabled} disabled={pendingOperation !== null}
|
|
135
|
+
title="Quiet mode preference" onclick={toggleDndMode}>
|
|
136
|
+
{dndEnabled ? 'DND On' : 'DND'}
|
|
137
|
+
</button>
|
|
138
|
+
</header>
|
|
139
|
+
|
|
140
|
+
{#if dndEnabled}
|
|
141
|
+
<p class="notification-quiet-status" role="status">Quiet mode is on. Security alerts remain visible.</p>
|
|
142
|
+
{/if}
|
|
143
|
+
<nav class="notification-categories" aria-label="Notification categories">
|
|
144
|
+
{#each categories as category (category.key)}
|
|
145
|
+
<button type="button" aria-pressed={activeTab === category.key} onclick={() => (activeTab = category.key)}>
|
|
146
|
+
{category.label}
|
|
147
|
+
{#if unreadCounts[category.key] > 0}
|
|
148
|
+
<span class="notification-count" data-security={category.key === 'SECURITY_ALERTS'} data-muted={dndEnabled && category.key !== 'SECURITY_ALERTS'}>
|
|
149
|
+
{unreadCounts[category.key] > 99 ? '99+' : unreadCounts[category.key]}
|
|
150
|
+
</span>
|
|
151
|
+
{/if}
|
|
152
|
+
</button>
|
|
153
|
+
{/each}
|
|
154
|
+
</nav>
|
|
155
|
+
<div class="notification-toolbar">
|
|
156
|
+
<span>{filteredItems.length} item{filteredItems.length === 1 ? '' : 's'}</span>
|
|
157
|
+
<button type="button" disabled={pendingOperation !== null || unreadCounts.ALL === 0} onclick={handleMarkAllAsRead}>Mark all as read</button>
|
|
158
|
+
<button type="button" disabled={pendingOperation !== null || !items.some(item => item.read)} onclick={handleClearRead}>Clear read</button>
|
|
159
|
+
</div>
|
|
160
|
+
{#if errorMessage}<p class="notification-error" role="alert">{errorMessage}</p>{/if}
|
|
161
|
+
<div class="notification-list" aria-busy={pendingOperation !== null}>
|
|
162
|
+
{#if filteredItems.length === 0}
|
|
163
|
+
<p class="notification-empty">No notifications in this category</p>
|
|
164
|
+
{:else}
|
|
165
|
+
{#each filteredItems as item, index (item.id)}
|
|
166
|
+
{#if customItem}
|
|
167
|
+
{@render customItem({ item, index })}
|
|
168
|
+
{:else}
|
|
169
|
+
<article class="notification-item" data-read={item.read} data-security={item.category === 'SECURITY_ALERTS'}>
|
|
170
|
+
<button class="notification-item-open" type="button" disabled={pendingOperation !== null} onclick={() => markSingleRead(item)}>
|
|
171
|
+
<span class="notification-dot" data-read={item.read} data-muted={dndEnabled && item.category !== 'SECURITY_ALERTS'} data-security={item.category === 'SECURITY_ALERTS'} aria-hidden="true"></span>
|
|
172
|
+
<span class="notification-copy">
|
|
173
|
+
<strong>{item.title}</strong>
|
|
174
|
+
{#if item.description}<span>{item.description}</span>{/if}
|
|
175
|
+
<time>{item.createdAt}</time>
|
|
176
|
+
</span>
|
|
177
|
+
{#if item.badge}<span class="notification-badge">{item.badge}</span>{/if}
|
|
178
|
+
</button>
|
|
179
|
+
{#if item.actions && item.actions.length > 0}
|
|
180
|
+
<div class="notification-actions">
|
|
181
|
+
{#each item.actions as action (action.id)}
|
|
182
|
+
<button type="button" data-variant={action.variant ?? 'default'} disabled={pendingOperation !== null}
|
|
183
|
+
onclick={() => handleActionClick(action, item)}>
|
|
184
|
+
{pendingOperation === `action:${item.id}:${action.id}` ? 'Working…' : action.label}
|
|
185
|
+
</button>
|
|
186
|
+
{/each}
|
|
187
|
+
</div>
|
|
188
|
+
{/if}
|
|
189
|
+
</article>
|
|
190
|
+
{/if}
|
|
191
|
+
{/each}
|
|
192
|
+
{/if}
|
|
193
|
+
</div>
|
|
194
|
+
</Sheet>
|
|
195
|
+
|
|
196
|
+
<style>
|
|
197
|
+
:global(.svadmin-notification-drawer) {
|
|
198
|
+
display: flex;
|
|
199
|
+
flex-direction: column;
|
|
200
|
+
width: min(30rem, 100vw);
|
|
201
|
+
max-width: 100vw;
|
|
202
|
+
padding: 0;
|
|
203
|
+
color: var(--foreground);
|
|
204
|
+
background: var(--card);
|
|
205
|
+
}
|
|
206
|
+
.notification-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 3rem 1rem 1rem; border-bottom: 1px solid var(--border); }
|
|
207
|
+
.notification-header h2 { margin: 0; font-size: var(--svadmin-text-section); font-weight: 500; }
|
|
208
|
+
.notification-header p { margin: 0.25rem 0 0; color: var(--muted-foreground); font-size: var(--svadmin-text-caption); }
|
|
209
|
+
button { font: inherit; cursor: pointer; }
|
|
210
|
+
button:disabled { cursor: default; opacity: 0.5; }
|
|
211
|
+
button:focus-visible { outline: var(--svadmin-focus-width) solid var(--ring); outline-offset: var(--svadmin-focus-offset); }
|
|
212
|
+
.notification-dnd { padding: 0.375rem 0.5rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--background); color: var(--muted-foreground); font-size: var(--svadmin-text-caption); white-space: nowrap; }
|
|
213
|
+
.notification-dnd[aria-pressed='true'] { color: var(--primary); background: var(--accent); }
|
|
214
|
+
.notification-categories { display: flex; flex-wrap: wrap; padding: 0.5rem; gap: 0.25rem; border-bottom: 1px solid var(--border); }
|
|
215
|
+
.notification-categories > button { display: inline-flex; align-items: center; gap: 0.25rem; padding: 0.5rem; border: 0; border-radius: var(--radius); background: transparent; color: var(--muted-foreground); font-size: var(--svadmin-text-caption); }
|
|
216
|
+
.notification-categories > button[aria-pressed='true'] { color: var(--primary); background: var(--accent); }
|
|
217
|
+
.notification-count { display: inline-grid; place-items: center; min-width: 1rem; padding: 0.125rem 0.25rem; border-radius: 1rem; background: var(--primary); color: var(--primary-foreground); font-size: var(--svadmin-text-caption); }
|
|
218
|
+
.notification-count[data-muted='true'] { background: var(--muted); color: var(--muted-foreground); }
|
|
219
|
+
.notification-count[data-security='true'] { background: var(--destructive); color: var(--destructive-foreground); }
|
|
220
|
+
.notification-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 0.75rem; padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); font-size: var(--svadmin-text-caption); }
|
|
221
|
+
.notification-toolbar > span { margin-right: auto; color: var(--muted-foreground); }
|
|
222
|
+
.notification-toolbar > button { padding: 0; border: 0; background: transparent; color: var(--primary); }
|
|
223
|
+
.notification-list { flex: 1; overflow-y: auto; padding: 0.5rem; min-height: 0; }
|
|
224
|
+
.notification-item { border-bottom: 1px solid var(--border); padding: 0.75rem 0.5rem; }
|
|
225
|
+
.notification-item-open { display: flex; gap: 0.5rem; width: 100%; padding: 0.25rem; border: 0; text-align: start; background: transparent; color: var(--foreground); }
|
|
226
|
+
.notification-item-open:hover { background: var(--accent); }
|
|
227
|
+
.notification-copy { display: flex; flex: 1; min-width: 0; flex-direction: column; gap: 0.375rem; font-size: var(--svadmin-text-label); }
|
|
228
|
+
.notification-copy strong { font-weight: 600; }
|
|
229
|
+
.notification-copy > span, .notification-copy time { color: var(--muted-foreground); font-size: var(--svadmin-text-caption); line-height: 1.5; overflow-wrap: anywhere; }
|
|
230
|
+
.notification-dot { width: 0.5rem; height: 0.5rem; margin-top: 0.375rem; border-radius: 50%; flex-shrink: 0; background: var(--primary); }
|
|
231
|
+
.notification-dot[data-muted='true'] { background: var(--muted-foreground); }
|
|
232
|
+
.notification-dot[data-security='true'] { background: var(--destructive); }
|
|
233
|
+
.notification-dot[data-read='true'] { background: transparent; }
|
|
234
|
+
.notification-badge { align-self: flex-start; border: 1px solid var(--border); border-radius: var(--radius); padding: 0.125rem 0.25rem; font-size: var(--svadmin-text-caption); }
|
|
235
|
+
.notification-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; padding: 0.5rem 0 0 1rem; }
|
|
236
|
+
.notification-actions button { padding: 0.375rem 0.5rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--background); color: var(--foreground); font-size: var(--svadmin-text-caption); }
|
|
237
|
+
.notification-actions button[data-variant='primary'] { background: var(--primary); border-color: var(--primary); color: var(--primary-foreground); }
|
|
238
|
+
.notification-actions button[data-variant='destructive'] { color: var(--destructive); border-color: var(--destructive); }
|
|
239
|
+
.notification-error { margin: 0; padding: 0.75rem 1rem; color: var(--destructive); background: var(--card); font-size: var(--svadmin-text-label); }
|
|
240
|
+
.notification-empty { padding: 3rem 1rem; margin: 0; color: var(--muted-foreground); text-align: center; font-size: var(--svadmin-text-label); }
|
|
241
|
+
.notification-quiet-status { margin: 0; padding: 0.75rem 1rem; color: var(--muted-foreground); background: var(--muted); font-size: var(--svadmin-text-caption); }
|
|
242
|
+
</style>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
export type NotificationCategory = 'TASKS' | 'ANNOUNCEMENTS' | 'SECURITY_ALERTS';
|
|
3
|
+
export interface NotificationAction {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
variant?: 'primary' | 'destructive' | 'default';
|
|
7
|
+
onClick?: (item: NotificationItem) => void | Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export interface NotificationItem {
|
|
10
|
+
id: string;
|
|
11
|
+
title: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
category: NotificationCategory;
|
|
14
|
+
read: boolean;
|
|
15
|
+
createdAt: string;
|
|
16
|
+
avatar?: string;
|
|
17
|
+
badge?: string;
|
|
18
|
+
actions?: NotificationAction[];
|
|
19
|
+
meta?: Record<string, unknown>;
|
|
20
|
+
}
|
|
21
|
+
export interface NotificationDrawerProps {
|
|
22
|
+
open?: boolean;
|
|
23
|
+
items?: NotificationItem[];
|
|
24
|
+
dndEnabled?: boolean;
|
|
25
|
+
class?: string;
|
|
26
|
+
onClose?: () => void | Promise<void>;
|
|
27
|
+
onItemClick?: (item: NotificationItem) => void | Promise<void>;
|
|
28
|
+
onMarkAllRead?: () => void | Promise<void>;
|
|
29
|
+
onClearRead?: () => void | Promise<void>;
|
|
30
|
+
onToggleDnd?: (enabled: boolean) => void | Promise<void>;
|
|
31
|
+
onAction?: (actionId: string, item: NotificationItem) => void | Promise<void>;
|
|
32
|
+
onError?: (error: unknown) => void;
|
|
33
|
+
customItem?: Snippet<[{
|
|
34
|
+
item: NotificationItem;
|
|
35
|
+
index: number;
|
|
36
|
+
}]>;
|
|
37
|
+
}
|
|
38
|
+
declare const NotificationDrawer: import("svelte").Component<NotificationDrawerProps, {}, "items" | "open" | "dndEnabled">;
|
|
39
|
+
type NotificationDrawer = ReturnType<typeof NotificationDrawer>;
|
|
40
|
+
export default NotificationDrawer;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import Barcode from './Barcode.svelte';
|
|
3
|
+
import QRCode from './QRCode.svelte';
|
|
4
|
+
import { currencyMinorUnits, numberToChineseCurrency, PRINT_PAPER_DIMENSIONS,
|
|
5
|
+
type PrintTemplateConfig } from './print-utils.js';
|
|
6
|
+
|
|
7
|
+
let { config, data = {}, items = [], copies = config.copies }: {
|
|
8
|
+
config: PrintTemplateConfig;
|
|
9
|
+
data?: Record<string, unknown>;
|
|
10
|
+
items?: Record<string, unknown>[];
|
|
11
|
+
copies?: string[];
|
|
12
|
+
} = $props();
|
|
13
|
+
|
|
14
|
+
const columns = $derived(config.columns.filter(column => column.visible));
|
|
15
|
+
const totalCents = $derived(items.reduce((sum, row) =>
|
|
16
|
+
sum + currencyMinorUnits(Number(row['total_amount'] ?? row['amount'] ?? 0)), 0));
|
|
17
|
+
const total = $derived(totalCents / 100);
|
|
18
|
+
const quantity = $derived(items.reduce((sum, row) => sum + Number(row['quantity'] ?? row['qty'] ?? 0), 0));
|
|
19
|
+
const paper = $derived(PRINT_PAPER_DIMENSIONS[config.paperSize]);
|
|
20
|
+
// 窄纸不能沿用 A4 的固定列宽,否则会把金额列挤出可打印区域。
|
|
21
|
+
const fluidColumns = $derived(paper.width <= 100);
|
|
22
|
+
const orderNumber = $derived(String(data['order_no'] ?? config.metaFields.find(field => field.field === 'order_no')?.value ?? ''));
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
{#each copies.length ? copies : ['打印联'] as copy, copyIndex (copyIndex)}
|
|
26
|
+
<article class="print-page" data-print-copy={copyIndex}
|
|
27
|
+
style:width="{paper.width}mm" style:min-height="{paper.height}mm">
|
|
28
|
+
{#if config.showWatermark && config.watermarkText}
|
|
29
|
+
<div class="watermark" aria-hidden="true">{config.watermarkText}</div>
|
|
30
|
+
{/if}
|
|
31
|
+
<header><div><strong>{config.companyName}</strong><p>{config.subTitle ?? ''}</p></div><span>{copy}</span></header>
|
|
32
|
+
<div class="document-title">
|
|
33
|
+
<h1>{config.title}</h1>
|
|
34
|
+
<div class="codes">
|
|
35
|
+
{#if config.showBarcode && orderNumber}
|
|
36
|
+
{#if /^[\x20-\x7e]+$/.test(orderNumber)}
|
|
37
|
+
<Barcode value={orderNumber} width={1} height={45} margin={10} />
|
|
38
|
+
{:else}<span>单号不支持 Code 128 B 编码</span>{/if}
|
|
39
|
+
{/if}
|
|
40
|
+
{#if config.showQrCode && orderNumber}
|
|
41
|
+
<QRCode value={orderNumber} size={80} color="black" background="white" ariaLabel="单据二维码" />
|
|
42
|
+
{/if}
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
<dl>{#each config.metaFields as field (field.id)}
|
|
46
|
+
<div><dt>{field.label}:</dt><dd>{String(data[field.field] ?? field.value ?? '-')}</dd></div>
|
|
47
|
+
{/each}</dl>
|
|
48
|
+
{#if columns.length}
|
|
49
|
+
<table>
|
|
50
|
+
<thead><tr>{#each columns as column (column.id)}
|
|
51
|
+
<th style:text-align={column.align ?? 'left'} style:width={fluidColumns ? 'auto' : column.width ?? 'auto'}>{column.label}</th>
|
|
52
|
+
{/each}</tr></thead>
|
|
53
|
+
<tbody>{#each items as row, index (index)}
|
|
54
|
+
<tr>{#each columns as column (column.id)}
|
|
55
|
+
<td style:text-align={column.align ?? 'left'}>
|
|
56
|
+
{#if column.field === 'index'}{index + 1}
|
|
57
|
+
{:else if column.field === 'total_amount' || column.field === 'unit_price'}
|
|
58
|
+
{config.currencySymbol}{(currencyMinorUnits(Number(row[column.field] ?? (column.field === 'total_amount' ? row['amount'] : 0) ?? 0)) / 100).toFixed(2)}
|
|
59
|
+
{:else if column.field === 'quantity'}{row['quantity'] ?? row['qty'] ?? ''}
|
|
60
|
+
{:else}{String(row[column.field] ?? '')}{/if}
|
|
61
|
+
</td>
|
|
62
|
+
{/each}</tr>
|
|
63
|
+
{:else}<tr><td colspan={columns.length}>暂无单据明细数据</td></tr>{/each}</tbody>
|
|
64
|
+
</table>
|
|
65
|
+
{/if}
|
|
66
|
+
<div class="summary"><strong>合计 (TOTAL):</strong><span>总件数: {quantity} 件</span>
|
|
67
|
+
<strong>合计金额: {config.currencySymbol}{total.toFixed(2)}</strong></div>
|
|
68
|
+
{#if config.showAmountInWords}
|
|
69
|
+
<div class="summary">金额大写: <strong>{numberToChineseCurrency(total)}</strong>
|
|
70
|
+
<span>小写合计: {config.currencySymbol}{total.toFixed(2)}</span></div>
|
|
71
|
+
{/if}
|
|
72
|
+
<footer>{#each config.signers as signer, index (index)}<span>{signer}</span>{/each}</footer>
|
|
73
|
+
{#if config.footerNotes}<p class="notes">{config.footerNotes}</p>{/if}
|
|
74
|
+
</article>
|
|
75
|
+
{/each}
|
|
76
|
+
|
|
77
|
+
<style>
|
|
78
|
+
.print-page { box-sizing: border-box; padding: 8mm; position: relative; background: white; color: black; font: 9pt/1.5 sans-serif; overflow-wrap: anywhere; }
|
|
79
|
+
header, .document-title, .summary, footer { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
|
|
80
|
+
header { border-bottom: 1px solid black; padding-bottom: 8px; }
|
|
81
|
+
header p, h1 { margin: 0; }
|
|
82
|
+
h1 { font-size: 15pt; }
|
|
83
|
+
.document-title { margin: 12px 0; }
|
|
84
|
+
.codes { display: flex; flex-wrap: wrap; align-items: center; max-width: 100%; }
|
|
85
|
+
.codes :global([data-svadmin-component="Barcode"]) { color: black; background: white; --foreground: black; --muted-foreground: black; max-width: 100%; }
|
|
86
|
+
dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-block: 1px solid color-mix(in srgb, currentColor 30%, transparent); padding: 8px 0; }
|
|
87
|
+
dl div { display: flex; flex-wrap: wrap; gap: 6px; } dd { margin: 0; }
|
|
88
|
+
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
|
|
89
|
+
th, td { border: 1px solid color-mix(in srgb, currentColor 30%, transparent); padding: 4px; overflow-wrap: anywhere; }
|
|
90
|
+
tr { break-inside: avoid; }
|
|
91
|
+
.summary { padding: 8px 0; border-bottom: 1px solid color-mix(in srgb, currentColor 30%, transparent); }
|
|
92
|
+
footer { margin-top: 16px; } .notes { font-size: 7.5pt; }
|
|
93
|
+
.watermark { position: absolute; inset: 0; display: grid; place-items: center; opacity: 0.05; font-size: 36pt; pointer-events: none; }
|
|
94
|
+
@media print { .print-page:not(:last-child) { break-after: page; } }
|
|
95
|
+
</style>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type PrintTemplateConfig } from './print-utils.js';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
config: PrintTemplateConfig;
|
|
4
|
+
data?: Record<string, unknown>;
|
|
5
|
+
items?: Record<string, unknown>[];
|
|
6
|
+
copies?: string[];
|
|
7
|
+
};
|
|
8
|
+
declare const PrintDocument: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
9
|
+
type PrintDocument = ReturnType<typeof PrintDocument>;
|
|
10
|
+
export default PrintDocument;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { Printer, X } from '@lucide/svelte';
|
|
3
|
+
import type { PrintTemplateConfig } from './print-utils.js';
|
|
4
|
+
import PrintDocument from './PrintDocument.svelte';
|
|
5
|
+
import { printDocument } from './print-document.js';
|
|
6
|
+
|
|
7
|
+
export interface PrintPreviewModalProps {
|
|
8
|
+
open?: boolean;
|
|
9
|
+
config: PrintTemplateConfig;
|
|
10
|
+
data?: Record<string, unknown>;
|
|
11
|
+
items?: Array<Record<string, unknown>>;
|
|
12
|
+
onClose?: () => void;
|
|
13
|
+
}
|
|
14
|
+
let { open = $bindable(false), config, data = {}, items = [], onClose }: PrintPreviewModalProps = $props();
|
|
15
|
+
let pages = $state<HTMLDivElement>();
|
|
16
|
+
let printing = $state(false);
|
|
17
|
+
let printError = $state('');
|
|
18
|
+
|
|
19
|
+
async function handlePrint() {
|
|
20
|
+
if (printing || !pages) return;
|
|
21
|
+
printing = true;
|
|
22
|
+
printError = '';
|
|
23
|
+
try { await printDocument(pages, config.paperSize); }
|
|
24
|
+
catch { printError = '打印失败,请检查浏览器打印权限后重试'; }
|
|
25
|
+
finally { printing = false; }
|
|
26
|
+
}
|
|
27
|
+
function handleClose() { open = false; onClose?.(); }
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
{#if open}
|
|
31
|
+
<div class="fixed inset-0 z-50 flex items-center justify-center bg-foreground/60 p-4"
|
|
32
|
+
data-svadmin-component="PrintPreviewModal" data-svadmin-resource="print_templates">
|
|
33
|
+
<div role="dialog" aria-modal="true" aria-label="单据打印预览"
|
|
34
|
+
class="w-full max-w-4xl max-h-[92vh] overflow-auto rounded-lg bg-card border border-border p-6 shadow-2xl text-foreground">
|
|
35
|
+
<div class="flex items-center justify-between gap-3 pb-3 border-b border-border">
|
|
36
|
+
<h3 class="font-bold text-base">单据打印预览 <span class="text-xs">{config.paperSize}</span></h3>
|
|
37
|
+
<div class="flex gap-2">
|
|
38
|
+
<button type="button" onclick={handlePrint} disabled={printing}
|
|
39
|
+
class="flex gap-2 items-center px-3 py-2 rounded-md bg-primary text-primary-foreground">
|
|
40
|
+
<Printer class="size-4" />打印全部联次
|
|
41
|
+
</button>
|
|
42
|
+
<button type="button" onclick={handleClose} aria-label="关闭" title="关闭"
|
|
43
|
+
class="p-2 rounded-md border border-border"><X class="size-4" /></button>
|
|
44
|
+
</div>
|
|
45
|
+
</div>
|
|
46
|
+
{#if printError}<p role="alert">{printError}</p>{/if}
|
|
47
|
+
<div class="overflow-x-auto mt-4">
|
|
48
|
+
<div bind:this={pages} class="print-pages"><PrintDocument {config} {data} {items} /></div>
|
|
49
|
+
</div>
|
|
50
|
+
</div>
|
|
51
|
+
</div>
|
|
52
|
+
{/if}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PrintTemplateConfig } from './print-utils.js';
|
|
2
|
+
export interface PrintPreviewModalProps {
|
|
3
|
+
open?: boolean;
|
|
4
|
+
config: PrintTemplateConfig;
|
|
5
|
+
data?: Record<string, unknown>;
|
|
6
|
+
items?: Array<Record<string, unknown>>;
|
|
7
|
+
onClose?: () => void;
|
|
8
|
+
}
|
|
9
|
+
declare const PrintPreviewModal: import("svelte").Component<PrintPreviewModalProps, {}, "open">;
|
|
10
|
+
type PrintPreviewModal = ReturnType<typeof PrintPreviewModal>;
|
|
11
|
+
export default PrintPreviewModal;
|