@svadmin/ui 0.111.0 → 0.113.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 +216 -0
- package/dist/app.theme.css +216 -0
- package/dist/components/AboutSettings.svelte +1 -1
- package/dist/components/AutoForm.svelte +24 -35
- package/dist/components/FormDependency.svelte +36 -0
- package/dist/components/FormDependency.svelte.d.ts +12 -0
- package/dist/components/Icon.svelte +57 -0
- package/dist/components/Icon.svelte.d.ts +10 -0
- package/dist/components/JsonSchemaForm.svelte +68 -10
- package/dist/components/PageContainer.svelte +263 -0
- package/dist/components/PageContainer.svelte.d.ts +53 -0
- package/dist/components/ProDescriptions.svelte +278 -0
- package/dist/components/ProDescriptions.svelte.d.ts +37 -0
- package/dist/components/QueryFilter.svelte +194 -0
- package/dist/components/QueryFilter.svelte.d.ts +34 -0
- package/dist/components/RealtimeMonitorView.svelte +245 -0
- package/dist/components/RealtimeMonitorView.svelte.d.ts +40 -0
- package/dist/components/RoleSwitcher.svelte +267 -0
- package/dist/components/RoleSwitcher.svelte.d.ts +40 -0
- package/dist/components/WorkflowDesigner.svelte +244 -0
- package/dist/components/WorkflowDesigner.svelte.d.ts +29 -0
- package/dist/components/auto-form-layout.d.ts +28 -0
- package/dist/components/auto-form-layout.js +70 -0
- package/dist/components/fields/UploadField.svelte +222 -0
- package/dist/components/fields/UploadField.svelte.d.ts +14 -0
- package/dist/components/icons/IconApprove.svelte +35 -0
- package/dist/components/icons/IconApprove.svelte.d.ts +4 -0
- package/dist/components/icons/IconAudit.svelte +38 -0
- package/dist/components/icons/IconAudit.svelte.d.ts +4 -0
- package/dist/components/icons/IconBilling.svelte +37 -0
- package/dist/components/icons/IconBilling.svelte.d.ts +4 -0
- package/dist/components/icons/IconCluster.svelte +41 -0
- package/dist/components/icons/IconCluster.svelte.d.ts +4 -0
- package/dist/components/icons/IconMonitor.svelte +37 -0
- package/dist/components/icons/IconMonitor.svelte.d.ts +4 -0
- package/dist/components/icons/IconReject.svelte +36 -0
- package/dist/components/icons/IconReject.svelte.d.ts +4 -0
- package/dist/components/icons/IconSeal.svelte +36 -0
- package/dist/components/icons/IconSeal.svelte.d.ts +4 -0
- package/dist/components/icons/IconSecurity.svelte +35 -0
- package/dist/components/icons/IconSecurity.svelte.d.ts +4 -0
- package/dist/components/icons/IconTenant.svelte +39 -0
- package/dist/components/icons/IconTenant.svelte.d.ts +4 -0
- package/dist/components/icons/IconWorkflow.svelte +38 -0
- package/dist/components/icons/IconWorkflow.svelte.d.ts +4 -0
- package/dist/components/icons/index.d.ts +11 -0
- package/dist/components/icons/index.js +10 -0
- package/dist/components/icons/types.d.ts +15 -0
- package/dist/components/icons/types.js +1 -0
- package/dist/components/json-schema-form-state.d.ts +3 -1
- package/dist/icon-registry.d.ts +27 -0
- package/dist/icon-registry.js +52 -0
- package/dist/icons.d.ts +5 -1
- package/dist/icons.js +4 -0
- package/dist/index.d.ts +27 -7
- package/dist/index.js +19 -6
- package/dist/intent-preload.d.ts +28 -0
- package/dist/intent-preload.js +76 -0
- package/package.json +5 -5
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import { cn } from '../utils.js';
|
|
4
|
+
import IconMonitor from './icons/IconMonitor.svelte';
|
|
5
|
+
import IconCluster from './icons/IconCluster.svelte';
|
|
6
|
+
import IconAudit from './icons/IconAudit.svelte';
|
|
7
|
+
import IconSecurity from './icons/IconSecurity.svelte';
|
|
8
|
+
|
|
9
|
+
export interface MetricCardItem {
|
|
10
|
+
label: string;
|
|
11
|
+
value: string | number;
|
|
12
|
+
subtext?: string;
|
|
13
|
+
trend?: 'up' | 'down' | 'neutral';
|
|
14
|
+
status?: 'normal' | 'warning' | 'danger';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface RealtimeMonitorViewProps {
|
|
18
|
+
/** Title of the monitor dashboard */
|
|
19
|
+
title?: string;
|
|
20
|
+
/** Subtitle or description */
|
|
21
|
+
description?: string;
|
|
22
|
+
/** Current streaming or service status */
|
|
23
|
+
liveStatus?: 'live' | 'buffering' | 'paused' | 'offline';
|
|
24
|
+
/** Server metrics list */
|
|
25
|
+
metrics?: MetricCardItem[];
|
|
26
|
+
/** Stream resolution string (e.g. 1080P 60fps) */
|
|
27
|
+
streamResolution?: string;
|
|
28
|
+
/** Bitrate display string (e.g. 6.4 Mbps) */
|
|
29
|
+
bitrate?: string;
|
|
30
|
+
/** Active viewers count */
|
|
31
|
+
viewersCount?: number;
|
|
32
|
+
/** Event logs or audit entries */
|
|
33
|
+
logs?: Array<{ id: string; time: string; level: 'info' | 'warn' | 'error'; message: string }>;
|
|
34
|
+
/** Callback when emergency switch is toggled */
|
|
35
|
+
onswitchtoggle?: (key: string, enabled: boolean) => void;
|
|
36
|
+
/** Custom extra actions in the header */
|
|
37
|
+
extra?: Snippet;
|
|
38
|
+
/** Additional CSS classes */
|
|
39
|
+
class?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let {
|
|
43
|
+
title = '实时运维监控看板',
|
|
44
|
+
description = '实时监控集群健康、流媒体推流质量与高频网关流量指标。',
|
|
45
|
+
liveStatus = 'live',
|
|
46
|
+
metrics = [
|
|
47
|
+
{ label: 'CPU 使用率', value: '38.4%', subtext: '8 核心正常', status: 'normal' },
|
|
48
|
+
{ label: '内存占用率', value: '62.1%', subtext: '已用 19.8 / 32 GB', status: 'normal' },
|
|
49
|
+
{ label: '网络吞吐 (In/Out)', value: '1.24 GB/s', subtext: '高峰负载平稳', status: 'normal' },
|
|
50
|
+
{ label: '实时 QPS', value: '18,420', subtext: '同比 +12.3%', trend: 'up', status: 'normal' },
|
|
51
|
+
],
|
|
52
|
+
streamResolution = '1080P @ 60 FPS',
|
|
53
|
+
bitrate = '6.8 Mbps',
|
|
54
|
+
viewersCount = 12480,
|
|
55
|
+
logs = [
|
|
56
|
+
{ id: '1', time: '05:40:12', level: 'info', message: '网关集群负载均衡健康检查完成 (所有节点在线)' },
|
|
57
|
+
{ id: '2', time: '05:41:03', level: 'info', message: '推流边缘节点 edge-sh-02 建立推流连接' },
|
|
58
|
+
{ id: '3', time: '05:42:25', level: 'warn', message: '节点 node-ap-04 出现短暂网络抖动 (已自动重连)' },
|
|
59
|
+
],
|
|
60
|
+
onswitchtoggle,
|
|
61
|
+
extra,
|
|
62
|
+
class: className = '',
|
|
63
|
+
}: RealtimeMonitorViewProps = $props();
|
|
64
|
+
|
|
65
|
+
let emergencySwitches = $state([
|
|
66
|
+
{ key: 'throttle', label: '网关高频限流保护', enabled: false },
|
|
67
|
+
{ key: 'circuit_breaker', label: '下游微服务自动熔断', enabled: true },
|
|
68
|
+
{ key: 'debug_dump', label: '全链路采样日志捕获', enabled: false },
|
|
69
|
+
]);
|
|
70
|
+
|
|
71
|
+
function toggleSwitch(key: string) {
|
|
72
|
+
const item = emergencySwitches.find((s) => s.key === key);
|
|
73
|
+
if (!item) return;
|
|
74
|
+
item.enabled = !item.enabled;
|
|
75
|
+
onswitchtoggle?.(key, item.enabled);
|
|
76
|
+
}
|
|
77
|
+
</script>
|
|
78
|
+
|
|
79
|
+
<div
|
|
80
|
+
data-svadmin-component="RealtimeMonitorView"
|
|
81
|
+
class={cn('svadmin-realtime-monitor flex flex-col gap-5 p-4 sm:p-6 bg-background text-foreground', className)}
|
|
82
|
+
>
|
|
83
|
+
<!-- Header with live pulse -->
|
|
84
|
+
<header class="flex flex-col sm:flex-row sm:items-center justify-between gap-3 pb-4 border-b border-border">
|
|
85
|
+
<div class="flex items-center gap-3">
|
|
86
|
+
<div class="p-2.5 rounded-[4px] bg-primary/10 text-primary">
|
|
87
|
+
<IconMonitor size={22} />
|
|
88
|
+
</div>
|
|
89
|
+
<div>
|
|
90
|
+
<div class="flex items-center gap-2.5">
|
|
91
|
+
<h1 class="text-base sm:text-lg font-semibold">{title}</h1>
|
|
92
|
+
<span
|
|
93
|
+
class={cn(
|
|
94
|
+
'inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full text-[10px] font-medium border font-mono tracking-wider uppercase',
|
|
95
|
+
liveStatus === 'live' && 'bg-success/10 text-success border-success/20',
|
|
96
|
+
liveStatus === 'buffering' && 'bg-warning/10 text-warning border-warning/20',
|
|
97
|
+
liveStatus === 'paused' && 'bg-info/10 text-info border-info/20',
|
|
98
|
+
liveStatus === 'offline' && 'bg-muted text-muted-foreground border-border'
|
|
99
|
+
)}
|
|
100
|
+
>
|
|
101
|
+
<span class="relative flex h-1.5 w-1.5">
|
|
102
|
+
{#if liveStatus === 'live'}
|
|
103
|
+
<span class="animate-ping absolute inline-flex h-full w-full rounded-full bg-success opacity-75"></span>
|
|
104
|
+
{/if}
|
|
105
|
+
<span
|
|
106
|
+
class={cn(
|
|
107
|
+
'relative inline-flex rounded-full h-1.5 w-1.5',
|
|
108
|
+
liveStatus === 'live' && 'bg-success',
|
|
109
|
+
liveStatus === 'buffering' && 'bg-warning',
|
|
110
|
+
liveStatus === 'paused' && 'bg-info',
|
|
111
|
+
liveStatus === 'offline' && 'bg-muted-foreground'
|
|
112
|
+
)}
|
|
113
|
+
></span>
|
|
114
|
+
</span>
|
|
115
|
+
{liveStatus}
|
|
116
|
+
</span>
|
|
117
|
+
</div>
|
|
118
|
+
{#if description}
|
|
119
|
+
<p class="text-xs text-muted-foreground mt-0.5">{description}</p>
|
|
120
|
+
{/if}
|
|
121
|
+
</div>
|
|
122
|
+
</div>
|
|
123
|
+
|
|
124
|
+
<div class="flex items-center gap-2">
|
|
125
|
+
{#if extra}
|
|
126
|
+
{@render extra()}
|
|
127
|
+
{/if}
|
|
128
|
+
</div>
|
|
129
|
+
</header>
|
|
130
|
+
|
|
131
|
+
<!-- Metric Cards Grid -->
|
|
132
|
+
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
|
|
133
|
+
{#each metrics as metric (metric.label)}
|
|
134
|
+
<div class="flex flex-col justify-between p-4 rounded-[4px] border border-border bg-card shadow-sm hover:border-primary/40 transition-colors">
|
|
135
|
+
<div class="flex items-center justify-between text-xs text-muted-foreground mb-1">
|
|
136
|
+
<span>{metric.label}</span>
|
|
137
|
+
{#if metric.trend === 'up'}
|
|
138
|
+
<span class="text-xs text-success font-medium flex items-center">↑ 升高</span>
|
|
139
|
+
{:else if metric.trend === 'down'}
|
|
140
|
+
<span class="text-xs text-destructive font-medium flex items-center">↓ 降低</span>
|
|
141
|
+
{/if}
|
|
142
|
+
</div>
|
|
143
|
+
<div class="text-xl sm:text-2xl font-bold tracking-tight text-foreground my-1 font-mono">
|
|
144
|
+
{metric.value}
|
|
145
|
+
</div>
|
|
146
|
+
{#if metric.subtext}
|
|
147
|
+
<div class="text-[11px] text-muted-foreground mt-1">
|
|
148
|
+
{metric.subtext}
|
|
149
|
+
</div>
|
|
150
|
+
{/if}
|
|
151
|
+
</div>
|
|
152
|
+
{/each}
|
|
153
|
+
</div>
|
|
154
|
+
|
|
155
|
+
<!-- Operational Panels -->
|
|
156
|
+
<div class="grid grid-cols-1 lg:grid-cols-3 gap-5">
|
|
157
|
+
<!-- Left 2 Cols: Stream / Gateway Telemetry Detail -->
|
|
158
|
+
<div class="lg:col-span-2 flex flex-col gap-4 p-4 rounded-[4px] border border-border bg-card shadow-sm">
|
|
159
|
+
<div class="flex items-center justify-between pb-2 border-b border-border">
|
|
160
|
+
<div class="flex items-center gap-2 text-sm font-semibold">
|
|
161
|
+
<IconCluster size={16} class="text-primary" />
|
|
162
|
+
<span>边缘节点推流与链路遥测</span>
|
|
163
|
+
</div>
|
|
164
|
+
<span class="text-xs px-2 py-0.5 rounded-[4px] bg-primary/10 text-primary font-mono">
|
|
165
|
+
{liveStatus === 'live' ? '推流正常传输中' : '等待推流输入'}
|
|
166
|
+
</span>
|
|
167
|
+
</div>
|
|
168
|
+
|
|
169
|
+
<!-- Telemetry Spec Grid -->
|
|
170
|
+
<div class="grid grid-cols-3 gap-3 p-3 bg-muted/40 rounded-[4px] border border-border/50 text-center text-xs">
|
|
171
|
+
<div>
|
|
172
|
+
<div class="text-muted-foreground text-[11px]">当前画质编码</div>
|
|
173
|
+
<div class="font-semibold mt-1 font-mono text-sm">{streamResolution}</div>
|
|
174
|
+
</div>
|
|
175
|
+
<div>
|
|
176
|
+
<div class="text-muted-foreground text-[11px]">实时编码码率</div>
|
|
177
|
+
<div class="font-semibold mt-1 font-mono text-sm">{bitrate}</div>
|
|
178
|
+
</div>
|
|
179
|
+
<div>
|
|
180
|
+
<div class="text-muted-foreground text-[11px]">在线连接客户端</div>
|
|
181
|
+
<div class="font-semibold mt-1 font-mono text-sm text-primary">{viewersCount.toLocaleString()}</div>
|
|
182
|
+
</div>
|
|
183
|
+
</div>
|
|
184
|
+
|
|
185
|
+
<!-- Emergency Switches -->
|
|
186
|
+
<div class="mt-2">
|
|
187
|
+
<div class="flex items-center gap-1.5 text-xs font-medium text-foreground mb-2.5">
|
|
188
|
+
<IconSecurity size={14} class="text-primary" />
|
|
189
|
+
<span>应急熔断与主动限流控制</span>
|
|
190
|
+
</div>
|
|
191
|
+
<div class="flex flex-col sm:flex-row gap-3">
|
|
192
|
+
{#each emergencySwitches as sw (sw.key)}
|
|
193
|
+
<button
|
|
194
|
+
type="button"
|
|
195
|
+
onclick={() => toggleSwitch(sw.key)}
|
|
196
|
+
class={cn(
|
|
197
|
+
'flex-1 flex items-center justify-between px-3 py-2 rounded-[4px] border text-xs font-medium transition-all cursor-pointer',
|
|
198
|
+
sw.enabled
|
|
199
|
+
? 'border-primary bg-primary/10 text-primary'
|
|
200
|
+
: 'border-border bg-card text-muted-foreground hover:bg-muted/50'
|
|
201
|
+
)}
|
|
202
|
+
>
|
|
203
|
+
<span>{sw.label}</span>
|
|
204
|
+
<span class={cn('w-2 h-2 rounded-full', sw.enabled ? 'bg-primary' : 'bg-muted-foreground/40')}></span>
|
|
205
|
+
</button>
|
|
206
|
+
{/each}
|
|
207
|
+
</div>
|
|
208
|
+
</div>
|
|
209
|
+
</div>
|
|
210
|
+
|
|
211
|
+
<!-- Right 1 Col: Log Stream -->
|
|
212
|
+
<div class="flex flex-col gap-3 p-4 rounded-[4px] border border-border bg-card shadow-sm">
|
|
213
|
+
<div class="flex items-center justify-between pb-2 border-b border-border">
|
|
214
|
+
<div class="flex items-center gap-2 text-sm font-semibold">
|
|
215
|
+
<IconAudit size={16} class="text-primary" />
|
|
216
|
+
<span>实时日志与审计事件</span>
|
|
217
|
+
</div>
|
|
218
|
+
<span class="text-[10px] text-muted-foreground font-mono">最新 3 条</span>
|
|
219
|
+
</div>
|
|
220
|
+
|
|
221
|
+
<div class="flex flex-col gap-2.5 text-xs overflow-y-auto max-h-64">
|
|
222
|
+
{#each logs as log (log.id)}
|
|
223
|
+
<div class="flex flex-col gap-0.5 p-2 rounded-[4px] bg-muted/40 border border-border/40">
|
|
224
|
+
<div class="flex items-center justify-between">
|
|
225
|
+
<span class="text-[10px] font-mono text-muted-foreground">{log.time}</span>
|
|
226
|
+
<span
|
|
227
|
+
class={cn(
|
|
228
|
+
'text-[10px] uppercase font-mono px-1 rounded-[2px]',
|
|
229
|
+
log.level === 'warn' && 'bg-warning/10 text-warning',
|
|
230
|
+
log.level === 'error' && 'bg-destructive/10 text-destructive',
|
|
231
|
+
log.level === 'info' && 'bg-primary/10 text-primary'
|
|
232
|
+
)}
|
|
233
|
+
>
|
|
234
|
+
{log.level}
|
|
235
|
+
</span>
|
|
236
|
+
</div>
|
|
237
|
+
<p class="text-muted-foreground text-[11px] leading-relaxed mt-0.5">
|
|
238
|
+
{log.message}
|
|
239
|
+
</p>
|
|
240
|
+
</div>
|
|
241
|
+
{/each}
|
|
242
|
+
</div>
|
|
243
|
+
</div>
|
|
244
|
+
</div>
|
|
245
|
+
</div>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
export interface MetricCardItem {
|
|
3
|
+
label: string;
|
|
4
|
+
value: string | number;
|
|
5
|
+
subtext?: string;
|
|
6
|
+
trend?: 'up' | 'down' | 'neutral';
|
|
7
|
+
status?: 'normal' | 'warning' | 'danger';
|
|
8
|
+
}
|
|
9
|
+
export interface RealtimeMonitorViewProps {
|
|
10
|
+
/** Title of the monitor dashboard */
|
|
11
|
+
title?: string;
|
|
12
|
+
/** Subtitle or description */
|
|
13
|
+
description?: string;
|
|
14
|
+
/** Current streaming or service status */
|
|
15
|
+
liveStatus?: 'live' | 'buffering' | 'paused' | 'offline';
|
|
16
|
+
/** Server metrics list */
|
|
17
|
+
metrics?: MetricCardItem[];
|
|
18
|
+
/** Stream resolution string (e.g. 1080P 60fps) */
|
|
19
|
+
streamResolution?: string;
|
|
20
|
+
/** Bitrate display string (e.g. 6.4 Mbps) */
|
|
21
|
+
bitrate?: string;
|
|
22
|
+
/** Active viewers count */
|
|
23
|
+
viewersCount?: number;
|
|
24
|
+
/** Event logs or audit entries */
|
|
25
|
+
logs?: Array<{
|
|
26
|
+
id: string;
|
|
27
|
+
time: string;
|
|
28
|
+
level: 'info' | 'warn' | 'error';
|
|
29
|
+
message: string;
|
|
30
|
+
}>;
|
|
31
|
+
/** Callback when emergency switch is toggled */
|
|
32
|
+
onswitchtoggle?: (key: string, enabled: boolean) => void;
|
|
33
|
+
/** Custom extra actions in the header */
|
|
34
|
+
extra?: Snippet;
|
|
35
|
+
/** Additional CSS classes */
|
|
36
|
+
class?: string;
|
|
37
|
+
}
|
|
38
|
+
declare const RealtimeMonitorView: import("svelte").Component<RealtimeMonitorViewProps, {}, "">;
|
|
39
|
+
type RealtimeMonitorView = ReturnType<typeof RealtimeMonitorView>;
|
|
40
|
+
export default RealtimeMonitorView;
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import { cn } from '../utils.js';
|
|
4
|
+
import IconSecurity from './icons/IconSecurity.svelte';
|
|
5
|
+
import IconTenant from './icons/IconTenant.svelte';
|
|
6
|
+
import IconApprove from './icons/IconApprove.svelte';
|
|
7
|
+
|
|
8
|
+
export interface RoleItem {
|
|
9
|
+
/** Unique role identifier */
|
|
10
|
+
key: string;
|
|
11
|
+
/** Human-readable role display name */
|
|
12
|
+
label: string;
|
|
13
|
+
/** Short role description */
|
|
14
|
+
description?: string;
|
|
15
|
+
/** Permissions array associated with this role */
|
|
16
|
+
permissions?: string[];
|
|
17
|
+
/** Organization or tenant name */
|
|
18
|
+
tenant?: string;
|
|
19
|
+
/** Optional badge text or tag */
|
|
20
|
+
badge?: string;
|
|
21
|
+
/** Whether the role is disabled */
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface RoleSwitcherProps {
|
|
26
|
+
/** List of available mock roles */
|
|
27
|
+
roles?: RoleItem[];
|
|
28
|
+
/** Currently active role key */
|
|
29
|
+
activeRole?: string;
|
|
30
|
+
/** Title shown in the role switcher drawer/popover */
|
|
31
|
+
title?: string;
|
|
32
|
+
/** Trigger button label override */
|
|
33
|
+
triggerText?: string;
|
|
34
|
+
/** Compact mode (icon or minimal badge only) */
|
|
35
|
+
compact?: boolean;
|
|
36
|
+
/** Callback when a role is selected */
|
|
37
|
+
onroleswitch?: (role: RoleItem) => void;
|
|
38
|
+
/** Callback when reset to standard role */
|
|
39
|
+
onreset?: () => void;
|
|
40
|
+
/** Custom extra action in footer */
|
|
41
|
+
extra?: Snippet;
|
|
42
|
+
/** Additional CSS classes */
|
|
43
|
+
class?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let {
|
|
47
|
+
roles = [
|
|
48
|
+
{
|
|
49
|
+
key: 'super_admin',
|
|
50
|
+
label: '超级管理员',
|
|
51
|
+
description: '系统最高权限,具备所有模块的写操作、系统审计与多租户管理权限',
|
|
52
|
+
permissions: ['system:write', 'user:admin', 'audit:export', 'tenant:full'],
|
|
53
|
+
tenant: '全平台 (Root)',
|
|
54
|
+
badge: '全量',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
key: 'operator',
|
|
58
|
+
label: '运营专家',
|
|
59
|
+
description: '负责业务数据运营、活动流转与内容审核,不可修改核心系统配置',
|
|
60
|
+
permissions: ['order:read', 'order:audit', 'marketing:write', 'content:publish'],
|
|
61
|
+
tenant: '华东大区运营中心',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
key: 'developer',
|
|
65
|
+
label: '研发技术专员',
|
|
66
|
+
description: '拥有 API 网关配置、自动化脚本调试与系统监控诊断权限',
|
|
67
|
+
permissions: ['gateway:config', 'monitor:read', 'devtools:debug'],
|
|
68
|
+
tenant: '技术工程部',
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
key: 'auditor',
|
|
72
|
+
label: '合规审计员',
|
|
73
|
+
description: '仅具备全局只读与全量不可篡改审计日志导出检索权限',
|
|
74
|
+
permissions: ['audit:read', 'audit:export', 'log:immutable'],
|
|
75
|
+
tenant: '风险与合规法务组',
|
|
76
|
+
badge: '只读',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
key: 'guest',
|
|
80
|
+
label: '访客体验角色',
|
|
81
|
+
description: '仅用于公共视图预览,受限于最低数据展示策略',
|
|
82
|
+
permissions: ['public:view'],
|
|
83
|
+
tenant: '演示沙盒环境',
|
|
84
|
+
disabled: false,
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
activeRole = 'super_admin',
|
|
88
|
+
title = '角色与权限模拟器',
|
|
89
|
+
triggerText,
|
|
90
|
+
compact = false,
|
|
91
|
+
onroleswitch,
|
|
92
|
+
onreset,
|
|
93
|
+
extra,
|
|
94
|
+
class: className = '',
|
|
95
|
+
}: RoleSwitcherProps = $props();
|
|
96
|
+
|
|
97
|
+
let isOpen = $state(false);
|
|
98
|
+
let selectedRoleKey = $derived(activeRole);
|
|
99
|
+
|
|
100
|
+
const fallbackRole: RoleItem = {
|
|
101
|
+
key: 'none',
|
|
102
|
+
label: '未选择角色',
|
|
103
|
+
description: '当前没有可用的角色配置。',
|
|
104
|
+
};
|
|
105
|
+
const currentRole = $derived(roles.find((r) => r.key === selectedRoleKey) ?? roles[0] ?? fallbackRole);
|
|
106
|
+
|
|
107
|
+
function handleSelect(role: RoleItem) {
|
|
108
|
+
if (role.disabled) return;
|
|
109
|
+
selectedRoleKey = role.key;
|
|
110
|
+
onroleswitch?.(role);
|
|
111
|
+
isOpen = false;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function handleReset() {
|
|
115
|
+
selectedRoleKey = roles[0]?.key || 'super_admin';
|
|
116
|
+
const fallback = roles[0];
|
|
117
|
+
if (fallback) {
|
|
118
|
+
onroleswitch?.(fallback);
|
|
119
|
+
}
|
|
120
|
+
onreset?.();
|
|
121
|
+
isOpen = false;
|
|
122
|
+
}
|
|
123
|
+
</script>
|
|
124
|
+
|
|
125
|
+
<div
|
|
126
|
+
data-svadmin-component="RoleSwitcher"
|
|
127
|
+
class={cn('svadmin-role-switcher relative inline-block text-foreground', className)}
|
|
128
|
+
>
|
|
129
|
+
<!-- Trigger Button -->
|
|
130
|
+
<button
|
|
131
|
+
type="button"
|
|
132
|
+
aria-haspopup="dialog"
|
|
133
|
+
aria-expanded={isOpen}
|
|
134
|
+
onclick={() => (isOpen = !isOpen)}
|
|
135
|
+
class={cn(
|
|
136
|
+
'inline-flex items-center gap-2 px-3 py-1.5 rounded-[4px] border border-border bg-card text-xs font-medium text-foreground hover:bg-muted/70 transition-colors shadow-sm focus:outline-none focus:ring-1 focus:ring-primary',
|
|
137
|
+
isOpen && 'border-primary ring-1 ring-primary'
|
|
138
|
+
)}
|
|
139
|
+
>
|
|
140
|
+
<div class="flex items-center justify-center w-5 h-5 rounded-[4px] bg-primary/10 text-primary shrink-0">
|
|
141
|
+
<IconSecurity size={13} />
|
|
142
|
+
</div>
|
|
143
|
+
{#if !compact}
|
|
144
|
+
<div class="flex flex-col text-left">
|
|
145
|
+
<span class="text-[10px] text-muted-foreground leading-tight">模拟角色</span>
|
|
146
|
+
<span class="font-semibold text-xs leading-none">{triggerText || currentRole.label}</span>
|
|
147
|
+
</div>
|
|
148
|
+
{/if}
|
|
149
|
+
<span class="inline-block px-1.5 py-0.2 rounded-[2px] bg-primary/15 text-[10px] text-primary font-mono font-medium">
|
|
150
|
+
{currentRole.key}
|
|
151
|
+
</span>
|
|
152
|
+
<svg
|
|
153
|
+
class={cn('w-3.5 h-3.5 text-muted-foreground transition-transform shrink-0', isOpen && 'rotate-180')}
|
|
154
|
+
fill="none"
|
|
155
|
+
viewBox="0 0 24 24"
|
|
156
|
+
stroke="currentColor"
|
|
157
|
+
>
|
|
158
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
|
|
159
|
+
</svg>
|
|
160
|
+
</button>
|
|
161
|
+
|
|
162
|
+
<!-- Overlay Dropdown Card -->
|
|
163
|
+
{#if isOpen}
|
|
164
|
+
<!-- Backdrop to close -->
|
|
165
|
+
<div
|
|
166
|
+
class="fixed inset-0 z-40"
|
|
167
|
+
tabindex="-1"
|
|
168
|
+
role="presentation"
|
|
169
|
+
onclick={() => (isOpen = false)}
|
|
170
|
+
onkeydown={(e) => e.key === 'Escape' && (isOpen = false)}
|
|
171
|
+
></div>
|
|
172
|
+
|
|
173
|
+
<div
|
|
174
|
+
role="dialog"
|
|
175
|
+
aria-label={title}
|
|
176
|
+
class="absolute right-0 top-full mt-1.5 z-50 w-80 sm:w-96 rounded-[4px] border border-border bg-card p-3.5 shadow-xl text-xs flex flex-col gap-3 animate-in fade-in zoom-in-95 duration-100"
|
|
177
|
+
>
|
|
178
|
+
<!-- Header -->
|
|
179
|
+
<div class="flex items-center justify-between pb-2 border-b border-border">
|
|
180
|
+
<div class="flex items-center gap-2">
|
|
181
|
+
<IconTenant size={15} class="text-primary" />
|
|
182
|
+
<span class="font-semibold text-sm">{title}</span>
|
|
183
|
+
</div>
|
|
184
|
+
<button
|
|
185
|
+
type="button"
|
|
186
|
+
onclick={handleReset}
|
|
187
|
+
class="text-[11px] text-muted-foreground hover:text-primary transition-colors cursor-pointer"
|
|
188
|
+
>
|
|
189
|
+
重置默认
|
|
190
|
+
</button>
|
|
191
|
+
</div>
|
|
192
|
+
|
|
193
|
+
<!-- Role Items List -->
|
|
194
|
+
<div class="flex flex-col gap-2 max-h-72 overflow-y-auto pr-1">
|
|
195
|
+
{#each roles as role (role.key)}
|
|
196
|
+
{@const isSelected = role.key === selectedRoleKey}
|
|
197
|
+
<button
|
|
198
|
+
type="button"
|
|
199
|
+
disabled={role.disabled}
|
|
200
|
+
onclick={() => handleSelect(role)}
|
|
201
|
+
class={cn(
|
|
202
|
+
'group w-full flex flex-col items-start gap-1 p-2.5 rounded-[4px] border transition-all text-left cursor-pointer',
|
|
203
|
+
isSelected
|
|
204
|
+
? 'border-primary bg-primary/5 text-foreground shadow-sm'
|
|
205
|
+
: 'border-border/60 hover:border-border hover:bg-muted/40',
|
|
206
|
+
role.disabled && 'opacity-50 cursor-not-allowed'
|
|
207
|
+
)}
|
|
208
|
+
>
|
|
209
|
+
<div class="flex items-center justify-between w-full">
|
|
210
|
+
<div class="flex items-center gap-2">
|
|
211
|
+
<span class={cn('font-medium text-xs', isSelected ? 'text-primary font-semibold' : 'text-foreground')}>
|
|
212
|
+
{role.label}
|
|
213
|
+
</span>
|
|
214
|
+
{#if role.badge}
|
|
215
|
+
<span class="px-1.5 py-0.5 rounded-[2px] bg-primary/10 text-primary text-[10px] font-medium">
|
|
216
|
+
{role.badge}
|
|
217
|
+
</span>
|
|
218
|
+
{/if}
|
|
219
|
+
</div>
|
|
220
|
+
{#if isSelected}
|
|
221
|
+
<span class="flex items-center gap-1 text-[11px] text-primary font-medium">
|
|
222
|
+
<IconApprove size={13} />
|
|
223
|
+
已生效
|
|
224
|
+
</span>
|
|
225
|
+
{/if}
|
|
226
|
+
</div>
|
|
227
|
+
|
|
228
|
+
{#if role.description}
|
|
229
|
+
<p class="text-[11px] text-muted-foreground line-clamp-2 leading-relaxed">
|
|
230
|
+
{role.description}
|
|
231
|
+
</p>
|
|
232
|
+
{/if}
|
|
233
|
+
|
|
234
|
+
{#if role.tenant}
|
|
235
|
+
<div class="flex items-center gap-1 text-[10px] text-muted-foreground/80 mt-0.5">
|
|
236
|
+
<span>所属部门/租户:</span>
|
|
237
|
+
<span class="font-medium text-foreground/80">{role.tenant}</span>
|
|
238
|
+
</div>
|
|
239
|
+
{/if}
|
|
240
|
+
|
|
241
|
+
{#if role.permissions && role.permissions.length > 0}
|
|
242
|
+
<div class="flex flex-wrap gap-1 mt-1.5 pt-1.5 border-t border-border/40 w-full">
|
|
243
|
+
{#each role.permissions.slice(0, 4) as perm (perm)}
|
|
244
|
+
<span class="px-1 py-0.2 rounded-[2px] bg-muted text-[10px] text-muted-foreground font-mono">
|
|
245
|
+
{perm}
|
|
246
|
+
</span>
|
|
247
|
+
{/each}
|
|
248
|
+
{#if role.permissions.length > 4}
|
|
249
|
+
<span class="text-[10px] text-muted-foreground/70 self-center">
|
|
250
|
+
+{role.permissions.length - 4}
|
|
251
|
+
</span>
|
|
252
|
+
{/if}
|
|
253
|
+
</div>
|
|
254
|
+
{/if}
|
|
255
|
+
</button>
|
|
256
|
+
{/each}
|
|
257
|
+
</div>
|
|
258
|
+
|
|
259
|
+
<!-- Footer Actions -->
|
|
260
|
+
{#if extra}
|
|
261
|
+
<div class="pt-2 border-t border-border flex items-center justify-end">
|
|
262
|
+
{@render extra()}
|
|
263
|
+
</div>
|
|
264
|
+
{/if}
|
|
265
|
+
</div>
|
|
266
|
+
{/if}
|
|
267
|
+
</div>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
export interface RoleItem {
|
|
3
|
+
/** Unique role identifier */
|
|
4
|
+
key: string;
|
|
5
|
+
/** Human-readable role display name */
|
|
6
|
+
label: string;
|
|
7
|
+
/** Short role description */
|
|
8
|
+
description?: string;
|
|
9
|
+
/** Permissions array associated with this role */
|
|
10
|
+
permissions?: string[];
|
|
11
|
+
/** Organization or tenant name */
|
|
12
|
+
tenant?: string;
|
|
13
|
+
/** Optional badge text or tag */
|
|
14
|
+
badge?: string;
|
|
15
|
+
/** Whether the role is disabled */
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface RoleSwitcherProps {
|
|
19
|
+
/** List of available mock roles */
|
|
20
|
+
roles?: RoleItem[];
|
|
21
|
+
/** Currently active role key */
|
|
22
|
+
activeRole?: string;
|
|
23
|
+
/** Title shown in the role switcher drawer/popover */
|
|
24
|
+
title?: string;
|
|
25
|
+
/** Trigger button label override */
|
|
26
|
+
triggerText?: string;
|
|
27
|
+
/** Compact mode (icon or minimal badge only) */
|
|
28
|
+
compact?: boolean;
|
|
29
|
+
/** Callback when a role is selected */
|
|
30
|
+
onroleswitch?: (role: RoleItem) => void;
|
|
31
|
+
/** Callback when reset to standard role */
|
|
32
|
+
onreset?: () => void;
|
|
33
|
+
/** Custom extra action in footer */
|
|
34
|
+
extra?: Snippet;
|
|
35
|
+
/** Additional CSS classes */
|
|
36
|
+
class?: string;
|
|
37
|
+
}
|
|
38
|
+
declare const RoleSwitcher: import("svelte").Component<RoleSwitcherProps, {}, "">;
|
|
39
|
+
type RoleSwitcher = ReturnType<typeof RoleSwitcher>;
|
|
40
|
+
export default RoleSwitcher;
|