UNPKG

@form-create/element-ui

Version:

Element UI版本低代码表单|FormCreate 是一个可以通过 JSON 生成具有动态渲染、数据收集、验证和提交功能的低代码表单生成组件。支持6个UI框架,适配移动端,并且支持生成任何 Vue 组件。内置20种常用表单组件和自定义组件,再复杂的表单都可以轻松搞定。

1,796 lines (1,795 loc) 123 kB
/*! * FormCreate 低代码表单渲染器 * @form-create/element-ui v2.6.3 * (c) 2018-2024 xaboy * Github https://github.com/xaboy/form-create * Site https://form-create.com/ * Released under the MIT License. */ (function(){"use strict";try{if(typeof document!="undefined"){var o=document.createElement("style");o.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}._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}._fc-group{display:flex;min-height:42px;justify-content:center;flex-direction:column}._fc-group-disabled ._fc-group-btn,._fc-group-disabled ._fc-group-add{cursor:not-allowed}._fc-group-handle{display:flex;flex-direction:row;position:absolute;bottom:-15px;right:30px;border-radius:15px;border:1px dashed #d9d9d9;padding:3px 8px;background-color:#fff}._fc-group-btn{cursor:pointer}._fc-group-idx{position:absolute;bottom:-15px;left:10px;width:30px;height:30px;display:flex;align-items:center;justify-content:center;background:#eee;border-radius:15px;font-weight:700}._fc-group-handle ._fc-group-btn+._fc-group-btn{margin-left:7px}._fc-group-container{position:relative;display:flex;flex-direction:column;border:1px dashed #d9d9d9;padding:20px 20px 25px;margin:5px 5px 25px;border-radius:5px}._fc-group-arrow{position:relative;width:20px;height:20px}._fc-group-arrow:before{content:"";position:absolute;top:8px;left:5px;width:9px;height:9px;border-left:2px solid #999;border-top:2px solid #999}._fc-group-arrow:before{transform:rotate(45deg)}._fc-group-arrow._fc-group-down{transform:rotate(180deg)}._fc-group-plus-minus{width:20px;height:20px;position:relative;cursor:pointer}._fc-group-plus-minus:before,._fc-group-plus-minus:after{content:"";position:absolute;top:50%;left:50%;width:60%;height:2px;background-color:#409eff;transform:translate(-50%,-50%)}._fc-group-plus-minus:before{transform:translate(-50%,-50%) rotate(90deg)}._fc-group-plus-minus._fc-group-minus:before{display:none}._fc-group-plus-minus._fc-group-minus:after{background-color:#f56c6c}._fc-group-add{cursor:pointer;width:25px;height:25px;border:1px solid rgb(64 158 255 / 50%);border-radius:15px}._fc-group-add._fc-group-plus-minus:before,._fc-group-add._fc-group-plus-minus:after{width:50%}.form-create .form-create .el-form-item{margin-bottom:22px}.form-create .form-create .el-form-item .el-form-item{margin-bottom:0}')),document.head.appendChild(o)}}catch(r){console.error("vite-plugin-css-injected-by-js",r)}})(); var pt = Object.defineProperty, mt = Object.defineProperties; var yt = Object.getOwnPropertyDescriptors; var Ee = Object.getOwnPropertySymbols; var gt = Object.prototype.hasOwnProperty, $t = Object.prototype.propertyIsEnumerable; var Se = (t, e, r) => e in t ? pt(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, y = (t, e) => { for (var r in e || (e = {})) gt.call(e, r) && Se(t, r, e[r]); if (Ee) for (var r of Ee(e)) $t.call(e, r) && Se(t, r, e[r]); return t; }, N = (t, e) => mt(t, yt(e)); import T from "vue"; function vt(t) { return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t; } function ae() { return ae = Object.assign ? Object.assign.bind() : function(t) { for (var e, r = 1; r < arguments.length; r++) for (var i in e = arguments[r], e) Object.prototype.hasOwnProperty.call(e, i) && (t[i] = e[i]); return t; }, ae.apply(this, arguments); } var bt = ["attrs", "props", "domProps"], Ct = ["class", "style", "directives"], _t = ["on", "nativeOn"], Ot = function(t) { return t.reduce(function(e, r) { for (var i in r) if (!e[i]) e[i] = r[i]; else if (bt.indexOf(i) !== -1) e[i] = ae({}, e[i], r[i]); else if (Ct.indexOf(i) !== -1) { var s = e[i] instanceof Array ? e[i] : [e[i]], n = r[i] instanceof Array ? r[i] : [r[i]]; e[i] = [].concat(s, n); } else if (_t.indexOf(i) !== -1) for (var o in r[i]) if (e[i][o]) { var a = e[i][o] instanceof Array ? e[i][o] : [e[i][o]], u = r[i][o] instanceof Array ? r[i][o] : [r[i][o]]; e[i][o] = [].concat(a, u); } else e[i][o] = r[i][o]; else if (i === "hook") for (var l in r[i]) e[i][l] = e[i][l] ? kt(e[i][l], r[i][l]) : r[i][l]; else e[i] = r[i]; return e; }, {}); }, kt = function(t, e) { return function() { t && t.apply(this, arguments), e && e.apply(this, arguments); }; }, wt = Ot; const F = /* @__PURE__ */ vt(wt); function Y(t, e) { return Object.keys(t).reduce((r, i) => ((!e || e.indexOf(i) === -1) && r.push(t[i]), r), []); } const Ft = "fcCheckbox", Et = { name: Ft, props: { formCreateInject: { type: Object, required: !0 }, value: { type: Array, default: () => [] }, type: String }, watch: { "formCreateInject.options": { handler() { this.update(); }, deep: !0 }, value() { this.update(); } }, data() { return { trueValue: [] }; }, methods: { options() { const t = this.formCreateInject.options; return Array.isArray(t) ? t : []; }, onInput(t) { this.$emit("input", this.options().filter((e) => t.indexOf(e.label) !== -1).map((e) => e.value).filter((e) => e !== void 0)); }, update() { const t = Array.isArray(this.value) ? this.value : [this.value]; this.trueValue = this.options().filter((e) => t.indexOf(e.value) !== -1).map((e) => e.label); } }, created() { this.update(); }, render() { const t = arguments[0]; return t("ElCheckboxGroup", F([{}, this.formCreateInject.prop, {}, { props: { value: this.trueValue } }, { ref: "el", on: { input: this.onInput } }]), [this.options().map((e, r) => { const i = y({}, e), s = this.type === "button" ? "ElCheckboxButton" : "ElCheckbox"; return delete i.value, t(s, F([{}, { props: i }, { key: s + r + "-" + e.value }])); }), Y(this.$slots)]); }, mounted() { this.$emit("fc.el", this.$refs.el); } }; function j(t) { return Array.isArray(t) ? t : [null, void 0, ""].indexOf(t) > -1 ? [] : [t]; } const St = "fcFrame", Rt = { name: St, props: { formCreateInject: { type: Object, required: !0 }, type: { type: String, default: "input" }, field: String, helper: { type: Boolean, default: !0 }, disabled: { type: Boolean, default: !1 }, src: { type: String, required: !0 }, icon: { type: String, default: "el-icon-upload2" }, width: { type: String, default: "500px" }, height: { type: String, default: "370px" }, maxLength: { type: Number, default: 0 }, okBtnText: { type: String, default: "确定" }, closeBtnText: { type: String, default: "关闭" }, modalTitle: String, handleIcon: { type: [String, Boolean], default: void 0 }, title: String, allowRemove: { type: Boolean, default: !0 }, onOpen: { type: Function, default: () => { } }, onOk: { type: Function, default: () => { } }, onCancel: { type: Function, default: () => { } }, onLoad: { type: Function, default: () => { } }, onBeforeRemove: { type: Function, default: () => { } }, onRemove: { type: Function, default: () => { } }, onHandle: { type: Function, default(t) { this.previewImage = this.getSrc(t), this.previewVisible = !0; } }, modal: { type: Object, default: () => ({}) }, srcKey: { type: [String, Number] }, value: [Array, String, Number, Object], previewMask: void 0, footer: { type: Boolean, default: !0 }, reload: { type: Boolean, default: !0 }, closeBtn: { type: Boolean, default: !0 }, okBtn: { type: Boolean, default: !0 } }, data() { return { fileList: j(this.value), previewVisible: !1, frameVisible: !1, previewImage: "" }; }, watch: { value(t) { this.fileList = j(t); }, fileList(t) { const e = this.maxLength === 1 ? t[0] || "" : t; this.$emit("input", e), this.$emit("change", e); }, src(t) { this.modalVm && (this.modalVm.src = t); } }, methods: { key(t) { return t; }, closeModel(t) { this.$emit(t ? "$close" : "$ok"), this.reload && (this.$off("$ok"), this.$off("$close")), this.frameVisible = !1; }, handleCancel() { this.previewVisible = !1; }, showModel() { this.disabled || this.onOpen() === !1 || (this.frameVisible = !0); }, makeInput() { const t = this.$createElement, e = { type: "text", value: this.fileList.map((r) => this.getSrc(r)).toString(), readonly: !0 }; return t("ElInput", F([{}, { props: e }, { key: this.key("input") }]), [this.fileList.length ? t("i", { slot: "suffix", class: "el-input__icon el-icon-circle-close", on: { click: () => this.fileList = [] } }) : null, t("ElButton", F([{ attrs: { icon: this.icon } }, { on: { click: () => this.showModel() } }, { slot: "append" }]))]); }, makeGroup(t) { const e = this.$createElement; return (!this.maxLength || this.fileList.length < this.maxLength) && t.push(this.makeBtn()), e("div", { key: this.key("group") }, [...t]); }, makeItem(t, e) { const r = this.$createElement; return r("div", { class: "fc-files", key: this.key("file" + t) }, [...e]); }, valid(t) { const e = this.formCreateInject.field || this.field; if (e && t !== e) throw new Error("[frame]无效的字段值"); }, makeIcons(t, e) { const r = this.$createElement; if (this.handleIcon !== !1 || this.allowRemove === !0) { const i = []; return (this.type !== "file" && this.handleIcon !== !1 || this.type === "file" && this.handleIcon) && i.push(this.makeHandleIcon(t, e)), this.allowRemove && i.push(this.makeRemoveIcon(t, e)), r("div", { class: "fc-upload-cover", key: this.key("uc") }, [i]); } }, makeHandleIcon(t, e) { const r = this.$createElement; return r("i", { class: this.handleIcon === !0 || this.handleIcon === void 0 ? "el-icon-view" : this.handleIcon, on: { click: () => this.handleClick(t) }, key: this.key("hi" + e) }); }, makeRemoveIcon(t, e) { const r = this.$createElement; return r("i", { class: "el-icon-delete", on: { click: () => this.handleRemove(t) }, key: this.key("ri" + e) }); }, makeFiles() { const t = this.$createElement; return this.makeGroup(this.fileList.map((e, r) => this.makeItem(r, [t("i", { class: "el-icon-tickets", on: { click: () => this.handleClick(e) } }), this.makeIcons(e, r)]))); }, makeImages() { const t = this.$createElement; return this.makeGroup(this.fileList.map((e, r) => this.makeItem(r, [t("img", { attrs: { src: this.getSrc(e) } }), this.makeIcons(e, r)]))); }, makeBtn() { const t = this.$createElement; return t("div", { class: "fc-upload-btn", on: { click: () => this.showModel() }, key: this.key("btn") }, [t("i", { class: this.icon })]); }, handleClick(t) { return this.onHandle(t); }, handleRemove(t) { this.disabled || this.onBeforeRemove(t) !== !1 && (this.fileList.splice(this.fileList.indexOf(t), 1), this.onRemove(t)); }, getSrc(t) { return this.srcKey ? t[this.srcKey] : t; }, frameLoad(t) { this.onLoad(t); try { this.helper === !0 && (t.form_create_helper = { api: this.formCreateInject.api, close: (e) => { this.valid(e), this.closeModel(); }, set: (e, r) => { this.valid(e), this.disabled || this.$emit("input", r); }, get: (e) => (this.valid(e), this.value), onOk: (e) => this.$on("$ok", e), onClose: (e) => this.$on("$close", e) }); } catch (e) { console.log(e); } }, makeFooter() { const t = this.$createElement, { okBtnText: e, closeBtnText: r, closeBtn: i, okBtn: s, footer: n } = this.$props; if (n) return t("div", { slot: "footer" }, [i ? t("ElButton", { on: { click: () => this.onCancel() !== !1 && (this.frameVisible = !1) } }, [r]) : null, s ? t("ElButton", { attrs: { type: "primary" }, on: { click: () => this.onOk() !== !1 && this.closeModel() } }, [e]) : null]); } }, render() { const t = arguments[0], e = this.type; let r; e === "input" ? r = this.makeInput() : e === "image" ? r = this.makeImages() : r = this.makeFiles(); const { width: i = "30%", height: s, src: n, title: o, modalTitle: a } = this.$props; return this.$nextTick(() => { this.$refs.frame && this.frameLoad(this.$refs.frame.contentWindow || {}); }), t("div", { class: "_fc-frame" }, [r, t("el-dialog", F([{}, { props: { appendToBody: !0, modal: this.previewMask, title: a, visible: this.previewVisible } }, { on: { close: this.handleCancel } }]), [t("img", { style: "width: 100%", attrs: { src: this.previewImage } })]), t("el-dialog", F([{}, { props: N(y({ width: i, title: o, appendToBody: !0 }, this.modal), { visible: this.frameVisible }) }, { on: { close: () => this.closeModel(!0) } }]), [this.frameVisible || !this.reload ? t("iframe", { ref: "frame", attrs: { src: n, frameBorder: "0" }, style: { height: s, border: "0 none", width: "100%" } }) : null, this.makeFooter()])]); }, mounted() { this.$on("fc.closeModal", this.closeModal); } }, jt = "fcRadio", It = { name: jt, props: { formCreateInject: { type: Object, required: !0 }, value: {}, type: String }, watch: { "formCreateInject.options": { handler() { this.update(); }, deep: !0 }, value() { this.update(); } }, data() { return { trueValue: [] }; }, methods: { options() { const t = this.formCreateInject.options; return Array.isArray(t) ? t : []; }, onInput(t) { this.$emit("input", this.options().filter((e) => e.label === t).reduce((e, r) => r.value, "")); }, update() { this.trueValue = this.options().filter((t) => t.value === this.value).reduce((t, e) => e.label, ""); } }, created() { this.update(); }, render() { const t = arguments[0]; return t("ElRadioGroup", F([{}, this.formCreateInject.prop, { ref: "el" }, { props: { value: this.trueValue } }, { on: { input: this.onInput } }]), [this.options().map((e, r) => { const i = y({}, e), s = this.type === "button" ? "ElRadioButton" : "ElRadio"; return delete i.value, t(s, F([{}, { props: i }, { key: s + r + "-" + e.value }])); }), Y(this.$slots)]); }, mounted() { this.$emit("fc.el", this.$refs.el); } }, h = { type(t, e) { return Object.prototype.toString.call(t) === "[object " + e + "]"; }, Undef(t) { return t == null; }, Element(t) { return typeof t == "object" && t !== null && t.nodeType === 1 && !h.Object(t); }, trueArray(t) { return Array.isArray(t) && t.length > 0; }, Function(t) { const e = this.getType(t); return e === "Function" || e === "AsyncFunction"; }, getType(t) { const e = Object.prototype.toString.call(t); return /^\[object (.*)\]$/.exec(e)[1]; }, empty(t) { return t == null || Array.isArray(t) && Array.isArray(t) && !t.length ? !0 : typeof t == "string" && !t; } }; ["Date", "Object", "String", "Boolean", "Array", "Number"].forEach((t) => { h[t] = function(e) { return h.type(e, t); }; }); function k(t, e) { return {}.hasOwnProperty.call(t, e); } const At = "fcSelect", Vt = { name: At, functional: !0, props: { formCreateInject: { type: Object, required: !0 } }, render(t, e) { const r = (n, o) => { const a = n.slot; return t("ElOption", F([{}, { props: n }, { key: "" + o + "-" + n.value }]), [a ? t("template", { slot: n.slotName || "default" }, [h.Function(a) ? n.slot(t) : a]) : null]); }, i = (n, o) => t("ElOptionGroup", { attrs: { label: n.label }, key: "" + o + "-" + n.label }, [h.trueArray(n.options) && n.options.map((a, u) => r(a, u))]), s = e.props.formCreateInject.options; return t("ElSelect", F([{}, e.data, { ref: "el" }]), [(Array.isArray(s) ? s : []).map((n, o) => k(n || "", "options") ? i(n, o) : r(n, o)), e.children]); }, mounted() { this.$emit("fc.el", this.$refs.el); } }, Pt = "fcTree", Tt = { name: Pt, formCreateParser: { mergeProp(t) { const e = t.prop.props; e.nodeKey || (e.nodeKey = "id"), e.props || (e.props = { label: "title" }); } }, props: { formCreateInject: { type: Object, required: !0 }, type: { type: String, default: "checked" }, value: { type: [Array, String, Number], default: () => [] } }, watch: { value() { this.setValue(); } }, methods: { onChange() { this.updateValue(); }, updateValue() { if (!this.$refs.tree) return; const t = this.type.toLocaleLowerCase(); let e; t === "selected" ? e = this.$refs.tree.getCurrentKey() : e = this.$refs.tree.getCheckedKeys(), this.$emit("input", e); }, setValue() { this.type.toLocaleLowerCase() === "selected" ? this.$refs.tree.setCurrentKey(this.value) : this.$refs.tree.setCheckedKeys(j(this.value)); } }, render() { const t = arguments[0]; return t("ElTree", F([{}, this.formCreateInject.prop, { ref: "tree", on: { check: () => this.updateValue(), "node-click": () => this.updateValue() } }]), [Y(this.$slots)]); }, mounted() { this.setValue(), this.$emit("fc.el", this.$refs.tree); } }; function Re(t, e) { return { url: t, name: Dt(t), uid: e }; } function Dt(t) { return ("" + t).split("/").pop(); } const Bt = "fcUpload", Lt = { name: Bt, props: { formCreateInject: { type: Object, required: !0 }, onHandle: { type: Function, default(t) { this.previewImage = t.url, this.previewVisible = !0; } }, uploadType: { type: String, default: "file" }, limit: { type: Number, default: 0 }, allowRemove: { type: Boolean, default: !0 }, previewMask: void 0, modalTitle: String, handleIcon: { type: [String, Boolean], default: () => { } }, value: [Array, String] }, data() { return { uploadList: [], previewVisible: !1, previewImage: "", cacheFiles: [] }; }, created() { this.formCreateInject.prop.props.showFileList === void 0 && (this.formCreateInject.prop.props.showFileList = !1), this.formCreateInject.prop.props.fileList = j(this.value).map(Re); }, watch: { value(t) { this.$refs.upload.uploadFiles.every((e) => !e.status || e.status === "success") && (this.$refs.upload.uploadFiles = j(t).map(Re), this.uploadList = this.$refs.upload.uploadFiles); }, limit(t, e) { (e === 1 || t === 1) && this.update(); } }, methods: { key(t) { return t; }, isDisabled() { return this.formCreateInject.prop.props.disabled === !0; }, onRemove(t) { this.isDisabled() || this.$refs.upload.handleRemove(t); }, handleClick(t) { this.onHandle(t); }, makeItem(t, e) { const r = this.$createElement; return this.uploadType === "image" ? r("img", { attrs: { src: t.url }, key: this.key("img" + e) }) : r("i", { class: "el-icon-tickets", key: this.key("i" + e) }); }, makeRemoveIcon(t, e) { const r = this.$createElement; return r("i", { class: "el-icon-delete", on: { click: () => this.onRemove(t) }, key: this.key("ri" + e) }); }, makeHandleIcon(t, e) { const r = this.$createElement; return r("i", { class: this.handleIcon === !0 || this.handleIcon === void 0 ? "el-icon-view" : this.handleIcon, on: { click: () => this.handleClick(t) }, key: this.key("hi" + e) }); }, makeProgress(t, e) { const r = this.$createElement; return r("ElProgress", F([{}, { props: { percentage: t.percentage, type: "circle", width: 52 } }, { style: "margin-top:2px;", key: this.key("pg" + e) }])); }, makeIcons(t, e) { const r = this.$createElement, i = []; if (this.allowRemove || this.handleIcon !== !1) return (this.uploadType !== "file" && this.handleIcon !== !1 || this.uploadType === "file" && this.handleIcon) && i.push(this.makeHandleIcon(t, e)), this.allowRemove && i.push(this.makeRemoveIcon(t, e)), r("div", { class: "fc-upload-cover" }, [i]); }, makeFiles() { const t = this.$createElement; return this.uploadList.map((e, r) => this.$scopedSlots.fileList ? this.$scopedSlots.fileList({ file: e, index: r, vm: this }) : t("div", { key: this.key(r), class: "fc-files" }, [e.percentage !== void 0 && e.status !== "success" ? this.makeProgress(e, r) : [this.makeItem(e, r), this.makeIcons(e, r)]])); }, makeUpload() { const t = this.$createElement, e = !this.limit || this.limit > this.uploadList.length; return t("ElUpload", F([{}, this.formCreateInject.prop, {}, { style: { display: "inline-block" }, key: this.key("upload"), ref: "upload" }]), [e ? t("template", { slot: "default" }, [this.$slots.default || t("div", { class: "fc-upload-btn" }, [t("i", { class: "el-icon-upload2" })])]) : null, Y(this.$slots, ["default"])]); }, update() { let t = this.$refs.upload.uploadFiles.map((e) => e.url).filter((e) => e !== void 0 && e.indexOf("blob:") !== 0); JSON.stringify(t) !== JSON.stringify(this.cacheFiles) && (this.cacheFiles = [...t], this.$emit("input", this.limit === 1 ? t[0] || "" : t)); }, handleCancel() { this.previewVisible = !1; } }, render() { const t = arguments[0]; 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), t("div", { class: "_fc-upload" }, [[this.formCreateInject.prop.props.showFileList ? [] : this.makeFiles(), this.makeUpload()], t("el-dialog", F([{}, { props: { appendToBody: !0, modal: this.previewMask, title: this.modalTitle, visible: this.previewVisible } }, { on: { close: this.handleCancel } }]), [t("img", { attrs: { alt: "example", src: this.previewImage }, style: "width: 100%" })])]); }, mounted() { this.uploadList = this.$refs.upload.uploadFiles, this.$watch(() => this.$refs.upload.uploadFiles, () => { this.update(); }, { deep: !0 }), this.$emit("fc.el", this.$refs.upload); } }; function w(t, e, r) { T.set(t, e, r); } function B(t, e) { T.delete(t, e); } function K(t, e = {}, r) { let i = !1; for (let s in e) if (Object.prototype.hasOwnProperty.call(e, s)) { let n = e[s]; if ((i = Array.isArray(n)) || h.Object(n)) { let o = t[s] === void 0; if (i) i = !1, o && w(t, s, []); else if (n._clone && r !== void 0) if (r) n = n.getRule(), o && w(t, s, {}); else { w(t, s, n._clone()); continue; } else o && w(t, s, {}); t[s] = K(t[s], n, r); } else w(t, s, n), h.Undef(n) || (h.Undef(n.__json) || (t[s].__json = n.__json), h.Undef(n.__origin) || (t[s].__origin = n.__origin)); } return r !== void 0 && Array.isArray(t) ? t.filter((s) => !s || !s.__ctrl) : t; } function L(t) { return K({}, { value: t }).value; } const Mt = Object.assign || function(t) { for (let e, r = 1; r < arguments.length; r++) for (let i in e = arguments[r], e) Object.prototype.hasOwnProperty.call(e, i) && w(t, i, e[i]); return t; }; function p() { return Mt.apply(this, arguments); } const Nt = "fcGroup", qt = { name: Nt, props: { field: String, rule: [Array, Object], rules: Array, expand: Number, options: Object, formCreateInject: { type: Object, required: !0 }, button: { type: Boolean, default: !0 }, max: { type: Number, default: 0 }, min: { type: Number, default: 0 }, value: { type: Array, default: () => [] }, sortBtn: { type: Boolean, default: !0 }, defaultValue: Object, disabled: { type: Boolean, default: !1 }, syncDisabled: { type: Boolean, default: !0 }, onBeforeRemove: { type: Function, default: () => { } }, onBeforeAdd: { type: Function, default: () => { } }, parse: Function }, data() { return { len: 0, cacheRule: {}, cacheValue: {}, sort: [], type: void 0 }; }, computed: { formRule() { return this.rules ? this.rules : this.rule ? Array.isArray(this.rule) ? this.rule : [this.rule] : []; } }, watch: { cacheRule: { handler(t) { this.sort = Object.keys(t); }, immediate: !0 }, formRule: { handler(t, e) { Object.keys(this.cacheRule).forEach((r) => { const i = this.cacheRule[r]; if (i.$f) { const s = i.$f.formData(); if (t === e) i.$f.deferSyncValue(() => { K(i.rule, t), i.$f.setValue(s); }, !0); else { const n = i.$f.formData(); i.$f.once("reloading", () => { i.$f.setValue(n); }), i.rule = L(t); } } }); }, deep: !0 }, expand(t) { let e = t - this.value.length; e > 0 && this.expandRule(e); }, value(t, e) { t = t || []; let r = this.sort, i = r.length, s = i - t.length; if (s < 0) { for (let n = s; n < 0; n++) this.addRule(t.length + n); this.sort = Object.keys(this.cacheRule); for (let n = 0; n < i; n++) this.setValue(r[n], t[n]); } else { if (s > 0) { for (let n = 0; n < s; n++) this.removeRule(r[i - n - 1]); this.sort = Object.keys(this.cacheRule); } t.forEach((n, o) => { this.setValue(r[o], t[o]); }); } } }, methods: { _value(t) { return t && k(t, this.field) ? t[this.field] : t; }, cache(t, e) { this.cacheValue[t] = JSON.stringify(e); }, input(t) { this.$emit("input", t), this.$emit("change", t); }, formData(t, e) { const r = this.cacheRule, i = this.sort; if (i.filter((n) => r[n].$f).length !== i.length) return; const s = i.map((n) => { const o = t === n ? e : y({}, this.cacheRule[n].$f.form), a = this.field ? o[this.field] || null : o; return this.cache(n, a), a; }); this.input(s); }, setValue(t, e) { const r = this.field, i = this.cacheRule[t].$f; r && (e = { [r]: this._value(e) }), this.cacheValue[t] !== JSON.stringify(r ? e[r] : e) && (this.cache(t, e), i && i.coverValue(e || {})); }, addRule(t, e) { const r = this.formCreateInject.form.copyRules(this.formRule), i = this.options ? y({}, this.options) : { submitBtn: !1, resetBtn: !1 }; if (this.defaultValue) { i.formData || (i.formData = {}); const s = L(this.defaultValue); p(i.formData, this.field ? { [this.field]: s } : s); } this.parse && this.parse({ rule: r, options: i, index: this.sort.length }), this.$set(this.cacheRule, ++this.len, { rule: r, options: i }), e && this.$nextTick(() => this.$emit("add", r, Object.keys(this.cacheRule).length - 1)); }, add$f(t, e, r) { this.cacheRule[e].$f = r, this.$nextTick(() => { this.$emit("itemMounted", r, Object.keys(this.cacheRule).indexOf(e)); }); }, removeRule(t, e) { const r = Object.keys(this.cacheRule).indexOf(t); this.$delete(this.cacheRule, t), this.$delete(this.cacheValue, t), e && this.$nextTick(() => this.$emit("remove", r)); }, add(t) { this.disabled || this.onBeforeAdd(this.value) === !1 || this.addRule(t, !0); }, del(t, e) { if (this.disabled || this.onBeforeRemove(this.value, t) === !1) return; this.removeRule(e, !0); const r = [...this.value]; r.splice(t, 1), this.input(r); }, addIcon(t) { const e = this.$createElement; return e("div", { class: "_fc-group-btn _fc-group-plus-minus", on: { click: this.add } }); }, delIcon(t, e) { const r = this.$createElement; return r("div", { class: "_fc-group-btn _fc-group-plus-minus _fc-group-minus", on: { click: () => this.del(t, e) } }); }, sortUpIcon(t) { const e = this.$createElement; return e("div", { class: "_fc-group-btn _fc-group-arrow _fc-group-up", on: { click: () => this.changeSort(t, -1) } }); }, sortDownIcon(t) { const e = this.$createElement; return e("div", { class: "_fc-group-btn _fc-group-arrow _fc-group-down", on: { click: () => this.changeSort(t, 1) } }); }, changeSort(t, e) { const r = this.sort[t]; this.$set(this.sort, t, this.sort[t + e]), this.sort[t + e] = r, this.formData(0); }, makeIcon(t, e, r) { if (this.$scopedSlots.button) return this.$scopedSlots.button({ total: t, index: e, vm: this, key: r, del: () => this.del(e, r), add: this.add }); const i = []; return (!this.max || t < this.max) && t === e + 1 && i.push(this.addIcon(r)), t > this.min && i.push(this.delIcon(e, r)), this.sortBtn && e && i.push(this.sortUpIcon(e)), this.sortBtn && e !== t - 1 && i.push(this.sortDownIcon(e)), i; }, emitEvent(t, e, r, i) { this.$emit(t, ...e, this.cacheRule[i].$f, r); }, expandRule(t) { for (let e = 0; e < t; e++) this.value.push(this.field ? null : {}); } }, created() { this.type = this.formCreateInject.form.$form(); const t = (this.expand || 0) - this.value.length; t > 0 && this.expandRule(t); for (let e = 0; e < this.value.length; e++) this.addRule(e); }, render() { const t = arguments[0], e = this.sort, r = this.button, i = this.type, s = this.disabled, n = e.length === 0 ? this.$scopedSlots.default ? this.$scopedSlots.default({ vm: this, add: this.add }) : t("div", { key: "a_def", class: "_fc-group-plus-minus _fc-group-add", on: { click: this.add } }) : e.map((o, a) => { const { rule: u, options: l } = this.cacheRule[o], c = r && !s ? this.makeIcon(e.length, a, o) : []; return t("div", { class: "_fc-group-container", key: o }, [t(i, F([{ key: o }, { on: { "update:value": (m) => this.formData(o, m), "emit-event": (m, ...v) => this.emitEvent(m, v, a, o), input: (m) => this.add$f(a, o, m) } }, {}, { props: { disabled: s, inFor: !0, value: this.field ? { [this.field]: this._value(this.value[a]) } : this.value[a], rule: u, option: l, extendOption: !0 } }])), t("div", { class: "_fc-group-idx" }, [a + 1]), c.length ? t("div", { class: "_fc-group-handle" }, [c]) : null]); }); return t("div", { key: "con", class: "_fc-group " + (s ? "_fc-group-disabled" : "") }, [n]); } }, Ut = "fcSubForm", Ht = { name: Ut, props: { rule: Array, options: Object, formCreateInject: { type: Object, required: !0 }, value: { type: Object, default: () => ({}) }, disabled: { type: Boolean, default: !1 }, syncDisabled: { type: Boolean, default: !0 } }, data() { return { cacheRule: {}, cacheValue: {}, type: void 0 }; }, watch: { value(t) { this.setValue(t); } }, methods: { formData(t) { this.cacheValue = JSON.stringify(t), this.$emit("input", t), this.$emit("change", t); }, setValue(t) { const e = JSON.stringify(t); this.cacheValue !== e && (this.cacheValue = e, this.cacheRule.$f.coverValue(t || {})); }, addRule() { const t = this.options ? this.options : { submitBtn: !1, resetBtn: !1 }; t.formData = y({}, this.value || {}), this.cacheRule = { rule: this.rule, options: t }; }, add$f(t) { this.cacheRule.$f = t, this.$nextTick(() => { this.$emit("itemMounted", t); }); }, emitEvent(t, ...e) { this.$emit(t, ...e); } }, created() { this.addRule(), this.type = this.formCreateInject.form.$form(); }, render() { const t = arguments[0], { rule: e, options: r } = this.cacheRule, i = this.type; return t(i, F([{}, { on: { "update:value": this.formData, "emit-event": this.emitEvent, input: this.add$f } }, {}, { props: { rule: e, option: r, disabled: this.disabled, extendOption: !0 } }])); } }, Jt = [ Et, Rt, It, Vt, Tt, Lt, qt, Ht ], je = "FormCreate", le = (t, e) => { if (!(!t || t === e)) { if (t.formCreateInject) return t.formCreateInject; if (t.$parent) return le(t.$parent, e); } }; function xt(t, e, r) { return { name: je, componentName: je, model: { prop: "api" }, components: e, directives: r, provide() { return { $pfc: this }; }, inject: { $pfc: { default: null } }, props: { rule: { type: Array, required: !0 }, option: { type: Object, default: () => ({}) }, extendOption: Boolean, disabled: { type: Boolean, default: void 0 }, value: Object, api: Object, name: String, subForm: { type: Boolean, default: !0 }, inFor: Boolean }, data() { return { formData: void 0, destroyed: !1, validate: {}, $f: void 0, isShow: !0, unique: 1, renderRule: [...this.rule || []], ctxInject: {}, updateValue: JSON.stringify(this.value || {}), isMore: !!this.inFor }; }, render() { return this.formCreate.render(); }, methods: { _refresh() { ++this.unique; }, _renderRule() { this.renderRule = [...this.rule || []]; }, _updateValue(i) { this.destroyed || (this.updateValue = JSON.stringify(i), this.$emit("update:value", i)); } }, watch: { value: { handler(i) { JSON.stringify(i || {}) !== this.updateValue && (this.$f.config.forceCoverValue ? this.$f.coverValue(i || {}) : this.$f.setValue(i || {})); }, deep: !0 }, option: { handler() { this.formCreate.initOptions(), this.$f.refresh(); }, deep: !0 }, rule(i, s) { i.length === this.renderRule.length && i.every((n) => this.renderRule.indexOf(n) > -1) || (this.formCreate.$handle.reloadRule(i), this._renderRule(), i !== s && this.formCreate.$handle.targetReload()); }, disabled() { this.$f.refresh(); } }, beforeCreate() { this.formCreate = new t(this), Object.keys(this.formCreate.prop).forEach((i) => { p(this.$options[i], this.formCreate.prop[i]); }), this.$emit("beforeCreate", this.formCreate.api()); }, created() { const i = this, s = this.formCreate.api(), n = () => { if (i.$pfc) { const a = le(i, i.$pfc); if (a) { let u; i.isMore ? (u = j(a.getSubForm()), u.push(s)) : u = s, a.subForm(u); } } }, o = () => { const a = le(i, i.$pfc); if (a) if (i.isMore) { const u = j(a.getSubForm()), l = u.indexOf(s); l > -1 && u.splice(l, 1); } else a.subForm(); }; i.$on("hook:beforeDestroy", () => { o(); }), this.$watch(() => this.subForm, (a) => { a ? n() : o(); }, { immediate: !0 }); } }; } const Ke = ["attrs", "props", "domProps", "scopedSlots"], We = ["class", "style", "directives"], Ge = ["on", "nativeOn"], D = (t, e = {}, r = {}) => { const i = [...Ke, ...r.normal || []], s = [...We, ...r.array || []], n = [...Ge, ...r.functional || []], o = r.props || []; return t.reduce((a, u) => { for (const l in u) if (a[l]) if (o.indexOf(l) > -1) a[l] = D([u[l]], a[l]); else if (i.indexOf(l) > -1) a[l] = y(y({}, a[l]), u[l]); else if (s.indexOf(l) > -1) { const c = a[l] instanceof Array ? a[l] : [a[l]], m = u[l] instanceof Array ? u[l] : [u[l]]; a[l] = [...c, ...m]; } else if (n.indexOf(l) > -1) for (const c in u[l]) if (a[l][c]) { const m = a[l][c] instanceof Array ? a[l][c] : [a[l][c]], v = u[l][c] instanceof Array ? u[l][c] : [u[l][c]]; a[l][c] = [...m, ...v]; } else a[l][c] = u[l][c]; else if (l === "hook") for (let c in u[l]) a[l][c] ? a[l][c] = Kt(a[l][c], u[l][c]) : a[l][c] = u[l][c]; else a[l] = u[l]; else i.indexOf(l) > -1 || n.indexOf(l) > -1 || o.indexOf(l) > -1 ? a[l] = y({}, u[l]) : s.indexOf(l) > -1 ? a[l] = u[l] instanceof Array ? [...u[l]] : typeof u[l] == "object" ? y({}, u[l]) : u[l] : a[l] = u[l]; return a; }, e); }, Kt = (t, e) => function() { t && t.apply(this, arguments), e && e.apply(this, arguments); }, Xe = ["type", "slot", "emitPrefix", "value", "name", "native", "hidden", "display", "inject", "options", "emit", "nativeEmit", "link", "prefix", "suffix", "update", "sync", "optionsTo", "key", "preview", "component", "cache"], pe = ["validate", "children", "control"], me = ["effect", "deep"]; function Wt() { return [...Xe, ...Ke, ...We, ...Ge, ...pe, ...me]; } function ye(t, e, r) { return `[form-create ${t}]: ${e}`; } function Gt(t, e) { console.warn(ye("tip", t)); } function ge(t, e) { console.error(ye("err", t)); } function Xt(t) { ge(t.toString()), console.error(t); } const ue = "[[FORM-CREATE-PREFIX-", fe = "-FORM-CREATE-SUFFIX]]"; function ze(t, e) { return JSON.stringify(K(Array.isArray(t) ? [] : {}, t, !0), function(r, i) { if (!(i && i._isVue === !0)) { if (typeof i != "function") return i; if (i.__json) return i.__json; if (i.__origin && (i = i.__origin), !i.__emit) return ue + i + fe; } }, e); } function te(t) { return new Function("return " + t)(); } function q(t, e) { if (t && h.String(t) && t.length > 4) { let r = t.trim(), i = !1; try { if (r.indexOf(fe) > 0 && r.indexOf(ue) === 0) r = r.replace(fe, "").replace(ue, ""), i = !0; else if (r.indexOf("$FN:") === 0) r = r.substring(4), i = !0; else if (r.indexOf("$EXEC:") === 0) r = r.substring(6), i = !0; else if (r.indexOf("$GLOBAL:") === 0) { const n = r.substring(8); return r = function(...o) { const a = o[0].api.getGlobalEvent(n); if (a) return a.call(this, ...o); }, r.__json = t, r.__inject = !0, r; } else { if (r.indexOf("$FNX:") === 0) return r = te("function($inject){" + r.substring(5) + "}"), r.__json = t, r.__inject = !0, r; (!e && r.indexOf("function ") === 0 && r !== "function " || !e && r.indexOf("function(") === 0 && r !== "function(") && (i = !0); } if (!i) return t; let s; try { s = te(r); } catch (n) { s = te("function " + r); } return s.__json = t, s; } catch (s) { ge(`解析失败:${r} err: ${s}`); return; } } return t; } function zt(t, e) { return JSON.parse(t, function(r, i) { return h.Undef(i) || !i.indexOf ? i : q(i, e); }); } function he(t, e) { return { value: t, enumerable: !1, configurable: !1, writable: !!e }; } function $e(t) { return Qe([t])[0]; } function Qe(t, e) { return K([], [...t], e || !1); } function U(t, e) { return D(Array.isArray(e) ? e : [e], t, { array: pe, normal: me }), t; } function Ie(t) { const e = h.Function(t.getRule) ? t.getRule() : t; return e.type || (e.type = "input"), e; } function Qt(t, e) { return t ? (Object.keys(e || {}).forEach((r) => { e[r] && (t[r] = U(t[r] || {}, e[r])); }), t) : e; } function Ze(t, e) { Object.defineProperties(t, Object.keys(e).reduce((r, i) => (r[i] = { get() { return e[i](); } }, r), {})); } function z(t) { return t.__fc__ || (t.__origin__ ? t.__origin__.__fc__ : null); } function R(t, e) { try { e = t(); } catch (r) { Xt(r); } return e; } const Ae = (t, e) => typeof t == "string" ? String(e) : typeof t == "number" ? Number(e) : e, x = { "==": (t, e) => JSON.stringify(t) === JSON.stringify(Ae(t, e)), "!=": (t, e) => !x["=="](t, e), ">": (t, e) => t > e, ">=": (t, e) => t >= e, "<": (t, e) => t < e, "<=": (t, e) => t <= e, on(t, e) { return t && t.indexOf && t.indexOf(Ae(t[0], e)) > -1; }, notOn(t, e) { return !x.on(t, e); }, in(t, e) { return e && e.indexOf && e.indexOf(t) > -1; }, notIn(t, e) { return !x.in(t, e); }, between(t, e) { return t > e[0] && t < e[1]; }, notBetween(t, e) { return t < e[0] || t > e[1]; }, empty(t) { return h.empty(t); }, notEmpty(t) { return !h.empty(t); }, pattern(t, e) { return new RegExp(e, "g").test(t); } }; function Ye() { return { props: {}, on: {}, options: [], children: [], effect: {}, hidden: !1, display: !0, value: void 0 }; } function E(t, e) { return (r, i, s, n = {}) => { const o = new ve(t, r, i, s, n); return e && (h.Function(e) ? e(o) : o.props(e)), o; }; } function ve(t, e, r, i, s) { this._data = p(Ye(), { type: t, title: e, field: r, value: i, props: s || {} }), this.event = this.on; } p(ve.prototype, { getRule() { return this._data; }, setProp(t, e) { return w(this._data, t, e), this; }, _clone() { const t = new this.constructor(); return t._data = $e(this._data), t; } }); function et(t) { t.forEach((e) => { ve.prototype[e] = function(r) { return U(this._data, { [e]: arguments.length < 2 ? r : { [r]: arguments[1] } }), this; }; }); } et(Wt()); const tt = E(""); function Zt(t, e, r) { let i = tt("", e); return i._data.type = t, i._data.title = r, i; } function Ve(t, e, r, i) { let s = tt("", r); return s._data.type = "template", s._data.template = t, s._data.title = i, s._data.vm = e, s; } function Yt() { return { create: Zt, createTmp: Ve, template: Ve, factory: E }; } function er(t, e, r) { const i = `fail to ${t} ${r.status}'`, s = new Error(i); return s.status = r.status, s.url = t, s; } function Pe(t) { const e = t.responseText || t.response; if (!e) return e; try { return JSON.parse(e); } catch (r) { return e; } } function rt(t) { if (typeof XMLHttpRequest == "undefined") return; const e = new XMLHttpRequest(), r = t.action; e.onerror = function(o) { t.onError(o); }, e.onload = function() { if (e.status < 200 || e.status >= 300) return t.onError(er(r, t, e), Pe(e)); t.onSuccess(Pe(e)); }, e.open(t.method || "get", r, !0); let i; t.data && ((t.dataType || "").toLowerCase() !== "json" ? (i = new FormData(), Object.keys(t.data).map((n) => { i.append(n, t.data[n]); })) : (i = JSON.stringify(t.data), e.setRequestHeader("content-type", "application/json"))), t.withCredentials && "withCredentials" in e && (e.withCredentials = !0); const s = t.headers || {}; Object.keys(s).forEach((n) => { s[n] !== null && e.setRequestHeader(n, s[n]); }), e.send(i); } function tr(t) { return new Promise((e, r) => { rt(N(y({}, t), { onSuccess(i) { let s = (o) => o; const n = q(t.parse); h.Function(n) ? s = n : n && h.String(n) && (s = (o) => (n.split(".").forEach((a) => { o && (o = o[a]); }), o)), e(s(i)); }, onError(i) { r(i); } })); }); } function X(t) { return L(t); } function rr(t) { function e(n) { return h.Undef(n) ? n = t.fields() : Array.isArray(n) || (n = [n]), n; } function r(n, o, a) { e(n).forEach((u) => { t.getCtxs(u).forEach((l) => { w(l.rule, o, a), t.$render.clearCache(l); }); }); } function i() { const n = t.subForm; return Object.keys(n).reduce((o, a) => { const u = n[a]; return u && (Array.isArray(u) ? o.push(...u) : o.push(u)), o; }, []); } const s = { get config() { return t.options; }, get options() { return t.options; }, get form() { return t.form; }, get rule() { return t.rules; }, get parent() { return t.vm.$pfc && t.vm.$pfc.$f; }, get top() { return s.parent ? s.parent.top : s; }, get children() { return i(); }, formData(n) { return e(n).reduce((o, a) => { const u = t.getFieldCtx(a); return u && (o[u.field] = X(u.rule.value)), o; }, t.options.appendValue !== !1 ? X(t.appendData) : {}); }, getValue(n) { const o = t.getFieldCtx(n); if (o) return X(o.rule.value); }, coverValue(n) { const o = y({}, n || {}); t.deferSyncValue(() => { s.fields().forEach((a) => { const u = t.fieldCtx[a]; if (u) { const l = k(o, a); u