UNPKG

@opensig/opendesign

Version:

371 lines (370 loc) 15.7 kB
import { defineComponent, useTemplateRef, createElementBlock, openBlock, normalizeClass, renderSlot, unref, createCommentVNode, createElementVNode, Fragment, createBlock, createVNode, withCtx, toDisplayString, normalizeStyle, withModifiers, resolveDynamicComponent } from "vue"; import { IconFile, IconLoading, IconImgError, IconRefresh, IconDelete, IconPreview, IconLinkPrefix, IconDownload } from "../_utils/icons.mjs"; import { OIcon } from "../icon/index2.mjs"; import { OFigure } from "../figure/index.mjs"; import { OButton } from "../button/index.mjs"; import slot from "./slot.mjs"; import { useI18n } from "../locale/index.mjs"; const _hoisted_1 = { class: "o-upload-card-item-wrap" }; const _hoisted_2 = { class: "o-upload-card-file" }; const _hoisted_3 = { class: "o-upload-card-icons" }; const _hoisted_4 = { key: 0, class: "o-upload-status-wrap" }; const _hoisted_5 = { class: "o-upload-status-info" }; const _hoisted_6 = { key: 0, class: "o-upload-status-wrap o-upload-status-wrap-error" }; const _hoisted_7 = { class: "o-upload-status-upper-layer" }; const _hoisted_8 = { class: "o-upload-status-info" }; const _hoisted_9 = { class: "o-upload-status-lower-layer" }; const _hoisted_10 = { key: 1, class: "o-upload-status-wrap o-upload-status-wrap-success" }; const _hoisted_11 = { key: 0, class: "o-upload-progress o-upload-card-progress" }; const _hoisted_12 = { key: 1, class: "o-upload-icon-link" }; const _hoisted_13 = { class: "o-upload-row-label" }; const _hoisted_14 = { class: "o-upload-row-icons" }; const _hoisted_15 = { key: 2, class: "o-upload-progress o-upload-row-progress" }; const _sfc_main = /* @__PURE__ */ defineComponent({ __name: "UploadItem", props: { file: {}, listType: {}, showProgress: {}, draggable: { type: Boolean } }, emits: ["replace", "remove", "retry", "preview", "itemClick", "download"], setup(__props, { expose: __expose, emit: __emit }) { const props = __props; const emits = __emit; const { t } = useI18n(); const onFileRemove = (e) => { e.stopPropagation(); emits("remove", props.file, e); }; const onFileUploadRetry = (e) => { e.stopPropagation(); emits("retry", props.file, e); }; const showLoading = () => { if (props.file.status !== "uploading") { return false; } if (!props.showProgress) { return true; } if (!props.file.percent && props.file.percent !== 0) { return true; } return false; }; const figureRef = useTemplateRef("figureRef"); const figurePreview = () => { var _a; (_a = figureRef.value) == null ? void 0 : _a.preview(); }; const onPreview = (e) => { e.stopPropagation(); figurePreview(); emits("preview", props.file, e); }; const onItemClick = (e) => { emits("itemClick", props.file, e); }; const onFileDownload = (e) => { e.stopPropagation(); emits("download", props.file, e); }; __expose({ preview: figurePreview }); return (_ctx, _cache) => { return openBlock(), createElementBlock( "div", { class: normalizeClass(["o-upload-item", { "o-upload-item-error": props.file.status === "failed" }]) }, [ renderSlot(_ctx.$slots, unref(slot).names.uploadItem, { item: __props.file }, () => [ props.listType === "picture-card" ? (openBlock(), createElementBlock( "div", { key: 0, class: normalizeClass(["o-upload-card-item", { "is-error": props.file.status === "failed" }]), onClick: onItemClick }, [ createElementVNode("div", _hoisted_1, [ createElementVNode("div", _hoisted_2, [ props.file.status === "finished" ? (openBlock(), createElementBlock( Fragment, { key: 0 }, [ props.file.imgUrl ? (openBlock(), createBlock(unref(OFigure), { key: 0, ref_key: "figureRef", ref: figureRef, "lazy-preview": "", class: "o-upload-thumbnail", src: props.file.imgUrl }, null, 8, ["src"])) : (openBlock(), createBlock(unref(IconFile), { key: 1, class: "o-upload-icon-file" })) ], 64 /* STABLE_FRAGMENT */ )) : createCommentVNode("v-if", true) ]), createElementVNode("div", _hoisted_3, [ showLoading() ? (openBlock(), createElementBlock("div", _hoisted_4, [ createVNode(unref(OIcon), { class: "o-upload-status-icon" }, { default: withCtx(() => [ createVNode(unref(IconLoading), { class: "o-rotating" }) ]), _: 1 /* STABLE */ }), createElementVNode( "div", _hoisted_5, toDisplayString(unref(t)("upload.loading")), 1 /* TEXT */ ) ])) : (openBlock(), createElementBlock( Fragment, { key: 1 }, [ props.file.status === "failed" ? (openBlock(), createElementBlock("div", _hoisted_6, [ createElementVNode("div", _hoisted_7, [ createVNode(unref(OIcon), { class: "o-upload-status-icon" }, { default: withCtx(() => [ createVNode(unref(IconImgError)) ]), _: 1 /* STABLE */ }), createElementVNode( "div", _hoisted_8, toDisplayString(unref(t)("upload.failed")), 1 /* TEXT */ ) ]), createElementVNode("div", _hoisted_9, [ props.file.retry ? (openBlock(), createBlock(unref(OButton), { key: 0, class: "o-upload-icon-btn o-upload-icon-retry", icon: unref(IconRefresh), title: unref(t)("upload.retry"), onClick: onFileUploadRetry }, null, 8, ["icon", "title"])) : createCommentVNode("v-if", true), createVNode(unref(OButton), { class: "o-upload-icon-btn o-upload-icon-remove", icon: unref(IconDelete), title: unref(t)("upload.delete"), onClick: onFileRemove }, null, 8, ["icon", "title"]) ]) ])) : (openBlock(), createElementBlock("div", _hoisted_10, [ props.file.imgUrl ? (openBlock(), createBlock(unref(OButton), { key: 0, icon: unref(IconPreview), class: "o-upload-icon-btn o-upload-icon-preview", title: unref(t)("upload.preview"), onClick: onPreview }, null, 8, ["icon", "title"])) : createCommentVNode("v-if", true), createVNode(unref(OButton), { class: "o-upload-icon-btn o-upload-icon-remove", icon: unref(IconDelete), title: unref(t)("upload.delete"), onClick: onFileRemove }, null, 8, ["icon", "title"]) ])) ], 64 /* STABLE_FRAGMENT */ )) ]), props.file.status === "uploading" && props.showProgress && props.file.percent ? (openBlock(), createElementBlock("div", _hoisted_11, [ createElementVNode( "div", { class: "o-upload-progress-bar", style: normalizeStyle({ width: props.file.percent + "%" }) }, null, 4 /* STYLE */ ) ])) : createCommentVNode("v-if", true) ]) ], 2 /* CLASS */ )) : (openBlock(), createElementBlock( "div", { key: 1, class: normalizeClass(["o-upload-row-item", { "is-error": props.file.status === "failed" }]), onClick: onItemClick }, [ props.listType === "picture" && props.file.imgUrl ? (openBlock(), createBlock(unref(OFigure), { key: 0, ref_key: "figureRef", ref: figureRef, preview: "", class: "o-upload-thumbnail", src: props.file.imgUrl, onClick: _cache[0] || (_cache[0] = withModifiers(() => { }, ["stop"])) }, null, 8, ["src"])) : props.file.icon !== false ? (openBlock(), createElementBlock("div", _hoisted_12, [ props.file.icon ? (openBlock(), createBlock(resolveDynamicComponent(props.file.icon), { key: 0 })) : (openBlock(), createBlock(unref(IconLinkPrefix), { key: 1 })) ])) : createCommentVNode("v-if", true), createElementVNode( "div", _hoisted_13, toDisplayString(props.file.name), 1 /* TEXT */ ), createElementVNode("div", _hoisted_14, [ showLoading() ? (openBlock(), createBlock(unref(OIcon), { key: 0, class: "o-upload-icon-loading" }, { default: withCtx(() => [ createVNode(unref(IconLoading), { class: "o-rotating" }) ]), _: 1 /* STABLE */ })) : (openBlock(), createElementBlock( Fragment, { key: 1 }, [ props.file.status === "failed" ? (openBlock(), createElementBlock( Fragment, { key: 0 }, [ props.file.retry ? (openBlock(), createBlock(unref(OButton), { key: 0, class: "o-upload-row-icon o-upload-icon-hover-in o-upload-icon-retry", icon: unref(IconRefresh), title: unref(t)("upload.retry"), onClick: onFileUploadRetry }, null, 8, ["icon", "title"])) : createCommentVNode("v-if", true) ], 64 /* STABLE_FRAGMENT */ )) : (openBlock(), createElementBlock( Fragment, { key: 1 }, [ props.draggable ? (openBlock(), createElementBlock( Fragment, { key: 0 }, [ props.file.imgUrl ? (openBlock(), createBlock(unref(OFigure), { key: 0, ref_key: "figureRef", ref: figureRef, "lazy-preview": "", class: "o-upload-thumbnail", src: props.file.imgUrl }, null, 8, ["src"])) : createCommentVNode("v-if", true), props.file.imgUrl ? (openBlock(), createBlock(unref(OButton), { key: 1, icon: unref(IconPreview), class: "o-upload-row-icon o-upload-icon-preview o-upload-icon-hover-in", title: unref(t)("upload.preview"), onClick: onPreview }, null, 8, ["icon", "title"])) : createCommentVNode("v-if", true), createVNode(unref(OButton), { class: "o-upload-row-icon o-upload-icon-download o-upload-icon-hover-in", icon: unref(IconDownload), title: unref(t)("upload.download"), onClick: onFileDownload }, null, 8, ["icon", "title"]) ], 64 /* STABLE_FRAGMENT */ )) : createCommentVNode("v-if", true) ], 64 /* STABLE_FRAGMENT */ )) ], 64 /* STABLE_FRAGMENT */ )), createVNode(unref(OButton), { class: "o-upload-row-icon o-upload-icon-remove o-upload-icon-hover-in", icon: unref(IconDelete), title: unref(t)("upload.delete"), onClick: onFileRemove }, null, 8, ["icon", "title"]) ]), props.file.status === "uploading" && props.showProgress && props.file.percent ? (openBlock(), createElementBlock("div", _hoisted_15, [ createElementVNode( "div", { class: "o-upload-progress-bar", style: normalizeStyle({ width: props.file.percent + "%" }) }, null, 4 /* STYLE */ ) ])) : createCommentVNode("v-if", true) ], 2 /* CLASS */ )), props.file.message ? (openBlock(), createElementBlock( "div", { key: 2, class: normalizeClass(["o-upload-item-tip", [ { "is-error": props.file.status === "failed" }, props.file.messageClass ]]) }, toDisplayString(props.file.message), 3 /* TEXT, CLASS */ )) : createCommentVNode("v-if", true) ]) ], 2 /* CLASS */ ); }; } }); export { _sfc_main as default };