SDraggerUpload.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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. // 业务主键,随上传一起提交用于关联业务数据
  146. businessKey: {
  147. type: String,
  148. default: void 0
  149. },
  150. // 兼容保留(PictureUpload 无上传列表概念,仅声明避免外部传参告警)
  151. showUploadList: {
  152. type: Boolean,
  153. default: !0
  154. },
  155. // 已废弃:由 showRemove 取代,仅保留声明避免外部传参告警
  156. showRemoveIcon: {
  157. type: Boolean,
  158. default: !1
  159. }
  160. },
  161. emits: ["change", "handChange", "dragChange", "download"],
  162. setup(u, { emit: _ }) {
  163. 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 = {
  164. pdf: Se,
  165. doc: R,
  166. docx: R,
  167. wps: R,
  168. rtf: R,
  169. xls: V,
  170. xlsx: V,
  171. csv: V,
  172. ppt: oe,
  173. pptx: oe,
  174. zip: D,
  175. rar: D,
  176. "7z": D,
  177. gz: D,
  178. tar: D,
  179. txt: L,
  180. log: L,
  181. json: L,
  182. xml: L,
  183. md: Oe,
  184. png: h,
  185. jpg: h,
  186. jpeg: h,
  187. gif: h,
  188. webp: h,
  189. bmp: h,
  190. svg: h,
  191. ico: h,
  192. mp4: B,
  193. mov: B,
  194. avi: B,
  195. mkv: B,
  196. webm: B,
  197. mp3: E,
  198. wav: E,
  199. flac: E,
  200. aac: E,
  201. m4a: E
  202. }, $ = (e = {}) => e.imageUrl || e.url || e.uid || "", K = (e = "") => {
  203. const t = String(e).split("?")[0].split("#")[0], l = t.substring(t.lastIndexOf("/") + 1);
  204. try {
  205. return decodeURIComponent(l);
  206. } catch (a) {
  207. return l;
  208. }
  209. }, O = (e = {}) => e.name || K($(e)) || window.$l("未命名文件"), A = (e = {}) => {
  210. const t = O(e), l = t.lastIndexOf(".");
  211. return l > -1 ? t.slice(l + 1).toLowerCase() : "";
  212. }, q = (e = {}) => {
  213. const t = e.type || e.mimeType || "";
  214. return t ? String(t).indexOf("image/") === 0 : ie.includes(A(e));
  215. }, G = (e = {}) => se[A(e)] || Fe, s = T([]), z = T(!1), H = T(0);
  216. ve(
  217. () => i.list,
  218. (e) => {
  219. s.value = e || [];
  220. },
  221. { immediate: !0, deep: !0 }
  222. );
  223. const P = () => {
  224. m("change", s.value), m("handChange", s.value);
  225. }, ue = (e) => {
  226. }, de = (e) => {
  227. s.value && s.value.length > 1 && s.value.forEach((t, l) => {
  228. t.sort = l;
  229. }), m("dragChange", s.value), P();
  230. }, re = () => {
  231. S.value && S.value.click();
  232. }, S = T(null), ce = (e) => {
  233. const t = e.target.files;
  234. if (t && t.length && s.value.length + t.length > i.maxFileCount) {
  235. window.$message.warning(
  236. window.$l("上传图片,最多可上传") + i.maxFileCount + window.$l("张")
  237. );
  238. return;
  239. }
  240. if (t && t.length) {
  241. for (let a = 0; a < t.length; a++)
  242. if (t[a].size > i.fileSize * 1024) {
  243. window.$message.warning(`${window.$l("上传图片大小不能大于")}${i.fileSize}KB`);
  244. return;
  245. }
  246. }
  247. const l = Array.from(t || []);
  248. be(k(), t).then((a) => {
  249. if (a && a.length)
  250. for (let n = 0; n < a.length; n++)
  251. s.value.push({
  252. sort: n,
  253. name: l[n] && l[n].name || K(a[n].imageUrl),
  254. imageUrl: a[n].imageUrl,
  255. uid: a[n].imageUrl,
  256. url: a[n].imageUrl
  257. });
  258. P();
  259. }).finally(() => {
  260. S.value && (S.value.value = "");
  261. });
  262. }, fe = (e) => {
  263. r.value && (e.showTool = !0);
  264. }, pe = (e) => {
  265. r.value && (e.showTool = !1);
  266. }, W = (e, t) => {
  267. s.value.splice(e, 1), ke(k(), t.imageUrl || t.uid), P();
  268. }, X = (e = {}) => {
  269. const t = $(e);
  270. if (!t) return;
  271. if (!q(e)) {
  272. window.open(t, "_blank", "noopener");
  273. return;
  274. }
  275. let l = s.value.findIndex((a) => a === e);
  276. l < 0 && (l = s.value.findIndex((a) => $(a) === t)), H.value = l > -1 ? l : 0, z.value = !0;
  277. }, Z = (...t) => J(this, [...t], function* (e = {}) {
  278. const l = $(e);
  279. if (!l) return;
  280. m("download", e);
  281. const a = O(e), n = (F, N) => {
  282. const f = document.createElement("a");
  283. f.href = F, f.download = a, N || (f.target = "_blank", f.rel = "noopener"), document.body.appendChild(f), f.click(), document.body.removeChild(f);
  284. };
  285. try {
  286. const F = yield fetch(l);
  287. if (!F.ok) throw new Error("fetch failed");
  288. const N = yield F.blob(), f = URL.createObjectURL(N);
  289. n(f, !0), setTimeout(() => URL.revokeObjectURL(f), 1e3);
  290. } catch (F) {
  291. n(l, !1);
  292. }
  293. });
  294. return (e, t) => (o(), g("div", {
  295. class: x(["s-file-upload-common", [`is-${u.listType}`, { "is-readonly": b.value }]])
  296. }, [
  297. u.label ? (o(), g("div", Ue, [
  298. w("div", xe, I(u.label), 1)
  299. ])) : d("", !0),
  300. j(p(he), {
  301. modelValue: s.value,
  302. "onUpdate:modelValue": t[0] || (t[0] = (l) => s.value = l),
  303. onStart: ue,
  304. onEnd: de,
  305. handle: ".move",
  306. class: x(r.value ? "img-list-wrap" : "file-list-wrap"),
  307. style: me(u.picStyle),
  308. disabled: !y.value,
  309. "item-key": "uid"
  310. }, {
  311. item: Q(({ element: l, index: a }) => [
  312. (o(), g("div", {
  313. key: l.uid || a,
  314. class: x(r.value ? "img-item-wrap" : "file-row"),
  315. onMouseover: (n) => fe(l),
  316. onMouseleave: (n) => pe(l)
  317. }, [
  318. r.value ? (o(), g(Y, { key: 0 }, [
  319. q(l) ? (o(), g("img", {
  320. key: 0,
  321. class: "upload-img-wrap",
  322. src: $(l),
  323. alt: O(l)
  324. }, null, 8, Ee)) : (o(), g("div", Be, [
  325. (o(), v(ee(G(l)), { class: "file-thumb-icon" })),
  326. w("span", De, I(A(l) || "FILE"), 1)
  327. ])),
  328. ge(w("div", Me, [
  329. w("div", Ae, [
  330. u.showPreview ? (o(), v(p(le), {
  331. key: 0,
  332. class: "tool-icon-wrap",
  333. title: e.$l("预览"),
  334. onClick: C((n) => X(l), ["stop"])
  335. }, null, 8, ["title", "onClick"])) : d("", !0),
  336. u.showDownload ? (o(), v(p(te), {
  337. key: 1,
  338. class: "tool-icon-wrap",
  339. title: e.$l("下载"),
  340. onClick: C((n) => Z(l), ["stop"])
  341. }, null, 8, ["title", "onClick"])) : d("", !0),
  342. c.value ? (o(), v(p(ae), {
  343. key: 2,
  344. class: "tool-icon-wrap",
  345. title: e.$l("删除"),
  346. onClick: C((n) => W(a, l), ["stop"])
  347. }, null, 8, ["title", "onClick"])) : d("", !0)
  348. ]),
  349. w("div", Te, [
  350. y.value ? (o(), v(p(ne), { key: 0 })) : d("", !0)
  351. ])
  352. ], 512), [
  353. [we, l.showTool]
  354. ])
  355. ], 64)) : (o(), g(Y, { key: 1 }, [
  356. (o(), v(ee(G(l)), { class: "file-row-icon" })),
  357. w("span", Le, I(A(l) || "FILE"), 1),
  358. w("span", {
  359. class: "file-row-name",
  360. title: O(l)
  361. }, I(O(l)), 9, Re),
  362. w("span", _e, [
  363. u.showPreview ? (o(), v(p(le), {
  364. key: 0,
  365. class: "file-action",
  366. title: e.$l("预览"),
  367. onClick: C((n) => X(l), ["stop"])
  368. }, null, 8, ["title", "onClick"])) : d("", !0),
  369. u.showDownload ? (o(), v(p(te), {
  370. key: 1,
  371. class: "file-action",
  372. title: e.$l("下载"),
  373. onClick: C((n) => Z(l), ["stop"])
  374. }, null, 8, ["title", "onClick"])) : d("", !0),
  375. c.value ? (o(), v(p(ae), {
  376. key: 2,
  377. class: "file-action",
  378. title: e.$l("删除"),
  379. onClick: C((n) => W(a, l), ["stop"])
  380. }, null, 8, ["title", "onClick"])) : d("", !0),
  381. y.value ? (o(), v(p(ne), {
  382. key: 3,
  383. class: "file-action move",
  384. title: e.$l("拖动排序")
  385. }, null, 8, ["title"])) : d("", !0)
  386. ])
  387. ], 64))
  388. ], 42, Ie))
  389. ]),
  390. footer: Q(() => [
  391. s.value.length < u.maxFileCount && u.isAdd && !b.value ? (o(), g("div", {
  392. key: 0,
  393. class: x(r.value ? "img-add-wrap" : "file-add-wrap"),
  394. onClick: re
  395. }, [
  396. j(p($e), {
  397. class: x(r.value ? "plus-icon" : "plus-icon plus-icon-small")
  398. }, null, 8, ["class"]),
  399. r.value ? d("", !0) : (o(), g("span", ze, I(e.$l("上传文件")), 1)),
  400. w("input", {
  401. accept: u.accept || "image/*",
  402. multiple: !0,
  403. type: "file",
  404. disabled: M.value,
  405. ref_key: "fileInput",
  406. ref: S,
  407. style: { display: "none" },
  408. onChange: ce
  409. }, null, 40, Pe)
  410. ], 2)) : d("", !0)
  411. ]),
  412. _: 1
  413. }, 8, ["modelValue", "class", "style", "disabled"]),
  414. j(ye, {
  415. value: z.value,
  416. "onUpdate:value": t[1] || (t[1] = (l) => z.value = l),
  417. list: s.value,
  418. active: H.value
  419. }, null, 8, ["value", "list", "active"])
  420. ], 2));
  421. }
  422. }, We = /* @__PURE__ */ Ce(Ne, [["__scopeId", "data-v-8d154ed9"]]);
  423. export {
  424. We as default
  425. };