@keyblade/pro-components 1.11.7 → 1.12.0-alpha.2

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.
@@ -0,0 +1,272 @@
1
+ import { defineComponent as ue, ref as m, computed as M, watch as G, resolveComponent as de, openBlock as J, createElementBlock as se, createVNode as ce, normalizeClass as fe, createBlock as ve, createCommentVNode as me } from "vue";
2
+ import { Message as x } from "@arco-design/web-vue";
3
+ import { conclude as L } from "vue-global-config";
4
+ import { EImageUploadInnerBeforeUploadStep as v } from "./types.js";
5
+ import { defaultImageUploadOptions as U } from "./constant.js";
6
+ import ge from "./cropper.vue.js";
7
+ import { defaultImageUploadCheckOptions as pe, defaultImageUploadCompressorOptions as Ie, defaultImageUploadCropOptions as he, oneTravelImageCheckAndTransform as xe, oneTravelImageCompressor as Ue } from "@keyblade/one-travel";
8
+ const Ce = "keyblade-pro-image-upload";
9
+ var K, X, Y;
10
+ const Oe = /* @__PURE__ */ ue({
11
+ __name: "image-upload",
12
+ props: {
13
+ action: {},
14
+ handlerResponse: {},
15
+ headers: {},
16
+ data: {},
17
+ name: { default: (K = U) == null ? void 0 : K.name },
18
+ tip: {},
19
+ accept: { default: () => {
20
+ var B;
21
+ return ((B = U) == null ? void 0 : B.accept) || [];
22
+ } },
23
+ multiple: { type: Boolean, default: U.multiple },
24
+ singleLimit: { default: U.singleLimit },
25
+ limit: {},
26
+ disabled: { type: Boolean, default: (X = U) == null ? void 0 : X.disabled },
27
+ hideInnerBeforeUploadLoading: { type: Boolean, default: (Y = U) == null ? void 0 : Y.hideInnerBeforeUploadLoading },
28
+ checkOptions: {},
29
+ compressorOptions: {},
30
+ cropOptions: {},
31
+ onSuccess: {},
32
+ onError: {},
33
+ onExceed: {},
34
+ onBeforeUpload: {},
35
+ onInnerBeforeUploadStart: {},
36
+ onInnerBeforeUploadEnd: {}
37
+ },
38
+ emits: ["cropperImgLoad"],
39
+ setup(B, { expose: Z, emit: _ }) {
40
+ const e = B, i = defineModel({ required: !0 }), S = m(), O = m(), g = m(), p = m(
41
+ []
42
+ ), o = m(), c = m(), d = m(), A = M(() => e.accept.map((a) => `.${a}`).join(",")), f = M(() => L([e.checkOptions, pe]) || {}), C = M(() => L([e.compressorOptions, Ie]) || {}), y = M(() => L([e.cropOptions, he]) || {}), R = (a) => {
43
+ var t, r, s, u;
44
+ const l = (u = (s = (r = (t = S.value) == null ? void 0 : t.$el) == null ? void 0 : r.querySelector) == null ? void 0 : s.call(r, "input")) == null ? void 0 : u.files;
45
+ return l && l.length > 0 && (d.value = {
46
+ selectCount: l.length
47
+ }), e != null && e.onBeforeUpload ? e == null ? void 0 : e.onBeforeUpload(a) : d.value && (e != null && e.singleLimit) && d.value.selectCount > (e == null ? void 0 : e.singleLimit) ? (d.value.handleIndex === void 0 ? (d.value.handleIndex = 0, x.error(`单次最多可选择${e == null ? void 0 : e.singleLimit}张图片`)) : d.value.handleIndex += 1, d.value.handleIndex === d.value.selectCount - 1 && (d.value = void 0), !1) : new Promise(async (E, w) => {
48
+ try {
49
+ E(await oe(a));
50
+ } catch {
51
+ w();
52
+ } finally {
53
+ $();
54
+ }
55
+ });
56
+ }, ee = async (a) => {
57
+ const l = i.value.findIndex((t) => t.uid === a.uid);
58
+ return i.value.splice(l, 1), i.value = [...i.value], !1;
59
+ }, ae = (a, l) => {
60
+ e != null && e.onExceed ? e == null || e.onExceed(a, l) : (x.error(`单次最多可选择${(e == null ? void 0 : e.limit) || 1}张图片`), i.value = a);
61
+ }, le = async (a) => {
62
+ if (e != null && e.onSuccess)
63
+ e == null || e.onSuccess(a);
64
+ else {
65
+ if (!(e != null && e.handlerResponse))
66
+ return;
67
+ const l = await e.handlerResponse(a.response), t = i.value.findIndex((r) => r.uid === a.uid);
68
+ l.success ? i.value[t] = {
69
+ ...i.value[t],
70
+ ...l
71
+ } : i.value.splice(t, 1);
72
+ }
73
+ }, ne = (a) => {
74
+ e != null && e.onError ? e == null || e.onError(a) : setTimeout(() => {
75
+ const l = i.value.findIndex((t) => t.uid === a.uid);
76
+ i.value.splice(l, 1);
77
+ });
78
+ }, oe = (a) => new Promise((l, t) => {
79
+ p.value.push({ file: a, resolve: l, reject: t }), p.value.length === 1 && !o.value && $();
80
+ }), $ = () => {
81
+ o.value === void 0 ? o.value = 0 : o.value + 1 >= p.value.length ? (o.value = void 0, p.value = []) : o.value += 1;
82
+ }, te = () => {
83
+ var a;
84
+ (a = g.value) == null || a.reject();
85
+ }, ie = (a) => {
86
+ var l;
87
+ (l = g.value) == null || l.resolve(a);
88
+ }, re = (a) => {
89
+ _("cropperImgLoad", a);
90
+ };
91
+ G(o, async () => {
92
+ var E, w, b, k, F, z, j, Q, H, W, N, P, T, q, V, D;
93
+ if (o.value === void 0 || p.value.length === 0)
94
+ return;
95
+ const a = p.value[o.value], { file: l, resolve: t, reject: r } = a;
96
+ let s = l.name, u = l;
97
+ if ((E = f.value) != null && E.enable) {
98
+ c.value = {
99
+ loading: !0,
100
+ text: `第${o.value + 1}张图片检测中,请稍等`
101
+ }, (w = e == null ? void 0 : e.onInnerBeforeUploadStart) == null || w.call(
102
+ e,
103
+ l,
104
+ o.value,
105
+ v.check
106
+ );
107
+ const n = await xe(l, l.name, {
108
+ imageMaxSize: f.value.maxSize,
109
+ imageAllowedType: f.value.allowedType,
110
+ imageMinWidth: f.value.minWidth,
111
+ imageMinHeight: f.value.minHeight,
112
+ imageMaxWidth: f.value.maxWidth,
113
+ imageMaxHeight: f.value.maxHeight
114
+ });
115
+ if (c.value = void 0, (b = e == null ? void 0 : e.onInnerBeforeUploadEnd) == null || b.call(
116
+ e,
117
+ l,
118
+ o.value,
119
+ v.check,
120
+ {
121
+ success: n.success,
122
+ error: n == null ? void 0 : n.error,
123
+ errorMessage: n == null ? void 0 : n.errorMessage
124
+ }
125
+ ), !n.success)
126
+ return (k = f.value) != null && k.showErrorMessage && x.error((n == null ? void 0 : n.errorMessage) || "图片校验及转换失败"), r();
127
+ if (n != null && n.hasTransform) {
128
+ const h = s == null ? void 0 : s.split(".");
129
+ h.pop(), s = `${h.join(",")}.jpg`, u = new File([n.file], s, {
130
+ type: n.file.type
131
+ });
132
+ } else
133
+ u = n.file;
134
+ }
135
+ if ((F = y.value) != null && F.enable) {
136
+ (z = e == null ? void 0 : e.onInnerBeforeUploadStart) == null || z.call(
137
+ e,
138
+ l,
139
+ o.value,
140
+ v.crop
141
+ );
142
+ try {
143
+ (j = y.value) != null && j.customCrop ? u = await y.value.customCrop(u) : u = await new Promise((n, h) => {
144
+ g.value = { file: u, resolve: n, reject: h };
145
+ }), (Q = e == null ? void 0 : e.onInnerBeforeUploadEnd) == null || Q.call(
146
+ e,
147
+ l,
148
+ o.value,
149
+ v.crop,
150
+ {
151
+ success: !1
152
+ }
153
+ );
154
+ } catch {
155
+ return (H = e == null ? void 0 : e.onInnerBeforeUploadEnd) == null || H.call(
156
+ e,
157
+ l,
158
+ o.value,
159
+ v.crop,
160
+ {
161
+ success: !1,
162
+ error: {
163
+ crop: !0
164
+ },
165
+ errorMessage: "图片剪裁失败"
166
+ }
167
+ ), (W = y.value) != null && W.showErrorMessage && x.error("图片剪裁失败"), r();
168
+ } finally {
169
+ g.value = void 0;
170
+ }
171
+ }
172
+ if ((N = C.value) != null && N.enable) {
173
+ c.value = {
174
+ loading: !0,
175
+ text: `第${o.value + 1}张图片处理中,请稍等`
176
+ }, (P = e == null ? void 0 : e.onInnerBeforeUploadStart) == null || P.call(
177
+ e,
178
+ l,
179
+ o.value,
180
+ v.compress
181
+ );
182
+ const n = await Ue(u, {
183
+ maxSize: C.value.maxSize,
184
+ size: C.value.size,
185
+ excludeAllowedTypes: (T = C.value.excludeAllowedTypes) == null ? void 0 : T.map((h) => `image/${h}`)
186
+ });
187
+ if (c.value = void 0, (q = e == null ? void 0 : e.onInnerBeforeUploadEnd) == null || q.call(
188
+ e,
189
+ l,
190
+ o.value,
191
+ v.compress,
192
+ {
193
+ success: n.success,
194
+ error: {
195
+ compress: !0
196
+ },
197
+ errorMessage: n == null ? void 0 : n.errorMessage
198
+ }
199
+ ), !n.success)
200
+ return (V = C.value) != null && V.showErrorMessage && x.error((n == null ? void 0 : n.errorMessage) || "图片压缩失败"), r();
201
+ u = new File([n.file], s, {
202
+ type: n.file.type
203
+ });
204
+ }
205
+ c.value = void 0, (D = e == null ? void 0 : e.onInnerBeforeUploadEnd) == null || D.call(
206
+ e,
207
+ l,
208
+ o.value,
209
+ v.all,
210
+ {
211
+ success: !0
212
+ }
213
+ ), t(u);
214
+ });
215
+ let I;
216
+ return G(
217
+ () => c.value,
218
+ () => {
219
+ var a;
220
+ c.value ? I = x.loading({
221
+ content: c.value.text,
222
+ id: "image-upload-id",
223
+ duration: 0
224
+ }) : (a = I == null ? void 0 : I.close) == null || a.call(I);
225
+ }
226
+ ), Z({
227
+ uploadInsRef: S,
228
+ cropperInsRef: O
229
+ }), (a, l) => {
230
+ const t = de("a-upload");
231
+ return J(), se("div", null, [
232
+ ce(t, {
233
+ class: fe([`${Ce}-upload`]),
234
+ ref_key: "uploadInsRef",
235
+ ref: S,
236
+ "list-type": "picture-card",
237
+ tip: a.tip || "上传",
238
+ "image-preview": "",
239
+ "file-list": i.value,
240
+ "onUpdate:fileList": l[0] || (l[0] = (r) => i.value = r),
241
+ action: a.action,
242
+ headers: a.headers,
243
+ data: a.data,
244
+ name: a.name,
245
+ accept: A.value,
246
+ multiple: a.multiple,
247
+ limit: a.limit,
248
+ disabled: a.disabled,
249
+ "on-before-upload": R,
250
+ "on-before-remove": ee,
251
+ onExceedLimit: ae,
252
+ onSuccess: le,
253
+ onError: ne
254
+ }, null, 8, ["class", "tip", "file-list", "action", "headers", "data", "name", "accept", "multiple", "limit", "disabled"]),
255
+ g.value && o.value !== void 0 ? (J(), ve(ge, {
256
+ key: 0,
257
+ ref_key: "cropperInsRef",
258
+ ref: O,
259
+ file: g.value.file,
260
+ index: o.value,
261
+ options: y.value,
262
+ onCancel: te,
263
+ onConfirm: ie,
264
+ onImgLoad: re
265
+ }, null, 8, ["file", "index", "options"])) : me("", !0)
266
+ ]);
267
+ };
268
+ }
269
+ });
270
+ export {
271
+ Oe as default
272
+ };
@@ -0,0 +1,4 @@
1
+ import f from "./image-upload.vue.js";
2
+ export {
3
+ f as default
4
+ };