SCopperUpload.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. var h = (l, f, n) => new Promise((s, t) => {
  2. var p = (a) => {
  3. try {
  4. i(n.next(a));
  5. } catch (r) {
  6. t(r);
  7. }
  8. }, u = (a) => {
  9. try {
  10. i(n.throw(a));
  11. } catch (r) {
  12. t(r);
  13. }
  14. }, i = (a) => a.done ? s(a.value) : Promise.resolve(a.value).then(p, u);
  15. i((n = n.apply(l, f)).next());
  16. });
  17. import { ref as c, reactive as B, watch as y, resolveComponent as S, openBlock as g, createElementBlock as C, createElementVNode as m, toDisplayString as b, createCommentVNode as U, createVNode as v, withCtx as O } from "vue";
  18. import { l as $, W as j } from "./index2.js";
  19. import { d as z } from "./upload.js";
  20. import D from "./CropperModal.js";
  21. import { _ as M } from "./index4.js";
  22. const R = { class: "s-file-upload-common" }, T = { class: "head" }, E = {
  23. key: 0,
  24. class: "label"
  25. }, P = {
  26. __name: "SCopperUpload",
  27. props: {
  28. /**
  29. * 文件列表
  30. * @list
  31. */
  32. list: {
  33. type: Array,
  34. default: () => []
  35. },
  36. /**
  37. * 标题
  38. * @label
  39. */
  40. label: {
  41. type: String,
  42. default: ""
  43. },
  44. /**
  45. * 只读
  46. * @readonly
  47. */
  48. readonly: {
  49. type: Boolean,
  50. default: !1
  51. },
  52. /**
  53. * 是否显示删除
  54. * @delete
  55. */
  56. showRemoveIcon: {
  57. type: Boolean,
  58. default: !0
  59. },
  60. /**
  61. * 是否显示新增
  62. * @add
  63. */
  64. add: {
  65. type: Boolean,
  66. default: !1
  67. },
  68. maxFileCount: {
  69. type: Number,
  70. default: 3
  71. },
  72. sizeLimit: {
  73. type: Number,
  74. default: 50
  75. },
  76. options: {
  77. type: Object,
  78. default: function() {
  79. return {
  80. autoCrop: !0,
  81. // 是否默认生成截图框
  82. autoCropWidth: 180,
  83. // 默认生成截图框宽度
  84. autoCropHeight: 180,
  85. // 默认生成截图框高度
  86. fixedBox: !1,
  87. // 是否固定截图框大小 不允许改变
  88. previewsCircle: !1,
  89. // 预览图是否是原圆形
  90. businessTableName: "sys_user",
  91. title: "",
  92. invariantId: ""
  93. };
  94. }
  95. },
  96. businessTableName: {
  97. type: String,
  98. default: void 0
  99. },
  100. businessKey: {
  101. type: String,
  102. default: void 0
  103. }
  104. },
  105. emits: ["handChange"],
  106. setup(l, { emit: f }) {
  107. const n = f, s = l, t = c([]), p = c(!1), u = B({}), i = c(""), a = c();
  108. y(
  109. () => s.list,
  110. (e) => {
  111. e && e.length && (t.value = e);
  112. },
  113. { immediate: !0 }
  114. ), y(
  115. () => s.options,
  116. (e) => {
  117. u.value = e;
  118. },
  119. { immediate: !0 }
  120. );
  121. const r = (e) => {
  122. const o = e.size / 1024 / 1024 < s.sizeLimit;
  123. return o || j.warn({
  124. key: "only-you",
  125. message: window.$l("提醒"),
  126. description: `${window.$l("文件不能大于")}${s.sizeLimit}MB!`
  127. }), o;
  128. }, _ = (e) => h(this, null, function* () {
  129. if (e.file.status === "removed") {
  130. n("handChange", t.value);
  131. return;
  132. }
  133. let o = setTimeout(() => {
  134. u.value.invariantId = i.value;
  135. const d = Object.assign({}, u.value, {
  136. img: e.file.thumbUrl,
  137. file: e.file
  138. });
  139. d && a.value.edit(d), clearTimeout(o);
  140. }, 500);
  141. }), w = ({ file: e }) => {
  142. i.value = e.uid;
  143. }, I = (e) => {
  144. const o = document.createElement("a");
  145. o.href = z(e.uid), o.download = "test", o.click();
  146. }, N = () => {
  147. p.value = !1;
  148. for (let e = t.value.length - 1; e >= 0; e--)
  149. t.value[e].uid === i.value && t.value[e].status != "done" && t.value.splice(e, 1);
  150. }, k = (e) => {
  151. p.value = !1;
  152. const o = t.value.findIndex((d) => d.uid === e.invariantId);
  153. o > -1 ? t.value.splice(o, 1, e) : t.value.push(e), n("handChange", t.value);
  154. };
  155. return (e, o) => {
  156. const d = S("PlusOutlined"), x = M;
  157. return g(), C("div", R, [
  158. m("div", T, [
  159. l.label ? (g(), C("div", E, b(l.label), 1)) : U("", !0)
  160. ]),
  161. v(x, {
  162. "list-type": "picture-card",
  163. accept: ".jpg, .png, .jpeg, .PNG, .gif",
  164. "before-upload": r,
  165. "file-list": t.value,
  166. "onUpdate:fileList": o[0] || (o[0] = (L) => t.value = L),
  167. "custom-request": w,
  168. onChange: _,
  169. onDownload: I,
  170. disabled: l.readonly,
  171. showUploadList: {
  172. showRemoveIcon: l.showRemoveIcon,
  173. showDownloadIcon: !1
  174. }
  175. }, {
  176. default: O(() => [
  177. m("span", null, [
  178. v(d),
  179. m("div", null, b(e.$l("图片上传")), 1)
  180. ])
  181. ]),
  182. _: 1
  183. }, 8, ["file-list", "disabled", "showUploadList"]),
  184. v(D, {
  185. ref_key: "cropperModal",
  186. ref: a,
  187. onCropperNo: N,
  188. onCropperOk: k
  189. }, null, 512)
  190. ]);
  191. };
  192. }
  193. }, K = /* @__PURE__ */ $(P, [["__scopeId", "data-v-110ca245"]]);
  194. export {
  195. K as default
  196. };