@movk/nuxt 1.1.1 → 1.2.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/README.md +5 -29
- package/dist/module.d.mts +3 -31
- package/dist/module.json +3 -3
- package/dist/module.mjs +135 -77
- package/dist/runtime/auto-form/controls.d.ts +221 -0
- package/dist/runtime/auto-form/controls.js +70 -0
- package/dist/runtime/{utils → auto-form}/field-utils.d.ts +4 -20
- package/dist/runtime/{utils → auto-form}/field-utils.js +1 -2
- package/dist/runtime/auto-form/metadata.d.ts +22 -0
- package/dist/runtime/auto-form/metadata.js +53 -0
- package/dist/runtime/auto-form/provider.d.ts +27 -0
- package/dist/runtime/{internal/useAutoFormProvider.js → auto-form/provider.js} +1 -1
- package/dist/runtime/{utils → auto-form}/reactive-utils.d.ts +4 -22
- package/dist/runtime/{utils → auto-form}/schema-introspector.d.ts +3 -9
- package/dist/runtime/{utils → auto-form}/schema-introspector.js +11 -9
- package/dist/runtime/components/AutoForm.d.vue.ts +4 -5
- package/dist/runtime/components/AutoForm.vue +12 -35
- package/dist/runtime/components/AutoForm.vue.d.ts +4 -5
- package/dist/runtime/components/ColorChooser.d.vue.ts +10 -6
- package/dist/runtime/components/ColorChooser.vue +4 -7
- package/dist/runtime/components/ColorChooser.vue.d.ts +10 -6
- package/dist/runtime/components/DatePicker.d.vue.ts +16 -10
- package/dist/runtime/components/DatePicker.vue.d.ts +16 -10
- package/dist/runtime/components/SearchForm.d.vue.ts +171 -0
- package/dist/runtime/components/SearchForm.vue +216 -0
- package/dist/runtime/components/SearchForm.vue.d.ts +171 -0
- package/dist/runtime/components/SlideVerify.d.vue.ts +5 -32
- package/dist/runtime/components/SlideVerify.vue +4 -4
- package/dist/runtime/components/SlideVerify.vue.d.ts +5 -32
- package/dist/runtime/components/StarRating.d.vue.ts +8 -16
- package/dist/runtime/components/StarRating.vue +50 -65
- package/dist/runtime/components/StarRating.vue.d.ts +8 -16
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererArray.d.vue.ts +10 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererArray.vue +16 -23
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererArray.vue.d.ts +10 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererChildren.d.vue.ts +26 -0
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererChildren.vue +50 -0
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererChildren.vue.d.ts +26 -0
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererField.d.vue.ts +8 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererField.vue +2 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererField.vue.d.ts +8 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererLayout.d.vue.ts +8 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererLayout.vue +29 -64
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererLayout.vue.d.ts +8 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererNested.d.vue.ts +8 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererNested.vue +15 -69
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererNested.vue.d.ts +8 -2
- package/dist/runtime/components/input/AsPhoneNumberInput.d.vue.ts +36 -0
- package/dist/runtime/components/input/AsPhoneNumberInput.vue +35 -0
- package/dist/runtime/components/input/AsPhoneNumberInput.vue.d.ts +36 -0
- package/dist/runtime/components/input/WithCharacterLimit.d.vue.ts +17 -9
- package/dist/runtime/components/input/WithCharacterLimit.vue +5 -5
- package/dist/runtime/components/input/WithCharacterLimit.vue.d.ts +17 -9
- package/dist/runtime/components/input/WithClear.d.vue.ts +13 -9
- package/dist/runtime/components/input/WithClear.vue +2 -2
- package/dist/runtime/components/input/WithClear.vue.d.ts +13 -9
- package/dist/runtime/components/input/WithCopy.d.vue.ts +16 -10
- package/dist/runtime/components/input/WithCopy.vue +3 -3
- package/dist/runtime/components/input/WithCopy.vue.d.ts +16 -10
- package/dist/runtime/components/input/WithFloatingLabel.d.vue.ts +36 -0
- package/dist/runtime/components/input/WithFloatingLabel.vue +67 -0
- package/dist/runtime/components/input/WithFloatingLabel.vue.d.ts +36 -0
- package/dist/runtime/components/input/WithPasswordToggle.d.vue.ts +11 -9
- package/dist/runtime/components/input/WithPasswordToggle.vue +3 -3
- package/dist/runtime/components/input/WithPasswordToggle.vue.d.ts +11 -9
- package/dist/runtime/components/theme-picker/ThemePicker.d.vue.ts +1 -1
- package/dist/runtime/components/theme-picker/ThemePicker.vue +19 -25
- package/dist/runtime/components/theme-picker/ThemePicker.vue.d.ts +1 -1
- package/dist/runtime/components/theme-picker/ThemePickerButton.d.vue.ts +1 -7
- package/dist/runtime/components/theme-picker/ThemePickerButton.vue.d.ts +1 -7
- package/dist/runtime/composables/index.d.ts +8 -0
- package/dist/runtime/composables/index.js +8 -0
- package/dist/runtime/composables/useApiFetch.d.ts +17 -14
- package/dist/runtime/composables/useApiFetch.js +3 -28
- package/dist/runtime/composables/useAutoForm.d.ts +14 -98
- package/dist/runtime/composables/useAutoForm.js +37 -157
- package/dist/runtime/composables/useClientApiFetch.d.ts +5 -6
- package/dist/runtime/composables/useDownloadWithProgress.js +5 -6
- package/dist/runtime/composables/useLazyApiFetch.d.ts +18 -0
- package/dist/runtime/composables/useLazyApiFetch.js +4 -0
- package/dist/runtime/composables/useTheme.d.ts +17 -14
- package/dist/runtime/composables/useTheme.js +68 -72
- package/dist/runtime/composables/useUploadWithProgress.d.ts +2 -2
- package/dist/runtime/composables/useUploadWithProgress.js +7 -7
- package/dist/runtime/constants/api-defaults.d.ts +9 -0
- package/dist/runtime/constants/api-defaults.js +32 -0
- package/dist/runtime/constants/auto-form.d.ts +0 -2
- package/dist/runtime/constants/auto-form.js +0 -25
- package/dist/runtime/constants/grid-cols.d.ts +7 -0
- package/dist/runtime/constants/grid-cols.js +44 -0
- package/dist/runtime/plugins/api.factory.js +78 -121
- package/dist/runtime/plugins/theme.js +44 -64
- package/dist/runtime/style.css +1 -1
- package/dist/runtime/types/api.d.ts +277 -146
- package/dist/runtime/types/auto-form.d.ts +122 -411
- package/dist/runtime/types/index.d.ts +3 -2
- package/dist/runtime/types/index.js +3 -2
- package/dist/runtime/types/module.d.ts +96 -0
- package/dist/runtime/types/theme.d.ts +2 -0
- package/dist/runtime/types/zod.d.ts +11 -10
- package/dist/runtime/utils/api-utils.d.ts +27 -48
- package/dist/runtime/utils/api-utils.js +18 -47
- package/dist/runtime/utils/meta.d.ts +7 -0
- package/dist/runtime/utils/meta.js +16 -0
- package/dist/types.d.mts +6 -2
- package/package.json +68 -37
- 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/types/auth.d.ts +0 -34
- package/dist/runtime/types/auto-form-renderer.d.ts +0 -22
- package/dist/runtime/types/components.d.ts +0 -43
- package/dist/runtime/utils/auto-form.d.ts +0 -3
- package/dist/runtime/utils/auto-form.js +0 -18
- /package/dist/runtime/{utils → auto-form}/reactive-utils.js +0 -0
- /package/dist/runtime/types/{auto-form-renderer.js → module.js} +0 -0
- /package/dist/runtime/types/{components.js → theme.js} +0 -0
|
@@ -1,56 +1,42 @@
|
|
|
1
1
|
import { useAppConfig, useColorMode, useSiteConfig } from "#imports";
|
|
2
|
-
import {
|
|
2
|
+
import { themeIcons } from "../utils/theme.js";
|
|
3
|
+
import { omit, kebabCase } from "@movk/core";
|
|
4
|
+
import { useLocalStorage } from "@vueuse/core";
|
|
3
5
|
import colors from "tailwindcss/colors";
|
|
4
6
|
import { computed } from "vue";
|
|
5
|
-
import { themeIcons } from "../utils/theme.js";
|
|
6
7
|
export function useTheme() {
|
|
7
8
|
const appConfig = useAppConfig();
|
|
8
9
|
const colorMode = useColorMode();
|
|
9
10
|
const site = useSiteConfig();
|
|
10
|
-
const
|
|
11
|
+
const name = kebabCase(site.name);
|
|
12
|
+
const radius = useLocalStorage(`${name}-ui-radius`, 0.25);
|
|
13
|
+
const font = useLocalStorage(`${name}-ui-font`, "Alibaba PuHuiTi");
|
|
14
|
+
const _iconSet = useLocalStorage(`${name}-ui-icons`, "lucide");
|
|
15
|
+
const blackAsPrimary = useLocalStorage(`${name}-ui-black-as-primary`, false);
|
|
16
|
+
const neutralColors = ["slate", "gray", "zinc", "neutral", "stone", "taupe", "mauve", "mist", "olive"];
|
|
11
17
|
const neutral = computed({
|
|
12
18
|
get() {
|
|
13
19
|
return appConfig.ui.colors.neutral;
|
|
14
20
|
},
|
|
15
21
|
set(option) {
|
|
16
22
|
appConfig.ui.colors.neutral = option;
|
|
17
|
-
window.localStorage.setItem(`${
|
|
23
|
+
window.localStorage.setItem(`${name}-ui-neutral`, appConfig.ui.colors.neutral);
|
|
18
24
|
}
|
|
19
25
|
});
|
|
20
26
|
const colorsToOmit = ["inherit", "current", "transparent", "black", "white", ...neutralColors];
|
|
21
|
-
const primaryColors = Object.keys(omit(colors,
|
|
27
|
+
const primaryColors = Object.keys(omit(colors, colorsToOmit));
|
|
22
28
|
const primary = computed({
|
|
23
29
|
get() {
|
|
24
30
|
return appConfig.ui.colors.primary;
|
|
25
31
|
},
|
|
26
32
|
set(option) {
|
|
27
33
|
appConfig.ui.colors.primary = option;
|
|
28
|
-
window.localStorage.setItem(`${
|
|
29
|
-
|
|
34
|
+
window.localStorage.setItem(`${name}-ui-primary`, appConfig.ui.colors.primary);
|
|
35
|
+
blackAsPrimary.value = false;
|
|
30
36
|
}
|
|
31
37
|
});
|
|
32
38
|
const radiuses = [0, 0.125, 0.25, 0.375, 0.5];
|
|
33
|
-
const
|
|
34
|
-
get() {
|
|
35
|
-
return appConfig.theme.radius;
|
|
36
|
-
},
|
|
37
|
-
set(option) {
|
|
38
|
-
appConfig.theme.radius = option;
|
|
39
|
-
window.localStorage.setItem(`${site.name}-ui-radius`, String(appConfig.theme.radius));
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
const fonts = ["Public Sans", "DM Sans", "Geist", "Inter", "Poppins", "Outfit", "Raleway"];
|
|
43
|
-
const font = computed({
|
|
44
|
-
get() {
|
|
45
|
-
return appConfig.theme.font;
|
|
46
|
-
},
|
|
47
|
-
set(option) {
|
|
48
|
-
appConfig.theme.font = option;
|
|
49
|
-
if (appConfig.theme.font) {
|
|
50
|
-
window.localStorage.setItem(`${site.name}-ui-font`, appConfig.theme.font);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
});
|
|
39
|
+
const fonts = ["Alibaba PuHuiTi", "Public Sans", "DM Sans", "Geist", "Inter", "Poppins", "Outfit", "Raleway"];
|
|
54
40
|
const icons = [{
|
|
55
41
|
label: "Lucide",
|
|
56
42
|
icon: "i-lucide-feather",
|
|
@@ -66,21 +52,18 @@ export function useTheme() {
|
|
|
66
52
|
}];
|
|
67
53
|
const icon = computed({
|
|
68
54
|
get() {
|
|
69
|
-
return
|
|
55
|
+
return _iconSet.value;
|
|
70
56
|
},
|
|
71
57
|
set(option) {
|
|
72
|
-
|
|
58
|
+
_iconSet.value = option;
|
|
73
59
|
appConfig.ui.icons = themeIcons[option];
|
|
74
|
-
if (appConfig.theme.icons) {
|
|
75
|
-
window.localStorage.setItem(`${site.name}-ui-icons`, appConfig.theme.icons);
|
|
76
|
-
}
|
|
77
60
|
}
|
|
78
61
|
});
|
|
79
|
-
const modes = [
|
|
62
|
+
const modes = computed(() => [
|
|
80
63
|
{ label: "light", icon: appConfig.ui.icons.light },
|
|
81
64
|
{ label: "dark", icon: appConfig.ui.icons.dark },
|
|
82
65
|
{ label: "system", icon: appConfig.ui.icons.system }
|
|
83
|
-
];
|
|
66
|
+
]);
|
|
84
67
|
const mode = computed({
|
|
85
68
|
get() {
|
|
86
69
|
return colorMode.value;
|
|
@@ -89,80 +72,93 @@ export function useTheme() {
|
|
|
89
72
|
colorMode.preference = option;
|
|
90
73
|
}
|
|
91
74
|
});
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
75
|
+
const radiusStyle = computed(() => `:root { --ui-radius: ${radius.value}rem; }`);
|
|
76
|
+
const blackAsPrimaryStyle = computed(() => blackAsPrimary.value ? `:root { --ui-primary: black; } .dark { --ui-primary: white; }` : ":root {}");
|
|
77
|
+
const fontStyle = computed(() => `:root { --font-sans: '${font.value}', sans-serif; }`);
|
|
78
|
+
const link = computed(() => {
|
|
79
|
+
const name2 = font.value;
|
|
80
|
+
if (name2 === "Alibaba PuHuiTi" || !fonts.includes(name2)) return [];
|
|
81
|
+
return [{
|
|
82
|
+
rel: "stylesheet",
|
|
83
|
+
href: `https://fonts.googleapis.com/css2?family=${encodeURIComponent(name2)}:wght@400;500;600;700&display=swap`,
|
|
84
|
+
id: `font-${kebabCase(name2)}`
|
|
85
|
+
}];
|
|
86
|
+
});
|
|
87
|
+
const style = [
|
|
88
|
+
{ innerHTML: radiusStyle, id: `${name}-ui-radius`, tagPriority: -2 },
|
|
89
|
+
{ innerHTML: blackAsPrimaryStyle, id: `${name}-ui-black-as-primary`, tagPriority: -2 },
|
|
90
|
+
{ innerHTML: fontStyle, id: `${name}-ui-font`, tagPriority: -2 }
|
|
91
|
+
];
|
|
96
92
|
const hasCSSChanges = computed(() => {
|
|
97
|
-
return
|
|
93
|
+
return radius.value !== 0.25 || blackAsPrimary.value || font.value !== "Alibaba PuHuiTi";
|
|
98
94
|
});
|
|
99
95
|
const hasAppConfigChanges = computed(() => {
|
|
100
|
-
return appConfig.ui.colors.primary !== "
|
|
96
|
+
return appConfig.ui.colors.primary !== "sky" || appConfig.ui.colors.neutral !== "slate" || _iconSet.value !== "lucide";
|
|
101
97
|
});
|
|
102
98
|
function exportCSS() {
|
|
103
99
|
const lines = [
|
|
104
100
|
'@import "tailwindcss";',
|
|
105
101
|
'@import "@nuxt/ui";'
|
|
106
102
|
];
|
|
107
|
-
if (
|
|
108
|
-
lines.push("", "@theme {", ` --font-sans: '${
|
|
103
|
+
if (font.value !== "Alibaba PuHuiTi") {
|
|
104
|
+
lines.push("", "@theme {", ` --font-sans: '${font.value}', sans-serif;`, "}");
|
|
109
105
|
}
|
|
110
106
|
const rootLines = [];
|
|
111
|
-
if (
|
|
112
|
-
rootLines.push(` --ui-radius: ${
|
|
107
|
+
if (radius.value !== 0.25) {
|
|
108
|
+
rootLines.push(` --ui-radius: ${radius.value}rem;`);
|
|
113
109
|
}
|
|
114
|
-
if (
|
|
110
|
+
if (blackAsPrimary.value) {
|
|
115
111
|
rootLines.push(" --ui-primary: black;");
|
|
116
112
|
}
|
|
117
113
|
if (rootLines.length) {
|
|
118
114
|
lines.push("", ":root {", ...rootLines, "}");
|
|
119
115
|
}
|
|
120
|
-
|
|
121
|
-
|
|
116
|
+
const darkLines = [];
|
|
117
|
+
if (blackAsPrimary.value) {
|
|
118
|
+
darkLines.push(" --ui-primary: white;");
|
|
119
|
+
}
|
|
120
|
+
if (darkLines.length) {
|
|
121
|
+
lines.push("", ".dark {", ...darkLines, "}");
|
|
122
122
|
}
|
|
123
123
|
return lines.join("\n");
|
|
124
124
|
}
|
|
125
125
|
function exportAppConfig() {
|
|
126
126
|
const config = {};
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
if (appConfig.ui.colors.neutral !== "slate") {
|
|
133
|
-
config.ui.colors.neutral = appConfig.ui.colors.neutral;
|
|
134
|
-
}
|
|
127
|
+
const defaultColors = { primary: "sky", secondary: "blue", success: "green", info: "blue", warning: "yellow", error: "red", neutral: "slate" };
|
|
128
|
+
const colorEntries = Object.entries(defaultColors).filter(([key, def]) => appConfig.ui.colors[key] !== def);
|
|
129
|
+
if (colorEntries.length) {
|
|
130
|
+
config.ui = { colors: Object.fromEntries(colorEntries.map(([key]) => [key, appConfig.ui.colors[key]])) };
|
|
135
131
|
}
|
|
136
|
-
if (
|
|
137
|
-
const
|
|
138
|
-
const icons2 = themeIcons[iconSet];
|
|
132
|
+
if (_iconSet.value !== "lucide") {
|
|
133
|
+
const iconMapping = themeIcons[_iconSet.value];
|
|
139
134
|
config.ui = config.ui || {};
|
|
140
|
-
config.ui.icons =
|
|
135
|
+
config.ui.icons = iconMapping;
|
|
141
136
|
}
|
|
142
137
|
const configString = JSON.stringify(config, null, 2).replace(/"([^"]+)":/g, "$1:").replace(/"/g, "'");
|
|
143
138
|
return `export default defineAppConfig(${configString})`;
|
|
144
139
|
}
|
|
145
140
|
function resetTheme() {
|
|
146
|
-
appConfig.ui.colors.primary = "
|
|
147
|
-
window.localStorage.removeItem(`${
|
|
141
|
+
appConfig.ui.colors.primary = "sky";
|
|
142
|
+
window.localStorage.removeItem(`${name}-ui-primary`);
|
|
148
143
|
appConfig.ui.colors.neutral = "slate";
|
|
149
|
-
window.localStorage.removeItem(`${
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
window.localStorage.removeItem(`${site.name}-ui-font`);
|
|
154
|
-
appConfig.theme.icons = "lucide";
|
|
144
|
+
window.localStorage.removeItem(`${name}-ui-neutral`);
|
|
145
|
+
radius.value = 0.25;
|
|
146
|
+
font.value = "Alibaba PuHuiTi";
|
|
147
|
+
_iconSet.value = "lucide";
|
|
155
148
|
appConfig.ui.icons = themeIcons.lucide;
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
window.localStorage.removeItem(`${
|
|
149
|
+
blackAsPrimary.value = false;
|
|
150
|
+
window.localStorage.removeItem(`${name}-ui-ai-theme`);
|
|
151
|
+
window.localStorage.removeItem(`${name}-ui-custom-colors`);
|
|
152
|
+
window.localStorage.removeItem(`${name}-ui-css-variables`);
|
|
159
153
|
}
|
|
160
154
|
return {
|
|
155
|
+
style,
|
|
156
|
+
link,
|
|
161
157
|
neutralColors,
|
|
162
158
|
neutral,
|
|
163
159
|
primaryColors,
|
|
164
160
|
primary,
|
|
165
|
-
|
|
161
|
+
blackAsPrimary,
|
|
166
162
|
radiuses,
|
|
167
163
|
radius,
|
|
168
164
|
fonts,
|
|
@@ -33,7 +33,7 @@ export interface UploadWithProgressOptions {
|
|
|
33
33
|
* })
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
|
-
export declare function useUploadWithProgress
|
|
36
|
+
export declare function useUploadWithProgress(): {
|
|
37
37
|
/** 上传进度 (0-100) */
|
|
38
38
|
progress: any;
|
|
39
39
|
/** 是否正在上传 */
|
|
@@ -44,7 +44,7 @@ export declare function useUploadWithProgress<T = unknown>(): {
|
|
|
44
44
|
error: any;
|
|
45
45
|
/** 执行上传 */
|
|
46
46
|
upload: (url: string, files: File | File[], options?: UploadWithProgressOptions) => Promise<{
|
|
47
|
-
data: ApiResponse
|
|
47
|
+
data: ApiResponse | null;
|
|
48
48
|
error: Error | null;
|
|
49
49
|
}>;
|
|
50
50
|
/** 中止上传 */
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { ref,
|
|
1
|
+
import { ref, useRuntimeConfig } from "#imports";
|
|
2
2
|
import {
|
|
3
3
|
showToast,
|
|
4
4
|
isBusinessSuccess,
|
|
5
5
|
extractMessage,
|
|
6
6
|
extractToastMessage,
|
|
7
|
-
getAuthHeaders
|
|
7
|
+
getAuthHeaders,
|
|
8
|
+
resolveEndpointConfig
|
|
8
9
|
} from "../utils/api-utils.js";
|
|
9
10
|
export function useUploadWithProgress() {
|
|
10
|
-
const
|
|
11
|
+
const publicConfig = useRuntimeConfig().public.movkApi;
|
|
11
12
|
const progress = ref(0);
|
|
12
13
|
const uploading = ref(false);
|
|
13
14
|
const data = ref(null);
|
|
@@ -21,9 +22,8 @@ export function useUploadWithProgress() {
|
|
|
21
22
|
};
|
|
22
23
|
const upload = async (url, files, options = {}) => {
|
|
23
24
|
const { fieldName = "file", fields = {}, headers = {}, toast, endpoint, onSuccess, onError } = options;
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const fullUrl = `${config.baseURL || ""}${url}`;
|
|
25
|
+
const config = resolveEndpointConfig(publicConfig, endpoint);
|
|
26
|
+
const fullUrl = `${config.baseURL}${url}`;
|
|
27
27
|
const formData = new FormData();
|
|
28
28
|
const fileArray = Array.isArray(files) ? files : [files];
|
|
29
29
|
fileArray.forEach((file) => formData.append(fieldName, file));
|
|
@@ -33,6 +33,7 @@ export function useUploadWithProgress() {
|
|
|
33
33
|
data.value = null;
|
|
34
34
|
error.value = null;
|
|
35
35
|
return new Promise((resolve) => {
|
|
36
|
+
const authHeaders = getAuthHeaders(config);
|
|
36
37
|
const xhr = new XMLHttpRequest();
|
|
37
38
|
currentXhr = xhr;
|
|
38
39
|
xhr.upload.addEventListener("progress", (e) => {
|
|
@@ -93,7 +94,6 @@ export function useUploadWithProgress() {
|
|
|
93
94
|
resolve({ data: null, error: error.value });
|
|
94
95
|
});
|
|
95
96
|
xhr.open("POST", fullUrl);
|
|
96
|
-
const authHeaders = getAuthHeaders(config);
|
|
97
97
|
Object.entries({ ...headers, ...authHeaders }).forEach(([key, value]) => {
|
|
98
98
|
xhr.setRequestHeader(key, value);
|
|
99
99
|
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ApiResponseConfig, ApiAuthConfig, ApiToastConfig } from '../types/api.js';
|
|
2
|
+
export declare const DEFAULT_RESPONSE_CONFIG: ApiResponseConfig;
|
|
3
|
+
export declare const DEFAULT_AUTH_CONFIG: ApiAuthConfig;
|
|
4
|
+
export declare const DEFAULT_TOAST_CONFIG: ApiToastConfig;
|
|
5
|
+
export declare const DEFAULT_ENDPOINT: {
|
|
6
|
+
default: {
|
|
7
|
+
baseURL: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export const DEFAULT_RESPONSE_CONFIG = {
|
|
2
|
+
successCodes: [200, 0],
|
|
3
|
+
codeKey: "code",
|
|
4
|
+
messageKey: "message",
|
|
5
|
+
dataKey: "data"
|
|
6
|
+
};
|
|
7
|
+
export const DEFAULT_AUTH_CONFIG = {
|
|
8
|
+
enabled: false,
|
|
9
|
+
tokenSource: "session",
|
|
10
|
+
sessionTokenPath: "token",
|
|
11
|
+
tokenType: "Bearer",
|
|
12
|
+
headerName: "Authorization",
|
|
13
|
+
unauthorized: {
|
|
14
|
+
redirect: true,
|
|
15
|
+
clearSession: true,
|
|
16
|
+
loginPath: "/login"
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
export const DEFAULT_TOAST_CONFIG = {
|
|
20
|
+
enabled: true,
|
|
21
|
+
success: {
|
|
22
|
+
show: true,
|
|
23
|
+
color: "success",
|
|
24
|
+
duration: 3e3
|
|
25
|
+
},
|
|
26
|
+
error: {
|
|
27
|
+
show: true,
|
|
28
|
+
color: "error",
|
|
29
|
+
duration: 3e3
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
export const DEFAULT_ENDPOINT = { default: { baseURL: "/api" } };
|
|
@@ -14,5 +14,3 @@ export declare const AUTOFORM_PATTERNS: {
|
|
|
14
14
|
/** 事件属性检测正则,匹配 onClick、onChange 等 Vue/React 事件命名模式 */
|
|
15
15
|
readonly EVENT_PROP: RegExp;
|
|
16
16
|
};
|
|
17
|
-
/** zod 克隆方法 */
|
|
18
|
-
export declare const CLONE_METHODS: readonly ["meta", "max", "min", "length", "regex", "startsWith", "endsWith", "includes", "uppercase", "lowercase", "optional", "nullable", "nullish", "describe", "refine", "superRefine", "check", "transform", "default", "mime", "readonly", "exclude", "extract"];
|
|
@@ -14,28 +14,3 @@ export const AUTOFORM_PATTERNS = {
|
|
|
14
14
|
/** 事件属性检测正则,匹配 onClick、onChange 等 Vue/React 事件命名模式 */
|
|
15
15
|
EVENT_PROP: /^on[A-Z]/
|
|
16
16
|
};
|
|
17
|
-
export const CLONE_METHODS = [
|
|
18
|
-
"meta",
|
|
19
|
-
"max",
|
|
20
|
-
"min",
|
|
21
|
-
"length",
|
|
22
|
-
"regex",
|
|
23
|
-
"startsWith",
|
|
24
|
-
"endsWith",
|
|
25
|
-
"includes",
|
|
26
|
-
"uppercase",
|
|
27
|
-
"lowercase",
|
|
28
|
-
"optional",
|
|
29
|
-
"nullable",
|
|
30
|
-
"nullish",
|
|
31
|
-
"describe",
|
|
32
|
-
"refine",
|
|
33
|
-
"superRefine",
|
|
34
|
-
"check",
|
|
35
|
-
"transform",
|
|
36
|
-
"default",
|
|
37
|
-
"mime",
|
|
38
|
-
"readonly",
|
|
39
|
-
"exclude",
|
|
40
|
-
"extract"
|
|
41
|
-
];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
declare const BREAKPOINTS: readonly ["sm", "md", "lg", "xl"];
|
|
2
|
+
type Breakpoint = (typeof BREAKPOINTS)[number];
|
|
3
|
+
type ColsConfig = Partial<Record<Breakpoint, number>>;
|
|
4
|
+
export declare const GRID_COL_SAFELIST: string[];
|
|
5
|
+
export declare function resolveMaxCols(cols: number | ColsConfig): number;
|
|
6
|
+
export declare function resolveGridClasses(cols: number | ColsConfig, gap: string): string;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const BREAKPOINTS = ["sm", "md", "lg", "xl"];
|
|
2
|
+
export const GRID_COL_SAFELIST = [
|
|
3
|
+
"grid-cols-1",
|
|
4
|
+
"grid-cols-2",
|
|
5
|
+
"grid-cols-3",
|
|
6
|
+
"grid-cols-4",
|
|
7
|
+
"grid-cols-5",
|
|
8
|
+
"grid-cols-6",
|
|
9
|
+
"sm:grid-cols-1",
|
|
10
|
+
"sm:grid-cols-2",
|
|
11
|
+
"sm:grid-cols-3",
|
|
12
|
+
"sm:grid-cols-4",
|
|
13
|
+
"sm:grid-cols-5",
|
|
14
|
+
"sm:grid-cols-6",
|
|
15
|
+
"md:grid-cols-1",
|
|
16
|
+
"md:grid-cols-2",
|
|
17
|
+
"md:grid-cols-3",
|
|
18
|
+
"md:grid-cols-4",
|
|
19
|
+
"md:grid-cols-5",
|
|
20
|
+
"md:grid-cols-6",
|
|
21
|
+
"lg:grid-cols-1",
|
|
22
|
+
"lg:grid-cols-2",
|
|
23
|
+
"lg:grid-cols-3",
|
|
24
|
+
"lg:grid-cols-4",
|
|
25
|
+
"lg:grid-cols-5",
|
|
26
|
+
"lg:grid-cols-6",
|
|
27
|
+
"xl:grid-cols-1",
|
|
28
|
+
"xl:grid-cols-2",
|
|
29
|
+
"xl:grid-cols-3",
|
|
30
|
+
"xl:grid-cols-4",
|
|
31
|
+
"xl:grid-cols-5",
|
|
32
|
+
"xl:grid-cols-6"
|
|
33
|
+
];
|
|
34
|
+
export function resolveMaxCols(cols) {
|
|
35
|
+
if (typeof cols === "number") return cols;
|
|
36
|
+
return Math.max(...BREAKPOINTS.map((bp) => cols[bp] ?? 1));
|
|
37
|
+
}
|
|
38
|
+
export function resolveGridClasses(cols, gap) {
|
|
39
|
+
if (typeof cols === "number") {
|
|
40
|
+
return `grid ${gap} grid-cols-${cols}`;
|
|
41
|
+
}
|
|
42
|
+
const bpClasses = BREAKPOINTS.filter((bp) => cols[bp] != null).map((bp) => `${bp}:grid-cols-${cols[bp]}`);
|
|
43
|
+
return ["grid", gap, "grid-cols-1", ...bpClasses].join(" ");
|
|
44
|
+
}
|