SDraggerUpload.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. import { ref as u, watch as O, resolveComponent as v, openBlock as w, createElementBlock as g, createElementVNode as a, toDisplayString as T, createCommentVNode as j, createVNode as c, withCtx as y, pushScopeId as q, popScopeId as z } from "vue";
  2. import { r as A, v as E } from "./index2.js";
  3. import { a as F, d as M, b as $ } from "./upload.js";
  4. import { U as P } from "./index6.js";
  5. import { M as H } from "./index7.js";
  6. const b = (n) => (q("data-v-6353f81e"), n = n(), z(), n), V = { class: "s-file-upload-common" }, G = { class: "head" }, K = {
  7. key: 0,
  8. class: "label"
  9. }, X = { class: "ant-upload-drag-icon" }, J = /* @__PURE__ */ b(() => /* @__PURE__ */ a("p", { class: "ant-upload-text" }, "点击或拖入文件到此处", -1)), Q = /* @__PURE__ */ b(() => /* @__PURE__ */ a("p", { class: "ant-upload-hint" }, "支持单个或批量上传", -1)), W = { class: "preview-content" }, Y = ["src"], Z = /* @__PURE__ */ Object.assign({
  10. inheritAttrs: !0
  11. }, {
  12. __name: "SDraggerUpload",
  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. setup(n) {
  89. const s = n, o = u([]), d = u(!1), p = u(""), r = u(""), l = u(0);
  90. O(() => s.list, (e) => {
  91. e && e.length && (o.value = e);
  92. }, { immediate: !0 });
  93. const _ = (e) => {
  94. console.log(s.sizeLimit);
  95. const t = e.size / 1024 / 1024 < s.sizeLimit;
  96. return t || E.warn({
  97. key: "only-you",
  98. message: "提醒",
  99. description: `文件不能大于${s.sizeLimit}MB!`
  100. }), t;
  101. }, x = ({ onSuccess: e, onError: t, file: i }) => {
  102. F(i, s.businessTableName, i.uid).then(() => {
  103. e();
  104. }).catch(() => {
  105. o.value.splice(o.value.length - 1, 1), t();
  106. });
  107. }, L = (e) => {
  108. o.value = e.fileList;
  109. };
  110. function C(e) {
  111. console.log(e);
  112. }
  113. const U = (e) => {
  114. l.value = o.value.findIndex((t) => t.uid === e.uid), d.value = !0, r.value = e.name || "预览", p.value = e.url || e.thumbUrl;
  115. }, R = (e) => {
  116. const t = document.createElement("a");
  117. t.href = M(e.uid), t.download = "test", t.click();
  118. }, S = () => {
  119. d.value = !1;
  120. }, h = (e) => {
  121. var t;
  122. l.value = l.value + e < 0 ? 0 : l.value + e > o.value.length - 1 ? o.value.length - 1 : l.value + e, (t = o.value[l.value]) != null && t.thumbUrl ? (r.value = o.value[l.value].name || "预览", p.value = o.value[l.value].thumbUrl) : D(o.value[l.value]);
  123. }, D = (e) => {
  124. if (e.type.includes("office")) {
  125. const t = window.open("", "");
  126. t.location = $(e.uid + "/" + e.name);
  127. } else if (e.type.includes("text"))
  128. k(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: "不支持此文件类型"
  135. });
  136. }, k = (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" }), m = window.URL.createObjectURL(i), f = window.open("", "");
  140. f.location = m;
  141. }, t.send();
  142. };
  143. return (e, t) => {
  144. const i = v("inbox-outlined"), m = P, f = v("LeftOutlined"), B = v("RightOutlined"), I = H;
  145. return w(), g("div", V, [
  146. a("div", G, [
  147. n.label ? (w(), g("div", K, T(n.label), 1)) : j("", !0)
  148. ]),
  149. c(m, {
  150. accept: n.accept,
  151. "list-type": "picture",
  152. "file-list": o.value,
  153. disabled: n.readonly,
  154. maxCount: n.maxFileCount,
  155. multiple: n.maxFileCount > 1,
  156. "before-upload": _,
  157. "custom-request": x,
  158. onDrop: C,
  159. onChange: L,
  160. onPreview: U,
  161. onDownload: R,
  162. showUploadList: n.showUploadList
  163. }, {
  164. default: y(() => [
  165. a("p", X, [
  166. c(i)
  167. ]),
  168. J,
  169. Q
  170. ]),
  171. _: 1
  172. }, 8, ["accept", "file-list", "disabled", "maxCount", "multiple", "showUploadList"]),
  173. c(I, {
  174. open: d.value,
  175. title: r.value,
  176. footer: null,
  177. onCancel: S,
  178. width: "800px"
  179. }, {
  180. default: y(() => [
  181. a("div", W, [
  182. a("div", {
  183. class: "prev",
  184. onClick: t[0] || (t[0] = (N) => h(-1))
  185. }, [
  186. c(f)
  187. ]),
  188. a("img", {
  189. alt: "example",
  190. class: "view",
  191. src: p.value
  192. }, null, 8, Y),
  193. a("div", {
  194. class: "next",
  195. onClick: t[1] || (t[1] = (N) => h(1))
  196. }, [
  197. c(B)
  198. ])
  199. ])
  200. ]),
  201. _: 1
  202. }, 8, ["open", "title"])
  203. ]);
  204. };
  205. }
  206. }), ae = /* @__PURE__ */ A(Z, [["__scopeId", "data-v-6353f81e"]]);
  207. export {
  208. ae as default
  209. };