index.es.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. /*!
  2. * FormCreate 低代码表单渲染器
  3. * @form-create/component-elm-frame 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 e=document.createElement("style");e.appendChild(document.createTextNode("._fc-frame .fc-files img{width:100%;height:100%;display:inline-block;vertical-align:top}._fc-frame .fc-upload-btn{border:1px dashed #c0ccda;cursor:pointer}._fc-frame .fc-upload-cover{opacity:0;position:absolute;inset:0;background:#0009;-webkit-transition:opacity .3s;-o-transition:opacity .3s;transition:opacity .3s}._fc-frame .fc-upload-cover i{color:#fff;font-size:20px;cursor:pointer;margin:0 2px}._fc-frame .fc-files:hover .fc-upload-cover{opacity:1}._fc-frame .el-upload{display:block}._fc-frame .fc-upload-btn,.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(e)}}catch(i){console.error("vite-plugin-css-injected-by-js",i)}})();
  10. var k = Object.defineProperty, g = Object.defineProperties;
  11. var v = Object.getOwnPropertyDescriptors;
  12. var u = Object.getOwnPropertySymbols;
  13. var $ = Object.prototype.hasOwnProperty, I = Object.prototype.propertyIsEnumerable;
  14. var f = (e, t, i) => t in e ? k(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i, d = (e, t) => {
  15. for (var i in t || (t = {}))
  16. $.call(t, i) && f(e, i, t[i]);
  17. if (u)
  18. for (var i of u(t))
  19. I.call(t, i) && f(e, i, t[i]);
  20. return e;
  21. }, p = (e, t) => g(e, v(t));
  22. function w(e) {
  23. return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
  24. }
  25. function c() {
  26. return c = Object.assign ? Object.assign.bind() : function(e) {
  27. 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]);
  28. return e;
  29. }, c.apply(this, arguments);
  30. }
  31. var B = ["attrs", "props", "domProps"], O = ["class", "style", "directives"], L = ["on", "nativeOn"], S = function(e) {
  32. return e.reduce(function(t, i) {
  33. for (var s in i) if (!t[s]) t[s] = i[s];
  34. else if (B.indexOf(s) !== -1) t[s] = c({}, t[s], i[s]);
  35. else if (O.indexOf(s) !== -1) {
  36. var o = t[s] instanceof Array ? t[s] : [t[s]], r = i[s] instanceof Array ? i[s] : [i[s]];
  37. t[s] = [].concat(o, r);
  38. } else if (L.indexOf(s) !== -1)
  39. for (var n in i[s]) if (t[s][n]) {
  40. var h = t[s][n] instanceof Array ? t[s][n] : [t[s][n]], y = i[s][n] instanceof Array ? i[s][n] : [i[s][n]];
  41. t[s][n] = [].concat(h, y);
  42. } else t[s][n] = i[s][n];
  43. else if (s === "hook") for (var l in i[s]) t[s][l] = t[s][l] ? E(t[s][l], i[s][l]) : i[s][l];
  44. else t[s] = i[s];
  45. return t;
  46. }, {});
  47. }, E = function(e, t) {
  48. return function() {
  49. e && e.apply(this, arguments), t && t.apply(this, arguments);
  50. };
  51. }, M = S;
  52. const a = /* @__PURE__ */ w(M);
  53. function m(e) {
  54. return Array.isArray(e) ? e : [null, void 0, ""].indexOf(e) > -1 ? [] : [e];
  55. }
  56. const x = "fcFrame", C = {
  57. name: x,
  58. props: {
  59. formCreateInject: {
  60. type: Object,
  61. required: !0
  62. },
  63. type: {
  64. type: String,
  65. default: "input"
  66. },
  67. field: String,
  68. helper: {
  69. type: Boolean,
  70. default: !0
  71. },
  72. disabled: {
  73. type: Boolean,
  74. default: !1
  75. },
  76. src: {
  77. type: String,
  78. required: !0
  79. },
  80. icon: {
  81. type: String,
  82. default: "el-icon-upload2"
  83. },
  84. width: {
  85. type: String,
  86. default: "500px"
  87. },
  88. height: {
  89. type: String,
  90. default: "370px"
  91. },
  92. maxLength: {
  93. type: Number,
  94. default: 0
  95. },
  96. okBtnText: {
  97. type: String,
  98. default: "确定"
  99. },
  100. closeBtnText: {
  101. type: String,
  102. default: "关闭"
  103. },
  104. modalTitle: String,
  105. handleIcon: {
  106. type: [String, Boolean],
  107. default: void 0
  108. },
  109. title: String,
  110. allowRemove: {
  111. type: Boolean,
  112. default: !0
  113. },
  114. onOpen: {
  115. type: Function,
  116. default: () => {
  117. }
  118. },
  119. onOk: {
  120. type: Function,
  121. default: () => {
  122. }
  123. },
  124. onCancel: {
  125. type: Function,
  126. default: () => {
  127. }
  128. },
  129. onLoad: {
  130. type: Function,
  131. default: () => {
  132. }
  133. },
  134. onBeforeRemove: {
  135. type: Function,
  136. default: () => {
  137. }
  138. },
  139. onRemove: {
  140. type: Function,
  141. default: () => {
  142. }
  143. },
  144. onHandle: {
  145. type: Function,
  146. default(e) {
  147. this.previewImage = this.getSrc(e), this.previewVisible = !0;
  148. }
  149. },
  150. modal: {
  151. type: Object,
  152. default: () => ({})
  153. },
  154. srcKey: {
  155. type: [String, Number]
  156. },
  157. value: [Array, String, Number, Object],
  158. previewMask: void 0,
  159. footer: {
  160. type: Boolean,
  161. default: !0
  162. },
  163. reload: {
  164. type: Boolean,
  165. default: !0
  166. },
  167. closeBtn: {
  168. type: Boolean,
  169. default: !0
  170. },
  171. okBtn: {
  172. type: Boolean,
  173. default: !0
  174. }
  175. },
  176. data() {
  177. return {
  178. fileList: m(this.value),
  179. previewVisible: !1,
  180. frameVisible: !1,
  181. previewImage: ""
  182. };
  183. },
  184. watch: {
  185. value(e) {
  186. this.fileList = m(e);
  187. },
  188. fileList(e) {
  189. const t = this.maxLength === 1 ? e[0] || "" : e;
  190. this.$emit("input", t), this.$emit("change", t);
  191. },
  192. src(e) {
  193. this.modalVm && (this.modalVm.src = e);
  194. }
  195. },
  196. methods: {
  197. key(e) {
  198. return e;
  199. },
  200. closeModel(e) {
  201. this.$emit(e ? "$close" : "$ok"), this.reload && (this.$off("$ok"), this.$off("$close")), this.frameVisible = !1;
  202. },
  203. handleCancel() {
  204. this.previewVisible = !1;
  205. },
  206. showModel() {
  207. this.disabled || this.onOpen() === !1 || (this.frameVisible = !0);
  208. },
  209. makeInput() {
  210. const e = this.$createElement, t = {
  211. type: "text",
  212. value: this.fileList.map((i) => this.getSrc(i)).toString(),
  213. readonly: !0
  214. };
  215. return e("ElInput", a([{}, {
  216. props: t
  217. }, {
  218. key: this.key("input")
  219. }]), [this.fileList.length ? e("i", {
  220. slot: "suffix",
  221. class: "el-input__icon el-icon-circle-close",
  222. on: {
  223. click: () => this.fileList = []
  224. }
  225. }) : null, e("ElButton", a([{
  226. attrs: {
  227. icon: this.icon
  228. }
  229. }, {
  230. on: {
  231. click: () => this.showModel()
  232. }
  233. }, {
  234. slot: "append"
  235. }]))]);
  236. },
  237. makeGroup(e) {
  238. const t = this.$createElement;
  239. return (!this.maxLength || this.fileList.length < this.maxLength) && e.push(this.makeBtn()), t("div", {
  240. key: this.key("group")
  241. }, [...e]);
  242. },
  243. makeItem(e, t) {
  244. const i = this.$createElement;
  245. return i("div", {
  246. class: "fc-files",
  247. key: this.key("file" + e)
  248. }, [...t]);
  249. },
  250. valid(e) {
  251. const t = this.formCreateInject.field || this.field;
  252. if (t && e !== t)
  253. throw new Error("[frame]无效的字段值");
  254. },
  255. makeIcons(e, t) {
  256. const i = this.$createElement;
  257. if (this.handleIcon !== !1 || this.allowRemove === !0) {
  258. const s = [];
  259. return (this.type !== "file" && this.handleIcon !== !1 || this.type === "file" && this.handleIcon) && s.push(this.makeHandleIcon(e, t)), this.allowRemove && s.push(this.makeRemoveIcon(e, t)), i("div", {
  260. class: "fc-upload-cover",
  261. key: this.key("uc")
  262. }, [s]);
  263. }
  264. },
  265. makeHandleIcon(e, t) {
  266. const i = this.$createElement;
  267. return i("i", {
  268. class: this.handleIcon === !0 || this.handleIcon === void 0 ? "el-icon-view" : this.handleIcon,
  269. on: {
  270. click: () => this.handleClick(e)
  271. },
  272. key: this.key("hi" + t)
  273. });
  274. },
  275. makeRemoveIcon(e, t) {
  276. const i = this.$createElement;
  277. return i("i", {
  278. class: "el-icon-delete",
  279. on: {
  280. click: () => this.handleRemove(e)
  281. },
  282. key: this.key("ri" + t)
  283. });
  284. },
  285. makeFiles() {
  286. const e = this.$createElement;
  287. return this.makeGroup(this.fileList.map((t, i) => this.makeItem(i, [e("i", {
  288. class: "el-icon-tickets",
  289. on: {
  290. click: () => this.handleClick(t)
  291. }
  292. }), this.makeIcons(t, i)])));
  293. },
  294. makeImages() {
  295. const e = this.$createElement;
  296. return this.makeGroup(this.fileList.map((t, i) => this.makeItem(i, [e("img", {
  297. attrs: {
  298. src: this.getSrc(t)
  299. }
  300. }), this.makeIcons(t, i)])));
  301. },
  302. makeBtn() {
  303. const e = this.$createElement;
  304. return e("div", {
  305. class: "fc-upload-btn",
  306. on: {
  307. click: () => this.showModel()
  308. },
  309. key: this.key("btn")
  310. }, [e("i", {
  311. class: this.icon
  312. })]);
  313. },
  314. handleClick(e) {
  315. return this.onHandle(e);
  316. },
  317. handleRemove(e) {
  318. this.disabled || this.onBeforeRemove(e) !== !1 && (this.fileList.splice(this.fileList.indexOf(e), 1), this.onRemove(e));
  319. },
  320. getSrc(e) {
  321. return this.srcKey ? e[this.srcKey] : e;
  322. },
  323. frameLoad(e) {
  324. this.onLoad(e);
  325. try {
  326. this.helper === !0 && (e.form_create_helper = {
  327. api: this.formCreateInject.api,
  328. close: (t) => {
  329. this.valid(t), this.closeModel();
  330. },
  331. set: (t, i) => {
  332. this.valid(t), this.disabled || this.$emit("input", i);
  333. },
  334. get: (t) => (this.valid(t), this.value),
  335. onOk: (t) => this.$on("$ok", t),
  336. onClose: (t) => this.$on("$close", t)
  337. });
  338. } catch (t) {
  339. console.log(t);
  340. }
  341. },
  342. makeFooter() {
  343. const e = this.$createElement, {
  344. okBtnText: t,
  345. closeBtnText: i,
  346. closeBtn: s,
  347. okBtn: o,
  348. footer: r
  349. } = this.$props;
  350. if (r)
  351. return e("div", {
  352. slot: "footer"
  353. }, [s ? e("ElButton", {
  354. on: {
  355. click: () => this.onCancel() !== !1 && (this.frameVisible = !1)
  356. }
  357. }, [i]) : null, o ? e("ElButton", {
  358. attrs: {
  359. type: "primary"
  360. },
  361. on: {
  362. click: () => this.onOk() !== !1 && this.closeModel()
  363. }
  364. }, [t]) : null]);
  365. }
  366. },
  367. render() {
  368. const e = arguments[0], t = this.type;
  369. let i;
  370. t === "input" ? i = this.makeInput() : t === "image" ? i = this.makeImages() : i = this.makeFiles();
  371. const {
  372. width: s = "30%",
  373. height: o,
  374. src: r,
  375. title: n,
  376. modalTitle: h
  377. } = this.$props;
  378. return this.$nextTick(() => {
  379. this.$refs.frame && this.frameLoad(this.$refs.frame.contentWindow || {});
  380. }), e("div", {
  381. class: "_fc-frame"
  382. }, [i, e("el-dialog", a([{}, {
  383. props: {
  384. appendToBody: !0,
  385. modal: this.previewMask,
  386. title: h,
  387. visible: this.previewVisible
  388. }
  389. }, {
  390. on: {
  391. close: this.handleCancel
  392. }
  393. }]), [e("img", {
  394. style: "width: 100%",
  395. attrs: {
  396. src: this.previewImage
  397. }
  398. })]), e("el-dialog", a([{}, {
  399. props: p(d({
  400. width: s,
  401. title: n,
  402. appendToBody: !0
  403. }, this.modal), {
  404. visible: this.frameVisible
  405. })
  406. }, {
  407. on: {
  408. close: () => this.closeModel(!0)
  409. }
  410. }]), [this.frameVisible || !this.reload ? e("iframe", {
  411. ref: "frame",
  412. attrs: {
  413. src: r,
  414. frameBorder: "0"
  415. },
  416. style: {
  417. height: o,
  418. border: "0 none",
  419. width: "100%"
  420. }
  421. }) : null, this.makeFooter()])]);
  422. },
  423. mounted() {
  424. this.$on("fc.closeModal", this.closeModal);
  425. }
  426. };
  427. export {
  428. C as default
  429. };