SDraggerUpload.js 6.2 KB

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