SDraggerUpload.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. var J = (u, _, m) => new Promise((i, M) => {
  2. var b = (c) => {
  3. try {
  4. y(m.next(c));
  5. } catch (k) {
  6. M(k);
  7. }
  8. }, r = (c) => {
  9. try {
  10. y(m.throw(c));
  11. } catch (k) {
  12. M(k);
  13. }
  14. }, y = (c) => c.done ? i(c.value) : Promise.resolve(c.value).then(b, r);
  15. y((m = m.apply(u, _)).next());
  16. });
  17. import { computed as U, ref as T, 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";
  18. import { d as he } from "./vuedraggable.js";
  19. import ye from "./SFilePreview.js";
  20. import { b as be, d as ke } from "./upload.js";
  21. 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 Oe, au as L, av as D, aw as oe, ax as V, ay as R, az as Se, aA as Fe } from "./index2.js";
  22. const Ue = {
  23. key: 0,
  24. class: "head"
  25. }, xe = { class: "label" }, Ie = ["onMouseover", "onMouseleave"], Ee = ["src", "alt"], Be = {
  26. key: 1,
  27. class: "file-thumb"
  28. }, De = { class: "file-thumb-ext" }, Me = { class: "tool-wrap" }, Ae = { class: "left" }, Te = { class: "right move" }, Le = { class: "file-row-ext" }, Re = ["title"], _e = { class: "file-row-actions" }, ze = {
  29. key: 0,
  30. class: "file-add-text"
  31. }, Pe = ["accept", "disabled"], Ne = {
  32. __name: "SDraggerUpload",
  33. props: {
  34. /**
  35. * 文件列表(同 PictureUpload 的 data)
  36. * @list
  37. */
  38. list: {
  39. type: Array,
  40. default: () => []
  41. },
  42. /**
  43. * 标题
  44. * @label
  45. */
  46. label: {
  47. type: String,
  48. default: ""
  49. },
  50. /**
  51. * 只读(同 PictureUpload 的 disabled)
  52. * @readonly
  53. */
  54. readonly: {
  55. type: Boolean,
  56. default: !1
  57. },
  58. /**
  59. * 详情模式:只读展示,不显示新增入口、不可删除拖拽,仅保留预览与下载
  60. * @detailMode
  61. */
  62. detailMode: {
  63. type: Boolean,
  64. default: !1
  65. },
  66. /**
  67. * 是否显示新增(isAdd=false 等价 PictureUpload 的 ishiddenAdd=true:隐藏添加框且不可删除/拖拽)
  68. * @isAdd
  69. */
  70. isAdd: {
  71. type: Boolean,
  72. default: !0
  73. },
  74. /**
  75. * 文件类型
  76. * @accept
  77. */
  78. accept: {
  79. type: String,
  80. default: "image/*"
  81. },
  82. /**
  83. * 展示形态:card 卡片(图片显示原图,其他类型显示文件类型);list 列表(文件类型 + 文件名 + 操作按钮)
  84. * @listType
  85. */
  86. listType: {
  87. type: String,
  88. default: "card"
  89. },
  90. /**
  91. * 是否显示预览按钮
  92. * @showPreview
  93. */
  94. showPreview: {
  95. type: Boolean,
  96. default: !0
  97. },
  98. /**
  99. * 是否显示下载按钮
  100. * @showDownload
  101. */
  102. showDownload: {
  103. type: Boolean,
  104. default: !0
  105. },
  106. /**
  107. * 是否显示删除按钮(仍需 isAdd 且非只读)
  108. * @showRemove
  109. */
  110. showRemove: {
  111. type: Boolean,
  112. default: !0
  113. },
  114. // 最多可上传数量(同 PictureUpload 的 maxSize)
  115. maxFileCount: {
  116. type: Number,
  117. default: 5
  118. },
  119. // 单文件大小上限,单位 KB(同 PictureUpload 的 fileSize)
  120. fileSize: {
  121. type: Number,
  122. default: 200
  123. },
  124. // FTP 上传目录(同 PictureUpload 的 path),不传时回退 businessTableName
  125. path: {
  126. type: String,
  127. default: void 0
  128. },
  129. // 是否隐藏拖拽排序图标(同 PictureUpload 的 noDrag)
  130. noDrag: {
  131. type: Boolean,
  132. default: !1
  133. },
  134. // 图片列表容器样式(同 PictureUpload 的 picStyle)
  135. picStyle: {
  136. type: Object,
  137. default: () => {
  138. }
  139. },
  140. // 兼容保留:不传 path 时作为 FTP 目录名
  141. businessTableName: {
  142. type: String,
  143. default: "sapit-ui-plus-components-upload"
  144. },
  145. businessKey: {
  146. type: String,
  147. default: void 0
  148. },
  149. // 兼容保留(PictureUpload 无上传列表概念,仅声明避免外部传参告警)
  150. showUploadList: {
  151. type: Boolean,
  152. default: !0
  153. },
  154. // 已废弃:由 showRemove 取代,仅保留声明避免外部传参告警
  155. showRemoveIcon: {
  156. type: Boolean,
  157. default: !1
  158. }
  159. },
  160. emits: ["change", "handChange", "dragChange", "download"],
  161. setup(u, { emit: _ }) {
  162. const m = _, i = u, M = U(() => i.readonly || i.detailMode), b = U(() => i.readonly || i.detailMode), r = U(() => i.listType !== "list"), y = U(() => i.isAdd && !b.value && !i.noDrag), c = 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 = {
  163. pdf: Se,
  164. doc: R,
  165. docx: R,
  166. wps: R,
  167. rtf: R,
  168. xls: V,
  169. xlsx: V,
  170. csv: V,
  171. ppt: oe,
  172. pptx: oe,
  173. zip: D,
  174. rar: D,
  175. "7z": D,
  176. gz: D,
  177. tar: D,
  178. txt: L,
  179. log: L,
  180. json: L,
  181. xml: L,
  182. md: Oe,
  183. png: h,
  184. jpg: h,
  185. jpeg: h,
  186. gif: h,
  187. webp: h,
  188. bmp: h,
  189. svg: h,
  190. ico: h,
  191. mp4: B,
  192. mov: B,
  193. avi: B,
  194. mkv: B,
  195. webm: B,
  196. mp3: E,
  197. wav: E,
  198. flac: E,
  199. aac: E,
  200. m4a: E
  201. }, $ = (e = {}) => e.imageUrl || e.url || e.uid || "", K = (e = "") => {
  202. const t = String(e).split("?")[0].split("#")[0], l = t.substring(t.lastIndexOf("/") + 1);
  203. try {
  204. return decodeURIComponent(l);
  205. } catch (a) {
  206. return l;
  207. }
  208. }, O = (e = {}) => e.name || K($(e)) || window.$l("未命名文件"), A = (e = {}) => {
  209. const t = O(e), l = t.lastIndexOf(".");
  210. return l > -1 ? t.slice(l + 1).toLowerCase() : "";
  211. }, q = (e = {}) => {
  212. const t = e.type || e.mimeType || "";
  213. return t ? String(t).indexOf("image/") === 0 : ie.includes(A(e));
  214. }, G = (e = {}) => se[A(e)] || Fe, s = T([]), z = T(!1), H = T(0);
  215. ve(
  216. () => i.list,
  217. (e) => {
  218. s.value = e || [];
  219. },
  220. { immediate: !0, deep: !0 }
  221. );
  222. const P = () => {
  223. m("change", s.value), m("handChange", s.value);
  224. }, ue = (e) => {
  225. }, de = (e) => {
  226. s.value && s.value.length > 1 && s.value.forEach((t, l) => {
  227. t.sort = l;
  228. }), m("dragChange", s.value), P();
  229. }, re = () => {
  230. S.value && S.value.click();
  231. }, S = T(null), ce = (e) => {
  232. const t = e.target.files;
  233. if (t && t.length && s.value.length + t.length > i.maxFileCount) {
  234. window.$message.warning(
  235. window.$l("上传图片,最多可上传") + i.maxFileCount + window.$l("张")
  236. );
  237. return;
  238. }
  239. if (t && t.length) {
  240. for (let a = 0; a < t.length; a++)
  241. if (t[a].size > i.fileSize * 1024) {
  242. window.$message.warning(`${window.$l("上传图片大小不能大于")}${i.fileSize}KB`);
  243. return;
  244. }
  245. }
  246. const l = Array.from(t || []);
  247. be(k(), t).then((a) => {
  248. if (a && a.length)
  249. for (let n = 0; n < a.length; n++)
  250. s.value.push({
  251. sort: n,
  252. name: l[n] && l[n].name || K(a[n].imageUrl),
  253. imageUrl: a[n].imageUrl,
  254. uid: a[n].imageUrl,
  255. url: a[n].imageUrl
  256. });
  257. P();
  258. }).finally(() => {
  259. S.value && (S.value.value = "");
  260. });
  261. }, fe = (e) => {
  262. r.value && (e.showTool = !0);
  263. }, pe = (e) => {
  264. r.value && (e.showTool = !1);
  265. }, W = (e, t) => {
  266. s.value.splice(e, 1), ke(k(), t.imageUrl || t.uid), P();
  267. }, X = (e = {}) => {
  268. const t = $(e);
  269. if (!t) return;
  270. if (!q(e)) {
  271. window.open(t, "_blank", "noopener");
  272. return;
  273. }
  274. let l = s.value.findIndex((a) => a === e);
  275. l < 0 && (l = s.value.findIndex((a) => $(a) === t)), H.value = l > -1 ? l : 0, z.value = !0;
  276. }, Z = (...t) => J(this, [...t], function* (e = {}) {
  277. const l = $(e);
  278. if (!l) return;
  279. m("download", e);
  280. const a = O(e), n = (F, N) => {
  281. const f = document.createElement("a");
  282. f.href = F, f.download = a, N || (f.target = "_blank", f.rel = "noopener"), document.body.appendChild(f), f.click(), document.body.removeChild(f);
  283. };
  284. try {
  285. const F = yield fetch(l);
  286. if (!F.ok) throw new Error("fetch failed");
  287. const N = yield F.blob(), f = URL.createObjectURL(N);
  288. n(f, !0), setTimeout(() => URL.revokeObjectURL(f), 1e3);
  289. } catch (F) {
  290. n(l, !1);
  291. }
  292. });
  293. return (e, t) => (o(), g("div", {
  294. class: x(["s-file-upload-common", [`is-${u.listType}`, { "is-readonly": b.value }]])
  295. }, [
  296. u.label ? (o(), g("div", Ue, [
  297. w("div", xe, I(u.label), 1)
  298. ])) : d("", !0),
  299. j(p(he), {
  300. modelValue: s.value,
  301. "onUpdate:modelValue": t[0] || (t[0] = (l) => s.value = l),
  302. onStart: ue,
  303. onEnd: de,
  304. handle: ".move",
  305. class: x(r.value ? "img-list-wrap" : "file-list-wrap"),
  306. style: me(u.picStyle),
  307. disabled: !y.value,
  308. "item-key": "uid"
  309. }, {
  310. item: Q(({ element: l, index: a }) => [
  311. (o(), g("div", {
  312. key: l.uid || a,
  313. class: x(r.value ? "img-item-wrap" : "file-row"),
  314. onMouseover: (n) => fe(l),
  315. onMouseleave: (n) => pe(l)
  316. }, [
  317. r.value ? (o(), g(Y, { key: 0 }, [
  318. q(l) ? (o(), g("img", {
  319. key: 0,
  320. class: "upload-img-wrap",
  321. src: $(l),
  322. alt: O(l)
  323. }, null, 8, Ee)) : (o(), g("div", Be, [
  324. (o(), v(ee(G(l)), { class: "file-thumb-icon" })),
  325. w("span", De, I(A(l) || "FILE"), 1)
  326. ])),
  327. ge(w("div", Me, [
  328. w("div", Ae, [
  329. u.showPreview ? (o(), v(p(le), {
  330. key: 0,
  331. class: "tool-icon-wrap",
  332. title: e.$l("预览"),
  333. onClick: C((n) => X(l), ["stop"])
  334. }, null, 8, ["title", "onClick"])) : d("", !0),
  335. u.showDownload ? (o(), v(p(te), {
  336. key: 1,
  337. class: "tool-icon-wrap",
  338. title: e.$l("下载"),
  339. onClick: C((n) => Z(l), ["stop"])
  340. }, null, 8, ["title", "onClick"])) : d("", !0),
  341. c.value ? (o(), v(p(ae), {
  342. key: 2,
  343. class: "tool-icon-wrap",
  344. title: e.$l("删除"),
  345. onClick: C((n) => W(a, l), ["stop"])
  346. }, null, 8, ["title", "onClick"])) : d("", !0)
  347. ]),
  348. w("div", Te, [
  349. y.value ? (o(), v(p(ne), { key: 0 })) : d("", !0)
  350. ])
  351. ], 512), [
  352. [we, l.showTool]
  353. ])
  354. ], 64)) : (o(), g(Y, { key: 1 }, [
  355. (o(), v(ee(G(l)), { class: "file-row-icon" })),
  356. w("span", Le, I(A(l) || "FILE"), 1),
  357. w("span", {
  358. class: "file-row-name",
  359. title: O(l)
  360. }, I(O(l)), 9, Re),
  361. w("span", _e, [
  362. u.showPreview ? (o(), v(p(le), {
  363. key: 0,
  364. class: "file-action",
  365. title: e.$l("预览"),
  366. onClick: C((n) => X(l), ["stop"])
  367. }, null, 8, ["title", "onClick"])) : d("", !0),
  368. u.showDownload ? (o(), v(p(te), {
  369. key: 1,
  370. class: "file-action",
  371. title: e.$l("下载"),
  372. onClick: C((n) => Z(l), ["stop"])
  373. }, null, 8, ["title", "onClick"])) : d("", !0),
  374. c.value ? (o(), v(p(ae), {
  375. key: 2,
  376. class: "file-action",
  377. title: e.$l("删除"),
  378. onClick: C((n) => W(a, l), ["stop"])
  379. }, null, 8, ["title", "onClick"])) : d("", !0),
  380. y.value ? (o(), v(p(ne), {
  381. key: 3,
  382. class: "file-action move",
  383. title: e.$l("拖动排序")
  384. }, null, 8, ["title"])) : d("", !0)
  385. ])
  386. ], 64))
  387. ], 42, Ie))
  388. ]),
  389. footer: Q(() => [
  390. s.value.length < u.maxFileCount && u.isAdd && !b.value ? (o(), g("div", {
  391. key: 0,
  392. class: x(r.value ? "img-add-wrap" : "file-add-wrap"),
  393. onClick: re
  394. }, [
  395. j(p($e), {
  396. class: x(r.value ? "plus-icon" : "plus-icon plus-icon-small")
  397. }, null, 8, ["class"]),
  398. r.value ? d("", !0) : (o(), g("span", ze, I(e.$l("上传文件")), 1)),
  399. w("input", {
  400. accept: u.accept || "image/*",
  401. multiple: !0,
  402. type: "file",
  403. disabled: M.value,
  404. ref_key: "fileInput",
  405. ref: S,
  406. style: { display: "none" },
  407. onChange: ce
  408. }, null, 40, Pe)
  409. ], 2)) : d("", !0)
  410. ]),
  411. _: 1
  412. }, 8, ["modelValue", "class", "style", "disabled"]),
  413. j(ye, {
  414. value: z.value,
  415. "onUpdate:value": t[1] || (t[1] = (l) => z.value = l),
  416. list: s.value,
  417. active: H.value
  418. }, null, 8, ["value", "list", "active"])
  419. ], 2));
  420. }
  421. }, We = /* @__PURE__ */ Ce(Ne, [["__scopeId", "data-v-964f3fa8"]]);
  422. export {
  423. We as default
  424. };