@h-ai/ui 1.0.0-beta.17 → 1.0.0-beta.19
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/README.en.md +30 -27
- package/README.ja.md +30 -27
- package/README.md +30 -27
- package/auto-import.js +118 -53
- package/dist/components/compounds/Accordion.svelte +6 -2
- package/dist/components/compounds/BottomNav.svelte +6 -2
- package/dist/components/compounds/Card.svelte +3 -1
- package/dist/components/compounds/Combobox.svelte +24 -6
- package/dist/components/compounds/DataTable.svelte +28 -8
- package/dist/components/compounds/DatePicker.svelte +6 -1
- package/dist/components/compounds/Drawer.svelte +12 -4
- package/dist/components/compounds/Dropdown.svelte +9 -2
- package/dist/components/compounds/Empty.svelte +10 -2
- package/dist/components/compounds/FormField.svelte +10 -2
- package/dist/components/compounds/JsonViewer.svelte +18 -6
- package/dist/components/compounds/Modal.svelte +8 -2
- package/dist/components/compounds/Pagination.svelte +22 -7
- package/dist/components/compounds/Popover.svelte +28 -3
- package/dist/components/compounds/Steps.svelte +6 -2
- package/dist/components/compounds/SwipeCell.svelte +3 -1
- package/dist/components/compounds/TableToolbar.svelte +32 -9
- package/dist/components/compounds/Tabs.svelte +15 -5
- package/dist/components/compounds/Timeline.svelte +6 -2
- package/dist/components/compounds/ToastContainer.svelte +27 -7
- package/dist/components/control-size.js +48 -8
- package/dist/components/primitives/Avatar.svelte +9 -3
- package/dist/components/primitives/BareInput.svelte +3 -1
- package/dist/components/primitives/Button.svelte +6 -2
- package/dist/components/primitives/IconButton.svelte +3 -1
- package/dist/components/primitives/Input.svelte +18 -2
- package/dist/components/primitives/Radio.svelte +3 -1
- package/dist/components/primitives/Range.svelte +3 -1
- package/dist/components/primitives/Rating.svelte +9 -3
- package/dist/components/primitives/Select.svelte +21 -5
- package/dist/components/primitives/Textarea.svelte +14 -2
- package/dist/components/scenes/ai/AiDocumentEditor.svelte +40 -12
- package/dist/components/scenes/ai/document-download.js +6 -2
- package/dist/components/scenes/ai/document-parse.js +24 -8
- package/dist/components/scenes/ai/editor-markdown-extensions.js +9 -3
- package/dist/components/scenes/ai/highlight.js +3 -1
- package/dist/components/scenes/ai/markdown-parse.js +36 -10
- package/dist/components/scenes/ai/mermaid-render.js +13 -1
- package/dist/components/scenes/ai/safe-html.js +9 -3
- package/dist/components/scenes/ai/table/AiTableEditor.svelte +27 -9
- package/dist/components/scenes/app/FeedbackDetail.svelte +102 -24
- package/dist/components/scenes/app/FeedbackForm.svelte +70 -16
- package/dist/components/scenes/app/FeedbackList.svelte +138 -21
- package/dist/components/scenes/app/FeedbackRecorder.svelte +18 -5
- package/dist/components/scenes/app/FeedbackReplay.svelte +15 -3
- package/dist/components/scenes/app/FeedbackScreenshot.svelte +64 -13
- package/dist/components/scenes/app/LanguageSwitch.svelte +6 -2
- package/dist/components/scenes/app/SettingsLayout.svelte +3 -1
- package/dist/components/scenes/app/ThemeSelector.svelte +22 -4
- package/dist/components/scenes/app/ThemeToggle.svelte +6 -2
- package/dist/components/scenes/app/feedback-functions.js +6 -2
- package/dist/components/scenes/charts/Chart.svelte +16 -5
- package/dist/components/scenes/charts/MetricCard.svelte +21 -4
- package/dist/components/scenes/charts/chart-presets.js +42 -5
- package/dist/components/scenes/charts/renderers/LineChart.svelte +38 -12
- package/dist/components/scenes/crud/CrudDetailDrawer.svelte +6 -2
- package/dist/components/scenes/crud/CrudDetailPanel.svelte +6 -2
- package/dist/components/scenes/crud/CrudEditPanel.svelte +41 -12
- package/dist/components/scenes/crud/CrudPage.svelte +34 -9
- package/dist/components/scenes/crud/crud-controller.svelte.js +23 -8
- package/dist/components/scenes/crud/crud-form-validation.js +27 -9
- package/dist/components/scenes/crypto/EncryptedInput.svelte +9 -3
- package/dist/components/scenes/error/error-presets.js +30 -5
- package/dist/components/scenes/guide/GuideHostContent.svelte +7 -1
- package/dist/components/scenes/guide/HelpCenter.svelte +23 -4
- package/dist/components/scenes/iam/AgreementNotice.svelte +9 -3
- package/dist/components/scenes/iam/AuthPanel.svelte +73 -15
- package/dist/components/scenes/iam/ChangePasswordForm.svelte +6 -2
- package/dist/components/scenes/iam/ForgotPasswordForm.svelte +9 -3
- package/dist/components/scenes/iam/LoginForm.svelte +32 -8
- package/dist/components/scenes/iam/PasswordInput.svelte +49 -11
- package/dist/components/scenes/iam/RegisterForm.svelte +11 -3
- package/dist/components/scenes/iam/ResetPasswordForm.svelte +6 -2
- package/dist/components/scenes/iam/SensitiveOperationsForm.svelte +3 -1
- package/dist/components/scenes/iam/SessionRecoveryDialog.svelte +4 -1
- package/dist/components/scenes/iam/UserProfile.svelte +41 -14
- package/dist/components/scenes/iam/auth-captcha.js +9 -2
- package/dist/components/scenes/iam/auth-error-message.js +11 -3
- package/dist/components/scenes/iam/password-utils.js +9 -2
- package/dist/components/scenes/iam/sensitive-actions.svelte.js +4 -1
- package/dist/components/scenes/storage/FileList.svelte +3 -1
- package/dist/components/scenes/storage/FileUpload.svelte +7 -2
- package/dist/components/scenes/types.d.ts +2 -2
- package/dist/guide-storage.js +12 -4
- package/dist/guide.svelte.js +59 -16
- package/dist/i18n.svelte.js +9 -3
- package/dist/internal/dialog-focus.d.ts +19 -0
- package/dist/internal/dialog-focus.js +104 -4
- package/dist/internal/form-validation.svelte.js +46 -15
- package/dist/internal/icon-safety.js +6 -2
- package/dist/message.svelte.js +6 -2
- package/dist/messagebox.svelte.js +6 -2
- package/dist/theme-config.js +135 -21
- package/dist/toast.svelte.js +14 -3
- package/dist/utils.js +6 -2
- package/package.json +19 -19
|
@@ -9,11 +9,48 @@
|
|
|
9
9
|
*/
|
|
10
10
|
export function resolveChartPreset(preset) {
|
|
11
11
|
switch (preset) {
|
|
12
|
-
case 'grouped-bar': return {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
case 'grouped-bar': return {
|
|
13
|
+
type: 'bar',
|
|
14
|
+
props: {
|
|
15
|
+
seriesLayout: 'group',
|
|
16
|
+
axis: true,
|
|
17
|
+
grid: true,
|
|
18
|
+
legend: true,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
case 'stacked-bar': return {
|
|
22
|
+
type: 'bar',
|
|
23
|
+
props: {
|
|
24
|
+
seriesLayout: 'stack',
|
|
25
|
+
axis: true,
|
|
26
|
+
grid: true,
|
|
27
|
+
legend: true,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
case 'stacked-area': return {
|
|
31
|
+
type: 'area',
|
|
32
|
+
props: {
|
|
33
|
+
seriesLayout: 'stack',
|
|
34
|
+
axis: true,
|
|
35
|
+
grid: true,
|
|
36
|
+
legend: true,
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
case 'donut': return {
|
|
40
|
+
type: 'pie',
|
|
41
|
+
props: { innerRadius: 0.65, legend: true },
|
|
42
|
+
};
|
|
43
|
+
case 'sparkline': return {
|
|
44
|
+
type: 'line',
|
|
45
|
+
props: {
|
|
46
|
+
axis: false,
|
|
47
|
+
grid: false,
|
|
48
|
+
legend: false,
|
|
49
|
+
points: false,
|
|
50
|
+
padding: { top: 4, right: 0, bottom: 4, left: 0 },
|
|
51
|
+
height: 64,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
17
54
|
default: return { props: {} };
|
|
18
55
|
}
|
|
19
56
|
}
|
|
@@ -216,9 +216,13 @@
|
|
|
216
216
|
* @returns 有限数字,无法转换时返回 0
|
|
217
217
|
*/
|
|
218
218
|
function toFiniteNumber(value: unknown): number {
|
|
219
|
-
const numberValue = typeof value === 'number'
|
|
219
|
+
const numberValue = typeof value === 'number'
|
|
220
|
+
? value
|
|
221
|
+
: Number(value)
|
|
220
222
|
|
|
221
|
-
return Number.isFinite(numberValue)
|
|
223
|
+
return Number.isFinite(numberValue)
|
|
224
|
+
? numberValue
|
|
225
|
+
: 0
|
|
222
226
|
}
|
|
223
227
|
|
|
224
228
|
/**
|
|
@@ -248,7 +252,15 @@
|
|
|
248
252
|
* @returns CSS 颜色值或变量
|
|
249
253
|
*/
|
|
250
254
|
function getSeriesColor(item: ChartSeries, index: number): string {
|
|
251
|
-
return item.color ?? `var(--color-${[
|
|
255
|
+
return item.color ?? `var(--color-${[
|
|
256
|
+
'primary',
|
|
257
|
+
'secondary',
|
|
258
|
+
'accent',
|
|
259
|
+
'success',
|
|
260
|
+
'warning',
|
|
261
|
+
'error',
|
|
262
|
+
'info',
|
|
263
|
+
][index % 7]})`
|
|
252
264
|
}
|
|
253
265
|
|
|
254
266
|
/**
|
|
@@ -275,17 +287,27 @@
|
|
|
275
287
|
|
|
276
288
|
if (Array.isArray(yAccessor)) {
|
|
277
289
|
return yAccessor.map((accessor, index) => ({
|
|
278
|
-
key: typeof accessor === 'string'
|
|
279
|
-
|
|
290
|
+
key: typeof accessor === 'string'
|
|
291
|
+
? accessor
|
|
292
|
+
: `series-${index}`,
|
|
293
|
+
label: typeof accessor === 'string'
|
|
294
|
+
? accessor
|
|
295
|
+
: `series-${index + 1}`,
|
|
280
296
|
value: accessor,
|
|
281
297
|
}))
|
|
282
298
|
}
|
|
283
299
|
|
|
284
|
-
return [
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
300
|
+
return [
|
|
301
|
+
{
|
|
302
|
+
key: typeof yAccessor === 'string'
|
|
303
|
+
? yAccessor
|
|
304
|
+
: 'value',
|
|
305
|
+
label: typeof yAccessor === 'string'
|
|
306
|
+
? yAccessor
|
|
307
|
+
: 'value',
|
|
308
|
+
value: yAccessor,
|
|
309
|
+
},
|
|
310
|
+
]
|
|
289
311
|
}
|
|
290
312
|
|
|
291
313
|
/**
|
|
@@ -323,7 +345,9 @@
|
|
|
323
345
|
function getSegmentedLineMax(items: SegmentedLineSeries[]): number {
|
|
324
346
|
const maxValue = Math.max(...items.flatMap(item => item.points.map(point => point.value)))
|
|
325
347
|
|
|
326
|
-
return maxValue > 0
|
|
348
|
+
return maxValue > 0
|
|
349
|
+
? maxValue
|
|
350
|
+
: 1
|
|
327
351
|
}
|
|
328
352
|
|
|
329
353
|
/**
|
|
@@ -406,7 +430,9 @@
|
|
|
406
430
|
const currentDistance = Math.abs(point.x - pointerX)
|
|
407
431
|
const bestDistance = Math.abs((primaryCoordinates[bestIndex]?.x ?? point.x) - pointerX)
|
|
408
432
|
|
|
409
|
-
return currentDistance < bestDistance
|
|
433
|
+
return currentDistance < bestDistance
|
|
434
|
+
? index
|
|
435
|
+
: bestIndex
|
|
410
436
|
}, 0)
|
|
411
437
|
const nearestPoint = primaryCoordinates[nearestIndex]
|
|
412
438
|
if (nearestPoint)
|
|
@@ -71,13 +71,17 @@
|
|
|
71
71
|
|
|
72
72
|
const dataAttributes = $derived(getDataAttributes(restProps))
|
|
73
73
|
function resolveText(text: string | (() => string)): string {
|
|
74
|
-
return typeof text === 'function'
|
|
74
|
+
return typeof text === 'function'
|
|
75
|
+
? text()
|
|
76
|
+
: text
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
function resolveOptions(options?: FieldDef['options']): Array<{ label: string, value: string | number | boolean }> {
|
|
78
80
|
if (!options)
|
|
79
81
|
return []
|
|
80
|
-
return typeof options === 'function'
|
|
82
|
+
return typeof options === 'function'
|
|
83
|
+
? options()
|
|
84
|
+
: options
|
|
81
85
|
}
|
|
82
86
|
|
|
83
87
|
function formatValue(field: FieldDef, value: unknown): string {
|
|
@@ -87,13 +87,17 @@
|
|
|
87
87
|
|
|
88
88
|
const dataAttributes = $derived(getDataAttributes(restProps))
|
|
89
89
|
function resolveText(text: string | (() => string)): string {
|
|
90
|
-
return typeof text === 'function'
|
|
90
|
+
return typeof text === 'function'
|
|
91
|
+
? text()
|
|
92
|
+
: text
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
function resolveOptions(options?: FieldDef['options']): Array<{ label: string, value: string | number | boolean }> {
|
|
94
96
|
if (!options)
|
|
95
97
|
return []
|
|
96
|
-
return typeof options === 'function'
|
|
98
|
+
return typeof options === 'function'
|
|
99
|
+
? options()
|
|
100
|
+
: options
|
|
97
101
|
}
|
|
98
102
|
|
|
99
103
|
function formatValue(field: FieldDef, value: unknown): string {
|
|
@@ -103,7 +103,9 @@
|
|
|
103
103
|
function resolveOptions(options?: CrudFieldDef['options']): Array<{ label: string, value: string | number | boolean }> {
|
|
104
104
|
if (!options)
|
|
105
105
|
return []
|
|
106
|
-
return typeof options === 'function'
|
|
106
|
+
return typeof options === 'function'
|
|
107
|
+
? options()
|
|
108
|
+
: options
|
|
107
109
|
}
|
|
108
110
|
|
|
109
111
|
const sortedFields = $derived(
|
|
@@ -115,8 +117,11 @@
|
|
|
115
117
|
if ((!attempted && !touched[field.id]) || (mode === 'edit' && field.readonly))
|
|
116
118
|
continue
|
|
117
119
|
const issue = getCrudValidationIssue(field, formData[field.id])
|
|
118
|
-
if (issue)
|
|
119
|
-
errors[field.id] = field.validation?.message
|
|
120
|
+
if (issue) {
|
|
121
|
+
errors[field.id] = field.validation?.message
|
|
122
|
+
? resolveText(field.validation.message)
|
|
123
|
+
: uiM(issue.key, issue.params)
|
|
124
|
+
}
|
|
120
125
|
}
|
|
121
126
|
return errors
|
|
122
127
|
})
|
|
@@ -204,14 +209,23 @@
|
|
|
204
209
|
{@const isReadonly = field.readonly && mode === 'edit'}
|
|
205
210
|
{@const isRequired = field.validation?.required}
|
|
206
211
|
{@const fieldValue = formData[field.id]}
|
|
207
|
-
{@const placeholder = field.placeholder
|
|
212
|
+
{@const placeholder = field.placeholder
|
|
213
|
+
? resolveText(field.placeholder)
|
|
214
|
+
: ''}
|
|
208
215
|
{@const controlId = `${panelId}-${field.id}`}
|
|
209
216
|
<FormField
|
|
210
217
|
for={controlId}
|
|
211
218
|
label={resolveText(field.label)}
|
|
212
219
|
required={isRequired}
|
|
213
220
|
error={fieldErrors[field.id]}
|
|
214
|
-
colSpan={field.colSpan ?? ([
|
|
221
|
+
colSpan={field.colSpan ?? ([
|
|
222
|
+
'textarea',
|
|
223
|
+
'multi-select',
|
|
224
|
+
'date-range',
|
|
225
|
+
'custom',
|
|
226
|
+
].includes(field.type)
|
|
227
|
+
? 2
|
|
228
|
+
: 'auto')}
|
|
215
229
|
data-field={field.id}
|
|
216
230
|
>
|
|
217
231
|
|
|
@@ -240,7 +254,10 @@
|
|
|
240
254
|
disabled={submitting || isReadonly}
|
|
241
255
|
options={[
|
|
242
256
|
{ value: '', label: placeholder || uiM('crud_filter_all') },
|
|
243
|
-
...opts.map(opt => ({
|
|
257
|
+
...opts.map(opt => ({
|
|
258
|
+
value: String(opt.value),
|
|
259
|
+
label: opt.label,
|
|
260
|
+
})),
|
|
244
261
|
]}
|
|
245
262
|
onchange={value => updateField(field.id, opts.find(opt => String(opt.value) === value)?.value ?? value)}
|
|
246
263
|
/>
|
|
@@ -285,11 +302,21 @@
|
|
|
285
302
|
disabled={submitting || isReadonly}
|
|
286
303
|
required={isRequired}
|
|
287
304
|
pattern={field.validation?.pattern}
|
|
288
|
-
minlength={field.type !== 'number'
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
305
|
+
minlength={field.type !== 'number'
|
|
306
|
+
? field.validation?.min
|
|
307
|
+
: undefined}
|
|
308
|
+
maxlength={field.type !== 'number'
|
|
309
|
+
? field.validation?.max
|
|
310
|
+
: undefined}
|
|
311
|
+
min={field.type === 'number'
|
|
312
|
+
? field.validation?.min
|
|
313
|
+
: undefined}
|
|
314
|
+
max={field.type === 'number'
|
|
315
|
+
? field.validation?.max
|
|
316
|
+
: undefined}
|
|
317
|
+
oninput={e => updateField(field.id, field.type === 'number' && e.currentTarget.value !== ''
|
|
318
|
+
? Number(e.currentTarget.value)
|
|
319
|
+
: e.currentTarget.value)}
|
|
293
320
|
/>
|
|
294
321
|
{/if}
|
|
295
322
|
</FormField>
|
|
@@ -311,7 +338,9 @@
|
|
|
311
338
|
{#if submitting}
|
|
312
339
|
<span class='loading loading-spinner loading-xs mr-2'></span>
|
|
313
340
|
{/if}
|
|
314
|
-
{mode === 'create'
|
|
341
|
+
{mode === 'create'
|
|
342
|
+
? uiM('crud_create')
|
|
343
|
+
: uiM('crud_save')}
|
|
315
344
|
</Button>
|
|
316
345
|
{/snippet}
|
|
317
346
|
|
|
@@ -361,7 +361,9 @@
|
|
|
361
361
|
|
|
362
362
|
/** 解析静态或延迟读取的显示文案。 */
|
|
363
363
|
function resolveText(text: string | (() => string)): string {
|
|
364
|
-
return typeof text === 'function'
|
|
364
|
+
return typeof text === 'function'
|
|
365
|
+
? text()
|
|
366
|
+
: text
|
|
365
367
|
}
|
|
366
368
|
|
|
367
369
|
// 同步 data.filters → 本地过滤/排序状态;没有 filters 时也要清空旧状态。
|
|
@@ -369,7 +371,9 @@
|
|
|
369
371
|
const filters = data.filters ?? {}
|
|
370
372
|
searchValue = String(filters.search ?? '')
|
|
371
373
|
sortBy = String(filters.sortBy ?? '')
|
|
372
|
-
sortDirection = filters.sortDirection === 'asc'
|
|
374
|
+
sortDirection = filters.sortDirection === 'asc'
|
|
375
|
+
? 'asc'
|
|
376
|
+
: 'desc'
|
|
373
377
|
const fv: Record<string, unknown> = {}
|
|
374
378
|
for (const f of crud.getFilterFields()) {
|
|
375
379
|
if (filters[f.id] !== undefined) {
|
|
@@ -405,9 +409,18 @@
|
|
|
405
409
|
sortBy,
|
|
406
410
|
sortDirection,
|
|
407
411
|
...Object.fromEntries(
|
|
408
|
-
Object.entries(conditions).filter(([key]) => ![
|
|
412
|
+
Object.entries(conditions).filter(([key]) => ![
|
|
413
|
+
'search',
|
|
414
|
+
'sortBy',
|
|
415
|
+
'sortDirection',
|
|
416
|
+
'page',
|
|
417
|
+
'pageSize',
|
|
418
|
+
].includes(key))
|
|
409
419
|
.filter(([, v]) => v !== undefined && v !== '')
|
|
410
|
-
.map(([k, v]) => [
|
|
420
|
+
.map(([k, v]) => [
|
|
421
|
+
k,
|
|
422
|
+
String(v),
|
|
423
|
+
]),
|
|
411
424
|
),
|
|
412
425
|
...overrides,
|
|
413
426
|
}
|
|
@@ -423,7 +436,9 @@
|
|
|
423
436
|
/** 序列化后的查询字符串。 */
|
|
424
437
|
const qs = params.toString()
|
|
425
438
|
/** 交给宿主路由的目标 URL。 */
|
|
426
|
-
const url = `${currentBasePath}${qs
|
|
439
|
+
const url = `${currentBasePath}${qs
|
|
440
|
+
? `?${qs}`
|
|
441
|
+
: ''}`
|
|
427
442
|
void Promise.resolve(nav.navigate(url)).then(() => nav.refresh?.())
|
|
428
443
|
}
|
|
429
444
|
|
|
@@ -469,7 +484,9 @@
|
|
|
469
484
|
/** 打开新建面板并填充默认值。 */
|
|
470
485
|
function openCreate() {
|
|
471
486
|
selectedItem = null
|
|
472
|
-
formData = {
|
|
487
|
+
formData = {
|
|
488
|
+
...crud.getDefaultValues(),
|
|
489
|
+
}
|
|
473
490
|
formError = ''
|
|
474
491
|
panelMode = 'create'
|
|
475
492
|
}
|
|
@@ -644,7 +661,11 @@
|
|
|
644
661
|
: undefined,
|
|
645
662
|
})),
|
|
646
663
|
)
|
|
647
|
-
useToastFeedback(() => error
|
|
664
|
+
useToastFeedback(() => error
|
|
665
|
+
? typeof error === 'string'
|
|
666
|
+
? error
|
|
667
|
+
: uiM('crud_load_failed')
|
|
668
|
+
: '')
|
|
648
669
|
useToastFeedback(() => deleteError)
|
|
649
670
|
</script>
|
|
650
671
|
|
|
@@ -845,8 +866,12 @@
|
|
|
845
866
|
<!-- 编辑/新建:抽屉或弹窗 -->
|
|
846
867
|
<CrudEditPanel
|
|
847
868
|
open={editOpen}
|
|
848
|
-
mode={panelMode === 'create'
|
|
849
|
-
|
|
869
|
+
mode={panelMode === 'create'
|
|
870
|
+
? 'create'
|
|
871
|
+
: 'edit'}
|
|
872
|
+
fields={panelMode === 'create'
|
|
873
|
+
? createFields
|
|
874
|
+
: editFields}
|
|
850
875
|
{density}
|
|
851
876
|
bind:formData
|
|
852
877
|
title={panelTitle}
|
|
@@ -17,7 +17,9 @@ import { SvelteURLSearchParams } from 'svelte/reactivity';
|
|
|
17
17
|
* 解析可能是 i18n 函数的文本。
|
|
18
18
|
*/
|
|
19
19
|
function resolveText(text) {
|
|
20
|
-
return typeof text === 'function'
|
|
20
|
+
return typeof text === 'function'
|
|
21
|
+
? text()
|
|
22
|
+
: text;
|
|
21
23
|
}
|
|
22
24
|
/**
|
|
23
25
|
* 映射分页结果的 `items`,保留 total / page / pageSize。
|
|
@@ -80,7 +82,9 @@ export function defineCrud(resource) {
|
|
|
80
82
|
label: resolveText(f.label),
|
|
81
83
|
width: f.width,
|
|
82
84
|
align: f.align,
|
|
83
|
-
render: f.render
|
|
85
|
+
render: f.render
|
|
86
|
+
? (item) => f.render(item[f.id], item)
|
|
87
|
+
: undefined,
|
|
84
88
|
})),
|
|
85
89
|
getDefaultValues: () => Object.fromEntries(fields.filter(f => f.defaultValue !== undefined).map(f => [f.id, f.defaultValue])),
|
|
86
90
|
api: resource.api,
|
|
@@ -192,8 +196,11 @@ export function createCrudController(crud, options = {}) {
|
|
|
192
196
|
return;
|
|
193
197
|
// 列表加载失败(慢响应/重启/超时)时保留上一次结果,绝不用空列表覆盖,避免误显示“0 条记录”;
|
|
194
198
|
// 同时暴露错误给页面:首次失败不能被当成一次成功的空结果。
|
|
195
|
-
if (requestSeq === listRequestSeq)
|
|
196
|
-
error = cause instanceof Error
|
|
199
|
+
if (requestSeq === listRequestSeq) {
|
|
200
|
+
error = cause instanceof Error
|
|
201
|
+
? cause
|
|
202
|
+
: new Error(String(cause));
|
|
203
|
+
}
|
|
197
204
|
}
|
|
198
205
|
finally {
|
|
199
206
|
if (requestSeq === listRequestSeq) {
|
|
@@ -209,12 +216,18 @@ export function createCrudController(crud, options = {}) {
|
|
|
209
216
|
}
|
|
210
217
|
/** 从 CrudPage 生成的 URL 中解析查询参数。 */
|
|
211
218
|
function parseParams(url) {
|
|
212
|
-
const qs = url.includes('?')
|
|
219
|
+
const qs = url.includes('?')
|
|
220
|
+
? url.slice(url.indexOf('?') + 1)
|
|
221
|
+
: '';
|
|
213
222
|
const sp = new SvelteURLSearchParams(qs);
|
|
214
223
|
const params = {
|
|
215
224
|
search: sp.get('search') ?? '',
|
|
216
|
-
page: sp.get('page')
|
|
217
|
-
|
|
225
|
+
page: sp.get('page')
|
|
226
|
+
? Number(sp.get('page'))
|
|
227
|
+
: 1,
|
|
228
|
+
pageSize: sp.get('pageSize')
|
|
229
|
+
? Number(sp.get('pageSize'))
|
|
230
|
+
: defaultPageSize,
|
|
218
231
|
};
|
|
219
232
|
for (const key of ['sortBy', 'sortDirection']) {
|
|
220
233
|
const v = sp.get(key);
|
|
@@ -236,7 +249,9 @@ export function createCrudController(crud, options = {}) {
|
|
|
236
249
|
const loc = globalThis.location;
|
|
237
250
|
if (!his?.replaceState || !loc)
|
|
238
251
|
return;
|
|
239
|
-
const qs = url.includes('?')
|
|
252
|
+
const qs = url.includes('?')
|
|
253
|
+
? url.slice(url.indexOf('?'))
|
|
254
|
+
: '';
|
|
240
255
|
try {
|
|
241
256
|
his.replaceState(his.state, '', `${loc.pathname}${qs}${loc.hash}`);
|
|
242
257
|
}
|
|
@@ -18,19 +18,37 @@ export function getCrudValidationIssue(field, value) {
|
|
|
18
18
|
if (empty)
|
|
19
19
|
return undefined;
|
|
20
20
|
if (field.type === 'number') {
|
|
21
|
-
const number = typeof value === 'number'
|
|
21
|
+
const number = typeof value === 'number'
|
|
22
|
+
? value
|
|
23
|
+
: Number(value);
|
|
22
24
|
if (!Number.isFinite(number))
|
|
23
25
|
return { key: 'form_number' };
|
|
24
|
-
if (rules?.min !== undefined && number < rules.min)
|
|
25
|
-
return {
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
if (rules?.min !== undefined && number < rules.min) {
|
|
27
|
+
return {
|
|
28
|
+
key: 'form_min',
|
|
29
|
+
params: { min: rules.min },
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
if (rules?.max !== undefined && number > rules.max) {
|
|
33
|
+
return {
|
|
34
|
+
key: 'form_max',
|
|
35
|
+
params: { max: rules.max },
|
|
36
|
+
};
|
|
37
|
+
}
|
|
28
38
|
}
|
|
29
39
|
else if (typeof value === 'string') {
|
|
30
|
-
if (rules?.min !== undefined && value.length < rules.min)
|
|
31
|
-
return {
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
if (rules?.min !== undefined && value.length < rules.min) {
|
|
41
|
+
return {
|
|
42
|
+
key: 'form_min_length',
|
|
43
|
+
params: { min: rules.min },
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (rules?.max !== undefined && value.length > rules.max) {
|
|
47
|
+
return {
|
|
48
|
+
key: 'form_max_length',
|
|
49
|
+
params: { max: rules.max },
|
|
50
|
+
};
|
|
51
|
+
}
|
|
34
52
|
}
|
|
35
53
|
if (field.type === 'email' && !/^[\w.!#$%&'*+/=?^`{|}~-]+@[a-z\d](?:[a-z\d-]*[a-z\d])?(?:\.[a-z\d](?:[a-z\d-]*[a-z\d])?)*$/i.test(String(value)))
|
|
36
54
|
return { key: 'form_email' };
|
|
@@ -83,8 +83,12 @@
|
|
|
83
83
|
const dataAttributes = $derived(getDataAttributes(restProps))
|
|
84
84
|
let showValue = $state(false)
|
|
85
85
|
let encryptionError = $state(false)
|
|
86
|
-
useToastFeedback(() => encryptionError
|
|
87
|
-
|
|
86
|
+
useToastFeedback(() => encryptionError
|
|
87
|
+
? uiM('encrypted_input_failed')
|
|
88
|
+
: '')
|
|
89
|
+
useToastFeedback(() => !onencrypt
|
|
90
|
+
? uiM('encrypted_input_unavailable')
|
|
91
|
+
: '', 'warning')
|
|
88
92
|
|
|
89
93
|
// 输入、回调或组件生命周期变化时,旧请求立即失效。
|
|
90
94
|
$effect(() => {
|
|
@@ -150,7 +154,9 @@
|
|
|
150
154
|
class='absolute right-3 top-1/2 -translate-y-1/2 text-base-content/50 hover:text-base-content'
|
|
151
155
|
onclick={toggleShow}
|
|
152
156
|
tabindex={-1}
|
|
153
|
-
ariaLabel={showValue
|
|
157
|
+
ariaLabel={showValue
|
|
158
|
+
? uiM('encrypted_input_hide')
|
|
159
|
+
: uiM('encrypted_input_show')}
|
|
154
160
|
>
|
|
155
161
|
{#if showValue}
|
|
156
162
|
<svg xmlns='http://www.w3.org/2000/svg' class='h-5 w-5' fill='none' viewBox='0 0 24 24' stroke='currentColor'>
|
|
@@ -15,11 +15,36 @@
|
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
17
17
|
export const ERROR_PRESETS = {
|
|
18
|
-
401: {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
401: {
|
|
19
|
+
code: '401',
|
|
20
|
+
titleKey: 'error_401_title',
|
|
21
|
+
descKey: 'error_401_desc',
|
|
22
|
+
icon: 'icon-[tabler--lock]',
|
|
23
|
+
},
|
|
24
|
+
403: {
|
|
25
|
+
code: '403',
|
|
26
|
+
titleKey: 'error_403_title',
|
|
27
|
+
descKey: 'error_403_desc',
|
|
28
|
+
icon: 'icon-[tabler--shield-lock]',
|
|
29
|
+
},
|
|
30
|
+
404: {
|
|
31
|
+
code: '404',
|
|
32
|
+
titleKey: 'error_404_title',
|
|
33
|
+
descKey: 'error_404_desc',
|
|
34
|
+
icon: 'icon-[tabler--map-search]',
|
|
35
|
+
},
|
|
36
|
+
500: {
|
|
37
|
+
code: '500',
|
|
38
|
+
titleKey: 'error_500_title',
|
|
39
|
+
descKey: 'error_500_desc',
|
|
40
|
+
icon: 'icon-[tabler--server-off]',
|
|
41
|
+
},
|
|
42
|
+
503: {
|
|
43
|
+
code: '503',
|
|
44
|
+
titleKey: 'error_503_title',
|
|
45
|
+
descKey: 'error_503_desc',
|
|
46
|
+
icon: 'icon-[tabler--tool]',
|
|
47
|
+
},
|
|
23
48
|
};
|
|
24
49
|
/**
|
|
25
50
|
* 根据 HTTP 状态码解析到最接近的预设
|
|
@@ -54,7 +54,13 @@
|
|
|
54
54
|
const offered = $derived.by(() => {
|
|
55
55
|
void locale
|
|
56
56
|
const tour = guide.offeredTour
|
|
57
|
-
return tour
|
|
57
|
+
return tour
|
|
58
|
+
? {
|
|
59
|
+
id: tour.id,
|
|
60
|
+
title: resolveGuideText(tour.title),
|
|
61
|
+
description: resolveGuideText(tour.description),
|
|
62
|
+
}
|
|
63
|
+
: null
|
|
58
64
|
})
|
|
59
65
|
const text = $derived.by(() => ({
|
|
60
66
|
welcome: uiM('guide_welcome', undefined, locale),
|
|
@@ -56,7 +56,15 @@
|
|
|
56
56
|
try {
|
|
57
57
|
if (article.enabled && !article.enabled())
|
|
58
58
|
return []
|
|
59
|
-
return [
|
|
59
|
+
return [
|
|
60
|
+
{
|
|
61
|
+
...article,
|
|
62
|
+
title: resolveGuideText(article.title),
|
|
63
|
+
description: resolveGuideText(article.description),
|
|
64
|
+
category: resolveGuideText(article.category),
|
|
65
|
+
content: resolveGuideText(article.content),
|
|
66
|
+
},
|
|
67
|
+
]
|
|
60
68
|
}
|
|
61
69
|
catch {
|
|
62
70
|
failed = true
|
|
@@ -70,14 +78,23 @@
|
|
|
70
78
|
void locale
|
|
71
79
|
return tours.flatMap((tour) => {
|
|
72
80
|
try {
|
|
73
|
-
return !tour.enabled || tour.enabled()
|
|
81
|
+
return !tour.enabled || tour.enabled()
|
|
82
|
+
? [
|
|
83
|
+
{
|
|
84
|
+
id: tour.id,
|
|
85
|
+
title: resolveGuideText(tour.title),
|
|
86
|
+
},
|
|
87
|
+
]
|
|
88
|
+
: []
|
|
74
89
|
}
|
|
75
90
|
catch { return [] }
|
|
76
91
|
})
|
|
77
92
|
})
|
|
78
93
|
const visible = $derived(localized.filter(article => (`${article.title} ${article.description} ${article.category} ${article.content}`).toLowerCase().includes(search.trim().toLowerCase())))
|
|
79
94
|
const selected = $derived(visible.find(article => article.id === currentId) ?? visible[0])
|
|
80
|
-
const markdown = $derived(selected
|
|
95
|
+
const markdown = $derived(selected
|
|
96
|
+
? import('../ai/MarkdownRenderer.svelte')
|
|
97
|
+
: null)
|
|
81
98
|
const text = $derived.by(() => ({
|
|
82
99
|
search: uiM('guide_search', undefined, locale),
|
|
83
100
|
empty: uiM('guide_empty', undefined, locale),
|
|
@@ -95,7 +112,9 @@
|
|
|
95
112
|
<Input id={searchId} bind:value={search} placeholder={text.search} data-testid='guide-search' />
|
|
96
113
|
<div class='mt-3 max-h-40 space-y-1 overflow-y-auto md:max-h-[50dvh]'>
|
|
97
114
|
{#each visible as article (article.id)}
|
|
98
|
-
<BareButton class={`w-full rounded-lg px-3 py-2 text-left text-sm hover:bg-base-content/5 ${selected?.id === article.id
|
|
115
|
+
<BareButton class={`w-full rounded-lg px-3 py-2 text-left text-sm hover:bg-base-content/5 ${selected?.id === article.id
|
|
116
|
+
? 'bg-primary/10 font-semibold text-primary'
|
|
117
|
+
: ''}`} onclick={() => currentId = article.id} data-testid={`guide-article-${article.id}`}>
|
|
99
118
|
{#if article.category}<span class='mb-1 block text-xs text-base-content/50'>{article.category}</span>{/if}
|
|
100
119
|
<span class='block'>{article.title}</span>
|
|
101
120
|
</BareButton>
|
|
@@ -9,11 +9,17 @@
|
|
|
9
9
|
const { agreements }: { agreements?: AgreementDisplay } = $props()
|
|
10
10
|
let selected = $state<'user' | 'privacy' | null>(null)
|
|
11
11
|
let open = $state(false)
|
|
12
|
-
const url = $derived(selected === 'user'
|
|
13
|
-
|
|
12
|
+
const url = $derived(selected === 'user'
|
|
13
|
+
? agreements?.userAgreementUrl
|
|
14
|
+
: agreements?.privacyPolicyUrl)
|
|
15
|
+
const markdown = $derived(selected === 'user'
|
|
16
|
+
? agreements?.userAgreementMarkdown
|
|
17
|
+
: agreements?.privacyPolicyMarkdown)
|
|
14
18
|
const hasUserAgreement = $derived(Boolean(agreements?.userAgreementMarkdown || agreements?.userAgreementUrl))
|
|
15
19
|
const hasPrivacyPolicy = $derived(Boolean(agreements?.privacyPolicyMarkdown || agreements?.privacyPolicyUrl))
|
|
16
|
-
const title = $derived(selected === 'user'
|
|
20
|
+
const title = $derived(selected === 'user'
|
|
21
|
+
? uiM('agreement_user_agreement')
|
|
22
|
+
: uiM('agreement_privacy_policy'))
|
|
17
23
|
|
|
18
24
|
function show(kind: 'user' | 'privacy') {
|
|
19
25
|
selected = kind
|