/*! * 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 || (this.deferSyncFn.sync = r), R(e), this.deferSyncFn === e && (this.deferSyncFn = null, e.sync && this.syncValue()); }, syncValue() { if (this.deferSyncFn) return this.deferSyncFn.sync = !0; this.vm._updateValue($($({}, this.options.appendValue !== !1 ? this.appendData : {}), this.form)); }, isChange(e, r) { return JSON.stringify(e.rule.value, Se) !== JSON.stringify(r === null ? void 0 : r, Se); }, isQuote(e, r) { return (h.Object(r) || Array.isArray(r)) && r === e.rule.value; }, refreshUpdate(e, r, n, s) { if (h.Function(e.rule.update)) { const i = R(() => e.rule.update(r, e.origin, this.api, { origin: n || "change", linkField: s })); if (i === void 0) return; e.rule.hidden = i === !0; } }, valueChange(e, r) { this.refreshRule(e, r), this.bus.$emit("change-" + e.field, r); }, refreshRule(e, r, n, s) { this.refreshControl(e) && (this.$render.clearCacheAll(), this.loadRule(), this.vm.$emit("update", this.api), this.refresh()), this.refreshUpdate(e, r, n, s); }, appendLink(e) { const r = e.rule.link; h.trueArray(r) && r.forEach((n) => { const s = () => this.refreshRule(e, e.rule.value, "link", n); this.bus.$on("change-" + n, s), e.linkOn.push(() => this.bus.$off("change-" + n, s)); }); }, fields() { return Object.keys(this.fieldCtx); } }); } function Se(t, e) { return typeof e == "function" ? "" + e : e; } function Re(t) { Object.keys(t).forEach((e) => delete t[e]); } const re = { init(t) { }, toFormValue(t, e) { return t; }, toValue(t, e) { return t; }, mounted(t) { }, render(t, e) { return e.$render.defaultRender(e, t); }, preview(t, e) { return this.render(t, e); }, mergeProp(t) { } }, jt = ["field", "value", "vm", "template", "name", "config", "control", "inject", "sync", "payload", "optionsTo", "update", "component", "cache"]; function At(t) { p(t.prototype, { getCtx(e) { return this.getFieldCtx(e) || this.getNameCtx(e)[0] || this.ctxs[e]; }, getCtxs(e) { return this.fieldCtx[e] || this.nameCtx[e] || (this.ctxs[e] ? [this.ctxs[e]] : []); }, setIdCtx(e, r, n) { const s = `${n}Ctx`; this[s][r] ? this[s][r].push(e) : this[s][r] = [e]; }, rmIdCtx(e, r, n) { const s = `${n}Ctx`, i = this[s][r]; if (!i) return !1; const o = i.splice(i.indexOf(e) >>> 0, 1).length > 0; return i.length || delete this[s][r], o; }, getFieldCtx(e) { return (this.fieldCtx[e] || [])[0]; }, getNameCtx(e) { return this.nameCtx[e] || []; }, setCtx(e) { let { id: r, field: n, name: s, rule: i } = e; this.ctxs[r] = e, s && this.setIdCtx(e, s, "name"), e.input && (this.setIdCtx(e, n, "field"), this.setFormData(e, e.parser.toFormValue(i.value, e)), this.isMounted && !this.reloading && this.vm.$emit("change", e.field, i.value, e.origin, this.api)); }, getParser(e) { const r = this.fc.parsers; return r[e.originType] || r[S(e.type)] || r[e.trueType] || re; }, bindParser(e) { e.setParser(this.getParser(e)); }, getType(e) { const r = this.fc.CreateNode.aliasMap, n = r[e] || r[S(e)] || e; return S(n); }, noWatch(e) { this.noWatchFn || (this.noWatchFn = e), R(e), this.noWatchFn === e && (this.noWatchFn = null); }, watchCtx(e) { const r = this.vm; Object.keys(e.rule).filter((n) => n[0] !== "_" && n[0] !== "$" && jt.indexOf(n) === -1).forEach((n) => { const s = n === "children"; e.watch.push(r.$watch(() => e.rule[n], (i, o) => { if (!(this.loading || this.noWatchFn || this.reloading)) { if (s && e.parser.loadChildren === !1) { this.$render.clearCache(e), this.nextRefresh(); return; } if (this.watching = !0, n === "link") { e.link(); return; } else if (["props", "on", "nativeOn", "deep"].indexOf(n) > -1) this.parseInjectEvent(e.rule, i || {}), n === "props" && e.input && this.setFormData(e, e.parser.toFormValue(e.rule.value, e)); else if (["emit", "nativeEmit"].indexOf(n) > -1) this.parseEmit(e, n === "emit"); else if (["prefix", "suffix"].indexOf(n) > -1) i && this.loadFn(i, e.rule); else if (n === "type") e.updateType(), this.bindParser(e); else if (n === "children") { const a = h.trueArray(i); this.deferSyncValue(() => { i !== o && (this.rmSub(o, e), this.$render.initOrgChildren()), a && this.loadChildren(i, e), this.vm.$emit("update", this.api); }); } this.$render.clearCache(e), this.refresh(), this.watching = !1; } }, { deep: !s, sync: s })); }), this.watchEffect(e); }, rmSub(e, r) { h.trueArray(e) && e.forEach((n) => { n && n.__fc__ && n.__fc__.parent === r && this.rmCtx(n.__fc__); }); }, rmCtx(e) { if (e.deleted) return; const { id: r, field: n, input: s, name: i } = e; e.input && Object.defineProperty(e.rule, "value", { value: e.rule.value, writable: !0 }), k(this.ctxs, r), k(this.$render.tempList, r), k(this.$render.orgChildren, r), k(this.vm.ctxInject, r), k(this.formData, r), k(this.subForm, r), k(e, "cacheValue"), s && this.rmIdCtx(e, n, "field"), i && this.rmIdCtx(e, i, "name"), s && !F(this.fieldCtx, n) && k(this.form, n), this.deferSyncValue(() => { this.reloading || (e.parser.loadChildren !== !1 && h.trueArray(e.rule.children) && e.rule.children.forEach((a) => a.__fc__ && this.rmCtx(a.__fc__)), e.root === this.rules && this.vm._renderRule()); }, s); const o = this.sort.indexOf(r); return o > -1 && this.sort.splice(o, 1), this.$render.clearCache(e), e.delete(), this.effect(e, "deleted"), s && !this.fieldCtx[n] && this.vm.$emit("removeField", n, e.rule, this.api), e.rule.__ctrl || this.vm.$emit("removeRule", e.rule, this.api), e; } }); } function wt(t) { p(t.prototype, { mounted() { const e = () => { this.isMounted = !0, this.lifecycle("mounted"); }; this.pageEnd ? e() : this.bus.$once("page-end", e); }, lifecycle(e) { this.vm.$emit(e, this.api), this.emitEvent(e, this.api); }, targetReload() { this.bus.$off("next-tick", this.nextReload), this.bus.$once("next-tick", this.nextReload); }, emitEvent(e, ...r) { const n = this.options[e] || this.options[S("on-" + e)]; if (n) { const s = P(n); h.Function(s) && R(() => s(...r)); } this.bus.$emit(e, ...r); } }); } function kt(t) { p(t.prototype, { useProvider() { const e = this.fc.providers; Object.keys(e).forEach((r) => { let n = e[r]; h.Function(n) && (n = n(this.fc)), n._c = Pt(n), this.onEffect(n), this.providers[r] = n; }); }, onEffect(e) { const r = []; (e._c || ["*"]).forEach((n) => { const s = n === "*" ? "*" : this.getType(n); r.indexOf(s) > -1 || (r.push(s), this.bus.$on(`p:${e.name}:${s}:${e.input ? 1 : 0}`, (i, o) => { e[i] && e[i](...o); })); }), e._used = r; }, watchEffect(e) { const r = this.vm; let n = { required: () => { var s, i; return (F(e.rule, "$required") ? e.rule.$required : (i = (s = e.rule) == null ? void 0 : s.effect) == null ? void 0 : i.required) || !1; } }; Object.keys(e.rule.effect || {}).forEach((s) => { n[s] = () => e.rule.effect[s]; }), Object.keys(e.rule).forEach((s) => { s[0] === "$" && (n[s.substr(1)] = () => e.rule[s]); }), Object.keys(n || {}).forEach((s) => { e.watch.push(r.$watch(n[s], (i) => { this.effect(e, "watch", { [s]: i }); }, { deep: !0 })); }); }, ruleEffect(e, r, n) { this.emitEffect({ rule: e, input: !!e.field, type: this.getType(e.type) }, r, n); }, effect(e, r, n) { this.emitEffect({ rule: e.rule, input: e.input, type: e.trueType, ctx: e, custom: n }, r); }, getEffect(e, r) { if (F(e, "$" + r)) return e["$" + r]; if (F(e, "effect") && F(e.effect, r)) return e.effect[r]; }, emitEffect({ ctx: e, rule: r, input: n, type: s, custom: i }, o, a) { if (!s || s === "fcFragment") return; const l = i || Object.keys(r).reduce((u, d) => (d[0] === "$" && (u[d.substr(1)] = r[d]), u), $({}, r.effect || {})); Object.keys(l).forEach((u) => { const d = this.providers[u]; if (!d || d.input && !n) return; let m; if (!d._c) m = "*"; else if (d._used.indexOf(s) > -1) m = s; else return; const _ = $({ value: l[u], getValue: () => this.getEffect(r, u) }, a || {}); e && (_.getProp = () => e.effectData(u), _.clearProp = () => e.clearEffectData(u), _.mergeProp = (O) => D(_.getProp(), [O]), _.id = e.id), this.bus.$emit(`p:${u}:${m}:${d.input ? 1 : 0}`, o, [_, r, this.api]); }); } }); } function Vt(t) { return t.filter(function(e, r, n) { return n.indexOf(e, 0) === r; }); } function Pt(t) { const e = t.components; if (Array.isArray(e)) { const r = Vt(e.filter((n) => n !== "*")); return r.length ? r : !1; } else return h.String(e) ? [e] : !1; } function A(t) { p(this, { fc: t, vm: t.vm, watching: !1, loading: !1, reloading: !1, noWatchFn: null, deferSyncFn: null, isMounted: !1, formData: {}, subForm: {}, form: {}, appendData: {}, providers: {}, cycleLoad: null, loadedId: 1, nextTick: null, changeStatus: !1, pageEnd: !0, nextReload: () => { this.lifecycle("reload"); } }), Ie(this, { options() { return t.options; }, bus() { return t.bus; } }), this.initData(t.rules), this.$manager = new t.manager(this), this.$render = new fe(this), this.api = t.extendApi(ct(this), this); } p(A.prototype, { initData(t) { p(this, { ctxs: {}, fieldCtx: {}, nameCtx: {}, sort: [], rules: t }); }, init() { this.appendData = $($($({}, this.fc.options.formData || {}), this.vm.value || {}), this.appendData), this.useProvider(), this.usePage(), this.loadRule(), this.$manager.__init(), this.lifecycle("created"), this.vm.$set(this.vm, "formData", this.formData); }, beforeFetch(t) { return new Promise((e) => { const r = this.options.beforeFetch && R(() => this.options.beforeFetch(t, { api: this.api })); r && h.Function(r.then) ? r.then(e) : e(); }); } }); $t(A); _t(A); Ot(A); Et(A); Rt(A); At(A); wt(A); kt(A); const Dt = "fcFragment", z = { name: Dt, functional: !0, props: ["vnode"], render(t, e) { return e.props.vnode ? e.props.vnode : e.children; } }; function Tt(t) { return h.String(t) ? { domProps: { innerHTML: t } } : t; } function It() { const t = {}; function e(r) { r && this.setVm(r); } return p(e.prototype, { setVm(r) { this.vm = r, this.$h = r.$createElement; }, make(r, n, s) { return w.config.isReservedTag(r) && n.nativeOn && delete n.nativeOn, this.makeComponent(r, n, s); }, makeComponent(r, n, s) { let i = this.$h(r, Tt(n), s || []); return i.context = this.vm, i; }, aliasMap: t }), p(e, { aliasMap: t, alias(r, n) { t[r] = n; }, use(r) { Object.keys(r).forEach((n) => { const s = K(n), i = mt(n).toLocaleLowerCase(), o = r[n]; [n, s, i].forEach((a) => { e.alias(n, o), e.prototype[a] = function(l, u) { return this.make(o, l, u); }; }); }); } }), e; } function Nt(t) { class e extends Je { } return Object.assign(e.prototype, t), e; } function Je(t) { p(this, { $handle: t, vm: t.vm, options: {}, ref: "fcForm", mergeOptionsRule: { normal: ["form", "row", "info", "submitBtn", "resetBtn"] } }), this.updateKey(), this.init(); } p(Je.prototype, { __init() { this.$render = this.$handle.$render, this.$r = (...t) => this.$render.renderRule(...t); }, updateKey() { this.key = G(); }, //TODO interface init() { }, update() { }, beforeRender() { }, form() { return this.vm.$refs[this.ref]; }, getSlot(t) { const e = (r) => { if (r) { let n = r.$scopedSlots[t]; return n || e(r.$pfc); } }; return e(this.vm); }, mergeOptions(t, e) { return q(t.map((r) => this.tidyOptions(r)), e, this.mergeOptionsRule); }, updateOptions(t) { this.options = this.mergeOptions([t], this.getDefaultOptions()), this.update(); }, tidyOptions(t) { return t; }, tidyRule(t) { }, mergeProp(t) { }, getDefaultOptions() { return {}; }, render(t) { } }); const Lt = function(t) { const e = { name: "loadData", _fn: [], created(r, n, s) { this.deleted(r); let i = M(r.getValue()); const o = []; i.forEach((a) => { if (a) { const l = () => { a.watch !== !1 && (t.bus.$off("p.loadData." + a.attr, l), t.bus.$once("p.loadData." + a.attr, l)); let u; a.attr && (u = t.loadData[a.attr] || a.default, a.copy !== !1 && (u = T(u))), W(r.getProp(), a.to || "options", u), s.sync(n); }; o.push(() => t.bus.$off("p.loadData." + a.attr, l)), l(); } }), this._fn[r.id] = o; }, deleted(r) { this._fn[r.id] && (this._fn[r.id].forEach((n) => { n(); }), delete this._fn[r.id]), r.clearProp(); } }; return e.watch = e.created, e; }, He = { name: "componentValidate", load(t, e, r) { const n = t.getValue(); n ? t.getProp().validate = [{ validator(...s) { const i = H(e); if (i) return r.exec(i.id, n === !0 ? "formCreateValidate" : n, ...s, { attr: t, rule: e, api: r }); } }] : (t.clearProp(), r.clearValidateState([e.field])); }, watch(...t) { He.load(...t); } }, Mt = function(t) { function e(n) { return h.String(n) && (n = { action: n, to: "options" }), n; } function r(n, s, i) { let o = n.value; const a = (m) => { m === void 0 ? (n.clearProp(), i.sync(s)) : W(n.getProp(), o.to || "options", m); }; if (h.Function(o) && (o = o(s, i)), o = e(o), !o || !o.action) { a(void 0); return; } o = T(o), o.to || (o.to = "options"); const l = o.onError, u = () => { if (!n.getValue()) return n.clearProp(), i.sync(s), !0; }, d = N($({ headers: {} }, o), { onSuccess(m, _) { if (u()) return; let O = (y) => _ ? y : F(y, "data") ? y.data : y; h.Function(o.parse) ? O = o.parse : o.parse && h.String(o.parse) && (O = (y) => (o.parse.split(".").forEach((b) => { y && (y = y[b]); }), y)), a(O(m, s, i)), i.sync(s); }, onError(m) { a(void 0), !u() && (l || ((_) => oe(_.message || "fetch fail " + o.action)))(m, s, i); } }); t.$handle.beforeFetch(d, { rule: s, api: i }).then(() => { if (h.Function(o.action)) { o.action(s, i).then((m) => { d.onSuccess(m, !0); }).catch((m) => { d.onError(m); }); return; } R(() => t.create.fetch(d, { inject: n, rule: s, api: i })); }); } return { name: "fetch", loaded(...n) { r(...n); }, watch(...n) { r(...n); } }; }, Ke = { name: "required", load(t, e, r) { const n = qt(t.getValue()); if (n.required === !1) t.clearProp(), r.clearValidateState([e.field]); else { const s = $({ required: !0, validator(i, o, a) { h.empty(o) ? a(s.message) : a(); } }, n); if (!s.message) { let i = e.title || ""; s.message = ((typeof i == "object" ? i.title : i) || "") + "不能为空"; } t.getProp().validate = [s]; } r.sync(e); }, watch(...t) { Ke.load(...t); } }; function qt(t) { return h.Boolean(t) ? { required: t } : h.String(t) ? { message: t } : h.Undef(t) ? { required: !1 } : h.Function(t) ? { validator: t } : h.Object(t) ? t : {}; } const Ut = { fetch: Mt, loadData: Lt, required: Ke, componentValidate: He }, Bt = "html", Jt = { name: Bt, loadChildren: !1, render(t, e) { return e.prop.domProps || (e.prop.domProps = {}), e.prop.domProps.innerHTML = t, e.vNode.make(e.prop.props.tag || "div", e.prop); }, renderChildren(t) { return Array.isArray(t.rule.children) ? t.rule.children.filter((e) => h.String(e)).join("") : ""; } }; function Ht(t, e) { let r; return arguments.length === 2 ? (r = arguments[1], e = r[t]) : r = arguments[2], { id: e, prop: r }; } function Z() { return Ht("name", ...arguments); } function je(t) { return !t || !t.el ? window.document.body : h.Element(t.el) ? t.el : document.querySelector(t.el); } function Ae(t, e) { const r = new w({ data() { return { rule: t, option: e || {} }; }, render(n) { return n("FormCreate", { ref: "fc", props: this.$data }); } }); return r.$mount(), r; } function Kt(t) { const e = t.key || [], r = t.array || [], n = t.normal || []; Pe.push(...e), ne.push(...r), ie.push(...n), Le([...e, ...r, ...n]); } let Wt = 1; const v = {}; function Xt(t) { const e = { [z.name]: z }, r = {}, n = {}, s = $({}, Ut), i = ft(); let o = { global: {} }; const a = {}, l = It(), u = {}; Kt(t.attrs || {}); function d(f) { const c = v[f]; if (Array.isArray(c)) return c.map((g) => g.api()); if (c) return c.api(); } function m() { const f = Z(...arguments); f.id && f.prop && (n[f.id] = f.prop); } function _() { const f = Z(...arguments); f.id && f.prop && (s[f.id] = N($({}, f.prop), { name: f.id })); } function O(f) { l.use(f); } function y() { const f = Z(...arguments); if (!f.id || !f.prop) return re; const c = S(f.id), g = f.prop, C = g.merge === !0 ? r[c] : void 0; r[c] = g, Object.setPrototypeOf(g, C || re), i[c] = ue(c), g.maker && p(i, g.maker); } function b(f, c) { let g; if (h.String(f)) { if (g = S(f), ["form-create", "formcreate"].indexOf(g) > -1) return U(); if (c === void 0) return e[g]; } else g = S(f.name), c = f; if (!g || !c) return; const C = S(g); e[g] = c, e[C] = c, delete l.aliasMap[g], delete l.aliasMap[C], delete r[g], delete r[C], c.formCreateParser && y(g, c.formCreateParser); } function de(f) { Object.keys(v).forEach((c) => { (Array.isArray(v[c]) ? v[c] : [v[c]]).forEach((C) => { C.bus.$emit("p.loadData." + f); }); }); } function he(f, c) { a[f] = c, de(f); } function ce(f, c) { return F(a, f) ? a[f] : c; } function We(f) { delete a[f], de(f); } function U() { return rt(me, e, n); } function pe() { return z; } function Xe(f, c) { return h.Function(f.install) ? f.install(V, c) : h.Function(f) && f(V, c), this; } function V(f, c, g) { let C = Ae(f, c || {}); const j = C.$refs.fc.formCreate; return j.$parent = g, je(j.options).appendChild(C.$el), j.api(); } Object.setPrototypeOf(V, u); function Ge(f) { let c = $({}, t); return f ? c.inherit = { components: e, parsers: r, directives: n, providers: s, maker: i, loadData: a } : delete c.inherit, Xt(c); } function me(f) { const c = f.$options.propsData.rule; p(this, { id: Wt++, vm: f, create: V, manager: Nt(t.manager), parsers: r, providers: s, rules: Array.isArray(c) ? c : [], name: f.$options.propsData.name || G(), inFor: f.$options.propsData.inFor, prop: { components: e, directives: n }, setData: he, getData: ce, loadData: a, CreateNode: l, bus: new w(), unwatch: null, options: {}, extendApi: t.extendApi || ((g) => g) }), this.init(), this.initOptions(), this.name && (this.inFor ? (v[this.name] || (v[this.name] = []), v[this.name].push(this)) : v[this.name] = this); } p(me.prototype, { init() { const f = this.vm, c = new A(this); this.$handle = c, f.$f = c.api, f.$emit("input", c.api), f.$on("hook:created", () => { this.isSub() && (this.unwatch = f.$watch(() => f.$pfc.option, () => { this.initOptions(), f.$f.refresh(); }, { deep: !0 }), this.initOptions()), this.created(); }), f.$on("hook:mounted", () => { this.mounted(); }), f.$on("hook:beforeDestroy", () => { if (f.destroyed = !0, this.unwatch && this.unwatch(), c.reloadRule([]), this.name) if (this.inFor) { const g = v[this.name].indexOf(this); v[this.name].splice(g, 1), v[this.name].length || delete v[this.name]; } else delete v[this.name]; }), f.$on("hook:updated", () => { c.bindNextTick(() => this.bus.$emit("next-tick", c.api)); }); }, isSub() { return this.vm.$pfc && this.vm.extendOption; }, initOptions() { this.options = {}; let f = $({ formData: {}, submitBtn: {}, resetBtn: {} }, T(o)); this.isSub() && this.mergeOptions(this.options, this.vm.$pfc.$f.config || {}, !0), f = this.mergeOptions(f, this.vm.$options.propsData.option), this.updateOptions(f); }, mergeOptions(f, c, g) { return c = T(c), g && ["page", "onSubmit", "onReset", "onCreated", "onChange", "onMounted", "mounted", "onReload", "reload", "formData", "el"].forEach((C) => { delete c[C]; }), c.global && (f.global = ut(f.global, c.global), delete c.global), this.$handle.$manager.mergeOptions([c], f), f; }, updateOptions(f) { this.mergeOptions(this.options, f), this.$handle.$manager.updateOptions(this.options); }, created() { this.$handle.init(), this.vm.$emit("created", this.api()); }, api() { return this.$handle.api; }, render() { return this.$handle.render(); }, mounted() { this.$handle.mounted(); } }); function ye(f) { p(f, { version: t.version, ui: t.ui, setData: he, getData: ce, removeData: We, maker: i, component: b, directive: m, register: _, $vnode: pe, parser: y, use: Xe, factory: Ge, componentAlias: O, copyRule: ae, copyRules: Te, fetch: qe, $form: U, parseFn: P, parseJson: at, toJson: De, getApi: d, init(c, g = {}) { let C = Ae(c, g), j = C.$refs.fc.formCreate; return { mount(I) { return I && h.Element(I) && (j.options.el = I), je(j.options).appendChild(C.$el), j.api(); }, remove() { C.$el.parentNode && C.$el.parentNode.removeChild(C.$el); }, destroy() { this.remove(), C.$destroy(); }, $f: j.api() }; } }); } function Qe(f) { p(f, { create: V, install(c, g) { if (o = $($({}, o), g || {}), c._installedFormCreate === !0) return; c._installedFormCreate = !0; const C = function(j, I = {}) { return V(j, I, this); }; ye(C), c.prototype.$formCreate = C, c.component("FormCreate", U()), c.component("FcFragment", pe()); } }); } if (ye(u), Qe(u), l.use({ fragment: "fcFragment" }), y(Jt), t.install && V.use(t), t.inherit) { const f = t.inherit; f.components && p(e, f.components), f.parsers && p(r, f.parsers), f.directives && p(n, f.directives), f.providers && p(s, f.providers), f.maker && p(i, f.maker), f.loadData && p(a, f.loadData); } const B = U(); return Object.setPrototypeOf(B, u), Object.defineProperties(B, { fetch: { get() { return u.fetch; }, set(f) { u.fetch = f; } } }), B.util = u, B; } export { le as Creator, Je as Manager, ae as copyRule, Te as copyRules, ue as creatorFactory, Xt as default, z as fragment, D as mergeRule, at as parseJson, De as toJson };