@movk/nuxt 1.1.2 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nuxt/movk-ui.css +3 -0
- package/README.md +75 -104
- package/dist/module.d.mts +59 -1
- package/dist/module.json +2 -2
- package/dist/module.mjs +136 -56
- package/dist/runtime/components/AutoForm.d.vue.ts +10 -31
- package/dist/runtime/components/AutoForm.vue +114 -148
- package/dist/runtime/components/AutoForm.vue.d.ts +10 -31
- package/dist/runtime/components/ColorChooser.d.vue.ts +20 -17
- package/dist/runtime/components/ColorChooser.vue +305 -31
- package/dist/runtime/components/ColorChooser.vue.d.ts +20 -17
- package/dist/runtime/components/DataTable.d.vue.ts +57 -0
- package/dist/runtime/components/DataTable.vue +584 -0
- package/dist/runtime/components/DataTable.vue.d.ts +57 -0
- package/dist/runtime/components/DatePicker.d.vue.ts +15 -22
- package/dist/runtime/components/DatePicker.vue +173 -65
- package/dist/runtime/components/DatePicker.vue.d.ts +15 -22
- package/dist/runtime/components/MessageBox.d.vue.ts +36 -0
- package/dist/runtime/components/MessageBox.vue +113 -0
- package/dist/runtime/components/MessageBox.vue.d.ts +36 -0
- package/dist/runtime/components/PillGroup.d.vue.ts +33 -0
- package/dist/runtime/components/PillGroup.vue +291 -0
- package/dist/runtime/components/PillGroup.vue.d.ts +33 -0
- package/dist/runtime/components/Popconfirm.d.vue.ts +30 -0
- package/dist/runtime/components/Popconfirm.vue +143 -0
- package/dist/runtime/components/Popconfirm.vue.d.ts +30 -0
- package/dist/runtime/components/SearchForm.d.vue.ts +43 -0
- package/dist/runtime/components/SearchForm.vue +274 -0
- package/dist/runtime/components/SearchForm.vue.d.ts +43 -0
- package/dist/runtime/components/SlideVerify.d.vue.ts +13 -79
- package/dist/runtime/components/SlideVerify.vue +117 -90
- package/dist/runtime/components/SlideVerify.vue.d.ts +13 -79
- package/dist/runtime/components/StarRating.d.vue.ts +25 -82
- package/dist/runtime/components/StarRating.vue +128 -99
- package/dist/runtime/components/StarRating.vue.d.ts +25 -82
- package/dist/runtime/components/input/AsPhoneNumberInput.d.vue.ts +32 -0
- package/dist/runtime/components/input/AsPhoneNumberInput.vue +48 -0
- package/dist/runtime/components/input/AsPhoneNumberInput.vue.d.ts +32 -0
- package/dist/runtime/components/input/WithCharacterLimit.d.vue.ts +13 -7
- package/dist/runtime/components/input/WithCharacterLimit.vue +27 -15
- package/dist/runtime/components/input/WithCharacterLimit.vue.d.ts +13 -7
- package/dist/runtime/components/input/WithClear.d.vue.ts +11 -5
- package/dist/runtime/components/input/WithClear.vue +29 -10
- package/dist/runtime/components/input/WithClear.vue.d.ts +11 -5
- package/dist/runtime/components/input/WithCopy.d.vue.ts +13 -7
- package/dist/runtime/components/input/WithCopy.vue +28 -11
- package/dist/runtime/components/input/WithCopy.vue.d.ts +13 -7
- package/dist/runtime/components/input/WithFloatingLabel.d.vue.ts +33 -0
- package/dist/runtime/components/input/WithFloatingLabel.vue +75 -0
- package/dist/runtime/components/input/WithFloatingLabel.vue.d.ts +33 -0
- package/dist/runtime/components/input/WithPasswordToggle.d.vue.ts +13 -7
- package/dist/runtime/components/input/WithPasswordToggle.vue +27 -10
- package/dist/runtime/components/input/WithPasswordToggle.vue.d.ts +13 -7
- package/dist/runtime/components/theme-picker/ThemePicker.d.vue.ts +8 -1
- package/dist/runtime/components/theme-picker/ThemePicker.vue +37 -28
- package/dist/runtime/components/theme-picker/ThemePicker.vue.d.ts +8 -1
- package/dist/runtime/components/theme-picker/ThemePickerButton.d.vue.ts +5 -6
- package/dist/runtime/components/theme-picker/ThemePickerButton.vue +4 -0
- package/dist/runtime/components/theme-picker/ThemePickerButton.vue.d.ts +5 -6
- package/dist/runtime/composables/index.d.ts +9 -8
- package/dist/runtime/composables/index.js +2 -1
- package/dist/runtime/composables/useApiFetch.d.ts +23 -15
- package/dist/runtime/composables/useApiFetch.js +21 -28
- package/dist/runtime/composables/useAutoForm.d.ts +14 -98
- package/dist/runtime/composables/useAutoForm.js +55 -161
- package/dist/runtime/composables/useClientApiFetch.d.ts +7 -7
- package/dist/runtime/composables/useDateFormatter.d.ts +16 -3
- package/dist/runtime/composables/useDateFormatter.js +89 -30
- package/dist/runtime/composables/useDownloadWithProgress.d.ts +26 -27
- package/dist/runtime/composables/useDownloadWithProgress.js +143 -42
- package/dist/runtime/composables/useLazyApiFetch.d.ts +19 -0
- package/dist/runtime/composables/useLazyApiFetch.js +4 -0
- package/dist/runtime/composables/useMessageBox.d.ts +6 -0
- package/dist/runtime/composables/useMessageBox.js +16 -0
- package/dist/runtime/composables/useTheme.d.ts +21 -8
- package/dist/runtime/composables/useTheme.js +109 -86
- package/dist/runtime/composables/useUploadWithProgress.d.ts +22 -28
- package/dist/runtime/composables/useUploadWithProgress.js +79 -68
- package/dist/runtime/domains/api/auth.d.ts +2 -0
- package/dist/runtime/domains/api/auth.js +31 -0
- package/dist/runtime/domains/api/endpoint-config.d.ts +11 -0
- package/dist/runtime/domains/api/endpoint-config.js +17 -0
- package/dist/runtime/domains/api/errors.d.ts +2 -0
- package/dist/runtime/domains/api/errors.js +10 -0
- package/dist/runtime/domains/api/fetch-key.d.ts +20 -0
- package/dist/runtime/domains/api/fetch-key.js +23 -0
- package/dist/runtime/domains/api/interceptors/error.d.ts +13 -0
- package/dist/runtime/domains/api/interceptors/error.js +49 -0
- package/dist/runtime/domains/api/interceptors/request.d.ts +12 -0
- package/dist/runtime/domains/api/interceptors/request.js +46 -0
- package/dist/runtime/domains/api/interceptors/response.d.ts +17 -0
- package/dist/runtime/domains/api/interceptors/response.js +27 -0
- package/dist/runtime/domains/api/response.d.ts +4 -0
- package/dist/runtime/domains/api/response.js +14 -0
- package/dist/runtime/domains/api/toast.d.ts +15 -0
- package/dist/runtime/domains/api/toast.js +46 -0
- package/dist/runtime/domains/api/transfer.d.ts +69 -0
- package/dist/runtime/domains/api/transfer.js +81 -0
- package/dist/runtime/domains/auto-form/actions.d.ts +2 -0
- package/dist/runtime/domains/auto-form/actions.js +4 -0
- package/dist/runtime/domains/auto-form/components/Array.d.vue.ts +13 -0
- package/dist/runtime/{components/auto-form-renderer/AutoFormRendererArray.vue → domains/auto-form/components/Array.vue} +37 -48
- package/dist/runtime/domains/auto-form/components/Array.vue.d.ts +13 -0
- package/dist/runtime/domains/auto-form/components/Children.d.vue.ts +11 -0
- package/dist/runtime/domains/auto-form/components/Children.vue +50 -0
- package/dist/runtime/domains/auto-form/components/Children.vue.d.ts +11 -0
- package/dist/runtime/domains/auto-form/components/Field.d.vue.ts +11 -0
- package/dist/runtime/domains/auto-form/components/Field.vue +56 -0
- package/dist/runtime/domains/auto-form/components/Field.vue.d.ts +11 -0
- package/dist/runtime/domains/auto-form/components/Layout.d.vue.ts +11 -0
- package/dist/runtime/domains/auto-form/components/Layout.vue +89 -0
- package/dist/runtime/domains/auto-form/components/Layout.vue.d.ts +11 -0
- package/dist/runtime/domains/auto-form/components/Nested.d.vue.ts +11 -0
- package/dist/runtime/domains/auto-form/components/Nested.vue +47 -0
- package/dist/runtime/domains/auto-form/components/Nested.vue.d.ts +11 -0
- package/dist/runtime/{constants/auto-form.d.ts → domains/auto-form/constants.d.ts} +0 -2
- package/dist/runtime/{constants/auto-form.js → domains/auto-form/constants.js} +0 -25
- package/dist/runtime/domains/auto-form/controls.d.ts +41 -0
- package/dist/runtime/domains/auto-form/controls.js +73 -0
- package/dist/runtime/{utils/field-utils.d.ts → domains/auto-form/fields.d.ts} +7 -21
- package/dist/runtime/{utils/field-utils.js → domains/auto-form/fields.js} +19 -4
- package/dist/runtime/domains/auto-form/metadata.d.ts +22 -0
- package/dist/runtime/domains/auto-form/metadata.js +53 -0
- package/dist/runtime/domains/auto-form/provider.d.ts +62 -0
- package/dist/runtime/{internal/useAutoFormProvider.js → domains/auto-form/provider.js} +6 -3
- package/dist/runtime/domains/auto-form/reactive.d.ts +12 -0
- package/dist/runtime/{utils/reactive-utils.js → domains/auto-form/reactive.js} +1 -1
- package/dist/runtime/domains/auto-form/schema.d.ts +7 -0
- package/dist/runtime/{utils/schema-introspector.js → domains/auto-form/schema.js} +12 -10
- package/dist/runtime/domains/data-table/columns/constants.d.ts +50 -0
- package/dist/runtime/domains/data-table/columns/constants.js +19 -0
- package/dist/runtime/domains/data-table/columns/resolve-columns.d.ts +4 -0
- package/dist/runtime/domains/data-table/columns/resolve-columns.js +59 -0
- package/dist/runtime/domains/data-table/columns/resolve-data-column.d.ts +9 -0
- package/dist/runtime/domains/data-table/columns/resolve-data-column.js +164 -0
- package/dist/runtime/domains/data-table/columns/resolve-group-column.d.ts +4 -0
- package/dist/runtime/domains/data-table/columns/resolve-group-column.js +19 -0
- package/dist/runtime/domains/data-table/columns/resolve-special-columns.d.ts +8 -0
- package/dist/runtime/domains/data-table/columns/resolve-special-columns.js +232 -0
- package/dist/runtime/domains/data-table/columns/style.d.ts +11 -0
- package/dist/runtime/domains/data-table/columns/style.js +67 -0
- package/dist/runtime/domains/data-table/columns/utils.d.ts +6 -0
- package/dist/runtime/domains/data-table/columns/utils.js +16 -0
- package/dist/runtime/domains/data-table/components/ActionConfirm.d.vue.ts +10 -0
- package/dist/runtime/domains/data-table/components/ActionConfirm.vue +39 -0
- package/dist/runtime/domains/data-table/components/ActionConfirm.vue.d.ts +10 -0
- package/dist/runtime/domains/data-table/components/ActionsCell.d.vue.ts +11 -0
- package/dist/runtime/domains/data-table/components/ActionsCell.vue +91 -0
- package/dist/runtime/domains/data-table/components/ActionsCell.vue.d.ts +11 -0
- package/dist/runtime/domains/data-table/components/CellTooltip.d.vue.ts +9 -0
- package/dist/runtime/domains/data-table/components/CellTooltip.vue +40 -0
- package/dist/runtime/domains/data-table/components/CellTooltip.vue.d.ts +9 -0
- package/dist/runtime/domains/data-table/components/Pagination.d.vue.ts +26 -0
- package/dist/runtime/domains/data-table/components/Pagination.vue +132 -0
- package/dist/runtime/domains/data-table/components/Pagination.vue.d.ts +26 -0
- package/dist/runtime/domains/data-table/indent.d.ts +8 -0
- package/dist/runtime/domains/data-table/indent.js +19 -0
- package/dist/runtime/domains/data-table/tree-selection.d.ts +9 -0
- package/dist/runtime/domains/data-table/tree-selection.js +76 -0
- package/dist/runtime/{utils/theme.d.ts → domains/theme/theme-icons.d.ts} +0 -1
- package/dist/runtime/index.css +1 -0
- package/dist/runtime/plugins/api.factory.js +28 -171
- package/dist/runtime/plugins/theme.js +72 -70
- package/dist/runtime/types/api/config.d.ts +127 -0
- package/dist/runtime/types/api/fetch.d.ts +50 -0
- package/dist/runtime/types/api/index.d.ts +5 -0
- package/dist/runtime/types/api/module.d.ts +94 -0
- package/dist/runtime/types/api/response.d.ts +62 -0
- package/dist/runtime/types/api/transfer.d.ts +32 -0
- package/dist/runtime/types/api/transfer.js +0 -0
- package/dist/runtime/types/app.config.d.ts +6 -0
- package/dist/runtime/types/auto-form/base.d.ts +26 -0
- package/dist/runtime/types/auto-form/base.js +0 -0
- package/dist/runtime/types/auto-form/component.d.ts +28 -0
- package/dist/runtime/types/auto-form/component.js +0 -0
- package/dist/runtime/types/auto-form/controls.d.ts +45 -0
- package/dist/runtime/types/auto-form/controls.js +0 -0
- package/dist/runtime/types/auto-form/fields.d.ts +68 -0
- package/dist/runtime/types/auto-form/fields.js +0 -0
- package/dist/runtime/types/auto-form/index.d.ts +7 -0
- package/dist/runtime/types/auto-form/index.js +0 -0
- package/dist/runtime/types/auto-form/search-form.d.ts +84 -0
- package/dist/runtime/types/auto-form/search-form.js +0 -0
- package/dist/runtime/types/auto-form/slots.d.ts +85 -0
- package/dist/runtime/types/auto-form/slots.js +0 -0
- package/dist/runtime/types/auto-form/zod-factory.d.ts +127 -0
- package/dist/runtime/types/auto-form/zod-factory.js +0 -0
- package/dist/runtime/types/components/color-chooser.d.ts +109 -0
- package/dist/runtime/types/components/color-chooser.js +0 -0
- package/dist/runtime/types/components/date-picker.d.ts +41 -0
- package/dist/runtime/types/components/date-picker.js +0 -0
- package/dist/runtime/types/components/index.d.ts +8 -0
- package/dist/runtime/types/components/index.js +0 -0
- package/dist/runtime/types/components/input/as-phone-number-input.d.ts +17 -0
- package/dist/runtime/types/components/input/as-phone-number-input.js +0 -0
- package/dist/runtime/types/components/input/index.d.ts +6 -0
- package/dist/runtime/types/components/input/index.js +0 -0
- package/dist/runtime/types/components/input/with-character-limit.d.ts +11 -0
- package/dist/runtime/types/components/input/with-character-limit.js +0 -0
- package/dist/runtime/types/components/input/with-clear.d.ts +10 -0
- package/dist/runtime/types/components/input/with-clear.js +0 -0
- package/dist/runtime/types/components/input/with-copy.d.ts +11 -0
- package/dist/runtime/types/components/input/with-copy.js +0 -0
- package/dist/runtime/types/components/input/with-floating-label.d.ts +12 -0
- package/dist/runtime/types/components/input/with-floating-label.js +0 -0
- package/dist/runtime/types/components/input/with-password-toggle.d.ts +7 -0
- package/dist/runtime/types/components/input/with-password-toggle.js +0 -0
- package/dist/runtime/types/components/message-box.d.ts +69 -0
- package/dist/runtime/types/components/message-box.js +0 -0
- package/dist/runtime/types/components/pill-group.d.ts +103 -0
- package/dist/runtime/types/components/pill-group.js +0 -0
- package/dist/runtime/types/components/popconfirm.d.ts +74 -0
- package/dist/runtime/types/components/popconfirm.js +0 -0
- package/dist/runtime/types/components/slide-verify.d.ts +54 -0
- package/dist/runtime/types/components/slide-verify.js +0 -0
- package/dist/runtime/types/components/star-rating.d.ts +55 -0
- package/dist/runtime/types/components/star-rating.js +0 -0
- package/dist/runtime/types/data-table/columns.d.ts +236 -0
- package/dist/runtime/types/data-table/columns.js +6 -0
- package/dist/runtime/types/data-table/component.d.ts +190 -0
- package/dist/runtime/types/data-table/component.js +0 -0
- package/dist/runtime/types/data-table/contexts.d.ts +44 -0
- package/dist/runtime/types/data-table/contexts.js +0 -0
- package/dist/runtime/types/data-table/index.d.ts +6 -0
- package/dist/runtime/types/data-table/index.js +1 -0
- package/dist/runtime/types/data-table/pagination.d.ts +87 -0
- package/dist/runtime/types/data-table/pagination.js +0 -0
- package/dist/runtime/types/index.d.ts +6 -5
- package/dist/runtime/types/index.js +5 -5
- package/dist/runtime/types/shared.d.ts +5 -0
- package/dist/runtime/types/shared.js +0 -0
- package/dist/runtime/types/zod.d.ts +19 -17
- package/dist/runtime/utils/extend-theme.d.ts +19 -0
- package/dist/runtime/utils/extend-theme.js +44 -0
- package/dist/runtime/utils/form-control.d.ts +33 -0
- package/dist/runtime/utils/form-control.js +54 -0
- package/dist/runtime/utils/meta.d.ts +4 -0
- package/dist/runtime/utils/meta.js +14 -0
- package/dist/runtime/utils/theme-defaults.d.ts +27 -0
- package/dist/runtime/utils/theme-defaults.js +28 -0
- package/dist/runtime/utils/tv.d.ts +1 -0
- package/dist/runtime/utils/tv.js +4 -0
- package/dist/runtime/vue/composables/useSiteConfig.d.ts +13 -0
- package/dist/runtime/vue/composables/useSiteConfig.js +11 -0
- package/dist/runtime/vue/plugins/theme.d.ts +6 -0
- package/dist/runtime/vue/plugins/theme.js +14 -0
- package/dist/runtime/vue/stubs/base.d.ts +2 -0
- package/dist/runtime/vue/stubs/base.js +2 -0
- package/dist/runtime/vue/stubs/inertia.d.ts +2 -0
- package/dist/runtime/vue/stubs/inertia.js +2 -0
- package/dist/runtime/vue/stubs/movk-extra.d.ts +2 -0
- package/dist/runtime/vue/stubs/movk-extra.js +2 -0
- package/dist/runtime/vue/stubs/none.d.ts +2 -0
- package/dist/runtime/vue/stubs/none.js +2 -0
- package/dist/runtime/vue/stubs/vue-router.d.ts +2 -0
- package/dist/runtime/vue/stubs/vue-router.js +2 -0
- package/dist/shared/nuxt.DfBEyjld.mjs +667 -0
- package/dist/types.d.mts +2 -6
- package/dist/unplugin.d.mts +28 -0
- package/dist/unplugin.mjs +292 -0
- package/dist/vite.d.mts +12 -0
- package/dist/vite.mjs +20 -0
- package/package.json +82 -42
- package/vue-plugin.d.ts +5 -0
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererArray.d.vue.ts +0 -20
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererArray.vue.d.ts +0 -20
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererField.d.vue.ts +0 -20
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererField.vue +0 -55
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererField.vue.d.ts +0 -20
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererLayout.d.vue.ts +0 -20
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererLayout.vue +0 -125
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererLayout.vue.d.ts +0 -20
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererNested.d.vue.ts +0 -20
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererNested.vue +0 -105
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererNested.vue.d.ts +0 -20
- package/dist/runtime/composables/useApiAuth.d.ts +0 -47
- package/dist/runtime/composables/useApiAuth.js +0 -66
- package/dist/runtime/internal/useAutoFormProvider.d.ts +0 -50
- package/dist/runtime/schemas/api.d.ts +0 -590
- package/dist/runtime/schemas/api.js +0 -228
- package/dist/runtime/server/api/_movk/session.post.d.ts +0 -10
- package/dist/runtime/server/api/_movk/session.post.js +0 -18
- package/dist/runtime/style.css +0 -1
- package/dist/runtime/types/api.d.ts +0 -218
- package/dist/runtime/types/auth.d.ts +0 -34
- package/dist/runtime/types/auto-form-renderer.d.ts +0 -22
- package/dist/runtime/types/auto-form.d.ts +0 -548
- package/dist/runtime/types/components.d.ts +0 -43
- package/dist/runtime/types/module.d.ts +0 -39
- package/dist/runtime/utils/api-utils.d.ts +0 -79
- package/dist/runtime/utils/api-utils.js +0 -127
- package/dist/runtime/utils/auto-form.d.ts +0 -3
- package/dist/runtime/utils/auto-form.js +0 -18
- package/dist/runtime/utils/reactive-utils.d.ts +0 -30
- package/dist/runtime/utils/schema-introspector.d.ts +0 -13
- /package/dist/runtime/{utils/theme.js → domains/theme/theme-icons.js} +0 -0
- /package/dist/runtime/types/{api.js → api/config.js} +0 -0
- /package/dist/runtime/types/{auto-form-renderer.js → api/fetch.js} +0 -0
- /package/dist/runtime/types/{auto-form.js → api/index.js} +0 -0
- /package/dist/runtime/types/{module.js → api/module.js} +0 -0
- /package/dist/runtime/types/{components.js → api/response.js} +0 -0
|
@@ -1,186 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import { defineNuxtPlugin, navigateTo, useNuxtApp, useUserSession, useRuntimeConfig } from "#imports";
|
|
9
|
-
import defu from "defu";
|
|
10
|
-
function getUserSession() {
|
|
11
|
-
try {
|
|
12
|
-
const nuxtApp = useNuxtApp();
|
|
13
|
-
return nuxtApp.runWithContext(() => useUserSession());
|
|
14
|
-
} catch {
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
function getTokenFromSession(tokenPath) {
|
|
19
|
-
const userSession = getUserSession();
|
|
20
|
-
if (!userSession?.session?.value) return null;
|
|
21
|
-
const sessionData = userSession.session.value;
|
|
22
|
-
return getPath(sessionData, tokenPath) || null;
|
|
23
|
-
}
|
|
24
|
-
function buildAuthHeader(token, config) {
|
|
25
|
-
const tokenType = config.tokenType === "Custom" ? config.customTokenType || "" : config.tokenType || "Bearer";
|
|
26
|
-
return tokenType ? `${tokenType} ${token}` : token;
|
|
27
|
-
}
|
|
28
|
-
async function handleUnauthorized(config) {
|
|
29
|
-
const userSession = getUserSession();
|
|
30
|
-
const unauthorizedConfig = config.unauthorized;
|
|
31
|
-
if (unauthorizedConfig?.clearSession && userSession?.clear) {
|
|
32
|
-
await userSession.clear();
|
|
33
|
-
}
|
|
34
|
-
if (unauthorizedConfig?.redirect) {
|
|
35
|
-
const loginPath = unauthorizedConfig.loginPath || "/login";
|
|
36
|
-
const nuxtApp = useNuxtApp();
|
|
37
|
-
await nuxtApp.runWithContext(() => navigateTo(loginPath));
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
function getApiFetchContext(context) {
|
|
41
|
-
return context.options.context || {};
|
|
42
|
-
}
|
|
43
|
-
function createBuiltinHooks(resolvedConfig, publicConfig) {
|
|
44
|
-
const { auth: authConfig, toast: toastConfig, response: responseConfig } = resolvedConfig;
|
|
45
|
-
return {
|
|
46
|
-
onRequest(context) {
|
|
47
|
-
if (authConfig.enabled) {
|
|
48
|
-
const tokenPath = authConfig.sessionTokenPath || "token";
|
|
49
|
-
const token = getTokenFromSession(tokenPath);
|
|
50
|
-
if (token) {
|
|
51
|
-
const headerName = authConfig.headerName || "Authorization";
|
|
52
|
-
const headerValue = buildAuthHeader(token, authConfig);
|
|
53
|
-
context.options.headers = context.options.headers || new Headers();
|
|
54
|
-
if (context.options.headers instanceof Headers) {
|
|
55
|
-
context.options.headers.set(headerName, headerValue);
|
|
56
|
-
} else {
|
|
57
|
-
context.options.headers[headerName] = headerValue;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
if (publicConfig.debug) {
|
|
62
|
-
console.log(`[Movk API] Request: ${context.options.method || "GET"} ${resolvedConfig.baseURL}${context.request}`);
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
async onRequestError({ error }) {
|
|
66
|
-
if (publicConfig.debug) {
|
|
67
|
-
console.error("[Movk API] Request Error:", error);
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
async onResponse(context) {
|
|
71
|
-
const response = context.response;
|
|
72
|
-
const data = response._data;
|
|
73
|
-
if (publicConfig.debug) {
|
|
74
|
-
console.log("[Movk API] Response:", data);
|
|
75
|
-
}
|
|
76
|
-
if (!import.meta.client) return;
|
|
77
|
-
const { toast, skipBusinessCheck } = getApiFetchContext(context);
|
|
78
|
-
const isSuccess = skipBusinessCheck || isBusinessSuccess(data, responseConfig);
|
|
79
|
-
const message = extractMessage(data, responseConfig);
|
|
80
|
-
if (isSuccess) {
|
|
81
|
-
const successMessage = toast !== false ? toast?.successMessage || message : void 0;
|
|
82
|
-
showToast("success", successMessage, toast, toastConfig);
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
async onResponseError(context) {
|
|
86
|
-
const { response } = context;
|
|
87
|
-
if (response.status === 401) {
|
|
88
|
-
await handleUnauthorized(authConfig);
|
|
89
|
-
}
|
|
90
|
-
if (publicConfig.debug) {
|
|
91
|
-
console.error("[Movk API] Error:", response.status, response._data);
|
|
92
|
-
}
|
|
93
|
-
if (!import.meta.client) return;
|
|
94
|
-
const { toast } = getApiFetchContext(context);
|
|
95
|
-
const data = response._data;
|
|
96
|
-
const message = data ? extractMessage(data, responseConfig) : void 0;
|
|
97
|
-
const errorMessage = toast !== false ? toast?.errorMessage || message || `\u8BF7\u6C42\u5931\u8D25 (${response.status})` : void 0;
|
|
98
|
-
showToast("error", errorMessage, toast, toastConfig);
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
function createApiClient(resolvedConfig, publicConfig, getOrCreateEndpoint) {
|
|
103
|
-
const builtinHooks = createBuiltinHooks(resolvedConfig, publicConfig);
|
|
104
|
-
resolvedConfig.builtinHooks = builtinHooks;
|
|
105
|
-
const $fetchInstance = $fetch.create({
|
|
1
|
+
import { resolveEndpointConfig } from "../domains/api/endpoint-config.js";
|
|
2
|
+
import { createOnRequest } from "../domains/api/interceptors/request.js";
|
|
3
|
+
import { createOnResponse } from "../domains/api/interceptors/response.js";
|
|
4
|
+
import { createOnResponseError } from "../domains/api/interceptors/error.js";
|
|
5
|
+
import { defineNuxtPlugin, useNuxtApp, useRuntimeConfig } from "#imports";
|
|
6
|
+
function createEndpointFetch(resolvedConfig, publicConfig, nuxtApp) {
|
|
7
|
+
return $fetch.create({
|
|
106
8
|
baseURL: resolvedConfig.baseURL,
|
|
107
9
|
headers: resolvedConfig.headers,
|
|
108
|
-
onRequest:
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
onResponseError: builtinHooks.onResponseError
|
|
10
|
+
onRequest: createOnRequest(resolvedConfig, publicConfig, nuxtApp),
|
|
11
|
+
onResponse: createOnResponse(resolvedConfig, publicConfig, nuxtApp),
|
|
12
|
+
onResponseError: createOnResponseError(resolvedConfig, publicConfig, nuxtApp)
|
|
112
13
|
});
|
|
113
|
-
const download = async (url, filename, options = {}) => {
|
|
114
|
-
const { toast, ...fetchOptions } = options;
|
|
115
|
-
const response = await $fetchInstance.raw(url, {
|
|
116
|
-
...fetchOptions,
|
|
117
|
-
method: "GET",
|
|
118
|
-
responseType: "blob",
|
|
119
|
-
context: { toast }
|
|
120
|
-
});
|
|
121
|
-
if (!response._data) {
|
|
122
|
-
throw new Error("\u4E0B\u8F7D\u5931\u8D25: \u672A\u63A5\u6536\u5230\u6570\u636E");
|
|
123
|
-
}
|
|
124
|
-
const finalFilename = filename || extractFilename(response.headers, url.split("/").pop() || "download");
|
|
125
|
-
triggerDownload(response._data, finalFilename);
|
|
126
|
-
if (import.meta.client && toast !== false) {
|
|
127
|
-
const message = extractToastMessage(toast, "success", `\u4E0B\u8F7D\u6210\u529F: ${finalFilename}`);
|
|
128
|
-
showToast("success", message, toast, resolvedConfig.toast);
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
const upload = async (url, file, options = {}) => {
|
|
132
|
-
const { toast, fieldName = "file", ...fetchOptions } = options;
|
|
133
|
-
const formData = file instanceof FormData ? file : (() => {
|
|
134
|
-
const fd = new FormData();
|
|
135
|
-
const files = Array.isArray(file) ? file : [file];
|
|
136
|
-
files.forEach((f) => fd.append(fieldName, f));
|
|
137
|
-
return fd;
|
|
138
|
-
})();
|
|
139
|
-
return $fetchInstance(url, {
|
|
140
|
-
...fetchOptions,
|
|
141
|
-
method: "POST",
|
|
142
|
-
body: formData,
|
|
143
|
-
context: { toast }
|
|
144
|
-
});
|
|
145
|
-
};
|
|
146
|
-
return {
|
|
147
|
-
$fetch: $fetchInstance,
|
|
148
|
-
use: (endpoint) => getOrCreateEndpoint(endpoint),
|
|
149
|
-
download,
|
|
150
|
-
upload,
|
|
151
|
-
getConfig: () => resolvedConfig
|
|
152
|
-
};
|
|
153
14
|
}
|
|
154
15
|
export default defineNuxtPlugin(() => {
|
|
16
|
+
const nuxtApp = useNuxtApp();
|
|
155
17
|
const runtimeConfig = useRuntimeConfig();
|
|
156
18
|
const publicConfig = runtimeConfig.public.movkApi;
|
|
157
|
-
const
|
|
19
|
+
const privateEndpoints = import.meta.server ? runtimeConfig.movkApi?.endpoints : void 0;
|
|
158
20
|
const endpointCache = /* @__PURE__ */ new Map();
|
|
21
|
+
const defaultEndpoint = publicConfig.defaultEndpoint || "default";
|
|
159
22
|
const getOrCreateEndpoint = (endpointName) => {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
if (!endpointConfig) {
|
|
166
|
-
console.warn(`[Movk API] Endpoint "${endpointName}" not found, using default`);
|
|
167
|
-
return getOrCreateEndpoint(publicConfig.defaultEndpoint || "default");
|
|
23
|
+
const cached = endpointCache.get(endpointName);
|
|
24
|
+
if (cached) return cached;
|
|
25
|
+
if (!publicConfig.endpoints?.[endpointName] && endpointName !== defaultEndpoint) {
|
|
26
|
+
console.warn(`[@movk/nuxt] Endpoint "${endpointName}" not found, using default`);
|
|
27
|
+
return getOrCreateEndpoint(defaultEndpoint);
|
|
168
28
|
}
|
|
169
|
-
const
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
};
|
|
177
|
-
const client = createApiClient(resolvedConfig, publicConfig, getOrCreateEndpoint);
|
|
178
|
-
endpointCache.set(endpointName, client);
|
|
179
|
-
return client;
|
|
29
|
+
const resolved = resolveEndpointConfig(publicConfig, endpointName, privateEndpoints);
|
|
30
|
+
const $fetchInstance = createEndpointFetch(resolved, publicConfig, nuxtApp);
|
|
31
|
+
const apiInstance = Object.assign($fetchInstance, {
|
|
32
|
+
use: (endpoint) => getOrCreateEndpoint(endpoint)
|
|
33
|
+
});
|
|
34
|
+
endpointCache.set(endpointName, apiInstance);
|
|
35
|
+
return apiInstance;
|
|
180
36
|
};
|
|
181
|
-
const defaultEndpoint = publicConfig.defaultEndpoint || "default";
|
|
182
37
|
const api = getOrCreateEndpoint(defaultEndpoint);
|
|
183
38
|
return {
|
|
184
|
-
provide: {
|
|
39
|
+
provide: {
|
|
40
|
+
api
|
|
41
|
+
}
|
|
185
42
|
};
|
|
186
43
|
});
|
|
@@ -1,98 +1,100 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { kebabCase } from "@movk/core";
|
|
2
|
+
import { defineNuxtPlugin, useAppConfig, useHead, useSiteConfig } from "#imports";
|
|
3
|
+
import { themeIcons } from "../domains/theme/theme-icons.js";
|
|
3
4
|
export default defineNuxtPlugin({
|
|
4
5
|
enforce: "post",
|
|
5
6
|
setup() {
|
|
6
7
|
const appConfig = useAppConfig();
|
|
7
8
|
const site = useSiteConfig();
|
|
9
|
+
const name = kebabCase(site.name);
|
|
8
10
|
if (import.meta.client) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const radius = localStorage.getItem(`${site.name}-ui-radius`);
|
|
16
|
-
if (radius) {
|
|
17
|
-
appConfig.theme.radius = Number.parseFloat(radius);
|
|
18
|
-
}
|
|
19
|
-
}, updateBlackAsPrimary = function() {
|
|
20
|
-
const blackAsPrimary = localStorage.getItem(`${site.name}-ui-black-as-primary`);
|
|
21
|
-
if (blackAsPrimary) {
|
|
22
|
-
appConfig.theme.blackAsPrimary = blackAsPrimary === "true";
|
|
23
|
-
}
|
|
24
|
-
}, updateFont = function() {
|
|
25
|
-
const font = localStorage.getItem(`${site.name}-ui-font`);
|
|
26
|
-
if (font) {
|
|
27
|
-
appConfig.theme.font = font;
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
updateColor("primary");
|
|
31
|
-
updateColor("neutral");
|
|
32
|
-
updateRadius();
|
|
33
|
-
updateBlackAsPrimary();
|
|
34
|
-
updateFont();
|
|
11
|
+
const primary = localStorage.getItem(`${name}-ui-primary`);
|
|
12
|
+
if (primary) appConfig.ui.colors.primary = primary;
|
|
13
|
+
const neutral = localStorage.getItem(`${name}-ui-neutral`);
|
|
14
|
+
if (neutral) appConfig.ui.colors.neutral = neutral;
|
|
15
|
+
const icons = localStorage.getItem(`${name}-ui-icons`);
|
|
16
|
+
if (icons) appConfig.ui.icons = themeIcons[icons];
|
|
35
17
|
}
|
|
36
|
-
onNuxtReady(() => {
|
|
37
|
-
function updateIcons() {
|
|
38
|
-
const icons = localStorage.getItem(`${site.name}-ui-icons`);
|
|
39
|
-
if (icons) {
|
|
40
|
-
appConfig.theme.icons = icons;
|
|
41
|
-
appConfig.ui.icons = themeIcons[icons];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
updateIcons();
|
|
45
|
-
});
|
|
46
18
|
if (import.meta.server) {
|
|
19
|
+
const pickerFonts = appConfig.movk?.picker?.fonts ?? [];
|
|
20
|
+
const fontHrefMap = {};
|
|
21
|
+
for (const f of pickerFonts) {
|
|
22
|
+
if (f.href) fontHrefMap[f.name] = f.href;
|
|
23
|
+
}
|
|
24
|
+
const fontHrefMapJson = JSON.stringify(fontHrefMap);
|
|
47
25
|
useHead({
|
|
48
26
|
script: [{
|
|
49
27
|
innerHTML: `
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
html =
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
28
|
+
(function() {
|
|
29
|
+
var primaryColor = localStorage.getItem('${name}-ui-primary');
|
|
30
|
+
var neutralColor = localStorage.getItem('${name}-ui-neutral');
|
|
31
|
+
if (!primaryColor && !neutralColor) return;
|
|
32
|
+
function swapColors(el) {
|
|
33
|
+
var html = el.innerHTML;
|
|
34
|
+
if (primaryColor && primaryColor !== 'black') {
|
|
35
|
+
html = html.replace(
|
|
36
|
+
/(--ui-color-primary-\\d{2,3}:\\s*var\\(--color-)${appConfig.ui.colors.primary}(-\\d{2,3}.*?\\))/g,
|
|
37
|
+
\`$1\${primaryColor}$2\`
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
if (neutralColor) {
|
|
41
|
+
html = html.replace(
|
|
42
|
+
/(--ui-color-neutral-\\d{2,3}:\\s*var\\(--color-)${appConfig.ui.colors.neutral}(-\\d{2,3}.*?\\))/g,
|
|
43
|
+
\`$1\${neutralColor === 'neutral' ? 'old-neutral' : neutralColor}$2\`
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
el.innerHTML = html;
|
|
59
47
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
48
|
+
var colorsEl = document.querySelector('style#nuxt-ui-colors');
|
|
49
|
+
if (colorsEl) {
|
|
50
|
+
swapColors(colorsEl);
|
|
51
|
+
} else {
|
|
52
|
+
var obs = new MutationObserver(function(mutations) {
|
|
53
|
+
for (var i = 0; i < mutations.length; i++) {
|
|
54
|
+
for (var j = 0; j < mutations[i].addedNodes.length; j++) {
|
|
55
|
+
var node = mutations[i].addedNodes[j];
|
|
56
|
+
if (node.id === 'nuxt-ui-colors') {
|
|
57
|
+
swapColors(node);
|
|
58
|
+
obs.disconnect();
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
obs.observe(document.head, { childList: true });
|
|
65
|
+
}
|
|
66
|
+
})();
|
|
70
67
|
`.replace(/\s+/g, " "),
|
|
71
68
|
type: "text/javascript",
|
|
72
69
|
tagPriority: -1
|
|
73
70
|
}, {
|
|
74
71
|
innerHTML: `
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
72
|
+
var r = localStorage.getItem('${name}-ui-radius');
|
|
73
|
+
if (r) document.documentElement.style.setProperty('--ui-radius', r + 'rem');
|
|
78
74
|
`.replace(/\s+/g, " "),
|
|
79
75
|
type: "text/javascript",
|
|
80
76
|
tagPriority: -1
|
|
81
77
|
}, {
|
|
82
78
|
innerHTML: `
|
|
83
|
-
if (localStorage.getItem('${
|
|
84
|
-
document.
|
|
85
|
-
|
|
86
|
-
document.querySelector('style#nuxt-ui-black-as-primary').innerHTML = '';
|
|
79
|
+
if (localStorage.getItem('${name}-ui-black-as-primary') === 'true') {
|
|
80
|
+
var isDark = document.documentElement.classList.contains('dark');
|
|
81
|
+
document.documentElement.style.setProperty('--ui-primary', isDark ? 'white' : 'black');
|
|
87
82
|
}
|
|
88
83
|
`.replace(/\s+/g, " ")
|
|
89
84
|
}, {
|
|
90
|
-
innerHTML:
|
|
91
|
-
if (localStorage.getItem('${
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
85
|
+
innerHTML: [
|
|
86
|
+
`if (localStorage.getItem('${name}-ui-font')) {`,
|
|
87
|
+
`var font = localStorage.getItem('${name}-ui-font');`,
|
|
88
|
+
`var fontEl = document.querySelector('style#nuxt-ui-font');`,
|
|
89
|
+
`if (fontEl) { fontEl.innerHTML = ':root { --font-sans: \\'' + font + '\\', sans-serif; }'; }`,
|
|
90
|
+
`var fontMap = ${fontHrefMapJson};`,
|
|
91
|
+
`var lnk = document.createElement('link');`,
|
|
92
|
+
`lnk.rel = 'stylesheet';`,
|
|
93
|
+
`lnk.href = fontMap[font] || ('https://fonts.googleapis.com/css2?family=' + encodeURIComponent(font) + ':wght@400;500;600;700&display=swap');`,
|
|
94
|
+
`lnk.id = 'font-' + font.toLowerCase().replace(/\\s+/g, '-');`,
|
|
95
|
+
`document.head.appendChild(lnk);`,
|
|
96
|
+
`}`
|
|
97
|
+
].join(" ")
|
|
96
98
|
}]
|
|
97
99
|
});
|
|
98
100
|
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { Suggest } from '@movk/core';
|
|
2
|
+
import type { Toast } from '@nuxt/ui/composables/useToast';
|
|
3
|
+
/**
|
|
4
|
+
* API 响应配置
|
|
5
|
+
* @description 定义业务状态码判断规则和数据/消息字段的映射关系
|
|
6
|
+
*/
|
|
7
|
+
export interface ApiResponseConfig {
|
|
8
|
+
/**
|
|
9
|
+
* 表示成功的业务状态码列表
|
|
10
|
+
* @defaultValue [200, 0]
|
|
11
|
+
*/
|
|
12
|
+
successCodes?: (number | string)[];
|
|
13
|
+
/**
|
|
14
|
+
* 响应中业务状态码的字段名
|
|
15
|
+
* @defaultValue 'code'
|
|
16
|
+
*/
|
|
17
|
+
codeKey?: string;
|
|
18
|
+
/**
|
|
19
|
+
* 响应中消息内容的字段名
|
|
20
|
+
* @defaultValue 'message'
|
|
21
|
+
*/
|
|
22
|
+
messageKey?: string;
|
|
23
|
+
/**
|
|
24
|
+
* 响应中业务数据的字段名
|
|
25
|
+
* @defaultValue 'data'
|
|
26
|
+
*/
|
|
27
|
+
dataKey?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* API 认证配置
|
|
31
|
+
* @description 定义认证令牌的来源、格式和请求头配置
|
|
32
|
+
*/
|
|
33
|
+
export interface ApiAuthConfig {
|
|
34
|
+
/**
|
|
35
|
+
* 是否启用认证
|
|
36
|
+
* @defaultValue false
|
|
37
|
+
*/
|
|
38
|
+
enabled?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* 令牌来源类型
|
|
41
|
+
* @defaultValue 'session'
|
|
42
|
+
*/
|
|
43
|
+
tokenSource?: Suggest<'session'>;
|
|
44
|
+
/**
|
|
45
|
+
* 令牌在会话对象中的路径(支持点号分隔的嵌套路径)
|
|
46
|
+
* @defaultValue 'token'
|
|
47
|
+
* @example 'token' | 'user.accessToken' | 'auth.credentials.token'
|
|
48
|
+
*/
|
|
49
|
+
sessionTokenPath?: string;
|
|
50
|
+
/**
|
|
51
|
+
* 令牌类型前缀
|
|
52
|
+
* @defaultValue 'Bearer'
|
|
53
|
+
*/
|
|
54
|
+
tokenType?: Suggest<'Bearer' | 'Basic' | 'Custom'>;
|
|
55
|
+
/**
|
|
56
|
+
* 自定义令牌类型前缀(当 tokenType 为 'Custom' 时使用)
|
|
57
|
+
*/
|
|
58
|
+
customTokenType?: string;
|
|
59
|
+
/**
|
|
60
|
+
* 认证请求头名称
|
|
61
|
+
* @defaultValue 'Authorization'
|
|
62
|
+
*/
|
|
63
|
+
headerName?: string;
|
|
64
|
+
/**
|
|
65
|
+
* 401 未授权处理配置
|
|
66
|
+
*/
|
|
67
|
+
unauthorized?: {
|
|
68
|
+
/** 是否自动重定向到登录页 @defaultValue true */
|
|
69
|
+
redirect?: boolean;
|
|
70
|
+
/** 登录页路径 @defaultValue '/login' */
|
|
71
|
+
loginPath?: string;
|
|
72
|
+
/** 是否清除用户会话 @defaultValue true */
|
|
73
|
+
clearSession?: boolean;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export interface ApiToast extends Toast {
|
|
77
|
+
/**
|
|
78
|
+
* 是否显示提示
|
|
79
|
+
* @defaultValue true
|
|
80
|
+
*/
|
|
81
|
+
show?: boolean;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Toast 提示配置
|
|
85
|
+
* @description 定义成功和错误提示的全局样式和行为
|
|
86
|
+
*/
|
|
87
|
+
export interface ApiToastConfig {
|
|
88
|
+
/**
|
|
89
|
+
* 是否启用 Toast 提示
|
|
90
|
+
* @defaultValue true
|
|
91
|
+
*/
|
|
92
|
+
enabled?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* 成功提示配置
|
|
95
|
+
*/
|
|
96
|
+
success?: ApiToast;
|
|
97
|
+
/**
|
|
98
|
+
* 错误提示配置
|
|
99
|
+
*/
|
|
100
|
+
error?: ApiToast;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* API 端点公共配置
|
|
104
|
+
* @description 定义单个 API 端点的配置(可在客户端访问的配置)
|
|
105
|
+
*/
|
|
106
|
+
export interface ApiEndpointPublicConfig {
|
|
107
|
+
/**
|
|
108
|
+
* 端点的基础 URL
|
|
109
|
+
*/
|
|
110
|
+
baseURL: string;
|
|
111
|
+
/**
|
|
112
|
+
* 端点别名(用于标识)
|
|
113
|
+
*/
|
|
114
|
+
alias?: string;
|
|
115
|
+
/**
|
|
116
|
+
* 端点级别的认证配置(覆盖全局配置)
|
|
117
|
+
*/
|
|
118
|
+
auth?: ApiAuthConfig;
|
|
119
|
+
/**
|
|
120
|
+
* 端点级别的 Toast 配置(覆盖全局配置)
|
|
121
|
+
*/
|
|
122
|
+
toast?: ApiToastConfig;
|
|
123
|
+
/**
|
|
124
|
+
* 端点级别的响应配置(覆盖全局配置)
|
|
125
|
+
*/
|
|
126
|
+
response?: ApiResponseConfig;
|
|
127
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { $Fetch } from 'nitropack/types';
|
|
2
|
+
import type { FetchError } from 'ofetch';
|
|
3
|
+
import type { UseFetchOptions as NuxtUseFetchOptions, AsyncData } from 'nuxt/app';
|
|
4
|
+
import type { RequestToastOptions, ApiError } from './response';
|
|
5
|
+
/**
|
|
6
|
+
* 端点名声明合并入口
|
|
7
|
+
* @description 构建期由模块按 nuxt.config 的 movk.api.endpoints 自动注入;
|
|
8
|
+
* 用户也可在自有 d.ts 中通过 `declare module '@movk/nuxt'` 追加自定义端点名
|
|
9
|
+
*/
|
|
10
|
+
export interface MovkApiEndpoints {
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 已声明的端点名联合
|
|
14
|
+
* @description 派生自 MovkApiEndpoints 的键集合
|
|
15
|
+
*/
|
|
16
|
+
export type MovkApiEndpointName = keyof MovkApiEndpoints & string;
|
|
17
|
+
/**
|
|
18
|
+
* API 实例类型
|
|
19
|
+
* @description $fetch.create() 返回的实例,附加 use() 方法支持多端点切换
|
|
20
|
+
*/
|
|
21
|
+
export type ApiInstance = $Fetch & {
|
|
22
|
+
/** 切换到指定端点,返回该端点的 $fetch 实例 */
|
|
23
|
+
use: (endpoint: MovkApiEndpointName) => ApiInstance;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* useApiFetch 选项类型
|
|
27
|
+
* @template T - 业务数据类型(已解包)
|
|
28
|
+
* @template DataT - transform 转换后的类型(默认等于 T)
|
|
29
|
+
*/
|
|
30
|
+
export type UseApiFetchOptions<T = unknown, DataT = T> = Omit<NuxtUseFetchOptions<T, DataT>, '$fetch' | 'context'> & {
|
|
31
|
+
/** 使用的端点名称(默认使用 defaultEndpoint) */
|
|
32
|
+
endpoint?: MovkApiEndpointName;
|
|
33
|
+
/** Toast 提示配置,设置为 false 禁用提示 */
|
|
34
|
+
toast?: RequestToastOptions | false;
|
|
35
|
+
/**
|
|
36
|
+
* 是否跳过业务状态码检查
|
|
37
|
+
* @description 仅跳过 code 校验,仍解包;与 skipUnwrap 正交。
|
|
38
|
+
*/
|
|
39
|
+
skipBusinessCheck?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* 是否跳过数据解包
|
|
42
|
+
* @description 为 true 时返回原始响应;与 skipBusinessCheck 正交。
|
|
43
|
+
*/
|
|
44
|
+
skipUnwrap?: boolean;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* useApiFetch 返回值类型
|
|
48
|
+
* @template DataT - 最终数据类型
|
|
49
|
+
*/
|
|
50
|
+
export type UseApiFetchReturn<DataT> = AsyncData<DataT | null, FetchError | ApiError | null>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { ApiAuthConfig, ApiEndpointPublicConfig, ApiResponseConfig, ApiToastConfig } from './config';
|
|
2
|
+
export type { MovkApiPublicConfig } from './module';
|
|
3
|
+
export type { ApiError, ApiResponse, RequestToastOptions } from './response';
|
|
4
|
+
export type { ApiInstance, MovkApiEndpointName, MovkApiEndpoints, UseApiFetchOptions, UseApiFetchReturn } from './fetch';
|
|
5
|
+
export type { TransferRequestOptions, TransferResult, TransferStatus } from './transfer';
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { ApiAuthConfig, ApiEndpointPublicConfig, ApiResponseConfig, ApiToastConfig } from './config';
|
|
2
|
+
/**
|
|
3
|
+
* Movk API 模块公共配置
|
|
4
|
+
* @description 定义模块的全局配置(可在客户端访问)
|
|
5
|
+
*/
|
|
6
|
+
export interface MovkApiPublicConfig {
|
|
7
|
+
/**
|
|
8
|
+
* 默认使用的端点名称
|
|
9
|
+
* @defaultValue 'default'
|
|
10
|
+
*/
|
|
11
|
+
defaultEndpoint?: string;
|
|
12
|
+
/**
|
|
13
|
+
* 是否启用调试模式(在控制台输出请求和响应日志)
|
|
14
|
+
* @defaultValue false
|
|
15
|
+
*/
|
|
16
|
+
debug?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* 端点配置映射
|
|
19
|
+
* @defaultValue { default: { baseURL: '/api' } }
|
|
20
|
+
*/
|
|
21
|
+
endpoints?: Record<string, ApiEndpointPublicConfig>;
|
|
22
|
+
/**
|
|
23
|
+
* 全局响应配置(已合并默认值,运行时必然存在)
|
|
24
|
+
*/
|
|
25
|
+
response?: ApiResponseConfig;
|
|
26
|
+
/**
|
|
27
|
+
* 全局认证配置(已合并默认值,运行时必然存在)
|
|
28
|
+
*/
|
|
29
|
+
auth?: ApiAuthConfig;
|
|
30
|
+
/**
|
|
31
|
+
* 全局 Toast 配置(已合并默认值,运行时必然存在)
|
|
32
|
+
*/
|
|
33
|
+
toast?: ApiToastConfig;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 端点私有配置(仅服务端)
|
|
37
|
+
* @description 从端点配置中拆分出的服务端专用字段,不会暴露给客户端
|
|
38
|
+
*/
|
|
39
|
+
export interface EndpointPrivateConfig {
|
|
40
|
+
/** 自定义请求头(仅服务端使用,不会暴露给客户端) */
|
|
41
|
+
headers?: Record<string, string>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Movk API 模块完整配置
|
|
45
|
+
* @description 定义模块的完整配置(公共+私有),用于模块初始化时的配置验证
|
|
46
|
+
*/
|
|
47
|
+
export interface MovkApiFullConfig {
|
|
48
|
+
/**
|
|
49
|
+
* 是否启用 API 模块
|
|
50
|
+
* @defaultValue true
|
|
51
|
+
*/
|
|
52
|
+
enabled?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* 默认使用的端点名称
|
|
55
|
+
* @defaultValue 'default'
|
|
56
|
+
*/
|
|
57
|
+
defaultEndpoint?: string;
|
|
58
|
+
/**
|
|
59
|
+
* 是否启用调试模式
|
|
60
|
+
* @defaultValue false
|
|
61
|
+
*/
|
|
62
|
+
debug?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* 端点配置映射(包含公共和私有配置)
|
|
65
|
+
* @defaultValue { default: { baseURL: '/api' } }
|
|
66
|
+
*/
|
|
67
|
+
endpoints?: Record<string, ApiEndpointPublicConfig & EndpointPrivateConfig>;
|
|
68
|
+
/**
|
|
69
|
+
* 全局响应配置
|
|
70
|
+
*/
|
|
71
|
+
response?: ApiResponseConfig;
|
|
72
|
+
/**
|
|
73
|
+
* 全局认证配置
|
|
74
|
+
*/
|
|
75
|
+
auth?: ApiAuthConfig;
|
|
76
|
+
/**
|
|
77
|
+
* 全局 Toast 配置
|
|
78
|
+
*/
|
|
79
|
+
toast?: ApiToastConfig;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* 已解析的端点配置
|
|
83
|
+
* @description 合并全局配置和端点配置后的最终配置,供内部使用
|
|
84
|
+
*/
|
|
85
|
+
export interface ResolvedEndpointConfig extends Omit<ApiEndpointPublicConfig, 'auth' | 'toast' | 'response'> {
|
|
86
|
+
/** 认证配置(已合并全局默认值,必然存在) */
|
|
87
|
+
auth: ApiAuthConfig;
|
|
88
|
+
/** Toast 配置(已合并全局默认值,必然存在) */
|
|
89
|
+
toast: ApiToastConfig;
|
|
90
|
+
/** 响应配置(已合并全局默认值,必然存在) */
|
|
91
|
+
response: ApiResponseConfig;
|
|
92
|
+
/** 自定义请求头(仅服务端配置) */
|
|
93
|
+
headers?: Record<string, string>;
|
|
94
|
+
}
|