qidian-vue-ui 2.8.17 → 2.8.18
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,10 +1,10 @@
|
|
|
1
|
-
.qd-image[data-v-
|
|
1
|
+
.qd-image[data-v-331db0ac] .t-image__overlay-content {
|
|
2
2
|
border-radius: inherit;
|
|
3
3
|
}
|
|
4
|
-
.qd-image__viewer-trigger[data-v-
|
|
4
|
+
.qd-image__viewer-trigger[data-v-331db0ac] {
|
|
5
5
|
display: none;
|
|
6
6
|
}
|
|
7
|
-
.qd-image__preview-mask[data-v-
|
|
7
|
+
.qd-image__preview-mask[data-v-331db0ac] {
|
|
8
8
|
display: flex;
|
|
9
9
|
align-items: center;
|
|
10
10
|
justify-content: center;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { default as QdImage } from './index.vue';
|
|
2
|
-
export type { QdImageProps } from './types';
|
|
2
|
+
export type { QdImageProps, QdImageViewerProps } from './types';
|
|
@@ -2,7 +2,7 @@ import './index.css'
|
|
|
2
2
|
import _sfc_main from "./index.vue2.mjs";
|
|
3
3
|
/* empty css */
|
|
4
4
|
import _export_sfc from "../../_virtual/_plugin-vue_export-helper.mjs";
|
|
5
|
-
const index = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-
|
|
5
|
+
const index = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-331db0ac"]]);
|
|
6
6
|
export {
|
|
7
7
|
index as default
|
|
8
8
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import './index.css'
|
|
2
2
|
import { defineComponent, mergeDefaults, useAttrs, inject, computed, ref, watch, onUnmounted, createElementBlock, openBlock, Fragment, withDirectives, createBlock, createCommentVNode, unref, mergeProps, createSlots, withCtx, renderSlot, createVNode, renderList, createElementVNode, normalizeProps, guardReactiveProps } from "vue";
|
|
3
|
-
import { isEmpty, validator, abortWrapper,
|
|
3
|
+
import { to, isEmpty, validator, abortWrapper, filterSlots, suspectedWrapperPromise } from "qidian-shared";
|
|
4
4
|
import { ImageErrorIcon, LoadingIcon, BrowseIcon } from "tdesign-icons-vue-next";
|
|
5
5
|
import { Image, LoadingDirective, ImageViewer } from "tdesign-vue-next";
|
|
6
6
|
import { PROVIDE_UPLOAD } from "../config-provider/config.mjs";
|
|
@@ -17,6 +17,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
17
17
|
src: {},
|
|
18
18
|
mode: {},
|
|
19
19
|
preview: { type: Boolean },
|
|
20
|
+
viewer: {},
|
|
20
21
|
alt: {},
|
|
21
22
|
error: {},
|
|
22
23
|
fallback: {},
|
|
@@ -49,13 +50,14 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
49
50
|
return { ...restAttrs, ...reProps.value.imageOptions };
|
|
50
51
|
});
|
|
51
52
|
const reProps = computed(() => {
|
|
52
|
-
const { src, mode, listOssByIds, preview, onError, onLoad, ...imageOptions } = props;
|
|
53
|
+
const { src, mode, listOssByIds, preview, viewer, onError, onLoad, ...imageOptions } = props;
|
|
53
54
|
const reListOssByIds = merge({}, globalUploadProps.value?.listOssByIds, listOssByIds);
|
|
54
55
|
return {
|
|
55
56
|
src,
|
|
56
57
|
mode,
|
|
57
58
|
listOssByIds: reListOssByIds,
|
|
58
59
|
preview,
|
|
60
|
+
viewer,
|
|
59
61
|
imageOptions
|
|
60
62
|
};
|
|
61
63
|
});
|
|
@@ -63,8 +65,11 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
63
65
|
const serviceAbortReason = /* @__PURE__ */ Symbol("abort");
|
|
64
66
|
let serviceAbort;
|
|
65
67
|
const viewerVisible = ref(false);
|
|
68
|
+
const viewerIndex = ref();
|
|
66
69
|
const imageError = ref(false);
|
|
70
|
+
const viewerSrcs = ref();
|
|
67
71
|
const viewerImages = computed(() => {
|
|
72
|
+
if (viewerSrcs.value?.length) return viewerSrcs.value.map((src2) => String(src2));
|
|
68
73
|
const src = reSrc.value;
|
|
69
74
|
if (src === void 0 || src === "") return [];
|
|
70
75
|
return [typeof src === "number" ? src + "" : src];
|
|
@@ -72,6 +77,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
72
77
|
function openViewer() {
|
|
73
78
|
if (!props.preview) return;
|
|
74
79
|
if (!viewerImages.value.length) return;
|
|
80
|
+
viewerIndex.value = props.viewer?.index ?? 0;
|
|
75
81
|
viewerVisible.value = true;
|
|
76
82
|
return true;
|
|
77
83
|
}
|
|
@@ -114,16 +120,60 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
114
120
|
}
|
|
115
121
|
return res?.[0]?.url;
|
|
116
122
|
}
|
|
123
|
+
async function requestViewerSrcs(currentParams, listOssByIds) {
|
|
124
|
+
const { service, transformParams, transformRes } = listOssByIds;
|
|
125
|
+
if (!service) return;
|
|
126
|
+
let serviceParams = currentParams;
|
|
127
|
+
if (transformParams) {
|
|
128
|
+
const [trErr, trRes] = await suspectedWrapperPromise(transformParams(currentParams));
|
|
129
|
+
if (trErr) throw trErr;
|
|
130
|
+
serviceParams = trRes;
|
|
131
|
+
}
|
|
132
|
+
const [serviceErr, serviceRes] = await to(service(serviceParams));
|
|
133
|
+
if (serviceErr) throw serviceErr;
|
|
134
|
+
let res;
|
|
135
|
+
if (transformRes) {
|
|
136
|
+
const [trErr, trRes] = await suspectedWrapperPromise(transformRes(serviceRes));
|
|
137
|
+
if (trErr) throw trErr;
|
|
138
|
+
res = trRes;
|
|
139
|
+
} else {
|
|
140
|
+
res = serviceRes;
|
|
141
|
+
}
|
|
142
|
+
return res?.map((item) => item.url);
|
|
143
|
+
}
|
|
117
144
|
watch(reSrc, () => {
|
|
118
145
|
imageError.value = false;
|
|
119
146
|
});
|
|
120
147
|
watch(
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
148
|
+
[
|
|
149
|
+
() => props.viewer?.images,
|
|
150
|
+
() => props.viewer?.mode ?? props.mode,
|
|
151
|
+
() => reProps.value.listOssByIds
|
|
152
|
+
],
|
|
153
|
+
async ([images, mode, listOssByIds]) => {
|
|
154
|
+
if (!images?.length) {
|
|
155
|
+
viewerSrcs.value = void 0;
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
if (mode === "url") {
|
|
159
|
+
viewerSrcs.value = images;
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (!listOssByIds?.service) {
|
|
163
|
+
viewerSrcs.value = images;
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const [error, srcs] = await to(requestViewerSrcs(images, listOssByIds));
|
|
167
|
+
if (error) throw error;
|
|
168
|
+
viewerSrcs.value = srcs;
|
|
169
|
+
},
|
|
170
|
+
{ immediate: true }
|
|
171
|
+
);
|
|
172
|
+
watch(
|
|
173
|
+
[() => reProps.value.src, () => reProps.value.mode, () => reProps.value.listOssByIds],
|
|
174
|
+
async ([newVal, mode, listOssByIds]) => {
|
|
124
175
|
serviceAbort?.abort?.(serviceAbortReason);
|
|
125
176
|
serviceAbort = void 0;
|
|
126
|
-
const { mode, listOssByIds } = reProps.value;
|
|
127
177
|
if (mode === "ossId") {
|
|
128
178
|
if (!listOssByIds || !listOssByIds.service || isEmpty(newVal) || newVal instanceof File || validator(newVal, "url")) {
|
|
129
179
|
serviceLoad.value = false;
|
|
@@ -201,13 +251,15 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
201
251
|
key: 0,
|
|
202
252
|
images: viewerImages.value,
|
|
203
253
|
visible: viewerVisible.value,
|
|
204
|
-
"onUpdate:visible": _cache[0] || (_cache[0] = ($event) => viewerVisible.value = $event)
|
|
254
|
+
"onUpdate:visible": _cache[0] || (_cache[0] = ($event) => viewerVisible.value = $event),
|
|
255
|
+
index: viewerIndex.value,
|
|
256
|
+
"onUpdate:index": _cache[1] || (_cache[1] = ($event) => viewerIndex.value = $event)
|
|
205
257
|
}, {
|
|
206
|
-
trigger: withCtx(() => [..._cache[
|
|
258
|
+
trigger: withCtx(() => [..._cache[2] || (_cache[2] = [
|
|
207
259
|
createElementVNode("span", { class: "qd-image__viewer-trigger" }, null, -1)
|
|
208
260
|
])]),
|
|
209
261
|
_: 1
|
|
210
|
-
}, 8, ["images", "visible"])) : createCommentVNode("", true)
|
|
262
|
+
}, 8, ["images", "visible", "index"])) : createCommentVNode("", true)
|
|
211
263
|
], 64);
|
|
212
264
|
};
|
|
213
265
|
}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import type { TdImageProps, UploadFile } from 'tdesign-vue-next';
|
|
2
2
|
import type { QdUploadProps } from '../upload';
|
|
3
|
+
export interface QdImageViewerProps {
|
|
4
|
+
images?: (string | number)[];
|
|
5
|
+
mode?: 'ossId' | 'url';
|
|
6
|
+
index?: number;
|
|
7
|
+
}
|
|
3
8
|
export interface QdImageProps<OR = unknown, OP extends string | number | (string | number)[] = string | number | (string | number)[], TOP = OP> extends Omit<TdImageProps, 'src'>, Pick<QdUploadProps<UploadFile, OR, OP, TOP>, 'listOssByIds'> {
|
|
4
9
|
src?: string | number | File;
|
|
5
10
|
mode?: 'ossId' | 'url';
|
|
6
11
|
preview?: boolean;
|
|
12
|
+
viewer?: QdImageViewerProps;
|
|
7
13
|
}
|