@svadmin/ui 0.117.0 → 0.119.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 +351 -52
- package/dist/app.theme.css +351 -52
- 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/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/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/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/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/FloatButtonGroup.svelte +162 -0
- package/dist/components/FloatButtonGroup.svelte.d.ts +34 -0
- 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/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/OrgTreePicker.svelte +325 -0
- package/dist/components/OrgTreePicker.svelte.d.ts +32 -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/PivotDrilldownModal.svelte +228 -0
- package/dist/components/PivotDrilldownModal.svelte.d.ts +22 -0
- package/dist/components/PresenceAvatarGroup.svelte +78 -29
- package/dist/components/PresenceAvatarGroup.svelte.d.ts +14 -8
- package/dist/components/ProSkeleton.svelte +186 -0
- package/dist/components/ProSkeleton.svelte.d.ts +20 -0
- 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/Ribbon.svelte +97 -0
- package/dist/components/Ribbon.svelte.d.ts +19 -0
- 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/TreeTransfer.svelte +288 -0
- package/dist/components/TreeTransfer.svelte.d.ts +25 -0
- 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/VirtualTreeSelect.svelte +431 -0
- package/dist/components/VirtualTreeSelect.svelte.d.ts +34 -0
- package/dist/components/WorkflowProcessCard.svelte +93 -0
- package/dist/components/WorkflowProcessCard.svelte.d.ts +21 -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 +51 -5
- package/dist/index.js +36 -3
- package/dist/recipes.d.ts +91 -619
- package/package.json +30 -30
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount, onDestroy } from 'svelte';
|
|
3
|
+
import { RotateCw, Check, X, ChevronsRight } from '@lucide/svelte';
|
|
4
|
+
import { cn } from '../utils.js';
|
|
5
|
+
import { useTranslation } from '@svadmin/core';
|
|
6
|
+
|
|
7
|
+
export interface SliderCaptchaResult {
|
|
8
|
+
token: string;
|
|
9
|
+
elapsedMs: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface SliderCaptchaProps {
|
|
13
|
+
width?: number | undefined;
|
|
14
|
+
height?: number | undefined;
|
|
15
|
+
puzzleSize?: number | undefined;
|
|
16
|
+
tolerance?: number | undefined;
|
|
17
|
+
minTimeMs?: number | undefined;
|
|
18
|
+
maxTimeMs?: number | undefined;
|
|
19
|
+
bgImage?: string | undefined;
|
|
20
|
+
text?: string | undefined;
|
|
21
|
+
successText?: string | undefined;
|
|
22
|
+
failText?: string | undefined;
|
|
23
|
+
disabled?: boolean | undefined;
|
|
24
|
+
class?: string | undefined;
|
|
25
|
+
onsuccess?: ((result: SliderCaptchaResult) => void) | undefined;
|
|
26
|
+
onfail?: (() => void) | undefined;
|
|
27
|
+
onrefresh?: (() => void) | undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let {
|
|
31
|
+
width = 320,
|
|
32
|
+
height = 160,
|
|
33
|
+
puzzleSize = 42,
|
|
34
|
+
tolerance = 5,
|
|
35
|
+
minTimeMs = 200,
|
|
36
|
+
maxTimeMs = 10000,
|
|
37
|
+
bgImage,
|
|
38
|
+
text,
|
|
39
|
+
successText,
|
|
40
|
+
failText,
|
|
41
|
+
disabled = false,
|
|
42
|
+
class: className = '',
|
|
43
|
+
onsuccess,
|
|
44
|
+
onfail,
|
|
45
|
+
onrefresh,
|
|
46
|
+
}: SliderCaptchaProps = $props();
|
|
47
|
+
|
|
48
|
+
const i18n = useTranslation();
|
|
49
|
+
|
|
50
|
+
function t(key: string, fallback: string): string {
|
|
51
|
+
const val = i18n.t(key);
|
|
52
|
+
return !val || val === key ? fallback : val;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const radius = 8; // 拼图凹凸圆弧半径
|
|
56
|
+
const handleWidth = 40;
|
|
57
|
+
const maxSlide = $derived(Math.max(0, width - handleWidth));
|
|
58
|
+
|
|
59
|
+
let bgCanvas: HTMLCanvasElement | null = $state(null);
|
|
60
|
+
let pieceCanvas: HTMLCanvasElement | null = $state(null);
|
|
61
|
+
|
|
62
|
+
let targetX = $state(180);
|
|
63
|
+
let targetY = $state(60);
|
|
64
|
+
|
|
65
|
+
let isDragging = $state(false);
|
|
66
|
+
let startDragX = 0;
|
|
67
|
+
let currentX = $state(0);
|
|
68
|
+
let startTime = 0;
|
|
69
|
+
let trajectory: Array<{ x: number; y: number; t: number }> = [];
|
|
70
|
+
|
|
71
|
+
type CaptchaStatus = 'idle' | 'sliding' | 'verifying' | 'success' | 'fail';
|
|
72
|
+
let status = $state<CaptchaStatus>('idle');
|
|
73
|
+
let isShaking = $state(false);
|
|
74
|
+
let resetTimer: ReturnType<typeof setTimeout> | null = null;
|
|
75
|
+
|
|
76
|
+
const resolvedText = $derived(text ?? t('captcha.dragPrompt', '向右滑动滑块完成安全验证'));
|
|
77
|
+
const resolvedSuccessText = $derived(successText ?? t('captcha.success', '验证成功'));
|
|
78
|
+
const resolvedFailText = $derived(failText ?? t('captcha.failed', '验证未通过,请重新尝试'));
|
|
79
|
+
|
|
80
|
+
// 拼图轮廓路径绘制
|
|
81
|
+
function createPuzzlePath(ctx: CanvasRenderingContext2D, x: number, y: number, size: number, r: number) {
|
|
82
|
+
const PI = Math.PI;
|
|
83
|
+
ctx.beginPath();
|
|
84
|
+
ctx.moveTo(x, y);
|
|
85
|
+
|
|
86
|
+
// 顶部凸起
|
|
87
|
+
ctx.lineTo(x + (size / 2 - r), y);
|
|
88
|
+
ctx.arc(x + size / 2, y - r + 2, r, 0.72 * PI, 2.26 * PI);
|
|
89
|
+
ctx.lineTo(x + size, y);
|
|
90
|
+
|
|
91
|
+
// 右侧凹入
|
|
92
|
+
ctx.lineTo(x + size, y + (size / 2 - r));
|
|
93
|
+
ctx.arc(x + size + r - 2, y + size / 2, r, 1.21 * PI, 2.78 * PI);
|
|
94
|
+
ctx.lineTo(x + size, y + size);
|
|
95
|
+
|
|
96
|
+
// 底部平整
|
|
97
|
+
ctx.lineTo(x, y + size);
|
|
98
|
+
|
|
99
|
+
// 左侧凸起
|
|
100
|
+
ctx.lineTo(x, y + (size / 2 + r));
|
|
101
|
+
ctx.arc(x + r - 2, y + size / 2, r, 0.28 * PI, 1.72 * PI, true);
|
|
102
|
+
ctx.lineTo(x, y);
|
|
103
|
+
|
|
104
|
+
ctx.closePath();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// 绘制程序化生成的高质量防伪背景
|
|
108
|
+
function drawProceduralBackground(ctx: CanvasRenderingContext2D, w: number, h: number) {
|
|
109
|
+
// 渐变底色
|
|
110
|
+
const grad = ctx.createLinearGradient(0, 0, w, h);
|
|
111
|
+
grad.addColorStop(0, 'rgb(37, 99, 235)');
|
|
112
|
+
grad.addColorStop(0.5, 'rgb(79, 70, 229)');
|
|
113
|
+
grad.addColorStop(1, 'rgb(124, 58, 237)');
|
|
114
|
+
ctx.fillStyle = grad;
|
|
115
|
+
ctx.fillRect(0, 0, w, h);
|
|
116
|
+
|
|
117
|
+
// 装饰圆点与几何网格
|
|
118
|
+
ctx.save();
|
|
119
|
+
ctx.strokeStyle = 'rgba(255, 255, 255, 0.12)';
|
|
120
|
+
ctx.lineWidth = 1;
|
|
121
|
+
for (let x = 0; x < w; x += 24) {
|
|
122
|
+
ctx.beginPath();
|
|
123
|
+
ctx.moveTo(x, 0);
|
|
124
|
+
ctx.lineTo(x, h);
|
|
125
|
+
ctx.stroke();
|
|
126
|
+
}
|
|
127
|
+
for (let y = 0; y < h; y += 24) {
|
|
128
|
+
ctx.beginPath();
|
|
129
|
+
ctx.moveTo(0, y);
|
|
130
|
+
ctx.lineTo(w, y);
|
|
131
|
+
ctx.stroke();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// 浮动噪点光斑
|
|
135
|
+
for (let i = 0; i < 6; i++) {
|
|
136
|
+
ctx.beginPath();
|
|
137
|
+
const cx = (Math.sin(i * 1.5 + 1) * 0.5 + 0.5) * w;
|
|
138
|
+
const cy = (Math.cos(i * 2 + 1) * 0.5 + 0.5) * h;
|
|
139
|
+
const r = 20 + i * 8;
|
|
140
|
+
const radial = ctx.createRadialGradient(cx, cy, 0, cx, cy, r);
|
|
141
|
+
radial.addColorStop(0, 'rgba(255, 255, 255, 0.25)');
|
|
142
|
+
radial.addColorStop(1, 'rgba(255, 255, 255, 0)');
|
|
143
|
+
ctx.fillStyle = radial;
|
|
144
|
+
ctx.arc(cx, cy, r, 0, Math.PI * 2);
|
|
145
|
+
ctx.fill();
|
|
146
|
+
}
|
|
147
|
+
ctx.restore();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// 初始化或重置拼图
|
|
151
|
+
export function reset() {
|
|
152
|
+
if (resetTimer) {
|
|
153
|
+
clearTimeout(resetTimer);
|
|
154
|
+
resetTimer = null;
|
|
155
|
+
}
|
|
156
|
+
status = 'idle';
|
|
157
|
+
currentX = 0;
|
|
158
|
+
isDragging = false;
|
|
159
|
+
isShaking = false;
|
|
160
|
+
trajectory = [];
|
|
161
|
+
|
|
162
|
+
// 计算随机目标位置
|
|
163
|
+
const minX = Math.floor(width * 0.45);
|
|
164
|
+
const maxX = width - puzzleSize - 20;
|
|
165
|
+
targetX = Math.floor(Math.random() * (maxX - minX + 1)) + minX;
|
|
166
|
+
|
|
167
|
+
const minY = 20;
|
|
168
|
+
const maxY = height - puzzleSize - 20;
|
|
169
|
+
targetY = Math.floor(Math.random() * (maxY - minY + 1)) + minY;
|
|
170
|
+
|
|
171
|
+
renderCanvas();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function renderCanvas() {
|
|
175
|
+
if (!bgCanvas || !pieceCanvas) return;
|
|
176
|
+
const bgCtx = bgCanvas.getContext('2d');
|
|
177
|
+
const pieceCtx = pieceCanvas.getContext('2d');
|
|
178
|
+
if (!bgCtx || !pieceCtx) return;
|
|
179
|
+
|
|
180
|
+
bgCtx.clearRect(0, 0, width, height);
|
|
181
|
+
pieceCtx.clearRect(0, 0, width, height);
|
|
182
|
+
|
|
183
|
+
if (bgImage) {
|
|
184
|
+
const img = new Image();
|
|
185
|
+
img.crossOrigin = 'anonymous';
|
|
186
|
+
img.onload = () => {
|
|
187
|
+
bgCtx.drawImage(img, 0, 0, width, height);
|
|
188
|
+
drawPuzzleShapes(bgCtx, pieceCtx);
|
|
189
|
+
};
|
|
190
|
+
img.onerror = () => {
|
|
191
|
+
drawProceduralBackground(bgCtx, width, height);
|
|
192
|
+
drawPuzzleShapes(bgCtx, pieceCtx);
|
|
193
|
+
};
|
|
194
|
+
img.src = bgImage;
|
|
195
|
+
} else {
|
|
196
|
+
drawProceduralBackground(bgCtx, width, height);
|
|
197
|
+
drawPuzzleShapes(bgCtx, pieceCtx);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function drawPuzzleShapes(bgCtx: CanvasRenderingContext2D, pieceCtx: CanvasRenderingContext2D) {
|
|
202
|
+
// 1. 裁剪拼图块:在 pieceCanvas 对应区域截取并画出拼图图案
|
|
203
|
+
pieceCtx.save();
|
|
204
|
+
createPuzzlePath(pieceCtx, targetX, targetY, puzzleSize, radius);
|
|
205
|
+
pieceCtx.clip();
|
|
206
|
+
if (bgCanvas) {
|
|
207
|
+
pieceCtx.drawImage(bgCanvas, 0, 0, width, height);
|
|
208
|
+
}
|
|
209
|
+
pieceCtx.strokeStyle = 'rgba(255, 255, 255, 0.9)';
|
|
210
|
+
pieceCtx.lineWidth = 2;
|
|
211
|
+
pieceCtx.shadowColor = 'rgba(0, 0, 0, 0.5)';
|
|
212
|
+
pieceCtx.shadowBlur = 4;
|
|
213
|
+
createPuzzlePath(pieceCtx, targetX, targetY, puzzleSize, radius);
|
|
214
|
+
pieceCtx.stroke();
|
|
215
|
+
pieceCtx.restore();
|
|
216
|
+
|
|
217
|
+
// 2. 在背景画布对应位置绘制凹槽阴影
|
|
218
|
+
bgCtx.save();
|
|
219
|
+
createPuzzlePath(bgCtx, targetX, targetY, puzzleSize, radius);
|
|
220
|
+
bgCtx.fillStyle = 'rgba(0, 0, 0, 0.55)';
|
|
221
|
+
bgCtx.fill();
|
|
222
|
+
bgCtx.strokeStyle = 'rgba(255, 255, 255, 0.7)';
|
|
223
|
+
bgCtx.lineWidth = 1.5;
|
|
224
|
+
bgCtx.stroke();
|
|
225
|
+
bgCtx.restore();
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function handleStart(clientX: number) {
|
|
229
|
+
if (disabled || status === 'success' || status === 'verifying') return;
|
|
230
|
+
isDragging = true;
|
|
231
|
+
startDragX = clientX;
|
|
232
|
+
startTime = Date.now();
|
|
233
|
+
status = 'sliding';
|
|
234
|
+
trajectory = [{ x: currentX, y: 0, t: startTime }];
|
|
235
|
+
|
|
236
|
+
window.addEventListener('mousemove', handleMouseMove);
|
|
237
|
+
window.addEventListener('mouseup', handleMouseUp);
|
|
238
|
+
window.addEventListener('touchmove', handleTouchMove);
|
|
239
|
+
window.addEventListener('touchend', handleTouchEnd);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function handleMove(clientX: number) {
|
|
243
|
+
if (!isDragging) return;
|
|
244
|
+
const deltaX = clientX - startDragX;
|
|
245
|
+
currentX = Math.max(0, Math.min(deltaX, maxSlide));
|
|
246
|
+
trajectory.push({ x: currentX, y: 0, t: Date.now() });
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function handleEnd() {
|
|
250
|
+
if (!isDragging) return;
|
|
251
|
+
isDragging = false;
|
|
252
|
+
window.removeEventListener('mousemove', handleMouseMove);
|
|
253
|
+
window.removeEventListener('mouseup', handleMouseUp);
|
|
254
|
+
window.removeEventListener('touchmove', handleTouchMove);
|
|
255
|
+
window.removeEventListener('touchend', handleTouchEnd);
|
|
256
|
+
|
|
257
|
+
status = 'verifying';
|
|
258
|
+
const elapsedMs = Date.now() - startTime;
|
|
259
|
+
|
|
260
|
+
const diff = Math.abs(currentX - targetX);
|
|
261
|
+
const isDistanceValid = diff <= tolerance;
|
|
262
|
+
const isTimeValid = elapsedMs >= minTimeMs && elapsedMs <= maxTimeMs;
|
|
263
|
+
const isHumanValid = trajectory.length >= 2;
|
|
264
|
+
|
|
265
|
+
if (isDistanceValid && isTimeValid && isHumanValid) {
|
|
266
|
+
status = 'success';
|
|
267
|
+
const token = `sc_${Math.random().toString(36).substring(2, 10)}_${Date.now()}`;
|
|
268
|
+
onsuccess?.({ token, elapsedMs });
|
|
269
|
+
} else {
|
|
270
|
+
status = 'fail';
|
|
271
|
+
isShaking = true;
|
|
272
|
+
onfail?.();
|
|
273
|
+
resetTimer = setTimeout(() => {
|
|
274
|
+
reset();
|
|
275
|
+
}, 900);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function handleMouseMove(e: MouseEvent) {
|
|
280
|
+
handleMove(e.clientX);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function handleMouseUp() {
|
|
284
|
+
handleEnd();
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function handleTouchMove(e: TouchEvent) {
|
|
288
|
+
if (e.touches.length > 0 && e.touches[0]) {
|
|
289
|
+
handleMove(e.touches[0].clientX);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function handleTouchEnd() {
|
|
294
|
+
handleEnd();
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function onSliderMouseDown(e: MouseEvent) {
|
|
298
|
+
e.preventDefault();
|
|
299
|
+
handleStart(e.clientX);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function onSliderTouchStart(e: TouchEvent) {
|
|
303
|
+
if (e.touches.length > 0 && e.touches[0]) {
|
|
304
|
+
handleStart(e.touches[0].clientX);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function handleRefreshClick() {
|
|
309
|
+
if (status === 'verifying' || disabled) return;
|
|
310
|
+
reset();
|
|
311
|
+
onrefresh?.();
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
onMount(() => {
|
|
315
|
+
reset();
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
onDestroy(() => {
|
|
319
|
+
if (resetTimer) clearTimeout(resetTimer);
|
|
320
|
+
window.removeEventListener('mousemove', handleMouseMove);
|
|
321
|
+
window.removeEventListener('mouseup', handleMouseUp);
|
|
322
|
+
window.removeEventListener('touchmove', handleTouchMove);
|
|
323
|
+
window.removeEventListener('touchend', handleTouchEnd);
|
|
324
|
+
});
|
|
325
|
+
</script>
|
|
326
|
+
|
|
327
|
+
<div
|
|
328
|
+
class={cn(
|
|
329
|
+
'relative select-none rounded-xl border border-border bg-card p-3 shadow-md transition-all',
|
|
330
|
+
isShaking && 'animate-shake',
|
|
331
|
+
className
|
|
332
|
+
)}
|
|
333
|
+
style="width: {width + 26}px;"
|
|
334
|
+
data-svadmin-component="SliderCaptcha"
|
|
335
|
+
>
|
|
336
|
+
<!-- 拼图展示区 -->
|
|
337
|
+
<div
|
|
338
|
+
class="relative overflow-hidden rounded-lg border border-border/80 bg-muted"
|
|
339
|
+
style="width: {width}px; height: {height}px;"
|
|
340
|
+
>
|
|
341
|
+
<!-- 背景 Canvas -->
|
|
342
|
+
<canvas
|
|
343
|
+
bind:this={bgCanvas}
|
|
344
|
+
{width}
|
|
345
|
+
{height}
|
|
346
|
+
class="block h-full w-full"
|
|
347
|
+
></canvas>
|
|
348
|
+
|
|
349
|
+
<!-- 裁剪移动拼图 Canvas -->
|
|
350
|
+
<canvas
|
|
351
|
+
bind:this={pieceCanvas}
|
|
352
|
+
{width}
|
|
353
|
+
{height}
|
|
354
|
+
class="pointer-events-none absolute top-0 left-0 transition-transform duration-75"
|
|
355
|
+
style="transform: translateX({currentX - targetX}px);"
|
|
356
|
+
></canvas>
|
|
357
|
+
|
|
358
|
+
<!-- 刷新按钮 -->
|
|
359
|
+
<button
|
|
360
|
+
type="button"
|
|
361
|
+
class="absolute top-2 right-2 rounded-md bg-black/40 p-1.5 text-white/90 backdrop-blur-sm hover:bg-black/60 hover:text-white transition-all disabled:opacity-40"
|
|
362
|
+
onclick={handleRefreshClick}
|
|
363
|
+
title={t('captcha.refresh', '换一张')}
|
|
364
|
+
aria-label="Refresh Captcha"
|
|
365
|
+
disabled={disabled || status === 'verifying'}
|
|
366
|
+
data-svadmin-action="refresh-captcha"
|
|
367
|
+
>
|
|
368
|
+
<RotateCw class={cn('h-3.5 w-3.5', status === 'verifying' && 'animate-spin')} />
|
|
369
|
+
</button>
|
|
370
|
+
</div>
|
|
371
|
+
|
|
372
|
+
<!-- 滑动轨道 -->
|
|
373
|
+
<div
|
|
374
|
+
class="relative mt-3 h-10 w-full overflow-hidden rounded-lg border border-border bg-muted/60 text-xs text-muted-foreground flex items-center justify-center font-medium"
|
|
375
|
+
>
|
|
376
|
+
<!-- 已经滑过的进度背景 -->
|
|
377
|
+
<div
|
|
378
|
+
class={cn(
|
|
379
|
+
'absolute top-0 bottom-0 left-0 transition-colors',
|
|
380
|
+
status === 'success'
|
|
381
|
+
? 'bg-primary/20 border-r border-primary'
|
|
382
|
+
: status === 'fail'
|
|
383
|
+
? 'bg-destructive/20 border-r border-destructive'
|
|
384
|
+
: 'bg-primary/10'
|
|
385
|
+
)}
|
|
386
|
+
style="width: {currentX + handleWidth}px;"
|
|
387
|
+
></div>
|
|
388
|
+
|
|
389
|
+
<!-- 轨道提示文字 -->
|
|
390
|
+
<span class="pointer-events-none z-10 px-4 text-center truncate">
|
|
391
|
+
{#if status === 'success'}
|
|
392
|
+
<span class="text-primary font-semibold flex items-center gap-1 justify-center">
|
|
393
|
+
<Check class="h-3.5 w-3.5" />
|
|
394
|
+
{resolvedSuccessText}
|
|
395
|
+
</span>
|
|
396
|
+
{:else if status === 'fail'}
|
|
397
|
+
<span class="text-destructive font-semibold flex items-center gap-1 justify-center">
|
|
398
|
+
<X class="h-3.5 w-3.5" />
|
|
399
|
+
{resolvedFailText}
|
|
400
|
+
</span>
|
|
401
|
+
{:else}
|
|
402
|
+
{resolvedText}
|
|
403
|
+
{/if}
|
|
404
|
+
</span>
|
|
405
|
+
|
|
406
|
+
<!-- 滑动手柄 -->
|
|
407
|
+
<div
|
|
408
|
+
role="slider"
|
|
409
|
+
tabindex="0"
|
|
410
|
+
aria-label="Slider handle"
|
|
411
|
+
aria-valuemin="0"
|
|
412
|
+
aria-valuemax={maxSlide}
|
|
413
|
+
aria-valuenow={currentX}
|
|
414
|
+
class={cn(
|
|
415
|
+
'absolute top-0 bottom-0 flex items-center justify-center rounded-md border shadow-sm cursor-grab active:cursor-grabbing transition-colors z-20',
|
|
416
|
+
status === 'success'
|
|
417
|
+
? 'bg-primary text-primary-foreground border-primary'
|
|
418
|
+
: status === 'fail'
|
|
419
|
+
? 'bg-destructive text-destructive-foreground border-destructive'
|
|
420
|
+
: 'bg-background text-foreground border-border hover:bg-muted active:scale-95',
|
|
421
|
+
disabled && 'cursor-not-allowed opacity-50'
|
|
422
|
+
)}
|
|
423
|
+
style="left: {currentX}px; width: {handleWidth}px;"
|
|
424
|
+
onmousedown={onSliderMouseDown}
|
|
425
|
+
ontouchstart={onSliderTouchStart}
|
|
426
|
+
data-svadmin-action="slider-handle"
|
|
427
|
+
>
|
|
428
|
+
{#if status === 'success'}
|
|
429
|
+
<Check class="h-4 w-4" />
|
|
430
|
+
{:else if status === 'fail'}
|
|
431
|
+
<X class="h-4 w-4" />
|
|
432
|
+
{:else}
|
|
433
|
+
<ChevronsRight class="h-4 w-4" />
|
|
434
|
+
{/if}
|
|
435
|
+
</div>
|
|
436
|
+
</div>
|
|
437
|
+
</div>
|
|
438
|
+
|
|
439
|
+
<style>
|
|
440
|
+
@keyframes shake {
|
|
441
|
+
0%, 100% { transform: translateX(0); }
|
|
442
|
+
20%, 60% { transform: translateX(-6px); }
|
|
443
|
+
40%, 80% { transform: translateX(6px); }
|
|
444
|
+
}
|
|
445
|
+
.animate-shake {
|
|
446
|
+
animation: shake 0.4s ease-in-out;
|
|
447
|
+
}
|
|
448
|
+
</style>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface SliderCaptchaResult {
|
|
2
|
+
token: string;
|
|
3
|
+
elapsedMs: number;
|
|
4
|
+
}
|
|
5
|
+
export interface SliderCaptchaProps {
|
|
6
|
+
width?: number | undefined;
|
|
7
|
+
height?: number | undefined;
|
|
8
|
+
puzzleSize?: number | undefined;
|
|
9
|
+
tolerance?: number | undefined;
|
|
10
|
+
minTimeMs?: number | undefined;
|
|
11
|
+
maxTimeMs?: number | undefined;
|
|
12
|
+
bgImage?: string | undefined;
|
|
13
|
+
text?: string | undefined;
|
|
14
|
+
successText?: string | undefined;
|
|
15
|
+
failText?: string | undefined;
|
|
16
|
+
disabled?: boolean | undefined;
|
|
17
|
+
class?: string | undefined;
|
|
18
|
+
onsuccess?: ((result: SliderCaptchaResult) => void) | undefined;
|
|
19
|
+
onfail?: (() => void) | undefined;
|
|
20
|
+
onrefresh?: (() => void) | undefined;
|
|
21
|
+
}
|
|
22
|
+
declare const SliderCaptcha: import("svelte").Component<SliderCaptchaProps, {
|
|
23
|
+
reset: () => void;
|
|
24
|
+
}, "">;
|
|
25
|
+
type SliderCaptcha = ReturnType<typeof SliderCaptcha>;
|
|
26
|
+
export default SliderCaptcha;
|
|
@@ -3,18 +3,18 @@
|
|
|
3
3
|
import { cn } from '../utils.js';
|
|
4
4
|
|
|
5
5
|
interface Props {
|
|
6
|
-
value?: string[];
|
|
6
|
+
value?: string[] | undefined;
|
|
7
7
|
name?: string | undefined;
|
|
8
|
-
placeholder?: string;
|
|
9
|
-
separator?: string;
|
|
10
|
-
maxItems?: number;
|
|
11
|
-
disabled?: boolean;
|
|
12
|
-
required?: boolean;
|
|
13
|
-
invalid?: boolean;
|
|
8
|
+
placeholder?: string | undefined;
|
|
9
|
+
separator?: string | undefined;
|
|
10
|
+
maxItems?: number | undefined;
|
|
11
|
+
disabled?: boolean | undefined;
|
|
12
|
+
required?: boolean | undefined;
|
|
13
|
+
invalid?: boolean | undefined;
|
|
14
14
|
describedby?: string | undefined;
|
|
15
|
-
ariaLabel?: string;
|
|
16
|
-
class?: string;
|
|
17
|
-
onchange?: (value: string[]) => void;
|
|
15
|
+
ariaLabel?: string | undefined;
|
|
16
|
+
class?: string | undefined;
|
|
17
|
+
onchange?: ((value: string[]) => void) | undefined;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
let {
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
interface Props {
|
|
2
|
-
value?: string[];
|
|
2
|
+
value?: string[] | undefined;
|
|
3
3
|
name?: string | undefined;
|
|
4
|
-
placeholder?: string;
|
|
5
|
-
separator?: string;
|
|
6
|
-
maxItems?: number;
|
|
7
|
-
disabled?: boolean;
|
|
8
|
-
required?: boolean;
|
|
9
|
-
invalid?: boolean;
|
|
4
|
+
placeholder?: string | undefined;
|
|
5
|
+
separator?: string | undefined;
|
|
6
|
+
maxItems?: number | undefined;
|
|
7
|
+
disabled?: boolean | undefined;
|
|
8
|
+
required?: boolean | undefined;
|
|
9
|
+
invalid?: boolean | undefined;
|
|
10
10
|
describedby?: string | undefined;
|
|
11
|
-
ariaLabel?: string;
|
|
12
|
-
class?: string;
|
|
13
|
-
onchange?: (value: string[]) => void;
|
|
11
|
+
ariaLabel?: string | undefined;
|
|
12
|
+
class?: string | undefined;
|
|
13
|
+
onchange?: ((value: string[]) => void) | undefined;
|
|
14
14
|
}
|
|
15
15
|
declare const TagsInput: import("svelte").Component<Props, {}, "value">;
|
|
16
16
|
type TagsInput = ReturnType<typeof TagsInput>;
|