var K = (r, _, g) => new Promise((n, T) => { var k = (c) => { try { b(g.next(c)); } catch (C) { T(C); } }, d = (c) => { try { b(g.throw(c)); } catch (C) { T(C); } }, b = (c) => c.done ? n(c.value) : Promise.resolve(c.value).then(k, d); b((g = g.apply(r, _)).next()); }); import { computed as R, ref as x, watch as be, openBlock as i, createElementBlock as w, normalizeClass as I, createElementVNode as y, toDisplayString as B, createCommentVNode as u, createVNode as D, unref as v, normalizeStyle as ke, withCtx as ee, Fragment as le, createBlock as m, resolveDynamicComponent as te, withDirectives as Ce, withModifiers as O, vShow as $e } from "vue"; import { d as Oe } from "./vuedraggable.js"; import Se from "./SFilePreview.js"; import Ue from "./CropperModal.js"; import { b as Fe, d as Re } from "./upload.js"; import { n as xe, ak as Ie, al as ae, am as oe, an as ne, ao as ie, ap as E, aq as L, ar as h, as as Be, at as j, au as M, av as se, aw as q, ax as N, ay as Ee, az as Le } from "./index2.js"; const Me = { key: 0, class: "head" }, Te = { class: "label" }, ze = ["onMouseover", "onMouseleave"], De = ["src", "alt"], je = { key: 1, class: "file-thumb" }, Ne = { class: "file-thumb-ext" }, _e = { class: "tool-wrap" }, Ae = { class: "left" }, Pe = { class: "right move" }, Ve = { class: "file-row-ext" }, Ke = ["title"], qe = { class: "file-row-actions" }, Ge = { key: 0, class: "file-add-text" }, He = ["accept", "disabled"], We = { __name: "SCopperUpload", 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/*" }, /** * 裁剪比例:1 = 1:1(头像);'16:9' 或 16/9 = 封面;0 = 自由裁剪 * @aspectRatio */ aspectRatio: { type: [Number, String], default: 1 }, /** * 选图后是否先裁剪(false 时原图直传,等同改造前的行为) * @crop */ crop: { type: Boolean, default: !0 }, /** * 展示形态: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(r, { emit: _ }) { const g = _, n = r, T = R(() => n.readonly || n.detailMode), k = R(() => n.readonly || n.detailMode), d = R(() => n.listType !== "list"), b = R(() => n.isAdd && !k.value && !n.noDrag), c = R(() => n.isAdd && !k.value && n.showRemove), C = () => n.path || n.businessTableName, re = ["png", "jpg", "jpeg", "gif", "webp", "bmp", "svg", "ico", "avif", "tif", "tiff"], ue = { pdf: Ee, doc: N, docx: N, wps: N, rtf: N, xls: q, xlsx: q, csv: q, ppt: se, pptx: se, zip: M, rar: M, "7z": M, gz: M, tar: M, txt: j, log: j, json: j, xml: j, md: Be, png: h, jpg: h, jpeg: h, gif: h, webp: h, bmp: h, svg: h, ico: h, mp4: L, mov: L, avi: L, mkv: L, webm: L, mp3: E, wav: E, flac: E, aac: E, m4a: E }, S = (e = {}) => e.imageUrl || e.url || e.uid || "", G = (e = "") => { const t = String(e).split("?")[0].split("#")[0], l = t.substring(t.lastIndexOf("/") + 1); try { return decodeURIComponent(l); } catch (a) { return l; } }, U = (e = {}) => e.name || G(S(e)) || window.$l("未命名文件"), z = (e = {}) => { const t = U(e), l = t.lastIndexOf("."); return l > -1 ? t.slice(l + 1).toLowerCase() : ""; }, H = (e = {}) => { const t = e.type || e.mimeType || ""; return t ? String(t).indexOf("image/") === 0 : re.includes(z(e)); }, W = (e = {}) => ue[z(e)] || Le, s = x([]), A = x(!1), X = x(0); be( () => n.list, (e) => { s.value = e || []; }, { immediate: !0, deep: !0 } ); const P = () => { g("change", s.value), g("handChange", s.value); }, de = (e) => { }, ce = (e) => { s.value && s.value.length > 1 && s.value.forEach((t, l) => { t.sort = l; }), g("dragChange", s.value), P(); }, pe = () => { F.value && F.value.click(); }, F = x(null), Z = x(null); let $ = null; const fe = (e, t, l) => { const a = URL.createObjectURL(e); return new Promise((o) => { $ = (p) => { $ = null, URL.revokeObjectURL(a), o(p); }, Z.value.edit({ img: a, aspectRatio: n.aspectRatio, title: l > 1 ? `${window.$l("图片裁剪")}(${t}/${l})` : window.$l("图片裁剪"), // png 保留 png(可能有透明背景),其余走 jpeg 控制体积 outputType: e.type === "image/png" ? "png" : "jpeg", file: e }); }); }, ve = (e) => { $ && $(e && e.blob || null); }, me = () => { $ && $(null); }, ge = (e, t) => { const l = e.type || t.type || "image/png", a = l === "image/png" ? "png" : "jpg", o = (t.name || "image").replace(/\.[^.]+$/, ""); return new File([e], `${o}.${a}`, { type: l, lastModified: Date.now() }); }, we = (e) => K(this, null, function* () { const t = Array.from(e && e.target && e.target.files || []); if (F.value && (F.value.value = ""), !t.length) return; if (s.value.length + t.length > n.maxFileCount) { window.$message.warning( window.$l("上传图片,最多可上传") + n.maxFileCount + window.$l("张") ); return; } let l = t; if (n.crop) { l = []; for (let a = 0; a < t.length; a++) { const o = yield fe(t[a], a + 1, t.length); if (!o) continue; const p = ge(o, t[a]); if (p.size > n.fileSize * 1024) { window.$message.warning(`${window.$l("上传图片大小不能大于")}${n.fileSize}KB`); continue; } l.push(p); } if (!l.length) return; } else for (let a = 0; a < t.length; a++) if (t[a].size > n.fileSize * 1024) { window.$message.warning(`${window.$l("上传图片大小不能大于")}${n.fileSize}KB`); return; } Fe(C(), l).then((a) => { if (a && a.length) for (let o = 0; o < a.length; o++) s.value.push({ sort: o, name: l[o] && l[o].name || G(a[o].imageUrl), imageUrl: a[o].imageUrl, uid: a[o].imageUrl, url: a[o].imageUrl }); P(); }); }), ye = (e) => { d.value && (e.showTool = !0); }, he = (e) => { d.value && (e.showTool = !1); }, J = (e, t) => { s.value.splice(e, 1), Re(C(), t.imageUrl || t.uid), P(); }, Q = (e = {}) => { const t = S(e); if (!t) return; if (!H(e)) { window.open(t, "_blank", "noopener"); return; } let l = s.value.findIndex((a) => a === e); l < 0 && (l = s.value.findIndex((a) => S(a) === t)), X.value = l > -1 ? l : 0, A.value = !0; }, Y = (...t) => K(this, [...t], function* (e = {}) { const l = S(e); if (!l) return; g("download", e); const a = U(e), o = (p, V) => { const f = document.createElement("a"); f.href = p, f.download = a, V || (f.target = "_blank", f.rel = "noopener"), document.body.appendChild(f), f.click(), document.body.removeChild(f); }; try { const p = yield fetch(l); if (!p.ok) throw new Error("fetch failed"); const V = yield p.blob(), f = URL.createObjectURL(V); o(f, !0), setTimeout(() => URL.revokeObjectURL(f), 1e3); } catch (p) { o(l, !1); } }); return (e, t) => (i(), w("div", { class: I(["s-file-upload-common", [`is-${r.listType}`, { "is-readonly": k.value }]]) }, [ r.label ? (i(), w("div", Me, [ y("div", Te, B(r.label), 1) ])) : u("", !0), D(v(Oe), { modelValue: s.value, "onUpdate:modelValue": t[0] || (t[0] = (l) => s.value = l), onStart: de, onEnd: ce, handle: ".move", class: I(d.value ? "img-list-wrap" : "file-list-wrap"), style: ke(r.picStyle), disabled: !b.value, "item-key": "uid" }, { item: ee(({ element: l, index: a }) => [ (i(), w("div", { key: l.uid || a, class: I(d.value ? "img-item-wrap" : "file-row"), onMouseover: (o) => ye(l), onMouseleave: (o) => he(l) }, [ d.value ? (i(), w(le, { key: 0 }, [ H(l) ? (i(), w("img", { key: 0, class: "upload-img-wrap", src: S(l), alt: U(l) }, null, 8, De)) : (i(), w("div", je, [ (i(), m(te(W(l)), { class: "file-thumb-icon" })), y("span", Ne, B(z(l) || "FILE"), 1) ])), Ce(y("div", _e, [ y("div", Ae, [ r.showPreview ? (i(), m(v(ae), { key: 0, class: "tool-icon-wrap", title: e.$l("预览"), onClick: O((o) => Q(l), ["stop"]) }, null, 8, ["title", "onClick"])) : u("", !0), r.showDownload ? (i(), m(v(oe), { key: 1, class: "tool-icon-wrap", title: e.$l("下载"), onClick: O((o) => Y(l), ["stop"]) }, null, 8, ["title", "onClick"])) : u("", !0), c.value ? (i(), m(v(ne), { key: 2, class: "tool-icon-wrap", title: e.$l("删除"), onClick: O((o) => J(a, l), ["stop"]) }, null, 8, ["title", "onClick"])) : u("", !0) ]), y("div", Pe, [ b.value ? (i(), m(v(ie), { key: 0 })) : u("", !0) ]) ], 512), [ [$e, l.showTool] ]) ], 64)) : (i(), w(le, { key: 1 }, [ (i(), m(te(W(l)), { class: "file-row-icon" })), y("span", Ve, B(z(l) || "FILE"), 1), y("span", { class: "file-row-name", title: U(l) }, B(U(l)), 9, Ke), y("span", qe, [ r.showPreview ? (i(), m(v(ae), { key: 0, class: "file-action", title: e.$l("预览"), onClick: O((o) => Q(l), ["stop"]) }, null, 8, ["title", "onClick"])) : u("", !0), r.showDownload ? (i(), m(v(oe), { key: 1, class: "file-action", title: e.$l("下载"), onClick: O((o) => Y(l), ["stop"]) }, null, 8, ["title", "onClick"])) : u("", !0), c.value ? (i(), m(v(ne), { key: 2, class: "file-action", title: e.$l("删除"), onClick: O((o) => J(a, l), ["stop"]) }, null, 8, ["title", "onClick"])) : u("", !0), b.value ? (i(), m(v(ie), { key: 3, class: "file-action move", title: e.$l("拖动排序") }, null, 8, ["title"])) : u("", !0) ]) ], 64)) ], 42, ze)) ]), footer: ee(() => [ s.value.length < r.maxFileCount && r.isAdd && !k.value ? (i(), w("div", { key: 0, class: I(d.value ? "img-add-wrap" : "file-add-wrap"), onClick: pe }, [ D(v(Ie), { class: I(d.value ? "plus-icon" : "plus-icon plus-icon-small") }, null, 8, ["class"]), d.value ? u("", !0) : (i(), w("span", Ge, B(e.$l("上传文件")), 1)), y("input", { accept: r.accept || "image/*", multiple: !0, type: "file", disabled: T.value, ref_key: "fileInput", ref: F, style: { display: "none" }, onChange: we }, null, 40, He) ], 2)) : u("", !0) ]), _: 1 }, 8, ["modelValue", "class", "style", "disabled"]), D(Se, { value: A.value, "onUpdate:value": t[1] || (t[1] = (l) => A.value = l), list: s.value, active: X.value }, null, 8, ["value", "list", "active"]), D(Ue, { ref_key: "cropperRef", ref: Z, onCropperOk: ve, onCropperNo: me }, null, 512) ], 2)); } }, tl = /* @__PURE__ */ xe(We, [["__scopeId", "data-v-600b5bd0"]]); export { tl as default };