UNPKG

@form-create/core

Version:

FormCreate低代码表单渲染引擎,可以通过 JSON 生成具有动态渲染、数据收集、验证和提交功能的低代码表单。支持6个UI框架,适配移动端,并且支持生成任何 Vue 组件。

1,667 lines (1,666 loc) 74.8 kB
/*! * FormCreate 低代码表单渲染器 * @form-create/core v2.6.3 * (c) 2018-2024 xaboy * Github https://github.com/xaboy/form-create * Site https://form-create.com/ * Released under the MIT License. */ var ze = Object.defineProperty, Ze = Object.defineProperties; var Ye = Object.getOwnPropertyDescriptors; var ge = Object.getOwnPropertySymbols; var xe = Object.prototype.hasOwnProperty, et = Object.prototype.propertyIsEnumerable; var $e = (t, e, r) => e in t ? ze(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, $ = (t, e) => { for (var r in e || (e = {})) xe.call(e, r) && $e(t, r, e[r]); if (ge) for (var r of ge(e)) et.call(e, r) && $e(t, r, e[r]); return t; }, N = (t, e) => Ze(t, Ye(e)); import w from "vue"; function E(t, e, r) { w.set(t, e, r); } function k(t, e) { w.delete(t, e); } const tt = Object.assign || function(t) { for (let e, r = 1; r < arguments.length; r++) for (let n in e = arguments[r], e) Object.prototype.hasOwnProperty.call(e, n) && E(t, n, e[n]); return t; }; function p() { return tt.apply(this, arguments); } function M(t) { return Array.isArray(t) ? t : [null, void 0, ""].indexOf(t) > -1 ? [] : [t]; } const _e = "FormCreate", Y = (t, e) => { if (!(!t || t === e)) { if (t.formCreateInject) return t.formCreateInject; if (t.$parent) return Y(t.$parent, e); } }; function rt(t, e, r) { return { name: _e, componentName: _e, 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(n) { this.destroyed || (this.updateValue = JSON.stringify(n), this.$emit("update:value", n)); } }, watch: { value: { handler(n) { JSON.stringify(n || {}) !== this.updateValue && (this.$f.config.forceCoverValue ? this.$f.coverValue(n || {}) : this.$f.setValue(n || {})); }, deep: !0 }, option: { handler() { this.formCreate.initOptions(), this.$f.refresh(); }, deep: !0 }, rule(n, s) { n.length === this.renderRule.length && n.every((i) => this.renderRule.indexOf(i) > -1) || (this.formCreate.$handle.reloadRule(n), this._renderRule(), n !== s && this.formCreate.$handle.targetReload()); }, disabled() { this.$f.refresh(); } }, beforeCreate() { this.formCreate = new t(this), Object.keys(this.formCreate.prop).forEach((n) => { p(this.$options[n], this.formCreate.prop[n]); }), this.$emit("beforeCreate", this.formCreate.api()); }, created() { const n = this, s = this.formCreate.api(), i = () => { if (n.$pfc) { const a = Y(n, n.$pfc); if (a) { let l; n.isMore ? (l = M(a.getSubForm()), l.push(s)) : l = s, a.subForm(l); } } }, o = () => { const a = Y(n, n.$pfc); if (a) if (n.isMore) { const l = M(a.getSubForm()), u = l.indexOf(s); u > -1 && l.splice(u, 1); } else a.subForm(); }; n.$on("hook:beforeDestroy", () => { o(); }), this.$watch(() => this.subForm, (a) => { a ? i() : o(); }, { immediate: !0 }); } }; } 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 F(t, e) { return {}.hasOwnProperty.call(t, e); } const we = ["attrs", "props", "domProps", "scopedSlots"], ke = ["class", "style", "directives"], Ve = ["on", "nativeOn"], q = (t, e = {}, r = {}) => { const n = [...we, ...r.normal || []], s = [...ke, ...r.array || []], i = [...Ve, ...r.functional || []], o = r.props || []; return t.reduce((a, l) => { for (const u in l) if (a[u]) if (o.indexOf(u) > -1) a[u] = q([l[u]], a[u]); else if (n.indexOf(u) > -1) a[u] = $($({}, a[u]), l[u]); else if (s.indexOf(u) > -1) { const d = a[u] instanceof Array ? a[u] : [a[u]], m = l[u] instanceof Array ? l[u] : [l[u]]; a[u] = [...d, ...m]; } else if (i.indexOf(u) > -1) for (const d in l[u]) if (a[u][d]) { const m = a[u][d] instanceof Array ? a[u][d] : [a[u][d]], _ = l[u][d] instanceof Array ? l[u][d] : [l[u][d]]; a[u][d] = [...m, ..._]; } else a[u][d] = l[u][d]; else if (u === "hook") for (let d in l[u]) a[u][d] ? a[u][d] = nt(a[u][d], l[u][d]) : a[u][d] = l[u][d]; else a[u] = l[u]; else n.indexOf(u) > -1 || i.indexOf(u) > -1 || o.indexOf(u) > -1 ? a[u] = $({}, l[u]) : s.indexOf(u) > -1 ? a[u] = l[u] instanceof Array ? [...l[u]] : typeof l[u] == "object" ? $({}, l[u]) : l[u] : a[u] = l[u]; return a; }, e); }, nt = (t, e) => function() { t && t.apply(this, arguments), e && e.apply(this, arguments); }, Pe = ["type", "slot", "emitPrefix", "value", "name", "native", "hidden", "display", "inject", "options", "emit", "nativeEmit", "link", "prefix", "suffix", "update", "sync", "optionsTo", "key", "preview", "component", "cache"], ne = ["validate", "children", "control"], ie = ["effect", "deep"]; function it() { return [...Pe, ...we, ...ke, ...Ve, ...ne, ...ie]; } function se(t, e, r) { return `[form-create ${t}]: ${e}`; } function st(t, e) { console.warn(se("tip", t)); } function oe(t, e) { console.error(se("err", t)); } function ot(t) { oe(t.toString()), console.error(t); } function X(t, e = {}, r) { let n = !1; for (let s in e) if (Object.prototype.hasOwnProperty.call(e, s)) { let i = e[s]; if ((n = Array.isArray(i)) || h.Object(i)) { let o = t[s] === void 0; if (n) n = !1, o && E(t, s, []); else if (i._clone && r !== void 0) if (r) i = i.getRule(), o && E(t, s, {}); else { E(t, s, i._clone()); continue; } else o && E(t, s, {}); t[s] = X(t[s], i, r); } else E(t, s, i), h.Undef(i) || (h.Undef(i.__json) || (t[s].__json = i.__json), h.Undef(i.__origin) || (t[s].__origin = i.__origin)); } return r !== void 0 && Array.isArray(t) ? t.filter((s) => !s || !s.__ctrl) : t; } function T(t) { return X({}, { value: t }).value; } const x = "[[FORM-CREATE-PREFIX-", ee = "-FORM-CREATE-SUFFIX]]"; function De(t, e) { return JSON.stringify(X(Array.isArray(t) ? [] : {}, t, !0), function(r, n) { if (!(n && n._isVue === !0)) { if (typeof n != "function") return n; if (n.__json) return n.__json; if (n.__origin && (n = n.__origin), !n.__emit) return x + n + ee; } }, e); } function Q(t) { return new Function("return " + t)(); } function P(t, e) { if (t && h.String(t) && t.length > 4) { let r = t.trim(), n = !1; try { if (r.indexOf(ee) > 0 && r.indexOf(x) === 0) r = r.replace(ee, "").replace(x, ""), n = !0; else if (r.indexOf("$FN:") === 0) r = r.substring(4), n = !0; else if (r.indexOf("$EXEC:") === 0) r = r.substring(6), n = !0; else if (r.indexOf("$GLOBAL:") === 0) { const i = r.substring(8); return r = function(...o) { const a = o[0].api.getGlobalEvent(i); if (a) return a.call(this, ...o); }, r.__json = t, r.__inject = !0, r; } else { if (r.indexOf("$FNX:") === 0) return r = Q("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(") && (n = !0); } if (!n) return t; let s; try { s = Q(r); } catch (i) { s = Q("function " + r); } return s.__json = t, s; } catch (s) { oe(`解析失败:${r} err: ${s}`); return; } } return t; } function at(t, e) { return JSON.parse(t, function(r, n) { return h.Undef(n) || !n.indexOf ? n : P(n, e); }); } function te(t, e) { return { value: t, enumerable: !1, configurable: !1, writable: !!e }; } function ae(t) { return Te([t])[0]; } function Te(t, e) { return X([], [...t], e || !1); } function D(t, e) { return q(Array.isArray(e) ? e : [e], t, { array: ne, normal: ie }), t; } function Ce(t) { const e = h.Function(t.getRule) ? t.getRule() : t; return e.type || (e.type = "input"), e; } function ut(t, e) { return t ? (Object.keys(e || {}).forEach((r) => { e[r] && (t[r] = D(t[r] || {}, e[r])); }), t) : e; } function Ie(t, e) { Object.defineProperties(t, Object.keys(e).reduce((r, n) => (r[n] = { get() { return e[n](); } }, r), {})); } function H(t) { return t.__fc__ || (t.__origin__ ? t.__origin__.__fc__ : null); } function R(t, e) { try { e = t(); } catch (r) { ot(r); } return e; } const Oe = (t, e) => typeof t == "string" ? String(e) : typeof t == "number" ? Number(e) : e, L = { "==": (t, e) => JSON.stringify(t) === JSON.stringify(Oe(t, e)), "!=": (t, e) => !L["=="](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(Oe(t[0], e)) > -1; }, notOn(t, e) { return !L.on(t, e); }, in(t, e) { return e && e.indexOf && e.indexOf(t) > -1; }, notIn(t, e) { return !L.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 Ne() { return { props: {}, on: {}, options: [], children: [], effect: {}, hidden: !1, display: !0, value: void 0 }; } function ue(t, e) { return (r, n, s, i = {}) => { const o = new le(t, r, n, s, i); return e && (h.Function(e) ? e(o) : o.props(e)), o; }; } function le(t, e, r, n, s) { this._data = p(Ne(), { type: t, title: e, field: r, value: n, props: s || {} }), this.event = this.on; } p(le.prototype, { getRule() { return this._data; }, setProp(t, e) { return E(this._data, t, e), this; }, _clone() { const t = new this.constructor(); return t._data = ae(this._data), t; } }); function Le(t) { t.forEach((e) => { le.prototype[e] = function(r) { return D(this._data, { [e]: arguments.length < 2 ? r : { [r]: arguments[1] } }), this; }; }); } Le(it()); const Me = ue(""); function lt(t, e, r) { let n = Me("", e); return n._data.type = t, n._data.title = r, n; } function be(t, e, r, n) { let s = Me("", r); return s._data.type = "template", s._data.template = t, s._data.title = n, s._data.vm = e, s; } function ft() { return { create: lt, createTmp: be, template: be, factory: ue }; } function dt(t, e, r) { const n = `fail to ${t} ${r.status}'`, s = new Error(n); return s.status = r.status, s.url = t, s; } function Ee(t) { const e = t.responseText || t.response; if (!e) return e; try { return JSON.parse(e); } catch (r) { return e; } } function qe(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(dt(r, t, e), Ee(e)); t.onSuccess(Ee(e)); }, e.open(t.method || "get", r, !0); let n; t.data && ((t.dataType || "").toLowerCase() !== "json" ? (n = new FormData(), Object.keys(t.data).map((i) => { n.append(i, t.data[i]); })) : (n = 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((i) => { s[i] !== null && e.setRequestHeader(i, s[i]); }), e.send(n); } function ht(t) { return new Promise((e, r) => { qe(N($({}, t), { onSuccess(n) { let s = (o) => o; const i = P(t.parse); h.Function(i) ? s = i : i && h.String(i) && (s = (o) => (i.split(".").forEach((a) => { o && (o = o[a]); }), o)), e(s(n)); }, onError(n) { r(n); } })); }); } function J(t) { return T(t); } function ct(t) { function e(i) { return h.Undef(i) ? i = t.fields() : Array.isArray(i) || (i = [i]), i; } function r(i, o, a) { e(i).forEach((l) => { t.getCtxs(l).forEach((u) => { E(u.rule, o, a), t.$render.clearCache(u); }); }); } function n() { const i = t.subForm; return Object.keys(i).reduce((o, a) => { const l = i[a]; return l && (Array.isArray(l) ? o.push(...l) : o.push(l)), 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 n(); }, formData(i) { return e(i).reduce((o, a) => { const l = t.getFieldCtx(a); return l && (o[l.field] = J(l.rule.value)), o; }, t.options.appendValue !== !1 ? J(t.appendData) : {}); }, getValue(i) { const o = t.getFieldCtx(i); if (o) return J(o.rule.value); }, coverValue(i) { const o = $({}, i || {}); t.deferSyncValue(() => { s.fields().forEach((a) => { const l = t.fieldCtx[a]; if (l) { const u = F(o, a); l.forEach((d) => { d.rule.value = u ? o[a] : void 0; }), delete o[a]; } }), p(t.appendData, o); }); }, setValue(i) { let o = i; arguments.length >= 2 && (o = { [i]: arguments[1] }), t.deferSyncValue(() => { Object.keys(o).forEach((a) => { const l = t.fieldCtx[a]; if (!l) return t.appendData[a] = o[a]; l.forEach((u) => { u.rule.value = o[a]; }); }); }); }, removeField(i) { const o = t.getCtx(i); return t.deferSyncValue(() => { t.getCtxs(i).forEach((a) => { a.rm(); }); }, !0), o ? o.origin : void 0; }, removeRule(i) { const o = i && H(i); 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: (i, o, a) => { let l = t.sort.length - 1, u; const d = t.getCtx(o); d ? a ? (u = d.rule.children, l = d.rule.children.length - 1) : (l = d.root.indexOf(d.origin), u = d.root) : u = t.rules, u.splice(l + 1, 0, i); }, prepend: (i, o, a) => { let l = 0, u; const d = t.getCtx(o); d ? a ? u = d.rule.children : (l = d.root.indexOf(d.origin), u = d.root) : u = t.rules, u.splice(l, 0, i); }, hidden(i, o) { r(o, "hidden", !!i), t.refresh(); }, hiddenStatus(i) { const o = t.getCtx(i); if (o) return !!o.rule.hidden; }, display(i, o) { r(o, "display", !!i), t.refresh(); }, displayStatus(i) { const o = t.getCtx(i); if (o) return !!o.rule.display; }, disabled(i, o) { e(o).forEach((a) => { t.getCtxs(a).forEach((l) => { l.rule.props && E(l.rule.props, "disabled", !!i); }); }), t.refresh(); }, all(i) { return Object.keys(t.ctxs).map((o) => { const a = t.ctxs[o]; return i ? a.origin : a.rule; }); }, model(i) { return t.fields().reduce((o, a) => { const l = t.fieldCtx[a][0]; return o[a] = i ? l.origin : l.rule, o; }, {}); }, component(i) { return Object.keys(t.nameCtx).reduce((o, a) => { const l = t.nameCtx[a].map((u) => i ? u.origin : u.rule); return o[a] = l.length === 1 ? l[0] : l, o; }, {}); }, bind() { return s.form; }, reload: (i) => { t.reloadRule(i); }, updateOptions(i) { t.fc.updateOptions(i), s.refresh(); }, onSubmit(i) { s.updateOptions({ onSubmit: i }); }, sync: (i) => { if (Array.isArray(i)) { i.forEach((a) => s.sync(a)); return; } let o = h.Object(i) ? H(i) : t.getCtxs(i); o && (o = Array.isArray(o) ? o : [o], o.forEach((a) => { if (!a.deleted) { const l = t.subForm[a.id]; l && (Array.isArray(l) ? l.forEach((u) => { u.refresh(); }) : l && l.refresh()), t.$render.clearCache(a); } }), t.refresh()); }, refresh: () => { n().forEach((i) => { i.refresh(); }), t.$render.clearCacheAll(), t.refresh(); }, refreshOptions() { t.$manager.updateOptions(t.options), s.refresh(); }, hideForm: (i) => { E(t.vm, "isShow", !i); }, changeStatus: () => t.changeStatus, clearChangeStatus: () => { t.changeStatus = !1; }, updateRule(i, o) { t.getCtxs(i).forEach((a) => { p(a.rule, o); }); }, updateRules(i) { Object.keys(i).forEach((o) => { s.updateRule(o, i[o]); }); }, mergeRule: (i, o) => { t.getCtxs(i).forEach((a) => { D(a.rule, o); }); }, mergeRules(i) { Object.keys(i).forEach((o) => { s.mergeRule(o, i[o]); }); }, getRule: (i, o) => { const a = t.getCtx(i); if (a) return o ? a.origin : a.rule; }, getRenderRule: (i) => { const o = t.getCtx(i); if (o) return o.prop; }, getRefRule: (i) => { const o = t.getCtxs(i); if (o && o.length) { const a = o.map((l) => l.rule); return a.length === 1 ? a[0] : a; } }, setEffect(i, o, a) { const l = t.getCtx(i); l && o && (o[0] === "$" && (o = o.substr(1)), F(l.rule, "$" + o) && E(l.rule, "$" + o, a), F(l.rule, "effect") || E(l.rule, "effect", {}), E(l.rule.effect, o, a)); }, clearEffectData(i, o) { const a = t.getCtx(i); a && (o && o[0] === "$" && (o = o.substr(1)), a.clearEffectData(o), s.sync(i)); }, updateValidate(i, o, a) { a ? s.mergeRule(i, { validate: o }) : r(i, "validate", o); }, updateValidates(i, o) { Object.keys(i).forEach((a) => { s.updateValidate(a, i[a], o); }); }, refreshValidate() { t.vm.validate = {}, s.refresh(); }, resetFields(i) { e(i).forEach((o) => { t.getCtxs(o).forEach((a) => { t.$render.clearCache(a), a.rule.value = J(a.defaultValue); }); }), t.vm.$nextTick(() => { s.clearValidateState(); }), i == null && (h.Function(t.options.onReset) && R(() => t.options.onReset(s)), t.vm.$emit("reset", s)); }, method(i, o) { const a = s.el(i); if (!a || !a[o]) throw new Error(se("err", `${o}方法不存在`)); return (...l) => a[o](...l); }, exec(i, o, ...a) { return R(() => s.method(i, o)(...a)); }, toJson(i) { return De(s.rule, i); }, trigger(i, o, ...a) { const l = s.el(i); l && l.$emit(o, ...a); }, el(i) { const o = t.getCtx(i); if (o) return o.exportEl || o.el || t.vm.$refs[o.ref]; }, closeModal: (i) => { const o = s.el(i); o && o.$emit && o.$emit("close-modal"); }, getSubForm(i) { const o = t.getCtx(i); return o ? t.subForm[o.id] : void 0; }, nextTick(i) { t.bus.$once("next-tick", i), t.refresh(); }, nextRefresh(i) { t.nextRefresh(), i && R(i); }, emit(i, ...o) { t.vm.$emit(i, ...o); }, deferSyncValue(i, o) { t.deferSyncValue(i, o); }, fetch(i) { return new Promise((o, a) => { t.beforeFetch(i).then(() => ht(i).then(o).catch(a)); }); }, getData(i, o) { return t.fc.getData(i, o); }, setData(i, o) { return t.fc.setData(i, o); }, helper: { tidyFields: e, props: r } }; return ["on", "once", "off", "set", "emit"].forEach((i) => { s[i] = function(...o) { t.vm[`$${i}`](...o); }; }), s.changeValue = s.changeField = s.setValue, s; } function pt(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, n) { this.cache[e.id] = { vnode: r, use: !1, parent: n, slot: e.rule.slot }; }, getCache(e) { const r = this.cache[e.id]; if (r) return r.use = !0, r.vnode; } }); } function S(t) { const e = t.replace(/(-[a-z])/g, function(r) { return r.replace("-", "").toLocaleUpperCase(); }); return Ue(e); } function Ue(t) { return t.replace(t[0], t[0].toLowerCase()); } function mt(t) { return t == null ? "" : typeof t == "object" ? JSON.stringify(t, null, 2) : String(t); } function K(t) { let e = t.replace(/([A-Z])/g, "-$1").toLocaleLowerCase(); return e.indexOf("-") === 0 && (e = e.substr(1)), e; } let yt = 0; function G() { const t = 370 + ++yt; return "F" + Math.random().toString(36).substr(3, 3) + (+`${Date.now()}`).toString(36) + t.toString(36) + "c"; } function W(t, e, r) { let n = t, s; return (e || "").split(".").forEach((i) => { s && ((!n[s] || typeof n[s] != "object") && (n[s] = {}), n = n[s]), s = i; }), n[s] = r, n; } function gt(t) { p(t.prototype, { initRender() { this.tempList = {}, this.clearOrgChildren(); }, initOrgChildren() { const e = this.$handle.ctxs; this.orgChildren = Object.keys(e).reduce((r, n) => { if (e[n].parser.loadChildren !== !1) { const s = e[n].rule.children; r[n] = h.trueArray(s) ? [...s] : []; } return r; }, {}); }, clearOrgChildren() { this.orgChildren = {}; }, getTypeSlot(e) { const r = (n) => { if (n) { let s; return e.rule.field && (s = n.$scopedSlots["field-" + K(e.rule.field)] || n.$scopedSlots["field-" + e.rule.field]), s || (s = n.$scopedSlots["type-" + K(e.type)] || n.$scopedSlots["type-" + e.type]), s || r(n.$pfc); } }; return r(this.vm); }, render() { if (!this.vm.isShow) return; this.$h = this.vm.$createElement, this.$manager.beforeRender(); let e; const r = () => this.renderList(); return r.renderSlot = (n) => this.renderList(n), r.renderName = (n) => this.renderId(n), r.renderField = (n) => this.renderId(n, "field"), this.vm.$scopedSlots.container ? e = [this.vm.$scopedSlots.container(r)] : e = r(), this.$manager.render(e); }, renderList(e) { return this.sort.map((r) => e ? this.renderSlot(this.$handle.ctxs[r], e) : this.renderCtx(this.$handle.ctxs[r])).filter((r) => r !== void 0); }, makeVm(e) { const r = e.vm; if (r) { if (h.Function(r)) return R(() => e.vm(this.$handle.getInjectData(e))); if (!r._isVue) return new w(r); } else return new w(); return r; }, mergeGlobal(e) { const r = this.$handle.options.global; r && (e.cacheConfig || (e.cacheConfig = r[e.originType] || r[e.type] || r[e.trueType] || {}), e.prop = D({}, [r["*"], e.cacheConfig, e.prop])); }, setOptions(e) { e.prop.optionsTo && e.prop.options && W(e.prop, e.prop.optionsTo, e.prop.options); }, deepSet(e) { const r = e.rule.deep; r && Object.keys(r).sort((n, s) => n.length < s.length ? -1 : 1).forEach((n) => { W(e.prop, n, r[n]); }); }, setTempProps(e, r) { if (!e.$props) return; const { prop: n } = r, s = Object.keys(e.$props), i = this.injectProp(r), o = Object.keys(i); s.forEach((l) => { F(n.props, l) ? e.$props[l] = n.props[l] : o.indexOf(l) > -1 && (e.$props[l] = i[l]); }); const a = e.$options.model && e.$options.model.prop || "value"; s.indexOf(a) > -1 && (e.$props[a] = n.value); }, renderTemp(e) { if (!w.compile) return st("当前使用的Vue构建版本不支持compile,无法使用template功能"), []; const r = e.prop, { id: n, key: s } = e; if (!this.tempList[n]) { e.el || (e.el = this.makeVm(r), this.vm.$nextTick(() => e.parser.mounted(e))); let l = e.el; e.input && l.$on(l.$options.model && l.$options.model.event || "input", (u) => { this.onInput(e, u); }), this.tempList[n] = { vm: l, template: w.compile(r.template) }; } const { vm: i, template: o } = this.tempList[n]; this.setTempProps(i, e); const a = o.render.call(i); return h.Undef(a.data) && (a.data = {}), a.key = s, a.data.ref = e.ref, a.data.key = s, a; }, parseSide(e, r) { return h.Object(e) ? D({ props: { formCreateInject: r.prop.props.formCreateInject } }, e) : e; }, renderSides(e, r, n) { const s = r[n ? "rule" : "prop"]; return [this.renderRule(this.parseSide(s.prefix, r)), e, this.renderRule(this.parseSide(s.suffix, r))]; }, renderSlot(e, r) { return e.rule.slot === r ? this.renderCtx(e) : void 0; }, renderId(e, r) { const n = this.$handle[r === "field" ? "fieldCtx" : "nameCtx"][e]; return n ? n.map((s) => this.renderCtx(s, s.parent)) : void 0; }, renderCtx(e, r) { if (e.type === "hidden") return; const n = e.rule; if (!this.cache[e.id] || this.cache[e.id].slot !== n.slot) { let s, i = n.cache !== !1; const o = e.trueType, a = !(h.Undef(n.display) || n.display); if (o === "template" && !n.template) s = this.renderSides(this.renderChildren(e), e, !0), a && this.display(s), s = this.item(e, s); else if (o === "fcFragment") s = this.renderChildren(e); else { e.initProp(), this.mergeGlobal(e), this.$manager.tidyRule(e), this.deepSet(e), this.setOptions(e), this.ctxProp(e); let l = e.prop; l.preview = !!(F(l, "preview") ? l.preview : this.options.preview), l.props.formCreateInject = this.injectProp(e); const u = l.preview; if (l.hidden) { this.setCache(e, void 0, r); return; } if (o === "template" && l.template) s = this.renderTemp(e), i = !1; else { let d = []; e.parser.renderChildren ? d = e.parser.renderChildren(e) : e.parser.loadChildren !== !1 && (d = this.renderChildren(e)); const m = this.getTypeSlot(e); m ? s = m({ rule: n, prop: l, preview: u, children: d, api: this.$handle.api, model: l.model || {} }) : s = u ? e.parser.preview(d, e) : e.parser.render(d, e); } s = this.renderSides(s, e), !(!e.input && h.Undef(l.native)) && l.native !== !0 && (s = this.$manager.makeWrap(e, s)), a && (s = this.display(s)), s = this.item(e, s); } return i && this.setCache(e, s, r), s; } return this.getCache(e); }, display(e) { if (Array.isArray(e)) { const r = []; return e.forEach((n) => { if (Array.isArray(n)) return this.display(n); this.none(n) && r.push(n); }), r; } else return this.none(e); }, none(e) { if (e && e.data) return Array.isArray(e.data.style) ? e.data.style.push({ display: "none" }) : h.String(e.data.style) ? e.data.style += ";display:none;" : e.data.style = [e.data.style, { display: "none" }], e; }, item(e, r) { return this.$h("fcFragment", { slot: e.rule.slot, key: e.key }, [r]); }, injectProp(e) { this.vm.ctxInject[e.id] || E(this.vm.ctxInject, e.id, { api: this.$handle.api, form: this.fc.create, subForm: (n) => { this.$handle.addSubForm(e, n); }, getSubForm: () => this.$handle.subForm[e.id], options: [], children: [], prop: {}, preview: !1, id: e.id, field: e.field, rule: e.rule, input: e.input }); const r = this.vm.ctxInject[e.id]; return p(r, { preview: e.prop.preview, options: e.prop.options, children: e.rule.children, prop: function() { const n = $({}, e.prop); return n.on = n.on ? $({}, n.on) : {}, delete n.model, n; }() }), r; }, ctxProp(e) { const { ref: r, key: n, rule: s } = e; this.$manager.mergeProp(e), e.parser.mergeProp(e); const i = [ { ref: r, key: s.key || `${n}fc`, slot: void 0, on: { "hook:mounted": () => { this.onMounted(e); }, "fc.sub-form": (o) => { this.$handle.addSubForm(e, o); }, "fc.el": (o) => { e.exportEl = o, o && ((o.$el || o).__rule__ = e.rule); } } } ]; return e.input && (this.vm.$props.disabled === !0 && (e.prop.props.disabled = !0), e.prop.model = { value: this.$handle.getFormData(e), callback: (o) => { this.onInput(e, o); }, expression: `formData.${e.id}` }), q(i, e.prop), e.prop; }, onMounted(e) { e.el = this.vm.$refs[e.ref], e.el && ((e.el.$el || e.el).__rule__ = e.rule), e.parser.mounted(e), this.$handle.effect(e, "mounted"); }, onInput(e, r) { this.$handle.onInput(e, r); }, renderChildren(e) { const { children: r } = e.rule, n = this.orgChildren[e.id], s = (i) => !h.String(i) && i.__fc__ && !this.$handle.ctxs[i.__fc__.id]; return !h.trueArray(r) && n ? (this.$handle.deferSyncValue(() => { n.forEach((i) => { i && s(i) && this.$handle.rmCtx(i.__fc__); }); }), this.orgChildren[e.id] = [], []) : (n && this.$handle.deferSyncValue(() => { n.forEach((i) => { i && r.indexOf(i) === -1 && s(i) && this.$handle.rmCtx(i.__fc__); }); }), r.map((i) => { if (i) { if (h.String(i)) return i; if (i.__fc__) return this.renderCtx(i.__fc__, e); i.type && this.vm.$nextTick(() => { this.$handle.loadChildren(r, e), this.$handle.refresh(); }); } })); }, defaultRender(e, r) { const n = e.prop; return n.component ? this.vNode.makeComponent(n.component, n, r) : this.vNode[e.type] ? this.vNode[e.type](n, r) : this.vNode[e.originType] ? this.vNode[e.originType](n, r) : this.vNode.make(Ue(e.originType), n, r); }, renderRule(e, r, n) { if (!e) return; if (h.String(e)) return e; let s; if (n) s = e.type; else if (s = e.is, e.type) { s = S(e.type); const o = this.vNode.aliasMap[s]; o && (s = S(o)); } if (!s) return; let i = [[r]]; return h.trueArray(e.children) && i.push(e.children.map((o) => this.renderRule(o))), this.$h(s, $({}, e), i); } }); } function fe(t) { p(this, { $handle: t, fc: t.fc, vm: t.vm, $manager: t.$manager, vNode: new t.fc.CreateNode(t.vm) }), Ie(this, { options() { return t.options; }, sort() { return t.sort; } }), this.initCache(), this.initRender(); } pt(fe); gt(fe); function $t(t) { p(t.prototype, { parseInjectEvent(e, r) { const n = e.inject || this.options.injectEvent; return this.parseEventLst(e, r, n); }, parseEventLst(e, r, n, s) { return Object.keys(r).forEach((i) => { const o = this.parseEvent(e, r[i], n, s); o && (r[i] = o); }), r; }, parseEvent(e, r, n, s) { if (h.Function(r) && (n !== !1 && !h.Undef(n) || r.__inject)) return this.inject(e, r, n); if (!s && Array.isArray(r) && r[0] && (h.String(r[0]) || h.Function(r[0]))) return this.parseEventLst(e, r, n, !0); if (h.String(r)) { const i = P(r); if (i && r !== i) return i.__inject ? this.parseEvent(e, i, n, !0) : i; } }, parseEmit(e, r) { let n = {}, s = e.rule, { emitPrefix: i, field: o, name: a, inject: l } = s, u = s[r ? "emit" : "nativeEmit"] || []; return h.trueArray(u) && u.forEach((d) => { if (!d) return; let m, _ = i || o || a; if (h.Object(d) && (m = d.inject, d = d.name, _ = d.prefix || _), _) { r || (_ = `native-${_}`); const O = K(`${_}-${d}`), y = (...b) => { this.vm.$emit(O, ...b), this.vm.$emit("emit-event", O, ...b); }; if (y.__emit = !0, !m && l === !1) n[d] = y; else { let b = m || l || this.options.injectEvent; n[d] = h.Undef(b) ? y : this.inject(s, y, b); } } }), e.computed[r ? "on" : "nativeOn"] = n, n; }, getInjectData(e, r) { const { option: n, rule: s } = this.vm.$options.propsData; return { api: this.api, $f: this.api, rule: s, self: e.__origin__, option: n, inject: r }; }, inject(e, r, n) { if (r.__origin) { if (this.watching && !this.loading) return r; r = r.__origin; } const s = this, i = function(...o) { const a = s.getInjectData(e, n); return a.args = [...o], o.unshift(a), r.apply(this, o); }; return i.__origin = r, i.__json = r.__json, i; } }); } const ve = ["hook:updated", "hook:mounted"]; function _t(t) { p(t.prototype, { usePage() { const e = this.options.page; if (!e) return; let r = 25, n = Ct(this.rules); h.Object(e) && (e.first && (r = parseInt(e.first, 10) || r), e.limit && (n = parseInt(e.limit, 10) || n)), p(this, { first: r, limit: n, pageEnd: this.rules.length <= r }), this.bus.$on("page-end", () => this.vm.$emit("page-end", this.api)), this.pageLoad(); }, pageLoad() { const e = () => { this.pageEnd ? (this.vm.$off(ve, e), this.bus.$emit("page-end")) : (this.first += this.limit, this.pageEnd = this.rules.length <= this.first, this.loadRule(), this.refresh()); }; this.vm.$on(ve, e); } }); } function Ct(t) { return t.length < 31 ? 31 : Math.ceil(t.length / 3); } function Ot(t) { p(t.prototype, { clearNextTick() { this.nextTick && clearTimeout(this.nextTick), this.nextTick = null; }, bindNextTick(e) { this.clearNextTick(), this.nextTick = setTimeout(() => { e(), this.nextTick = null; }, 10); }, render() { return ++this.loadedId, this.vm.unique > 0 ? this.$render.render() : (this.vm.unique = 1, []); } }); } function bt(t) { Object.defineProperties(t.origin, { __fc__: te(t, !0) }), t.rule !== t.origin && Object.defineProperties(t.rule, { __fc__: te(t, !0) }); } function Be(t, e, r) { const n = G(); p(this, { id: n, ref: n, wrapRef: n + "fi", rule: e, origin: e.__origin__ || e, name: e.name, watch: [], linkOn: [], root: [], ctrlRule: [], parent: null, cacheConfig: null, prop: $({}, e), computed: {}, payload: {}, input: !!e.field, el: void 0, exportEl: void 0, defaultValue: e.field ? T(r) : void 0, field: e.field || void 0 }), this.updateKey(), bt(this), this.update(t, !0); } p(Be.prototype, { effectData(t) { return this.payload[t] || (this.payload[t] = {}), this.payload[t]; }, clearEffectData(t) { t === void 0 ? this.payload = {} : delete this.payload[t]; }, updateKey(t) { this.key = G(), t && this.parent && this.parent.updateKey(t); }, updateType() { this.originType = this.rule.type, this.type = S(this.rule.type), this.trueType = this.$handle.getType(this.originType); }, setParser(t) { this.parser = t, t.init(this); }, initProp() { const t = $({}, this.rule); delete t.children, this.prop = D({}, [t, ...Object.keys(this.payload).map((e) => this.payload[e]), this.computed]); }, injectValidate() { return M(this.prop.validate).map((t) => { if (h.Function(t.validator)) { const e = $({}, t), r = this; return e.validator = function(...n) { return t.validator.call({ that: this, id: r.id, field: r.field, rule: r.rule, api: r.$handle.api }, ...n); }, e; } return t; }); }, check(t) { return this.vm === t.vm; }, unwatch() { this.watch.forEach((t) => t()), this.watch = []; }, unlink() { this.linkOn.forEach((t) => t()), this.linkOn = []; }, link() { this.unlink(), this.$handle.appendLink(this); }, watchTo() { this.$handle.watchCtx(this); }, delete() { this.unwatch(), this.unlink(), this.rmCtrl(), p(this, { deleted: !0, prop: $({}, this.rule), computed: {}, el: void 0, $handle: void 0, $render: void 0, $api: void 0, vm: void 0, vNode: void 0, parent: null, cacheConfig: null }); }, rmCtrl() { this.ctrlRule.forEach((t) => t.__fc__ && t.__fc__.rm()), this.ctrlRule = []; }, rm() { const t = () => { let e = this.root.indexOf(this.origin); e > -1 && (this.root.splice(e, 1), this.$handle && this.$handle.refresh()); }; if (this.deleted) { t(); return; } this.$handle.noWatch(() => { this.$handle.deferSyncValue(() => { this.rmCtrl(), t(), this.$handle.rmCtx(this), p(this, { root: [] }); }, this.input); }); }, update(t, e) { p(this, { deleted: !1, $handle: t, $render: t.$render, $api: t.api, vm: t.vm, vNode: t.$render.vNode, updated: !1, cacheValue: this.rule.value }), !e && this.unwatch(), this.watchTo(), this.link(), this.updateType(); } }); function Et(t) { p(t.prototype, { nextRefresh(e) { const r = this.loadedId; this.vm.$nextTick(() => { r === this.loadedId && (e ? e() : this.refresh()); }); }, parseRule(e) { const r = Ce(e); return Object.defineProperties(r, { __origin__: te(e, !0) }), vt(r), this.appendValue(r), r.options = Array.isArray(r.options) ? r.options : [], [r, r.prefix, r.suffix].forEach((n) => { n && this.loadFn(n, r); }), this.loadCtrl(r), r.update && (r.update = P(r.update)), r; }, loadFn(e, r) { ["on", "props", "nativeOn", "deep"].forEach((n) => { e[n] && this.parseInjectEvent(r, e[n]); }); }, loadCtrl(e) { e.control && e.control.forEach((r) => { r.handle && (r.handle = P(r.handle)); }); }, syncProp(e) { const r = e.rule; h.trueArray(r.sync) && q([{ on: r.sync.reduce((n, s) => (n[`update:${s}`] = (i) => { r.props[s] = i, this.vm.$emit("sync", s, i, r, this.fapi); }, n), {}) }], e.computed); }, loadRule() { this.cycleLoad = !1, this.loading = !0, this.pageEnd && this.bus.$emit("load-start"), this.deferSyncValue(() => { if (this._loadRule(this.rules), this.loading = !1, this.cycleLoad && this.pageEnd) return this.loadRule(); this.pageEnd && this.bus.$emit("load-end"), this.vm._renderRule(), this.$render.initOrgChildren(), this.syncForm(); }); }, loadChildren(e, r) { if (this.cycleLoad = !1, this.loading = !0, this.bus.$emit("load-start"), this._loadRule(e, r), this.loading = !1, this.cycleLoad) return this.loadRule(); this.bus.$emit("load-end"), this.syncForm(), this.$render.clearCache(r); }, _loadRule(e, r) { const n = (i) => { let o = e[i - 1]; if (!o || !o.__fc__) return i > 0 ? n(i - 1) : -1; let a = this.sort.indexOf(o.__fc__.id); return a > -1 ? a : n(i - 1); }, s = (i, o) => { h.trueArray(i) && this._loadRule(i, o); }; e.map((i, o) => { if (r && !h.Object(i) || !this.pageEnd && !r && o >= this.first) return; if (i.__fc__ && i.__fc__.root === e && this.ctxs[i.__fc__.id]) return s(i.__fc__.rule.children, i.__fc__), i.__fc__; let a = Ce(i); const l = () => !!(a.field && this.fieldCtx[a.field] && this.fieldCtx[a.field][0] !== i.__fc__); this.ruleEffect(a, "init", { repeat: l() }), l() && this.vm.$emit("repeat-field", i, this.api); let u, d = !1, m = !!i.__fc__, _ = a.value; if (m) { u = i.__fc__, _ = u.defaultValue; const y = !u.check(this); if (u.deleted) { if (y) { if (Fe(u)) return; u.update(this); } } else if (y) { if (Fe(u)) return; e[o] = i = i._clone ? i._clone() : ae(i), u = null, d = !0; } } if (u) u.originType !== u.rule.type && u.updateType(), this.bindParser(u), this.appendValue(u.rule); else { const y = this.parseRule(i); u = new Be(this, y, _), this.bindParser(u); } if ([!1, !0].forEach((y) => this.parseEmit(u, y)), this.syncProp(u), u.parent = r || null, u.root = e, this.setCtx(u), !d && !m && this.effect(u, "load"), this.effect(u, "created"), u.parser.loadChildren === !1 || s(u.rule.children, u), !r) { const y = n(o); y > -1 || !o ? this.sort.splice(y + 1, 0, u.id) : this.sort.push(u.id); } const O = u.rule; return u.updated || (u.updated = !0, h.Function(O.update) && this.bus.$once("load-end", () => { this.refreshUpdate(u, O.value, "init"); }), this.effect(u, "loaded")), u.input && Object.defineProperty(O, "value", this.valueHandle(u)), this.refreshControl(u) && (this.cycleLoad = !0), u; }); }, refreshControl(e) { return e.input && e.rule.control && this.useCtrl(e); }, useCtrl(e) { const r = Ft(e), n = [], s = this.api; if (!r.length) return !1; for (let a = 0; a < r.length; a++) { const l = r[a], u = l.handle || function(m) { return (L[l.condition || "=="] || L["=="])(m, l.value); }; if (!h.trueArray(l.rule)) continue; const d = N($({}, l), { valid: R(() => u(e.rule.value, s)), ctrl: St(e, l.rule), isHidden: h.String(l.rule[0]) }); d.valid && d.ctrl || !d.valid && !d.ctrl && !d.isHidden || n.push(d); } if (!n.length) return !1; const i = []; let o = !1; return this.deferSyncValue(() => { n.reverse().forEach(({ isHidden: a, valid: l, rule: u, prepend: d, append: m, child: _, ctrl: O, method: y }) => { if (a) { l ? e.ctrlRule.push({ __ctrl: !0, children: u, valid: l }) : O && e.ctrlRule.splice(e.ctrlRule.indexOf(O) >>> 0, 1), i[l ? "push" : "unshift"](() => { y === "disabled" || y === "enabled" ? this.api.disabled(!l, u) : y === "display" ? this.api.display(l, u) : y === "required" ? (u.forEach((b) => { this.api.setEffect(b, "required", l); }), l || this.api.clearValidateState(u)) : this.api.hidden(!l, u); }); return; } if (l) { o = !0; const b = { type: "fcFragment", native: !0, __ctrl: !0, children: u }; e.ctrlRule.push(b), this.bus.$once("load-start", () => { d ? s.prepend(b, d, _) : m || _ ? s.append(b, m || e.id, _) : e.root.splice(e.root.indexOf(e.origin) + 1, 0, b); }); } else { e.ctrlRule.splice(e.ctrlRule.indexOf(O), 1); const b = H(O); b && b.rm(); } }); }), i.length && this.vm.$nextTick(() => { i.forEach((a) => a()); }), this.vm.$emit("control", e.origin, this.api), this.effect(e, "control"), o; }, reloadRule(e) { return this._reloadRule(e); }, _reloadRule(e) { e || (e = this.rules); const r = $({}, this.ctxs); this.clearNextTick(), this.$render.clearOrgChildren(), this.initData(e), this.fc.rules = e, this.deferSyncValue(() => { this.bus.$once("load-end", () => { Object.keys(r).filter((n) => this.ctxs[n] === void 0).forEach((n) => this.rmCtx(r[n])), this.$render.clearCacheAll(); }), this.reloading = !0, this.loadRule(), this.reloading = !1, this.refresh(), this.vm.$emit("reloading", this.api); }), this.vm.$emit("update", this.api); }, //todo 组件生成全部通过 alias refresh() { this.vm._refresh(); } }); } function vt(t) { const e = Ne(); return Object.keys(e).forEach((r) => { F(t, r) || E(t, r, e[r]); }), t; } function Ft(t) { const e = t.rule.control || []; return h.Object(e) ? [e] : e; } function St(t, e) { for (let r = 0; r < t.ctrlRule.length; r++) { const n = t.ctrlRule[r]; if (n.children === e) return n; } } function Fe(t) { return !!t.rule.__ctrl; } function Rt(t) { p(t.prototype, { getValue(e) { return h.Undef(e.cacheValue) && (e.cacheValue = e.parser.toValue(this.getFormData(e), e)), e.cacheValue; }, setValue(e, r, n, s) { e.deleted || (e.cacheValue = r, this.changeStatus = !0, this.nextRefresh(), this.$render.clearCache(e), this.setFormData(e, n), this.syncValue(), this.valueChange(e, r), this.vm.$emit("change", e.field, r, e.origin, this.api, s || !1), this.effect(e, "value"), this.emitEvent("change", e.field, r, { rule: e.origin, api: this.api, setFlag: s || !1 })); }, onInput(e, r) { let n; e.input && (this.isQuote(e, n = e.parser.toValue(r, e)) || this.isChange(e, n)) && this.setValue(e, n, r); }, setFormData(e, r) { E(this.formData, e.id, r === null ? void 0 : r); }, getFormData(e) { return this.formData[e.id]; }, validate() { return Re(this.vm.validate), this.fields().forEach((e) => { this.fieldCtx[e].forEach((r) => { this.vm.validate[r.id] = M(r.rule.validate); }); }), this.vm.validate; }, syncForm() { Re(this.form), Object.defineProperties(this.form, this.fields().reduce((e, r) => { const n = this.getFieldCtx(r), s = this.valueHandle(n); return s.configurable = !0, e[r] = s, e; }, this.options.appendValue !== !1 ? Object.keys(this.appendData).reduce((e, r) => (e[r] = { enumerable: !0, configurable: !0, get: () => this.appendData[r], set: (n) => { this.appendData[r] = n; } }, e), {}) : {})), this.syncValue(); }, valueHandle(e) { return { enumerable: !0, get: () => this.getValue(e), set: (r) => { this.isChange(e, r) && this.setValue(e, r, e.parser.toFormValue(r, e), !0); } }; }, appendValue(e) { !e.field || !F(this.appendData, e.field) || (e.value = this.appendData[e.field], delete this.appendData[e.field]); }, addSubForm(e, r) { this.subForm[e.id] = r; }, deferSyncValue(e, r) { this.deferSyncFn || (this.deferSyncFn = e), this.deferSyncFn.sync || (t