SFileUpload.js 6.7 KB

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