index.es.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*!
  2. * FormCreate 低代码表单渲染器
  3. * @form-create/component-elm-upload v2.6.3
  4. * (c) 2018-2024 xaboy
  5. * Github https://github.com/xaboy/form-create
  6. * Site https://form-create.com/
  7. * Released under the MIT License.
  8. */
  9. (function(){"use strict";try{if(typeof document!="undefined"){var o=document.createElement("style");o.appendChild(document.createTextNode("._fc-upload .fc-files img{width:100%;height:100%;display:inline-block;vertical-align:top}._fc-upload .fc-upload-btn{border:1px dashed #c0ccda;cursor:pointer}._fc-upload .fc-upload-cover{opacity:0;position:absolute;inset:0;background:#0009;-webkit-transition:opacity .3s;-o-transition:opacity .3s;transition:opacity .3s}._fc-upload .fc-upload-cover i{color:#fff;font-size:20px;cursor:pointer;margin:0 2px}._fc-upload .fc-files:hover .fc-upload-cover{opacity:1}._fc-upload .el-upload{display:block}._fc-upload .fc-upload-btn,._fc-upload .fc-files{display:inline-block;width:58px;height:58px;text-align:center;line-height:58px;border:1px solid #c0ccda;border-radius:4px;overflow:hidden;background:#fff;position:relative;-webkit-box-shadow:2px 2px 5px rgba(0,0,0,.1);box-shadow:2px 2px 5px #0000001a;margin-right:4px;-webkit-box-sizing:border-box;box-sizing:border-box}")),document.head.appendChild(o)}}catch(i){console.error("vite-plugin-css-injected-by-js",i)}})();
  10. function f(e) {
  11. return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
  12. }
  13. function n() {
  14. return n = Object.assign ? Object.assign.bind() : function(e) {
  15. for (var t, i = 1; i < arguments.length; i++) for (var s in t = arguments[i], t) Object.prototype.hasOwnProperty.call(t, s) && (e[s] = t[s]);
  16. return e;
  17. }, n.apply(this, arguments);
  18. }
  19. var m = ["attrs", "props", "domProps"], y = ["class", "style", "directives"], g = ["on", "nativeOn"], k = function(e) {
  20. return e.reduce(function(t, i) {
  21. for (var s in i) if (!t[s]) t[s] = i[s];
  22. else if (m.indexOf(s) !== -1) t[s] = n({}, t[s], i[s]);
  23. else if (y.indexOf(s) !== -1) {
  24. var h = t[s] instanceof Array ? t[s] : [t[s]], u = i[s] instanceof Array ? i[s] : [i[s]];
  25. t[s] = [].concat(h, u);
  26. } else if (g.indexOf(s) !== -1)
  27. for (var r in i[s]) if (t[s][r]) {
  28. var d = t[s][r] instanceof Array ? t[s][r] : [t[s][r]], c = i[s][r] instanceof Array ? i[s][r] : [i[s][r]];
  29. t[s][r] = [].concat(d, c);
  30. } else t[s][r] = i[s][r];
  31. else if (s === "hook") for (var o in i[s]) t[s][o] = t[s][o] ? v(t[s][o], i[s][o]) : i[s][o];
  32. else t[s] = i[s];
  33. return t;
  34. }, {});
  35. }, v = function(e, t) {
  36. return function() {
  37. e && e.apply(this, arguments), t && t.apply(this, arguments);
  38. };
  39. }, I = k;
  40. const l = /* @__PURE__ */ f(I);
  41. function a(e) {
  42. return Array.isArray(e) ? e : [null, void 0, ""].indexOf(e) > -1 ? [] : [e];
  43. }
  44. function w(e, t) {
  45. return Object.keys(e).reduce((i, s) => ((!t || t.indexOf(s) === -1) && i.push(e[s]), i), []);
  46. }
  47. function p(e, t) {
  48. return {
  49. url: e,
  50. name: $(e),
  51. uid: t
  52. };
  53. }
  54. function $(e) {
  55. return ("" + e).split("/").pop();
  56. }
  57. const F = "fcUpload", j = {
  58. name: F,
  59. props: {
  60. formCreateInject: {
  61. type: Object,
  62. required: !0
  63. },
  64. onHandle: {
  65. type: Function,
  66. default(e) {
  67. this.previewImage = e.url, this.previewVisible = !0;
  68. }
  69. },
  70. uploadType: {
  71. type: String,
  72. default: "file"
  73. },
  74. limit: {
  75. type: Number,
  76. default: 0
  77. },
  78. allowRemove: {
  79. type: Boolean,
  80. default: !0
  81. },
  82. previewMask: void 0,
  83. modalTitle: String,
  84. handleIcon: {
  85. type: [String, Boolean],
  86. default: () => {
  87. }
  88. },
  89. value: [Array, String]
  90. },
  91. data() {
  92. return {
  93. uploadList: [],
  94. previewVisible: !1,
  95. previewImage: "",
  96. cacheFiles: []
  97. };
  98. },
  99. created() {
  100. this.formCreateInject.prop.props.showFileList === void 0 && (this.formCreateInject.prop.props.showFileList = !1), this.formCreateInject.prop.props.fileList = a(this.value).map(p);
  101. },
  102. watch: {
  103. value(e) {
  104. this.$refs.upload.uploadFiles.every((t) => !t.status || t.status === "success") && (this.$refs.upload.uploadFiles = a(e).map(p), this.uploadList = this.$refs.upload.uploadFiles);
  105. },
  106. limit(e, t) {
  107. (t === 1 || e === 1) && this.update();
  108. }
  109. },
  110. methods: {
  111. key(e) {
  112. return e;
  113. },
  114. isDisabled() {
  115. return this.formCreateInject.prop.props.disabled === !0;
  116. },
  117. onRemove(e) {
  118. this.isDisabled() || this.$refs.upload.handleRemove(e);
  119. },
  120. handleClick(e) {
  121. this.onHandle(e);
  122. },
  123. makeItem(e, t) {
  124. const i = this.$createElement;
  125. return this.uploadType === "image" ? i("img", {
  126. attrs: {
  127. src: e.url
  128. },
  129. key: this.key("img" + t)
  130. }) : i("i", {
  131. class: "el-icon-tickets",
  132. key: this.key("i" + t)
  133. });
  134. },
  135. makeRemoveIcon(e, t) {
  136. const i = this.$createElement;
  137. return i("i", {
  138. class: "el-icon-delete",
  139. on: {
  140. click: () => this.onRemove(e)
  141. },
  142. key: this.key("ri" + t)
  143. });
  144. },
  145. makeHandleIcon(e, t) {
  146. const i = this.$createElement;
  147. return i("i", {
  148. class: this.handleIcon === !0 || this.handleIcon === void 0 ? "el-icon-view" : this.handleIcon,
  149. on: {
  150. click: () => this.handleClick(e)
  151. },
  152. key: this.key("hi" + t)
  153. });
  154. },
  155. makeProgress(e, t) {
  156. const i = this.$createElement;
  157. return i("ElProgress", l([{}, {
  158. props: {
  159. percentage: e.percentage,
  160. type: "circle",
  161. width: 52
  162. }
  163. }, {
  164. style: "margin-top:2px;",
  165. key: this.key("pg" + t)
  166. }]));
  167. },
  168. makeIcons(e, t) {
  169. const i = this.$createElement, s = [];
  170. if (this.allowRemove || this.handleIcon !== !1)
  171. return (this.uploadType !== "file" && this.handleIcon !== !1 || this.uploadType === "file" && this.handleIcon) && s.push(this.makeHandleIcon(e, t)), this.allowRemove && s.push(this.makeRemoveIcon(e, t)), i("div", {
  172. class: "fc-upload-cover"
  173. }, [s]);
  174. },
  175. makeFiles() {
  176. const e = this.$createElement;
  177. return this.uploadList.map((t, i) => this.$scopedSlots.fileList ? this.$scopedSlots.fileList({
  178. file: t,
  179. index: i,
  180. vm: this
  181. }) : e("div", {
  182. key: this.key(i),
  183. class: "fc-files"
  184. }, [t.percentage !== void 0 && t.status !== "success" ? this.makeProgress(t, i) : [this.makeItem(t, i), this.makeIcons(t, i)]]));
  185. },
  186. makeUpload() {
  187. const e = this.$createElement, t = !this.limit || this.limit > this.uploadList.length;
  188. return e("ElUpload", l([{}, this.formCreateInject.prop, {}, {
  189. style: {
  190. display: "inline-block"
  191. },
  192. key: this.key("upload"),
  193. ref: "upload"
  194. }]), [t ? e("template", {
  195. slot: "default"
  196. }, [this.$slots.default || e("div", {
  197. class: "fc-upload-btn"
  198. }, [e("i", {
  199. class: "el-icon-upload2"
  200. })])]) : null, w(this.$slots, ["default"])]);
  201. },
  202. update() {
  203. let e = this.$refs.upload.uploadFiles.map((t) => t.url).filter((t) => t !== void 0 && t.indexOf("blob:") !== 0);
  204. JSON.stringify(e) !== JSON.stringify(this.cacheFiles) && (this.cacheFiles = [...e], this.$emit("input", this.limit === 1 ? e[0] || "" : e));
  205. },
  206. handleCancel() {
  207. this.previewVisible = !1;
  208. }
  209. },
  210. render() {
  211. const e = arguments[0];
  212. return this.$refs.upload && (this.formCreateInject.prop.props.showFileList === void 0 && (this.formCreateInject.prop.props.showFileList = this.$refs.upload.showFileList), this.formCreateInject.prop.props.fileList = this.$refs.upload.fileList), e("div", {
  213. class: "_fc-upload"
  214. }, [[this.formCreateInject.prop.props.showFileList ? [] : this.makeFiles(), this.makeUpload()], e("el-dialog", l([{}, {
  215. props: {
  216. appendToBody: !0,
  217. modal: this.previewMask,
  218. title: this.modalTitle,
  219. visible: this.previewVisible
  220. }
  221. }, {
  222. on: {
  223. close: this.handleCancel
  224. }
  225. }]), [e("img", {
  226. attrs: {
  227. alt: "example",
  228. src: this.previewImage
  229. },
  230. style: "width: 100%"
  231. })])]);
  232. },
  233. mounted() {
  234. this.uploadList = this.$refs.upload.uploadFiles, this.$watch(() => this.$refs.upload.uploadFiles, () => {
  235. this.update();
  236. }, {
  237. deep: !0
  238. }), this.$emit("fc.el", this.$refs.upload);
  239. }
  240. };
  241. export {
  242. j as default
  243. };