var J = (u, _, m) => new Promise((i, M) => { var b = (r) => { try { y(m.next(r)); } catch (k) { M(k); } }, c = (r) => { try { y(m.throw(r)); } catch (k) { M(k); } }, y = (r) => r.done ? i(r.value) : Promise.resolve(r.value).then(b, c); y((m = m.apply(u, _)).next()); }); import { computed as U, ref as A, watch as ve, openBlock as o, createElementBlock as g, normalizeClass as x, createElementVNode as w, toDisplayString as I, createCommentVNode as d, createVNode as j, unref as p, normalizeStyle as me, withCtx as Q, Fragment as Y, createBlock as v, resolveDynamicComponent as ee, withDirectives as ge, withModifiers as C, vShow as we } from "vue"; import { d as he } from "./vuedraggable.js"; import ye from "./SFilePreview.js"; import { b as be, d as ke } from "./upload.js"; import { n as Ce, ak as $e, al as le, am as te, an as ae, ao as ne, ap as E, aq as B, ar as h, as as Oe, at as L, au as D, av as oe, aw as V, ax as R, ay as Se, az as Fe } from "./index2.js"; const Ue = { key: 0, class: "head" }, xe = { class: "label" }, Ie = ["onMouseover", "onMouseleave"], Ee = ["src", "alt"], Be = { key: 1, class: "file-thumb" }, De = { class: "file-thumb-ext" }, Me = { class: "tool-wrap" }, Te = { class: "left" }, Ae = { class: "right move" }, Le = { class: "file-row-ext" }, Re = ["title"], _e = { class: "file-row-actions" }, ze = { key: 0, class: "file-add-text" }, Pe = ["accept", "disabled"], Ne = { __name: "SDraggerUpload", props: { /** * 文件列表(同 PictureUpload 的 data) * @list */ list: { type: Array, default: () => [] }, /** * 标题 * @label */ label: { type: String, default: "" }, /** * 只读(同 PictureUpload 的 disabled) * @readonly */ readonly: { type: Boolean, default: !1 }, /** * 详情模式:只读展示,不显示新增入口、不可删除拖拽,仅保留预览与下载 * @detailMode */ detailMode: { type: Boolean, default: !1 }, /** * 是否显示新增(isAdd=false 等价 PictureUpload 的 ishiddenAdd=true:隐藏添加框且不可删除/拖拽) * @isAdd */ isAdd: { type: Boolean, default: !0 }, /** * 文件类型 * @accept */ accept: { type: String, default: "image/*" }, /** * 展示形态:card 卡片(图片显示原图,其他类型显示文件类型);list 列表(文件类型 + 文件名 + 操作按钮) * @listType */ listType: { type: String, default: "card" }, /** * 是否显示预览按钮 * @showPreview */ showPreview: { type: Boolean, default: !0 }, /** * 是否显示下载按钮 * @showDownload */ showDownload: { type: Boolean, default: !0 }, /** * 是否显示删除按钮(仍需 isAdd 且非只读) * @showRemove */ showRemove: { type: Boolean, default: !0 }, // 最多可上传数量(同 PictureUpload 的 maxSize) maxFileCount: { type: Number, default: 5 }, // 单文件大小上限,单位 KB(同 PictureUpload 的 fileSize) fileSize: { type: Number, default: 200 }, // FTP 上传目录(同 PictureUpload 的 path),不传时回退 businessTableName path: { type: String, default: void 0 }, // 是否隐藏拖拽排序图标(同 PictureUpload 的 noDrag) noDrag: { type: Boolean, default: !1 }, // 图片列表容器样式(同 PictureUpload 的 picStyle) picStyle: { type: Object, default: () => { } }, // 兼容保留:不传 path 时作为 FTP 目录名 businessTableName: { type: String, default: "sapit-ui-plus-components-upload" }, businessKey: { type: String, default: void 0 }, // 兼容保留(PictureUpload 无上传列表概念,仅声明避免外部传参告警) showUploadList: { type: Boolean, default: !0 }, // 已废弃:由 showRemove 取代,仅保留声明避免外部传参告警 showRemoveIcon: { type: Boolean, default: !1 } }, emits: ["change", "handChange", "dragChange", "download"], setup(u, { emit: _ }) { const m = _, i = u, M = U(() => i.readonly || i.detailMode), b = U(() => i.readonly || i.detailMode), c = U(() => i.listType !== "list"), y = U(() => i.isAdd && !b.value && !i.noDrag), r = U(() => i.isAdd && !b.value && i.showRemove), k = () => i.path || i.businessTableName, ie = ["png", "jpg", "jpeg", "gif", "webp", "bmp", "svg", "ico", "avif", "tif", "tiff"], se = { pdf: Se, doc: R, docx: R, wps: R, rtf: R, xls: V, xlsx: V, csv: V, ppt: oe, pptx: oe, zip: D, rar: D, "7z": D, gz: D, tar: D, txt: L, log: L, json: L, xml: L, md: Oe, png: h, jpg: h, jpeg: h, gif: h, webp: h, bmp: h, svg: h, ico: h, mp4: B, mov: B, avi: B, mkv: B, webm: B, mp3: E, wav: E, flac: E, aac: E, m4a: E }, $ = (e = {}) => e.imageUrl || e.url || e.uid || "", K = (e = "") => { const t = String(e).split("?")[0].split("#")[0], l = t.substring(t.lastIndexOf("/") + 1); try { return decodeURIComponent(l); } catch (a) { return l; } }, O = (e = {}) => e.name || K($(e)) || window.$l("未命名文件"), T = (e = {}) => { const t = O(e), l = t.lastIndexOf("."); return l > -1 ? t.slice(l + 1).toLowerCase() : ""; }, q = (e = {}) => { const t = e.type || e.mimeType || ""; return t ? String(t).indexOf("image/") === 0 : ie.includes(T(e)); }, G = (e = {}) => se[T(e)] || Fe, s = A([]), z = A(!1), H = A(0); ve( () => i.list, (e) => { s.value = e || []; }, { immediate: !0, deep: !0 } ); const P = () => { m("change", s.value), m("handChange", s.value); }, ue = (e) => { }, de = (e) => { s.value && s.value.length > 1 && s.value.forEach((t, l) => { t.sort = l; }), m("dragChange", s.value), P(); }, ce = () => { S.value && S.value.click(); }, S = A(null), re = (e) => { const t = e.target.files; if (t && t.length && s.value.length + t.length > i.maxFileCount) { window.$message.warning( window.$l("上传图片,最多可上传") + i.maxFileCount + window.$l("张") ); return; } if (t && t.length) { for (let a = 0; a < t.length; a++) if (t[a].size > i.fileSize * 1024) { window.$message.warning(`${window.$l("上传图片大小不能大于")}${i.fileSize}KB`); return; } } const l = Array.from(t || []); be(k(), t).then((a) => { if (a && a.length) for (let n = 0; n < a.length; n++) s.value.push({ sort: n, name: l[n] && l[n].name || K(a[n].imageUrl), imageUrl: a[n].imageUrl, uid: a[n].imageUrl, url: a[n].imageUrl }); P(); }).finally(() => { S.value && (S.value.value = ""); }); }, fe = (e) => { c.value && (e.showTool = !0); }, pe = (e) => { c.value && (e.showTool = !1); }, W = (e, t) => { s.value.splice(e, 1), ke(k(), t.imageUrl || t.uid), P(); }, X = (e = {}) => { const t = $(e); if (!t) return; if (!q(e)) { window.open(t, "_blank", "noopener"); return; } let l = s.value.findIndex((a) => a === e); l < 0 && (l = s.value.findIndex((a) => $(a) === t)), H.value = l > -1 ? l : 0, z.value = !0; }, Z = (...t) => J(this, [...t], function* (e = {}) { const l = $(e); if (!l) return; m("download", e); const a = O(e), n = (F, N) => { const f = document.createElement("a"); f.href = F, f.download = a, N || (f.target = "_blank", f.rel = "noopener"), document.body.appendChild(f), f.click(), document.body.removeChild(f); }; try { const F = yield fetch(l); if (!F.ok) throw new Error("fetch failed"); const N = yield F.blob(), f = URL.createObjectURL(N); n(f, !0), setTimeout(() => URL.revokeObjectURL(f), 1e3); } catch (F) { n(l, !1); } }); return (e, t) => (o(), g("div", { class: x(["s-file-upload-common", [`is-${u.listType}`, { "is-readonly": b.value }]]) }, [ u.label ? (o(), g("div", Ue, [ w("div", xe, I(u.label), 1) ])) : d("", !0), j(p(he), { modelValue: s.value, "onUpdate:modelValue": t[0] || (t[0] = (l) => s.value = l), onStart: ue, onEnd: de, handle: ".move", class: x(c.value ? "img-list-wrap" : "file-list-wrap"), style: me(u.picStyle), disabled: !y.value, "item-key": "uid" }, { item: Q(({ element: l, index: a }) => [ (o(), g("div", { key: l.uid || a, class: x(c.value ? "img-item-wrap" : "file-row"), onMouseover: (n) => fe(l), onMouseleave: (n) => pe(l) }, [ c.value ? (o(), g(Y, { key: 0 }, [ q(l) ? (o(), g("img", { key: 0, class: "upload-img-wrap", src: $(l), alt: O(l) }, null, 8, Ee)) : (o(), g("div", Be, [ (o(), v(ee(G(l)), { class: "file-thumb-icon" })), w("span", De, I(T(l) || "FILE"), 1) ])), ge(w("div", Me, [ w("div", Te, [ u.showPreview ? (o(), v(p(le), { key: 0, class: "tool-icon-wrap", title: e.$l("预览"), onClick: C((n) => X(l), ["stop"]) }, null, 8, ["title", "onClick"])) : d("", !0), u.showDownload ? (o(), v(p(te), { key: 1, class: "tool-icon-wrap", title: e.$l("下载"), onClick: C((n) => Z(l), ["stop"]) }, null, 8, ["title", "onClick"])) : d("", !0), r.value ? (o(), v(p(ae), { key: 2, class: "tool-icon-wrap", title: e.$l("删除"), onClick: C((n) => W(a, l), ["stop"]) }, null, 8, ["title", "onClick"])) : d("", !0) ]), w("div", Ae, [ y.value ? (o(), v(p(ne), { key: 0 })) : d("", !0) ]) ], 512), [ [we, l.showTool] ]) ], 64)) : (o(), g(Y, { key: 1 }, [ (o(), v(ee(G(l)), { class: "file-row-icon" })), w("span", Le, I(T(l) || "FILE"), 1), w("span", { class: "file-row-name", title: O(l) }, I(O(l)), 9, Re), w("span", _e, [ u.showPreview ? (o(), v(p(le), { key: 0, class: "file-action", title: e.$l("预览"), onClick: C((n) => X(l), ["stop"]) }, null, 8, ["title", "onClick"])) : d("", !0), u.showDownload ? (o(), v(p(te), { key: 1, class: "file-action", title: e.$l("下载"), onClick: C((n) => Z(l), ["stop"]) }, null, 8, ["title", "onClick"])) : d("", !0), r.value ? (o(), v(p(ae), { key: 2, class: "file-action", title: e.$l("删除"), onClick: C((n) => W(a, l), ["stop"]) }, null, 8, ["title", "onClick"])) : d("", !0), y.value ? (o(), v(p(ne), { key: 3, class: "file-action move", title: e.$l("拖动排序") }, null, 8, ["title"])) : d("", !0) ]) ], 64)) ], 42, Ie)) ]), footer: Q(() => [ s.value.length < u.maxFileCount && u.isAdd && !b.value ? (o(), g("div", { key: 0, class: x(c.value ? "img-add-wrap" : "file-add-wrap"), onClick: ce }, [ j(p($e), { class: x(c.value ? "plus-icon" : "plus-icon plus-icon-small") }, null, 8, ["class"]), c.value ? d("", !0) : (o(), g("span", ze, I(e.$l("上传文件")), 1)), w("input", { accept: u.accept || "image/*", multiple: !0, type: "file", disabled: M.value, ref_key: "fileInput", ref: S, style: { display: "none" }, onChange: re }, null, 40, Pe) ], 2)) : d("", !0) ]), _: 1 }, 8, ["modelValue", "class", "style", "disabled"]), j(ye, { value: z.value, "onUpdate:value": t[1] || (t[1] = (l) => z.value = l), list: s.value, active: H.value }, null, 8, ["value", "list", "active"]) ], 2)); } }, We = /* @__PURE__ */ Ce(Ne, [["__scopeId", "data-v-5b30c036"]]); export { We as default };