@movk/nuxt 1.8.2 → 2.0.0-beta.1
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 +16 -6
- package/README.md +16 -6
- package/dist/module.d.mts +6 -0
- package/dist/module.json +3 -3
- package/dist/module.mjs +21 -24
- package/dist/runtime/components/AutoForm.d.vue.ts +15 -1
- package/dist/runtime/components/AutoForm.vue +48 -50
- package/dist/runtime/components/AutoForm.vue.d.ts +15 -1
- package/dist/runtime/components/DataTable.d.vue.ts +4 -2
- package/dist/runtime/components/DataTable.vue +166 -174
- package/dist/runtime/components/DataTable.vue.d.ts +4 -2
- package/dist/runtime/components/DatePicker.d.vue.ts +6 -5
- package/dist/runtime/components/DatePicker.vue +96 -43
- package/dist/runtime/components/DatePicker.vue.d.ts +6 -5
- package/dist/runtime/components/MessageBox.d.vue.ts +1 -5
- package/dist/runtime/components/MessageBox.vue +9 -7
- package/dist/runtime/components/MessageBox.vue.d.ts +1 -5
- package/dist/runtime/components/SearchForm.d.vue.ts +12 -4
- package/dist/runtime/components/SearchForm.vue +130 -120
- package/dist/runtime/components/SearchForm.vue.d.ts +12 -4
- package/dist/runtime/components/Tree.d.vue.ts +3 -1
- package/dist/runtime/components/Tree.vue +102 -140
- package/dist/runtime/components/Tree.vue.d.ts +3 -1
- package/dist/runtime/components/theme-picker/ThemePicker.vue +5 -3
- package/dist/runtime/components/theme-picker/ThemePickerButton.vue +15 -6
- package/dist/runtime/composables/index.d.ts +1 -0
- package/dist/runtime/composables/index.js +1 -0
- package/dist/runtime/composables/useApiFetch.d.ts +7 -7
- package/dist/runtime/composables/useApiFetch.js +5 -23
- package/dist/runtime/composables/useAutoForm.js +2 -2
- package/dist/runtime/composables/useClientApiFetch.d.ts +5 -5
- package/dist/runtime/composables/useDateFormatter.d.ts +32 -34
- package/dist/runtime/composables/useDateFormatter.js +75 -232
- package/dist/runtime/composables/useDownloadWithProgress.d.ts +11 -8
- package/dist/runtime/composables/useDownloadWithProgress.js +49 -132
- package/dist/runtime/composables/useMessageBox.js +3 -2
- package/dist/runtime/composables/useMovkLocale.d.ts +16 -0
- package/dist/runtime/composables/useMovkLocale.js +20 -0
- package/dist/runtime/composables/useTheme.js +8 -18
- package/dist/runtime/composables/useUploadWithProgress.d.ts +9 -6
- package/dist/runtime/composables/useUploadWithProgress.js +50 -84
- package/dist/runtime/domains/ai/chat-transport.js +1 -0
- package/dist/runtime/domains/api/adapters/xhr.d.ts +17 -0
- package/dist/runtime/domains/api/adapters/xhr.js +55 -0
- package/dist/runtime/domains/api/auth.d.ts +4 -1
- package/dist/runtime/domains/api/auth.js +9 -13
- package/dist/runtime/domains/api/client.d.ts +13 -0
- package/dist/runtime/domains/api/client.js +35 -0
- package/dist/runtime/domains/api/download.d.ts +10 -0
- package/dist/runtime/domains/api/download.js +28 -0
- package/dist/runtime/domains/api/errors.d.ts +20 -2
- package/dist/runtime/domains/api/errors.js +61 -8
- package/dist/runtime/domains/api/fetch-key.d.ts +2 -2
- package/dist/runtime/domains/api/fetch-key.js +4 -4
- package/dist/runtime/domains/api/interceptors/request.d.ts +2 -6
- package/dist/runtime/domains/api/interceptors/request.js +3 -2
- package/dist/runtime/domains/api/interceptors/response.d.ts +8 -12
- package/dist/runtime/domains/api/interceptors/response.js +34 -20
- package/dist/runtime/domains/api/report.d.ts +25 -0
- package/dist/runtime/domains/api/report.js +51 -0
- package/dist/runtime/domains/api/response.d.ts +29 -4
- package/dist/runtime/domains/api/response.js +27 -6
- package/dist/runtime/domains/api/session.d.ts +12 -0
- package/dist/runtime/domains/api/session.js +9 -0
- package/dist/runtime/domains/api/stream.d.ts +2 -1
- package/dist/runtime/domains/api/stream.js +2 -1
- package/dist/runtime/domains/api/toast.d.ts +6 -3
- package/dist/runtime/domains/api/toast.js +7 -7
- package/dist/runtime/domains/auto-form/actions.d.ts +2 -1
- package/dist/runtime/domains/auto-form/actions.js +6 -4
- package/dist/runtime/domains/auto-form/array-ops.d.ts +3 -0
- package/dist/runtime/domains/auto-form/array-ops.js +9 -0
- package/dist/runtime/domains/auto-form/async-items.d.ts +10 -0
- package/dist/runtime/domains/auto-form/async-items.js +42 -0
- package/dist/runtime/domains/auto-form/components/Array.d.vue.ts +0 -4
- package/dist/runtime/domains/auto-form/components/Array.vue +81 -73
- package/dist/runtime/domains/auto-form/components/Array.vue.d.ts +0 -4
- package/dist/runtime/domains/auto-form/components/Children.d.vue.ts +0 -2
- package/dist/runtime/domains/auto-form/components/Children.vue +0 -5
- package/dist/runtime/domains/auto-form/components/Children.vue.d.ts +0 -2
- package/dist/runtime/domains/auto-form/components/Field.d.vue.ts +0 -2
- package/dist/runtime/domains/auto-form/components/Field.vue +9 -2
- package/dist/runtime/domains/auto-form/components/Field.vue.d.ts +0 -2
- package/dist/runtime/domains/auto-form/components/Layout.d.vue.ts +0 -2
- package/dist/runtime/domains/auto-form/components/Layout.vue +3 -6
- package/dist/runtime/domains/auto-form/components/Layout.vue.d.ts +0 -2
- package/dist/runtime/domains/auto-form/components/Nested.d.vue.ts +0 -2
- package/dist/runtime/domains/auto-form/components/Nested.vue +5 -9
- package/dist/runtime/domains/auto-form/components/Nested.vue.d.ts +0 -2
- package/dist/runtime/domains/auto-form/controls.d.ts +5 -572
- package/dist/runtime/domains/auto-form/controls.js +7 -20
- package/dist/runtime/domains/auto-form/fields.d.ts +21 -4
- package/dist/runtime/domains/auto-form/fields.js +52 -40
- package/dist/runtime/domains/auto-form/provider.d.ts +15 -6
- package/dist/runtime/domains/auto-form/provider.js +24 -10
- package/dist/runtime/domains/auto-form/schema.d.ts +9 -4
- package/dist/runtime/domains/auto-form/schema.js +91 -50
- package/dist/runtime/domains/auto-form/search-query.d.ts +10 -0
- package/dist/runtime/domains/auto-form/search-query.js +57 -0
- package/dist/runtime/domains/auto-form/useAutoFormCore.d.ts +62 -0
- package/dist/runtime/domains/auto-form/useAutoFormCore.js +108 -0
- package/dist/runtime/domains/auto-form/useSearchQuerySync.d.ts +11 -0
- package/dist/runtime/domains/auto-form/useSearchQuerySync.js +64 -0
- package/dist/runtime/domains/data-table/columns/constants.d.ts +2 -0
- package/dist/runtime/domains/data-table/columns/constants.js +1 -1
- package/dist/runtime/domains/data-table/columns/resolve-columns.d.ts +2 -1
- package/dist/runtime/domains/data-table/columns/resolve-columns.js +3 -2
- package/dist/runtime/domains/data-table/columns/resolve-data-column.d.ts +7 -2
- package/dist/runtime/domains/data-table/columns/resolve-data-column.js +10 -5
- package/dist/runtime/domains/data-table/columns/resolve-special-columns.js +14 -8
- package/dist/runtime/domains/data-table/components/ColumnSettings.d.vue.ts +20 -0
- package/dist/runtime/domains/data-table/components/ColumnSettings.vue +63 -0
- package/dist/runtime/domains/data-table/components/ColumnSettings.vue.d.ts +20 -0
- package/dist/runtime/domains/data-table/components/Pagination.d.vue.ts +2 -8
- package/dist/runtime/domains/data-table/components/Pagination.vue +34 -36
- package/dist/runtime/domains/data-table/components/Pagination.vue.d.ts +2 -8
- package/dist/runtime/domains/data-table/export.d.ts +23 -0
- package/dist/runtime/domains/data-table/export.js +43 -0
- package/dist/runtime/domains/data-table/load-more.d.ts +8 -0
- package/dist/runtime/domains/data-table/load-more.js +14 -0
- package/dist/runtime/domains/data-table/pagination.d.ts +29 -0
- package/dist/runtime/domains/data-table/pagination.js +42 -0
- package/dist/runtime/domains/data-table/persist.d.ts +12 -0
- package/dist/runtime/domains/data-table/persist.js +41 -0
- package/dist/runtime/domains/data-table/state/keys.d.ts +11 -0
- package/dist/runtime/domains/data-table/state/keys.js +44 -0
- package/dist/runtime/domains/data-table/state/models.d.ts +5 -0
- package/dist/runtime/domains/data-table/state/models.js +38 -0
- package/dist/runtime/domains/data-table/tree-layout.d.ts +13 -0
- package/dist/runtime/domains/data-table/tree-layout.js +30 -0
- package/dist/runtime/domains/theme/theme-color.d.ts +3 -0
- package/dist/runtime/domains/theme/theme-color.js +16 -0
- package/dist/runtime/domains/theme/theme-fouc.d.ts +5 -0
- package/dist/runtime/domains/theme/theme-fouc.js +43 -0
- package/dist/runtime/domains/tree/components/TreeToolbar.d.vue.ts +7 -5
- package/dist/runtime/domains/tree/components/TreeToolbar.vue +6 -4
- package/dist/runtime/domains/tree/components/TreeToolbar.vue.d.ts +7 -5
- package/dist/runtime/domains/tree/tree-disabled.d.ts +5 -0
- package/dist/runtime/domains/tree/tree-disabled.js +15 -0
- package/dist/runtime/domains/tree/tree-lazy.d.ts +8 -0
- package/dist/runtime/domains/tree/tree-lazy.js +19 -1
- package/dist/runtime/domains/tree/tree-search.d.ts +3 -1
- package/dist/runtime/domains/tree/tree-search.js +4 -0
- package/dist/runtime/domains/tree/useTreeLazy.d.ts +22 -0
- package/dist/runtime/domains/tree/useTreeLazy.js +57 -0
- package/dist/runtime/domains/tree/useTreeSearch.d.ts +27 -0
- package/dist/runtime/domains/tree/useTreeSearch.js +59 -0
- package/dist/runtime/domains/tree/useTreeSelection.d.ts +31 -0
- package/dist/runtime/domains/tree/useTreeSelection.js +89 -0
- package/dist/runtime/domains/zod/apply.d.ts +23 -0
- package/dist/runtime/domains/zod/apply.js +26 -0
- package/dist/runtime/domains/zod/error-map.d.ts +13 -0
- package/dist/runtime/domains/zod/error-map.js +19 -0
- package/dist/runtime/domains/zod/locale-map.d.ts +5 -0
- package/dist/runtime/domains/zod/locale-map.js +17 -0
- package/dist/runtime/domains/zod/sync.d.ts +12 -0
- package/dist/runtime/domains/zod/sync.js +30 -0
- package/dist/runtime/locale/en.d.ts +74 -0
- package/dist/runtime/locale/en.js +73 -0
- package/dist/runtime/locale/index.d.ts +8 -0
- package/dist/runtime/locale/index.js +15 -0
- package/dist/runtime/locale/zh_cn.d.ts +74 -0
- package/dist/runtime/locale/zh_cn.js +73 -0
- package/dist/runtime/plugins/api.factory.js +5 -22
- package/dist/runtime/plugins/theme.js +4 -42
- package/dist/runtime/plugins/zod.d.ts +2 -0
- package/dist/runtime/plugins/zod.js +16 -0
- package/dist/runtime/types/api/config.d.ts +12 -0
- package/dist/runtime/types/api/fetch.d.ts +3 -16
- package/dist/runtime/types/api/index.d.ts +1 -1
- package/dist/runtime/types/api/response.d.ts +33 -19
- package/dist/runtime/types/api/stream.d.ts +2 -3
- package/dist/runtime/types/api/transfer.d.ts +3 -7
- package/dist/runtime/types/auto-form/base.d.ts +9 -1
- package/dist/runtime/types/auto-form/component.d.ts +31 -3
- package/dist/runtime/types/auto-form/fields.d.ts +15 -1
- package/dist/runtime/types/auto-form/index.d.ts +3 -3
- package/dist/runtime/types/auto-form/search-form.d.ts +26 -12
- package/dist/runtime/types/auto-form/zod-factory.d.ts +2 -2
- package/dist/runtime/types/components/date-picker.d.ts +14 -3
- package/dist/runtime/types/components/index.d.ts +1 -6
- package/dist/runtime/types/components/message-box.d.ts +5 -18
- package/dist/runtime/types/components/tree.d.ts +17 -14
- package/dist/runtime/types/data-table/columns.d.ts +6 -14
- package/dist/runtime/types/data-table/component.d.ts +42 -1
- package/dist/runtime/types/data-table/index.d.ts +1 -1
- package/dist/runtime/types/data-table/pagination.d.ts +7 -8
- package/dist/runtime/types/index.d.ts +2 -0
- package/dist/runtime/types/locale.d.ts +82 -0
- package/dist/runtime/types/shared.d.ts +13 -0
- package/dist/runtime/types/zod-config.d.ts +38 -0
- package/dist/runtime/types/zod.d.ts +9 -1
- package/dist/runtime/utils/date/convert.d.ts +29 -0
- package/dist/runtime/utils/date/convert.js +93 -0
- package/dist/runtime/utils/date/guards.d.ts +10 -0
- package/dist/runtime/utils/date/guards.js +18 -0
- package/dist/runtime/utils/extend-theme.js +2 -1
- package/dist/runtime/utils/form-control.d.ts +0 -12
- package/dist/runtime/utils/form-control.js +3 -39
- package/dist/runtime/utils/interpolate.d.ts +2 -0
- package/dist/runtime/utils/interpolate.js +4 -0
- package/dist/runtime/utils/theme-defaults.d.ts +10 -0
- package/dist/runtime/utils/theme-defaults.js +9 -0
- package/dist/runtime/utils/tree-selection.d.ts +2 -15
- package/dist/runtime/utils/tv.d.ts +1 -1
- package/dist/runtime/vue/plugins/zod.d.ts +7 -0
- package/dist/runtime/vue/plugins/zod.js +12 -0
- package/dist/shared/{nuxt.C7xx2FPO.mjs → nuxt.CbmfnBRt.mjs} +92 -236
- package/dist/unplugin.d.mts +3 -2
- package/dist/unplugin.mjs +22 -22
- package/dist/vite.d.mts +1 -0
- package/dist/vite.mjs +2 -1
- package/package.json +40 -34
- package/vue-plugin.d.ts +7 -1
- package/dist/runtime/components/ColorChooser.d.vue.ts +0 -36
- package/dist/runtime/components/ColorChooser.vue +0 -328
- package/dist/runtime/components/ColorChooser.vue.d.ts +0 -36
- package/dist/runtime/components/PillGroup.d.vue.ts +0 -33
- package/dist/runtime/components/PillGroup.vue +0 -291
- package/dist/runtime/components/PillGroup.vue.d.ts +0 -33
- package/dist/runtime/components/Popconfirm.d.vue.ts +0 -30
- package/dist/runtime/components/Popconfirm.vue +0 -143
- package/dist/runtime/components/Popconfirm.vue.d.ts +0 -30
- package/dist/runtime/components/SlideVerify.d.vue.ts +0 -41
- package/dist/runtime/components/SlideVerify.vue +0 -174
- package/dist/runtime/components/SlideVerify.vue.d.ts +0 -41
- package/dist/runtime/components/input/AsPhoneNumberInput.d.vue.ts +0 -32
- package/dist/runtime/components/input/AsPhoneNumberInput.vue +0 -48
- package/dist/runtime/components/input/AsPhoneNumberInput.vue.d.ts +0 -32
- package/dist/runtime/components/input/WithCharacterLimit.d.vue.ts +0 -32
- package/dist/runtime/components/input/WithCharacterLimit.vue +0 -54
- package/dist/runtime/components/input/WithCharacterLimit.vue.d.ts +0 -32
- package/dist/runtime/components/input/WithClear.d.vue.ts +0 -33
- package/dist/runtime/components/input/WithClear.vue +0 -60
- package/dist/runtime/components/input/WithClear.vue.d.ts +0 -33
- package/dist/runtime/components/input/WithCopy.d.vue.ts +0 -33
- package/dist/runtime/components/input/WithCopy.vue +0 -66
- package/dist/runtime/components/input/WithCopy.vue.d.ts +0 -33
- package/dist/runtime/components/input/WithFloatingLabel.d.vue.ts +0 -33
- package/dist/runtime/components/input/WithFloatingLabel.vue +0 -75
- package/dist/runtime/components/input/WithFloatingLabel.vue.d.ts +0 -33
- package/dist/runtime/components/input/WithPasswordToggle.d.vue.ts +0 -32
- package/dist/runtime/components/input/WithPasswordToggle.vue +0 -61
- package/dist/runtime/components/input/WithPasswordToggle.vue.d.ts +0 -32
- package/dist/runtime/domains/api/interceptors/compose.d.ts +0 -24
- package/dist/runtime/domains/api/interceptors/compose.js +0 -18
- package/dist/runtime/domains/api/interceptors/error.d.ts +0 -13
- package/dist/runtime/domains/api/interceptors/error.js +0 -49
- package/dist/runtime/domains/api/transfer.d.ts +0 -69
- package/dist/runtime/domains/api/transfer.js +0 -82
- package/dist/runtime/types/components/color-chooser.d.ts +0 -109
- package/dist/runtime/types/components/input/as-phone-number-input.d.ts +0 -17
- package/dist/runtime/types/components/input/index.d.ts +0 -6
- package/dist/runtime/types/components/input/index.js +0 -0
- package/dist/runtime/types/components/input/with-character-limit.d.ts +0 -11
- package/dist/runtime/types/components/input/with-character-limit.js +0 -0
- package/dist/runtime/types/components/input/with-clear.d.ts +0 -10
- package/dist/runtime/types/components/input/with-clear.js +0 -0
- package/dist/runtime/types/components/input/with-copy.d.ts +0 -11
- package/dist/runtime/types/components/input/with-copy.js +0 -0
- package/dist/runtime/types/components/input/with-floating-label.d.ts +0 -12
- package/dist/runtime/types/components/input/with-floating-label.js +0 -0
- package/dist/runtime/types/components/input/with-password-toggle.d.ts +0 -7
- package/dist/runtime/types/components/input/with-password-toggle.js +0 -0
- package/dist/runtime/types/components/pill-group.d.ts +0 -103
- package/dist/runtime/types/components/pill-group.js +0 -0
- package/dist/runtime/types/components/popconfirm.d.ts +0 -74
- package/dist/runtime/types/components/popconfirm.js +0 -0
- package/dist/runtime/types/components/slide-verify.d.ts +0 -54
- package/dist/runtime/types/components/slide-verify.js +0 -0
- /package/dist/runtime/types/{components/color-chooser.js → locale.js} +0 -0
- /package/dist/runtime/types/{components/input/as-phone-number-input.js → zod-config.js} +0 -0
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import { CalendarDate } from '@internationalized/date';
|
|
2
1
|
import type { DateValue } from '@internationalized/date';
|
|
3
|
-
import
|
|
4
|
-
|
|
2
|
+
import { isDateRange, isDateValue } from '../utils/date/guards';
|
|
3
|
+
import { convertData, fromDate, fromTimestamp, fromUnixTimestamp, toISO } from '../utils/date/convert';
|
|
4
|
+
import type { ValueFormat } from '../utils/date/convert';
|
|
5
|
+
export type { ValueFormat };
|
|
5
6
|
/**
|
|
6
7
|
* 日期格式化器配置选项
|
|
7
8
|
*/
|
|
8
9
|
export interface DateFormatterOptions {
|
|
9
|
-
/**
|
|
10
|
-
* 语言区域
|
|
11
|
-
* @defaultValue 'zh-CN'
|
|
12
|
-
*/
|
|
10
|
+
/** 语言区域,缺省时跟随 `<UApp :locale>`,组件外调用时为 `'en'` */
|
|
13
11
|
locale?: string;
|
|
14
12
|
/**
|
|
15
13
|
* 日期格式化选项
|
|
@@ -22,14 +20,8 @@ export interface DateFormatterOptions {
|
|
|
22
20
|
*/
|
|
23
21
|
timeZone?: string;
|
|
24
22
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*/
|
|
28
|
-
declare function isDateValue(value: unknown): value is DateValue;
|
|
29
|
-
/**
|
|
30
|
-
* 检查值是否为 DateRange 类型
|
|
31
|
-
*/
|
|
32
|
-
declare function isDateRange(value: unknown): value is DateRange;
|
|
23
|
+
type Nullable<T> = T | undefined | null;
|
|
24
|
+
type WeekdayStyle = 'narrow' | 'short' | 'long';
|
|
33
25
|
/**
|
|
34
26
|
* 日期格式化工具 Composable
|
|
35
27
|
*
|
|
@@ -50,24 +42,26 @@ declare function isDateRange(value: unknown): value is DateRange;
|
|
|
50
42
|
* ```
|
|
51
43
|
*/
|
|
52
44
|
export declare function useDateFormatter(options?: DateFormatterOptions): {
|
|
53
|
-
format: (date: DateValue
|
|
54
|
-
formatRange: (start: DateValue
|
|
55
|
-
formatArray: (dates: DateValue[]
|
|
56
|
-
toISO:
|
|
57
|
-
toDate: (date: DateValue
|
|
58
|
-
toTimestamp: (date: DateValue
|
|
59
|
-
toUnixTimestamp: (date: DateValue
|
|
60
|
-
toFormat: (date: DateValue
|
|
61
|
-
fromISO: (value: string
|
|
62
|
-
fromDate:
|
|
63
|
-
fromTimestamp:
|
|
64
|
-
fromUnixTimestamp:
|
|
65
|
-
fromFormat: (value: unknown,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
45
|
+
format: (date: Nullable<DateValue>) => string;
|
|
46
|
+
formatRange: (start: Nullable<DateValue>, end: Nullable<DateValue>, separator?: string) => string;
|
|
47
|
+
formatArray: (dates: Nullable<DateValue[]>, separator?: string) => string;
|
|
48
|
+
toISO: typeof toISO;
|
|
49
|
+
toDate: (date: Nullable<DateValue>) => Date | null;
|
|
50
|
+
toTimestamp: (date: Nullable<DateValue>) => number | null;
|
|
51
|
+
toUnixTimestamp: (date: Nullable<DateValue>) => number | null;
|
|
52
|
+
toFormat: (date: Nullable<DateValue>, valueFormat: ValueFormat) => unknown;
|
|
53
|
+
fromISO: (value: Nullable<string>) => DateValue | null;
|
|
54
|
+
fromDate: typeof fromDate;
|
|
55
|
+
fromTimestamp: typeof fromTimestamp;
|
|
56
|
+
fromUnixTimestamp: typeof fromUnixTimestamp;
|
|
57
|
+
fromFormat: (value: unknown, valueFormat: ValueFormat) => DateValue | null;
|
|
58
|
+
/** 解析 ISO 8601 字符串,支持日期、日期时间、带时区的日期时间 */
|
|
59
|
+
parse: (value: string) => DateValue | null;
|
|
60
|
+
convertData: typeof convertData;
|
|
61
|
+
/** 按 format 递归转换 single / range / array;date-value 时透传 */
|
|
62
|
+
convertToFormat: <T>(data: T, valueFormat: ValueFormat) => unknown;
|
|
63
|
+
convertFromFormat: <T>(data: T, valueFormat: ValueFormat) => unknown;
|
|
64
|
+
getToday: () => import("@internationalized/date").CalendarDate;
|
|
71
65
|
getNow: () => import("@internationalized/date").ZonedDateTime;
|
|
72
66
|
getStartOfWeek: (date: DateValue) => DateValue;
|
|
73
67
|
getEndOfWeek: (date: DateValue) => DateValue;
|
|
@@ -75,8 +69,9 @@ export declare function useDateFormatter(options?: DateFormatterOptions): {
|
|
|
75
69
|
getEndOfMonth: (date: DateValue) => DateValue;
|
|
76
70
|
getStartOfYear: (date: DateValue) => DateValue;
|
|
77
71
|
getEndOfYear: (date: DateValue) => DateValue;
|
|
72
|
+
/** 星期几数字(0-6,0 为本地化的一周第一天) */
|
|
78
73
|
getDayOfWeek: (date: DateValue) => number;
|
|
79
|
-
getDayOfWeekName: (date: DateValue, style?:
|
|
74
|
+
getDayOfWeekName: (date: DateValue, style?: WeekdayStyle) => string;
|
|
80
75
|
getWeeksInMonth: (date: DateValue) => number;
|
|
81
76
|
isWeekday: (date: DateValue) => boolean;
|
|
82
77
|
isWeekend: (date: DateValue) => boolean;
|
|
@@ -86,8 +81,11 @@ export declare function useDateFormatter(options?: DateFormatterOptions): {
|
|
|
86
81
|
isToday: (date: DateValue) => boolean;
|
|
87
82
|
isDateValue: typeof isDateValue;
|
|
88
83
|
isDateRange: typeof isDateRange;
|
|
84
|
+
/** 批量转换为 ISO 字符串 */
|
|
89
85
|
convertToISO: <T>(data: T) => T;
|
|
86
|
+
/** 批量转换为格式化字符串 */
|
|
90
87
|
convertToFormatted: <T>(data: T) => T;
|
|
88
|
+
/** 批量转换为 Date 对象 */
|
|
91
89
|
convertToDate: <T>(data: T) => T;
|
|
92
90
|
locale: string;
|
|
93
91
|
timeZone: string;
|
|
@@ -1,272 +1,115 @@
|
|
|
1
1
|
import {
|
|
2
|
-
CalendarDate,
|
|
3
2
|
DateFormatter as IntlDateFormatter,
|
|
4
|
-
getLocalTimeZone,
|
|
5
|
-
today,
|
|
6
|
-
now,
|
|
7
|
-
startOfWeek,
|
|
8
|
-
endOfWeek,
|
|
9
|
-
startOfMonth,
|
|
10
3
|
endOfMonth,
|
|
11
|
-
|
|
4
|
+
endOfWeek,
|
|
12
5
|
endOfYear,
|
|
13
6
|
getDayOfWeek,
|
|
7
|
+
getLocalTimeZone,
|
|
14
8
|
getWeeksInMonth,
|
|
15
|
-
isWeekday,
|
|
16
|
-
isWeekend,
|
|
17
9
|
isSameDay,
|
|
18
10
|
isSameMonth,
|
|
19
11
|
isSameYear,
|
|
20
12
|
isToday,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
13
|
+
isWeekday,
|
|
14
|
+
isWeekend,
|
|
15
|
+
now,
|
|
16
|
+
startOfMonth,
|
|
17
|
+
startOfWeek,
|
|
18
|
+
startOfYear,
|
|
19
|
+
today
|
|
25
20
|
} from "@internationalized/date";
|
|
26
|
-
|
|
21
|
+
import { getCurrentInstance } from "vue";
|
|
22
|
+
import { useLocale } from "@nuxt/ui/composables/useLocale";
|
|
23
|
+
import { isDateRange, isDateValue, safe } from "../utils/date/guards.js";
|
|
24
|
+
import {
|
|
25
|
+
convertData,
|
|
26
|
+
convertFromFormat,
|
|
27
|
+
fromDate,
|
|
28
|
+
fromFormat,
|
|
29
|
+
fromTimestamp,
|
|
30
|
+
fromUnixTimestamp,
|
|
31
|
+
parseISO,
|
|
32
|
+
toDate,
|
|
33
|
+
toFormat,
|
|
34
|
+
toISO,
|
|
35
|
+
toTimestamp,
|
|
36
|
+
toUnixTimestamp
|
|
37
|
+
} from "../utils/date/convert.js";
|
|
27
38
|
const DEFAULT_FORMAT_OPTIONS = { dateStyle: "medium" };
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return fn();
|
|
32
|
-
} catch {
|
|
33
|
-
return fallback;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
function isDateValue(value) {
|
|
37
|
-
return value !== null && value !== void 0 && typeof value === "object" && "calendar" in value && "year" in value && "month" in value && "day" in value;
|
|
38
|
-
}
|
|
39
|
-
function isDateRange(value) {
|
|
40
|
-
return value !== null && value !== void 0 && typeof value === "object" && "start" in value && "end" in value;
|
|
39
|
+
function resolveLocale(locale) {
|
|
40
|
+
if (locale) return locale;
|
|
41
|
+
return getCurrentInstance() ? useLocale().code.value : "en";
|
|
41
42
|
}
|
|
42
43
|
export function useDateFormatter(options = {}) {
|
|
43
|
-
const locale = options.locale
|
|
44
|
-
const formatOptions = options.formatOptions ?? DEFAULT_FORMAT_OPTIONS;
|
|
44
|
+
const locale = resolveLocale(options.locale);
|
|
45
45
|
const timeZone = options.timeZone ?? getLocalTimeZone();
|
|
46
|
-
const formatter = new IntlDateFormatter(locale, { ...formatOptions, timeZone });
|
|
46
|
+
const formatter = new IntlDateFormatter(locale, { ...options.formatOptions ?? DEFAULT_FORMAT_OPTIONS, timeZone });
|
|
47
|
+
const weekdayFormatters = /* @__PURE__ */ new Map();
|
|
47
48
|
function format(date) {
|
|
48
|
-
|
|
49
|
-
return safe(() => formatter.format(date.toDate(timeZone)), "");
|
|
49
|
+
return date ? safe(() => formatter.format(date.toDate(timeZone)), "") : "";
|
|
50
50
|
}
|
|
51
51
|
function formatRange(start, end, separator = " - ") {
|
|
52
|
-
|
|
53
|
-
return `${format(start)}${separator}${format(end)}`;
|
|
52
|
+
return start && end ? `${format(start)}${separator}${format(end)}` : "";
|
|
54
53
|
}
|
|
55
54
|
function formatArray(dates, separator = ", ") {
|
|
56
|
-
|
|
57
|
-
return dates.map(format).join(separator);
|
|
58
|
-
}
|
|
59
|
-
function toISO(date) {
|
|
60
|
-
if (!date) return "";
|
|
61
|
-
return safe(() => date.toString(), "");
|
|
62
|
-
}
|
|
63
|
-
function toDate(date) {
|
|
64
|
-
if (!date) return null;
|
|
65
|
-
return safe(() => new Date(Date.UTC(date.year, date.month - 1, date.day)), null);
|
|
66
|
-
}
|
|
67
|
-
function toTimestamp(date) {
|
|
68
|
-
const jsDate = toDate(date);
|
|
69
|
-
return jsDate ? jsDate.getTime() : null;
|
|
70
|
-
}
|
|
71
|
-
function toUnixTimestamp(date) {
|
|
72
|
-
const timestamp = toTimestamp(date);
|
|
73
|
-
return timestamp === null ? null : Math.floor(timestamp / 1e3);
|
|
74
|
-
}
|
|
75
|
-
function toFormat(date, format2) {
|
|
76
|
-
if (!date) return void 0;
|
|
77
|
-
switch (format2) {
|
|
78
|
-
case "date-value":
|
|
79
|
-
return date;
|
|
80
|
-
case "iso":
|
|
81
|
-
return toISO(date);
|
|
82
|
-
case "timestamp":
|
|
83
|
-
return toTimestamp(date);
|
|
84
|
-
case "unix":
|
|
85
|
-
return toUnixTimestamp(date);
|
|
86
|
-
case "date":
|
|
87
|
-
return toDate(date);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
function convertToFormat(data, format2) {
|
|
91
|
-
if (format2 === "date-value") return data;
|
|
92
|
-
return convertData(data, (value) => toFormat(value, format2));
|
|
93
|
-
}
|
|
94
|
-
function fromDate(value) {
|
|
95
|
-
if (!value || Number.isNaN(value.getTime())) return null;
|
|
96
|
-
return safe(
|
|
97
|
-
() => new CalendarDate(value.getUTCFullYear(), value.getUTCMonth() + 1, value.getUTCDate()),
|
|
98
|
-
null
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
function fromTimestamp(value) {
|
|
102
|
-
if (value === null || value === void 0 || Number.isNaN(value)) return null;
|
|
103
|
-
return fromDate(new Date(value));
|
|
104
|
-
}
|
|
105
|
-
function fromUnixTimestamp(value) {
|
|
106
|
-
if (value === null || value === void 0 || Number.isNaN(value)) return null;
|
|
107
|
-
return fromTimestamp(value * 1e3);
|
|
108
|
-
}
|
|
109
|
-
function fromISO(value) {
|
|
110
|
-
if (!value) return null;
|
|
111
|
-
return parse(value);
|
|
112
|
-
}
|
|
113
|
-
function fromFormat(value, format2) {
|
|
114
|
-
if (value === null || value === void 0) return null;
|
|
115
|
-
if (format2 === "date-value") return isDateValue(value) ? value : null;
|
|
116
|
-
if (format2 === "iso") return typeof value === "string" ? fromISO(value) : null;
|
|
117
|
-
if (format2 === "timestamp") return typeof value === "number" ? fromTimestamp(value) : null;
|
|
118
|
-
if (format2 === "unix") return typeof value === "number" ? fromUnixTimestamp(value) : null;
|
|
119
|
-
if (format2 === "date") return value instanceof Date ? fromDate(value) : null;
|
|
120
|
-
return null;
|
|
121
|
-
}
|
|
122
|
-
function convertFromFormat(data, format2) {
|
|
123
|
-
if (data === null || data === void 0) return data;
|
|
124
|
-
if (format2 === "date-value") return data;
|
|
125
|
-
if (Array.isArray(data)) return data.map((item) => convertFromFormat(item, format2));
|
|
126
|
-
if (typeof data === "object" && "start" in data && "end" in data) {
|
|
127
|
-
const range = data;
|
|
128
|
-
return {
|
|
129
|
-
start: range.start === void 0 || range.start === null ? range.start : fromFormat(range.start, format2),
|
|
130
|
-
end: range.end === void 0 || range.end === null ? range.end : fromFormat(range.end, format2)
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
return fromFormat(data, format2);
|
|
134
|
-
}
|
|
135
|
-
function getToday() {
|
|
136
|
-
return today(timeZone);
|
|
137
|
-
}
|
|
138
|
-
function getNow() {
|
|
139
|
-
return now(timeZone);
|
|
140
|
-
}
|
|
141
|
-
function parse(value) {
|
|
142
|
-
try {
|
|
143
|
-
if (!value.includes("T")) return parseDate(value);
|
|
144
|
-
if (value.includes("[")) return parseZonedDateTime(value);
|
|
145
|
-
if (ABSOLUTE_RE.test(value)) return parseAbsolute(value, timeZone);
|
|
146
|
-
return parseDateTime(value);
|
|
147
|
-
} catch {
|
|
148
|
-
return null;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
function getStartOfWeek(date) {
|
|
152
|
-
return startOfWeek(date, locale);
|
|
153
|
-
}
|
|
154
|
-
function getEndOfWeek(date) {
|
|
155
|
-
return endOfWeek(date, locale);
|
|
156
|
-
}
|
|
157
|
-
function getStartOfMonth(date) {
|
|
158
|
-
return startOfMonth(date);
|
|
159
|
-
}
|
|
160
|
-
function getEndOfMonth(date) {
|
|
161
|
-
return endOfMonth(date);
|
|
162
|
-
}
|
|
163
|
-
function getStartOfYear(date) {
|
|
164
|
-
return startOfYear(date);
|
|
165
|
-
}
|
|
166
|
-
function getEndOfYear(date) {
|
|
167
|
-
return endOfYear(date);
|
|
168
|
-
}
|
|
169
|
-
function getDayOfWeekNumber(date) {
|
|
170
|
-
return getDayOfWeek(date, locale);
|
|
55
|
+
return dates?.length ? dates.map(format).join(separator) : "";
|
|
171
56
|
}
|
|
172
57
|
function getDayOfWeekName(date, style = "long") {
|
|
173
58
|
return safe(() => {
|
|
174
|
-
|
|
175
|
-
|
|
59
|
+
let weekday = weekdayFormatters.get(style);
|
|
60
|
+
if (!weekday) {
|
|
61
|
+
weekday = new IntlDateFormatter(locale, { weekday: style, timeZone });
|
|
62
|
+
weekdayFormatters.set(style, weekday);
|
|
63
|
+
}
|
|
64
|
+
return weekday.format(date.toDate(timeZone));
|
|
176
65
|
}, "");
|
|
177
66
|
}
|
|
178
|
-
function getWeeksInMonthNumber(date) {
|
|
179
|
-
return getWeeksInMonth(date, locale);
|
|
180
|
-
}
|
|
181
|
-
function checkIsWeekday(date) {
|
|
182
|
-
return isWeekday(date, locale);
|
|
183
|
-
}
|
|
184
|
-
function checkIsWeekend(date) {
|
|
185
|
-
return isWeekend(date, locale);
|
|
186
|
-
}
|
|
187
|
-
function checkIsSameDay(a, b) {
|
|
188
|
-
return isSameDay(a, b);
|
|
189
|
-
}
|
|
190
|
-
function checkIsSameMonth(a, b) {
|
|
191
|
-
return isSameMonth(a, b);
|
|
192
|
-
}
|
|
193
|
-
function checkIsSameYear(a, b) {
|
|
194
|
-
return isSameYear(a, b);
|
|
195
|
-
}
|
|
196
|
-
function checkIsToday(date) {
|
|
197
|
-
return isToday(date, timeZone);
|
|
198
|
-
}
|
|
199
|
-
function convertData(data, converter) {
|
|
200
|
-
if (!data) return data;
|
|
201
|
-
if (isDateValue(data)) {
|
|
202
|
-
return converter(data);
|
|
203
|
-
}
|
|
204
|
-
if (isDateRange(data)) {
|
|
205
|
-
const range = data;
|
|
206
|
-
return {
|
|
207
|
-
start: range.start ? converter(range.start) : range.start,
|
|
208
|
-
end: range.end ? converter(range.end) : range.end
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
if (Array.isArray(data)) {
|
|
212
|
-
return data.map((item) => convertData(item, converter));
|
|
213
|
-
}
|
|
214
|
-
if (typeof data === "object") {
|
|
215
|
-
return Object.fromEntries(
|
|
216
|
-
Object.entries(data).map(([k, v]) => [k, convertData(v, converter)])
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
return data;
|
|
220
|
-
}
|
|
221
|
-
function convertToISO(data) {
|
|
222
|
-
return convertData(data, toISO);
|
|
223
|
-
}
|
|
224
|
-
function convertToFormatted(data) {
|
|
225
|
-
return convertData(data, format);
|
|
226
|
-
}
|
|
227
|
-
function convertToDate(data) {
|
|
228
|
-
return convertData(data, toDate);
|
|
229
|
-
}
|
|
230
67
|
return {
|
|
231
68
|
format,
|
|
232
69
|
formatRange,
|
|
233
70
|
formatArray,
|
|
234
71
|
toISO,
|
|
235
|
-
toDate,
|
|
236
|
-
toTimestamp,
|
|
237
|
-
toUnixTimestamp,
|
|
238
|
-
toFormat,
|
|
239
|
-
fromISO,
|
|
72
|
+
toDate: (date) => toDate(date, timeZone),
|
|
73
|
+
toTimestamp: (date) => toTimestamp(date, timeZone),
|
|
74
|
+
toUnixTimestamp: (date) => toUnixTimestamp(date, timeZone),
|
|
75
|
+
toFormat: (date, valueFormat) => toFormat(date, valueFormat, timeZone),
|
|
76
|
+
fromISO: (value) => value ? parseISO(value, timeZone) : null,
|
|
240
77
|
fromDate,
|
|
241
78
|
fromTimestamp,
|
|
242
79
|
fromUnixTimestamp,
|
|
243
|
-
fromFormat,
|
|
244
|
-
|
|
80
|
+
fromFormat: (value, valueFormat) => fromFormat(value, valueFormat, timeZone),
|
|
81
|
+
/** 解析 ISO 8601 字符串,支持日期、日期时间、带时区的日期时间 */
|
|
82
|
+
parse: (value) => parseISO(value, timeZone),
|
|
245
83
|
convertData,
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
84
|
+
/** 按 format 递归转换 single / range / array;date-value 时透传 */
|
|
85
|
+
convertToFormat: (data, valueFormat) => valueFormat === "date-value" ? data : convertData(data, (value) => toFormat(value, valueFormat, timeZone)),
|
|
86
|
+
convertFromFormat: (data, valueFormat) => convertFromFormat(data, valueFormat, timeZone),
|
|
87
|
+
getToday: () => today(timeZone),
|
|
88
|
+
getNow: () => now(timeZone),
|
|
89
|
+
getStartOfWeek: (date) => startOfWeek(date, locale),
|
|
90
|
+
getEndOfWeek: (date) => endOfWeek(date, locale),
|
|
91
|
+
getStartOfMonth: (date) => startOfMonth(date),
|
|
92
|
+
getEndOfMonth: (date) => endOfMonth(date),
|
|
93
|
+
getStartOfYear: (date) => startOfYear(date),
|
|
94
|
+
getEndOfYear: (date) => endOfYear(date),
|
|
95
|
+
/** 星期几数字(0-6,0 为本地化的一周第一天) */
|
|
96
|
+
getDayOfWeek: (date) => getDayOfWeek(date, locale),
|
|
257
97
|
getDayOfWeekName,
|
|
258
|
-
getWeeksInMonth:
|
|
259
|
-
isWeekday:
|
|
260
|
-
isWeekend:
|
|
261
|
-
isSameDay:
|
|
262
|
-
isSameMonth:
|
|
263
|
-
isSameYear:
|
|
264
|
-
isToday:
|
|
98
|
+
getWeeksInMonth: (date) => getWeeksInMonth(date, locale),
|
|
99
|
+
isWeekday: (date) => isWeekday(date, locale),
|
|
100
|
+
isWeekend: (date) => isWeekend(date, locale),
|
|
101
|
+
isSameDay: (a, b) => isSameDay(a, b),
|
|
102
|
+
isSameMonth: (a, b) => isSameMonth(a, b),
|
|
103
|
+
isSameYear: (a, b) => isSameYear(a, b),
|
|
104
|
+
isToday: (date) => isToday(date, timeZone),
|
|
265
105
|
isDateValue,
|
|
266
106
|
isDateRange,
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
107
|
+
/** 批量转换为 ISO 字符串 */
|
|
108
|
+
convertToISO: (data) => convertData(data, toISO),
|
|
109
|
+
/** 批量转换为格式化字符串 */
|
|
110
|
+
convertToFormatted: (data) => convertData(data, format),
|
|
111
|
+
/** 批量转换为 Date 对象 */
|
|
112
|
+
convertToDate: (data) => convertData(data, (value) => toDate(value, timeZone)),
|
|
270
113
|
locale,
|
|
271
114
|
timeZone
|
|
272
115
|
};
|
|
@@ -5,22 +5,25 @@ import type { ApiError, TransferRequestOptions, TransferResult, TransferStatus }
|
|
|
5
5
|
* 下载选项(带进度监控)
|
|
6
6
|
*/
|
|
7
7
|
export interface DownloadWithProgressOptions extends TransferRequestOptions {
|
|
8
|
-
/**
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
/**
|
|
9
|
+
* HTTP 方法
|
|
10
|
+
* @defaultValue 'GET'
|
|
11
|
+
*/
|
|
12
|
+
method?: string;
|
|
13
|
+
/** 请求体,对象按 JSON 序列化 */
|
|
11
14
|
body?: RequestInit['body'] | Record<string, unknown>;
|
|
12
15
|
/** 自定义文件名,不提供时从响应头或 URL 提取 */
|
|
13
16
|
filename?: string;
|
|
14
17
|
/** 下载成功回调(文件名) */
|
|
15
18
|
onSuccess?: (filename: string) => void;
|
|
16
19
|
/** 下载失败回调;中止时不触发 */
|
|
17
|
-
onError?: (error: ApiError
|
|
20
|
+
onError?: (error: ApiError) => void;
|
|
18
21
|
}
|
|
19
22
|
/**
|
|
20
23
|
* 带进度监控的文件下载 composable(仅客户端)
|
|
21
24
|
*
|
|
22
|
-
* @description
|
|
23
|
-
* - 后端返回 JSON
|
|
25
|
+
* @description 以 `$api.raw` + 流式响应实现,端点 / 认证 / 业务校验 / toast / hook / 错误归一全部复用:
|
|
26
|
+
* - 后端返回 JSON 时按端点策略判定,错误不会触发文件下载
|
|
24
27
|
* - 后端无 content-length 时 progress 为 null,UI 据此切 indeterminate
|
|
25
28
|
*
|
|
26
29
|
* @example
|
|
@@ -37,10 +40,10 @@ export declare function useDownloadWithProgress<T = Blob>(): {
|
|
|
37
40
|
progress: Ref<number | null>;
|
|
38
41
|
/** 传输状态 */
|
|
39
42
|
status: Ref<TransferStatus>;
|
|
40
|
-
/** 业务数据(默认 Blob;JSON
|
|
43
|
+
/** 业务数据(默认 Blob;JSON 响应时为按策略处理后的业务数据) */
|
|
41
44
|
data: Ref<T | null>;
|
|
42
45
|
/** 错误信息 */
|
|
43
|
-
error: Ref<ApiError |
|
|
46
|
+
error: Ref<ApiError | null>;
|
|
44
47
|
/** 执行下载 */
|
|
45
48
|
download: (url: NitroFetchRequest, options?: DownloadWithProgressOptions) => Promise<TransferResult<T>>;
|
|
46
49
|
/** 中止下载 */
|