SFileUpload.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. import { computed as M, ref as c, watch as z, resolveComponent as L, openBlock as r, createElementBlock as f, createElementVNode as i, toDisplayString as P, createCommentVNode as h, createVNode as v, unref as u, normalizeStyle as R, withCtx as S, withDirectives as K, createBlock as x, vShow as j } from "vue";
  2. import { d as H } from "./vuedraggable.js";
  3. import { b as q, d as G } from "./upload.js";
  4. import { n as J, ak as Q, al as W, am as X, an as Y, $ as Z, a0 as ee } from "./index2.js";
  5. const le = { class: "s-file-upload-common" }, te = {
  6. key: 0,
  7. class: "head"
  8. }, ae = { class: "label" }, ne = ["onMouseover", "onMouseleave"], ie = ["src"], oe = { class: "tool-wrap" }, se = { class: "left" }, ue = { class: "right move" }, de = { class: "plus-wrap" }, ce = ["accept", "disabled"], re = { class: "preview-content" }, ve = ["src"], me = {
  9. __name: "SFileUpload",
  10. props: {
  11. /**
  12. * 文件列表(同 PictureUpload 的 data)
  13. * @list
  14. */
  15. list: {
  16. type: Array,
  17. default: () => []
  18. },
  19. /**
  20. * 标题
  21. * @label
  22. */
  23. label: {
  24. type: String,
  25. default: ""
  26. },
  27. /**
  28. * 只读(同 PictureUpload 的 disabled)
  29. * @readonly
  30. */
  31. readonly: {
  32. type: Boolean,
  33. default: !1
  34. },
  35. /**
  36. * 是否显示新增(isAdd=false 等价 PictureUpload 的 ishiddenAdd=true:隐藏添加框且不可删除/拖拽)
  37. * @isAdd
  38. */
  39. isAdd: {
  40. type: Boolean,
  41. default: !0
  42. },
  43. /**
  44. * 文件类型
  45. * @accept
  46. */
  47. accept: {
  48. type: String,
  49. default: "image/*"
  50. },
  51. // 最多可上传数量(同 PictureUpload 的 maxSize)
  52. maxFileCount: {
  53. type: Number,
  54. default: 5
  55. },
  56. // 单文件大小上限,单位 KB(同 PictureUpload 的 fileSize)
  57. fileSize: {
  58. type: Number,
  59. default: 200
  60. },
  61. // FTP 上传目录(同 PictureUpload 的 path),不传时回退 businessTableName
  62. path: {
  63. type: String,
  64. default: void 0
  65. },
  66. // 是否隐藏拖拽排序图标(同 PictureUpload 的 noDrag)
  67. noDrag: {
  68. type: Boolean,
  69. default: !1
  70. },
  71. // 图片列表容器样式(同 PictureUpload 的 picStyle)
  72. picStyle: {
  73. type: Object,
  74. default: () => {
  75. }
  76. },
  77. // 兼容保留:不传 path 时作为 FTP 目录名
  78. businessTableName: {
  79. type: String,
  80. default: "sapit-ui-plus-components-upload"
  81. },
  82. businessKey: {
  83. type: String,
  84. default: void 0
  85. },
  86. // 兼容保留(PictureUpload 无上传列表概念,仅声明避免外部传参告警)
  87. showUploadList: {
  88. type: Boolean,
  89. default: !0
  90. },
  91. // 兼容保留( PictureUpload 无此概念,仅声明)
  92. listType: {
  93. type: String,
  94. default: "picture-card"
  95. },
  96. showRemoveIcon: {
  97. type: Boolean,
  98. default: !1
  99. }
  100. },
  101. emits: ["change", "handChange", "dragChange"],
  102. setup(o, { emit: B }) {
  103. const w = B, s = o, m = M(() => s.readonly), $ = () => s.path || s.businessTableName, a = c([]), p = c(!1), y = c(""), C = c(""), d = c(0);
  104. z(
  105. () => s.list,
  106. (l) => {
  107. a.value = l || [];
  108. },
  109. { immediate: !0, deep: !0 }
  110. );
  111. const b = () => {
  112. w("change", a.value), w("handChange", a.value);
  113. }, F = (l) => {
  114. }, A = (l) => {
  115. a.value && a.value.length > 1 && a.value.forEach((e, n) => {
  116. e.sort = n;
  117. }), w("dragChange", a.value), b();
  118. }, E = () => {
  119. g.value.click();
  120. }, g = c(null), N = (l) => {
  121. const e = l.target.files;
  122. if (e && e.length && a.value.length + e.length > s.maxFileCount) {
  123. window.$message.warning(window.$l("上传图片,最多可上传") + s.maxFileCount + window.$l("张"));
  124. return;
  125. }
  126. if (e && e.length) {
  127. for (let n = 0; n < e.length; n++)
  128. if (e[n].size > s.fileSize * 1024) {
  129. window.$message.warning(
  130. `${window.$l("上传图片大小不能大于")}${s.fileSize}KB`
  131. );
  132. return;
  133. }
  134. }
  135. q($(), e).then((n) => {
  136. if (n && n.length)
  137. for (let t = 0; t < n.length; t++)
  138. a.value.push({
  139. sort: t,
  140. imageUrl: n[t].imageUrl,
  141. uid: n[t].imageUrl,
  142. url: n[t].imageUrl
  143. });
  144. b();
  145. }).finally(() => {
  146. g.value && (g.value.value = "");
  147. });
  148. }, O = (l) => {
  149. l.showTool = !0;
  150. }, T = (l) => {
  151. l.showTool = !1;
  152. }, V = (l, e) => {
  153. a.value.splice(l, 1), G($(), e.imageUrl || e.uid), b();
  154. }, D = (l = {}) => {
  155. d.value = a.value.findIndex((e) => e === l), p.value = !0, C.value = l.name || window.$l("预览"), y.value = l.imageUrl || l.url;
  156. }, I = () => {
  157. p.value = !1;
  158. }, _ = (l) => {
  159. d.value = d.value + l < 0 ? 0 : d.value + l > a.value.length - 1 ? a.value.length - 1 : d.value + l;
  160. const e = a.value[d.value];
  161. e && (C.value = e.name || window.$l("预览"), y.value = e.imageUrl || e.url);
  162. };
  163. return (l, e) => {
  164. const n = L("s-modal");
  165. return r(), f("div", le, [
  166. o.label ? (r(), f("div", te, [
  167. i("div", ae, P(o.label), 1)
  168. ])) : h("", !0),
  169. v(u(H), {
  170. modelValue: a.value,
  171. "onUpdate:modelValue": e[0] || (e[0] = (t) => a.value = t),
  172. onStart: F,
  173. onEnd: A,
  174. handle: ".move",
  175. class: "img-list-wrap",
  176. style: R(o.picStyle),
  177. disabled: m.value,
  178. "item-key": "uid"
  179. }, {
  180. item: S(({ element: t, index: U }) => [
  181. (r(), f("div", {
  182. class: "img-item-wrap",
  183. key: t.uid || U,
  184. onMouseover: (k) => O(t),
  185. onMouseleave: (k) => T(t)
  186. }, [
  187. i("img", {
  188. class: "upload-img-wrap",
  189. src: t.imageUrl || t.url
  190. }, null, 8, ie),
  191. K(i("div", oe, [
  192. i("div", se, [
  193. v(u(W), {
  194. class: "tool-icon-wrap",
  195. style: { "margin-right": "8px" },
  196. onClick: (k) => D(t)
  197. }, null, 8, ["onClick"]),
  198. o.isAdd && !m.value ? (r(), x(u(X), {
  199. key: 0,
  200. class: "tool-icon-wrap",
  201. onClick: (k) => V(U, t)
  202. }, null, 8, ["onClick"])) : h("", !0)
  203. ]),
  204. i("div", ue, [
  205. o.isAdd && !m.value && !o.noDrag ? (r(), x(u(Y), { key: 0 })) : h("", !0)
  206. ])
  207. ], 512), [
  208. [j, t.showTool]
  209. ])
  210. ], 40, ne))
  211. ]),
  212. footer: S(() => [
  213. a.value.length < o.maxFileCount && o.isAdd ? (r(), f("div", {
  214. key: 0,
  215. class: "img-add-wrap",
  216. onClick: E
  217. }, [
  218. i("div", de, [
  219. v(u(Q), { class: "plus-icon" }),
  220. i("input", {
  221. accept: o.accept || "image/*",
  222. multiple: !0,
  223. type: "file",
  224. disabled: m.value,
  225. ref_key: "fileInput",
  226. ref: g,
  227. style: { display: "none" },
  228. onChange: N
  229. }, null, 40, ce)
  230. ])
  231. ])) : h("", !0)
  232. ]),
  233. _: 1
  234. }, 8, ["modelValue", "style", "disabled"]),
  235. v(n, {
  236. value: p.value,
  237. "onUpdate:value": e[3] || (e[3] = (t) => p.value = t),
  238. title: C.value,
  239. onHandCancel: I,
  240. width: "800px"
  241. }, {
  242. default: S(() => [
  243. i("div", re, [
  244. i("div", {
  245. class: "prev",
  246. onClick: e[1] || (e[1] = (t) => _(-1))
  247. }, [
  248. v(u(Z))
  249. ]),
  250. i("img", {
  251. alt: "example",
  252. class: "view",
  253. src: y.value
  254. }, null, 8, ve),
  255. i("div", {
  256. class: "next",
  257. onClick: e[2] || (e[2] = (t) => _(1))
  258. }, [
  259. v(u(ee))
  260. ])
  261. ])
  262. ]),
  263. _: 1
  264. }, 8, ["value", "title"])
  265. ]);
  266. };
  267. }
  268. }, we = /* @__PURE__ */ J(me, [["__scopeId", "data-v-934171ad"]]);
  269. export {
  270. we as default
  271. };