@keyblade/pro-components 1.12.0-alpha.7 → 1.12.0-alpha.8

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