SFileUpload.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. import { ref as c, watch as j, onMounted as z, resolveComponent as w, openBlock as s, createElementBlock as u, withModifiers as L, toDisplayString as r, createCommentVNode as p, createVNode as o, withCtx as C, createTextVNode as D, createElementVNode as m } from "vue";
  2. import { l as E, W as I, U as M } from "./index2.js";
  3. import { a as H, d as V, p as G } from "./upload.js";
  4. import { _ as K } from "./index16.js";
  5. const W = { class: "s-file-upload-common" }, X = {
  6. key: 0,
  7. class: "head"
  8. }, J = {
  9. key: 0,
  10. class: "head"
  11. }, Q = { key: 1 }, Y = { class: "preview-content" }, Z = ["src"], _ = {
  12. __name: "SFileUpload",
  13. props: {
  14. /**
  15. * 文件列表
  16. * @list
  17. */
  18. list: {
  19. type: Array,
  20. default: () => []
  21. },
  22. /**
  23. * 标题
  24. * @label
  25. */
  26. label: {
  27. type: String,
  28. default: ""
  29. },
  30. /**
  31. * 只读
  32. * @readonly
  33. */
  34. readonly: {
  35. type: Boolean,
  36. default: !1
  37. },
  38. /**
  39. * 是否显示删除
  40. * @delete
  41. */
  42. showRemoveIcon: {
  43. type: Boolean,
  44. default: !1
  45. },
  46. /**
  47. * 是否显示新增
  48. * @isAdd
  49. */
  50. isAdd: {
  51. type: Boolean,
  52. default: !0
  53. },
  54. /**
  55. * 文件类型
  56. * @accept
  57. */
  58. accept: {
  59. type: String,
  60. default: ""
  61. },
  62. // 展示类型 picture | picture-card 注:规范内不设定text上传类型
  63. listType: {
  64. type: String,
  65. default: "picture"
  66. },
  67. maxFileCount: {
  68. type: Number,
  69. default: 3
  70. },
  71. sizeLimit: {
  72. type: Number,
  73. default: 50
  74. },
  75. businessTableName: {
  76. type: String,
  77. default: "sapit-ui-plus-components-upload"
  78. },
  79. businessKey: {
  80. type: String,
  81. default: void 0
  82. },
  83. showUploadList: {
  84. type: Boolean,
  85. default: !0
  86. }
  87. },
  88. emits: ["handChange"],
  89. setup(l, { emit: U }) {
  90. const k = U, v = l, n = c([]), f = c(!1), y = c(""), h = c(""), a = c(0);
  91. j(
  92. () => v.list,
  93. (e) => {
  94. e && e.length && (n.value = e);
  95. },
  96. { immediate: !0 }
  97. );
  98. const T = (e) => {
  99. const t = e.size / 1024 / 1024 < v.sizeLimit;
  100. return t || I.warn({
  101. key: "only-you",
  102. message: window.$l("提醒"),
  103. description: `${window.$l("文件不能大于")}${v.sizeLimit}MB!`
  104. }), t;
  105. }, $ = (e) => {
  106. n.value = e.fileList, k("handChange", n.value);
  107. }, R = ({ onSuccess: e, onError: t, file: i }) => {
  108. H(i, v.businessTableName, i.uid).then((d) => {
  109. e(d);
  110. }).catch(() => {
  111. n.value.splice(n.value.length - 1, 1), t();
  112. });
  113. }, B = (e) => {
  114. const t = document.createElement("a");
  115. t.href = V(e.uid), t.download = "test", t.click();
  116. }, F = (e) => {
  117. a.value = n.value.findIndex((t) => t.uid === e.uid), f.value = !0, h.value = e.name || window.$l("预览"), y.value = e.url || e.thumbUrl;
  118. }, N = () => {
  119. f.value = !1;
  120. }, x = (e) => {
  121. var t;
  122. a.value = a.value + e < 0 ? 0 : a.value + e > n.value.length - 1 ? n.value.length - 1 : a.value + e, (t = n.value[a.value]) != null && t.thumbUrl ? (h.value = n.value[a.value].name || window.$l("预览"), y.value = n.value[a.value].thumbUrl) : O(n.value[a.value]);
  123. }, O = (e) => {
  124. if (e.type.includes("office")) {
  125. const t = window.open("", "");
  126. t.location = G(e.uid + "/" + e.name);
  127. } else if (e.type.includes("text"))
  128. S(e.url);
  129. else if (e.type.includes("pdf") || e.type.includes("png") || e.type.includes("gif") || e.type.includes("jpeg") || e.type.includes("bmp") || e.type.includes("ico") || e.type.includes("webp")) {
  130. const t = window.open("", "");
  131. t.location = e.url;
  132. } else
  133. this.$notification.warning({
  134. message: window.$l("不支持此文件类型")
  135. });
  136. }, S = (e) => {
  137. const t = new XMLHttpRequest();
  138. t.open("GET", e, !0), t.responseType = "blob", t.setRequestHeader("Content-Type", "application/json"), t.onload = function() {
  139. const i = new Blob([t.response], { type: "application/json;charset=utf-8" }), d = window.URL.createObjectURL(i), b = window.open("", "");
  140. b.location = d;
  141. }, t.send();
  142. };
  143. return z(() => {
  144. }), (e, t) => {
  145. const i = w("PlusOutlined"), d = M, b = K, A = w("LeftOutlined"), q = w("RightOutlined"), P = w("s-modal");
  146. return s(), u("div", W, [
  147. l.isAdd && l.listType === "picture-card" && n.value.length <= l.maxFileCount ? (s(), u("div", X, [
  148. l.label ? (s(), u("div", {
  149. key: 0,
  150. class: "label",
  151. onClick: t[0] || (t[0] = L(() => {
  152. }, ["stop"]))
  153. }, r(l.label), 1)) : p("", !0)
  154. ])) : p("", !0),
  155. o(b, {
  156. accept: l.accept,
  157. "list-type": l.listType,
  158. "file-list": n.value,
  159. disabled: l.readonly,
  160. maxCount: l.maxFileCount,
  161. multiple: l.maxFileCount > 1,
  162. "before-upload": T,
  163. "custom-request": R,
  164. onChange: $,
  165. onPreview: F,
  166. onDownload: B,
  167. showUploadList: l.showUploadList
  168. }, {
  169. default: C(() => [
  170. l.isAdd && l.listType === "picture" && n.value.length <= l.maxFileCount ? (s(), u("div", J, [
  171. l.label ? (s(), u("div", {
  172. key: 0,
  173. class: "label",
  174. onClick: t[1] || (t[1] = L(() => {
  175. }, ["stop"]))
  176. }, r(l.label), 1)) : p("", !0),
  177. o(d, null, {
  178. default: C(() => [
  179. o(i),
  180. D(" " + r(e.$l("点击上传")), 1)
  181. ]),
  182. _: 1
  183. })
  184. ])) : p("", !0),
  185. l.isAdd && l.listType === "picture-card" && n.value.length <= l.maxFileCount ? (s(), u("span", Q, [
  186. o(i),
  187. m("div", null, r(e.$l("点击上传")), 1)
  188. ])) : p("", !0)
  189. ]),
  190. _: 1
  191. }, 8, ["accept", "list-type", "file-list", "disabled", "maxCount", "multiple", "showUploadList"]),
  192. o(P, {
  193. value: f.value,
  194. "onUpdate:value": t[4] || (t[4] = (g) => f.value = g),
  195. title: h.value,
  196. onHandCancel: N,
  197. width: "800px"
  198. }, {
  199. default: C(() => [
  200. m("div", Y, [
  201. m("div", {
  202. class: "prev",
  203. onClick: t[2] || (t[2] = (g) => x(-1))
  204. }, [
  205. o(A)
  206. ]),
  207. m("img", {
  208. alt: "example",
  209. class: "view",
  210. src: y.value
  211. }, null, 8, Z),
  212. m("div", {
  213. class: "next",
  214. onClick: t[3] || (t[3] = (g) => x(1))
  215. }, [
  216. o(q)
  217. ])
  218. ])
  219. ]),
  220. _: 1
  221. }, 8, ["value", "title"])
  222. ]);
  223. };
  224. }
  225. }, ae = /* @__PURE__ */ E(_, [["__scopeId", "data-v-bc90ac97"]]);
  226. export {
  227. ae as default
  228. };