@movk/nuxt 1.8.3 → 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 +15 -22
- 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 +6 -7
- 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 -14
- package/dist/runtime/domains/api/interceptors/response.js +34 -25
- 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 +1 -1
- package/dist/runtime/domains/api/session.js +1 -1
- 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.DfVF6ZZv.mjs → nuxt.CbmfnBRt.mjs} +82 -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 +39 -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 -26
- package/dist/runtime/domains/api/interceptors/unauthorized.d.ts +0 -12
- package/dist/runtime/domains/api/interceptors/unauthorized.js +0 -34
- package/dist/runtime/domains/api/transfer.d.ts +0 -69
- package/dist/runtime/domains/api/transfer.js +0 -87
- 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,29 +1,32 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { computed, ref, useSlots, watch } from "vue";
|
|
3
3
|
import { reactiveOmit } from "@vueuse/core";
|
|
4
|
-
import { Tree, omitUndefined, splitHighlight
|
|
5
|
-
import { UCheckbox, UIcon, UTree } from "#components";
|
|
4
|
+
import { Tree, omitUndefined, splitHighlight } from "@movk/core";
|
|
5
|
+
import { UButton, UCheckbox, UIcon, UTree } from "#components";
|
|
6
6
|
import { useAppConfig } from "#imports";
|
|
7
7
|
import { useExtendedTv } from "../utils/extend-theme";
|
|
8
|
+
import { useMovkLocale } from "../composables/useMovkLocale";
|
|
8
9
|
import treeTheme from "#build/ui/tree";
|
|
9
10
|
import theme from "#build/movk-ui/tree";
|
|
10
11
|
import { createGetKey, normalizeChildren } from "../domains/tree/resolve-tree";
|
|
11
12
|
import { resolveLeadingIcon } from "../domains/tree/tree-icon";
|
|
12
|
-
import {
|
|
13
|
-
import { isPlaceholder,
|
|
14
|
-
import { collectDisabledKeys } from "../domains/tree/tree-disabled";
|
|
15
|
-
import {
|
|
13
|
+
import { labelOf } from "../domains/tree/tree-search";
|
|
14
|
+
import { isPlaceholder, markLazyPlaceholders, placeholderParentKey } from "../domains/tree/tree-lazy";
|
|
15
|
+
import { applyDisabled, collectDisabledKeys } from "../domains/tree/tree-disabled";
|
|
16
|
+
import { useTreeLazy } from "../domains/tree/useTreeLazy";
|
|
17
|
+
import { useTreeSearch } from "../domains/tree/useTreeSearch";
|
|
18
|
+
import { useTreeSelection } from "../domains/tree/useTreeSelection";
|
|
16
19
|
import { resolveDefaultExpandedKeys } from "../utils/tree-expand";
|
|
17
20
|
import TreeToolbar from "../domains/tree/components/TreeToolbar.vue";
|
|
18
21
|
const props = defineProps({
|
|
19
22
|
items: { type: null, required: false },
|
|
20
23
|
childrenKey: { type: String, required: false, default: "children" },
|
|
21
|
-
labelKey: { type: null, required: false },
|
|
24
|
+
labelKey: { type: null, required: false, default: "label" },
|
|
22
25
|
getKey: { type: Function, required: false },
|
|
23
26
|
defaultExpanded: { type: [Boolean, Number, Function], required: false },
|
|
24
27
|
selectedKeys: { type: Array, required: false },
|
|
25
28
|
multiple: { type: Boolean, required: false },
|
|
26
|
-
strategy: { type: String, required: false },
|
|
29
|
+
strategy: { type: String, required: false, default: "cascade" },
|
|
27
30
|
propagateSelect: { type: Boolean, required: false },
|
|
28
31
|
bubbleSelect: { type: Boolean, required: false },
|
|
29
32
|
size: { type: null, required: false },
|
|
@@ -33,6 +36,8 @@ const props = defineProps({
|
|
|
33
36
|
disabled: { type: Boolean, required: false },
|
|
34
37
|
searchable: { type: Boolean, required: false },
|
|
35
38
|
filter: { type: Function, required: false },
|
|
39
|
+
searchMethod: { type: Function, required: false },
|
|
40
|
+
searchDebounce: { type: Number, required: false, default: 300 },
|
|
36
41
|
highlight: { type: Boolean, required: false, default: true },
|
|
37
42
|
lazy: { type: Boolean, required: false },
|
|
38
43
|
loadChildren: { type: Function, required: false },
|
|
@@ -41,7 +46,7 @@ const props = defineProps({
|
|
|
41
46
|
ui: { type: Object, required: false },
|
|
42
47
|
class: { type: [Array, String, null, Number, Boolean], required: false, skipCheck: true }
|
|
43
48
|
});
|
|
44
|
-
const emit = defineEmits(["update:modelValue", "update:expanded", "update:search", "change"]);
|
|
49
|
+
const emit = defineEmits(["update:modelValue", "update:expanded", "update:search", "loadError", "searchError", "change"]);
|
|
45
50
|
defineSlots();
|
|
46
51
|
defineOptions({ inheritAttrs: false });
|
|
47
52
|
const modelValue = defineModel();
|
|
@@ -50,7 +55,8 @@ const search = defineModel("search", { type: String, ...{ default: "" } });
|
|
|
50
55
|
const expanded = defineModel("expanded", { type: Array, ...{ default: () => [] } });
|
|
51
56
|
const slots = useSlots();
|
|
52
57
|
const appConfig = useAppConfig();
|
|
53
|
-
const
|
|
58
|
+
const { t } = useMovkLocale();
|
|
59
|
+
const labelKey = computed(() => props.labelKey);
|
|
54
60
|
function folderIcon(expanded2) {
|
|
55
61
|
return expanded2 ? props.expandedIcon ?? appConfig.ui?.icons?.folderOpen ?? "i-lucide-folder-open" : props.collapsedIcon ?? appConfig.ui?.icons?.folder ?? "i-lucide-folder";
|
|
56
62
|
}
|
|
@@ -74,73 +80,50 @@ function buildBase(items) {
|
|
|
74
80
|
return props.lazy ? markLazyPlaceholders(normalized, getKey.value, labelKey.value) : normalized;
|
|
75
81
|
}
|
|
76
82
|
const baseItems = ref([]);
|
|
83
|
+
const lazy = useTreeLazy({
|
|
84
|
+
baseItems,
|
|
85
|
+
getKey: () => getKey.value,
|
|
86
|
+
buildBase,
|
|
87
|
+
loadChildren: () => props.lazy ? props.loadChildren : void 0,
|
|
88
|
+
onError: (node, error) => emit("loadError", node, error)
|
|
89
|
+
});
|
|
77
90
|
let initialized = false;
|
|
78
91
|
watch(() => props.items, (items) => {
|
|
79
|
-
baseItems.value =
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
}
|
|
92
|
+
baseItems.value = lazy.rebuild(items ?? []);
|
|
93
|
+
if (initialized || baseItems.value.length === 0) return;
|
|
94
|
+
initialized = true;
|
|
95
|
+
if (expanded.value.length > 0) return;
|
|
96
|
+
const de = props.defaultExpanded;
|
|
97
|
+
expanded.value = de === true || typeof de === "number" || typeof de === "function" ? resolveDefaultExpandedKeys(baseItems.value, de, { getKey: getKey.value }) : Tree.findAll(baseItems.value, ({ node }) => !!node.defaultExpanded).map((n) => getKey.value(n));
|
|
87
98
|
}, { immediate: true });
|
|
88
|
-
const searching
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
...children !== rawChildren ? { children } : null
|
|
101
|
-
};
|
|
102
|
-
});
|
|
103
|
-
return inject(nodes);
|
|
104
|
-
}
|
|
105
|
-
const displayItems = computed(() => {
|
|
106
|
-
const term = search.value;
|
|
107
|
-
const filtered = !searching.value ? baseItems.value : Tree.filter(baseItems.value, ({ node }) => props.filter ? props.filter(node, term) : matchNode(node, labelKey.value, term));
|
|
108
|
-
return applyDisabled(filtered);
|
|
99
|
+
const { term, searching, matchedItems, isEmpty, remote, remoteLoading, remoteError, retry } = useTreeSearch({
|
|
100
|
+
search,
|
|
101
|
+
enabled: () => !!props.searchable && !props.disabled,
|
|
102
|
+
baseItems,
|
|
103
|
+
expanded,
|
|
104
|
+
getKey: () => getKey.value,
|
|
105
|
+
labelKey: () => labelKey.value,
|
|
106
|
+
filter: () => props.filter,
|
|
107
|
+
searchMethod: () => props.searchMethod,
|
|
108
|
+
searchDebounce: () => props.searchDebounce,
|
|
109
|
+
buildBase: (items) => normalizeChildren(items, props.childrenKey),
|
|
110
|
+
onError: (term2, error) => emit("searchError", term2, error)
|
|
109
111
|
});
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
async function onExpandedUpdate(incoming) {
|
|
112
|
+
const remoteItems = computed(() => remote.value ? matchedItems.value : void 0);
|
|
113
|
+
const disabledKeys = computed(() => collectDisabledKeys(
|
|
114
|
+
remoteItems.value ? [...baseItems.value, ...remoteItems.value] : baseItems.value,
|
|
115
|
+
getKey.value
|
|
116
|
+
));
|
|
117
|
+
const displayItems = computed(() => applyDisabled(matchedItems.value, disabledKeys.value, getKey.value));
|
|
118
|
+
function onExpandedUpdate(incoming) {
|
|
118
119
|
if (props.disabled) return;
|
|
119
120
|
const previous = expanded.value;
|
|
120
121
|
const keys = disabledKeys.value.size ? [...incoming.filter((k) => !disabledKeys.value.has(k)), ...previous.filter((k) => disabledKeys.value.has(k))] : incoming;
|
|
121
122
|
expanded.value = keys;
|
|
122
|
-
if (!props.lazy || !props.loadChildren) return;
|
|
123
|
-
for (const key of keys.filter((k) => !previous.includes(k))) {
|
|
124
|
-
if (loadingKeys.value.has(key)) continue;
|
|
125
|
-
const node = Tree.find(baseItems.value, ({ node: node2 }) => getKey.value(node2) === key);
|
|
126
|
-
const child = node?.children?.[0];
|
|
127
|
-
if (!node || !child || !isPlaceholder(child)) continue;
|
|
128
|
-
loadingKeys.value = new Set(loadingKeys.value).add(key);
|
|
129
|
-
try {
|
|
130
|
-
const loaded = buildBase(await props.loadChildren(node));
|
|
131
|
-
baseItems.value = Tree.updateNode(
|
|
132
|
-
baseItems.value,
|
|
133
|
-
key,
|
|
134
|
-
({ node: node2 }) => ({ ...node2, children: loaded.length ? loaded : void 0, isLeaf: loaded.length === 0 }),
|
|
135
|
-
{ id: LAZY_KEY_FIELD }
|
|
136
|
-
);
|
|
137
|
-
} finally {
|
|
138
|
-
const set = new Set(loadingKeys.value);
|
|
139
|
-
set.delete(key);
|
|
140
|
-
loadingKeys.value = set;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
123
|
}
|
|
124
|
+
watch([expanded, baseItems], ([keys]) => {
|
|
125
|
+
if (props.lazy) keys.forEach((key) => lazy.load(key));
|
|
126
|
+
}, { immediate: true });
|
|
144
127
|
const FORWARD_OMIT = /* @__PURE__ */ new Set([
|
|
145
128
|
"items",
|
|
146
129
|
"modelValue",
|
|
@@ -154,6 +137,8 @@ const FORWARD_OMIT = /* @__PURE__ */ new Set([
|
|
|
154
137
|
"search",
|
|
155
138
|
"filter",
|
|
156
139
|
"highlight",
|
|
140
|
+
"searchMethod",
|
|
141
|
+
"searchDebounce",
|
|
157
142
|
"lazy",
|
|
158
143
|
"loadChildren",
|
|
159
144
|
"toolbar",
|
|
@@ -166,7 +151,7 @@ const FORWARD_OMIT = /* @__PURE__ */ new Set([
|
|
|
166
151
|
const forwardProps = reactiveOmit(props, (_value, key) => FORWARD_OMIT.has(key));
|
|
167
152
|
const utreeProps = computed(() => {
|
|
168
153
|
const multiple = props.checkable ? true : props.multiple;
|
|
169
|
-
const cascade =
|
|
154
|
+
const cascade = props.strategy !== "isolated";
|
|
170
155
|
const selectOptions = multiple ? {
|
|
171
156
|
multiple: true,
|
|
172
157
|
propagateSelect: props.propagateSelect || cascade,
|
|
@@ -174,67 +159,23 @@ const utreeProps = computed(() => {
|
|
|
174
159
|
} : { multiple };
|
|
175
160
|
return omitUndefined({ ...forwardProps, ...selectOptions });
|
|
176
161
|
});
|
|
177
|
-
const RESERVED_SLOTS = ["toolbar", "toolbar-leading", "toolbar-trailing", "empty", "loading"];
|
|
178
|
-
const forwardSlots = computed(() => Object.keys(slots).filter((name) => !RESERVED_SLOTS.includes(name)));
|
|
179
|
-
function nodeLabel(node) {
|
|
180
|
-
const value = getPath(node, labelKey.value);
|
|
181
|
-
return value == null ? "" : String(value);
|
|
182
|
-
}
|
|
183
162
|
const isMultiple = computed(() => !!(props.checkable || props.multiple));
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
163
|
+
const selection = useTreeSelection({
|
|
164
|
+
baseItems,
|
|
165
|
+
remoteItems,
|
|
166
|
+
getKey: () => getKey.value,
|
|
167
|
+
disabledKeys,
|
|
168
|
+
strategy: () => props.strategy,
|
|
169
|
+
multiple: () => isMultiple.value,
|
|
170
|
+
disabled: () => !!props.disabled,
|
|
171
|
+
modelValue,
|
|
172
|
+
selectedKeys: selectedKeysState,
|
|
173
|
+
onChange: (payload) => emit("change", payload)
|
|
193
174
|
});
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
const nodes = keys.map((k) => nodesByKey.value.get(k)).filter((n) => !!n);
|
|
199
|
-
return isMultiple.value ? nodes : nodes[0];
|
|
200
|
-
}
|
|
201
|
-
const selectedKeys = computed(
|
|
202
|
-
() => selectedKeysState.value !== void 0 ? selectedKeysState.value : modelToKeys(modelValue.value)
|
|
203
|
-
);
|
|
204
|
-
const effectiveModel = computed(
|
|
205
|
-
() => selectedKeysState.value !== void 0 ? keysToModel(selectedKeysState.value) : modelValue.value
|
|
206
|
-
);
|
|
207
|
-
const treeSelection = computed(
|
|
208
|
-
() => computeTreeSelection(baseItems.value, new Set(selectedKeys.value), {
|
|
209
|
-
getKey: getKey.value,
|
|
210
|
-
strategy: props.strategy ?? "cascade"
|
|
211
|
-
})
|
|
212
|
-
);
|
|
213
|
-
const selectableLeafCount = computed(
|
|
214
|
-
() => Tree.findAll(baseItems.value, ({ node }) => !isPlaceholder(node) && !disabledKeys.value.has(getKey.value(node)) && !(Array.isArray(node.children) && node.children.length > 0)).length
|
|
215
|
-
);
|
|
216
|
-
const selectionSummaryValue = computed(
|
|
217
|
-
() => selectionSummary(treeSelection.value.leaves.length, selectableLeafCount.value)
|
|
218
|
-
);
|
|
219
|
-
function setModel(value) {
|
|
220
|
-
modelValue.value = value;
|
|
221
|
-
const keys = modelToKeys(value);
|
|
222
|
-
if (selectedKeysState.value !== void 0) selectedKeysState.value = keys;
|
|
223
|
-
const selection = computeTreeSelection(baseItems.value, keys, {
|
|
224
|
-
getKey: getKey.value,
|
|
225
|
-
strategy: props.strategy ?? "cascade"
|
|
226
|
-
});
|
|
227
|
-
emit("change", { value, keys, selection });
|
|
228
|
-
}
|
|
229
|
-
function onModelUpdate(value) {
|
|
230
|
-
if (props.disabled) return;
|
|
231
|
-
if (Array.isArray(value)) {
|
|
232
|
-
setModel(value.filter((node) => !node.disabled));
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
if (value && value.disabled) return;
|
|
236
|
-
setModel(value);
|
|
237
|
-
}
|
|
175
|
+
const { effectiveModel, treeSelection, summary: selectionSummaryValue, onModelUpdate, selectAll, clearSelection } = selection;
|
|
176
|
+
const RESERVED_SLOTS = ["toolbar", "toolbar-leading", "toolbar-trailing", "empty", "loading"];
|
|
177
|
+
const forwardSlots = computed(() => Object.keys(slots).filter((name) => !RESERVED_SLOTS.includes(name)));
|
|
178
|
+
const nodeLabel = (node) => labelOf(node, labelKey.value);
|
|
238
179
|
const expandableKeys = computed(
|
|
239
180
|
() => Tree.findAll(baseItems.value, ({ node }) => !!node.children?.length).map((n) => getKey.value(n))
|
|
240
181
|
);
|
|
@@ -257,11 +198,10 @@ function toggleExpand() {
|
|
|
257
198
|
function expandToDepth(depth) {
|
|
258
199
|
expanded.value = resolveDefaultExpandedKeys(baseItems.value, depth, { getKey: getKey.value });
|
|
259
200
|
}
|
|
260
|
-
function
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
setModel(isMultiple.value ? [] : void 0);
|
|
201
|
+
async function reload(key) {
|
|
202
|
+
if (key !== void 0) return lazy.reload(key);
|
|
203
|
+
lazy.clearLoaded();
|
|
204
|
+
baseItems.value = lazy.rebuild(props.items ?? []);
|
|
265
205
|
}
|
|
266
206
|
defineExpose({
|
|
267
207
|
expandAll,
|
|
@@ -269,6 +209,8 @@ defineExpose({
|
|
|
269
209
|
expandToDepth,
|
|
270
210
|
selectAll,
|
|
271
211
|
clearSelection,
|
|
212
|
+
reload,
|
|
213
|
+
getNode: (key) => selection.nodesByKey.value.get(key),
|
|
272
214
|
get treeSelection() {
|
|
273
215
|
return treeSelection.value;
|
|
274
216
|
}
|
|
@@ -315,9 +257,16 @@ defineExpose({
|
|
|
315
257
|
</TreeToolbar>
|
|
316
258
|
</slot>
|
|
317
259
|
|
|
318
|
-
<div v-if="
|
|
260
|
+
<div v-if="remoteLoading" :class="extraUi.empty" role="status">
|
|
261
|
+
{{ t("tree.searchLoading") }}
|
|
262
|
+
</div>
|
|
263
|
+
<div v-else-if="remoteError" :class="extraUi.empty">
|
|
264
|
+
<span role="status">{{ t("tree.searchError") }}</span>
|
|
265
|
+
<UButton :label="t('tree.retry')" color="error" variant="link" size="xs" @click="retry" />
|
|
266
|
+
</div>
|
|
267
|
+
<div v-else-if="isEmpty" :class="extraUi.empty" data-slot="empty">
|
|
319
268
|
<slot name="empty">
|
|
320
|
-
|
|
269
|
+
{{ t("tree.empty") }}
|
|
321
270
|
</slot>
|
|
322
271
|
</div>
|
|
323
272
|
|
|
@@ -355,14 +304,27 @@ defineExpose({
|
|
|
355
304
|
</template>
|
|
356
305
|
|
|
357
306
|
<template v-if="!slots['item-label'] && (props.lazy || searching && props.highlight)" #item-label="{ item }">
|
|
358
|
-
<
|
|
359
|
-
<span :class="extraUi.loading">
|
|
360
|
-
|
|
307
|
+
<template v-if="isPlaceholder(item)">
|
|
308
|
+
<span v-if="lazy.errorKeys.value.has(placeholderParentKey(item))" :class="extraUi.loading">
|
|
309
|
+
{{ t("tree.loadError") }}
|
|
310
|
+
<UButton
|
|
311
|
+
:label="t('tree.retry')"
|
|
312
|
+
color="error"
|
|
313
|
+
variant="link"
|
|
314
|
+
size="xs"
|
|
315
|
+
:padded="false"
|
|
316
|
+
@click.stop="lazy.load(placeholderParentKey(item), { retry: true })"
|
|
317
|
+
/>
|
|
361
318
|
</span>
|
|
362
|
-
|
|
319
|
+
<slot v-else name="loading" :node="item">
|
|
320
|
+
<span :class="extraUi.loading">
|
|
321
|
+
<UIcon name="i-lucide-loader-circle" :class="extraUi.loadingIcon" />{{ t("tree.loading") }}
|
|
322
|
+
</span>
|
|
323
|
+
</slot>
|
|
324
|
+
</template>
|
|
363
325
|
<template v-else-if="searching && props.highlight">
|
|
364
326
|
<span
|
|
365
|
-
v-for="(segment, index) in splitHighlight(nodeLabel(item),
|
|
327
|
+
v-for="(segment, index) in splitHighlight(nodeLabel(item), term)"
|
|
366
328
|
:key="index"
|
|
367
329
|
:class="segment.match ? extraUi.highlight : void 0"
|
|
368
330
|
>{{ segment.text }}</span>
|
|
@@ -18,6 +18,8 @@ declare const __VLS_export: <T extends TreeItem[] = TreeItem[], M extends boolea
|
|
|
18
18
|
selection: import("../types").TreeSelectionResult<T[number]>;
|
|
19
19
|
}) => any) | undefined;
|
|
20
20
|
"onUpdate:modelValue"?: ((value: (M extends true ? T[number][] : T[number]) | undefined) => any) | undefined;
|
|
21
|
+
onLoadError?: ((node: T[number], error: unknown) => any) | undefined;
|
|
22
|
+
onSearchError?: ((term: string, error: unknown) => any) | undefined;
|
|
21
23
|
"onUpdate:expanded"?: ((val: string[]) => any) | undefined;
|
|
22
24
|
"onUpdate:search"?: ((value: string) => any) | undefined;
|
|
23
25
|
"onUpdate:selectedKeys"?: ((value: string[] | undefined) => any) | undefined;
|
|
@@ -31,7 +33,7 @@ declare const __VLS_export: <T extends TreeItem[] = TreeItem[], M extends boolea
|
|
|
31
33
|
value: (M extends true ? T[number][] : T[number]) | undefined;
|
|
32
34
|
keys: string[];
|
|
33
35
|
selection: import("../types").TreeSelectionResult<T[number]>;
|
|
34
|
-
}) => void) & ((evt: "update:modelValue", val: M extends true ? T[number][] : T[number]) => void) & ((evt: "update:expanded", val: string[]) => void) & ((evt: "update:search", value: string) => void)) & (((event: "update:modelValue", value: (M extends true ? T[number][] : T[number]) | undefined) => void) & ((event: "update:expanded", value: string[]) => void) & ((event: "update:search", value: string) => void) & ((event: "update:selectedKeys", value: string[] | undefined) => void));
|
|
36
|
+
}) => void) & ((evt: "update:modelValue", val: M extends true ? T[number][] : T[number]) => void) & ((evt: "loadError", node: T[number], error: unknown) => void) & ((evt: "searchError", term: string, error: unknown) => void) & ((evt: "update:expanded", val: string[]) => void) & ((evt: "update:search", value: string) => void)) & (((event: "update:modelValue", value: (M extends true ? T[number][] : T[number]) | undefined) => void) & ((event: "update:expanded", value: string[]) => void) & ((event: "update:search", value: string) => void) & ((event: "update:selectedKeys", value: string[] | undefined) => void));
|
|
35
37
|
}>) => import("vue").VNode & {
|
|
36
38
|
__ctx?: NonNullable<Awaited<typeof __VLS_setup>>;
|
|
37
39
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { useAppConfig, useColorMode } from "#imports";
|
|
3
3
|
import { useClipboard } from "@vueuse/core";
|
|
4
|
-
import { ref } from "vue";
|
|
4
|
+
import { computed, ref } from "vue";
|
|
5
5
|
import { useTheme } from "../../composables/useTheme";
|
|
6
6
|
import ThemePickerButton from "./ThemePickerButton.vue";
|
|
7
7
|
import theme from "#build/movk-ui/theme-picker";
|
|
@@ -41,6 +41,8 @@ const {
|
|
|
41
41
|
exportConfig,
|
|
42
42
|
resetTheme
|
|
43
43
|
} = useTheme();
|
|
44
|
+
const selectedIcon = computed(() => icons.find((option) => option.value === icon.value)?.icon);
|
|
45
|
+
const colorModePreference = computed(() => colorMode.preference);
|
|
44
46
|
</script>
|
|
45
47
|
|
|
46
48
|
<template>
|
|
@@ -168,7 +170,7 @@ const {
|
|
|
168
170
|
v-model="icon"
|
|
169
171
|
size="sm"
|
|
170
172
|
color="neutral"
|
|
171
|
-
:icon="
|
|
173
|
+
:icon="selectedIcon"
|
|
172
174
|
:items="icons"
|
|
173
175
|
class="w-full ring-default rounded-sm hover:bg-elevated/50 capitalize text-[11px] data-[state=open]:bg-elevated/50"
|
|
174
176
|
:ui="{ item: 'capitalize text-[11px]', trailingIcon: 'group-data-[state=open]:rotate-180 transition-transform duration-200' }"
|
|
@@ -196,7 +198,7 @@ const {
|
|
|
196
198
|
v-for="m in modes"
|
|
197
199
|
:key="m.label"
|
|
198
200
|
v-bind="m"
|
|
199
|
-
:selected="
|
|
201
|
+
:selected="colorModePreference === m.label"
|
|
200
202
|
@click="mode = m.label"
|
|
201
203
|
/>
|
|
202
204
|
</div>
|
|
@@ -3,13 +3,26 @@
|
|
|
3
3
|
</script>
|
|
4
4
|
|
|
5
5
|
<script setup>
|
|
6
|
-
|
|
6
|
+
import { useAppConfig } from "#imports";
|
|
7
|
+
import { computed } from "vue";
|
|
8
|
+
import { resolveSwatchColor } from "../../domains/theme/theme-color";
|
|
9
|
+
const props = defineProps({
|
|
7
10
|
label: { type: String, required: true },
|
|
8
11
|
icon: { type: String, required: false },
|
|
9
12
|
chip: { type: String, required: false },
|
|
10
13
|
selected: { type: Boolean, required: false }
|
|
11
14
|
});
|
|
12
15
|
const slots = defineSlots();
|
|
16
|
+
const appConfig = useAppConfig();
|
|
17
|
+
const chipStyle = computed(() => {
|
|
18
|
+
if (!props.chip) return;
|
|
19
|
+
const ui = appConfig.ui;
|
|
20
|
+
const prefix = ui && "prefix" in ui && typeof ui.prefix === "string" ? ui.prefix : void 0;
|
|
21
|
+
return {
|
|
22
|
+
"--color-light": resolveSwatchColor(props.chip, 500, prefix),
|
|
23
|
+
"--color-dark": resolveSwatchColor(props.chip, 400, prefix)
|
|
24
|
+
};
|
|
25
|
+
});
|
|
13
26
|
</script>
|
|
14
27
|
|
|
15
28
|
<template>
|
|
@@ -26,11 +39,7 @@ const slots = defineSlots();
|
|
|
26
39
|
<slot name="leading">
|
|
27
40
|
<span
|
|
28
41
|
class="inline-block size-2 rounded-full bg-(--color-light) dark:bg-(--color-dark)"
|
|
29
|
-
|
|
30
|
-
:style="{
|
|
31
|
-
'--color-light': `var(--color-${chip}-500)`,
|
|
32
|
-
'--color-dark': `var(--color-${chip}-400)`
|
|
33
|
-
}"
|
|
42
|
+
:style="chipStyle"
|
|
34
43
|
/>
|
|
35
44
|
</slot>
|
|
36
45
|
</template>
|
|
@@ -4,9 +4,9 @@ import type { UseApiFetchOptions, UseApiFetchReturn } from '../types/api';
|
|
|
4
4
|
* API Fetch 组合式函数
|
|
5
5
|
*
|
|
6
6
|
* 基于 Nuxt useFetch 的薄封装,自动注入 $api 实例。
|
|
7
|
-
* 所有核心能力(认证、业务检查、数据解包、Toast
|
|
7
|
+
* 所有核心能力(认证、业务检查、数据解包、Toast、错误归一)由 $api 客户端统一处理。
|
|
8
8
|
*
|
|
9
|
-
* @typeParam T - 业务数据类型(默认已由 $api 自动解包;
|
|
9
|
+
* @typeParam T - 业务数据类型(默认已由 $api 自动解包;unwrap: false 时为原始响应类型)
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
12
|
* ```ts
|
|
@@ -32,16 +32,16 @@ import type { UseApiFetchOptions, UseApiFetchReturn } from '../types/api';
|
|
|
32
32
|
* toast: { successMessage: '加载成功' }
|
|
33
33
|
* })
|
|
34
34
|
*
|
|
35
|
-
* //
|
|
36
|
-
* const { data } = await useApiFetch('/legacy', {
|
|
35
|
+
* // 关闭业务状态码校验(仍按 dataKey 解包,适合 code 字段缺失的场景)
|
|
36
|
+
* const { data } = await useApiFetch('/legacy', { businessCheck: false })
|
|
37
37
|
*
|
|
38
|
-
* //
|
|
39
|
-
* const { data } = await useApiFetch<ApiResponse>('/external', {
|
|
38
|
+
* // 关闭解包,拿原始响应(与 businessCheck 正交)
|
|
39
|
+
* const { data } = await useApiFetch<ApiResponse>('/external', { unwrap: false })
|
|
40
40
|
*
|
|
41
41
|
* // 用户自定义 hooks:与内置拦截器组合(内置先执行),不会覆盖认证/业务校验/解包/Toast
|
|
42
42
|
* const { data } = await useApiFetch('/users', {
|
|
43
43
|
* onResponse({ response }) {
|
|
44
|
-
* // response._data
|
|
44
|
+
* // response._data 已是解包后的业务数据(除非 unwrap 为 false)
|
|
45
45
|
* // 仅业务成功时触发;返回值被 ofetch 忽略,副作用专用
|
|
46
46
|
* console.log('自定义处理:', response._data)
|
|
47
47
|
* }
|
|
@@ -2,34 +2,18 @@ import { computed, toValue } from "vue";
|
|
|
2
2
|
import { useNuxtApp, useFetch } from "#app";
|
|
3
3
|
import { buildApiFetchKey } from "../domains/api/fetch-key.js";
|
|
4
4
|
import { deepToValue } from "../domains/api/deep-to-value.js";
|
|
5
|
-
import { composeHook, getInterceptors } from "../domains/api/interceptors/compose.js";
|
|
6
5
|
export function useApiFetch(url, options = {}) {
|
|
7
6
|
const { $api } = useNuxtApp();
|
|
8
|
-
const {
|
|
9
|
-
endpoint,
|
|
10
|
-
toast,
|
|
11
|
-
skipBusinessCheck,
|
|
12
|
-
skipUnwrap,
|
|
13
|
-
...fetchOptions
|
|
14
|
-
} = options;
|
|
7
|
+
const { endpoint, ...fetchOptions } = options;
|
|
15
8
|
const apiInstance = endpoint ? $api.use(endpoint) : $api;
|
|
16
|
-
const movk = getInterceptors(apiInstance);
|
|
17
|
-
const composedHooks = movk ? {
|
|
18
|
-
onRequest: composeHook(movk.onRequest, fetchOptions.onRequest),
|
|
19
|
-
onResponse: composeHook(movk.onResponse, fetchOptions.onResponse),
|
|
20
|
-
onResponseError: composeHook(movk.onResponseError, fetchOptions.onResponseError)
|
|
21
|
-
} : {};
|
|
22
|
-
const definedHooks = Object.fromEntries(
|
|
23
|
-
Object.entries(composedHooks).filter(([, value]) => value !== void 0)
|
|
24
|
-
);
|
|
25
9
|
const fetchKey = computed(() => {
|
|
26
10
|
const userKey = toValue(fetchOptions.key);
|
|
27
11
|
if (userKey) return userKey;
|
|
28
12
|
return buildApiFetchKey({
|
|
29
13
|
endpoint,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
toast,
|
|
14
|
+
businessCheck: fetchOptions.businessCheck,
|
|
15
|
+
unwrap: fetchOptions.unwrap,
|
|
16
|
+
toast: fetchOptions.toast,
|
|
33
17
|
method: toValue(fetchOptions.method),
|
|
34
18
|
url: typeof url === "function" ? url() : url,
|
|
35
19
|
query: deepToValue(fetchOptions.query),
|
|
@@ -38,9 +22,7 @@ export function useApiFetch(url, options = {}) {
|
|
|
38
22
|
});
|
|
39
23
|
return useFetch(url, {
|
|
40
24
|
...fetchOptions,
|
|
41
|
-
...definedHooks,
|
|
42
25
|
key: fetchKey,
|
|
43
|
-
$fetch: apiInstance
|
|
44
|
-
context: { toast, skipBusinessCheck, skipUnwrap }
|
|
26
|
+
$fetch: apiInstance
|
|
45
27
|
});
|
|
46
28
|
}
|
|
@@ -42,7 +42,7 @@ function createCalendarDateFactory(type = "calendarDate") {
|
|
|
42
42
|
}
|
|
43
43
|
return false;
|
|
44
44
|
},
|
|
45
|
-
{ message: error
|
|
45
|
+
error ? { message: error } : void 0
|
|
46
46
|
);
|
|
47
47
|
const finalType = meta?.type || type;
|
|
48
48
|
return applyMeta(schema, { ...meta || {}, type: finalType });
|
|
@@ -54,7 +54,7 @@ function inputTimeFactory(controlMeta) {
|
|
|
54
54
|
(val) => {
|
|
55
55
|
return val !== null && val !== void 0 && typeof val === "object" && "hour" in val && "minute" in val && typeof val.hour === "number" && typeof val.minute === "number";
|
|
56
56
|
},
|
|
57
|
-
{ message: error
|
|
57
|
+
error ? { message: error } : void 0
|
|
58
58
|
);
|
|
59
59
|
return applyMeta(schema, { ...meta || {}, type: "inputTime" });
|
|
60
60
|
}
|
|
@@ -3,17 +3,17 @@ import type { UseApiFetchOptions, UseApiFetchReturn } from '../types/api';
|
|
|
3
3
|
/**
|
|
4
4
|
* 仅客户端执行的 useApiFetch
|
|
5
5
|
*
|
|
6
|
-
* 设置 `server: false, lazy: true
|
|
7
|
-
* 适合非 SEO
|
|
6
|
+
* 设置 `server: false, lazy: true`:SSR 阶段跳过,客户端水合后自动发起且不阻塞导航。
|
|
7
|
+
* 适合非 SEO 敏感数据;需手动触发时传 `immediate: false` 再调用 `execute()`
|
|
8
8
|
*
|
|
9
9
|
* @typeParam T - 业务数据类型(已由 $api 自动解包)
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
12
|
* ```ts
|
|
13
|
-
* const { data,
|
|
13
|
+
* const { data, status } = useClientApiFetch<User>('/user/preferences')
|
|
14
14
|
*
|
|
15
|
-
* //
|
|
16
|
-
*
|
|
15
|
+
* // 用户操作时才请求
|
|
16
|
+
* const { execute } = useClientApiFetch<User>('/user/export', { immediate: false })
|
|
17
17
|
*
|
|
18
18
|
* // 使用 transform 转换数据(接收已解包的业务数据)
|
|
19
19
|
* const { data } = useClientApiFetch<User[]>('/users', {
|