@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
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
import { UPagination, USelect } from "#components";
|
|
3
3
|
import { useAppConfig } from "#imports";
|
|
4
4
|
import { computed } from "vue";
|
|
5
|
-
import {
|
|
5
|
+
import { useExtendedTv } from "../../../utils/extend-theme";
|
|
6
|
+
import { useMovkLocale } from "../../../composables/useMovkLocale";
|
|
7
|
+
import { interpolate } from "../../../utils/interpolate";
|
|
6
8
|
import theme from "#build/movk-ui/data-table-pagination";
|
|
7
9
|
const props = defineProps({
|
|
8
10
|
tableApi: { type: Object, required: true },
|
|
@@ -20,52 +22,48 @@ const props = defineProps({
|
|
|
20
22
|
});
|
|
21
23
|
defineSlots();
|
|
22
24
|
const appConfig = useAppConfig();
|
|
23
|
-
const
|
|
24
|
-
() => tv({ extend: tv(theme), ...appConfig.movk?.dataTablePagination || {} })()
|
|
25
|
-
);
|
|
25
|
+
const { t } = useMovkLocale();
|
|
26
26
|
const cfg = computed(() => ({
|
|
27
27
|
pageSizes: props.uiConfig?.pageSizes ?? [],
|
|
28
28
|
showSelectedCount: props.uiConfig?.showSelectedCount ?? true,
|
|
29
29
|
showRowRange: props.uiConfig?.showRowRange ?? true,
|
|
30
30
|
paginationProps: props.uiConfig?.paginationProps,
|
|
31
|
-
pageSizeSelectProps: props.uiConfig?.pageSizeSelectProps
|
|
32
|
-
ui: props.uiConfig?.ui
|
|
33
|
-
}));
|
|
34
|
-
const text = computed(() => ({
|
|
35
|
-
total: props.uiConfig?.text?.total ?? "\u5171",
|
|
36
|
-
item: props.uiConfig?.text?.item ?? "\u6761",
|
|
37
|
-
range: props.uiConfig?.text?.range ?? "\u663E\u793A",
|
|
38
|
-
selected: props.uiConfig?.text?.selected ?? "\u5DF2\u9009",
|
|
39
|
-
page: props.uiConfig?.text?.page ?? "\u9875"
|
|
31
|
+
pageSizeSelectProps: props.uiConfig?.pageSizeSelectProps
|
|
40
32
|
}));
|
|
33
|
+
const { extendUi: ui } = useExtendedTv(
|
|
34
|
+
{ slots: {} },
|
|
35
|
+
theme,
|
|
36
|
+
() => appConfig.movk?.dataTablePagination,
|
|
37
|
+
() => ({
|
|
38
|
+
ui: {
|
|
39
|
+
...props.uiConfig?.ui,
|
|
40
|
+
pageSizeSelect: [props.uiConfig?.ui?.pageSizeSelect, cfg.value.pageSizeSelectProps?.class],
|
|
41
|
+
pagination: [props.uiConfig?.ui?.pagination, cfg.value.paginationProps?.class]
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
);
|
|
45
|
+
function format(key, vars) {
|
|
46
|
+
const custom = props.uiConfig?.text?.[key];
|
|
47
|
+
return custom ? interpolate(custom, vars) : t(`pagination.${key}`, vars);
|
|
48
|
+
}
|
|
41
49
|
const pageSizeOptions = computed(
|
|
42
50
|
() => cfg.value.pageSizes.map((size) => ({
|
|
43
|
-
label:
|
|
51
|
+
label: format("pageSize", { size }),
|
|
44
52
|
value: size
|
|
45
53
|
}))
|
|
46
54
|
);
|
|
47
55
|
const showPageSizeSelect = computed(() => cfg.value.pageSizes.length > 1);
|
|
48
|
-
const pageSizeSelectAttrs = computed(() => ({
|
|
49
|
-
|
|
50
|
-
class: uiCls.value.pageSizeSelect({ class: cfg.value.pageSizeSelectProps?.class })
|
|
51
|
-
}));
|
|
52
|
-
const paginationAttrs = computed(() => ({
|
|
53
|
-
...cfg.value.paginationProps,
|
|
54
|
-
class: uiCls.value.pagination({ class: cfg.value.paginationProps?.class })
|
|
55
|
-
}));
|
|
56
|
+
const pageSizeSelectAttrs = computed(() => ({ ...cfg.value.pageSizeSelectProps, class: ui.value.pageSizeSelect }));
|
|
57
|
+
const paginationAttrs = computed(() => ({ ...cfg.value.paginationProps, class: ui.value.pagination }));
|
|
56
58
|
const summaryText = computed(() => {
|
|
59
|
+
const { from, to, page, pageCount, rowCount } = props;
|
|
57
60
|
if (!props.rowCountKnown) {
|
|
58
|
-
|
|
59
|
-
return `${text.value.range} ${props.from}-${props.to}\uFF0C\u7B2C ${props.page} / ${props.pageCount} ${text.value.page}`;
|
|
60
|
-
}
|
|
61
|
-
if (!cfg.value.showRowRange || props.rowCount === 0) {
|
|
62
|
-
return `${text.value.total} ${props.rowCount} ${text.value.item}`;
|
|
61
|
+
return from === 0 ? format("empty", {}) : format("rangeUnknown", { from, to, page, pageCount });
|
|
63
62
|
}
|
|
64
|
-
|
|
63
|
+
if (!cfg.value.showRowRange || rowCount === 0) return format("total", { total: rowCount });
|
|
64
|
+
return format("range", { from, to, total: rowCount });
|
|
65
65
|
});
|
|
66
|
-
const selectedText = computed(
|
|
67
|
-
() => `${text.value.selected} ${props.selectedCount} ${text.value.item}`
|
|
68
|
-
);
|
|
66
|
+
const selectedText = computed(() => format("selected", { count: props.selectedCount }));
|
|
69
67
|
const summarySlotProps = computed(() => ({
|
|
70
68
|
summaryText: summaryText.value,
|
|
71
69
|
selectedText: selectedText.value,
|
|
@@ -95,20 +93,20 @@ const setPageSize = (value) => props.setPageSize(value);
|
|
|
95
93
|
</script>
|
|
96
94
|
|
|
97
95
|
<template>
|
|
98
|
-
<div :class="
|
|
99
|
-
<div :class="
|
|
96
|
+
<div :class="ui.root" data-slot="root">
|
|
97
|
+
<div :class="ui.summary" data-slot="summary">
|
|
100
98
|
<slot name="summary" v-bind="summarySlotProps">
|
|
101
|
-
<span :class="
|
|
99
|
+
<span :class="ui.summaryText">{{ summaryText }}</span>
|
|
102
100
|
<span
|
|
103
101
|
v-if="cfg.showSelectedCount && selectedCount > 0"
|
|
104
|
-
:class="
|
|
102
|
+
:class="ui.selectedCount"
|
|
105
103
|
>
|
|
106
104
|
{{ selectedText }}
|
|
107
105
|
</span>
|
|
108
106
|
</slot>
|
|
109
107
|
</div>
|
|
110
108
|
|
|
111
|
-
<div :class="
|
|
109
|
+
<div :class="ui.actions" data-slot="actions">
|
|
112
110
|
<slot name="actions" v-bind="actionsSlotProps">
|
|
113
111
|
<USelect
|
|
114
112
|
v-if="showPageSizeSelect"
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import type { TableData } from '@nuxt/ui';
|
|
2
|
-
import type { DataTablePaginationProps, DataTablePaginationSlots
|
|
2
|
+
import type { DataTablePaginationProps, DataTablePaginationSlots } from '../../../types/data-table/pagination';
|
|
3
3
|
declare const __VLS_export: <T extends TableData>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
4
|
-
props: import("vue").PublicProps & __VLS_PrettifyLocal<DataTablePaginationProps<T
|
|
5
|
-
uiConfig?: DataTablePaginationUi & {
|
|
6
|
-
ui?: {
|
|
7
|
-
[x: string]: import("@nuxt/ui").SlotClass;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
}> & (typeof globalThis extends {
|
|
4
|
+
props: import("vue").PublicProps & __VLS_PrettifyLocal<DataTablePaginationProps<T>> & (typeof globalThis extends {
|
|
11
5
|
__VLS_PROPS_FALLBACK: infer P;
|
|
12
6
|
} ? P : {});
|
|
13
7
|
expose: (exposed: {}) => void;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Column, RowData, Table } from '@tanstack/vue-table';
|
|
2
|
+
export type DataTableExportRows = 'all' | 'selected' | 'page';
|
|
3
|
+
export interface DataTableCsvOptions {
|
|
4
|
+
/** 导出的列 id,缺省时为当前可见的数据列(排除选择、序号等内置列) */
|
|
5
|
+
columns?: string[];
|
|
6
|
+
/**
|
|
7
|
+
* 导出范围:全部(过滤排序后、分页前)、已选、当前页
|
|
8
|
+
* @defaultValue 'all'
|
|
9
|
+
*/
|
|
10
|
+
rows?: DataTableExportRows;
|
|
11
|
+
}
|
|
12
|
+
export interface DataTableExportOptions extends DataTableCsvOptions {
|
|
13
|
+
/**
|
|
14
|
+
* 下载文件名
|
|
15
|
+
* @defaultValue 'export.csv'
|
|
16
|
+
*/
|
|
17
|
+
filename?: string;
|
|
18
|
+
}
|
|
19
|
+
/** 按列访问器取值生成 CSV 文本,单元格按 RFC 4180 转义 */
|
|
20
|
+
export declare function buildCsv<T extends RowData>(api: Table<T>, options?: DataTableCsvOptions): string;
|
|
21
|
+
export declare function resolveCsvColumns<T extends RowData>(api: Table<T>, ids?: string[]): Column<T, unknown>[];
|
|
22
|
+
/** 生成 CSV 并触发下载;带 BOM 以便 Excel 正确识别 UTF-8 */
|
|
23
|
+
export declare function downloadCsv<T extends RowData>(api: Table<T>, options?: DataTableExportOptions): void;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const SPECIAL_COLUMN_PREFIX = "__";
|
|
2
|
+
function escapeCell(value) {
|
|
3
|
+
if (value === null || value === void 0) return "";
|
|
4
|
+
const text = typeof value === "object" ? JSON.stringify(value) : String(value);
|
|
5
|
+
return /[",\r\n]/.test(text) ? `"${text.replace(/"/g, '""')}"` : text;
|
|
6
|
+
}
|
|
7
|
+
function headerOf(column) {
|
|
8
|
+
const header = column.columnDef.header;
|
|
9
|
+
return typeof header === "string" ? header : column.id;
|
|
10
|
+
}
|
|
11
|
+
function rowsOf(api, scope) {
|
|
12
|
+
if (scope === "selected") return api.getSelectedRowModel().flatRows;
|
|
13
|
+
if (scope === "page") {
|
|
14
|
+
const pinning = api.getState().rowPinning;
|
|
15
|
+
if (pinning?.top?.length || pinning?.bottom?.length) {
|
|
16
|
+
const top = api.getTopRows();
|
|
17
|
+
const bottom = api.getBottomRows();
|
|
18
|
+
if (top.length || bottom.length) return [...top, ...api.getCenterRows(), ...bottom];
|
|
19
|
+
}
|
|
20
|
+
return api.getRowModel().rows;
|
|
21
|
+
}
|
|
22
|
+
return api.getPrePaginationRowModel().flatRows;
|
|
23
|
+
}
|
|
24
|
+
export function buildCsv(api, options = {}) {
|
|
25
|
+
const columns = resolveCsvColumns(api, options.columns);
|
|
26
|
+
const lines = [
|
|
27
|
+
columns.map((column) => escapeCell(headerOf(column))),
|
|
28
|
+
...rowsOf(api, options.rows ?? "all").map((row) => columns.map((column) => escapeCell(row.getValue(column.id))))
|
|
29
|
+
];
|
|
30
|
+
return lines.map((cells) => cells.join(",")).join("\r\n");
|
|
31
|
+
}
|
|
32
|
+
export function resolveCsvColumns(api, ids) {
|
|
33
|
+
return ids ? ids.map((id) => api.getColumn(id)).filter((column) => !!column) : api.getVisibleLeafColumns().filter((column) => !column.id.startsWith(SPECIAL_COLUMN_PREFIX));
|
|
34
|
+
}
|
|
35
|
+
export function downloadCsv(api, options = {}) {
|
|
36
|
+
const blob = new Blob([`\uFEFF${buildCsv(api, options)}`], { type: "text/csv;charset=utf-8" });
|
|
37
|
+
const url = URL.createObjectURL(blob);
|
|
38
|
+
const link = document.createElement("a");
|
|
39
|
+
link.href = url;
|
|
40
|
+
link.download = options.filename ?? "export.csv";
|
|
41
|
+
link.click();
|
|
42
|
+
URL.revokeObjectURL(url);
|
|
43
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
interface LoadMoreHooks {
|
|
2
|
+
setLoading: (loading: boolean) => void;
|
|
3
|
+
/** 缺省时输出到控制台 */
|
|
4
|
+
onError?: (error: unknown) => void;
|
|
5
|
+
}
|
|
6
|
+
/** 调用 loadMore;返回 Promise 时期间置为 loading,失败交给 onError 并始终复位 loading */
|
|
7
|
+
export declare function runLoadMore(loadMore: (() => void | Promise<void>) | undefined, hooks: LoadMoreHooks): Promise<void>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export async function runLoadMore(loadMore, hooks) {
|
|
2
|
+
if (!loadMore) return;
|
|
3
|
+
try {
|
|
4
|
+
const result = loadMore();
|
|
5
|
+
if (!(result instanceof Promise)) return;
|
|
6
|
+
hooks.setLoading(true);
|
|
7
|
+
await result;
|
|
8
|
+
} catch (error) {
|
|
9
|
+
if (hooks.onError) hooks.onError(error);
|
|
10
|
+
else console.error("[DataTable] loadMore failed:", error);
|
|
11
|
+
} finally {
|
|
12
|
+
hooks.setLoading(false);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { RowData, Table } from '@tanstack/vue-table';
|
|
2
|
+
export interface PaginationViewOptions {
|
|
3
|
+
manual: boolean;
|
|
4
|
+
/** 手动分页时的总行数,未知时为 undefined */
|
|
5
|
+
rowCount?: number;
|
|
6
|
+
/** 手动分页时的总页数,缺省时由 rowCount 推导 */
|
|
7
|
+
pageCount?: number;
|
|
8
|
+
show?: boolean;
|
|
9
|
+
pageSizes?: number[];
|
|
10
|
+
}
|
|
11
|
+
export interface PaginationView<T extends RowData> {
|
|
12
|
+
tableApi: Table<T>;
|
|
13
|
+
pagination: {
|
|
14
|
+
pageIndex: number;
|
|
15
|
+
pageSize: number;
|
|
16
|
+
};
|
|
17
|
+
page: number;
|
|
18
|
+
rowCount: number;
|
|
19
|
+
rowCountKnown: boolean;
|
|
20
|
+
pageCount: number;
|
|
21
|
+
currentPageRowCount: number;
|
|
22
|
+
from: number;
|
|
23
|
+
to: number;
|
|
24
|
+
show: boolean;
|
|
25
|
+
setPage: (page: number) => void;
|
|
26
|
+
setPageSize: (pageSize: unknown) => void;
|
|
27
|
+
}
|
|
28
|
+
/** 由 TanStack 实例与分页配置推导分页栏展示所需的全部数据 */
|
|
29
|
+
export declare function buildPaginationView<T extends RowData>(api: Table<T>, options: PaginationViewOptions): PaginationView<T>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export function buildPaginationView(api, options) {
|
|
2
|
+
const { manual } = options;
|
|
3
|
+
const rowCountKnown = !manual || options.rowCount !== void 0;
|
|
4
|
+
const pagination = api.getState().pagination;
|
|
5
|
+
const pageIndex = pagination?.pageIndex ?? 0;
|
|
6
|
+
const pageSize = pagination?.pageSize ?? 10;
|
|
7
|
+
const currentPageRowCount = api.getRowModel().rows.length;
|
|
8
|
+
const fallbackManualPageCount = options.rowCount !== void 0 ? Math.ceil(Math.max(0, options.rowCount) / pageSize) : api.getPageCount();
|
|
9
|
+
const pageCount = manual ? Math.max(0, options.pageCount ?? fallbackManualPageCount) : api.getPageCount();
|
|
10
|
+
const rowCount = rowCountKnown ? manual ? Math.max(0, options.rowCount) : api.getRowCount() : 0;
|
|
11
|
+
const referenceCount = rowCountKnown ? rowCount : pageCount * pageSize;
|
|
12
|
+
const hasRows = referenceCount > 0 && currentPageRowCount > 0;
|
|
13
|
+
const from = hasRows ? pageIndex * pageSize + 1 : 0;
|
|
14
|
+
const to = hasRows ? Math.min(referenceCount, from + currentPageRowCount - 1) : 0;
|
|
15
|
+
const show = options.show ?? (pageCount > 1 || (options.pageSizes?.length ?? 0) > 1);
|
|
16
|
+
const setPage = (value) => {
|
|
17
|
+
const nextPage = Math.floor(Number(value));
|
|
18
|
+
if (!Number.isFinite(nextPage) || nextPage < 1) return;
|
|
19
|
+
const nextIndex = Math.min(Math.max(1, pageCount), nextPage) - 1;
|
|
20
|
+
api.setPagination((prev) => ({ ...prev, pageIndex: nextIndex }));
|
|
21
|
+
};
|
|
22
|
+
const setPageSize = (value) => {
|
|
23
|
+
if (value === "" || value == null) return;
|
|
24
|
+
const nextPageSize = Math.floor(Number(value));
|
|
25
|
+
if (!Number.isFinite(nextPageSize) || nextPageSize <= 0) return;
|
|
26
|
+
api.setPagination((prev) => ({ ...prev, pageSize: nextPageSize }));
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
tableApi: api,
|
|
30
|
+
pagination: { pageIndex, pageSize },
|
|
31
|
+
page: pageIndex + 1,
|
|
32
|
+
rowCount,
|
|
33
|
+
rowCountKnown,
|
|
34
|
+
pageCount,
|
|
35
|
+
currentPageRowCount,
|
|
36
|
+
from,
|
|
37
|
+
to,
|
|
38
|
+
show,
|
|
39
|
+
setPage,
|
|
40
|
+
setPageSize
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { WritableComputedRef } from 'vue';
|
|
2
|
+
type PersistSources = Record<string, WritableComputedRef<any>>;
|
|
3
|
+
export declare function readPersistedState(key: string): Record<string, unknown> | undefined;
|
|
4
|
+
export declare function writePersistedState(key: string, state: Record<string, unknown> | undefined): void;
|
|
5
|
+
/**
|
|
6
|
+
* 挂载后从 localStorage 恢复各项状态,之后随变化写回。
|
|
7
|
+
* 仅在客户端挂载后读取,避免与服务端渲染结果不一致
|
|
8
|
+
*/
|
|
9
|
+
export declare function useTablePersistence(getKey: () => string | undefined, sources: PersistSources): {
|
|
10
|
+
clear: () => void;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { onMounted, watch } from "vue";
|
|
2
|
+
const STORAGE_PREFIX = "movk-data-table:";
|
|
3
|
+
export function readPersistedState(key) {
|
|
4
|
+
try {
|
|
5
|
+
const raw = localStorage.getItem(STORAGE_PREFIX + key);
|
|
6
|
+
const parsed = raw ? JSON.parse(raw) : void 0;
|
|
7
|
+
return parsed && typeof parsed === "object" ? parsed : void 0;
|
|
8
|
+
} catch {
|
|
9
|
+
return void 0;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export function writePersistedState(key, state) {
|
|
13
|
+
try {
|
|
14
|
+
if (state === void 0) localStorage.removeItem(STORAGE_PREFIX + key);
|
|
15
|
+
else localStorage.setItem(STORAGE_PREFIX + key, JSON.stringify(state));
|
|
16
|
+
} catch {
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function useTablePersistence(getKey, sources) {
|
|
20
|
+
onMounted(() => {
|
|
21
|
+
const key = getKey();
|
|
22
|
+
if (!key) return;
|
|
23
|
+
const stored = readPersistedState(key);
|
|
24
|
+
if (stored) {
|
|
25
|
+
for (const [name, source] of Object.entries(sources)) {
|
|
26
|
+
if (stored[name] !== void 0) source.value = stored[name];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
watch(
|
|
30
|
+
() => Object.fromEntries(Object.entries(sources).map(([name, source]) => [name, source.value])),
|
|
31
|
+
(state) => writePersistedState(key, state),
|
|
32
|
+
{ deep: true }
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
clear: () => {
|
|
37
|
+
const key = getKey();
|
|
38
|
+
if (key) writePersistedState(key, void 0);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ExpandedState, RowSelectionState, VisibilityState } from '@tanstack/vue-table';
|
|
2
|
+
export declare function hasEntries(v: unknown): boolean;
|
|
3
|
+
export declare function keysToVisibility(keys: string[], allColumnIds: string[]): VisibilityState;
|
|
4
|
+
export declare function visibilityToKeys(state: VisibilityState, allColumnIds: string[]): string[];
|
|
5
|
+
export declare function keysToVisibilityExclude(excludeKeys: string[], allColumnIds: string[]): VisibilityState;
|
|
6
|
+
export declare function visibilityToExcludeKeys(state: VisibilityState, allColumnIds: string[]): string[];
|
|
7
|
+
export declare function keysToRowSelection(keys: string[]): RowSelectionState;
|
|
8
|
+
export declare function rowSelectionToKeys(state: RowSelectionState): string[];
|
|
9
|
+
export declare function keysToExpanded(keys: string[]): Record<string, boolean>;
|
|
10
|
+
export declare function expandedToKeys(state: ExpandedState): string[];
|
|
11
|
+
export declare function areSameKeys(a: readonly (string | number)[], b: readonly (string | number)[]): boolean;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export function hasEntries(v) {
|
|
2
|
+
return typeof v === "object" && v !== null && Object.keys(v).length > 0;
|
|
3
|
+
}
|
|
4
|
+
export function keysToVisibility(keys, allColumnIds) {
|
|
5
|
+
const set = new Set(keys);
|
|
6
|
+
const state = {};
|
|
7
|
+
for (const id of allColumnIds) state[id] = set.has(id);
|
|
8
|
+
return state;
|
|
9
|
+
}
|
|
10
|
+
export function visibilityToKeys(state, allColumnIds) {
|
|
11
|
+
return allColumnIds.filter((id) => state[id] !== false);
|
|
12
|
+
}
|
|
13
|
+
export function keysToVisibilityExclude(excludeKeys, allColumnIds) {
|
|
14
|
+
const set = new Set(excludeKeys);
|
|
15
|
+
const state = {};
|
|
16
|
+
for (const id of allColumnIds) state[id] = !set.has(id);
|
|
17
|
+
return state;
|
|
18
|
+
}
|
|
19
|
+
export function visibilityToExcludeKeys(state, allColumnIds) {
|
|
20
|
+
return allColumnIds.filter((id) => state[id] === false);
|
|
21
|
+
}
|
|
22
|
+
export function keysToRowSelection(keys) {
|
|
23
|
+
const state = {};
|
|
24
|
+
for (const key of keys) state[key] = true;
|
|
25
|
+
return state;
|
|
26
|
+
}
|
|
27
|
+
export function rowSelectionToKeys(state) {
|
|
28
|
+
return Object.entries(state).filter(([, s]) => s).map(([k]) => k);
|
|
29
|
+
}
|
|
30
|
+
export function keysToExpanded(keys) {
|
|
31
|
+
const state = {};
|
|
32
|
+
for (const key of keys) state[key] = true;
|
|
33
|
+
return state;
|
|
34
|
+
}
|
|
35
|
+
export function expandedToKeys(state) {
|
|
36
|
+
if (state === true) return [];
|
|
37
|
+
return Object.entries(state).filter(([, e]) => e).map(([k]) => k);
|
|
38
|
+
}
|
|
39
|
+
export function areSameKeys(a, b) {
|
|
40
|
+
if (a.length !== b.length) return false;
|
|
41
|
+
const set = new Set(a.map(String));
|
|
42
|
+
for (const key of b) if (!set.has(String(key))) return false;
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Ref, WritableComputedRef } from 'vue';
|
|
2
|
+
/** 未绑定时回退到默认值的可写模型;`syncBack` 为真时在挂载后把默认值回写给父组件 */
|
|
3
|
+
export declare function useEffectiveModel<V>(model: Ref<V | undefined>, getDefault: () => V, syncBack?: (value: V) => boolean, isUnset?: (value: V | undefined) => boolean): WritableComputedRef<V>;
|
|
4
|
+
/** 双向同步 key 数组与 TanStack 记录形式的状态,`updating` 防止回环 */
|
|
5
|
+
export declare function useSyncKeys<R>(keys: Ref<string[] | undefined>, record: Ref<R | undefined>, toRecord: (keys: string[]) => R, toKeys: (record: R) => string[]): void;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { computed, onMounted, watch } from "vue";
|
|
2
|
+
import { areSameKeys } from "./keys.js";
|
|
3
|
+
export function useEffectiveModel(model, getDefault, syncBack, isUnset = (value) => value === void 0) {
|
|
4
|
+
const effective = computed({
|
|
5
|
+
get: () => isUnset(model.value) ? getDefault() : model.value,
|
|
6
|
+
set: (value) => {
|
|
7
|
+
model.value = value;
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
if (syncBack !== void 0) {
|
|
11
|
+
onMounted(() => {
|
|
12
|
+
if (!isUnset(model.value)) return;
|
|
13
|
+
const defaults = getDefault();
|
|
14
|
+
if (syncBack(defaults)) model.value = defaults;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return effective;
|
|
18
|
+
}
|
|
19
|
+
export function useSyncKeys(keys, record, toRecord, toKeys) {
|
|
20
|
+
let updating = false;
|
|
21
|
+
watch(keys, (next) => {
|
|
22
|
+
if (updating) return;
|
|
23
|
+
const current = record.value !== void 0 ? toKeys(record.value) : [];
|
|
24
|
+
if (areSameKeys(current, next ?? [])) return;
|
|
25
|
+
updating = true;
|
|
26
|
+
record.value = toRecord(next ?? []);
|
|
27
|
+
updating = false;
|
|
28
|
+
}, { deep: true });
|
|
29
|
+
watch(record, (next) => {
|
|
30
|
+
if (updating) return;
|
|
31
|
+
if (next === void 0 || keys.value === void 0) return;
|
|
32
|
+
const derived = toKeys(next);
|
|
33
|
+
if (areSameKeys(derived, keys.value ?? [])) return;
|
|
34
|
+
updating = true;
|
|
35
|
+
keys.value = derived;
|
|
36
|
+
updating = false;
|
|
37
|
+
}, { deep: true });
|
|
38
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ColumnSizingState } from '@tanstack/vue-table';
|
|
2
|
+
import type { WritableComputedRef } from 'vue';
|
|
3
|
+
import type { DataTableProps } from '../../types/data-table/component';
|
|
4
|
+
interface ExpandColumnAutoSizeOptions<T> {
|
|
5
|
+
data: () => unknown[];
|
|
6
|
+
childrenKey: () => string | undefined;
|
|
7
|
+
hasExpandColumn: () => boolean;
|
|
8
|
+
indentSize: () => DataTableProps<T>['indentSize'];
|
|
9
|
+
sizing: WritableComputedRef<ColumnSizingState>;
|
|
10
|
+
}
|
|
11
|
+
/** 树模式下按最大缩进深度放宽展开列;用户手动调整过的宽度不覆盖 */
|
|
12
|
+
export declare function useExpandColumnAutoSize<T>(options: ExpandColumnAutoSizeOptions<T>): void;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { computed, watch } from "vue";
|
|
2
|
+
import { Tree } from "@movk/core";
|
|
3
|
+
import { resolveMaxIndentPx } from "./indent.js";
|
|
4
|
+
const EXPAND_DEFAULT_SIZE = 60;
|
|
5
|
+
const EXPAND_BUTTON_SLOT = 60;
|
|
6
|
+
export function useExpandColumnAutoSize(options) {
|
|
7
|
+
const treeMaxDepth = computed(() => {
|
|
8
|
+
const childrenKey = options.childrenKey();
|
|
9
|
+
const data = options.data();
|
|
10
|
+
if (!childrenKey || data.length === 0) return 0;
|
|
11
|
+
return Tree.getStats(data, { children: childrenKey }).depth - 1;
|
|
12
|
+
});
|
|
13
|
+
const expandColumnSize = computed(() => {
|
|
14
|
+
if (!options.childrenKey() || !options.hasExpandColumn()) return null;
|
|
15
|
+
const maxButtonDepth = Math.max(0, treeMaxDepth.value - 1);
|
|
16
|
+
if (maxButtonDepth === 0) return null;
|
|
17
|
+
const indentPx = resolveMaxIndentPx(options.indentSize(), maxButtonDepth);
|
|
18
|
+
return Math.max(EXPAND_DEFAULT_SIZE, EXPAND_BUTTON_SLOT + indentPx * 2);
|
|
19
|
+
});
|
|
20
|
+
let autoExpandSize = null;
|
|
21
|
+
watch(expandColumnSize, (target) => {
|
|
22
|
+
if (target == null) return;
|
|
23
|
+
const state = options.sizing.value;
|
|
24
|
+
const current = state.__expand;
|
|
25
|
+
const canOverride = current == null || current === EXPAND_DEFAULT_SIZE || current === autoExpandSize;
|
|
26
|
+
if (!canOverride || current === target) return;
|
|
27
|
+
options.sizing.value = { ...state, __expand: target };
|
|
28
|
+
autoExpandSize = target;
|
|
29
|
+
}, { immediate: true });
|
|
30
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import colors from "tailwindcss/colors";
|
|
2
|
+
const palettes = colors;
|
|
3
|
+
function resolvePalette(color) {
|
|
4
|
+
const palette = palettes[color];
|
|
5
|
+
return typeof palette === "object" ? palette : void 0;
|
|
6
|
+
}
|
|
7
|
+
export function resolveThemeColor(neutral, mode) {
|
|
8
|
+
if (mode !== "dark") return "white";
|
|
9
|
+
const shades = resolvePalette(neutral) ?? colors.neutral;
|
|
10
|
+
return shades[900];
|
|
11
|
+
}
|
|
12
|
+
export function resolveSwatchColor(color, shade, prefix) {
|
|
13
|
+
const variable = `--${prefix ? `${prefix}-` : ""}color-${color}-${shade}`;
|
|
14
|
+
const fallback = resolvePalette(color === "old-neutral" ? "neutral" : color)?.[shade];
|
|
15
|
+
return fallback ? `var(${variable}, ${fallback})` : `var(${variable})`;
|
|
16
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
function escapeRegExp(value) {
|
|
2
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3
|
+
}
|
|
4
|
+
function shadePattern(key, prefix) {
|
|
5
|
+
const varPrefix = prefix ? escapeRegExp(`${prefix}-`) : "";
|
|
6
|
+
return `(--ui-color-${key}-\\d{2,3}:\\s*var\\(--${varPrefix}color-)[a-z-]+?(-\\d{2,3}\\s*[,)])`;
|
|
7
|
+
}
|
|
8
|
+
export function createColorSwapScript(name, prefix) {
|
|
9
|
+
return `(function () {
|
|
10
|
+
var primary = localStorage.getItem(${JSON.stringify(`${name}-ui-primary`)});
|
|
11
|
+
var neutral = localStorage.getItem(${JSON.stringify(`${name}-ui-neutral`)});
|
|
12
|
+
if (!primary && !neutral) return;
|
|
13
|
+
function resolve(color) {
|
|
14
|
+
if (!color || !/^[a-z-]+$/.test(color)) return null;
|
|
15
|
+
return color === 'neutral' ? 'old-neutral' : color;
|
|
16
|
+
}
|
|
17
|
+
function replace(html, pattern, color) {
|
|
18
|
+
var resolved = resolve(color);
|
|
19
|
+
return resolved ? html.replace(new RegExp(pattern, 'g'), '$1' + resolved + '$2') : html;
|
|
20
|
+
}
|
|
21
|
+
function swap(el) {
|
|
22
|
+
var html = el.innerHTML;
|
|
23
|
+
if (primary !== 'black') html = replace(html, ${JSON.stringify(shadePattern("primary", prefix))}, primary);
|
|
24
|
+
html = replace(html, ${JSON.stringify(shadePattern("neutral", prefix))}, neutral);
|
|
25
|
+
if (html !== el.innerHTML) el.innerHTML = html;
|
|
26
|
+
}
|
|
27
|
+
var el = document.querySelector('style#nuxt-ui-colors');
|
|
28
|
+
if (el) return swap(el);
|
|
29
|
+
var obs = new MutationObserver(function (mutations) {
|
|
30
|
+
for (var i = 0; i < mutations.length; i++) {
|
|
31
|
+
for (var j = 0; j < mutations[i].addedNodes.length; j++) {
|
|
32
|
+
var node = mutations[i].addedNodes[j];
|
|
33
|
+
if (node.id === 'nuxt-ui-colors') {
|
|
34
|
+
swap(node);
|
|
35
|
+
obs.disconnect();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
obs.observe(document.head, { childList: true });
|
|
42
|
+
})();`.replace(/\s+/g, " ");
|
|
43
|
+
}
|
|
@@ -18,12 +18,14 @@ type __VLS_Props = {
|
|
|
18
18
|
search?: string;
|
|
19
19
|
};
|
|
20
20
|
};
|
|
21
|
-
declare
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
} & {
|
|
25
|
-
|
|
21
|
+
declare const __VLS_template: () => {
|
|
22
|
+
__VLS_Slots: {
|
|
23
|
+
leading?: (props: {}) => any;
|
|
24
|
+
} & {
|
|
25
|
+
trailing?: (props: {}) => any;
|
|
26
|
+
};
|
|
26
27
|
};
|
|
28
|
+
type __VLS_Slots = ReturnType<typeof __VLS_template>['__VLS_Slots'];
|
|
27
29
|
declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
28
30
|
clear: () => any;
|
|
29
31
|
"select-all": () => any;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { computed } from "vue";
|
|
3
3
|
import { UButton, UCheckbox, UInput, UTooltip } from "#components";
|
|
4
|
+
import { useMovkLocale } from "../../../composables/useMovkLocale";
|
|
4
5
|
const props = defineProps({
|
|
5
6
|
toolbar: { type: Boolean, required: false },
|
|
6
7
|
searchable: { type: Boolean, required: false },
|
|
@@ -14,11 +15,12 @@ const props = defineProps({
|
|
|
14
15
|
ui: { type: Object, required: true }
|
|
15
16
|
});
|
|
16
17
|
const emit = defineEmits(["update:search", "toggle-expand", "select-all", "clear"]);
|
|
18
|
+
const { t } = useMovkLocale();
|
|
17
19
|
const checkboxLabel = computed(() => {
|
|
18
20
|
const count = props.selectionSummary?.checkedCount ?? 0;
|
|
19
|
-
return count > 0 ?
|
|
21
|
+
return count > 0 ? t("tree.selected", { count }) : t("tree.selectAll");
|
|
20
22
|
});
|
|
21
|
-
const expandTooltip = computed(() => props.expanded ? "
|
|
23
|
+
const expandTooltip = computed(() => props.expanded ? t("tree.collapseAll") : t("tree.expandAll"));
|
|
22
24
|
function onToggleAll(checked) {
|
|
23
25
|
if (checked) emit("select-all");
|
|
24
26
|
else emit("clear");
|
|
@@ -33,7 +35,7 @@ function onToggleAll(checked) {
|
|
|
33
35
|
v-if="searchable"
|
|
34
36
|
:model-value="search"
|
|
35
37
|
icon="i-lucide-search"
|
|
36
|
-
placeholder="
|
|
38
|
+
:placeholder="t('tree.search')"
|
|
37
39
|
:size="size"
|
|
38
40
|
:disabled="disabled"
|
|
39
41
|
:class="ui.search"
|
|
@@ -46,7 +48,7 @@ function onToggleAll(checked) {
|
|
|
46
48
|
variant="link"
|
|
47
49
|
:size="size"
|
|
48
50
|
:disabled="disabled"
|
|
49
|
-
aria-label="
|
|
51
|
+
:aria-label="t('tree.clearSearch')"
|
|
50
52
|
@click="emit('update:search', '')"
|
|
51
53
|
/>
|
|
52
54
|
</template>
|