UNPKG

@form-create/ant-design-vue

Version:

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

1,837 lines (1,835 loc) 114 kB
/*! * FormCreate 低代码表单渲染器 * @form-create/ant-design-vue 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-cover{opacity:0;position:absolute;inset:0;background:#0009;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 .ant-upload{display:block}._fc-frame .fc-upload-btn,.fc-files{display:inline-block;width:104px;height:104px;text-align:center;line-height:104px;border:1px solid #c0ccda;border-radius:4px;overflow:hidden;background:#fff;position:relative;box-shadow:2px 2px 5px #0000001a;margin-right:4px;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 .ant-form-item{margin-bottom:22px}.form-create .form-create .ant-form-item .ant-form-item{margin-bottom:0}.form-create .form-create .ant-form-item.ant-form-item-with-help{margin-bottom:3px}.form-create .form-create .ant-form-item .ant-form-item.ant-form-item-with-help{margin-bottom:-22px}')),document.head.appendChild(o)}}catch(r){console.error("vite-plugin-css-injected-by-js",r)}})(); var gt = Object.defineProperty, $t = Object.defineProperties; var bt = Object.getOwnPropertyDescriptors; var Ae = Object.getOwnPropertySymbols; var _t = Object.prototype.hasOwnProperty, vt = Object.prototype.propertyIsEnumerable; var Pe = (t, e, r) => e in t ? gt(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, m = (t, e) => { for (var r in e || (e = {})) _t.call(e, r) && Pe(t, r, e[r]); if (Ae) for (var r of Ae(e)) vt.call(e, r) && Pe(t, r, e[r]); return t; }, P = (t, e) => $t(t, bt(e)); import I from "vue"; import Q from "moment"; function Ct(t) { return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t; } function ue() { return ue = 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; }, ue.apply(this, arguments); } var Ot = ["attrs", "props", "domProps"], kt = ["class", "style", "directives"], wt = ["on", "nativeOn"], Ft = function(t) { return t.reduce(function(e, r) { for (var i in r) if (!e[i]) e[i] = r[i]; else if (Ot.indexOf(i) !== -1) e[i] = ue({}, e[i], r[i]); else if (kt.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 (wt.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] ? Et(e[i][l], r[i][l]) : r[i][l]; else e[i] = r[i]; return e; }, {}); }, Et = function(t, e) { return function() { t && t.apply(this, arguments), e && e.apply(this, arguments); }; }, St = Ft; const L = /* @__PURE__ */ Ct(St); function We(t) { return t == null ? "" : typeof t == "object" ? JSON.stringify(t, null, 2) : String(t); } function w(t, e, r) { I.set(t, e, r); } function B(t, e) { I.delete(t, e); } const 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); } function J(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] = J(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 M(t) { return J({}, { value: t }).value; } function T(t) { return Array.isArray(t) ? t : [null, void 0, ""].indexOf(t) > -1 ? [] : [t]; } function Rt(t, e) { return Object.keys(t).reduce((r, i) => ((!e || e.indexOf(i) === -1) && r.push(t[i]), r), []); } const Ve = function(t, e) { return { url: t, name: jt(t), status: "done", uid: e + 1 }; }, jt = function(t) { return We(t).split("/").pop(); }, Ie = function(t) { return { url: t.url, file: t }; }, At = "fcUpload", Pt = { name: At, formCreateParser: { toFormValue(t) { return T(t); }, toValue(t, e) { return e.prop.props.limit === 1 ? t[0] || "" : t; } }, props: { limit: { type: Number, default: 0 }, formCreateInject: { type: Object, required: !0 }, value: { type: Array, default: () => [] }, onSuccess: { type: Function, required: !0 }, onHandle: { type: Function, default: function(t) { this.previewImage = t.url, this.previewVisible = !0; } }, modalTitle: String, previewMask: void 0 }, data() { const t = this.value.map(Ve); return { defaultUploadList: t, previewImage: "", previewVisible: !1, uploadList: t.map(Ie) }; }, watch: { value(t) { const e = t.map(Ve); this.$refs.upload.sFileList = e, this.uploadList = e.map(Ie); } }, methods: { handleChange({ file: t, fileList: e }) { const r = this.uploadList; t.status === "done" ? (this.onSuccess(t, e), t.url && r.push({ url: t.url, file: e[e.length - 1] }), this.input()) : t.status === "removed" && (r.forEach((i, s) => { i.file === t && r.splice(s, 1); }), this.input()); }, input() { this.$emit("input", this.uploadList.map((t) => t.url)); } }, render() { const t = arguments[0], e = !this.limit || this.limit > this.uploadList.length, r = m({}, this.formCreateInject.prop); return r.on = J({}, r.on || {}), t("div", { class: "_fc-upload" }, [t("AUpload", L([{}, r, {}, { on: { preview: this.onHandle.bind(this), change: this.handleChange.bind(this) }, props: { defaultFileList: this.defaultUploadList }, ref: "upload" }]), [e ? t("template", { slot: "default" }, [this.$slots.default || t("AIcon", { attrs: { type: "plus" } })]) : null, Rt(this.$slots, ["default"])]), t("aModal", L([{}, { props: { mask: this.previewMask, title: this.modalTitle, footer: null } }, { model: { value: this.previewVisible, callback: (i) => { this.previewVisible = i; } } }]), [t("img", { style: "width: 100%", attrs: { src: this.previewImage } })])]); }, mounted() { this.$emit("fc.el", this.$refs.upload); } }, Vt = "fcFrame", It = { name: Vt, 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: "folder" }, width: { type: [Number, String], default: 500 }, 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: T(this.value), previewVisible: !1, frameVisible: !1, previewImage: "" }; }, watch: { value(t) { this.fileList = T(t); }, fileList(t) { const e = this.maxLength === 1 ? t[0] || "" : t; this.$emit("input", e), this.$emit("change", e); } }, methods: { key(t) { return t; }, closeModal(t) { this.$emit(t ? "$close" : "$ok"), this.reload && (this.$off("$ok"), this.$off("$close")), this.frameVisible = !1; }, showModal() { 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("AInput", L([{}, { props: e }, { key: this.key("input") }]), [t("AIcon", { attrs: { type: this.icon }, slot: "addonAfter", on: { click: this.showModal } }), this.fileList.length ? t("AIcon", { attrs: { type: "close-circle" }, slot: "suffix", on: { click: () => this.fileList = [] } }) : null]); }, 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("AIcon", { attrs: { type: this.handleIcon === !0 || this.handleIcon === void 0 ? "eye-o" : this.handleIcon }, on: { click: () => this.handleClick(t) }, key: this.key("hi" + e) }); }, makeRemoveIcon(t, e) { const r = this.$createElement; return r("AIcon", { attrs: { type: "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("AIcon", { attrs: { type: "file" }, 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.showModal() }, key: this.key("btn") }, [t("AIcon", { attrs: { type: this.icon, theme: "filled" } })]); }, 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.closeModal(); }, 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, o = []; return n && (i && o.push(t("AButton", { on: { click: () => this.onCancel() !== !1 && this.closeModal(!0) } }, [r])), s && o.push(t("AButton", { attrs: { type: "primary" }, on: { click: () => this.onOk() !== !1 && this.closeModal() } }, [e]))), o; } }, 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("aModal", L([{}, { props: { mask: this.previewMask, title: a, footer: null } }, { model: { value: this.previewVisible, callback: (u) => { this.previewVisible = u; } } }]), [t("img", { style: "width: 100%", attrs: { src: this.previewImage } })]), t("aModal", L([{}, { props: P(m({ width: i, title: o }, this.modal), { visible: this.frameVisible }) }, { on: { cancel: () => this.closeModal(!0) } }]), [this.frameVisible || !this.reload ? t("iframe", { ref: "frame", attrs: { src: n, frameborder: "0" }, style: { height: s, border: "0 none", width: "100%" } }) : null, t("div", { slot: "footer" }, [this.makeFooter()])])]); }, mounted() { this.$on("fc.closeModal", this.closeModal); } }, Dt = 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 Dt.apply(this, arguments); } const Tt = "fcGroup", Bt = { name: Tt, 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(() => { J(i.rule, t), i.$f.setValue(s); }, !0); else { const n = i.$f.formData(); i.$f.once("reloading", () => { i.$f.setValue(n); }), i.rule = M(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 : m({}, 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 ? m({}, this.options) : { submitBtn: !1, resetBtn: !1 }; if (this.defaultValue) { i.formData || (i.formData = {}); const s = M(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, L([{ key: o }, { on: { "update:value": (y) => this.formData(o, y), "emit-event": (y, ...b) => this.emitEvent(y, b, a, o), input: (y) => this.add$f(a, o, y) } }, {}, { 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]); } }, Mt = "fcSubForm", Nt = { name: Mt, 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 = m({}, 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, L([{}, { on: { "update:value": this.formData, "emit-event": this.emitEvent, input: this.add$f } }, {}, { props: { rule: e, option: r, disabled: this.disabled, extendOption: !0 } }])); } }, Lt = [ Pt, It, Bt, Nt ], ge = { name: "checkbox", mergeProp(t) { const e = t.prop.props; k(e, "options") || (e.options = t.prop.options || []); } }, qt = P(m({}, ge), { name: "radio" }), Ut = P(m({}, ge), { name: "select" }), De = "FormCreate", fe = (t, e) => { if (!(!t || t === e)) { if (t.formCreateInject) return t.formCreateInject; if (t.$parent) return fe(t.$parent, e); } }; function Ht(t, e, r) { return { name: De, componentName: De, 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 = fe(i, i.$pfc); if (a) { let u; i.isMore ? (u = T(a.getSubForm()), u.push(s)) : u = s, a.subForm(u); } } }, o = () => { const a = fe(i, i.$pfc); if (a) if (i.isMore) { const u = T(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 Xe = ["attrs", "props", "domProps", "scopedSlots"], ze = ["class", "style", "directives"], Qe = ["on", "nativeOn"], D = (t, e = {}, r = {}) => { const i = [...Xe, ...r.normal || []], s = [...ze, ...r.array || []], n = [...Qe, ...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] = m(m({}, a[l]), u[l]); else if (s.indexOf(l) > -1) { const c = a[l] instanceof Array ? a[l] : [a[l]], y = u[l] instanceof Array ? u[l] : [u[l]]; a[l] = [...c, ...y]; } else if (n.indexOf(l) > -1) for (const c in u[l]) if (a[l][c]) { const y = a[l][c] instanceof Array ? a[l][c] : [a[l][c]], b = u[l][c] instanceof Array ? u[l][c] : [u[l][c]]; a[l][c] = [...y, ...b]; } else a[l][c] = u[l][c]; else if (l === "hook") for (let c in u[l]) a[l][c] ? a[l][c] = Jt(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] = m({}, u[l]) : s.indexOf(l) > -1 ? a[l] = u[l] instanceof Array ? [...u[l]] : typeof u[l] == "object" ? m({}, u[l]) : u[l] : a[l] = u[l]; return a; }, e); }, Jt = (t, e) => function() { t && t.apply(this, arguments), e && e.apply(this, arguments); }, Ze = ["type", "slot", "emitPrefix", "value", "name", "native", "hidden", "display", "inject", "options", "emit", "nativeEmit", "link", "prefix", "suffix", "update", "sync", "optionsTo", "key", "preview", "component", "cache"], $e = ["validate", "children", "control"], be = ["effect", "deep"]; function xt() { return [...Ze, ...Xe, ...ze, ...Qe, ...$e, ...be]; } function _e(t, e, r) { return `[form-create ${t}]: ${e}`; } function Yt(t, e) { console.warn(_e("tip", t)); } function ve(t, e) { console.error(_e("err", t)); } function Gt(t) { ve(t.toString()), console.error(t); } const he = "[[FORM-CREATE-PREFIX-", ce = "-FORM-CREATE-SUFFIX]]"; function et(t, e) { return JSON.stringify(J(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 he + i + ce; } }, e); } function ie(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(ce) > 0 && r.indexOf(he) === 0) r = r.replace(ce, "").replace(he, ""), 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 = ie("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 = ie(r); } catch (n) { s = ie("function " + r); } return s.__json = t, s; } catch (s) { ve(`解析失败:${r} err: ${s}`); return; } } return t; } function Kt(t, e) { return JSON.parse(t, function(r, i) { return h.Undef(i) || !i.indexOf ? i : q(i, e); }); } function de(t, e) { return { value: t, enumerable: !1, configurable: !1, writable: !!e }; } function Ce(t) { return tt([t])[0]; } function tt(t, e) { return J([], [...t], e || !1); } function U(t, e) { return D(Array.isArray(e) ? e : [e], t, { array: $e, normal: be }), t; } function Te(t) { const e = h.Function(t.getRule) ? t.getRule() : t; return e.type || (e.type = "input"), e; } function Wt(t, e) { return t ? (Object.keys(e || {}).forEach((r) => { e[r] && (t[r] = U(t[r] || {}, e[r])); }), t) : e; } function rt(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 S(t, e) { try { e = t(); } catch (r) { Gt(r); } return e; } const Be = (t, e) => typeof t == "string" ? String(e) : typeof t == "number" ? Number(e) : e, Y = { "==": (t, e) => JSON.stringify(t) === JSON.stringify(Be(t, e)), "!=": (t, e) => !Y["=="](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(Be(t[0], e)) > -1; }, notOn(t, e) { return !Y.on(t, e); }, in(t, e) { return e && e.indexOf && e.indexOf(t) > -1; }, notIn(t, e) { return !Y.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 it() { return { props: {}, on: {}, options: [], children: [], effect: {}, hidden: !1, display: !0, value: void 0 }; } function F(t, e) { return (r, i, s, n = {}) => { const o = new Oe(t, r, i, s, n); return e && (h.Function(e) ? e(o) : o.props(e)), o; }; } function Oe(t, e, r, i, s) { this._data = p(it(), { type: t, title: e, field: r, value: i, props: s || {} }), this.event = this.on; } p(Oe.prototype, { getRule() { return this._data; }, setProp(t, e) { return w(this._data, t, e), this; }, _clone() { const t = new this.constructor(); return t._data = Ce(this._data), t; } }); function nt(t) { t.forEach((e) => { Oe.prototype[e] = function(r) { return U(this._data, { [e]: arguments.length < 2 ? r : { [r]: arguments[1] } }), this; }; }); } nt(xt()); const st = F(""); function Xt(t, e, r) { let i = st("", e); return i._data.type = t, i._data.title = r, i; } function Me(t, e, r, i) { let s = st("", r); return s._data.type = "template", s._data.template = t, s._data.title = i, s._data.vm = e, s; } function zt() { return { create: Xt, createTmp: Me, template: Me, factory: F }; } function Qt(t, e, r) { const i = `fail to ${t} ${r.status}'`, s = new Error(i); return s.status = r.status, s.url = t, s; } function Ne(t) { const e = t.responseText || t.response; if (!e) return e; try { return JSON.parse(e); } catch (r) { return e; } } function ot(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(Qt(r, t, e), Ne(e)); t.onSuccess(Ne(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 Zt(t) { return new Promise((e, r) => { ot(P(m({}, 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 W(t) { return M(t); } function er(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] = W(u.rule.value)), o; }, t.options.appendValue !== !1 ? W(t.appendData) : {}); }, getValue(n) { const o = t.getFieldCtx(n); if (o) return W(o.rule.value); }, coverValue(n) { const o = m({}, n || {}); t.deferSyncValue(() => { s.fields().forEach((a) => { const u = t.fieldCtx[a]; if (u) { const l = k(o, a); u.forEach((c) => { c.rule.value = l ? o[a] : void 0; }), delete o[a]; } }), p(t.appendData, o); }); }, setValue(n) { let o = n; arguments.length >= 2 && (o = { [n]: arguments[1] }), t.deferSyncValue(() => { Object.keys(o).forEach((a) => { const u = t.fieldCtx[a]; if (!u) return t.appendData[a] = o[a]; u.forEach((l) => { l.rule.value = o[a]; }); }); }); }, removeField(n) { const o = t.getCtx(n); return t.deferSyncValue(() => { t.getCtxs(n).forEach((a) => { a.rm(); }); }, !0), o ? o.origin : void 0; }, removeRule(n) { const o = n && Z(n); if (o) return o.rm(), o.origin; }, destroy: () => { t.vm.$el.parentNode && t.vm.$el.parentNode.removeChild(t.vm.$el), t.vm.$destroy(); }, fields: () => t.fields(), append: (n, o, a) => { let u = t.sort.length - 1, l; const c = t.getCtx(o); c ? a ? (l = c.rule.children, u = c.rule.children.length - 1) : (u = c.root.indexOf(c.origin), l = c.root) : l = t.rules, l.splice(u + 1, 0, n); }, prepend: (n, o, a) => { let u = 0, l; const c = t.getCtx(o); c ? a ? l = c.rule.children : (u = c.root.indexOf(c.origin), l = c.root) : l = t.rules, l.splice(u, 0, n); }, hidden(n, o) { r(o, "hidden", !!n), t.refresh(); }, hiddenStatus(n) { const o = t.getCtx(n); if (o) return !!o.rule.hidden; }, display(n, o) { r(o, "display", !!n), t.refresh(); }, displayStatus(n) { const o = t.getCtx(n); if (o) return !!o.rule.display; }, disabled(n, o) { e(o).forEach((a) => { t.getCtxs(a).forEach((u) => { u.rule.props && w(u.rule.props, "disabled", !!n); }); }), t.refresh(); }, all(n) { return Object.keys(t.ctxs).map((o) => { const a = t.ctxs[o]; return n ? a.origin : a.rule; }); }, model(n) { return t.fields().reduce((o, a) => { const u = t.fieldCtx[a][0]; return o[a] = n ? u.origin : u.rule, o; }, {}); }, component(n) { return Object.keys(t.nameCtx).reduce((o, a) => { const u = t.nameCtx[a].map((l) => n ? l.origin : l.rule); return o[a] = u.length === 1 ? u[0] : u, o; }, {}); }, bind() { return s.form; }, reload: (n) => { t.reloadRule(n); }, updateOptions(n) { t.fc.updateOptions(n), s.refresh(); }, onSubmit(n) { s.updateOptions({ onSubmit: n }); }, sync: (n) => { if (Array.isArray(n)) { n.forEach((a) => s.sync(a)); return; } let o = h.Object(n) ? Z(n) : t.getCtxs(n); o && (o = Array.isArray(o) ? o : [o], o.forEach((a) => { if (!a.deleted) { const u = t.subForm[a.id]; u && (Array.isArray(u) ? u.forEach((l) => { l.refresh(); }) : u && u.refresh()), t.$render.clearCache(a); } }), t.refresh()); }, refresh: () => { i().forEach((n) => { n.refresh(); }), t.$render.clearCacheAll(), t.refresh(); }, refreshOptions() { t.$manager.updateOptions(t.options), s.refresh(); }, hideForm: (n) => { w(t.vm, "isShow", !n); }, changeStatus: () => t.changeStatus, clearChangeStatus: () => { t.changeStatus = !1; }, updateRule(n, o) { t.getCtxs(n).forEach((a) => { p(a.rule, o); }); }, updateRules(n) { Object.keys(n).forEach((o) => { s.updateRule(o, n[o]); }); }, mergeRule: (n, o) => { t.getCtxs(n).forEach((a) => { U(a.rule, o); }); }, mergeRules(n) { Object.keys(n).forEach((o) => { s.mergeRule(o, n[o]); }); }, getRule: (n, o) => { const a = t.getCtx(n); if (a) return o ? a.origin : a.rule; }, getRenderRule: (n) => { const o = t.getCtx(n); if (o) return o.prop; }, getRefRule: (n) => { const o = t.getCtxs(n); if (o && o.length) { const a = o.map((u) => u.rule); return a.length === 1 ? a[0] : a; } }, setEffect(n, o, a) { const u = t.getCtx(n); u && o && (o[0] === "$" && (o = o.substr(1)), k(u.rule, "$" + o) && w(u.rule, "$" + o, a), k(u.rule, "effect") || w(u.rule, "effect", {}), w(u.rule.effect, o, a)); }, clearEffectData(n, o) { const a = t.getCtx(n); a && (o && o[0] === "$" && (o = o.substr(1)), a.clearEffectData(o), s.sync(n)); }, updateValidate(n, o, a) { a ? s.mergeRule(n, { validate: o }) : r(n, "validate", o); }, updateValidates(n, o) { Object.keys(n).forEach((a) => { s.updateValidate(a, n[a], o); }); }, refreshValidate() { t.vm.validate = {}, s.refresh(); }, resetFields(n) { e(n).forEach((o) => { t.getCtxs(o).forEach((a) => { t.$render.clearCache(a), a.rule.value = W(a.defaultValue); }); }), t.vm.$nextTick(() => { s.clearValidateState(); }), n == null && (h.Function(t.options.onReset) && S(() => t.options.onReset(s)), t.vm.$emit("reset", s)); }, method(n, o) { const a = s.el(n); if (!a || !a[o]) throw new Error(_e("err", `${o}方法不存在`)); return (...u) => a[o](...u); }, exec(n, o, ...a) { return S(() => s.method(n, o)(...a)); }, toJson(n) { return et(s.rule, n); }, trigger(n, o, ...a) { const u = s.el(n); u && u.$emit(o, ...a); }, el(n) { const o = t.getCtx(n); if (o) return o.exportEl || o.el || t.vm.$refs[o.ref]; }, closeModal: (n) => { const o = s.el(n); o && o.$emit && o.$emit("close-modal"); }, getSubForm(n) { const o = t.getCtx(n); return o ? t.subForm[o.id] : void 0; }, nextTick(n) { t.bus.$once("next-tick", n), t.refresh(); }, nextRefresh(n) { t.nextRefresh(), n && S(n); }, emit(n, ...o) { t.vm.$emit(n, ...o); }, deferSyncValue(n, o) { t.deferSyncValue(n, o); }, fetch(n) { return new Promise((o, a) => { t.beforeFetch(n).then(() => Zt(n).then(o).catch(a)); }); }, getData(n, o) { return t.fc.getData(n, o); }, setData(n, o) { return t.fc.setData(n, o); }, helper: { tidyFields: e, props: r } }; return ["on", "once", "off", "set", "emit"].forEach((n) => { s[n] = function(...o) { t.vm[`$${n}`](...o); }; }), s.changeValue = s.changeField = s.setValue, s; } function tr(t) { p(t.prototype, { initCache() { this.clearCacheAll(); }, clearCache(e) { if (e.rule.cache) return; if (!this.cache[e.id]) { e.parent && this.clearCache(e.parent); return; } (this.cache[e.id].use === !0 || this.cache[e.id].parent) && this.$handle.refresh(); const r = this.cache[e.id].parent; this.cache[e.id] = null, r && this.clearCache(r); }, clearCacheAll() { this.cache = {}; }, setCache(e, r, i) { this.cache[e.id] = { vnode: r, use: !1, parent: i, slot: e.rule.slot }; }, getCache(e) { const r = this.cache[e.id]; if (r) return r.use = !0, r.vnode; } }); } function R(t) { const e = t.replace(/(-[a-z])/g, function(r) { return r.replace("-", "").toLocaleUpperCase(); }); return at(e); } function at(t) { return t.replace(t[0], t[0].toLowerCase()); } function ee(t) { let e = t.replace(/([A-Z])/g, "-$1").toLocaleLowerCase(); return e.indexOf("-") === 0 && (e = e.substr(1)), e; } let rr = 0; function re() { const t = 370 + ++rr; return "F" + Math.random().toString(36).substr(3, 3) + (+`${Date.now()}`).toString(36) + t.toString(36) + "c"; } function te(t, e, r) { let i = t, s; return (e || "").split(".").forEach((n) => { s && ((!i[s] || typeof i[s] != "object") && (i[s] = {}), i = i[s]), s = n; }), i[s] = r, i; } function ir(t) { p(t.prototype, { initRender() { this.tempList = {}, this.clearOrgChildren(); }, initOrgChildren() { const e = this.$handle.ctxs; this.orgChildren = Object.keys(e).reduce((r, i) => { if (e[i].parser.loadChildren !== !1) { const s = e[i].rule.children;