vft 0.0.386 → 0.0.387
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/es/components/carousel/use-carousel.js +1 -1
- package/es/components/input/input.vue2.js +4 -4
- package/es/components/input-tag/composables/use-input-tag.js +1 -1
- package/es/components/super-form/super-form-item.vue2.js +1 -1
- package/es/components/super-form/use/helper.js +1 -1
- package/es/components/upload/index.d.ts +9 -0
- package/es/components/upload/types.d.ts +6 -0
- package/es/components/upload/upload-content.vue2.js +126 -116
- package/es/components/upload/upload.vue2.js +62 -53
- package/es/components/upload/utils.d.ts +7 -0
- package/es/components/upload/utils.js +33 -20
- package/es/package.json.d.ts +1 -1
- package/es/package.json.js +1 -1
- package/es/utils/vue/vnode.js +1 -1
- package/lib/components/input/input.vue2.cjs +1 -1
- package/lib/components/upload/index.d.ts +9 -0
- package/lib/components/upload/types.d.ts +6 -0
- package/lib/components/upload/upload-content.vue2.cjs +1 -1
- package/lib/components/upload/upload.vue2.cjs +1 -1
- package/lib/components/upload/utils.cjs +1 -1
- package/lib/components/upload/utils.d.ts +7 -0
- package/lib/package.json.cjs +1 -1
- package/lib/package.json.d.ts +1 -1
- package/package.json +4 -4
- package/web-types.json +1 -1
|
@@ -10,7 +10,7 @@ import "../../hooks/use-model-toggle/index.js";
|
|
|
10
10
|
import { useOrderedChildren as Ie } from "../../hooks/use-ordered-children/index.js";
|
|
11
11
|
import "@popperjs/core";
|
|
12
12
|
import "../../hooks/use-z-index/index.js";
|
|
13
|
-
import {
|
|
13
|
+
import { CAROUSEL_ITEM_NAME as H, carouselContextKey as ge } from "./constants.js";
|
|
14
14
|
const L = 300, _e = (t, O, M) => {
|
|
15
15
|
const {
|
|
16
16
|
children: o,
|
|
@@ -13,8 +13,8 @@ import "../../hooks/use-z-index/index.js";
|
|
|
13
13
|
import { UPDATE_MODEL_EVENT as Q } from "@vft/constants";
|
|
14
14
|
import { useAttrs as Ze, useCursor as _e } from "@vft/use";
|
|
15
15
|
import { calcTextareaHeight as ye } from "./utils.js";
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
16
|
+
import { useFormSize as et, useFormDisabled as tt } from "../form/hooks/use-form-common-props.js";
|
|
17
|
+
import { useFormItem as at, useFormItemInputId as ot } from "../form/hooks/use-form-item.js";
|
|
18
18
|
const nt = ["role"], lt = ["id", "type", "disabled", "formatter", "parser", "readonly", "autocomplete", "tabindex", "aria-label", "placeholder", "form"], st = ["id", "tabindex", "disabled", "readonly", "autocomplete", "aria-label", "placeholder", "form"], It = /* @__PURE__ */ Oe({
|
|
19
19
|
__name: "input",
|
|
20
20
|
props: {
|
|
@@ -85,9 +85,9 @@ const nt = ["role"], lt = ["id", "type", "disabled", "formatter", "parser", "rea
|
|
|
85
85
|
o.is("focus", v.value)
|
|
86
86
|
]), d = Ze({
|
|
87
87
|
excludeKeys: l(() => Object.keys(X.value))
|
|
88
|
-
}), { form: Ce, formItem: F } =
|
|
88
|
+
}), { form: Ce, formItem: F } = at(), { inputId: Y } = ot(xe.props, {
|
|
89
89
|
formItemContext: F
|
|
90
|
-
}), ke =
|
|
90
|
+
}), ke = et(), h = tt(), o = pe("input"), Z = pe("textarea"), M = H(), b = H(), v = S(!1), N = S(!1), C = S(!1), K = S(!1), _ = S(), O = H(e.inputStyle), k = l(() => M.value || b.value), T = l(() => G(e.prefixIcon, "icon", { size: 16 })), ee = l(() => G(e.suffixIcon, "icon", { size: 16 })), Ie = l(() => G(e.clearIcon, "icon", {
|
|
91
91
|
icon: "icon-circle-close",
|
|
92
92
|
size: 16
|
|
93
93
|
})), te = l(() => Ce?.statusIcon ?? !1), I = l(() => F?.validateState || ""), ae = l(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { shallowRef as B, ref as L, computed as c, watch as G } from "vue";
|
|
2
2
|
import { EVENT_CODE as g } from "../../../constants/aria.js";
|
|
3
|
-
import { CHANGE_EVENT as i,
|
|
3
|
+
import { CHANGE_EVENT as i, INPUT_EVENT as H, UPDATE_MODEL_EVENT as d } from "../../../constants/event.js";
|
|
4
4
|
import "@vueuse/core";
|
|
5
5
|
import { isUndefined as K } from "@vft/utils";
|
|
6
6
|
import { debugWarn as C } from "../../../utils/error.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineComponent as Q, computed as v, ref as re, unref as c, useSlots as oe, createVNode as s, mergeProps as L, withDirectives as ie, vShow as ne,
|
|
1
|
+
import { defineComponent as Q, computed as v, ref as re, unref as c, useSlots as oe, createVNode as s, mergeProps as L, withDirectives as ie, vShow as ne, isVNode as le, createTextVNode as G, resolveComponent as V } from "vue";
|
|
2
2
|
import "../alert/index.js";
|
|
3
3
|
import "../avatar/index.js";
|
|
4
4
|
import "../avatar-stack/index.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isNumber as n } from "@vft/utils";
|
|
2
|
-
import {
|
|
2
|
+
import { FormCompEnum as e, isInput as u } from "../component-map.js";
|
|
3
3
|
function T(r, E = "") {
|
|
4
4
|
return E = (E || "").replace(":", "") || "", [
|
|
5
5
|
e.INPUT,
|
|
@@ -95,6 +95,9 @@ export declare const VftUpload: import("vft/es/utils").SFCWithInstall<{
|
|
|
95
95
|
onSizeInvalid: {
|
|
96
96
|
type: import("vue").PropType<(file: File, width: number, height: number, expectedWidth: number, expectedHeight: number) => void>;
|
|
97
97
|
};
|
|
98
|
+
onTypeInvalid: {
|
|
99
|
+
type: import("vue").PropType<(file: File, acceptedTypes: string) => void>;
|
|
100
|
+
};
|
|
98
101
|
beforeUpload: {
|
|
99
102
|
type: import("vue").PropType<(rawFile: import("./types").UploadRawFile) => import("../types").Awaitable<void | undefined | null | boolean | File | Blob>>;
|
|
100
103
|
};
|
|
@@ -288,6 +291,9 @@ export declare const VftUpload: import("vft/es/utils").SFCWithInstall<{
|
|
|
288
291
|
onSizeInvalid: {
|
|
289
292
|
type: import("vue").PropType<(file: File, width: number, height: number, expectedWidth: number, expectedHeight: number) => void>;
|
|
290
293
|
};
|
|
294
|
+
onTypeInvalid: {
|
|
295
|
+
type: import("vue").PropType<(file: File, acceptedTypes: string) => void>;
|
|
296
|
+
};
|
|
291
297
|
beforeUpload: {
|
|
292
298
|
type: import("vue").PropType<(rawFile: import("./types").UploadRawFile) => import("../types").Awaitable<void | undefined | null | boolean | File | Blob>>;
|
|
293
299
|
};
|
|
@@ -478,6 +484,9 @@ export declare const VftUpload: import("vft/es/utils").SFCWithInstall<{
|
|
|
478
484
|
onSizeInvalid: {
|
|
479
485
|
type: import("vue").PropType<(file: File, width: number, height: number, expectedWidth: number, expectedHeight: number) => void>;
|
|
480
486
|
};
|
|
487
|
+
onTypeInvalid: {
|
|
488
|
+
type: import("vue").PropType<(file: File, acceptedTypes: string) => void>;
|
|
489
|
+
};
|
|
481
490
|
beforeUpload: {
|
|
482
491
|
type: import("vue").PropType<(rawFile: import("./types").UploadRawFile) => import("../types").Awaitable<void | undefined | null | boolean | File | Blob>>;
|
|
483
492
|
};
|
|
@@ -46,6 +46,8 @@ export interface UploadHooks {
|
|
|
46
46
|
onExceed: (files: File[], uploadFiles: UploadUserFile[]) => void;
|
|
47
47
|
/** 文件大小超出限制时的回调 */
|
|
48
48
|
onSizeExceed?: (file: File, maxSize: number) => void;
|
|
49
|
+
/** 文件类型不符合要求时的回调 */
|
|
50
|
+
onTypeInvalid?: (file: File, acceptedTypes: string) => void;
|
|
49
51
|
}
|
|
50
52
|
export interface UploadBasicProps {
|
|
51
53
|
action?: string;
|
|
@@ -77,6 +79,8 @@ export interface UploadBasicProps {
|
|
|
77
79
|
sizeHeight?: number;
|
|
78
80
|
/** 尺寸不符合时的回调函数 */
|
|
79
81
|
onSizeInvalid?: (file: File, width: number, height: number, expectedWidth: number, expectedHeight: number) => void;
|
|
82
|
+
/** 文件类型不符合要求时的回调 */
|
|
83
|
+
onTypeInvalid?: (file: File, acceptedTypes: string) => void;
|
|
80
84
|
}
|
|
81
85
|
export interface UploadEventProps {
|
|
82
86
|
beforeUpload?: UploadHooks['beforeUpload'];
|
|
@@ -90,6 +94,7 @@ export interface UploadEventProps {
|
|
|
90
94
|
onExceed?: UploadHooks['onExceed'];
|
|
91
95
|
onSizeExceed?: UploadHooks['onSizeExceed'];
|
|
92
96
|
onSizeInvalid?: UploadBasicProps['onSizeInvalid'];
|
|
97
|
+
onTypeInvalid?: UploadBasicProps['onTypeInvalid'];
|
|
93
98
|
}
|
|
94
99
|
export interface UploadContentEventProps {
|
|
95
100
|
beforeUpload?: UploadHooks['beforeUpload'];
|
|
@@ -100,6 +105,7 @@ export interface UploadContentEventProps {
|
|
|
100
105
|
onError?: (err: UploadAjaxError, rawFile: UploadRawFile) => void;
|
|
101
106
|
onExceed?: UploadHooks['onExceed'];
|
|
102
107
|
onSizeExceed?: UploadHooks['onSizeExceed'];
|
|
108
|
+
onTypeInvalid?: UploadHooks['onTypeInvalid'];
|
|
103
109
|
}
|
|
104
110
|
export interface UploadContentBasicProps extends Omit<UploadBasicProps, 'fileList'> {
|
|
105
111
|
fileList?: UploadUserFile[];
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { defineComponent as
|
|
1
|
+
import { defineComponent as F, shallowRef as I, createElementBlock as W, openBlock as q, withKeys as $, normalizeClass as x, withModifiers as T, unref as y, createBlock as A, renderSlot as w, createElementVNode as N, withCtx as X, nextTick as G } from "vue";
|
|
2
2
|
import "../form/index.js";
|
|
3
3
|
import "@vueuse/core";
|
|
4
|
-
import { isObject as
|
|
5
|
-
import { debugWarn as
|
|
4
|
+
import { isObject as L, entriesOf as J } from "@vft/utils";
|
|
5
|
+
import { debugWarn as Q } from "../../utils/error.js";
|
|
6
6
|
import "../config-provider/hooks/use-global-config.js";
|
|
7
|
-
import { cloneDeep as
|
|
8
|
-
import { useNamespace as
|
|
7
|
+
import { cloneDeep as O, isEqual as Y } from "lodash-es";
|
|
8
|
+
import { useNamespace as Z } from "../../hooks/use-namespace/index.js";
|
|
9
9
|
import "../../hooks/use-model-toggle/index.js";
|
|
10
10
|
import "@popperjs/core";
|
|
11
11
|
import "../../hooks/use-z-index/index.js";
|
|
12
|
-
import { ajaxUpload as
|
|
13
|
-
import { genFileId as
|
|
14
|
-
import
|
|
15
|
-
import { isImageOrVideo as
|
|
16
|
-
import { useFormDisabled as
|
|
17
|
-
import { useFormItem as
|
|
18
|
-
const
|
|
12
|
+
import { ajaxUpload as ee } from "./ajax.js";
|
|
13
|
+
import { genFileId as te } from "./constants.js";
|
|
14
|
+
import oe from "./upload-dragger.vue2.js";
|
|
15
|
+
import { validateFileType as _, isImageOrVideo as ae, validateFileSize as ne } from "./utils.js";
|
|
16
|
+
import { useFormDisabled as ie } from "../form/hooks/use-form-common-props.js";
|
|
17
|
+
import { useFormItem as le } from "../form/hooks/use-form-item.js";
|
|
18
|
+
const se = ["onKeydown"], re = ["name", "multiple", "accept"], de = F({
|
|
19
19
|
name: "VftUploadContent",
|
|
20
20
|
inheritAttrs: !1
|
|
21
|
-
}),
|
|
22
|
-
...
|
|
21
|
+
}), Ie = /* @__PURE__ */ F({
|
|
22
|
+
...de,
|
|
23
23
|
props: {
|
|
24
24
|
fileList: { default: [] },
|
|
25
25
|
replaceOnLimit: { type: Boolean, default: !1 },
|
|
@@ -36,7 +36,7 @@ const ne = ["onKeydown"], ie = ["name", "multiple", "accept"], se = O({
|
|
|
36
36
|
type: { default: "select" },
|
|
37
37
|
autoUpload: { type: Boolean, default: !1 },
|
|
38
38
|
listType: { default: "text" },
|
|
39
|
-
httpRequest: { type: Function, default:
|
|
39
|
+
httpRequest: { type: Function, default: ee },
|
|
40
40
|
disabled: { type: Boolean },
|
|
41
41
|
limit: {},
|
|
42
42
|
maxSize: { default: void 0 },
|
|
@@ -44,6 +44,7 @@ const ne = ["onKeydown"], ie = ["name", "multiple", "accept"], se = O({
|
|
|
44
44
|
sizeWidth: { default: void 0 },
|
|
45
45
|
sizeHeight: { default: void 0 },
|
|
46
46
|
onSizeInvalid: {},
|
|
47
|
+
onTypeInvalid: {},
|
|
47
48
|
beforeUpload: {},
|
|
48
49
|
onRemove: {},
|
|
49
50
|
onStart: {},
|
|
@@ -53,158 +54,167 @@ const ne = ["onKeydown"], ie = ["name", "multiple", "accept"], se = O({
|
|
|
53
54
|
onExceed: {},
|
|
54
55
|
onSizeExceed: {}
|
|
55
56
|
},
|
|
56
|
-
setup(
|
|
57
|
-
const
|
|
57
|
+
setup(P, { expose: D }) {
|
|
58
|
+
const l = P, g = Z("upload"), k = ie(), { formItem: K } = le(), c = I(
|
|
58
59
|
{}
|
|
59
|
-
),
|
|
60
|
+
), v = I(), B = async (e) => {
|
|
60
61
|
if (e.length === 0) return;
|
|
61
62
|
const {
|
|
62
|
-
autoUpload:
|
|
63
|
+
autoUpload: o,
|
|
63
64
|
limit: a,
|
|
64
|
-
fileList:
|
|
65
|
-
multiple:
|
|
66
|
-
onStart:
|
|
67
|
-
onExceed:
|
|
68
|
-
replaceOnLimit:
|
|
65
|
+
fileList: i,
|
|
66
|
+
multiple: u,
|
|
67
|
+
onStart: p,
|
|
68
|
+
onExceed: z,
|
|
69
|
+
replaceOnLimit: E,
|
|
69
70
|
maxSize: r,
|
|
70
|
-
onSizeExceed:
|
|
71
|
-
sizeWidth:
|
|
72
|
-
sizeHeight:
|
|
73
|
-
onSizeInvalid: d
|
|
74
|
-
|
|
71
|
+
onSizeExceed: b,
|
|
72
|
+
sizeWidth: m,
|
|
73
|
+
sizeHeight: h,
|
|
74
|
+
onSizeInvalid: d,
|
|
75
|
+
accept: s,
|
|
76
|
+
onTypeInvalid: f
|
|
77
|
+
} = l;
|
|
78
|
+
if (s) {
|
|
79
|
+
const n = e.filter((t) => !_(t, s));
|
|
80
|
+
if (n.length > 0 && (n.forEach((t) => {
|
|
81
|
+
f && f(t, s);
|
|
82
|
+
}), e = e.filter((t) => _(t, s)), e.length === 0))
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
75
85
|
if (r) {
|
|
76
|
-
const
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
}), e = e.filter((
|
|
86
|
+
const n = e.filter((t) => t.size > r);
|
|
87
|
+
if (n.length > 0 && (n.forEach((t) => {
|
|
88
|
+
b && b(t, r);
|
|
89
|
+
}), e = e.filter((t) => t.size <= r), e.length === 0))
|
|
80
90
|
return;
|
|
81
91
|
}
|
|
82
|
-
if (
|
|
83
|
-
const
|
|
84
|
-
for (const
|
|
85
|
-
if (
|
|
92
|
+
if (m && h) {
|
|
93
|
+
const n = [];
|
|
94
|
+
for (const t of e)
|
|
95
|
+
if (ae(t))
|
|
86
96
|
try {
|
|
87
|
-
const { isValid:
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
97
|
+
const { isValid: S, width: H, height: M } = await ne(
|
|
98
|
+
t,
|
|
99
|
+
m,
|
|
100
|
+
h
|
|
91
101
|
);
|
|
92
|
-
|
|
93
|
-
} catch (
|
|
94
|
-
console.error("尺寸校验失败:",
|
|
102
|
+
S ? n.push(t) : d && d(t, H, M, m, h);
|
|
103
|
+
} catch (S) {
|
|
104
|
+
console.error("尺寸校验失败:", S);
|
|
95
105
|
}
|
|
96
106
|
else
|
|
97
|
-
|
|
98
|
-
if (e =
|
|
107
|
+
n.push(t);
|
|
108
|
+
if (e = n, e.length === 0) return;
|
|
99
109
|
}
|
|
100
|
-
if (a &&
|
|
101
|
-
|
|
110
|
+
if (a && i && i.length + e.length > a && !(a === 1 && E)) {
|
|
111
|
+
z?.(e, i);
|
|
102
112
|
return;
|
|
103
113
|
}
|
|
104
|
-
|
|
105
|
-
for (const
|
|
106
|
-
const
|
|
107
|
-
|
|
114
|
+
u || (e = e.slice(0, 1));
|
|
115
|
+
for (const n of e) {
|
|
116
|
+
const t = n;
|
|
117
|
+
t.uid = te(), p?.(t), o && C(t);
|
|
108
118
|
}
|
|
109
|
-
},
|
|
110
|
-
if (
|
|
111
|
-
return
|
|
112
|
-
let
|
|
119
|
+
}, C = async (e) => {
|
|
120
|
+
if (v.value.value = "", !l.beforeUpload)
|
|
121
|
+
return R(e);
|
|
122
|
+
let o, a = {};
|
|
113
123
|
try {
|
|
114
|
-
const
|
|
115
|
-
a =
|
|
124
|
+
const u = l.data, p = l.beforeUpload(e);
|
|
125
|
+
a = L(l.data) ? O(l.data) : l.data, o = await p, L(l.data) && Y(u, a) && (a = O(l.data));
|
|
116
126
|
} catch {
|
|
117
|
-
|
|
127
|
+
o = !1;
|
|
118
128
|
}
|
|
119
|
-
if (
|
|
120
|
-
|
|
129
|
+
if (o === !1) {
|
|
130
|
+
l.onRemove?.(e);
|
|
121
131
|
return;
|
|
122
132
|
}
|
|
123
|
-
let
|
|
124
|
-
|
|
133
|
+
let i = e;
|
|
134
|
+
o instanceof Blob && (o instanceof File ? i = o : i = new File([o], e.name, {
|
|
125
135
|
type: e.type
|
|
126
|
-
})),
|
|
127
|
-
},
|
|
136
|
+
})), R(Object.assign(i, { uid: e.uid }), a);
|
|
137
|
+
}, R = (e, o) => {
|
|
128
138
|
const {
|
|
129
139
|
headers: a,
|
|
130
|
-
data:
|
|
131
|
-
method:
|
|
132
|
-
withCredentials:
|
|
133
|
-
name:
|
|
134
|
-
action:
|
|
140
|
+
data: i,
|
|
141
|
+
method: u,
|
|
142
|
+
withCredentials: p,
|
|
143
|
+
name: z,
|
|
144
|
+
action: E,
|
|
135
145
|
onProgress: r,
|
|
136
|
-
onSuccess:
|
|
137
|
-
onError:
|
|
138
|
-
httpRequest:
|
|
139
|
-
} =
|
|
146
|
+
onSuccess: b,
|
|
147
|
+
onError: m,
|
|
148
|
+
httpRequest: h
|
|
149
|
+
} = l, { uid: d } = e, s = {
|
|
140
150
|
headers: a || {},
|
|
141
|
-
withCredentials:
|
|
151
|
+
withCredentials: p,
|
|
142
152
|
file: e,
|
|
143
|
-
data:
|
|
144
|
-
method:
|
|
145
|
-
filename:
|
|
146
|
-
action:
|
|
147
|
-
onProgress: (
|
|
148
|
-
r?.(
|
|
153
|
+
data: o ?? (i || {}),
|
|
154
|
+
method: u,
|
|
155
|
+
filename: z,
|
|
156
|
+
action: E,
|
|
157
|
+
onProgress: (n) => {
|
|
158
|
+
r?.(n, e);
|
|
149
159
|
},
|
|
150
|
-
onSuccess: (
|
|
151
|
-
|
|
160
|
+
onSuccess: (n) => {
|
|
161
|
+
b?.(n, e), delete c.value[d];
|
|
152
162
|
},
|
|
153
|
-
onError: (
|
|
154
|
-
|
|
163
|
+
onError: (n) => {
|
|
164
|
+
m?.(n, e), delete c.value[d];
|
|
155
165
|
}
|
|
156
|
-
},
|
|
157
|
-
|
|
158
|
-
},
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
166
|
+
}, f = h(s);
|
|
167
|
+
c.value[d] = f, f instanceof Promise && f.then(s.onSuccess, s.onError);
|
|
168
|
+
}, V = async (e) => {
|
|
169
|
+
const o = e.target.files;
|
|
170
|
+
o && (await B(Array.from(o)), G(() => {
|
|
171
|
+
K?.validate("change").catch((a) => Q(a));
|
|
162
172
|
}));
|
|
163
|
-
},
|
|
164
|
-
|
|
165
|
-
},
|
|
166
|
-
|
|
173
|
+
}, U = () => {
|
|
174
|
+
k.value || (v.value.value = "", v.value.click());
|
|
175
|
+
}, j = () => {
|
|
176
|
+
U();
|
|
167
177
|
};
|
|
168
|
-
return
|
|
178
|
+
return D({
|
|
169
179
|
abort: (e) => {
|
|
170
|
-
|
|
180
|
+
J(c.value).filter(
|
|
171
181
|
e ? ([a]) => String(e.uid) === a : () => !0
|
|
172
|
-
).forEach(([a,
|
|
173
|
-
|
|
182
|
+
).forEach(([a, i]) => {
|
|
183
|
+
i instanceof XMLHttpRequest && i.abort(), delete c.value[a];
|
|
174
184
|
});
|
|
175
185
|
},
|
|
176
|
-
upload:
|
|
177
|
-
}), (e,
|
|
178
|
-
class:
|
|
186
|
+
upload: C
|
|
187
|
+
}), (e, o) => (q(), W("div", {
|
|
188
|
+
class: x([y(g).b(), y(g).m(e.listType), y(g).is("drag", e.drag)]),
|
|
179
189
|
tabindex: "0",
|
|
180
|
-
onClick:
|
|
181
|
-
onKeydown:
|
|
190
|
+
onClick: U,
|
|
191
|
+
onKeydown: $(T(j, ["self"]), ["enter", "space"])
|
|
182
192
|
}, [
|
|
183
|
-
e.drag ? (
|
|
193
|
+
e.drag ? (q(), A(oe, {
|
|
184
194
|
key: 0,
|
|
185
|
-
disabled:
|
|
186
|
-
onFile:
|
|
195
|
+
disabled: y(k),
|
|
196
|
+
onFile: o[0] || (o[0] = (a) => B(a.file))
|
|
187
197
|
}, {
|
|
188
|
-
default:
|
|
198
|
+
default: X(() => [
|
|
189
199
|
w(e.$slots, "default")
|
|
190
200
|
]),
|
|
191
201
|
_: 3
|
|
192
202
|
}, 8, ["disabled"])) : w(e.$slots, "default", { key: 1 }),
|
|
193
|
-
|
|
203
|
+
N("input", {
|
|
194
204
|
ref_key: "inputRef",
|
|
195
|
-
ref:
|
|
196
|
-
class:
|
|
205
|
+
ref: v,
|
|
206
|
+
class: x(y(g).e("input")),
|
|
197
207
|
name: e.name,
|
|
198
208
|
multiple: e.multiple,
|
|
199
209
|
accept: e.accept,
|
|
200
210
|
type: "file",
|
|
201
|
-
onChange:
|
|
202
|
-
onClick:
|
|
211
|
+
onChange: V,
|
|
212
|
+
onClick: o[1] || (o[1] = T(() => {
|
|
203
213
|
}, ["stop"]))
|
|
204
|
-
}, null, 42,
|
|
205
|
-
], 42,
|
|
214
|
+
}, null, 42, re)
|
|
215
|
+
], 42, se));
|
|
206
216
|
}
|
|
207
217
|
});
|
|
208
218
|
export {
|
|
209
|
-
|
|
219
|
+
Ie as default
|
|
210
220
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { defineComponent as L, useSlots as j, shallowRef as N, computed as
|
|
1
|
+
import { defineComponent as L, useSlots as j, shallowRef as N, computed as z, onBeforeUnmount as O, provide as q, toRef as D, createElementBlock as H, openBlock as c, normalizeClass as K, unref as o, createBlock as y, createCommentVNode as s, renderSlot as n, createSlots as B, withCtx as f, createVNode as W, mergeProps as C } from "vue";
|
|
2
2
|
import "../form/index.js";
|
|
3
|
-
import { VftMessage as
|
|
3
|
+
import { VftMessage as g } from "../message/index.js";
|
|
4
4
|
import { ajaxUpload as A } from "./ajax.js";
|
|
5
5
|
import { uploadContextKey as G } from "./constants.js";
|
|
6
6
|
import E from "./upload-content.vue2.js";
|
|
@@ -35,6 +35,7 @@ const X = L({
|
|
|
35
35
|
sizeWidth: { default: void 0 },
|
|
36
36
|
sizeHeight: { default: void 0 },
|
|
37
37
|
onSizeInvalid: {},
|
|
38
|
+
onTypeInvalid: {},
|
|
38
39
|
beforeUpload: {},
|
|
39
40
|
beforeRemove: {},
|
|
40
41
|
onRemove: {},
|
|
@@ -47,30 +48,30 @@ const X = L({
|
|
|
47
48
|
} },
|
|
48
49
|
onSizeExceed: {}
|
|
49
50
|
},
|
|
50
|
-
setup(
|
|
51
|
-
const t =
|
|
52
|
-
abort:
|
|
53
|
-
submit:
|
|
54
|
-
clearFiles:
|
|
55
|
-
uploadFiles:
|
|
51
|
+
setup(I, { expose: P }) {
|
|
52
|
+
const t = I, i = j(), v = Q(), u = N(), {
|
|
53
|
+
abort: h,
|
|
54
|
+
submit: w,
|
|
55
|
+
clearFiles: $,
|
|
56
|
+
uploadFiles: r,
|
|
56
57
|
handleStart: S,
|
|
57
|
-
handleError:
|
|
58
|
+
handleError: M,
|
|
58
59
|
handleRemove: p,
|
|
59
|
-
handleSuccess:
|
|
60
|
-
handleProgress:
|
|
61
|
-
} = J(t, u), m =
|
|
62
|
-
abort:
|
|
63
|
-
submit:
|
|
64
|
-
clearFiles:
|
|
65
|
-
uploadFiles:
|
|
60
|
+
handleSuccess: T,
|
|
61
|
+
handleProgress: U
|
|
62
|
+
} = J(t, u), m = z(() => t.listType === "picture-card"), V = {
|
|
63
|
+
abort: h,
|
|
64
|
+
submit: w,
|
|
65
|
+
clearFiles: $,
|
|
66
|
+
uploadFiles: r,
|
|
66
67
|
uploadRef: u
|
|
67
|
-
},
|
|
68
|
+
}, k = z(() => ({
|
|
68
69
|
...t,
|
|
69
|
-
fileList:
|
|
70
|
+
fileList: r.value,
|
|
70
71
|
onStart: S,
|
|
71
|
-
onProgress:
|
|
72
|
-
onSuccess:
|
|
73
|
-
onError:
|
|
72
|
+
onProgress: U,
|
|
73
|
+
onSuccess: T,
|
|
74
|
+
onError: M,
|
|
74
75
|
onRemove: p,
|
|
75
76
|
onChange: (e, l) => {
|
|
76
77
|
t.onChange?.(e, l, V);
|
|
@@ -80,31 +81,39 @@ const X = L({
|
|
|
80
81
|
t.onSizeExceed?.(e, l);
|
|
81
82
|
else {
|
|
82
83
|
const d = `文件大小不能超过 ${(l / 1048576).toFixed(2)}MB`;
|
|
83
|
-
console.warn("默认文件大小超出提示:", d),
|
|
84
|
+
console.warn("默认文件大小超出提示:", d), g.warning(d);
|
|
84
85
|
}
|
|
85
86
|
},
|
|
86
|
-
onSizeInvalid: (e, l,
|
|
87
|
+
onSizeInvalid: (e, l, a, d, R) => {
|
|
87
88
|
if (t.onSizeInvalid)
|
|
88
|
-
t.onSizeInvalid(e, l,
|
|
89
|
+
t.onSizeInvalid(e, l, a, d, R);
|
|
89
90
|
else {
|
|
90
|
-
const
|
|
91
|
-
console.warn("默认尺寸校验提示:",
|
|
91
|
+
const b = `文件尺寸不符合要求,当前尺寸:${l}x${a},期望尺寸:${d}x${R}`;
|
|
92
|
+
console.warn("默认尺寸校验提示:", b), g.warning(b);
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
onTypeInvalid: (e, l) => {
|
|
96
|
+
if (t.onTypeInvalid)
|
|
97
|
+
t.onTypeInvalid(e, l);
|
|
98
|
+
else {
|
|
99
|
+
const a = `文件类型不符合要求,当前文件:${e.name},支持的类型:${l}`;
|
|
100
|
+
console.warn("默认文件类型校验提示:", a), g.warning(a);
|
|
92
101
|
}
|
|
93
102
|
}
|
|
94
103
|
}));
|
|
95
104
|
return O(() => {
|
|
96
|
-
|
|
105
|
+
r.value.forEach(({ url: e }) => {
|
|
97
106
|
e?.startsWith("blob:") && URL.revokeObjectURL(e);
|
|
98
107
|
});
|
|
99
108
|
}), q(G, {
|
|
100
109
|
accept: D(t, "accept")
|
|
101
|
-
}),
|
|
102
|
-
abort:
|
|
103
|
-
submit:
|
|
104
|
-
clearFiles:
|
|
110
|
+
}), P({
|
|
111
|
+
abort: h,
|
|
112
|
+
submit: w,
|
|
113
|
+
clearFiles: $,
|
|
105
114
|
handleStart: S,
|
|
106
115
|
handleRemove: p,
|
|
107
|
-
fileList:
|
|
116
|
+
fileList: r
|
|
108
117
|
}), (e, l) => (c(), H("div", {
|
|
109
118
|
class: K(["vft-upload-wrapper", { disabled: o(v) }])
|
|
110
119
|
}, [
|
|
@@ -112,18 +121,18 @@ const X = L({
|
|
|
112
121
|
key: 0,
|
|
113
122
|
disabled: o(v),
|
|
114
123
|
"list-type": e.listType,
|
|
115
|
-
files: o(
|
|
124
|
+
files: o(r),
|
|
116
125
|
"handle-preview": e.onPreview,
|
|
117
126
|
onRemove: o(p)
|
|
118
|
-
},
|
|
127
|
+
}, B({
|
|
119
128
|
append: f(() => [
|
|
120
|
-
W(E,
|
|
129
|
+
W(E, C({
|
|
121
130
|
ref_key: "uploadRef",
|
|
122
131
|
ref: u
|
|
123
|
-
},
|
|
132
|
+
}, k.value), {
|
|
124
133
|
default: f(() => [
|
|
125
|
-
o(
|
|
126
|
-
!o(
|
|
134
|
+
o(i).trigger ? n(e.$slots, "trigger", { key: 0 }) : s("", !0),
|
|
135
|
+
!o(i).trigger && o(i).default ? n(e.$slots, "default", { key: 1 }) : s("", !0)
|
|
127
136
|
]),
|
|
128
137
|
_: 3
|
|
129
138
|
}, 16)
|
|
@@ -132,41 +141,41 @@ const X = L({
|
|
|
132
141
|
}, [
|
|
133
142
|
e.$slots.file ? {
|
|
134
143
|
name: "default",
|
|
135
|
-
fn: f(({ file:
|
|
136
|
-
|
|
144
|
+
fn: f(({ file: a }) => [
|
|
145
|
+
n(e.$slots, "file", { file: a })
|
|
137
146
|
]),
|
|
138
147
|
key: "0"
|
|
139
148
|
} : void 0
|
|
140
|
-
]), 1032, ["disabled", "list-type", "files", "handle-preview", "onRemove"])) :
|
|
141
|
-
!m.value || m.value && !e.showFileList ? (c(), y(E,
|
|
149
|
+
]), 1032, ["disabled", "list-type", "files", "handle-preview", "onRemove"])) : s("", !0),
|
|
150
|
+
!m.value || m.value && !e.showFileList ? (c(), y(E, C({
|
|
142
151
|
key: 1,
|
|
143
152
|
ref_key: "uploadRef",
|
|
144
153
|
ref: u
|
|
145
|
-
},
|
|
154
|
+
}, k.value), {
|
|
146
155
|
default: f(() => [
|
|
147
|
-
o(
|
|
148
|
-
!o(
|
|
156
|
+
o(i).trigger ? n(e.$slots, "trigger", { key: 0 }) : s("", !0),
|
|
157
|
+
!o(i).trigger && o(i).default ? n(e.$slots, "default", { key: 1 }) : s("", !0)
|
|
149
158
|
]),
|
|
150
159
|
_: 3
|
|
151
|
-
}, 16)) :
|
|
152
|
-
e.$slots.trigger ?
|
|
153
|
-
|
|
160
|
+
}, 16)) : s("", !0),
|
|
161
|
+
e.$slots.trigger ? n(e.$slots, "default", { key: 2 }) : s("", !0),
|
|
162
|
+
n(e.$slots, "tip"),
|
|
154
163
|
!m.value && e.showFileList ? (c(), y(F, {
|
|
155
164
|
key: 3,
|
|
156
165
|
disabled: o(v),
|
|
157
166
|
"list-type": e.listType,
|
|
158
|
-
files: o(
|
|
167
|
+
files: o(r),
|
|
159
168
|
"handle-preview": e.onPreview,
|
|
160
169
|
onRemove: o(p)
|
|
161
|
-
},
|
|
170
|
+
}, B({ _: 2 }, [
|
|
162
171
|
e.$slots.file ? {
|
|
163
172
|
name: "default",
|
|
164
|
-
fn: f(({ file:
|
|
165
|
-
|
|
173
|
+
fn: f(({ file: a }) => [
|
|
174
|
+
n(e.$slots, "file", { file: a })
|
|
166
175
|
]),
|
|
167
176
|
key: "0"
|
|
168
177
|
} : void 0
|
|
169
|
-
]), 1032, ["disabled", "list-type", "files", "handle-preview", "onRemove"])) :
|
|
178
|
+
]), 1032, ["disabled", "list-type", "files", "handle-preview", "onRemove"])) : s("", !0)
|
|
170
179
|
], 2));
|
|
171
180
|
}
|
|
172
181
|
});
|
|
@@ -25,3 +25,10 @@ export declare function validateFileSize(file: File, expectedWidth: number, expe
|
|
|
25
25
|
* @returns boolean
|
|
26
26
|
*/
|
|
27
27
|
export declare function isImageOrVideo(file: File): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* 验证文件类型是否符合accept属性要求
|
|
30
|
+
* @param file 文件对象
|
|
31
|
+
* @param accept accept属性值,如 "image/*,.pdf,.doc"
|
|
32
|
+
* @returns boolean
|
|
33
|
+
*/
|
|
34
|
+
export declare function validateFileType(file: File, accept: string): boolean;
|
|
@@ -1,40 +1,53 @@
|
|
|
1
|
-
function
|
|
2
|
-
return new Promise((n,
|
|
3
|
-
const
|
|
4
|
-
if (!
|
|
5
|
-
|
|
1
|
+
function o(r) {
|
|
2
|
+
return new Promise((n, s) => {
|
|
3
|
+
const e = r.type.startsWith("image/"), i = r.type.startsWith("video/");
|
|
4
|
+
if (!e && !i) {
|
|
5
|
+
s(new Error("文件类型不支持尺寸校验"));
|
|
6
6
|
return;
|
|
7
7
|
}
|
|
8
|
-
if (
|
|
8
|
+
if (e) {
|
|
9
9
|
const t = new Image();
|
|
10
10
|
t.onload = () => {
|
|
11
11
|
n({ width: t.naturalWidth, height: t.naturalHeight });
|
|
12
12
|
}, t.onerror = () => {
|
|
13
|
-
|
|
14
|
-
}, t.src = URL.createObjectURL(
|
|
15
|
-
} else if (
|
|
13
|
+
s(new Error("图片加载失败"));
|
|
14
|
+
}, t.src = URL.createObjectURL(r);
|
|
15
|
+
} else if (i) {
|
|
16
16
|
const t = document.createElement("video");
|
|
17
17
|
t.onloadedmetadata = () => {
|
|
18
18
|
n({ width: t.videoWidth, height: t.videoHeight }), URL.revokeObjectURL(t.src);
|
|
19
19
|
}, t.onerror = () => {
|
|
20
|
-
|
|
21
|
-
}, t.src = URL.createObjectURL(
|
|
20
|
+
s(new Error("视频加载失败")), URL.revokeObjectURL(t.src);
|
|
21
|
+
}, t.src = URL.createObjectURL(r);
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
|
-
async function
|
|
25
|
+
async function a(r, n, s) {
|
|
26
26
|
try {
|
|
27
|
-
const { width:
|
|
28
|
-
return { isValid:
|
|
29
|
-
} catch (
|
|
30
|
-
return console.error("尺寸校验失败:",
|
|
27
|
+
const { width: e, height: i } = await o(r);
|
|
28
|
+
return { isValid: e === n && i === s, width: e, height: i };
|
|
29
|
+
} catch (e) {
|
|
30
|
+
return console.error("尺寸校验失败:", e), { isValid: !1, width: 0, height: 0 };
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
function c(
|
|
34
|
-
return
|
|
33
|
+
function c(r) {
|
|
34
|
+
return r.type.startsWith("image/") || r.type.startsWith("video/");
|
|
35
|
+
}
|
|
36
|
+
function d(r, n) {
|
|
37
|
+
return n ? n.split(",").map((e) => e.trim()).some((e) => {
|
|
38
|
+
if (e.startsWith(".")) {
|
|
39
|
+
const i = e.toLowerCase();
|
|
40
|
+
return r.name.toLowerCase().endsWith(i);
|
|
41
|
+
} else if (e.includes("/*")) {
|
|
42
|
+
const i = e.replace("/*", "");
|
|
43
|
+
return r.type.startsWith(i + "/");
|
|
44
|
+
} else
|
|
45
|
+
return r.type === e;
|
|
46
|
+
}) : !0;
|
|
35
47
|
}
|
|
36
48
|
export {
|
|
37
|
-
|
|
49
|
+
o as getFileDimensions,
|
|
38
50
|
c as isImageOrVideo,
|
|
39
|
-
|
|
51
|
+
a as validateFileSize,
|
|
52
|
+
d as validateFileType
|
|
40
53
|
};
|
package/es/package.json.d.ts
CHANGED
package/es/package.json.js
CHANGED
package/es/utils/vue/vnode.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isArray as E, hasOwn as m, camelize as N } from "@vft/utils";
|
|
2
2
|
import { isVNode as o, Fragment as S, Comment as A, Text as s, createCommentVNode as L, createBlock as _, openBlock as C } from "vue";
|
|
3
3
|
import { debugWarn as O } from "../error.js";
|
|
4
4
|
const R = "utils/vue/vnode";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue");require("../form/index.cjs");const k=require("../icon/index.cjs"),Y=require("@vueuse/core"),s=require("@vft/utils"),T=require("../../utils/error.cjs");require("../config-provider/hooks/use-global-config.cjs");const Be=require("lodash-es"),Z=require("../../hooks/use-namespace/index.cjs");require("../../hooks/use-model-toggle/index.cjs");require("@popperjs/core");require("../../hooks/use-z-index/index.cjs");const q=require("@vft/constants"),_=require("@vft/use"),ee=require("./utils.cjs"),te=require("../form/hooks/use-form-item.cjs"),oe=require("../form/hooks/use-form-common-props.cjs"),Ve=["role"],Ie=["id","type","disabled","formatter","parser","readonly","autocomplete","tabindex","aria-label","placeholder","form"],Se=["id","tabindex","disabled","readonly","autocomplete","aria-label","placeholder","form"],ze=e.defineComponent({__name:"input",props:{id:{},size:{default:""},disabled:{type:Boolean},modelValue:{},type:{default:"text"},resize:{},autosize:{type:[Object,Boolean],default:!1},autocomplete:{default:"off"},formatter:{},parser:{},placeholder:{},form:{},readonly:{type:Boolean},clearable:{type:Boolean},showPassword:{type:Boolean},showWordLimit:{type:Boolean},suffixIcon:{},prefixIcon:{},clearIcon:{},containerRole:{},label:{},tabindex:{default:0},validateEvent:{type:Boolean,default:!0},inputStyle:{type:[Boolean,null,String,Object,Array]}},emits:{[q.UPDATE_MODEL_EVENT]:t=>s.isString(t),input:t=>s.isString(t),change:t=>s.isString(t),suffixClick:t=>s.isString(t),prefixClick:t=>s.isString(t),focus:t=>t instanceof FocusEvent,blur:t=>t instanceof FocusEvent,clear:()=>!0,enter:()=>!0,mouseleave:t=>t instanceof MouseEvent,mouseenter:t=>t instanceof MouseEvent,keydown:t=>t instanceof Event,compositionstart:t=>t instanceof CompositionEvent,compositionupdate:t=>t instanceof CompositionEvent,compositionend:t=>t instanceof CompositionEvent},setup(t,{expose:ne,emit:ae}){const l=ae,v=e.useAttrs(),i=e.useSlots(),M=e.computed(()=>{const o={};return t.containerRole==="combobox"&&(o["aria-haspopup"]=v["aria-haspopup"],o["aria-owns"]=v["aria-owns"],o["aria-expanded"]=v["aria-expanded"]),o}),le=e.computed(()=>[t.type==="textarea"?A.b():n.b(),n.m(ie.value),n.is("disabled",m.value),n.is("exceed",fe.value),n.is("focus",c.value),{[n.b("group")]:i.prepend||i.append,[n.bm("group","append")]:i.append,[n.bm("group","prepend")]:i.prepend,[n.m("prefix")]:i.prefix||t.prefixIcon,[n.m("suffix")]:i.suffix||t.suffixIcon||t.clearable||t.showPassword,[n.bm("suffix","password-clear")]:E.value&&z.value},v.class]),se=e.getCurrentInstance(),re=e.computed(()=>[n.e("wrapper"),n.is("focus",c.value)]),r=_.useAttrs({excludeKeys:e.computed(()=>Object.keys(M.value))}),{form:ue,formItem:C}=te.useFormItem(),{inputId:F}=te.useFormItemInputId(se.props,{formItemContext:C}),ie=oe.useFormSize(),m=oe.useFormDisabled(),n=Z.useNamespace("input"),A=Z.useNamespace("textarea"),w=e.shallowRef(),f=e.shallowRef(),c=e.ref(!1),V=e.ref(!1),y=e.ref(!1),x=e.ref(!1),D=e.ref(),I=e.shallowRef(t.inputStyle),h=e.computed(()=>w.value||f.value),S=e.computed(()=>s.singleAttrToObj(t.prefixIcon,"icon",{size:16})),O=e.computed(()=>s.singleAttrToObj(t.suffixIcon,"icon",{size:16})),ce=e.computed(()=>s.singleAttrToObj(t.clearIcon,"icon",{icon:"icon-circle-close",size:16})),R=e.computed(()=>ue?.statusIcon??!1),g=e.computed(()=>C?.validateState||""),K=e.computed(()=>g.value&&{validating:"icon-loading",success:"icon-circle-check",error:"icon-circle-close"}[g.value]),de=e.computed(()=>x.value?{icon:"icon-view",size:16}:{icon:"icon-hide",size:16}),me=e.computed(()=>[v.style,t.inputStyle]),$=e.computed(()=>[t.inputStyle,I.value,{resize:t.resize}]),u=e.computed(()=>Be.isNil(t.modelValue)?"":String(t.modelValue)),E=e.computed(()=>t.clearable&&!m.value&&!t.readonly&&!!u.value&&(c.value||V.value)),z=e.computed(()=>t.showPassword&&!m.value&&!t.readonly&&!!u.value&&(!!u.value||c.value)),p=e.computed(()=>t.showWordLimit&&!!r.value.maxlength&&(t.type==="text"||t.type==="textarea")&&!m.value&&!t.readonly&&!t.showPassword),N=e.computed(()=>Array.from(u.value).length),fe=e.computed(()=>!!p.value&&N.value>Number(r.value.maxlength)),pe=e.computed(()=>!!i.suffix||!!t.suffixIcon||E.value||t.showPassword||p.value||!!g.value&&R.value),[ve,ye]=_.useCursor(w);Y.useResizeObserver(f,o=>{if(!p.value||t.resize!=="both")return;const a=o[0],{width:d}=a.contentRect;D.value={right:`calc(100% - ${d+15+6}px)`}});const B=()=>{if(!(!Y.isClient||t.type!=="textarea"))if(t.autosize){const o=s.isObject(t.autosize)?t.autosize.minRows:void 0,a=s.isObject(t.autosize)?t.autosize.maxRows:void 0;I.value={...ee.calcTextareaHeight(f.value,o,a)}}else I.value={minHeight:ee.calcTextareaHeight(f.value).minHeight}},b=()=>{const o=h.value;!o||o.value===u.value||(o.value=u.value)},P=async o=>{ve();let{value:a}=o.target;if(r.value.maxlength&&a.length>=r.value.maxlength&&(a=a.slice(0,Number(r.value.maxlength))),t.formatter&&(a=t.parser?t.parser(a):a,a=t.formatter(a)),!y.value){if(a===u.value){b();return}l(q.UPDATE_MODEL_EVENT,a),l("input",a),await e.nextTick(),b(),ye()}},j=o=>{l("change",o.target.value)},he=()=>{l("suffixClick",t.modelValue)},ge=()=>{l("prefixClick",t.modelValue)},L=o=>{l("compositionstart",o),y.value=!0},be=o=>/([(\uAC00-\uD7AF)|\u3130-\u318F])+/.test(o),W=o=>{l("compositionupdate",o);const a=o.target?.value,d=a[a.length-1]||"";y.value=!be(d)},H=o=>{l("compositionend",o),y.value&&(y.value=!1,P(o))},ke=()=>{x.value=!x.value,U()},U=async()=>{await e.nextTick(),h.value?.focus()},Ce=()=>h.value?.blur(),G=o=>{c.value=!0,l("focus",o)},J=o=>{c.value=!1,l("blur",o),t.validateEvent&&C?.validate?.("blur").catch(a=>T.debugWarn(a))},we=o=>{V.value=!1,l("mouseleave",o)},xe=o=>{V.value=!0,l("mouseenter",o)},Q=o=>{let a=o.key;if(o.target.type==="number"&&["e","+","-0","E"].includes(a))return o.returnValue=!1,!1;l("keydown",o)},Ee=()=>{h.value?.select()},X=()=>{l(q.UPDATE_MODEL_EVENT,""),l("change",""),l("clear"),l("input","")};return e.watch(()=>t.modelValue,()=>{e.nextTick(()=>B()),t.validateEvent&&C?.validate?.("change").catch(o=>T.debugWarn(o))}),e.watch(u,()=>b()),e.watch(()=>t.type,async()=>{await e.nextTick(),b(),B()}),e.onMounted(()=>{!t.formatter&&t.parser&&T.debugWarn("VftInput","If you set the parser, you also need to set the formatter."),b(),e.nextTick(B)}),ne({input:w,textarea:f,ref:h,textareaStyle:$,autosize:t.autosize,focus:U,blur:Ce,select:Ee,clear:X,resizeTextarea:B}),(o,a)=>e.withDirectives((e.openBlock(),e.createElementBlock("div",e.mergeProps(M.value,{class:le.value,style:me.value,role:o.containerRole,onMouseenter:xe,onMouseleave:we,onMousewheel:a[1]||(a[1]=d=>o.type==="number"&&c.value?d.preventDefault():null)}),[o.type!=="textarea"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[o.$slots.prepend?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(e.unref(n).be("group","prepend"))},[e.renderSlot(o.$slots,"prepend")],2)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:e.normalizeClass(re.value)},[o.$slots.prefix||S.value?.icon?(e.openBlock(),e.createElementBlock("span",{key:0,class:e.normalizeClass(e.unref(n).e("prefix"))},[e.createElementVNode("span",{class:e.normalizeClass(e.unref(n).e("prefix-inner")),onClick:ge},[e.renderSlot(o.$slots,"prefix"),S.value?.icon?(e.openBlock(),e.createBlock(e.unref(k.VftIcon),e.mergeProps({key:0,pointer:""},S.value,{class:e.unref(n).e("icon")}),null,16,["class"])):e.createCommentVNode("",!0)],2)],2)):e.createCommentVNode("",!0),e.createElementVNode("input",e.mergeProps({id:e.unref(F),ref_key:"input",ref:w,class:e.unref(n).e("inner")},e.unref(r),{type:o.showPassword?x.value?"text":"password":o.type,disabled:e.unref(m),formatter:o.formatter,parser:o.parser,readonly:o.readonly,autocomplete:o.autocomplete,tabindex:o.tabindex,"aria-label":o.label,placeholder:o.placeholder,style:o.inputStyle,form:o.form,onCompositionstart:L,onCompositionupdate:W,onCompositionend:H,onInput:P,onFocus:G,onBlur:J,onChange:j,onKeydown:Q,onKeyup:a[0]||(a[0]=e.withKeys(d=>l("enter"),["enter"]))}),null,16,Ie),pe.value?(e.openBlock(),e.createElementBlock("span",{key:1,class:e.normalizeClass(e.unref(n).e("suffix"))},[e.createElementVNode("span",{class:e.normalizeClass(e.unref(n).e("suffix-inner")),onClick:he},[!E.value||!z.value||!p.value?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[e.renderSlot(o.$slots,"suffix"),O.value?.icon?(e.openBlock(),e.createBlock(e.unref(k.VftIcon),e.mergeProps({key:0},O.value,{class:e.unref(n).e("icon")}),null,16,["class"])):e.createCommentVNode("",!0)],64)):e.createCommentVNode("",!0),E.value?(e.openBlock(),e.createBlock(e.unref(k.VftIcon),e.mergeProps({key:1,pointer:"",class:[e.unref(n).e("icon"),e.unref(n).e("clear")]},ce.value,{onMousedown:e.withModifiers(e.unref(s.noop),["prevent"]),onClick:e.withModifiers(X,["stop"])}),null,16,["class","onMousedown"])):e.createCommentVNode("",!0),z.value?(e.openBlock(),e.createBlock(e.unref(k.VftIcon),e.mergeProps({key:2},de.value,{class:[e.unref(n).e("icon"),e.unref(n).e("password")],onClick:ke}),null,16,["class"])):e.createCommentVNode("",!0),p.value?(e.openBlock(),e.createElementBlock("span",{key:3,class:e.normalizeClass(e.unref(n).e("count"))},[e.createElementVNode("span",{class:e.normalizeClass(e.unref(n).e("count-inner"))},e.toDisplayString(N.value)+" / "+e.toDisplayString(e.unref(r).maxlength),3)],2)):e.createCommentVNode("",!0),g.value&&K.value&&R.value?(e.openBlock(),e.createBlock(e.unref(k.VftIcon),{key:4,icon:K.value,class:e.normalizeClass([e.unref(n).e("icon"),e.unref(n).e("validateIcon"),e.unref(n).is("loading",g.value==="validating")])},null,8,["icon","class"])):e.createCommentVNode("",!0)],2)],2)):e.createCommentVNode("",!0)],2),o.$slots.append?(e.openBlock(),e.createElementBlock("div",{key:1,class:e.normalizeClass(e.unref(n).be("group","append"))},[e.renderSlot(o.$slots,"append")],2)):e.createCommentVNode("",!0)],64)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("textarea",e.mergeProps({id:e.unref(F),ref_key:"textarea",ref:f,class:e.unref(A).e("inner")},e.unref(r),{tabindex:o.tabindex,disabled:e.unref(m),readonly:o.readonly,autocomplete:o.autocomplete,style:$.value,"aria-label":o.label,placeholder:o.placeholder,form:o.form,onCompositionstart:L,onCompositionupdate:W,onCompositionend:H,onInput:P,onFocus:G,onBlur:J,onChange:j,onKeydown:Q}),null,16,Se),p.value?(e.openBlock(),e.createElementBlock("span",{key:0,style:e.normalizeStyle(D.value),class:e.normalizeClass(e.unref(n).e("count"))},e.toDisplayString(N.value)+" / "+e.toDisplayString(e.unref(r).maxlength),7)):e.createCommentVNode("",!0)],64))],16,Ve)),[[e.vShow,o.type!=="hidden"]])}});exports.default=ze;
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue");require("../form/index.cjs");const k=require("../icon/index.cjs"),Y=require("@vueuse/core"),s=require("@vft/utils"),T=require("../../utils/error.cjs");require("../config-provider/hooks/use-global-config.cjs");const Be=require("lodash-es"),Z=require("../../hooks/use-namespace/index.cjs");require("../../hooks/use-model-toggle/index.cjs");require("@popperjs/core");require("../../hooks/use-z-index/index.cjs");const q=require("@vft/constants"),_=require("@vft/use"),ee=require("./utils.cjs"),te=require("../form/hooks/use-form-common-props.cjs"),oe=require("../form/hooks/use-form-item.cjs"),Ve=["role"],Ie=["id","type","disabled","formatter","parser","readonly","autocomplete","tabindex","aria-label","placeholder","form"],Se=["id","tabindex","disabled","readonly","autocomplete","aria-label","placeholder","form"],ze=e.defineComponent({__name:"input",props:{id:{},size:{default:""},disabled:{type:Boolean},modelValue:{},type:{default:"text"},resize:{},autosize:{type:[Object,Boolean],default:!1},autocomplete:{default:"off"},formatter:{},parser:{},placeholder:{},form:{},readonly:{type:Boolean},clearable:{type:Boolean},showPassword:{type:Boolean},showWordLimit:{type:Boolean},suffixIcon:{},prefixIcon:{},clearIcon:{},containerRole:{},label:{},tabindex:{default:0},validateEvent:{type:Boolean,default:!0},inputStyle:{type:[Boolean,null,String,Object,Array]}},emits:{[q.UPDATE_MODEL_EVENT]:t=>s.isString(t),input:t=>s.isString(t),change:t=>s.isString(t),suffixClick:t=>s.isString(t),prefixClick:t=>s.isString(t),focus:t=>t instanceof FocusEvent,blur:t=>t instanceof FocusEvent,clear:()=>!0,enter:()=>!0,mouseleave:t=>t instanceof MouseEvent,mouseenter:t=>t instanceof MouseEvent,keydown:t=>t instanceof Event,compositionstart:t=>t instanceof CompositionEvent,compositionupdate:t=>t instanceof CompositionEvent,compositionend:t=>t instanceof CompositionEvent},setup(t,{expose:ne,emit:ae}){const l=ae,v=e.useAttrs(),i=e.useSlots(),M=e.computed(()=>{const o={};return t.containerRole==="combobox"&&(o["aria-haspopup"]=v["aria-haspopup"],o["aria-owns"]=v["aria-owns"],o["aria-expanded"]=v["aria-expanded"]),o}),le=e.computed(()=>[t.type==="textarea"?A.b():n.b(),n.m(ie.value),n.is("disabled",m.value),n.is("exceed",fe.value),n.is("focus",c.value),{[n.b("group")]:i.prepend||i.append,[n.bm("group","append")]:i.append,[n.bm("group","prepend")]:i.prepend,[n.m("prefix")]:i.prefix||t.prefixIcon,[n.m("suffix")]:i.suffix||t.suffixIcon||t.clearable||t.showPassword,[n.bm("suffix","password-clear")]:E.value&&z.value},v.class]),se=e.getCurrentInstance(),re=e.computed(()=>[n.e("wrapper"),n.is("focus",c.value)]),r=_.useAttrs({excludeKeys:e.computed(()=>Object.keys(M.value))}),{form:ue,formItem:C}=oe.useFormItem(),{inputId:F}=oe.useFormItemInputId(se.props,{formItemContext:C}),ie=te.useFormSize(),m=te.useFormDisabled(),n=Z.useNamespace("input"),A=Z.useNamespace("textarea"),w=e.shallowRef(),f=e.shallowRef(),c=e.ref(!1),V=e.ref(!1),y=e.ref(!1),x=e.ref(!1),D=e.ref(),I=e.shallowRef(t.inputStyle),h=e.computed(()=>w.value||f.value),S=e.computed(()=>s.singleAttrToObj(t.prefixIcon,"icon",{size:16})),O=e.computed(()=>s.singleAttrToObj(t.suffixIcon,"icon",{size:16})),ce=e.computed(()=>s.singleAttrToObj(t.clearIcon,"icon",{icon:"icon-circle-close",size:16})),R=e.computed(()=>ue?.statusIcon??!1),g=e.computed(()=>C?.validateState||""),K=e.computed(()=>g.value&&{validating:"icon-loading",success:"icon-circle-check",error:"icon-circle-close"}[g.value]),de=e.computed(()=>x.value?{icon:"icon-view",size:16}:{icon:"icon-hide",size:16}),me=e.computed(()=>[v.style,t.inputStyle]),$=e.computed(()=>[t.inputStyle,I.value,{resize:t.resize}]),u=e.computed(()=>Be.isNil(t.modelValue)?"":String(t.modelValue)),E=e.computed(()=>t.clearable&&!m.value&&!t.readonly&&!!u.value&&(c.value||V.value)),z=e.computed(()=>t.showPassword&&!m.value&&!t.readonly&&!!u.value&&(!!u.value||c.value)),p=e.computed(()=>t.showWordLimit&&!!r.value.maxlength&&(t.type==="text"||t.type==="textarea")&&!m.value&&!t.readonly&&!t.showPassword),N=e.computed(()=>Array.from(u.value).length),fe=e.computed(()=>!!p.value&&N.value>Number(r.value.maxlength)),pe=e.computed(()=>!!i.suffix||!!t.suffixIcon||E.value||t.showPassword||p.value||!!g.value&&R.value),[ve,ye]=_.useCursor(w);Y.useResizeObserver(f,o=>{if(!p.value||t.resize!=="both")return;const a=o[0],{width:d}=a.contentRect;D.value={right:`calc(100% - ${d+15+6}px)`}});const B=()=>{if(!(!Y.isClient||t.type!=="textarea"))if(t.autosize){const o=s.isObject(t.autosize)?t.autosize.minRows:void 0,a=s.isObject(t.autosize)?t.autosize.maxRows:void 0;I.value={...ee.calcTextareaHeight(f.value,o,a)}}else I.value={minHeight:ee.calcTextareaHeight(f.value).minHeight}},b=()=>{const o=h.value;!o||o.value===u.value||(o.value=u.value)},P=async o=>{ve();let{value:a}=o.target;if(r.value.maxlength&&a.length>=r.value.maxlength&&(a=a.slice(0,Number(r.value.maxlength))),t.formatter&&(a=t.parser?t.parser(a):a,a=t.formatter(a)),!y.value){if(a===u.value){b();return}l(q.UPDATE_MODEL_EVENT,a),l("input",a),await e.nextTick(),b(),ye()}},j=o=>{l("change",o.target.value)},he=()=>{l("suffixClick",t.modelValue)},ge=()=>{l("prefixClick",t.modelValue)},L=o=>{l("compositionstart",o),y.value=!0},be=o=>/([(\uAC00-\uD7AF)|\u3130-\u318F])+/.test(o),W=o=>{l("compositionupdate",o);const a=o.target?.value,d=a[a.length-1]||"";y.value=!be(d)},H=o=>{l("compositionend",o),y.value&&(y.value=!1,P(o))},ke=()=>{x.value=!x.value,U()},U=async()=>{await e.nextTick(),h.value?.focus()},Ce=()=>h.value?.blur(),G=o=>{c.value=!0,l("focus",o)},J=o=>{c.value=!1,l("blur",o),t.validateEvent&&C?.validate?.("blur").catch(a=>T.debugWarn(a))},we=o=>{V.value=!1,l("mouseleave",o)},xe=o=>{V.value=!0,l("mouseenter",o)},Q=o=>{let a=o.key;if(o.target.type==="number"&&["e","+","-0","E"].includes(a))return o.returnValue=!1,!1;l("keydown",o)},Ee=()=>{h.value?.select()},X=()=>{l(q.UPDATE_MODEL_EVENT,""),l("change",""),l("clear"),l("input","")};return e.watch(()=>t.modelValue,()=>{e.nextTick(()=>B()),t.validateEvent&&C?.validate?.("change").catch(o=>T.debugWarn(o))}),e.watch(u,()=>b()),e.watch(()=>t.type,async()=>{await e.nextTick(),b(),B()}),e.onMounted(()=>{!t.formatter&&t.parser&&T.debugWarn("VftInput","If you set the parser, you also need to set the formatter."),b(),e.nextTick(B)}),ne({input:w,textarea:f,ref:h,textareaStyle:$,autosize:t.autosize,focus:U,blur:Ce,select:Ee,clear:X,resizeTextarea:B}),(o,a)=>e.withDirectives((e.openBlock(),e.createElementBlock("div",e.mergeProps(M.value,{class:le.value,style:me.value,role:o.containerRole,onMouseenter:xe,onMouseleave:we,onMousewheel:a[1]||(a[1]=d=>o.type==="number"&&c.value?d.preventDefault():null)}),[o.type!=="textarea"?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[o.$slots.prepend?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(e.unref(n).be("group","prepend"))},[e.renderSlot(o.$slots,"prepend")],2)):e.createCommentVNode("",!0),e.createElementVNode("div",{class:e.normalizeClass(re.value)},[o.$slots.prefix||S.value?.icon?(e.openBlock(),e.createElementBlock("span",{key:0,class:e.normalizeClass(e.unref(n).e("prefix"))},[e.createElementVNode("span",{class:e.normalizeClass(e.unref(n).e("prefix-inner")),onClick:ge},[e.renderSlot(o.$slots,"prefix"),S.value?.icon?(e.openBlock(),e.createBlock(e.unref(k.VftIcon),e.mergeProps({key:0,pointer:""},S.value,{class:e.unref(n).e("icon")}),null,16,["class"])):e.createCommentVNode("",!0)],2)],2)):e.createCommentVNode("",!0),e.createElementVNode("input",e.mergeProps({id:e.unref(F),ref_key:"input",ref:w,class:e.unref(n).e("inner")},e.unref(r),{type:o.showPassword?x.value?"text":"password":o.type,disabled:e.unref(m),formatter:o.formatter,parser:o.parser,readonly:o.readonly,autocomplete:o.autocomplete,tabindex:o.tabindex,"aria-label":o.label,placeholder:o.placeholder,style:o.inputStyle,form:o.form,onCompositionstart:L,onCompositionupdate:W,onCompositionend:H,onInput:P,onFocus:G,onBlur:J,onChange:j,onKeydown:Q,onKeyup:a[0]||(a[0]=e.withKeys(d=>l("enter"),["enter"]))}),null,16,Ie),pe.value?(e.openBlock(),e.createElementBlock("span",{key:1,class:e.normalizeClass(e.unref(n).e("suffix"))},[e.createElementVNode("span",{class:e.normalizeClass(e.unref(n).e("suffix-inner")),onClick:he},[!E.value||!z.value||!p.value?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[e.renderSlot(o.$slots,"suffix"),O.value?.icon?(e.openBlock(),e.createBlock(e.unref(k.VftIcon),e.mergeProps({key:0},O.value,{class:e.unref(n).e("icon")}),null,16,["class"])):e.createCommentVNode("",!0)],64)):e.createCommentVNode("",!0),E.value?(e.openBlock(),e.createBlock(e.unref(k.VftIcon),e.mergeProps({key:1,pointer:"",class:[e.unref(n).e("icon"),e.unref(n).e("clear")]},ce.value,{onMousedown:e.withModifiers(e.unref(s.noop),["prevent"]),onClick:e.withModifiers(X,["stop"])}),null,16,["class","onMousedown"])):e.createCommentVNode("",!0),z.value?(e.openBlock(),e.createBlock(e.unref(k.VftIcon),e.mergeProps({key:2},de.value,{class:[e.unref(n).e("icon"),e.unref(n).e("password")],onClick:ke}),null,16,["class"])):e.createCommentVNode("",!0),p.value?(e.openBlock(),e.createElementBlock("span",{key:3,class:e.normalizeClass(e.unref(n).e("count"))},[e.createElementVNode("span",{class:e.normalizeClass(e.unref(n).e("count-inner"))},e.toDisplayString(N.value)+" / "+e.toDisplayString(e.unref(r).maxlength),3)],2)):e.createCommentVNode("",!0),g.value&&K.value&&R.value?(e.openBlock(),e.createBlock(e.unref(k.VftIcon),{key:4,icon:K.value,class:e.normalizeClass([e.unref(n).e("icon"),e.unref(n).e("validateIcon"),e.unref(n).is("loading",g.value==="validating")])},null,8,["icon","class"])):e.createCommentVNode("",!0)],2)],2)):e.createCommentVNode("",!0)],2),o.$slots.append?(e.openBlock(),e.createElementBlock("div",{key:1,class:e.normalizeClass(e.unref(n).be("group","append"))},[e.renderSlot(o.$slots,"append")],2)):e.createCommentVNode("",!0)],64)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createElementVNode("textarea",e.mergeProps({id:e.unref(F),ref_key:"textarea",ref:f,class:e.unref(A).e("inner")},e.unref(r),{tabindex:o.tabindex,disabled:e.unref(m),readonly:o.readonly,autocomplete:o.autocomplete,style:$.value,"aria-label":o.label,placeholder:o.placeholder,form:o.form,onCompositionstart:L,onCompositionupdate:W,onCompositionend:H,onInput:P,onFocus:G,onBlur:J,onChange:j,onKeydown:Q}),null,16,Se),p.value?(e.openBlock(),e.createElementBlock("span",{key:0,style:e.normalizeStyle(D.value),class:e.normalizeClass(e.unref(n).e("count"))},e.toDisplayString(N.value)+" / "+e.toDisplayString(e.unref(r).maxlength),7)):e.createCommentVNode("",!0)],64))],16,Ve)),[[e.vShow,o.type!=="hidden"]])}});exports.default=ze;
|
|
@@ -95,6 +95,9 @@ export declare const VftUpload: import("vft/es/utils").SFCWithInstall<{
|
|
|
95
95
|
onSizeInvalid: {
|
|
96
96
|
type: import("vue").PropType<(file: File, width: number, height: number, expectedWidth: number, expectedHeight: number) => void>;
|
|
97
97
|
};
|
|
98
|
+
onTypeInvalid: {
|
|
99
|
+
type: import("vue").PropType<(file: File, acceptedTypes: string) => void>;
|
|
100
|
+
};
|
|
98
101
|
beforeUpload: {
|
|
99
102
|
type: import("vue").PropType<(rawFile: import("./types").UploadRawFile) => import("../types").Awaitable<void | undefined | null | boolean | File | Blob>>;
|
|
100
103
|
};
|
|
@@ -288,6 +291,9 @@ export declare const VftUpload: import("vft/es/utils").SFCWithInstall<{
|
|
|
288
291
|
onSizeInvalid: {
|
|
289
292
|
type: import("vue").PropType<(file: File, width: number, height: number, expectedWidth: number, expectedHeight: number) => void>;
|
|
290
293
|
};
|
|
294
|
+
onTypeInvalid: {
|
|
295
|
+
type: import("vue").PropType<(file: File, acceptedTypes: string) => void>;
|
|
296
|
+
};
|
|
291
297
|
beforeUpload: {
|
|
292
298
|
type: import("vue").PropType<(rawFile: import("./types").UploadRawFile) => import("../types").Awaitable<void | undefined | null | boolean | File | Blob>>;
|
|
293
299
|
};
|
|
@@ -478,6 +484,9 @@ export declare const VftUpload: import("vft/es/utils").SFCWithInstall<{
|
|
|
478
484
|
onSizeInvalid: {
|
|
479
485
|
type: import("vue").PropType<(file: File, width: number, height: number, expectedWidth: number, expectedHeight: number) => void>;
|
|
480
486
|
};
|
|
487
|
+
onTypeInvalid: {
|
|
488
|
+
type: import("vue").PropType<(file: File, acceptedTypes: string) => void>;
|
|
489
|
+
};
|
|
481
490
|
beforeUpload: {
|
|
482
491
|
type: import("vue").PropType<(rawFile: import("./types").UploadRawFile) => import("../types").Awaitable<void | undefined | null | boolean | File | Blob>>;
|
|
483
492
|
};
|
|
@@ -46,6 +46,8 @@ export interface UploadHooks {
|
|
|
46
46
|
onExceed: (files: File[], uploadFiles: UploadUserFile[]) => void;
|
|
47
47
|
/** 文件大小超出限制时的回调 */
|
|
48
48
|
onSizeExceed?: (file: File, maxSize: number) => void;
|
|
49
|
+
/** 文件类型不符合要求时的回调 */
|
|
50
|
+
onTypeInvalid?: (file: File, acceptedTypes: string) => void;
|
|
49
51
|
}
|
|
50
52
|
export interface UploadBasicProps {
|
|
51
53
|
action?: string;
|
|
@@ -77,6 +79,8 @@ export interface UploadBasicProps {
|
|
|
77
79
|
sizeHeight?: number;
|
|
78
80
|
/** 尺寸不符合时的回调函数 */
|
|
79
81
|
onSizeInvalid?: (file: File, width: number, height: number, expectedWidth: number, expectedHeight: number) => void;
|
|
82
|
+
/** 文件类型不符合要求时的回调 */
|
|
83
|
+
onTypeInvalid?: (file: File, acceptedTypes: string) => void;
|
|
80
84
|
}
|
|
81
85
|
export interface UploadEventProps {
|
|
82
86
|
beforeUpload?: UploadHooks['beforeUpload'];
|
|
@@ -90,6 +94,7 @@ export interface UploadEventProps {
|
|
|
90
94
|
onExceed?: UploadHooks['onExceed'];
|
|
91
95
|
onSizeExceed?: UploadHooks['onSizeExceed'];
|
|
92
96
|
onSizeInvalid?: UploadBasicProps['onSizeInvalid'];
|
|
97
|
+
onTypeInvalid?: UploadBasicProps['onTypeInvalid'];
|
|
93
98
|
}
|
|
94
99
|
export interface UploadContentEventProps {
|
|
95
100
|
beforeUpload?: UploadHooks['beforeUpload'];
|
|
@@ -100,6 +105,7 @@ export interface UploadContentEventProps {
|
|
|
100
105
|
onError?: (err: UploadAjaxError, rawFile: UploadRawFile) => void;
|
|
101
106
|
onExceed?: UploadHooks['onExceed'];
|
|
102
107
|
onSizeExceed?: UploadHooks['onSizeExceed'];
|
|
108
|
+
onTypeInvalid?: UploadHooks['onTypeInvalid'];
|
|
103
109
|
}
|
|
104
110
|
export interface UploadContentBasicProps extends Omit<UploadBasicProps, 'fileList'> {
|
|
105
111
|
fileList?: UploadUserFile[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue");require("../form/index.cjs");require("@vueuse/core");const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue");require("../form/index.cjs");require("@vueuse/core");const C=require("@vft/utils"),D=require("../../utils/error.cjs");require("../config-provider/hooks/use-global-config.cjs");const k=require("lodash-es"),L=require("../../hooks/use-namespace/index.cjs");require("../../hooks/use-model-toggle/index.cjs");require("@popperjs/core");require("../../hooks/use-z-index/index.cjs");const M=require("./ajax.cjs"),K=require("./constants.cjs"),V=require("./upload-dragger.vue2.cjs"),b=require("./utils.cjs"),H=require("../form/hooks/use-form-common-props.cjs"),W=require("../form/hooks/use-form-item.cjs"),$=["onKeydown"],A=["name","multiple","accept"],N=t.defineComponent({name:"VftUploadContent",inheritAttrs:!1}),X=t.defineComponent({...N,props:{fileList:{default:[]},replaceOnLimit:{type:Boolean,default:!1},action:{default:"#"},headers:{},method:{default:"post"},data:{},multiple:{type:Boolean,default:!1},name:{default:"file"},drag:{type:Boolean,default:!1},withCredentials:{type:Boolean},showFileList:{type:Boolean,default:!0},accept:{default:""},type:{default:"select"},autoUpload:{type:Boolean,default:!1},listType:{default:"text"},httpRequest:{type:Function,default:M.ajaxUpload},disabled:{type:Boolean},limit:{},maxSize:{default:void 0},sizeExceedMessage:{default:"文件大小超出限制"},sizeWidth:{default:void 0},sizeHeight:{default:void 0},onSizeInvalid:{},onTypeInvalid:{},beforeUpload:{},onRemove:{},onStart:{},onSuccess:{},onProgress:{},onError:{},onExceed:{},onSizeExceed:{}},setup(U,{expose:w}){const l=U,y=L.useNamespace("upload"),_=H.useFormDisabled(),{formItem:x}=W.useFormItem(),f=t.shallowRef({}),v=t.shallowRef(),B=async e=>{if(e.length===0)return;const{autoUpload:n,limit:a,fileList:s,multiple:p,onStart:h,onExceed:S,replaceOnLimit:z,maxSize:u,onSizeExceed:q,sizeWidth:m,sizeHeight:g,onSizeInvalid:d,accept:r,onTypeInvalid:c}=l;if(r){const i=e.filter(o=>!b.validateFileType(o,r));if(i.length>0&&(i.forEach(o=>{c&&c(o,r)}),e=e.filter(o=>b.validateFileType(o,r)),e.length===0))return}if(u){const i=e.filter(o=>o.size>u);if(i.length>0&&(i.forEach(o=>{q&&q(o,u)}),e=e.filter(o=>o.size<=u),e.length===0))return}if(m&&g){const i=[];for(const o of e)if(b.isImageOrVideo(o))try{const{isValid:E,width:P,height:j}=await b.validateFileSize(o,m,g);E?i.push(o):d&&d(o,P,j,m,g)}catch(E){console.error("尺寸校验失败:",E)}else i.push(o);if(e=i,e.length===0)return}if(a&&s&&s.length+e.length>a&&!(a===1&&z)){S?.(e,s);return}p||(e=e.slice(0,1));for(const i of e){const o=i;o.uid=K.genFileId(),h?.(o),n&&R(o)}},R=async e=>{if(v.value.value="",!l.beforeUpload)return I(e);let n,a={};try{const p=l.data,h=l.beforeUpload(e);a=C.isObject(l.data)?k.cloneDeep(l.data):l.data,n=await h,C.isObject(l.data)&&k.isEqual(p,a)&&(a=k.cloneDeep(l.data))}catch{n=!1}if(n===!1){l.onRemove?.(e);return}let s=e;n instanceof Blob&&(n instanceof File?s=n:s=new File([n],e.name,{type:e.type})),I(Object.assign(s,{uid:e.uid}),a)},I=(e,n)=>{const{headers:a,data:s,method:p,withCredentials:h,name:S,action:z,onProgress:u,onSuccess:q,onError:m,httpRequest:g}=l,{uid:d}=e,r={headers:a||{},withCredentials:h,file:e,data:n??(s||{}),method:p,filename:S,action:z,onProgress:i=>{u?.(i,e)},onSuccess:i=>{q?.(i,e),delete f.value[d]},onError:i=>{m?.(i,e),delete f.value[d]}},c=g(r);f.value[d]=c,c instanceof Promise&&c.then(r.onSuccess,r.onError)},F=async e=>{const n=e.target.files;n&&(await B(Array.from(n)),t.nextTick(()=>{x?.validate("change").catch(a=>D.debugWarn(a))}))},T=()=>{_.value||(v.value.value="",v.value.click())},O=()=>{T()};return w({abort:e=>{C.entriesOf(f.value).filter(e?([a])=>String(e.uid)===a:()=>!0).forEach(([a,s])=>{s instanceof XMLHttpRequest&&s.abort(),delete f.value[a]})},upload:R}),(e,n)=>(t.openBlock(),t.createElementBlock("div",{class:t.normalizeClass([t.unref(y).b(),t.unref(y).m(e.listType),t.unref(y).is("drag",e.drag)]),tabindex:"0",onClick:T,onKeydown:t.withKeys(t.withModifiers(O,["self"]),["enter","space"])},[e.drag?(t.openBlock(),t.createBlock(V.default,{key:0,disabled:t.unref(_),onFile:n[0]||(n[0]=a=>B(a.file))},{default:t.withCtx(()=>[t.renderSlot(e.$slots,"default")]),_:3},8,["disabled"])):t.renderSlot(e.$slots,"default",{key:1}),t.createElementVNode("input",{ref_key:"inputRef",ref:v,class:t.normalizeClass(t.unref(y).e("input")),name:e.name,multiple:e.multiple,accept:e.accept,type:"file",onChange:F,onClick:n[1]||(n[1]=t.withModifiers(()=>{},["stop"]))},null,42,A)],42,$))}});exports.default=X;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue");require("../form/index.cjs");const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue");require("../form/index.cjs");const p=require("../message/index.cjs"),M=require("./ajax.cjs"),P=require("./constants.cjs"),C=require("./upload-content.vue2.cjs"),w=require("./upload-list.vue2.cjs"),V=require("./use-handlers.cjs"),_=require("../form/hooks/use-form-common-props.cjs"),E=e.defineComponent({name:"vft-upload"}),F=e.defineComponent({...E,props:{action:{default:"#"},headers:{},method:{default:"post"},data:{},multiple:{type:Boolean,default:!1},name:{default:"file"},drag:{type:Boolean,default:!1},withCredentials:{type:Boolean},showFileList:{type:Boolean,default:!0},accept:{default:""},type:{default:"select"},fileList:{default:[]},autoUpload:{type:Boolean,default:!1},listType:{default:"text"},httpRequest:{type:Function,default:M.ajaxUpload},disabled:{type:Boolean},limit:{},replaceOnLimit:{type:Boolean,default:!1},maxSize:{default:void 0},sizeExceedMessage:{default:"文件大小超出限制"},sizeWidth:{default:void 0},sizeHeight:{default:void 0},onSizeInvalid:{},onTypeInvalid:{},beforeUpload:{},beforeRemove:{},onRemove:{},onChange:{},onPreview:{},onSuccess:{},onProgress:{},onError:{},onExceed:{type:Function,default:()=>{}},onSizeExceed:{}},setup(k,{expose:B}){const o=k,a=e.useSlots(),f=_.useFormDisabled(),i=e.shallowRef(),{abort:c,submit:m,clearFiles:v,uploadFiles:r,handleStart:y,handleError:$,handleRemove:d,handleSuccess:b,handleProgress:R}=V.useHandlers(o,i),u=e.computed(()=>o.listType==="picture-card"),z={abort:c,submit:m,clearFiles:v,uploadFiles:r,uploadRef:i},g=e.computed(()=>({...o,fileList:r.value,onStart:y,onProgress:R,onSuccess:b,onError:$,onRemove:d,onChange:(t,l)=>{o.onChange?.(t,l,z)},onSizeExceed:(t,l)=>{if(o.onSizeExceed)o.onSizeExceed?.(t,l);else{const s=`文件大小不能超过 ${(l/1048576).toFixed(2)}MB`;console.warn("默认文件大小超出提示:",s),p.VftMessage.warning(s)}},onSizeInvalid:(t,l,n,s,S)=>{if(o.onSizeInvalid)o.onSizeInvalid(t,l,n,s,S);else{const h=`文件尺寸不符合要求,当前尺寸:${l}x${n},期望尺寸:${s}x${S}`;console.warn("默认尺寸校验提示:",h),p.VftMessage.warning(h)}},onTypeInvalid:(t,l)=>{if(o.onTypeInvalid)o.onTypeInvalid(t,l);else{const n=`文件类型不符合要求,当前文件:${t.name},支持的类型:${l}`;console.warn("默认文件类型校验提示:",n),p.VftMessage.warning(n)}}}));return e.onBeforeUnmount(()=>{r.value.forEach(({url:t})=>{t?.startsWith("blob:")&&URL.revokeObjectURL(t)})}),e.provide(P.uploadContextKey,{accept:e.toRef(o,"accept")}),B({abort:c,submit:m,clearFiles:v,handleStart:y,handleRemove:d,fileList:r}),(t,l)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["vft-upload-wrapper",{disabled:e.unref(f)}])},[u.value&&t.showFileList?(e.openBlock(),e.createBlock(w.default,{key:0,disabled:e.unref(f),"list-type":t.listType,files:e.unref(r),"handle-preview":t.onPreview,onRemove:e.unref(d)},e.createSlots({append:e.withCtx(()=>[e.createVNode(C.default,e.mergeProps({ref_key:"uploadRef",ref:i},g.value),{default:e.withCtx(()=>[e.unref(a).trigger?e.renderSlot(t.$slots,"trigger",{key:0}):e.createCommentVNode("",!0),!e.unref(a).trigger&&e.unref(a).default?e.renderSlot(t.$slots,"default",{key:1}):e.createCommentVNode("",!0)]),_:3},16)]),_:2},[t.$slots.file?{name:"default",fn:e.withCtx(({file:n})=>[e.renderSlot(t.$slots,"file",{file:n})]),key:"0"}:void 0]),1032,["disabled","list-type","files","handle-preview","onRemove"])):e.createCommentVNode("",!0),!u.value||u.value&&!t.showFileList?(e.openBlock(),e.createBlock(C.default,e.mergeProps({key:1,ref_key:"uploadRef",ref:i},g.value),{default:e.withCtx(()=>[e.unref(a).trigger?e.renderSlot(t.$slots,"trigger",{key:0}):e.createCommentVNode("",!0),!e.unref(a).trigger&&e.unref(a).default?e.renderSlot(t.$slots,"default",{key:1}):e.createCommentVNode("",!0)]),_:3},16)):e.createCommentVNode("",!0),t.$slots.trigger?e.renderSlot(t.$slots,"default",{key:2}):e.createCommentVNode("",!0),e.renderSlot(t.$slots,"tip"),!u.value&&t.showFileList?(e.openBlock(),e.createBlock(w.default,{key:3,disabled:e.unref(f),"list-type":t.listType,files:e.unref(r),"handle-preview":t.onPreview,onRemove:e.unref(d)},e.createSlots({_:2},[t.$slots.file?{name:"default",fn:e.withCtx(({file:n})=>[e.renderSlot(t.$slots,"file",{file:n})]),key:"0"}:void 0]),1032,["disabled","list-type","files","handle-preview","onRemove"])):e.createCommentVNode("",!0)],2))}});exports.default=F;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(i){return new Promise((n,s)=>{const e=i.type.startsWith("image/"),r=i.type.startsWith("video/");if(!e&&!r){s(new Error("文件类型不支持尺寸校验"));return}if(e){const t=new Image;t.onload=()=>{n({width:t.naturalWidth,height:t.naturalHeight})},t.onerror=()=>{s(new Error("图片加载失败"))},t.src=URL.createObjectURL(i)}else if(r){const t=document.createElement("video");t.onloadedmetadata=()=>{n({width:t.videoWidth,height:t.videoHeight}),URL.revokeObjectURL(t.src)},t.onerror=()=>{s(new Error("视频加载失败")),URL.revokeObjectURL(t.src)},t.src=URL.createObjectURL(i)}})}async function a(i,n,s){try{const{width:e,height:r}=await o(i);return{isValid:e===n&&r===s,width:e,height:r}}catch(e){return console.error("尺寸校验失败:",e),{isValid:!1,width:0,height:0}}}function c(i){return i.type.startsWith("image/")||i.type.startsWith("video/")}function d(i,n){return n?n.split(",").map(e=>e.trim()).some(e=>{if(e.startsWith(".")){const r=e.toLowerCase();return i.name.toLowerCase().endsWith(r)}else if(e.includes("/*")){const r=e.replace("/*","");return i.type.startsWith(r+"/")}else return i.type===e}):!0}exports.getFileDimensions=o;exports.isImageOrVideo=c;exports.validateFileSize=a;exports.validateFileType=d;
|
|
@@ -25,3 +25,10 @@ export declare function validateFileSize(file: File, expectedWidth: number, expe
|
|
|
25
25
|
* @returns boolean
|
|
26
26
|
*/
|
|
27
27
|
export declare function isImageOrVideo(file: File): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* 验证文件类型是否符合accept属性要求
|
|
30
|
+
* @param file 文件对象
|
|
31
|
+
* @param accept accept属性值,如 "image/*,.pdf,.doc"
|
|
32
|
+
* @returns boolean
|
|
33
|
+
*/
|
|
34
|
+
export declare function validateFileType(file: File, accept: string): boolean;
|
package/lib/package.json.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="0.0.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="0.0.387";exports.version=e;
|
package/lib/package.json.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vft",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.387",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "lib/index.cjs",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -55,12 +55,12 @@
|
|
|
55
55
|
"resize-detector": "0.3.0",
|
|
56
56
|
"sortablejs": "1.15.0",
|
|
57
57
|
"photoswipe": "5.4.4",
|
|
58
|
+
"@vft/constants": "0.0.72",
|
|
58
59
|
"@vft/router": "0.0.67",
|
|
59
60
|
"@vft/utils": "0.0.136",
|
|
60
|
-
"@vft/
|
|
61
|
-
"@vft/constants": "0.0.72",
|
|
61
|
+
"@vft/store": "0.0.54",
|
|
62
62
|
"@vft/use": "0.0.79",
|
|
63
|
-
"@vft/
|
|
63
|
+
"@vft/directives": "0.0.34"
|
|
64
64
|
},
|
|
65
65
|
"vetur": {
|
|
66
66
|
"tags": "tags.json",
|
package/web-types.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"$schema":"http://json.schemastore.org/web-types","framework":"vue","name":"vft","version":"0.0.
|
|
1
|
+
{"$schema":"http://json.schemastore.org/web-types","framework":"vue","name":"vft","version":"0.0.387","js-types-syntax":"typescript","description-markup":"markdown","contributions":{"html":{}}}
|