@svadmin/ui 0.116.0 → 0.118.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 +320 -26
- package/dist/app.theme.css +320 -26
- package/dist/components/AboutSettings.svelte +1 -1
- package/dist/components/ApprovalTimeline.svelte +170 -0
- package/dist/components/ApprovalTimeline.svelte.d.ts +26 -0
- package/dist/components/CopyableText.svelte +90 -0
- package/dist/components/CopyableText.svelte.d.ts +13 -0
- package/dist/components/Divider.svelte +89 -0
- package/dist/components/Divider.svelte.d.ts +19 -0
- package/dist/components/EllipsisText.svelte +78 -0
- package/dist/components/EllipsisText.svelte.d.ts +15 -0
- package/dist/components/ExcelExportButton.svelte +142 -0
- package/dist/components/ExcelExportButton.svelte.d.ts +21 -0
- package/dist/components/ExcelImportWizard.svelte +571 -0
- package/dist/components/ExcelImportWizard.svelte.d.ts +26 -0
- package/dist/components/FloatButtonGroup.svelte +162 -0
- package/dist/components/FloatButtonGroup.svelte.d.ts +34 -0
- package/dist/components/FullscreenButton.svelte +88 -0
- package/dist/components/FullscreenButton.svelte.d.ts +10 -0
- package/dist/components/GlobalShortcuts.svelte +229 -0
- package/dist/components/GlobalShortcuts.svelte.d.ts +18 -0
- package/dist/components/Header.svelte +17 -1
- package/dist/components/Header.svelte.d.ts +3 -0
- package/dist/components/Layout.svelte +3 -0
- package/dist/components/Layout.svelte.d.ts +1 -0
- package/dist/components/LightFilter.svelte +281 -0
- package/dist/components/LightFilter.svelte.d.ts +36 -0
- package/dist/components/LockScreen.svelte +295 -0
- package/dist/components/LockScreen.svelte.d.ts +21 -0
- package/dist/components/OrgTreePicker.svelte +325 -0
- package/dist/components/OrgTreePicker.svelte.d.ts +32 -0
- package/dist/components/PivotDrilldownModal.svelte +228 -0
- package/dist/components/PivotDrilldownModal.svelte.d.ts +22 -0
- package/dist/components/PricingCard.svelte +12 -12
- package/dist/components/PricingCard.svelte.d.ts +12 -12
- package/dist/components/PricingTable.svelte +185 -0
- package/dist/components/PricingTable.svelte.d.ts +40 -0
- package/dist/components/ProCard.svelte +267 -0
- package/dist/components/ProCard.svelte.d.ts +56 -0
- package/dist/components/ProSkeleton.svelte +186 -0
- package/dist/components/ProSkeleton.svelte.d.ts +20 -0
- package/dist/components/QuotaProgressBar.svelte +8 -8
- package/dist/components/QuotaProgressBar.svelte.d.ts +8 -8
- package/dist/components/Ribbon.svelte +97 -0
- package/dist/components/Ribbon.svelte.d.ts +19 -0
- package/dist/components/TreeTransfer.svelte +288 -0
- package/dist/components/TreeTransfer.svelte.d.ts +25 -0
- package/dist/components/TypographyEllipsis.svelte +12 -9
- package/dist/components/TypographyEllipsis.svelte.d.ts +9 -8
- package/dist/components/TypographyText.svelte +41 -3
- package/dist/components/TypographyText.svelte.d.ts +10 -2
- package/dist/components/UsageCard.svelte +97 -0
- package/dist/components/UsageCard.svelte.d.ts +26 -0
- package/dist/components/WorkflowProcessCard.svelte +93 -0
- package/dist/components/WorkflowProcessCard.svelte.d.ts +21 -0
- package/dist/components/ui/badge/badge.svelte +156 -12
- package/dist/components/ui/badge/badge.svelte.d.ts +9 -0
- package/dist/components/ui/badge/index.d.ts +1 -1
- package/dist/index.d.ts +44 -3
- package/dist/index.js +28 -2
- package/package.json +5 -5
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
const resources = $derived(adminContext.resources.filter((resource) => resource.meta?.['aboutVisible'] !== false));
|
|
12
12
|
const providerNames = $derived(adminContext.getDataProviderNames());
|
|
13
13
|
let { version: suppliedVersion, headingLevel = 'h1' }: { version?: string; headingLevel?: 'h1' | 'h2' } = $props();
|
|
14
|
-
const buildVersion = "0.
|
|
14
|
+
const buildVersion = "0.118.0";
|
|
15
15
|
const version = $derived(suppliedVersion ?? (
|
|
16
16
|
buildVersion.startsWith('__')
|
|
17
17
|
? (i18n.locale === 'zh-CN' ? '开发构建(未提供版本)' : 'Development build (version unavailable)')
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import { cn } from '../utils.js';
|
|
4
|
+
import { Check, X, Clock, Loader2 } from '@lucide/svelte';
|
|
5
|
+
|
|
6
|
+
export type ApprovalStatus = 'approved' | 'rejected' | 'pending' | 'running';
|
|
7
|
+
|
|
8
|
+
export interface ApprovalStep {
|
|
9
|
+
id: string;
|
|
10
|
+
title: string;
|
|
11
|
+
approverName?: string;
|
|
12
|
+
approverRole?: string;
|
|
13
|
+
approverAvatar?: string;
|
|
14
|
+
status: ApprovalStatus;
|
|
15
|
+
time?: string;
|
|
16
|
+
comment?: string;
|
|
17
|
+
extra?: Snippet;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ApprovalTimelineProps {
|
|
21
|
+
/** List of approval workflow steps */
|
|
22
|
+
steps: ApprovalStep[];
|
|
23
|
+
/** Whether to render step comments in bordered cards */
|
|
24
|
+
cardMode?: boolean;
|
|
25
|
+
/** Current active step index (0-based) */
|
|
26
|
+
current?: number;
|
|
27
|
+
/** Additional CSS classes */
|
|
28
|
+
class?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let {
|
|
32
|
+
steps = [],
|
|
33
|
+
cardMode = true,
|
|
34
|
+
current,
|
|
35
|
+
class: className = '',
|
|
36
|
+
}: ApprovalTimelineProps = $props();
|
|
37
|
+
|
|
38
|
+
function getStatusIcon(status: ApprovalStatus) {
|
|
39
|
+
switch (status) {
|
|
40
|
+
case 'approved':
|
|
41
|
+
return Check;
|
|
42
|
+
case 'rejected':
|
|
43
|
+
return X;
|
|
44
|
+
case 'running':
|
|
45
|
+
return Loader2;
|
|
46
|
+
case 'pending':
|
|
47
|
+
default:
|
|
48
|
+
return Clock;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function getStatusColorClasses(status: ApprovalStatus) {
|
|
53
|
+
switch (status) {
|
|
54
|
+
case 'approved':
|
|
55
|
+
return {
|
|
56
|
+
iconBg: 'bg-success text-success-foreground',
|
|
57
|
+
badge: 'bg-success/10 text-success border-success/20',
|
|
58
|
+
line: 'border-success',
|
|
59
|
+
};
|
|
60
|
+
case 'rejected':
|
|
61
|
+
return {
|
|
62
|
+
iconBg: 'bg-destructive text-destructive-foreground',
|
|
63
|
+
badge: 'bg-destructive/10 text-destructive border-destructive/20',
|
|
64
|
+
line: 'border-destructive',
|
|
65
|
+
};
|
|
66
|
+
case 'running':
|
|
67
|
+
return {
|
|
68
|
+
iconBg: 'bg-primary text-primary-foreground',
|
|
69
|
+
badge: 'bg-primary/10 text-primary border-primary/20',
|
|
70
|
+
line: 'border-primary',
|
|
71
|
+
};
|
|
72
|
+
case 'pending':
|
|
73
|
+
default:
|
|
74
|
+
return {
|
|
75
|
+
iconBg: 'bg-muted text-muted-foreground',
|
|
76
|
+
badge: 'bg-muted text-muted-foreground border-border',
|
|
77
|
+
line: 'border-border',
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
</script>
|
|
82
|
+
|
|
83
|
+
<div
|
|
84
|
+
data-svadmin-component="ApprovalTimeline"
|
|
85
|
+
class={cn('w-full relative', className)}
|
|
86
|
+
>
|
|
87
|
+
<div class="relative flex flex-col space-y-6">
|
|
88
|
+
{#each steps as step, index (step.id)}
|
|
89
|
+
{@const colors = getStatusColorClasses(step.status)}
|
|
90
|
+
{@const Icon = getStatusIcon(step.status)}
|
|
91
|
+
{@const isLast = index === steps.length - 1}
|
|
92
|
+
{@const isCurrent = current !== undefined ? index === current : step.status === 'running'}
|
|
93
|
+
|
|
94
|
+
<div class="relative flex items-start gap-4">
|
|
95
|
+
<!-- Connecting Line & Status Icon Node -->
|
|
96
|
+
<div class="relative flex flex-col items-center">
|
|
97
|
+
<div
|
|
98
|
+
class={cn(
|
|
99
|
+
'flex h-7 w-7 shrink-0 items-center justify-center rounded-full shadow-xs ring-4 ring-background transition-colors',
|
|
100
|
+
colors.iconBg,
|
|
101
|
+
isCurrent && 'ring-primary/30',
|
|
102
|
+
)}
|
|
103
|
+
>
|
|
104
|
+
<Icon class={cn('h-3.5 w-3.5 stroke-[2.5]', step.status === 'running' && 'animate-spin')} />
|
|
105
|
+
</div>
|
|
106
|
+
|
|
107
|
+
{#if !isLast}
|
|
108
|
+
<div
|
|
109
|
+
class={cn(
|
|
110
|
+
'w-0.5 flex-1 min-h-[44px] my-1 border-l-2 transition-colors',
|
|
111
|
+
colors.line,
|
|
112
|
+
)}
|
|
113
|
+
></div>
|
|
114
|
+
{/if}
|
|
115
|
+
</div>
|
|
116
|
+
|
|
117
|
+
<!-- Step Detail Content -->
|
|
118
|
+
<div class="flex-1 pb-4">
|
|
119
|
+
<div class="flex flex-wrap items-center justify-between gap-2">
|
|
120
|
+
<div class="flex items-center gap-2">
|
|
121
|
+
<h4 class="text-sm font-semibold tracking-tight text-foreground">{step.title}</h4>
|
|
122
|
+
<span
|
|
123
|
+
class={cn(
|
|
124
|
+
'inline-flex items-center rounded-full border px-2 py-0.5 text-[11px] font-medium uppercase tracking-wider',
|
|
125
|
+
colors.badge,
|
|
126
|
+
)}
|
|
127
|
+
>
|
|
128
|
+
{step.status}
|
|
129
|
+
</span>
|
|
130
|
+
</div>
|
|
131
|
+
|
|
132
|
+
{#if step.time}
|
|
133
|
+
<time class="text-xs text-muted-foreground font-mono">{step.time}</time>
|
|
134
|
+
{/if}
|
|
135
|
+
</div>
|
|
136
|
+
|
|
137
|
+
{#if step.approverName || step.approverRole}
|
|
138
|
+
<div class="mt-1 flex items-center gap-2 text-xs text-muted-foreground">
|
|
139
|
+
{#if step.approverName}
|
|
140
|
+
<span class="font-medium text-foreground">{step.approverName}</span>
|
|
141
|
+
{/if}
|
|
142
|
+
{#if step.approverRole}
|
|
143
|
+
<span>({step.approverRole})</span>
|
|
144
|
+
{/if}
|
|
145
|
+
</div>
|
|
146
|
+
{/if}
|
|
147
|
+
|
|
148
|
+
{#if step.comment}
|
|
149
|
+
<div
|
|
150
|
+
class={cn(
|
|
151
|
+
'mt-2 text-xs text-foreground',
|
|
152
|
+
cardMode
|
|
153
|
+
? 'rounded-lg border border-border bg-card p-3 shadow-2xs'
|
|
154
|
+
: 'text-muted-foreground italic',
|
|
155
|
+
)}
|
|
156
|
+
>
|
|
157
|
+
<p>{step.comment}</p>
|
|
158
|
+
</div>
|
|
159
|
+
{/if}
|
|
160
|
+
|
|
161
|
+
{#if step.extra}
|
|
162
|
+
<div class="mt-2">
|
|
163
|
+
{@render step.extra()}
|
|
164
|
+
</div>
|
|
165
|
+
{/if}
|
|
166
|
+
</div>
|
|
167
|
+
</div>
|
|
168
|
+
{/each}
|
|
169
|
+
</div>
|
|
170
|
+
</div>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
export type ApprovalStatus = 'approved' | 'rejected' | 'pending' | 'running';
|
|
3
|
+
export interface ApprovalStep {
|
|
4
|
+
id: string;
|
|
5
|
+
title: string;
|
|
6
|
+
approverName?: string;
|
|
7
|
+
approverRole?: string;
|
|
8
|
+
approverAvatar?: string;
|
|
9
|
+
status: ApprovalStatus;
|
|
10
|
+
time?: string;
|
|
11
|
+
comment?: string;
|
|
12
|
+
extra?: Snippet;
|
|
13
|
+
}
|
|
14
|
+
export interface ApprovalTimelineProps {
|
|
15
|
+
/** List of approval workflow steps */
|
|
16
|
+
steps: ApprovalStep[];
|
|
17
|
+
/** Whether to render step comments in bordered cards */
|
|
18
|
+
cardMode?: boolean;
|
|
19
|
+
/** Current active step index (0-based) */
|
|
20
|
+
current?: number;
|
|
21
|
+
/** Additional CSS classes */
|
|
22
|
+
class?: string;
|
|
23
|
+
}
|
|
24
|
+
declare const ApprovalTimeline: import("svelte").Component<ApprovalTimelineProps, {}, "">;
|
|
25
|
+
type ApprovalTimeline = ReturnType<typeof ApprovalTimeline>;
|
|
26
|
+
export default ApprovalTimeline;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onDestroy } from 'svelte';
|
|
3
|
+
import { Copy, Check } from '@lucide/svelte';
|
|
4
|
+
import { cn } from '../utils.js';
|
|
5
|
+
import { useTranslation } from '@svadmin/core';
|
|
6
|
+
|
|
7
|
+
const i18n = useTranslation();
|
|
8
|
+
|
|
9
|
+
export interface CopyableTextProps {
|
|
10
|
+
text: string;
|
|
11
|
+
copyValue?: string;
|
|
12
|
+
tooltip?: string;
|
|
13
|
+
copiedTooltip?: string;
|
|
14
|
+
masked?: boolean;
|
|
15
|
+
maskVisibleLength?: number;
|
|
16
|
+
oncopied?: (value: string) => void;
|
|
17
|
+
class?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let {
|
|
21
|
+
text,
|
|
22
|
+
copyValue,
|
|
23
|
+
tooltip,
|
|
24
|
+
copiedTooltip,
|
|
25
|
+
masked = false,
|
|
26
|
+
maskVisibleLength = 4,
|
|
27
|
+
oncopied,
|
|
28
|
+
class: className = '',
|
|
29
|
+
}: CopyableTextProps = $props();
|
|
30
|
+
|
|
31
|
+
let copied = $state(false);
|
|
32
|
+
let resetTimer: ReturnType<typeof setTimeout> | undefined;
|
|
33
|
+
|
|
34
|
+
onDestroy(() => {
|
|
35
|
+
if (resetTimer) clearTimeout(resetTimer);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const displayText = $derived.by(() => {
|
|
39
|
+
if (!masked || !text) return text;
|
|
40
|
+
if (text.length <= maskVisibleLength * 2) {
|
|
41
|
+
return '••••••••';
|
|
42
|
+
}
|
|
43
|
+
const head = text.slice(0, maskVisibleLength);
|
|
44
|
+
const tail = text.slice(-maskVisibleLength);
|
|
45
|
+
return `${head}••••••••${tail}`;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const actualTooltip = $derived(tooltip ?? i18n.t('common.copy'));
|
|
49
|
+
const actualCopiedTooltip = $derived(copiedTooltip ?? i18n.t('common.copied'));
|
|
50
|
+
|
|
51
|
+
async function handleCopy() {
|
|
52
|
+
const valueToCopy = copyValue ?? text;
|
|
53
|
+
try {
|
|
54
|
+
if (typeof navigator === 'undefined' || !navigator.clipboard) return;
|
|
55
|
+
await navigator.clipboard.writeText(valueToCopy);
|
|
56
|
+
copied = true;
|
|
57
|
+
oncopied?.(valueToCopy);
|
|
58
|
+
if (resetTimer) clearTimeout(resetTimer);
|
|
59
|
+
resetTimer = setTimeout(() => {
|
|
60
|
+
copied = false;
|
|
61
|
+
}, 1500);
|
|
62
|
+
} catch {
|
|
63
|
+
// Graceful fallback
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
</script>
|
|
67
|
+
|
|
68
|
+
<span
|
|
69
|
+
class={cn('inline-flex items-center gap-1.5 font-mono text-sm text-foreground', className)}
|
|
70
|
+
data-svadmin-component="CopyableText"
|
|
71
|
+
data-copied={copied}
|
|
72
|
+
>
|
|
73
|
+
<span class="truncate">{displayText}</span>
|
|
74
|
+
<button
|
|
75
|
+
type="button"
|
|
76
|
+
class={cn(
|
|
77
|
+
'inline-flex h-6 w-6 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus:outline-none focus-visible:ring-1 focus-visible:ring-ring',
|
|
78
|
+
copied && 'text-success hover:text-success'
|
|
79
|
+
)}
|
|
80
|
+
onclick={handleCopy}
|
|
81
|
+
title={copied ? actualCopiedTooltip : actualTooltip}
|
|
82
|
+
aria-label={copied ? actualCopiedTooltip : actualTooltip}
|
|
83
|
+
>
|
|
84
|
+
{#if copied}
|
|
85
|
+
<Check class="h-3.5 w-3.5 text-success animate-in zoom-in-50" />
|
|
86
|
+
{:else}
|
|
87
|
+
<Copy class="h-3.5 w-3.5" />
|
|
88
|
+
{/if}
|
|
89
|
+
</button>
|
|
90
|
+
</span>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface CopyableTextProps {
|
|
2
|
+
text: string;
|
|
3
|
+
copyValue?: string;
|
|
4
|
+
tooltip?: string;
|
|
5
|
+
copiedTooltip?: string;
|
|
6
|
+
masked?: boolean;
|
|
7
|
+
maskVisibleLength?: number;
|
|
8
|
+
oncopied?: (value: string) => void;
|
|
9
|
+
class?: string;
|
|
10
|
+
}
|
|
11
|
+
declare const CopyableText: import("svelte").Component<CopyableTextProps, {}, "">;
|
|
12
|
+
type CopyableText = ReturnType<typeof CopyableText>;
|
|
13
|
+
export default CopyableText;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import { cn } from '../utils.js';
|
|
4
|
+
|
|
5
|
+
export interface DividerProps {
|
|
6
|
+
/** Direction of the divider */
|
|
7
|
+
type?: 'horizontal' | 'vertical';
|
|
8
|
+
/** Alignment of the text title inside the horizontal divider */
|
|
9
|
+
orientation?: 'left' | 'center' | 'right';
|
|
10
|
+
/** Whether the divider line is dashed */
|
|
11
|
+
dashed?: boolean;
|
|
12
|
+
/** Whether to use plain style text without extra bolding */
|
|
13
|
+
plain?: boolean;
|
|
14
|
+
/** Custom CSS class names */
|
|
15
|
+
class?: string;
|
|
16
|
+
/** Slot for divider text/content */
|
|
17
|
+
children?: Snippet;
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let {
|
|
22
|
+
type = 'horizontal',
|
|
23
|
+
orientation = 'center',
|
|
24
|
+
dashed = false,
|
|
25
|
+
plain = true,
|
|
26
|
+
class: className = '',
|
|
27
|
+
children,
|
|
28
|
+
...restProps
|
|
29
|
+
}: DividerProps = $props();
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
{#if type === 'vertical'}
|
|
33
|
+
<span
|
|
34
|
+
role="separator"
|
|
35
|
+
aria-orientation="vertical"
|
|
36
|
+
data-svadmin-component="Divider"
|
|
37
|
+
data-svadmin-type="vertical"
|
|
38
|
+
class={cn(
|
|
39
|
+
'inline-block h-3.5 w-[1px] mx-2 align-middle bg-border',
|
|
40
|
+
dashed && 'border-l border-dashed border-border bg-transparent',
|
|
41
|
+
className
|
|
42
|
+
)}
|
|
43
|
+
{...restProps}
|
|
44
|
+
></span>
|
|
45
|
+
{:else if !children}
|
|
46
|
+
<hr
|
|
47
|
+
aria-orientation="horizontal"
|
|
48
|
+
data-svadmin-component="Divider"
|
|
49
|
+
data-svadmin-type="horizontal"
|
|
50
|
+
class={cn(
|
|
51
|
+
'my-4 w-full border-0 border-t border-border',
|
|
52
|
+
dashed && 'border-dashed',
|
|
53
|
+
className
|
|
54
|
+
)}
|
|
55
|
+
{...restProps}
|
|
56
|
+
/>
|
|
57
|
+
{:else}
|
|
58
|
+
<div
|
|
59
|
+
role="separator"
|
|
60
|
+
aria-orientation="horizontal"
|
|
61
|
+
data-svadmin-component="Divider"
|
|
62
|
+
data-svadmin-type="horizontal"
|
|
63
|
+
data-orientation={orientation}
|
|
64
|
+
class={cn(
|
|
65
|
+
'my-4 flex items-center w-full text-xs text-muted-foreground',
|
|
66
|
+
plain ? 'font-normal' : 'font-semibold text-foreground',
|
|
67
|
+
className
|
|
68
|
+
)}
|
|
69
|
+
{...restProps}
|
|
70
|
+
>
|
|
71
|
+
<span
|
|
72
|
+
class={cn(
|
|
73
|
+
'border-t border-border',
|
|
74
|
+
dashed && 'border-dashed',
|
|
75
|
+
orientation === 'left' ? 'w-6' : orientation === 'right' ? 'flex-1' : 'flex-1'
|
|
76
|
+
)}
|
|
77
|
+
></span>
|
|
78
|
+
<span class="px-3 whitespace-nowrap">
|
|
79
|
+
{@render children()}
|
|
80
|
+
</span>
|
|
81
|
+
<span
|
|
82
|
+
class={cn(
|
|
83
|
+
'border-t border-border',
|
|
84
|
+
dashed && 'border-dashed',
|
|
85
|
+
orientation === 'left' ? 'flex-1' : orientation === 'right' ? 'w-6' : 'flex-1'
|
|
86
|
+
)}
|
|
87
|
+
></span>
|
|
88
|
+
</div>
|
|
89
|
+
{/if}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
export interface DividerProps {
|
|
3
|
+
/** Direction of the divider */
|
|
4
|
+
type?: 'horizontal' | 'vertical';
|
|
5
|
+
/** Alignment of the text title inside the horizontal divider */
|
|
6
|
+
orientation?: 'left' | 'center' | 'right';
|
|
7
|
+
/** Whether the divider line is dashed */
|
|
8
|
+
dashed?: boolean;
|
|
9
|
+
/** Whether to use plain style text without extra bolding */
|
|
10
|
+
plain?: boolean;
|
|
11
|
+
/** Custom CSS class names */
|
|
12
|
+
class?: string;
|
|
13
|
+
/** Slot for divider text/content */
|
|
14
|
+
children?: Snippet;
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
}
|
|
17
|
+
declare const Divider: import("svelte").Component<DividerProps, {}, "">;
|
|
18
|
+
type Divider = ReturnType<typeof Divider>;
|
|
19
|
+
export default Divider;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { cn } from '../utils.js';
|
|
3
|
+
import { useTranslation } from '@svadmin/core';
|
|
4
|
+
import type { Snippet } from 'svelte';
|
|
5
|
+
|
|
6
|
+
const i18n = useTranslation();
|
|
7
|
+
|
|
8
|
+
export interface EllipsisTextProps {
|
|
9
|
+
text?: string;
|
|
10
|
+
maxLines?: number;
|
|
11
|
+
expandable?: boolean;
|
|
12
|
+
defaultExpanded?: boolean;
|
|
13
|
+
expandText?: string;
|
|
14
|
+
collapseText?: string;
|
|
15
|
+
tooltip?: boolean | string;
|
|
16
|
+
class?: string;
|
|
17
|
+
children?: Snippet;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let {
|
|
21
|
+
text = '',
|
|
22
|
+
maxLines = 3,
|
|
23
|
+
expandable = true,
|
|
24
|
+
defaultExpanded = false,
|
|
25
|
+
expandText,
|
|
26
|
+
collapseText,
|
|
27
|
+
tooltip = false,
|
|
28
|
+
class: className = '',
|
|
29
|
+
children,
|
|
30
|
+
}: EllipsisTextProps = $props();
|
|
31
|
+
|
|
32
|
+
let expandedState = $state<boolean | undefined>(undefined);
|
|
33
|
+
const expanded = $derived(expandedState ?? defaultExpanded);
|
|
34
|
+
|
|
35
|
+
const actualExpandText = $derived(expandText ?? i18n.t('common.expand'));
|
|
36
|
+
const actualCollapseText = $derived(collapseText ?? i18n.t('common.collapse'));
|
|
37
|
+
const tooltipText = $derived.by(() => {
|
|
38
|
+
if (!tooltip) return undefined;
|
|
39
|
+
if (typeof tooltip === 'string') return tooltip;
|
|
40
|
+
return text || undefined;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
function toggleExpand() {
|
|
44
|
+
expandedState = !expanded;
|
|
45
|
+
}
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
<div
|
|
49
|
+
class={cn('relative text-sm text-foreground leading-relaxed', className)}
|
|
50
|
+
data-svadmin-component="EllipsisText"
|
|
51
|
+
data-expanded={expanded}
|
|
52
|
+
title={!expanded ? tooltipText : undefined}
|
|
53
|
+
>
|
|
54
|
+
<div
|
|
55
|
+
class={cn(
|
|
56
|
+
'transition-all duration-200',
|
|
57
|
+
!expanded && 'overflow-hidden [-webkit-box-orient:vertical] [-webkit-line-clamp:var(--line-clamp)] [display:-webkit-box]'
|
|
58
|
+
)}
|
|
59
|
+
style="--line-clamp: {maxLines};"
|
|
60
|
+
>
|
|
61
|
+
{#if children}
|
|
62
|
+
{@render children()}
|
|
63
|
+
{:else}
|
|
64
|
+
{text}
|
|
65
|
+
{/if}
|
|
66
|
+
</div>
|
|
67
|
+
|
|
68
|
+
{#if expandable}
|
|
69
|
+
<button
|
|
70
|
+
type="button"
|
|
71
|
+
class="mt-1 inline-flex items-center text-xs font-medium text-primary hover:text-primary/80 transition-colors focus:outline-none focus-visible:underline"
|
|
72
|
+
onclick={toggleExpand}
|
|
73
|
+
aria-expanded={expanded}
|
|
74
|
+
>
|
|
75
|
+
{expanded ? actualCollapseText : actualExpandText}
|
|
76
|
+
</button>
|
|
77
|
+
{/if}
|
|
78
|
+
</div>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
export interface EllipsisTextProps {
|
|
3
|
+
text?: string;
|
|
4
|
+
maxLines?: number;
|
|
5
|
+
expandable?: boolean;
|
|
6
|
+
defaultExpanded?: boolean;
|
|
7
|
+
expandText?: string;
|
|
8
|
+
collapseText?: string;
|
|
9
|
+
tooltip?: boolean | string;
|
|
10
|
+
class?: string;
|
|
11
|
+
children?: Snippet;
|
|
12
|
+
}
|
|
13
|
+
declare const EllipsisText: import("svelte").Component<EllipsisTextProps, {}, "">;
|
|
14
|
+
type EllipsisText = ReturnType<typeof EllipsisText>;
|
|
15
|
+
export default EllipsisText;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import { Download, Loader2 } from '@lucide/svelte';
|
|
4
|
+
import { cn } from '../utils.js';
|
|
5
|
+
import { useTranslation } from '@svadmin/core';
|
|
6
|
+
|
|
7
|
+
export interface ExcelExportColumn {
|
|
8
|
+
key: string;
|
|
9
|
+
label: string;
|
|
10
|
+
formatter?: ((value: unknown, record: Record<string, unknown>) => string) | undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ExcelExportButtonProps {
|
|
14
|
+
columns: ExcelExportColumn[];
|
|
15
|
+
dataSource: Record<string, unknown>[] | (() => Promise<Record<string, unknown>[]>);
|
|
16
|
+
filename?: string | undefined;
|
|
17
|
+
format?: 'csv' | 'tsv' | undefined;
|
|
18
|
+
disabled?: boolean | undefined;
|
|
19
|
+
variant?: 'default' | 'outline' | 'secondary' | 'ghost' | undefined;
|
|
20
|
+
size?: 'default' | 'sm' | 'lg' | undefined;
|
|
21
|
+
class?: string | undefined;
|
|
22
|
+
children?: Snippet | undefined;
|
|
23
|
+
onexport?: ((count: number) => void) | undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let {
|
|
27
|
+
columns = [],
|
|
28
|
+
dataSource,
|
|
29
|
+
filename = 'export',
|
|
30
|
+
format = 'csv',
|
|
31
|
+
disabled = false,
|
|
32
|
+
variant = 'outline',
|
|
33
|
+
size = 'default',
|
|
34
|
+
class: className = '',
|
|
35
|
+
children,
|
|
36
|
+
onexport,
|
|
37
|
+
}: ExcelExportButtonProps = $props();
|
|
38
|
+
|
|
39
|
+
const i18n = useTranslation();
|
|
40
|
+
let loading = $state(false);
|
|
41
|
+
|
|
42
|
+
// 转义 CSV/TSV 字段值
|
|
43
|
+
function formatCell(val: unknown, delimiter: string): string {
|
|
44
|
+
if (val === null || val === undefined) return '';
|
|
45
|
+
const rawText = String(val);
|
|
46
|
+
const text = /^[=+\-@]/.test(rawText) ? `'${rawText}` : rawText;
|
|
47
|
+
if (text.includes(delimiter) || text.includes('"') || text.includes('\n') || text.includes('\r')) {
|
|
48
|
+
return `"${text.replace(/"/g, '""')}"`;
|
|
49
|
+
}
|
|
50
|
+
return text;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function handleExport() {
|
|
54
|
+
if (disabled || loading) return;
|
|
55
|
+
loading = true;
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
let records: Record<string, unknown>[] = [];
|
|
59
|
+
if (typeof dataSource === 'function') {
|
|
60
|
+
records = await dataSource();
|
|
61
|
+
} else if (Array.isArray(dataSource)) {
|
|
62
|
+
records = dataSource;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const delimiter = format === 'tsv' ? '\t' : ',';
|
|
66
|
+
const ext = format === 'tsv' ? 'tsv' : 'csv';
|
|
67
|
+
|
|
68
|
+
// 构建表头
|
|
69
|
+
const headerRow = columns.map((col) => formatCell(col.label, delimiter)).join(delimiter);
|
|
70
|
+
|
|
71
|
+
// 构建数据行
|
|
72
|
+
const bodyRows = records.map((record) => {
|
|
73
|
+
return columns
|
|
74
|
+
.map((col) => {
|
|
75
|
+
const rawVal = record[col.key];
|
|
76
|
+
const displayVal = col.formatter ? col.formatter(rawVal, record) : rawVal;
|
|
77
|
+
return formatCell(displayVal, delimiter);
|
|
78
|
+
})
|
|
79
|
+
.join(delimiter);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// UTF-8 BOM 确保 Windows Excel 识别中文字符
|
|
83
|
+
const csvContent = '\uFEFF' + [headerRow, ...bodyRows].join('\r\n');
|
|
84
|
+
const blob = new Blob([csvContent], {
|
|
85
|
+
type: format === 'tsv' ? 'text/tab-separated-values;charset=utf-8' : 'text/csv;charset=utf-8',
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// 触发下载
|
|
89
|
+
const safeFilename = filename.endsWith(`.${ext}`) ? filename : `${filename}.${ext}`;
|
|
90
|
+
const url = URL.createObjectURL(blob);
|
|
91
|
+
const a = document.createElement('a');
|
|
92
|
+
a.href = url;
|
|
93
|
+
a.download = safeFilename;
|
|
94
|
+
document.body.appendChild(a);
|
|
95
|
+
a.click();
|
|
96
|
+
document.body.removeChild(a);
|
|
97
|
+
URL.revokeObjectURL(url);
|
|
98
|
+
|
|
99
|
+
onexport?.(records.length);
|
|
100
|
+
} finally {
|
|
101
|
+
loading = false;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const variantClasses = {
|
|
106
|
+
default: 'bg-primary text-primary-foreground hover:bg-primary/90 shadow-2xs',
|
|
107
|
+
outline: 'border border-input bg-background hover:bg-accent hover:text-accent-foreground shadow-2xs',
|
|
108
|
+
secondary: 'bg-secondary text-secondary-foreground hover:bg-secondary/80 shadow-2xs',
|
|
109
|
+
ghost: 'hover:bg-accent hover:text-accent-foreground',
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const sizeClasses = {
|
|
113
|
+
default: 'h-9 px-3.5 py-2 text-xs',
|
|
114
|
+
sm: 'h-8 px-2.5 text-xs',
|
|
115
|
+
lg: 'h-10 px-4 text-sm',
|
|
116
|
+
};
|
|
117
|
+
</script>
|
|
118
|
+
|
|
119
|
+
<button
|
|
120
|
+
type="button"
|
|
121
|
+
data-svadmin-component="ExcelExportButton"
|
|
122
|
+
disabled={disabled || loading}
|
|
123
|
+
class={cn(
|
|
124
|
+
'inline-flex items-center justify-center gap-1.5 font-medium rounded-lg transition-colors focus-visible:outline-hidden focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 cursor-pointer select-none',
|
|
125
|
+
variantClasses[variant] ?? variantClasses.outline,
|
|
126
|
+
sizeClasses[size] ?? sizeClasses.default,
|
|
127
|
+
className,
|
|
128
|
+
)}
|
|
129
|
+
onclick={handleExport}
|
|
130
|
+
>
|
|
131
|
+
{#if loading}
|
|
132
|
+
<Loader2 size={14} class="animate-spin" />
|
|
133
|
+
{:else}
|
|
134
|
+
<Download size={14} />
|
|
135
|
+
{/if}
|
|
136
|
+
|
|
137
|
+
{#if children}
|
|
138
|
+
{@render children()}
|
|
139
|
+
{:else}
|
|
140
|
+
<span>{loading ? '正在导出...' : i18n.t('excel.export')}</span>
|
|
141
|
+
{/if}
|
|
142
|
+
</button>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
export interface ExcelExportColumn {
|
|
3
|
+
key: string;
|
|
4
|
+
label: string;
|
|
5
|
+
formatter?: ((value: unknown, record: Record<string, unknown>) => string) | undefined;
|
|
6
|
+
}
|
|
7
|
+
export interface ExcelExportButtonProps {
|
|
8
|
+
columns: ExcelExportColumn[];
|
|
9
|
+
dataSource: Record<string, unknown>[] | (() => Promise<Record<string, unknown>[]>);
|
|
10
|
+
filename?: string | undefined;
|
|
11
|
+
format?: 'csv' | 'tsv' | undefined;
|
|
12
|
+
disabled?: boolean | undefined;
|
|
13
|
+
variant?: 'default' | 'outline' | 'secondary' | 'ghost' | undefined;
|
|
14
|
+
size?: 'default' | 'sm' | 'lg' | undefined;
|
|
15
|
+
class?: string | undefined;
|
|
16
|
+
children?: Snippet | undefined;
|
|
17
|
+
onexport?: ((count: number) => void) | undefined;
|
|
18
|
+
}
|
|
19
|
+
declare const ExcelExportButton: import("svelte").Component<ExcelExportButtonProps, {}, "">;
|
|
20
|
+
type ExcelExportButton = ReturnType<typeof ExcelExportButton>;
|
|
21
|
+
export default ExcelExportButton;
|