@gx-design-vue/image 0.0.9 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Image.d.ts +1 -1
- package/dist/components/ImageViewer.d.ts +2 -2
- package/dist/image.mjs +64 -65
- package/dist/image.umd.js +1 -1
- package/package.json +3 -4
package/dist/Image.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ExtractPropTypes } from 'vue';
|
|
2
2
|
import { gImagePorps } from './props';
|
|
3
3
|
import './style.less';
|
|
4
|
-
export
|
|
4
|
+
export type GImageProps = Partial<ExtractPropTypes<typeof gImagePorps>>;
|
|
5
5
|
declare const GImage: import("vue").DefineComponent<{
|
|
6
6
|
appendToBody: {
|
|
7
7
|
type: import("vue").PropType<boolean>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const on: (element: HTMLElement | Document | Window | null, event: string, handler: EventListenerOrEventListenerObject, useCapture?: boolean) => void;
|
|
2
2
|
export declare const off: (element: HTMLElement | Document | Window | null, event: string, handler: EventListenerOrEventListenerObject, useCapture?: boolean) => void;
|
|
3
|
-
export
|
|
4
|
-
export
|
|
3
|
+
export type AnyFunction<T> = (...args: any[]) => T;
|
|
4
|
+
export type ImageViewerAction = 'zoomIn' | 'zoomOut' | 'clocelise' | 'anticlocelise';
|
|
5
5
|
export declare const isFirefox: () => boolean;
|
|
6
6
|
export declare function rafThrottle<T extends AnyFunction<any>>(fn: T): AnyFunction<void>;
|
|
7
7
|
declare const GImageViewer: import("vue").DefineComponent<{
|
package/dist/image.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createVNode as l, defineComponent as Z, ref as g, computed as b, watch as U, nextTick as oe, Fragment as re, resolveComponent as ue, cloneVNode as ve, Teleport as ce, isVNode as me, createTextVNode as ge, mergeProps as he } from "vue";
|
|
2
2
|
import { ExpandOutlined as ye, OneToOneOutlined as we, CloseOutlined as be, LeftOutlined as pe, RightOutlined as Oe, ZoomOutOutlined as Ce, ZoomInOutlined as Ie, RotateLeftOutlined as ke, RotateRightOutlined as xe, LoadingOutlined as Le } from "@ant-design/icons-vue";
|
|
3
|
-
import {
|
|
3
|
+
import { isServer as T, getPrefixCls as K, getSlotVNode as ee, isInContainer as Se, isString as Ne, getScrollContainer as $e } from "@gx-design-vue/pro-utils";
|
|
4
4
|
import { onMountedOrActivated as se } from "@gx-design-vue/pro-hooks";
|
|
5
5
|
import { createTypes as Te } from "vue-types";
|
|
6
6
|
import { useThrottleFn as Ae, useEventListener as te } from "@vueuse/core";
|
|
@@ -126,16 +126,16 @@ function q(e) {
|
|
|
126
126
|
}));
|
|
127
127
|
};
|
|
128
128
|
}
|
|
129
|
-
const fe = Z({
|
|
129
|
+
const fe = /* @__PURE__ */ Z({
|
|
130
130
|
props: ze,
|
|
131
131
|
emits: ["close", "switch"],
|
|
132
132
|
setup: function(e, {
|
|
133
133
|
emit: a
|
|
134
134
|
}) {
|
|
135
135
|
let d = null, w = null, p = null;
|
|
136
|
-
const
|
|
136
|
+
const i = K({
|
|
137
137
|
suffixCls: "image-viewer"
|
|
138
|
-
}), f = g(!0), h = g(e.initialIndex), k = g(null), x = g(null), O = g(V.CONTAIN),
|
|
138
|
+
}), f = g(!0), h = g(e.initialIndex), k = g(null), x = g(null), O = g(V.CONTAIN), o = g({
|
|
139
139
|
scale: 1,
|
|
140
140
|
deg: 0,
|
|
141
141
|
offsetX: 0,
|
|
@@ -151,13 +151,13 @@ const fe = Z({
|
|
|
151
151
|
scale: n,
|
|
152
152
|
deg: y,
|
|
153
153
|
offsetX: t,
|
|
154
|
-
offsetY:
|
|
154
|
+
offsetY: r,
|
|
155
155
|
enableTransition: c
|
|
156
|
-
} =
|
|
156
|
+
} = o.value, m = {
|
|
157
157
|
transform: `scale(${n}) rotate(${y}deg)`,
|
|
158
158
|
transition: c ? "transform .3s" : "",
|
|
159
159
|
marginLeft: `${t}px`,
|
|
160
|
-
marginTop: `${
|
|
160
|
+
marginTop: `${r}px`
|
|
161
161
|
};
|
|
162
162
|
return O.value.name === V.CONTAIN.name && (m.maxWidth = m.maxHeight = "100%"), m;
|
|
163
163
|
}), z = () => {
|
|
@@ -200,25 +200,25 @@ const fe = Z({
|
|
|
200
200
|
}, E = () => {
|
|
201
201
|
f.value = !1;
|
|
202
202
|
}, D = (n) => {
|
|
203
|
-
f.value = !1, n.target.alt = "
|
|
203
|
+
f.value = !1, n.target.alt = "加载失败";
|
|
204
204
|
}, H = (n) => {
|
|
205
205
|
if (f.value || n.button !== 0)
|
|
206
206
|
return;
|
|
207
207
|
const {
|
|
208
208
|
offsetX: y,
|
|
209
209
|
offsetY: t
|
|
210
|
-
} =
|
|
210
|
+
} = o.value, r = n.pageX, c = n.pageY;
|
|
211
211
|
p = q((m) => {
|
|
212
|
-
|
|
213
|
-
...
|
|
214
|
-
offsetX: y + m.pageX -
|
|
212
|
+
o.value = {
|
|
213
|
+
...o.value,
|
|
214
|
+
offsetX: y + m.pageX - r,
|
|
215
215
|
offsetY: t + m.pageY - c
|
|
216
216
|
};
|
|
217
217
|
}), Y(document, "mousemove", p), Y(document, "mouseup", () => {
|
|
218
218
|
X(document, "mousemove", p);
|
|
219
219
|
}), n.preventDefault();
|
|
220
220
|
}, F = () => {
|
|
221
|
-
|
|
221
|
+
o.value = {
|
|
222
222
|
scale: 1,
|
|
223
223
|
deg: 0,
|
|
224
224
|
offsetX: 0,
|
|
@@ -245,7 +245,7 @@ const fe = Z({
|
|
|
245
245
|
return;
|
|
246
246
|
const {
|
|
247
247
|
zoomRate: t,
|
|
248
|
-
rotateDeg:
|
|
248
|
+
rotateDeg: r,
|
|
249
249
|
enableTransition: c
|
|
250
250
|
} = {
|
|
251
251
|
zoomRate: 0.2,
|
|
@@ -255,19 +255,19 @@ const fe = Z({
|
|
|
255
255
|
};
|
|
256
256
|
switch (n) {
|
|
257
257
|
case "zoomOut":
|
|
258
|
-
|
|
258
|
+
o.value.scale > 0.2 && (o.value.scale = parseFloat((o.value.scale - t).toFixed(3)));
|
|
259
259
|
break;
|
|
260
260
|
case "zoomIn":
|
|
261
|
-
|
|
261
|
+
o.value.scale = parseFloat((o.value.scale + t).toFixed(3));
|
|
262
262
|
break;
|
|
263
263
|
case "clocelise":
|
|
264
|
-
|
|
264
|
+
o.value.deg += r;
|
|
265
265
|
break;
|
|
266
266
|
case "anticlocelise":
|
|
267
|
-
|
|
267
|
+
o.value.deg -= r;
|
|
268
268
|
break;
|
|
269
269
|
}
|
|
270
|
-
|
|
270
|
+
o.value.enableTransition = c;
|
|
271
271
|
};
|
|
272
272
|
return U(I, () => {
|
|
273
273
|
oe(() => {
|
|
@@ -281,50 +281,50 @@ const fe = Z({
|
|
|
281
281
|
}), () => l("div", {
|
|
282
282
|
ref: (n) => k.value = n,
|
|
283
283
|
tabindex: 1,
|
|
284
|
-
class: [`${
|
|
284
|
+
class: [`${i}-wrapper`, `${L.value}`],
|
|
285
285
|
style: {
|
|
286
286
|
zIndex: e.zIndex
|
|
287
287
|
}
|
|
288
288
|
}, [l("div", {
|
|
289
|
-
class: `${
|
|
289
|
+
class: `${i}-mask`,
|
|
290
290
|
onClick: () => e.onHideOnClickModal && z()
|
|
291
291
|
}, null), l("span", {
|
|
292
|
-
class: [`${
|
|
292
|
+
class: [`${i}-btn`, `${i}-close`],
|
|
293
293
|
onClick: () => z()
|
|
294
294
|
}, [l(be, null, null)]), !u.value && l(re, null, [l("span", {
|
|
295
295
|
class: {
|
|
296
|
-
[`${
|
|
297
|
-
[`${
|
|
296
|
+
[`${i}-btn`]: !0,
|
|
297
|
+
[`${i}-prev`]: !0,
|
|
298
298
|
["is-disabled"]: !e.infinite && s.value
|
|
299
299
|
},
|
|
300
300
|
onClick: () => R()
|
|
301
301
|
}, [l(pe, null, null)]), l("span", {
|
|
302
302
|
class: {
|
|
303
|
-
[`${
|
|
304
|
-
[`${
|
|
303
|
+
[`${i}-btn`]: !0,
|
|
304
|
+
[`${i}-next`]: !0,
|
|
305
305
|
["is-disabled"]: !e.infinite && s.value
|
|
306
306
|
},
|
|
307
307
|
onClick: () => j()
|
|
308
308
|
}, [l(Oe, null, null)])]), l("div", {
|
|
309
|
-
class: [`${
|
|
309
|
+
class: [`${i}-btn`, `${i}-actions`]
|
|
310
310
|
}, [l("div", {
|
|
311
|
-
class: `${
|
|
311
|
+
class: `${i}-actions-inner`
|
|
312
312
|
}, [l(Ce, {
|
|
313
313
|
onClick: () => C("zoomOut")
|
|
314
314
|
}, null), l(Ie, {
|
|
315
315
|
onClick: () => C("zoomIn")
|
|
316
316
|
}, null), l("i", {
|
|
317
|
-
class: `${
|
|
317
|
+
class: `${i}-actions-divider`
|
|
318
318
|
}, null), l("i", {
|
|
319
319
|
onClick: () => M()
|
|
320
320
|
}, [O.value.icon]), l("i", {
|
|
321
|
-
class: `${
|
|
321
|
+
class: `${i}-actions-divider`
|
|
322
322
|
}, null), l(ke, {
|
|
323
323
|
onClick: () => C("anticlocelise")
|
|
324
324
|
}, null), l(xe, {
|
|
325
325
|
onClick: () => C("clocelise")
|
|
326
326
|
}, null)])]), f.value && l("div", {
|
|
327
|
-
class: `${
|
|
327
|
+
class: `${i}-canvas`
|
|
328
328
|
}, [l(ue("a-spin"), {
|
|
329
329
|
indicator: l(Le, {
|
|
330
330
|
style: {
|
|
@@ -333,10 +333,10 @@ const fe = Z({
|
|
|
333
333
|
}
|
|
334
334
|
}, null)
|
|
335
335
|
}, null)]), l("div", {
|
|
336
|
-
class: `${
|
|
336
|
+
class: `${i}-canvas`
|
|
337
337
|
}, [e.urlList.map((n, y) => l("img", {
|
|
338
338
|
ref: (t) => x.value = t,
|
|
339
|
-
class: `${
|
|
339
|
+
class: `${i}-img`,
|
|
340
340
|
key: n,
|
|
341
341
|
style: {
|
|
342
342
|
...A.value,
|
|
@@ -353,7 +353,7 @@ function Fe(e) {
|
|
|
353
353
|
return typeof e == "function" || Object.prototype.toString.call(e) === "[object Object]" && !me(e);
|
|
354
354
|
}
|
|
355
355
|
let le = "";
|
|
356
|
-
const Ge = Z({
|
|
356
|
+
const Ge = /* @__PURE__ */ Z({
|
|
357
357
|
props: {
|
|
358
358
|
hideOnClickModal: P.hideOnClickModal
|
|
359
359
|
},
|
|
@@ -362,16 +362,16 @@ const Ge = Z({
|
|
|
362
362
|
}) {
|
|
363
363
|
const d = K({
|
|
364
364
|
suffixCls: "image-viewer-group"
|
|
365
|
-
}), w = g(!1), p = g(""),
|
|
365
|
+
}), w = g(!1), p = g(""), i = b(() => {
|
|
366
366
|
var u, s, v, I, L;
|
|
367
367
|
return ((u = a.default) == null ? void 0 : u.call(a).length) === 1 && (String((s = a.default) == null ? void 0 : s.call(a)[0].type) === String(Symbol("Fragment")) || String((v = a.default) == null ? void 0 : v.call(a)[0].type) === String(Symbol())) ? ((I = a.default) == null ? void 0 : I.call(a)[0].children) || [] : ((L = a.default) == null ? void 0 : L.call(a)) || [];
|
|
368
|
-
}), f = b(() =>
|
|
368
|
+
}), f = b(() => i.value.filter((v) => k(v)).map((v) => v.props.src).filter((v) => v) || []), h = b(() => Array.isArray(f.value) && f.value.length > 0), k = (u) => u && u.type && (u.type.isGImage || u.type.name === "GImage"), x = () => {
|
|
369
369
|
let u = 0;
|
|
370
370
|
const s = f.value.findIndex((v) => v === p.value);
|
|
371
371
|
return s >= 0 && (u = s), u;
|
|
372
372
|
}, O = (u) => {
|
|
373
373
|
!h.value || !u || (p.value = u, le = document.body.style.overflow, document.body.style.overflow = "hidden", w.value = !0);
|
|
374
|
-
},
|
|
374
|
+
}, o = () => {
|
|
375
375
|
document.body.style.overflow = le, w.value = !1;
|
|
376
376
|
};
|
|
377
377
|
return () => {
|
|
@@ -380,7 +380,7 @@ const Ge = Z({
|
|
|
380
380
|
class: `${d}`
|
|
381
381
|
}, [l(ue("a-space"), {
|
|
382
382
|
size: 15
|
|
383
|
-
}, Fe(u =
|
|
383
|
+
}, Fe(u = i.value.map((s, v) => k(s) ? l("div", {
|
|
384
384
|
key: v,
|
|
385
385
|
class: `${d}-item`,
|
|
386
386
|
onClick: () => {
|
|
@@ -398,7 +398,7 @@ const Ge = Z({
|
|
|
398
398
|
initialIndex: x(),
|
|
399
399
|
urlList: f.value,
|
|
400
400
|
onHideOnClickModal: e.hideOnClickModal,
|
|
401
|
-
onClose: () =>
|
|
401
|
+
onClose: () => o()
|
|
402
402
|
}, null)]
|
|
403
403
|
})]);
|
|
404
404
|
};
|
|
@@ -411,7 +411,7 @@ const N = {
|
|
|
411
411
|
COVER: "cover",
|
|
412
412
|
FILL: "fill",
|
|
413
413
|
SCALE_DOWN: "scale-down"
|
|
414
|
-
}, G = Z({
|
|
414
|
+
}, G = /* @__PURE__ */ Z({
|
|
415
415
|
props: P,
|
|
416
416
|
name: "GImage",
|
|
417
417
|
inheritAttrs: !1,
|
|
@@ -423,7 +423,7 @@ const N = {
|
|
|
423
423
|
}) {
|
|
424
424
|
const p = K({
|
|
425
425
|
suffixCls: "image"
|
|
426
|
-
}),
|
|
426
|
+
}), i = g(!1), f = g(!0), h = g(0), k = g(0), x = g(!1), O = g(null), o = g();
|
|
427
427
|
let u, s;
|
|
428
428
|
const v = b(() => ({
|
|
429
429
|
width: e.width ? `${e.width}px` : void 0,
|
|
@@ -452,23 +452,23 @@ const N = {
|
|
|
452
452
|
}), z = b(() => {
|
|
453
453
|
const {
|
|
454
454
|
src: t,
|
|
455
|
-
previewSrcList:
|
|
455
|
+
previewSrcList: r
|
|
456
456
|
} = e;
|
|
457
457
|
let c = 0;
|
|
458
|
-
const m =
|
|
458
|
+
const m = r.indexOf(t);
|
|
459
459
|
return m >= 0 && (c = m), c;
|
|
460
460
|
}), S = b(() => w), W = (t) => {
|
|
461
|
-
const
|
|
461
|
+
const r = e.width || h.value, c = e.height || k.value;
|
|
462
462
|
if (!O.value)
|
|
463
463
|
return {};
|
|
464
464
|
const {
|
|
465
465
|
clientWidth: m,
|
|
466
466
|
clientHeight: B
|
|
467
467
|
} = O.value;
|
|
468
|
-
if (!
|
|
468
|
+
if (!r || !c || !m || !B)
|
|
469
469
|
return {};
|
|
470
|
-
const J =
|
|
471
|
-
switch (t === N.SCALE_DOWN && (t =
|
|
470
|
+
const J = r / c, Q = m / B;
|
|
471
|
+
switch (t === N.SCALE_DOWN && (t = r < m && c < B ? N.NONE : N.CONTAIN), t) {
|
|
472
472
|
case N.NONE:
|
|
473
473
|
return {
|
|
474
474
|
width: "auto",
|
|
@@ -493,35 +493,34 @@ const N = {
|
|
|
493
493
|
if (T)
|
|
494
494
|
return;
|
|
495
495
|
const t = S.value;
|
|
496
|
-
f.value = !0,
|
|
497
|
-
const
|
|
498
|
-
|
|
496
|
+
f.value = !0, i.value = !1;
|
|
497
|
+
const r = new Image();
|
|
498
|
+
r.onload = (c) => R(c, r), r.onerror = j, Object.keys(t).forEach((c) => {
|
|
499
499
|
if (c.toLowerCase() === "onload")
|
|
500
500
|
return;
|
|
501
501
|
const m = t[c];
|
|
502
|
-
|
|
503
|
-
}),
|
|
502
|
+
r.setAttribute(c, m);
|
|
503
|
+
}), r.src = e.src;
|
|
504
504
|
};
|
|
505
505
|
function D() {
|
|
506
|
-
Se(O.value,
|
|
506
|
+
Se(O.value, o.value) && (E(), M());
|
|
507
507
|
}
|
|
508
508
|
const H = Ae(D, 200), F = async () => {
|
|
509
|
-
var i;
|
|
510
509
|
if (T)
|
|
511
510
|
return;
|
|
512
511
|
await oe();
|
|
513
512
|
const {
|
|
514
513
|
scrollContainer: t
|
|
515
514
|
} = e;
|
|
516
|
-
Me(t) ?
|
|
515
|
+
Me(t) ? o.value = t : Ne(t) && t !== "" ? o.value = document.querySelector(t) ?? void 0 : O.value && (o.value = $e(O.value)), o.value && (u = te(o, "scroll", H), setTimeout(() => D(), 200));
|
|
517
516
|
}, M = () => {
|
|
518
|
-
T || !
|
|
519
|
-
}, R = (t,
|
|
520
|
-
h.value =
|
|
517
|
+
T || !o.value || !H || (u(), o.value = void 0);
|
|
518
|
+
}, R = (t, r) => {
|
|
519
|
+
h.value = r.width, k.value = r.height, f.value = !1, i.value = !1;
|
|
521
520
|
}, j = (t) => {
|
|
522
|
-
f.value = !1,
|
|
521
|
+
f.value = !1, i.value = !0, d("error", t);
|
|
523
522
|
}, C = (t) => {
|
|
524
|
-
if (
|
|
523
|
+
if (t.ctrlKey) {
|
|
525
524
|
if (t.deltaY < 0)
|
|
526
525
|
return t.preventDefault(), !1;
|
|
527
526
|
if (t.deltaY > 0)
|
|
@@ -535,11 +534,11 @@ const N = {
|
|
|
535
534
|
s == null || s(), document.body.style.overflow = ie, x.value = !1;
|
|
536
535
|
};
|
|
537
536
|
return U(() => e.src, () => {
|
|
538
|
-
e.lazy ? (f.value = !0,
|
|
537
|
+
e.lazy ? (f.value = !0, i.value = !1, M(), F()) : E();
|
|
539
538
|
}), se(() => {
|
|
540
539
|
e.lazy ? F() : E();
|
|
541
540
|
}), () => {
|
|
542
|
-
const t = ee(a, e, "fallback"),
|
|
541
|
+
const t = ee(a, e, "fallback"), r = ee(a, e, "placeholder");
|
|
543
542
|
return l(re, null, [l("div", {
|
|
544
543
|
class: {
|
|
545
544
|
[`${p}`]: !0,
|
|
@@ -553,11 +552,11 @@ const N = {
|
|
|
553
552
|
onClick: () => {
|
|
554
553
|
d("click");
|
|
555
554
|
}
|
|
556
|
-
}, [f.value ?
|
|
555
|
+
}, [f.value ? r || l("div", {
|
|
557
556
|
class: `${p}-placeholder`
|
|
558
|
-
}, null) :
|
|
557
|
+
}, null) : i.value ? t || l("div", {
|
|
559
558
|
class: `${p}-error`
|
|
560
|
-
}, [ge("
|
|
559
|
+
}, [ge("加载失败")]) : l("img", he({
|
|
561
560
|
class: {
|
|
562
561
|
[`${p}-inner`]: !0,
|
|
563
562
|
[`${p}-inner-center`]: L.value,
|
package/dist/image.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(v,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("@ant-design/icons-vue"),require("@gx-design-vue/pro-utils"),require("@gx-design-vue/pro-hooks"),require("vue-types"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","vue","@ant-design/icons-vue","@gx-design-vue/pro-utils","@gx-design-vue/pro-hooks","vue-types","@vueuse/core"],e):(v=typeof globalThis<"u"?globalThis:v||self,e(v.GImage={},v.vue,v.iconsVue,v.proUtils,v.proHooks,v.vueTypes,v.core))})(this,function(v,e,O,w,J,oe,W){"use strict";const de="",ue="";var Q=oe.createTypes({func:void 0,bool:void 0,string:void 0,number:void 0,array:void 0,object:void 0,integer:void 0});Q.extend([{name:"looseBool",getter:!0,type:Boolean,default:void 0},{name:"style",getter:!0,type:[String,Object],default:void 0},{name:"VueNode",getter:!0,type:null}]);const H=Q,j={appendToBody:{type:Boolean,default:!1},hideOnClickModal:{type:Boolean,default:!0},src:{type:String,default:""},fit:{type:String,default:""},lazy:H.bool,scrollContainer:{type:[String,Object]},placeholder:{type:[Function,Object],default:()=>{}},fallback:{type:[Function,Object],default:()=>{}},onError:{type:Function},onClick:{type:Function},disablePreview:H.bool,previewSrcList:{type:Array,default:()=>[]},width:H.number,height:H.number,zIndex:{type:Number,default:2e3}},re={urlList:{type:Array,default:()=>[]},zIndex:j.zIndex,initialIndex:{type:Number,default:0},infinite:{type:Boolean,default:!0},onHideOnClickModal:j.hideOnClickModal},T={tab:"Tab",enter:"Enter",space:"Space",left:"ArrowLeft",up:"ArrowUp",right:"ArrowRight",down:"ArrowDown",esc:"Escape",delete:"Delete",backspace:"Backspace"},R=function(t,l,u,N=!1){t&&l&&u&&t.addEventListener(l,u,N)},q=function(t,l,u,N=!1){t&&l&&u&&t.removeEventListener(l,u,N)},A={CONTAIN:{name:"contain",icon:e.createVNode(O.ExpandOutlined,null,null)},ORIGINAL:{name:"original",icon:e.createVNode(O.OneToOneOutlined,null,null)}},U=function(){return!w.isServer&&!!window.navigator.userAgent.match(/firefox/i)}()?"DOMMouseScroll":"mousewheel";function B(t){let l=!1;return function(...u){l||(l=!0,window.requestAnimationFrame(()=>{t.apply(this,u),l=!1}))}}const X=e.defineComponent({props:re,emits:["close","switch"],setup:function(t,{emit:l}){let u=null,N=null,b=null;const r=w.getPrefixCls({suffixCls:"image-viewer"}),f=e.ref(!0),h=e.ref(t.initialIndex),I=e.ref(null),x=e.ref(null),p=e.ref(A.CONTAIN),i=e.ref({scale:1,deg:0,offsetX:0,offsetY:0,enableTransition:!1}),c=e.computed(()=>{const{urlList:a}=t;return a.length<=1}),d=e.computed(()=>h.value===0),m=e.computed(()=>h.value===t.urlList.length-1),k=e.computed(()=>t.urlList[h.value]),S=e.ref("viewer-fade-enter-active"),E=e.computed(()=>{const{scale:a,deg:y,offsetX:n,offsetY:o,enableTransition:s}=i.value,g={transform:`scale(${a}) rotate(${y}deg)`,transition:s?"transform .3s":"",marginLeft:`${n}px`,marginTop:`${o}px`};return p.value.name===A.CONTAIN.name&&(g.maxWidth=g.maxHeight="100%"),g}),z=()=>{Z(),setTimeout(()=>{l("close")},200)},L=()=>{S.value="viewer-fade-enter-active",u=B(a=>{switch(a.code){case T.esc:z();break;case T.space:D();break;case T.left:G();break;case T.up:C("zoomIn");break;case T.right:Y();break;case T.down:C("zoomOut");break}}),N=B(a=>{(a.wheelDelta?a.wheelDelta:-a.detail)>0?C("zoomIn",{zoomRate:.015,enableTransition:!1}):C("zoomOut",{zoomRate:.015,enableTransition:!1})}),R(document,"keydown",u),R(document,U,N)},Z=()=>{S.value="viewer-fade-leave-active",q(document,"keydown",u),q(document,U,N),u=null,N=null},F=()=>{f.value=!1},_=a=>{f.value=!1,a.target.alt="\u52A0\u8F7D\u5931\u8D25"},P=a=>{if(f.value||a.button!==0)return;const{offsetX:y,offsetY:n}=i.value,o=a.pageX,s=a.pageY;b=B(g=>{i.value={...i.value,offsetX:y+g.pageX-o,offsetY:n+g.pageY-s}}),R(document,"mousemove",b),R(document,"mouseup",()=>{q(document,"mousemove",b)}),a.preventDefault()},M=()=>{i.value={scale:1,deg:0,offsetX:0,offsetY:0,enableTransition:!1}},D=()=>{if(f.value)return;const a=Object.keys(A),y=Object.values(A),n=p.value.name,s=(y.findIndex(g=>g.name===n)+1)%a.length;p.value=A[a[s]],M()},G=()=>{if(d.value&&!t.infinite)return;const a=t.urlList.length;h.value=(h.value-1+a)%a},Y=()=>{if(m.value&&!t.infinite)return;const a=t.urlList.length;h.value=(h.value+1)%a},C=(a,y={})=>{if(f.value)return;const{zoomRate:n,rotateDeg:o,enableTransition:s}={zoomRate:.2,rotateDeg:90,enableTransition:!0,...y};switch(a){case"zoomOut":i.value.scale>.2&&(i.value.scale=parseFloat((i.value.scale-n).toFixed(3)));break;case"zoomIn":i.value.scale=parseFloat((i.value.scale+n).toFixed(3));break;case"clocelise":i.value.deg+=o;break;case"anticlocelise":i.value.deg-=o;break}i.value.enableTransition=s};return e.watch(k,()=>{e.nextTick(()=>{x.value.complete||(f.value=!0)})}),e.watch(h,a=>{M(),l("switch",a)}),J.onMountedOrActivated(()=>{var a,y;L(),(y=(a=I.value)==null?void 0:a.focus)==null||y.call(a)}),()=>e.createVNode("div",{ref:a=>I.value=a,tabindex:1,class:[`${r}-wrapper`,`${S.value}`],style:{zIndex:t.zIndex}},[e.createVNode("div",{class:`${r}-mask`,onClick:()=>t.onHideOnClickModal&&z()},null),e.createVNode("span",{class:[`${r}-btn`,`${r}-close`],onClick:()=>z()},[e.createVNode(O.CloseOutlined,null,null)]),!c.value&&e.createVNode(e.Fragment,null,[e.createVNode("span",{class:{[`${r}-btn`]:!0,[`${r}-prev`]:!0,["is-disabled"]:!t.infinite&&d.value},onClick:()=>G()},[e.createVNode(O.LeftOutlined,null,null)]),e.createVNode("span",{class:{[`${r}-btn`]:!0,[`${r}-next`]:!0,["is-disabled"]:!t.infinite&&d.value},onClick:()=>Y()},[e.createVNode(O.RightOutlined,null,null)])]),e.createVNode("div",{class:[`${r}-btn`,`${r}-actions`]},[e.createVNode("div",{class:`${r}-actions-inner`},[e.createVNode(O.ZoomOutOutlined,{onClick:()=>C("zoomOut")},null),e.createVNode(O.ZoomInOutlined,{onClick:()=>C("zoomIn")},null),e.createVNode("i",{class:`${r}-actions-divider`},null),e.createVNode("i",{onClick:()=>D()},[p.value.icon]),e.createVNode("i",{class:`${r}-actions-divider`},null),e.createVNode(O.RotateLeftOutlined,{onClick:()=>C("anticlocelise")},null),e.createVNode(O.RotateRightOutlined,{onClick:()=>C("clocelise")},null)])]),f.value&&e.createVNode("div",{class:`${r}-canvas`},[e.createVNode(e.resolveComponent("a-spin"),{indicator:e.createVNode(O.LoadingOutlined,{style:{color:"#fff",fontSize:"40px"}},null)},null)]),e.createVNode("div",{class:`${r}-canvas`},[t.urlList.map((a,y)=>e.createVNode("img",{ref:n=>x.value=n,class:`${r}-img`,key:a,style:{...E.value,display:y===h.value?"block":"none"},src:a,onLoad:()=>F(),onError:n=>_(n),onMousedown:n=>P(n)},null))])])}});function ie(t){return typeof t=="function"||Object.prototype.toString.call(t)==="[object Object]"&&!e.isVNode(t)}let ee="";const ce=e.defineComponent({props:{hideOnClickModal:j.hideOnClickModal},setup(t,{slots:l}){const u=w.getPrefixCls({suffixCls:"image-viewer-group"}),N=e.ref(!1),b=e.ref(""),r=e.computed(()=>{var c,d,m,k,S;return((c=l.default)==null?void 0:c.call(l).length)===1&&(String((d=l.default)==null?void 0:d.call(l)[0].type)===String(Symbol("Fragment"))||String((m=l.default)==null?void 0:m.call(l)[0].type)===String(Symbol()))?((k=l.default)==null?void 0:k.call(l)[0].children)||[]:((S=l.default)==null?void 0:S.call(l))||[]}),f=e.computed(()=>r.value.filter(m=>I(m)).map(m=>m.props.src).filter(m=>m)||[]),h=e.computed(()=>Array.isArray(f.value)&&f.value.length>0),I=c=>c&&c.type&&(c.type.isGImage||c.type.name==="GImage"),x=()=>{let c=0;const d=f.value.findIndex(m=>m===b.value);return d>=0&&(c=d),c},p=c=>{!h.value||!c||(b.value=c,ee=document.body.style.overflow,document.body.style.overflow="hidden",N.value=!0)},i=()=>{document.body.style.overflow=ee,N.value=!1};return()=>{let c;return e.createVNode("div",{class:`${u}`},[e.createVNode(e.resolveComponent("a-space"),{size:15},ie(c=r.value.map((d,m)=>I(d)?e.createVNode("div",{key:m,class:`${u}-item`,onClick:()=>{var k;return p(((k=d.props)==null?void 0:k.src)||"")}},[e.cloneVNode(d,{disablePreview:!0})]):null))?c:{default:()=>[c]}),e.createVNode(e.Teleport,{to:"body"},{default:()=>[h.value&&N.value&&e.createVNode(X,{initialIndex:x(),urlList:f.value,onHideOnClickModal:t.hideOnClickModal,onClose:()=>i()},null)]})])}}}),se=t=>t&&t.nodeType===Node.ELEMENT_NODE,te=()=>document.documentElement.style.objectFit!==void 0;let ne="";const V={NONE:"none",CONTAIN:"contain",COVER:"cover",FILL:"fill",SCALE_DOWN:"scale-down"},$=e.defineComponent({props:j,name:"GImage",inheritAttrs:!1,emits:["error","click"],setup(t,{slots:l,emit:u,attrs:N}){const b=w.getPrefixCls({suffixCls:"image"}),r=e.ref(!1),f=e.ref(!0),h=e.ref(0),I=e.ref(0),x=e.ref(!1),p=e.ref(null),i=e.ref();let c,d;const m=e.computed(()=>({width:t.width?`${t.width}px`:void 0,height:t.height?`${t.height}px`:void 0})),k=e.computed(()=>{const{fit:n}=t;return!w.isServer&&n?te()?{"object-fit":n,...m.value}:{...Z(n),...m.value}:m.value}),S=e.computed(()=>{const{fit:n}=t;return!w.isServer&&!te()&&n!==V.FILL}),E=e.computed(()=>{const{previewSrcList:n}=t;return Array.isArray(n)&&n.length>0}),z=e.computed(()=>{const{src:n,previewSrcList:o}=t;let s=0;const g=o.indexOf(n);return g>=0&&(s=g),s}),L=e.computed(()=>N),Z=n=>{const o=t.width||h.value,s=t.height||I.value;if(!p.value)return{};const{clientWidth:g,clientHeight:K}=p.value;if(!o||!s||!g||!K)return{};const ae=o/s,le=g/K;switch(n===V.SCALE_DOWN&&(n=o<g&&s<K?V.NONE:V.CONTAIN),n){case V.NONE:return{width:"auto",height:"auto"};case V.CONTAIN:return ae<le?{width:"auto"}:{height:"auto"};case V.COVER:return ae<le?{height:"auto"}:{width:"auto"};default:return{}}},F=()=>{if(w.isServer)return;const n=L.value;f.value=!0,r.value=!1;const o=new Image;o.onload=s=>G(s,o),o.onerror=Y,Object.keys(n).forEach(s=>{if(s.toLowerCase()==="onload")return;const g=n[s];o.setAttribute(s,g)}),o.src=t.src};function _(){w.isInContainer(p.value,i.value)&&(F(),D())}const P=W.useThrottleFn(_,200),M=async()=>{var o;if(w.isServer)return;await e.nextTick();const{scrollContainer:n}=t;se(n)?i.value=n:w.isString(n)&&n!==""?i.value=(o=document.querySelector(n))!=null?o:void 0:p.value&&(i.value=w.getScrollContainer(p.value)),i.value&&(c=W.useEventListener(i,"scroll",P),setTimeout(()=>_(),200))},D=()=>{w.isServer||!i.value||!P||(c(),i.value=void 0)},G=(n,o)=>{h.value=o.width,I.value=o.height,f.value=!1,r.value=!1},Y=n=>{f.value=!1,r.value=!0,u("error",n)},C=n=>{if(!!n.ctrlKey){if(n.deltaY<0)return n.preventDefault(),!1;if(n.deltaY>0)return n.preventDefault(),!1}},a=()=>{!E.value||t.disablePreview||(d=W.useEventListener("wheel",C,{passive:!1}),ne=document.body.style.overflow,document.body.style.overflow="hidden",x.value=!0)},y=()=>{d==null||d(),document.body.style.overflow=ne,x.value=!1};return e.watch(()=>t.src,()=>{t.lazy?(f.value=!0,r.value=!1,D(),M()):F()}),J.onMountedOrActivated(()=>{t.lazy?M():F()}),()=>{const n=w.getSlotVNode(l,t,"fallback"),o=w.getSlotVNode(l,t,"placeholder");return e.createVNode(e.Fragment,null,[e.createVNode("div",{class:{[`${b}`]:!0,[`${L.value.class}`]:L.value.class},ref:s=>p.value=s,style:{...L.value.style||{},display:t.lazy?"block":void 0},onClick:()=>{u("click")}},[f.value?o||e.createVNode("div",{class:`${b}-placeholder`},null):r.value?n||e.createVNode("div",{class:`${b}-error`},[e.createTextVNode("\u52A0\u8F7D\u5931\u8D25")]):e.createVNode("img",e.mergeProps({class:{[`${b}-inner`]:!0,[`${b}-inner-center`]:S.value,[`${b}-preview`]:E.value}},L.value,{src:t.src,style:k.value,onClick:()=>a()}),null),e.createVNode(e.Teleport,{to:"body",disabled:!t.appendToBody},{default:()=>[E.value&&x.value&&e.createVNode(X,{zIndex:t.zIndex,initialIndex:z.value,urlList:t.previewSrcList,onHideOnClickModal:t.hideOnClickModal,onClose:()=>y()},null)]})])])}}});$.isWImage=!0,$.install=t=>(t.component($.name,$),t),v.GImage=$,v.ImageViewer=X,v.ImageViewerGroup=ce,v.default=$,Object.defineProperties(v,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
1
|
+
(function(v,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("@ant-design/icons-vue"),require("@gx-design-vue/pro-utils"),require("@gx-design-vue/pro-hooks"),require("vue-types"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","vue","@ant-design/icons-vue","@gx-design-vue/pro-utils","@gx-design-vue/pro-hooks","vue-types","@vueuse/core"],e):(v=typeof globalThis<"u"?globalThis:v||self,e(v.GImage={},v.vue,v.iconsVue,v.proUtils,v.proHooks,v.vueTypes,v.core))})(this,function(v,e,O,w,J,oe,W){"use strict";const de="",ue="";var Q=oe.createTypes({func:void 0,bool:void 0,string:void 0,number:void 0,array:void 0,object:void 0,integer:void 0});Q.extend([{name:"looseBool",getter:!0,type:Boolean,default:void 0},{name:"style",getter:!0,type:[String,Object],default:void 0},{name:"VueNode",getter:!0,type:null}]);const H=Q,j={appendToBody:{type:Boolean,default:!1},hideOnClickModal:{type:Boolean,default:!0},src:{type:String,default:""},fit:{type:String,default:""},lazy:H.bool,scrollContainer:{type:[String,Object]},placeholder:{type:[Function,Object],default:()=>{}},fallback:{type:[Function,Object],default:()=>{}},onError:{type:Function},onClick:{type:Function},disablePreview:H.bool,previewSrcList:{type:Array,default:()=>[]},width:H.number,height:H.number,zIndex:{type:Number,default:2e3}},re={urlList:{type:Array,default:()=>[]},zIndex:j.zIndex,initialIndex:{type:Number,default:0},infinite:{type:Boolean,default:!0},onHideOnClickModal:j.hideOnClickModal},T={tab:"Tab",enter:"Enter",space:"Space",left:"ArrowLeft",up:"ArrowUp",right:"ArrowRight",down:"ArrowDown",esc:"Escape",delete:"Delete",backspace:"Backspace"},R=function(t,l,u,N=!1){t&&l&&u&&t.addEventListener(l,u,N)},q=function(t,l,u,N=!1){t&&l&&u&&t.removeEventListener(l,u,N)},A={CONTAIN:{name:"contain",icon:e.createVNode(O.ExpandOutlined,null,null)},ORIGINAL:{name:"original",icon:e.createVNode(O.OneToOneOutlined,null,null)}},U=function(){return!w.isServer&&!!window.navigator.userAgent.match(/firefox/i)}()?"DOMMouseScroll":"mousewheel";function B(t){let l=!1;return function(...u){l||(l=!0,window.requestAnimationFrame(()=>{t.apply(this,u),l=!1}))}}const X=e.defineComponent({props:re,emits:["close","switch"],setup:function(t,{emit:l}){let u=null,N=null,b=null;const o=w.getPrefixCls({suffixCls:"image-viewer"}),f=e.ref(!0),h=e.ref(t.initialIndex),I=e.ref(null),x=e.ref(null),p=e.ref(A.CONTAIN),r=e.ref({scale:1,deg:0,offsetX:0,offsetY:0,enableTransition:!1}),c=e.computed(()=>{const{urlList:a}=t;return a.length<=1}),d=e.computed(()=>h.value===0),m=e.computed(()=>h.value===t.urlList.length-1),k=e.computed(()=>t.urlList[h.value]),S=e.ref("viewer-fade-enter-active"),E=e.computed(()=>{const{scale:a,deg:y,offsetX:n,offsetY:i,enableTransition:s}=r.value,g={transform:`scale(${a}) rotate(${y}deg)`,transition:s?"transform .3s":"",marginLeft:`${n}px`,marginTop:`${i}px`};return p.value.name===A.CONTAIN.name&&(g.maxWidth=g.maxHeight="100%"),g}),z=()=>{Z(),setTimeout(()=>{l("close")},200)},L=()=>{S.value="viewer-fade-enter-active",u=B(a=>{switch(a.code){case T.esc:z();break;case T.space:D();break;case T.left:G();break;case T.up:C("zoomIn");break;case T.right:Y();break;case T.down:C("zoomOut");break}}),N=B(a=>{(a.wheelDelta?a.wheelDelta:-a.detail)>0?C("zoomIn",{zoomRate:.015,enableTransition:!1}):C("zoomOut",{zoomRate:.015,enableTransition:!1})}),R(document,"keydown",u),R(document,U,N)},Z=()=>{S.value="viewer-fade-leave-active",q(document,"keydown",u),q(document,U,N),u=null,N=null},F=()=>{f.value=!1},_=a=>{f.value=!1,a.target.alt="加载失败"},P=a=>{if(f.value||a.button!==0)return;const{offsetX:y,offsetY:n}=r.value,i=a.pageX,s=a.pageY;b=B(g=>{r.value={...r.value,offsetX:y+g.pageX-i,offsetY:n+g.pageY-s}}),R(document,"mousemove",b),R(document,"mouseup",()=>{q(document,"mousemove",b)}),a.preventDefault()},M=()=>{r.value={scale:1,deg:0,offsetX:0,offsetY:0,enableTransition:!1}},D=()=>{if(f.value)return;const a=Object.keys(A),y=Object.values(A),n=p.value.name,s=(y.findIndex(g=>g.name===n)+1)%a.length;p.value=A[a[s]],M()},G=()=>{if(d.value&&!t.infinite)return;const a=t.urlList.length;h.value=(h.value-1+a)%a},Y=()=>{if(m.value&&!t.infinite)return;const a=t.urlList.length;h.value=(h.value+1)%a},C=(a,y={})=>{if(f.value)return;const{zoomRate:n,rotateDeg:i,enableTransition:s}={zoomRate:.2,rotateDeg:90,enableTransition:!0,...y};switch(a){case"zoomOut":r.value.scale>.2&&(r.value.scale=parseFloat((r.value.scale-n).toFixed(3)));break;case"zoomIn":r.value.scale=parseFloat((r.value.scale+n).toFixed(3));break;case"clocelise":r.value.deg+=i;break;case"anticlocelise":r.value.deg-=i;break}r.value.enableTransition=s};return e.watch(k,()=>{e.nextTick(()=>{x.value.complete||(f.value=!0)})}),e.watch(h,a=>{M(),l("switch",a)}),J.onMountedOrActivated(()=>{var a,y;L(),(y=(a=I.value)==null?void 0:a.focus)==null||y.call(a)}),()=>e.createVNode("div",{ref:a=>I.value=a,tabindex:1,class:[`${o}-wrapper`,`${S.value}`],style:{zIndex:t.zIndex}},[e.createVNode("div",{class:`${o}-mask`,onClick:()=>t.onHideOnClickModal&&z()},null),e.createVNode("span",{class:[`${o}-btn`,`${o}-close`],onClick:()=>z()},[e.createVNode(O.CloseOutlined,null,null)]),!c.value&&e.createVNode(e.Fragment,null,[e.createVNode("span",{class:{[`${o}-btn`]:!0,[`${o}-prev`]:!0,["is-disabled"]:!t.infinite&&d.value},onClick:()=>G()},[e.createVNode(O.LeftOutlined,null,null)]),e.createVNode("span",{class:{[`${o}-btn`]:!0,[`${o}-next`]:!0,["is-disabled"]:!t.infinite&&d.value},onClick:()=>Y()},[e.createVNode(O.RightOutlined,null,null)])]),e.createVNode("div",{class:[`${o}-btn`,`${o}-actions`]},[e.createVNode("div",{class:`${o}-actions-inner`},[e.createVNode(O.ZoomOutOutlined,{onClick:()=>C("zoomOut")},null),e.createVNode(O.ZoomInOutlined,{onClick:()=>C("zoomIn")},null),e.createVNode("i",{class:`${o}-actions-divider`},null),e.createVNode("i",{onClick:()=>D()},[p.value.icon]),e.createVNode("i",{class:`${o}-actions-divider`},null),e.createVNode(O.RotateLeftOutlined,{onClick:()=>C("anticlocelise")},null),e.createVNode(O.RotateRightOutlined,{onClick:()=>C("clocelise")},null)])]),f.value&&e.createVNode("div",{class:`${o}-canvas`},[e.createVNode(e.resolveComponent("a-spin"),{indicator:e.createVNode(O.LoadingOutlined,{style:{color:"#fff",fontSize:"40px"}},null)},null)]),e.createVNode("div",{class:`${o}-canvas`},[t.urlList.map((a,y)=>e.createVNode("img",{ref:n=>x.value=n,class:`${o}-img`,key:a,style:{...E.value,display:y===h.value?"block":"none"},src:a,onLoad:()=>F(),onError:n=>_(n),onMousedown:n=>P(n)},null))])])}});function ie(t){return typeof t=="function"||Object.prototype.toString.call(t)==="[object Object]"&&!e.isVNode(t)}let ee="";const ce=e.defineComponent({props:{hideOnClickModal:j.hideOnClickModal},setup(t,{slots:l}){const u=w.getPrefixCls({suffixCls:"image-viewer-group"}),N=e.ref(!1),b=e.ref(""),o=e.computed(()=>{var c,d,m,k,S;return((c=l.default)==null?void 0:c.call(l).length)===1&&(String((d=l.default)==null?void 0:d.call(l)[0].type)===String(Symbol("Fragment"))||String((m=l.default)==null?void 0:m.call(l)[0].type)===String(Symbol()))?((k=l.default)==null?void 0:k.call(l)[0].children)||[]:((S=l.default)==null?void 0:S.call(l))||[]}),f=e.computed(()=>o.value.filter(m=>I(m)).map(m=>m.props.src).filter(m=>m)||[]),h=e.computed(()=>Array.isArray(f.value)&&f.value.length>0),I=c=>c&&c.type&&(c.type.isGImage||c.type.name==="GImage"),x=()=>{let c=0;const d=f.value.findIndex(m=>m===b.value);return d>=0&&(c=d),c},p=c=>{!h.value||!c||(b.value=c,ee=document.body.style.overflow,document.body.style.overflow="hidden",N.value=!0)},r=()=>{document.body.style.overflow=ee,N.value=!1};return()=>{let c;return e.createVNode("div",{class:`${u}`},[e.createVNode(e.resolveComponent("a-space"),{size:15},ie(c=o.value.map((d,m)=>I(d)?e.createVNode("div",{key:m,class:`${u}-item`,onClick:()=>{var k;return p(((k=d.props)==null?void 0:k.src)||"")}},[e.cloneVNode(d,{disablePreview:!0})]):null))?c:{default:()=>[c]}),e.createVNode(e.Teleport,{to:"body"},{default:()=>[h.value&&N.value&&e.createVNode(X,{initialIndex:x(),urlList:f.value,onHideOnClickModal:t.hideOnClickModal,onClose:()=>r()},null)]})])}}}),se=t=>t&&t.nodeType===Node.ELEMENT_NODE,te=()=>document.documentElement.style.objectFit!==void 0;let ne="";const V={NONE:"none",CONTAIN:"contain",COVER:"cover",FILL:"fill",SCALE_DOWN:"scale-down"},$=e.defineComponent({props:j,name:"GImage",inheritAttrs:!1,emits:["error","click"],setup(t,{slots:l,emit:u,attrs:N}){const b=w.getPrefixCls({suffixCls:"image"}),o=e.ref(!1),f=e.ref(!0),h=e.ref(0),I=e.ref(0),x=e.ref(!1),p=e.ref(null),r=e.ref();let c,d;const m=e.computed(()=>({width:t.width?`${t.width}px`:void 0,height:t.height?`${t.height}px`:void 0})),k=e.computed(()=>{const{fit:n}=t;return!w.isServer&&n?te()?{"object-fit":n,...m.value}:{...Z(n),...m.value}:m.value}),S=e.computed(()=>{const{fit:n}=t;return!w.isServer&&!te()&&n!==V.FILL}),E=e.computed(()=>{const{previewSrcList:n}=t;return Array.isArray(n)&&n.length>0}),z=e.computed(()=>{const{src:n,previewSrcList:i}=t;let s=0;const g=i.indexOf(n);return g>=0&&(s=g),s}),L=e.computed(()=>N),Z=n=>{const i=t.width||h.value,s=t.height||I.value;if(!p.value)return{};const{clientWidth:g,clientHeight:K}=p.value;if(!i||!s||!g||!K)return{};const ae=i/s,le=g/K;switch(n===V.SCALE_DOWN&&(n=i<g&&s<K?V.NONE:V.CONTAIN),n){case V.NONE:return{width:"auto",height:"auto"};case V.CONTAIN:return ae<le?{width:"auto"}:{height:"auto"};case V.COVER:return ae<le?{height:"auto"}:{width:"auto"};default:return{}}},F=()=>{if(w.isServer)return;const n=L.value;f.value=!0,o.value=!1;const i=new Image;i.onload=s=>G(s,i),i.onerror=Y,Object.keys(n).forEach(s=>{if(s.toLowerCase()==="onload")return;const g=n[s];i.setAttribute(s,g)}),i.src=t.src};function _(){w.isInContainer(p.value,r.value)&&(F(),D())}const P=W.useThrottleFn(_,200),M=async()=>{if(w.isServer)return;await e.nextTick();const{scrollContainer:n}=t;se(n)?r.value=n:w.isString(n)&&n!==""?r.value=document.querySelector(n)??void 0:p.value&&(r.value=w.getScrollContainer(p.value)),r.value&&(c=W.useEventListener(r,"scroll",P),setTimeout(()=>_(),200))},D=()=>{w.isServer||!r.value||!P||(c(),r.value=void 0)},G=(n,i)=>{h.value=i.width,I.value=i.height,f.value=!1,o.value=!1},Y=n=>{f.value=!1,o.value=!0,u("error",n)},C=n=>{if(n.ctrlKey){if(n.deltaY<0)return n.preventDefault(),!1;if(n.deltaY>0)return n.preventDefault(),!1}},a=()=>{!E.value||t.disablePreview||(d=W.useEventListener("wheel",C,{passive:!1}),ne=document.body.style.overflow,document.body.style.overflow="hidden",x.value=!0)},y=()=>{d==null||d(),document.body.style.overflow=ne,x.value=!1};return e.watch(()=>t.src,()=>{t.lazy?(f.value=!0,o.value=!1,D(),M()):F()}),J.onMountedOrActivated(()=>{t.lazy?M():F()}),()=>{const n=w.getSlotVNode(l,t,"fallback"),i=w.getSlotVNode(l,t,"placeholder");return e.createVNode(e.Fragment,null,[e.createVNode("div",{class:{[`${b}`]:!0,[`${L.value.class}`]:L.value.class},ref:s=>p.value=s,style:{...L.value.style||{},display:t.lazy?"block":void 0},onClick:()=>{u("click")}},[f.value?i||e.createVNode("div",{class:`${b}-placeholder`},null):o.value?n||e.createVNode("div",{class:`${b}-error`},[e.createTextVNode("加载失败")]):e.createVNode("img",e.mergeProps({class:{[`${b}-inner`]:!0,[`${b}-inner-center`]:S.value,[`${b}-preview`]:E.value}},L.value,{src:t.src,style:k.value,onClick:()=>a()}),null),e.createVNode(e.Teleport,{to:"body",disabled:!t.appendToBody},{default:()=>[E.value&&x.value&&e.createVNode(X,{zIndex:t.zIndex,initialIndex:z.value,urlList:t.previewSrcList,onHideOnClickModal:t.hideOnClickModal,onClose:()=>y()},null)]})])])}}});$.isWImage=!0,$.install=t=>(t.component($.name,$),t),v.GImage=$,v.ImageViewer=X,v.ImageViewerGroup=ce,v.default=$,Object.defineProperties(v,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gx-design-vue/image",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "vite",
|
|
6
6
|
"build": "vite build",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@vueuse/core": "^9.10.0",
|
|
29
|
-
"@gx-design-vue/pro-utils": "^0.
|
|
30
|
-
"@gx-design-vue/pro-hooks": "^0.
|
|
29
|
+
"@gx-design-vue/pro-utils": "^0.1.1",
|
|
30
|
+
"@gx-design-vue/pro-hooks": "^0.1.1",
|
|
31
31
|
"ant-design-vue": "^3.2.15",
|
|
32
32
|
"vue": "^3.2.45",
|
|
33
33
|
"vue-types": "^4.1.1"
|
|
@@ -43,7 +43,6 @@
|
|
|
43
43
|
"@vitejs/plugin-vue-jsx": "^3.0.0",
|
|
44
44
|
"@vue/eslint-config-prettier": "^7.0.0",
|
|
45
45
|
"@vue/eslint-config-typescript": "^10.0.0",
|
|
46
|
-
"@vue/test-utils": "^2.0.0-rc.18",
|
|
47
46
|
"@vue/tsconfig": "^0.1.3",
|
|
48
47
|
"eslint": "^8.13.0",
|
|
49
48
|
"eslint-plugin-prettier": "^4.0.0",
|