UNPKG

@farris/ui-vue

Version:

Farris Vue, a Farris Design based Vue3 component library.

1,520 lines 64.5 kB
var ie = Object.defineProperty; var ne = (o, n, e) => n in o ? ie(o, n, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[n] = e; var y = (o, n, e) => ne(o, typeof n != "symbol" ? n + "" : n, e); import { computed as M, ref as B, createVNode as E, defineComponent as J, onMounted as Q, watch as G, createTextVNode as Y, nextTick as se, inject as K } from "vue"; import { resolveAppearance as re, createPropsResolver as oe } from "../dynamic-resolver/index.esm.js"; import I from "bignumber.js"; import { useNumberLocales as le } from "../number-spinner/index.esm.js"; import { DgControl as p, canvasChanged as U, refreshCanvas as ae, useDesignerComponent as de } from "../designer-canvas/index.esm.js"; import { cloneDeep as ue } from "lodash-es"; import { FormSchemaEntityField$Type as Z, FormSchemaEntityFieldType$Type as ce, withInstall as pe } from "../common/index.esm.js"; function ge(o, n, e) { return n; } const me = /* @__PURE__ */ new Map([ ["appearance", re] ]), fe = "https://json-schema.org/draft/2020-12/schema", he = "https://farris-design.gitee.io/number-range.schema.json", ye = "number-range", be = "A Farris Component", ve = "object", Ce = { id: { description: "The unique identifier for a number-range", type: "string" }, type: { description: "The type string of number-range component", type: "string", default: "number-range" }, appearance: { description: "", type: "object", properties: { class: { type: "string" }, style: { type: "string" } }, default: {} }, binding: { description: "", type: "object", default: {} }, disabled: { type: "boolean", default: !1 }, editable: { description: "", type: "boolean", default: !0 }, placeholder: { description: "", type: "string", default: "" }, readonly: { description: "", type: "boolean", default: !1 }, required: { description: "", type: "boolean", default: !1 }, precision: { description: "", type: "number", default: 0 }, tabindex: { description: "", type: "number", default: -1 }, visible: { description: "", type: "boolean", default: !0 }, beginValue: { description: "", type: "number" }, endValue: { description: "", type: "number" }, nullable: { description: "", type: "boolean", default: !1 }, min: { description: "", type: "string" }, max: { description: "", type: "string" }, beginPlaceholder: { description: "", type: "string" }, endPlaceholder: { description: "", type: "string" }, textAlign: { description: "", type: "string", enum: [ "left", "middle", "right" ], default: "left" } }, xe = [ "type" ], we = { $schema: fe, $id: he, title: ye, description: be, type: ve, properties: Ce, required: xe }, W = { /** * 组件标识 */ id: String, /** * 自动补全小数 */ autoDecimal: { type: Boolean, default: !0 }, /** * 下限placeholder---未实现 */ beginPlaceholder: { type: String, default: "开始数字" }, /** * 下限值 */ beginValue: { type: [Number, String], default: "" }, /** * 启用大数支持 */ bigNumber: { type: Boolean, default: !1 }, /** * 允许为空 */ nullable: { type: Boolean, default: !1 }, /** * 小数点符号 */ decimalSeparator: { type: String, default: "." }, /** * 是否禁用 */ disabled: { type: Boolean, default: !1 }, /** * 是否可编辑 */ editable: { type: Boolean, default: !0 }, /** * 上限placeholder---未实现 */ endPlaceholder: { type: String, default: "结束数字" }, /** * 上限值 */ endValue: { type: [Number, String], default: "" }, /** * 格式化 formatter 和 parser 必须同时存在 * formatter: (val: number) => string; * parser: (val: string | number) => number; */ formatter: { type: Function }, /** * 千分位符号 */ groupSeparator: { type: String, default: "," }, /** * 使用千分位时,每组显示的字符数 */ groupSize: { type: Number, default: 3 }, /** * 最大值 */ max: { type: [Number, String] }, /** * 最小值 */ min: { type: [Number, String] }, parser: { type: Function }, /** * 空白提示文本 */ placeholder: { type: String, default: "请输入数字" }, /** * 精度 */ precision: { type: Number, default: 0 }, /** * 前缀 */ prefix: { type: String, default: "" }, /** * 是否只读 */ readonly: { type: Boolean, default: !1 }, /** * 间隔符---未实现 */ separator: { type: String, default: "~" }, /** * 是否显示加减按钮 */ showButton: { type: Boolean, default: !0 }, /** * 显示0值 */ showZero: { type: Boolean, default: !0 }, /** * up or down 步长 */ step: { type: Number, default: 1 }, /** * 后缀 */ suffix: { type: String, default: "" }, /** * 文本方向 */ textAlign: { type: String, default: "left" }, /** * 是否使用千分值 */ useThousands: { type: Boolean, default: !0 } }, D = oe(W, we, me, ge); function ee(o, n) { const e = M(() => Number(o.precision) || 0); function t(l) { return l.toFixed(e.value); } function i(l) { return isNaN(l) || l === null || l === void 0 || l === ""; } function s(l) { const u = i(o.max) ? null : new I(String(o.max), 10), d = i(o.min) ? null : new I(String(o.min), 10); return u && l.gt(u) ? u : d && l.lt(d) ? d : l; } function r(l, u, d, a) { const g = new I(l, 10), f = i(d && d.value) ? null : new I(String(d.value), 10), m = i(u && u.value) ? null : new I(String(u.value), 10); let h; return a ? h = f && g.gt(f) ? f : g : h = m && g.lt(m) ? m : g, h.toString(); } function c(l, u = !0) { if (o.parser) return isNaN(Number(l)) ? o.parser(l) : l; let d = new I(l, 10); if (u && (d = s(d)), d.isNaN()) { if (o.nullable) return null; const g = new I("" + o.min, 10), f = new I("" + o.max, 10); if (!g.isNaN()) d = g; else if (!f.isNaN()) d = f; else return 0; } return t(d); } return { getRealValue: c, isEmpty: i, precision: e, getValidNumberObject: s, getValidNumberInRange: r }; } function te(o, n, e) { const t = M(() => ({ prefix: o.prefix, suffix: o.suffix, decimalSeparator: o.decimalSeparator, groupSeparator: o.useThousands ? o.groupSeparator : "", groupSize: o.groupSize })), { getValidNumberObject: i, precision: s } = e; function r(u) { return u = u == null || u === "" ? "" : String(u), u = u.replace(new RegExp(o.prefix, "g"), "").replace(new RegExp(o.suffix, "g"), "").replace(/,/g, ""), o.groupSeparator && o.groupSeparator !== "," && (u = u.replace(new RegExp(`\\${o.groupSeparator}`, "g"), "")), o.decimalSeparator && o.decimalSeparator !== "." && (u = u.replace(new RegExp(`\\${o.decimalSeparator}`, "g"), ".")), u; } function c(u, d) { return o.precision !== null && o.precision !== void 0 ? u.toFormat(s.value, d) : u.toFormat(d); } function l(u, d = !0) { const a = r(u), g = new I(a, 10); let f = g; return d && (f = i(g)), f.valueOf() === "0" && !o.showZero || f.isNaN() ? "" : o.formatter ? o.formatter(f.toNumber()) : c(f, t.value); } return { cleanFormat: r, format: l }; } function A(o, n, e, t, i, s, r, c, l, u) { const { format: d } = i, { getRealValue: a, getValidNumberInRange: g } = s; function f() { const v = new I(t.value || 0); return !((o.max || o.max === 0) && !new I(o.max).isNaN() && v.gte(new I(o.max)) && (t.value || t.value === 0)); } function m() { const v = new I(t.value || 0); return !((o.min || o.min === 0) && !new I(o.min).isNaN() && v.lte(new I(o.min)) && (t.value || t.value === 0)); } function h(v) { if (o.readonly || o.disabled) return; const k = v === "up" ? f : m, F = v === "up" ? "plus" : "minus"; if (k()) { let P = new I(t.value || 0)[F](Number(o.step)).toFixed(); P = g(P, c, l, u); const T = a(P); e.value = d(P), t.value !== T && (t.value = T, r(t.value)); } } function b() { h("up"); } function C() { h("down"); } function x(v) { b(), v.stopPropagation(); } function V(v) { C(), v.stopPropagation(); } return { canDownward: m, canUpward: f, downward: C, onClickDownButton: V, onClickUpButton: x, upward: b }; } function O(o, n, e, t, i, s, r, c, l, u, d) { const { cleanFormat: a, format: g } = i, { getRealValue: f, isEmpty: m, getValidNumberInRange: h } = s, { downward: b, upward: C } = r, x = M(() => e.value), V = B(!1); function v(w) { var z; if (w.stopPropagation(), o.readonly || o.disabled) return; V.value = !1; let P = (z = w.target) == null ? void 0 : z.value; o.nullable || (P = P || 0); let T = a(P); T = h(T, l, u, d); const L = f(T); e.value = g(T), t.value !== L && (t.value = L, c(t.value)), n.emit("blur", { event: w, formatted: e.value, value: t.value }); } function k(w) { w.stopPropagation(), !(o.readonly || o.disabled) && (V.value = !0, e.value = m(t.value) || !o.showZero && t.value === "0" ? "" : String(t.value), n.emit("focus", { event: w, formatted: e.value, value: t.value })); } function F(w) { var L; w.stopPropagation(); let P = (L = w.target) == null ? void 0 : L.value; o.nullable || (P = P || 0); const T = a(P); e.value = T, t.value = f(T), c(t.value); } function S(w) { w.key === "ArrowDown" && (w.preventDefault(), b()), w.key === "ArrowUp" && (w.preventDefault(), C()), w.stopPropagation(); } return { textBoxValue: x, onBlurTextBox: v, onFocusTextBox: k, onInput: F, onKeyDown: S, isTextBoxFocused: V }; } function X(o, n, e, t, i) { const { onBlurTextBox: s, onFocusTextBox: r, onInput: c, onKeyDown: l, textBoxValue: u } = e, d = M(() => o.disabled || o.readonly || !o.editable ? "" : t ? i.range.begin : i.range.end), a = M(() => ({ "form-control": !0, "sub-input": !0 })), g = M(() => ({ "text-align": o.textAlign })); function f(m) { m.stopPropagation(); } return () => E("input", { class: a.value, style: g.value, type: "text", value: u.value, disabled: o.disabled, readonly: o.readonly || !o.editable, placeholder: d.value, onBlur: s, onChange: f, onFocus: r, onInput: c, onKeydown: l }, null); } function q(o, n, e) { const { canDownward: t, canUpward: i, onClickDownButton: s, onClickUpButton: r } = e, c = M(() => ({ "input-group-append": !0, "btn-group": !0, "btn-group-number": !0, "sub-btn-group": !0 })), l = M(() => ({ btn: !0, "btn-secondary": !0, "btn-number-flag": !0 })), u = M(() => ({ cursor: i() ? "pointer" : "not-allowed", "margin-left": 0 })), d = M(() => ({ cursor: t() ? "pointer" : "not-allowed", "margin-left": 0 })); return () => E("div", { class: c.value }, [E("button", { class: l.value, style: u.value, onClick: r, disabled: !i() }, [E("span", { class: "f-icon f-icon-arrow-chevron-up number-arrow-chevron" }, null)]), E("button", { class: l.value, style: d.value, onClick: s, disabled: !t() }, [E("span", { class: "f-icon f-icon-arrow-chevron-down number-arrow-chevron" }, null)])]); } const $ = /* @__PURE__ */ J({ name: "FNumberRange", props: W, emits: ["valueChange", "blur", "focus", "click", "input", "beginValueChange", "endValueChange"], setup(o, n) { const e = B(o.beginValue), t = B(""), i = B(o.endValue), s = B(""), r = ee(o), c = te(o, n, r), l = le(o), u = (F) => { n.emit("beginValueChange", F); }, d = A(o, n, t, e, c, r, u, e, i, !0), a = O(o, n, t, e, c, r, d, u, e, i, !0), g = q(o, n, d), f = X(o, n, a, !0, l), m = (F) => { n.emit("endValueChange", F); }, h = A(o, n, s, i, c, r, m, e, i, !1), b = O(o, n, s, i, c, r, h, m, e, i, !1), C = q(o, n, h), x = X(o, n, b, !1, l), { getRealValue: V } = r, { format: v } = c, k = M(() => !o.disabled && !o.readonly && o.showButton); return Q(() => { const F = V(o.beginValue, !1), S = V(o.endValue, !1); t.value = v(F, !1), s.value = v(S, !1); }), G(() => [o.beginValue], ([F]) => { if (!a.isTextBoxFocused.value) { const S = V(F, !1); e.value = S, t.value = v(S, !1); } }), G(() => [o.endValue], ([F]) => { if (!b.isTextBoxFocused.value) { const S = V(F, !1); i.value = S, s.value = v(S, !1); } }), G(() => [o.precision, o.useThousands, o.prefix, o.suffix, o.showZero], () => { t.value = v(e.value), s.value = v(i.value); }), () => E("div", { class: "input-group number-range f-cmp-number-spinner" }, [E("div", { class: "form-control input-container" }, [E("div", { class: "sub-input-group" }, [f(), k.value && g()]), E("span", { class: "spliter" }, [Y("~")]), E("div", { class: "sub-input-group" }, [x(), k.value && C()])])]); } }); function _(o, n, e, t) { const { onBlurTextBox: i, onFocusTextBox: s, onInput: r, onKeyDown: c, textBoxValue: l } = e, u = M(() => t ? o.beginPlaceholder : o.endPlaceholder), d = M(() => ({ "form-control": !0, "sub-input": !0 })), a = M(() => ({ "text-align": o.textAlign })); function g(f) { f.stopPropagation(); } return () => E("input", { class: d.value, style: a.value, type: "text", value: l.value, disabled: o.disabled, readonly: o.readonly || !o.editable, placeholder: u.value, onBlur: i, onChange: g, onFocus: s, onInput: r, onKeydown: c }, null); } function Ve(o) { const { formSchemaUtils: n, formStateMachineUtils: e } = o; function t(l, u = "") { return { path: u + l.code, field: l.id, fullPath: l.code }; } function i(l, u = "") { const d = n.getViewModelById(l); return d ? d.states.map((a) => t(a, u)) : []; } function s(l) { const u = n.getRootViewModelId(), d = i(l); if (l === u) return d; const a = i(u, "root-component."); return [...d, ...a]; } function r(l) { return l.binding && l.binding.path || l.id || ""; } function c() { return e && e.getRenderStates() || []; } return { getVariables: s, getControlName: r, getStateMachines: c }; } class Fe { constructor(n) { y(this, "sessionVariables", [ { key: "CurrentSysOrgName", name: "当前组织Name", description: "当前组织Name" }, // { // key: "CurrentSysOrgCode", // name: "当前组织Code", // description: "当前组织Code" // }, { key: "CurrentSysOrgId", name: "当前组织Id", description: "当前组织Id" }, { key: "CurrentUserName", name: "当前用户Name", description: "当前用户Name" }, { key: "CurrentUserCode", name: "当前用户Code", description: "当前用户Code" }, { key: "CurrentUserId", name: "当前用户Id", description: "当前用户Id" }, { key: "CurrentLanguage", name: "当前语言编号", description: "当前登录的语言编号,例如简体中文返回'zh-CHS',英文返回'en',繁体中文'zh-CHT'" } ]); y(this, "expressionNames", { compute: "计算表达式", dependency: "依赖表达式", validate: "验证表达式", dataPicking: "帮助前表达式", visible: "可见表达式", readonly: "只读表达式", required: "必填表达式" }); y(this, "getExpressionConverter", (n, e) => ({ convertFrom: (t, i, s, r) => { const c = s.getExpressionRuleValue(n, e || i); return c && c.value || ""; }, convertTo: (t, i, s, r, c) => { var l; if (i === "dataPicking" && (s != null && s.target)) { const u = `${s.target}_dataPicking`; ((l = s.rules) == null ? void 0 : l.some( (a) => a.id === u && a.value )) ? t.dictPickingExpressionId = u : delete t.dictPickingExpressionId; } r.updateExpression(s); } })); this.formSchemaService = n; } getExpressionRule(n, e) { const t = this.getExpressionData(); if (!t) return ""; const i = t.find((r) => r.target === n); if (!i) return ""; const s = i.rules.find((r) => r.type === e); return s || ""; } // 获取上下文表单变量 getContextFormVariables() { const { module: n } = this.formSchemaService.getFormSchema(); if (!n.viewmodels || n.viewmodels.length === 0) return []; const e = this.formSchemaService.getRootViewModelId(), t = this.formSchemaService.getViewModelById(e); if (!t || !t.states || t.states.length === 0) return []; const i = []; return t.states.filter((s) => s.category === "remote").forEach((s) => { i.push({ key: s.code, name: s.name, description: s.name, category: s.category }); }), i; } createTreeNode(n, e, t = "label") { return { id: n.id, name: n.name, bindingPath: n[t], parents: e, type: "field" }; } buildEntityFieldsTreeData(n = null, e) { const t = []; return n == null || n.forEach((i) => { var c; const s = this.createTreeNode(i, e); let r = []; (c = i.type) != null && c.fields && (r = this.buildEntityFieldsTreeData(i.type.fields, [...e, i.label])), t.push({ data: s, children: r, expanded: !0 }); }), t; } buildChildEntityTreeData(n = null, e) { const t = []; return n == null || n.forEach((i) => { var l, u; const s = this.createTreeNode(i, e); s.type = "entity"; const r = this.buildEntityFieldsTreeData((l = i.type) == null ? void 0 : l.fields, [...e, i.label]), c = this.buildChildEntityTreeData((u = i.type) == null ? void 0 : u.entities, [...e, i.label]); c != null && c.length && (r == null || r.push(...c)), t.push({ data: s, children: r || [], // 空值回退 expanded: !0 }); }), t; } getEntitiesTreeData() { const n = this.formSchemaService.getSchemaEntities(); if (!(n != null && n.length)) return []; const e = n[0]; if (!(e != null && e.type)) return []; const t = this.buildEntityFieldsTreeData(e.type.fields, [e.code]), i = this.buildChildEntityTreeData(e.type.entities, [e.code]); return i != null && i.length && (t == null || t.push(...i)), { entityCode: e.code, fields: [{ data: this.createTreeNode(e, [], "code"), children: t || [] }] }; } getEntitiesAndVariables() { return { entities: this.getEntitiesTreeData(), variables: { session: { name: "系统变量", items: this.sessionVariables, visible: !1 }, forms: { name: "表单变量", items: this.getContextFormVariables(), visible: !0 } } }; } onBeforeOpenExpression(n, e, t) { const i = t === "Field" ? n.binding.field : n.id, s = this.getExpressionRule(i, e), r = this.getEntitiesAndVariables(), c = { message: ["validate", "required", "dataPicking"].includes(e) && s ? s.message : "", ...r }; return s.messageType != null && (c.messageType = s.messageType), c; } buildRule(n, e, t, i) { const { expression: s, message: r, messageType: c } = e, l = { id: `${n}_${t}`, type: t, value: s }; return (t === "validate" || t === "dataPicking" || t === "required") && (l.message = r), t === "dataPicking" && (l.messageType = c), t === "validate" && i && (l.elementId = i), l; } getExpressionData() { const { expressions: n } = this.formSchemaService.getFormSchema().module; return n || []; } updateExpression(n, e, t, i) { const s = e === "Field" ? n.binding.field : n.id, r = this.buildRule(s, t, i, n.type === "form-group" ? n.id : ""); let l = this.getExpressionData().find((d) => d.targetType === e && d.target === s); const u = (d) => d.value.trim() === ""; if (l) { const d = l.rules.find((a) => a.id === r.id); if (d) u(r) ? l.rules = l.rules.filter((a) => a.id !== r.id) : (Object.assign(d, r), i === "validate" && n.type === "form-group" && (d.elementId = n.id)); else { if (u(r)) return null; l.rules = l.rules || [], l.rules.push(r); } } else { if (u(r)) return null; l = { target: `${s}`, rules: [r], targetType: e }; } return l; } getExpressionEditorOptions(n, e, t, i) { return t.reduce((s, r) => { var l, u; const c = e === "Field" ? (l = n == null ? void 0 : n.binding) == null ? void 0 : l.field : n.id; return s[r] = { hide: e === "Field" ? !!((u = n == null ? void 0 : n.binding) != null && u.field) : !1, description: "", title: this.expressionNames[r], type: "string", $converter: this.getExpressionConverter(c), refreshPanelAfterChanged: !0, editor: { type: "expression-editor", singleExpand: !1, dialogTitle: `${this.expressionNames[r]}编辑器`, showMessage: r === "validate" || r === "dataPicking" || r === "required", showMessageType: r === "dataPicking", beforeOpen: () => this.onBeforeOpenExpression(n, r, e), onSubmitModal: (d) => { const a = this.updateExpression(n, e, d, r); if (i) { const g = this.buildRule(c, d, r); i(g); } return a; } } }, s; }, {}); } getExpressionInfo(n, e, t) { const i = e === "Field" ? n.binding.field : n.id, s = this.getExpressionRule(i, t), r = { value: s && s.value, targetId: i, targetType: e, expressionType: t }; return s && s.message && (r.message = s.message), r; } getExpressionConfig(n, e, t = ["compute", "dependency", "validate"], i) { return { description: "表达式", title: "表达式", hide: !n.binding, properties: { ...this.getExpressionEditorOptions(n, e, t, i) } }; } getExpressionOptions(n, e, t) { const i = this.getExpressionInfo(n, e, t); return { dialogTitle: `${this.expressionNames[t] || "表达式"}编辑器`, singleExpand: !1, showMessage: t === "required", beforeOpen: () => this.onBeforeOpenExpression(n, t, e), expressionInfo: i }; } } class Ee { constructor(n, e) { y(this, "componentId"); y(this, "viewModelId"); y(this, "eventsEditorUtils"); y(this, "formSchemaUtils"); y(this, "formMetadataConverter"); y(this, "designViewModelUtils"); y(this, "designViewModelField"); y(this, "controlCreatorUtils"); y(this, "designerHostService"); y(this, "designerContext"); y(this, "modalService", null); /** 表单规则 */ y(this, "formRule", null); y(this, "schemaService", null); y(this, "metadataService", null); y(this, "propertyConfig", { type: "object", categories: {} }); y(this, "expressionProperty"); var t; this.componentId = n, this.designerHostService = e, this.eventsEditorUtils = e.eventsEditorUtils, this.formSchemaUtils = e.formSchemaUtils, this.formMetadataConverter = e.formMetadataConverter, this.viewModelId = ((t = this.formSchemaUtils) == null ? void 0 : t.getViewModelIdByComponentId(n)) || "", this.designViewModelUtils = e.designViewModelUtils, this.controlCreatorUtils = e.controlCreatorUtils, this.metadataService = e.metadataService, this.schemaService = e.schemaService, this.designerContext = e.designerContext, this.modalService = e.modalService, this.expressionProperty = new Fe(this.formSchemaUtils); } getFormDesignerInstance() { var n, e; return (e = (n = this.designerContext) == null ? void 0 : n.instances) == null ? void 0 : e.formDesigner.value; } getTableInfo() { var n; return (n = this.schemaService) == null ? void 0 : n.getTableInfoByViewModelId(this.viewModelId); } setDesignViewModelField(n) { var t; const e = n.binding && n.binding.type === "Form" && n.binding.field; if (e) { if (!this.designViewModelField) { const i = this.designViewModelUtils.getDgViewModel(this.viewModelId); this.designViewModelField = i.fields.find((s) => s.id === e); } n.updateOn = (t = this.designViewModelField) == null ? void 0 : t.updateOn; } } getBasicPropConfig(n) { return { description: "Basic Information", title: "基本信息", properties: { id: { description: "组件标识", title: "标识", type: "string", readonly: !0 }, type: { description: "组件类型", title: "控件类型", type: "select", editor: { type: "combo-list", textField: "name", valueField: "value", idField: "value", editable: !1, data: [{ value: n.type, name: p[n.type] && p[n.type].name }] } } } }; } getAppearanceConfig(n = null, e = {}, t) { const i = { title: "外观", description: "Appearance" }, s = { class: { title: "class样式", type: "string", description: "组件的CSS样式", $converter: "/converter/appearance.converter", parentPropertyID: "appearance" }, style: { title: "style样式", type: "string", description: "组件的样式", $converter: "/converter/appearance.converter", parentPropertyID: "appearance" } }; for (const r in e) s[r] = Object.assign(s[r] || {}, e[r]); return { ...i, properties: { ...s }, setPropertyRelates(r, c) { if (r) { switch (r && r.propertyID) { case "class": case "style": { U.value++; break; } } t && t(r, n, c); } } }; } /** * * @param propertyData * @param propertyTypes * @param propertyName * @param constInfos * @param variableInfos * @param expressionType 指定表达式类型,存在属性和表达式类型不一致的情况 * @returns */ getPropertyEditorParams(n, e = [], t = "visible", i = {}, s = {}, r = "") { const { getVariables: c, getControlName: l, getStateMachines: u } = Ve(this.designerHostService), d = this.getRealTargetType(n), a = e && e.length > 0 ? e : ["Const", "Variable", "StateMachine", "Expression"], g = { type: "property-editor", propertyTypes: a }; return a.map((f) => { switch (f) { case "Const": Object.assign(g, { constType: "enum", constEnums: [{ id: !0, name: "是" }, { id: !1, name: "否" }] }, i); break; case "Expression": g.expressionConfig = this.getExpressionOptions(n, d, r || t); break; case "StateMachine": g.stateMachines = u(); break; case "Variable": Object.assign(g, { controlName: l(n), newVariablePrefix: "is", newVariableType: "Boolean", variables: c(this.viewModelId), parentComponentId: this.componentId === "root-component" ? "" : "root-component", onBeforeOpenVariables: (m) => { m.value = c(this.viewModelId); } }, s), this.designerContext.designerMode === "PC_RTC" && (g.newVariablePrefix = "ext_" + g.newVariablePrefix); break; } }), g; } getVisibleProperty(n, e = "") { var s; let t = ["Const", "Variable", "StateMachine", "Expression"]; return e === "gridFieldEditor" ? t = ["Const", "Expression"] : e === "form-group" && !((s = n.binding) != null && s.field) && (t = ["Const", "Variable", "StateMachine"]), { visible: { title: "是否可见", type: "boolean", description: "运行时组件是否可见", editor: this.getPropertyEditorParams(n, t, "visible") } }; } /** * 获取行为 * @param propertyData * @param viewModelId * @returns */ getBehaviorConfig(n, e = "", t = {}, i) { const s = { title: "行为", description: "" }, r = this.getVisibleProperty(n, e); for (const l in t) r[l] = Object.assign(r[l] || {}, t[l]); const c = this; return { ...s, properties: { ...r }, setPropertyRelates(l, u) { if (l) { switch (l.propertyID) { case "disabled": case "readonly": case "visible": c.afterMutilEditorChanged(n, l); break; } i && i(l, u); } } }; } /** * 当多值编辑器变更时 * @param propertyData * @param changeObject */ afterMutilEditorChanged(n, e) { this.addNewVariableToViewModel(e, this.viewModelId), this.updateExpressionValue(e, n), this.clearExpression(e, n); } /** * * @param propertyId * @param componentInstance * @returns */ updateElementByParentContainer(n, e) { const t = e && e.parent && e.parent.schema; if (!t) return; const i = t.contents.findIndex((r) => r.id === n), s = ue(t.contents[i]); t.contents.splice(i, 1), t.contents.splice(i, 0, s), ae(); } /** * 属性编辑器,在编辑过程中会新增变量,此处需要将新增的变量追加到ViewModel中 * @param changeObject * @param viewModelId * @returns */ addNewVariableToViewModel(n, e) { const t = n.propertyValue; if (!(t && typeof t == "object") || !(t.type === "Variable" && t.isNewVariable)) return; const r = { id: t.field, category: "locale", code: t.fullPath, name: t.fullPath, type: t.newVariableType || "String", isRtcVariable: this.designerContext.designerMode === "PC_RTC" ? !0 : void 0 }; delete t.newVariableType, delete t.isNewVariable, this.formSchemaUtils.getVariableByCode(r.code) || this.formSchemaUtils.getViewModelById("root-viewmodel").states.push(r); } getExpressions() { let n = []; return this.formRule ? (this.formRule.expressions = this.formRule.expressions || [], n = this.formRule.expressions || []) : n = this.formSchemaUtils.getExpressions(), n; } /** * 更新表达式到expressions节点 * @param changeObject */ updateExpressionValue(n, e) { const t = n.propertyValue; if (!((t && t.type) === "Expression" && t.expressionInfo)) return; const { expressionId: r, expressionInfo: c } = t, { targetId: l, targetType: u, expressionType: d, value: a, message: g } = c, f = this.getExpressions(); let m = f.find((b) => b.target === l); m || (m = { target: l, rules: [], targetType: u }, f.push(m)); const h = m.rules.find((b) => b.type === d); if (h) h.value = a, h.message = g, (d === "minDate" || d === "maxDate" || d === "defaultTime") && (h.elementId = e.id); else { const b = { id: r, type: d, value: a, message: g, elementId: e.id }; m.rules.push(b); } delete t.expressionInfo; } /** * 属性类型切换为非表达式后,清除原表达式 * @param changeObject * @param propertyData * @returns */ clearExpression(n, e) { const t = n.propertyValue; if (t && t.type === "Expression") return; const s = n.propertyID, r = this.getExpressions(), c = e.binding ? e.binding.field : e.id, l = r.find((u) => u.target === c); !l || !l.rules || (l.rules = l.rules.filter((u) => u.type !== s)); } getExpressionOptions(n, e, t) { return this.expressionProperty.getExpressionOptions(n, e, t); } getRealTargetType(n) { return ["response-toolbar-item", "tab-toolbar-item", "section-toolbar-item", "drawer-toolbar-item"].indexOf(n.type) > -1 ? "Button" : n.binding && n.binding.field ? "Field" : "Container"; } createBaseEventProperty(n) { const e = {}; return e[this.viewModelId] = { type: "events-editor", editor: { initialData: n, viewSourceHandle: (t) => { var i; ((i = t.controller) == null ? void 0 : i.label.indexOf(this.formSchemaUtils.getModule().code)) > -1 && this.eventsEditorUtils.jumpToMethod(t); } } }, e; } } const N = class N { /** * 根据绑定字段类型获取可用的输入类控件 */ static getEditorTypesByMDataType(n, e = !1, t = "") { if (e) return [{ key: p["language-textbox"].type, value: p["language-textbox"].name }]; let i = N.fieldControlTypeMapping[n]; if (t === "data-grid-column" && (i != null && i.length)) { const s = [p["check-group"].type, p["radio-group"].type, p.image.type, p["rich-text-editor"].type]; i = i.filter((r) => !s.includes(r.key)); } return i; } /** * 获取所有输入类控件 */ static getAllInputTypes() { const n = []; for (const e in N.fieldControlTypeMapping) N.fieldControlTypeMapping[e].forEach((t) => { n.find((i) => i.key === t.key && i.value === t.value) || n.push({ key: t.key, value: t.value }); }); return n; } /** * 提供schema字段基础属性和DOM控件属性的映射 * @param control 控件元数据 */ static mappingDomPropAndSchemaProp(n, e) { var s; const t = (s = n.editor) == null ? void 0 : s.type, i = []; return (n.type === p["data-grid-column"].type || n.type === p["tree-grid-column"].type) && e && e.categoryId && e.categoryId.indexOf("gridFieldEditor") < 0 && i.push({ domField: "title", schemaField: "name" }), i.push({ domField: "label", schemaField: "name" }), i.push({ domField: "editor.required", schemaField: "require" }), i.push({ domField: "editor.readonly", schemaField: "readonly" }), (t === p["input-group"].type || t === p.textarea.type || t === p["number-spinner"].type) && i.push({ domField: "editor.maxLength", schemaField: "type.length" }), t === p["number-spinner"].type && i.push({ domField: "editor.precision", schemaField: "type.precision" }), (n.type === p["data-grid-column"].type || n.type === p["tree-grid-column"].type) && i.push({ domField: "formatter.precision", schemaField: "type.precision" }), (t === p["combo-list"].type || t === p["radio-group"].type) && i.push({ domField: "editor.data", schemaField: "type.enumValues" }), (n.type === p["data-grid-column"].type || n.type === p["tree-grid-column"].type) && i.push({ domField: "formatter.data", schemaField: "type.enumValues" }), t === p["date-picker"].type && (i.push({ domField: "editor.displayFormat", schemaField: "editor.format" }), i.push({ domField: "editor.fieldType", schemaField: "type.name" })), t === p["number-spinner"].type && (i.push({ domField: "editor.max", schemaField: "editor.maxValue" }), i.push({ domField: "editor.min", schemaField: "editor.minValue" })), t === p.lookup.type && (i.push({ domField: "editor.dataSource", schemaField: "editor.dataSource" }), i.push({ domField: "editor.valueField", schemaField: "editor.valueField" }), i.push({ domField: "editor.textField", schemaField: "editor.textField" }), i.push({ domField: "editor.displayType", schemaField: "editor.displayType" }), i.push({ domField: "editor.mapFields", schemaField: "editor.mapFields" }), i.push({ domField: "editor.helpId", schemaField: "editor.helpId" })), i.push({ domField: "path", schemaField: "bindingPath" }), i.push({ domField: "binding.path", schemaField: "bindingField" }), i.push({ domField: "binding.fullPath", schemaField: "path" }), (n.type === p["data-grid-column"].type || n.type === p["tree-grid-column"].type) && i.push({ domField: "field", schemaField: "bindingPath" }), i; } }; /** * <字段类型,可配置的控件类型列表>的映射 */ y(N, "fieldControlTypeMapping", { String: [ { key: p["input-group"].type, value: p["input-group"].name }, { key: p.lookup.type, value: p.lookup.name }, { key: p.image.type, value: p.image.name }, { key: p["date-picker"].type, value: p["date-picker"].name }, { key: p.switch.type, value: p.switch.name }, { key: p["check-box"].type, value: p["check-box"].name }, { key: p["check-group"].type, value: p["check-group"].name }, { key: p["radio-group"].type, value: p["radio-group"].name }, { key: p["combo-list"].type, value: p["combo-list"].name }, { key: p.textarea.type, value: p.textarea.name }, { key: p["time-picker"].type, value: p["time-picker"].name } ], Text: [ { key: p.textarea.type, value: p.textarea.name }, { key: p.lookup.type, value: p.lookup.name }, { key: p.image.type, value: p.image.name }, { key: p["rich-text-editor"].type, value: p["rich-text-editor"].name } ], Decimal: [ { key: p["number-spinner"].type, value: p["number-spinner"].name } ], Integer: [ { key: p["number-spinner"].type, value: p["number-spinner"].name } ], Number: [ { key: p["number-spinner"].type, value: p["number-spinner"].name }, { key: p.switch.type, value: p.switch.name }, { key: p["check-box"].type, value: p["check-box"].name } ], BigNumber: [ { key: p["number-spinner"].type, value: p["number-spinner"].name } ], Date: [ { key: p["date-picker"].type, value: p["date-picker"].name } ], DateTime: [ { key: p["date-picker"].type, value: p["date-picker"].name } ], Boolean: [ { key: p.switch.type, value: p.switch.name }, { key: p["check-box"].type, value: p["check-box"].name } ], Enum: [ { key: p["combo-list"].type, value: p["combo-list"].name }, { key: p["radio-group"].type, value: p["radio-group"].name } ], Object: [ { key: p.lookup.type, value: p.lookup.name }, { key: p["combo-list"].type, value: p["combo-list"].name }, { key: p["radio-group"].type, value: p["radio-group"].name } ] }); let j = N; var R = /* @__PURE__ */ ((o) => (o.Form = "Form", o.Variable = "Variable", o))(R || {}); class H { constructor() { /** 控件标题 */ y(this, "label", ""); /** 控件id */ y(this, "id", ""); /** 每个控件占用的栅格数 */ y(this, "columnInSM", 12); y(this, "columnInMD", 6); y(this, "columnInLG", 3); y(this, "columnInEL", 2); /** 每个控件占用的列数 */ y(this, "displayWidthInSM", 1); y(this, "displayWidthInMD", 1); y(this, "displayWidthInLG", 1); y(this, "displayWidthInEL", 1); /** 编辑器内部默认显示的屏幕大小-----可以去掉 */ y(this, "displayColumnCountAtBreakPoint", "md"); /** 控件所在行,传0即可-----编辑器内部使用 */ y(this, "tagRow", 0); /** 控件是否显示上方空白:传0即可-----编辑器内部使用 */ y(this, "showTopBorder", 0); /** 区域,从1开始。卡片内的控件从上往下,从左往右划分区域,遇到分组fieldSet时group+1,分组结束后group+1 */ y(this, "group", 1); /** 控件是否符合标准的class配置(设计器用的) */ y(this, "isSupportedClass", !0); /** 控件所在分组id(设计器用的) */ y(this, "fieldSetId", ""); } } function Ie(o) { let n, e; const t = /* @__PURE__ */ new Map(); let i = []; function s(d, a) { const f = ((d == null ? void 0 : d.split(" ")) || []).filter((x) => x.startsWith("col-")); if (f.length === 0) { a.isSupportedClass = !1; return; } let m = f.find((x) => /^col-([1-9]|10|11|12)$/.test(x)), h = f.find((x) => /^col-md-([1-9]|10|11|12)$/.test(x)), b = f.find((x) => /^col-xl-([1-9]|10|11|12)$/.test(x)), C = f.find((x) => /^col-el-([1-9]|10|11|12)$/.test(x)); m = m || "col-12", a.columnInSM = parseInt(m.replace("col-", ""), 10), a.displayWidthInSM = a.columnInSM / 12, a.displayWidthInSM !== 1 && (a.isSupportedClass = !1), h = h || "col-md-" + a.columnInSM, a.columnInMD = parseInt(h.replace("col-md-", ""), 10), a.displayWidthInMD = a.columnInMD / 6, [1, 2].includes(a.displayWidthInMD) || (a.isSupportedClass = !1), b = b || "col-xl-" + a.columnInMD, a.columnInLG = parseInt(b.replace("col-xl-", ""), 10), a.displayWidthInLG = a.columnInLG / 3, [1, 2, 3, 4].includes(a.displayWidthInLG) || (a.isSupportedClass = !1), C = C || "col-el-" + a.columnInLG, a.columnInEL = parseInt(C.replace("col-el-", ""), 10), a.displayWidthInEL = a.columnInEL / 2, [1, 2, 3, 4, 5, 6].includes(a.displayWidthInEL) || (a.isSupportedClass = !1); } function r(d, a, g, f = !1) { let m = !1; if (!d.contents || d.contents.length === 0) { const h = new H(); s(d.layout, h), a.push(h); return; } d.contents.forEach((h) => { if (h.type === "fieldset") { g += 1, r(h, a, g, !0), m = !0; return; } if (h.type === "dynamic-form") return; m && (g += 1, m = !1); const b = h.appearance && h.appearance.class, C = new H(); b ? s(b, C) : C.isSupportedClass = !1, C.label = h.label || h.id, C.id = h.id, C.group = g, f && (C.fieldSetId = d.id), e === h.id && (n = g), t.set(h.id, h), a.push(C); }); } function c(d) { const a = o.getComponentById(d); if (!a || !a.componentType || !a.componentType.startsWith("form")) return { result: !1, message: "只可以在响应式表单组件中调整响应式布局配置" }; const g = o.selectNode(a, (f) => f.type === p["response-form"].type); return !g || !g.contents || g.contents.length === 0 ? { result: !1, message: "Form区域内没有控件,请先添加控件" } : { result: !0, message: "", formNode: g }; } function l(d, a) { a = a || d.id; const { result: g, message: f, formNode: m } = c(a); if (!g) return { result: g, message: f }; e = d.id, i = [], t.clear(); const h = m.contents[0].type === p.fieldset.type ? 0 : 1; r(m, i, h); const b = i.find((x) => !x.isSupportedClass); return { defaultState: { defaultGroupNumber: n || 1, model: b ? "customize" : "standard" }, importData: i }; } function u(d, a) { a = a; const { result: g, formNode: f } = c(a); if (!g) return ""; const m = []; return d.forEach((h) => { var x; const b = t.get(h.id), C = b.appearance && b.appearance.class; if (C) { const v = C.split(" ").filter((T) => !T.startsWith("col-")), k = "col-" + h.columnInSM, F = "col-md-" + h.columnInMD, S = "col-xl-" + h.columnInLG, w = "col-el-" + h.columnInEL, P = [k, F, S, w].concat(v); b.appearance.class = P.join(" "); } if (h.fieldSetId) { const V = f.contents.find((k) => k.id === h.fieldSetId), v = m.find((k) => k.id === h.fieldSetId); v ? (x = v.contents) == null || x.push(b) : (m.push(V), V.contents = [b]); } else m.push(b); }), f.contents = m, f.id; } return { checkCanFindFormNode: c, checkCanOpenLayoutEditor: l, changeFormControlsByResponseLayoutConfig: u, getResonseFormLayoutConfig: r }; } class Se extends Ee { constructor(e, t) { super(e, t); y(this, "responseLayoutEditorFunction"); /** 控件绑定的变量 */ y(this, "bindingVarible"); y(this, "formGroupEvents", [ // { // label: 'fieldValueChanging', // name: '绑定字段值变化前事件', // }, // { // label: 'fieldValueChanged', // name: '绑定字段值变化后事件', // }, { label: "onClickLabel", name: "标签点击事件" } ]); y(this, "numberEditorOptions", { type: "number-spinner", useThousands: !1, keyboard: !1, showButton: !1 }); y(this, "showCustomValue", (e) => { var i; const t = this.designViewModelField != null && ((i = this.designViewModelField) == null ? void 0 : i.type.name) !== "Boolean"; return this.formRule ? e.dataType !== "boolean" : t; }); this.responseLayoutEditorFunction = Ie(this.formSchemaUtils); } getCommonPropertyConfig(e, t, i = "Card") { this.propertyConfig.categories.basic = this.getBasicProperties(e, t, i), this.propertyConfig.categories.appearance = this.getAppearanceProperties(e, t), this.propertyConfig.categories.behavior = this.getBehaviorConfig(e, "form-group"); } getPropertyConfig(e, t) { return this.getCommonPropertyConfig(e, t, "Card"), this.propertyConfig.categories.editor = this.getEditorProperties(e), this.propertyConfig.categories.expressions = this.getExpressionConfig(e, "Field"), this.propertyConfig.categories.eventsEditor = this.getEventPropertyConfig(e), this.propertyConfig; } getGridFieldEdtiorPropConfig(e, t) { return this.propertyConfig.categories = {}, this.getCommonPropertyConfig(e, t, "Grid"), this.getGridFieldEdtiorProperties ? this.propertyConfig.categories.editor = this.getGridFieldEdtiorProperties(e) : this.propertyConfig.categories.editor = this.getEditorProperties(e), this.propertyConfig.categories.expressons = this.getExpressionConfig(e, "Field"), this.propertyConfig.categories; } getBasicProperties(e, t, i = "Card") { var d; const s = this; this.setDesignViewModelField(e); const { canChangeControlType: r, editorTypeList: c } = this.getAvailableEditorType(e); let l = c; this.formRule && (l = c.filter((a) => a.key !== "image" && a.key !== "rich-text-editor")); const u = { description: "Basic Information", title: "基本信息", properties: { id: { description: "组件标识", title: "标识", type: "string", readonly: !0 }, type: { description: "编辑器类型", title: "编辑器类型", type: "string", $converter: "/converter/change-editor.converter", parentPropertyID: "editor", editor: { type: "combo-list", textField: "value", valueField: "key", idField: "key", editable: !1, data: l, readonly: !r } }, label: { title: "标签", type: "string", $converter: "/converter/form-group-label.converter" }, showLabelType: { description: "标签显示方式:1、显示:显示标签 2、占位:保留标签空间,但不显示文本 3、不显示:不显示标签", title: "标签显示", type: "enum", editor: { data: [{ id: "visible", name: "显示" }, { id: "reserve-space", name: "占位" }, { id: "none", name: "不显示" }] }, defaultValue: ((d = e.editor) == null ? void 0 : d.type) === "image" ? "none" : "visible" }, binding: { description: "绑定的表单字段", title: "绑定", editor: { type: "binding-selector", bindingType: { enable: !1 }, editorParams: { componentSchema: e, needSyncToViewModel: !0, viewModelId: this.viewModelId, designerHostService: this.designerHostService, disableOccupiedFields: !0 }, textField: "bindingField" }, refreshPanelAfterChanged: !0, readonly: this.formSchemaUtils.designerMode === "PC_RTC" && !e.isRtcControl } }, setPropertyRelates(a, g, f) { if (a) switch (a && a.propertyID) { case "type": { s.changeControlType(e, a, t); break; } case "label": { a.needRefreshControlTree = !0; break; } case "binding": { s.changeBindingField(e, a, f); break; } } } }; return i.toLocaleLowerCase() !== "card" && delete u.properties.showLabelType, u; } /** * 校验控件是否支持切换类型 * @param control 控件 */ checkCanChangeControlType(e, t) { if (!e.binding) return !1; if (e.binding.type === "Variable") { if (this.bindingVarible = this.formSchemaUtils.getVariableById(e.binding.field), !this.bindingVarible) return !1; } else if (!this.designViewModelField || this.designViewModelField.$type !== Z.SimpleField) return !1; return !0; } /** * 获取可选的编辑器类型 */ getAvailableEditorType(e) { var s, r; const t = this.checkCanChangeControlType(e, this.viewModelId); if (!t) return { canChangeControlType: !1, editorTypeList: [{ key: e.editor.type, value: ((s = p[e.editor.type]) == null ? void 0 : s.name) || e.editor.type }] }; let i = []; return this.designViewModelField && this.designViewModelField.$type === Z.SimpleField ? i = j.getEditorTypesByMDataType(this.designViewModelField.type.name, this.designViewModelField.multiLanguage) : this.bindingVarible && (i = j.getEditorTypesByMDataType(this.bindingVarible.type, !!((r = this.designViewModelField) != null && r.multiLanguage))), { canChangeControlType: t, editorTypeList: i }; } changeBindingField(e, t, i) { t.needRefreshEntityTree = !0; } getAppearanceProperties(e, t) { const i = this; return { title: "外观", description: "Appearance", properties: { class: { title: "class样式", type: "string", description: "组件的CSS样式", $converter: "/converter/appearance.converter", parentPropertyID: "appearance" }, style: { title: "style样式", type: "string", description: "组件的内联样式", $converter: "/converter/appearance.converter", parentPropertyID: "appearance" }, fill: { title: "填充宽度", description: "启用后,控件占满父容器宽度", type: "boolean", parentPropertyID: "appearance", defaultValue: !1 }, responseLayout: { description: "响应式列宽", title: "响应式列宽", type: "boolean", visible: !i.formRule, // 这个属性,标记当属性变更得时候触发重新更新属性 refreshPanelAfterChanged: !0, editor: { type: "response-layout-editor-setting", beforeOpen: () => i.responseLayoutEditorFunction.checkCanOpenLayoutEditor(e, i.componentId) } } }, setPropertyRelates(s, r) { if (s) switch (s && s.propertyID) { case "responseLayout": i.responseLayoutEditorFunction.changeFormControlsByResponseLayoutConfig(s.propertyValue, i.componentId || e.id), i.updateUnifiedLayoutAfterResponseLayoutChanged(i.componentId), i.updateElementByParentContainer(e.id, t), delete e.responseLayout; break; case "class": i.updateUnifiedLayoutAfterControlChanged(s.propertyValue, e.id, this.componentId), U.value++; break; case "style": { U.valu