| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481 |
- var K = (r, _, g) => new Promise((n, T) => {
- var k = (d) => {
- try {
- b(g.next(d));
- } catch (C) {
- T(C);
- }
- }, c = (d) => {
- try {
- b(g.throw(d));
- } catch (C) {
- T(C);
- }
- }, b = (d) => d.done ? n(d.value) : Promise.resolve(d.value).then(k, c);
- 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), c = R(() => n.listType !== "list"), b = R(() => n.isAdd && !k.value && !n.noDrag), d = 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);
- }, ce = (e) => {
- }, de = (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) => {
- c.value && (e.showTool = !0);
- }, he = (e) => {
- c.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: ce,
- onEnd: de,
- handle: ".move",
- class: I(c.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(c.value ? "img-item-wrap" : "file-row"),
- onMouseover: (o) => ye(l),
- onMouseleave: (o) => he(l)
- }, [
- c.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),
- d.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),
- d.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(c.value ? "img-add-wrap" : "file-add-wrap"),
- onClick: pe
- }, [
- D(v(Ie), {
- class: I(c.value ? "plus-icon" : "plus-icon plus-icon-small")
- }, null, 8, ["class"]),
- c.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-64e419f4"]]);
- export {
- tl as default
- };
|