var J = (d, _, m) => new Promise((i, A) => { var b = (r) => { try { y(m.next(r)); } catch (k) { A(k); } }, c = (r) => { try { y(m.throw(r)); } catch (k) { A(k); } }, y = (r) => r.done ? i(r.value) : Promise.resolve(r.value).then(b, c); y((m = m.apply(d, _)).next()); }); import { computed as U, ref as T, watch as pe, openBlock as o, createElementBlock as g, normalizeClass as x, createElementVNode as w, toDisplayString as I, createCommentVNode as u, createVNode as j, unref as v, normalizeStyle as me, withCtx as Q, Fragment as Y, createBlock as p, 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, al as $e, am as le, an as te, ao as ae, ap as ne, aq as E, ar as B, as as h, at as Fe, au as L, av as M, aw as oe, ax as V, ay as R, az as Oe, aA as Se } from "./index2.js"; const Ue = { key: 0, class: "head" }, xe = { class: "label" }, Ie = ["onMouseover", "onMouseleave"], Ee = ["src", "alt"], Be = { key: 1, class: "file-thumb" }, Me = { class: "file-thumb-ext" }, Ae = { class: "tool-wrap" }, De = { class: "left" }, Te = { 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: "SFileUpload", 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(d, { emit: _ }) { const m = _, i = d, A = 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: Oe, doc: R, docx: R, wps: R, rtf: R, xls: V, xlsx: V, csv: V, ppt: oe, pptx: oe, zip: M, rar: M, "7z": M, gz: M, tar: M, txt: L, log: L, json: L, xml: L, md: Fe, 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; } }, F = (e = {}) => e.name || K($(e)) || window.$l("未命名文件"), D = (e = {}) => { const t = F(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(D(e)); }, G = (e = {}) => se[D(e)] || Se, s = T([]), z = T(!1), H = T(0); pe( () => i.list, (e) => { s.value = e || []; }, { immediate: !0, deep: !0 } ); const P = () => { m("change", s.value), m("handChange", s.value); }, de = (e) => { }, ue = (e) => { s.value && s.value.length > 1 && s.value.forEach((t, l) => { t.sort = l; }), m("dragChange", s.value), P(); }, ce = () => { O.value && O.value.click(); }, O = T(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(() => { O.value && (O.value.value = ""); }); }, fe = (e) => { c.value && (e.showTool = !0); }, ve = (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 = F(e), n = (S, N) => { const f = document.createElement("a"); f.href = S, f.download = a, N || (f.target = "_blank", f.rel = "noopener"), document.body.appendChild(f), f.click(), document.body.removeChild(f); }; try { const S = yield fetch(l); if (!S.ok) throw new Error("fetch failed"); const N = yield S.blob(), f = URL.createObjectURL(N); n(f, !0), setTimeout(() => URL.revokeObjectURL(f), 1e3); } catch (S) { n(l, !1); } }); return (e, t) => (o(), g("div", { class: x(["s-file-upload-common", [`is-${d.listType}`, { "is-readonly": b.value }]]) }, [ d.label ? (o(), g("div", Ue, [ w("div", xe, I(d.label), 1) ])) : u("", !0), j(v(he), { modelValue: s.value, "onUpdate:modelValue": t[0] || (t[0] = (l) => s.value = l), onStart: de, onEnd: ue, handle: ".move", class: x(c.value ? "img-list-wrap" : "file-list-wrap"), style: me(d.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) => ve(l) }, [ c.value ? (o(), g(Y, { key: 0 }, [ q(l) ? (o(), g("img", { key: 0, class: "upload-img-wrap", src: $(l), alt: F(l) }, null, 8, Ee)) : (o(), g("div", Be, [ (o(), p(ee(G(l)), { class: "file-thumb-icon" })), w("span", Me, I(D(l) || "FILE"), 1) ])), ge(w("div", Ae, [ w("div", De, [ d.showPreview ? (o(), p(v(le), { key: 0, class: "tool-icon-wrap", title: e.$l("预览"), onClick: C((n) => X(l), ["stop"]) }, null, 8, ["title", "onClick"])) : u("", !0), d.showDownload ? (o(), p(v(te), { key: 1, class: "tool-icon-wrap", title: e.$l("下载"), onClick: C((n) => Z(l), ["stop"]) }, null, 8, ["title", "onClick"])) : u("", !0), r.value ? (o(), p(v(ae), { key: 2, class: "tool-icon-wrap", title: e.$l("删除"), onClick: C((n) => W(a, l), ["stop"]) }, null, 8, ["title", "onClick"])) : u("", !0) ]), w("div", Te, [ y.value ? (o(), p(v(ne), { key: 0 })) : u("", !0) ]) ], 512), [ [we, l.showTool] ]) ], 64)) : (o(), g(Y, { key: 1 }, [ (o(), p(ee(G(l)), { class: "file-row-icon" })), w("div", Le, I(D(l) || "FILE"), 1), w("div", { class: "file-row-name", title: F(l) }, I(F(l)), 9, Re), w("div", _e, [ d.showPreview ? (o(), p(v(le), { key: 0, class: "file-action", title: e.$l("预览"), onClick: C((n) => X(l), ["stop"]) }, null, 8, ["title", "onClick"])) : u("", !0), d.showDownload ? (o(), p(v(te), { key: 1, class: "file-action", title: e.$l("下载"), onClick: C((n) => Z(l), ["stop"]) }, null, 8, ["title", "onClick"])) : u("", !0), r.value ? (o(), p(v(ae), { key: 2, class: "file-action", title: e.$l("删除"), onClick: C((n) => W(a, l), ["stop"]) }, null, 8, ["title", "onClick"])) : u("", !0), y.value ? (o(), p(v(ne), { key: 3, class: "file-action move", title: e.$l("拖动排序") }, null, 8, ["title"])) : u("", !0) ]) ], 64)) ], 42, Ie)) ]), footer: Q(() => [ s.value.length < d.maxFileCount && d.isAdd && !b.value ? (o(), g("div", { key: 0, class: x(c.value ? "img-add-wrap" : "file-add-wrap"), onClick: ce }, [ j(v($e), { class: x(c.value ? "plus-icon" : "plus-icon plus-icon-small") }, null, 8, ["class"]), c.value ? u("", !0) : (o(), g("span", ze, I(e.$l("上传文件")), 1)), w("input", { accept: d.accept || "image/*", multiple: !0, type: "file", disabled: A.value, ref_key: "fileInput", ref: O, style: { display: "none" }, onChange: re }, null, 40, Pe) ], 2)) : u("", !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-b277a24a"]]); export { We as default };