UNPKG

@farris/ui-vue

Version:

Farris Vue, a Farris Design based Vue3 component library.

1,347 lines 76.3 kB
var D = Object.defineProperty; var Y = (u, n, e) => n in u ? D(u, n, { enumerable: !0, configurable: !0, writable: !0, value: e }) : u[n] = e; var f = (u, n, e) => Y(u, typeof n != "symbol" ? n + "" : n, e); import { FormSchemaEntityField$Type as Q, FormSchemaEntityFieldType$Type as X, EVENT_PROPERTY_TAB_IDS as R, isImageUrl as $, urlPrependBasePath as _, isBase64ImageUrl as ee, getCustomClass as te, getCustomStyle as ie, withInstall as ne } from "../../components/common/index.esm.js"; import { createVNode as b, Fragment as se, createTextVNode as re, nextTick as oe, defineComponent as K, ref as w, inject as H, onMounted as ae, computed as E, watch as le } from "vue"; import { DgControl as l, canvasChanged as P, refreshCanvas as de, useDesignerComponent as ce } from "../../components/designer-canvas/index.esm.js"; import { cloneDeep as ue } from "lodash-es"; import { resolveAppearance as U, createPropsResolver as L } from "../../components/dynamic-resolver/index.esm.js"; import { LocaleService as S } from "../../components/locale/index.esm.js"; import { FNotifyService as Ae } from "../../components/notify/index.esm.js"; function pe(u) { const { formSchemaUtils: n, formStateMachineUtils: e } = u; function t(o, A = "") { return { path: A + o.code, field: o.id, fullPath: o.code }; } function i(o, A = "") { const d = n.getViewModelById(o); return d ? d.states.map((a) => t(a, A)) : []; } function s(o) { const A = n.getRootViewModelId(), d = i(o); if (o === A) return d; const a = i(A, "root-component."); return [...d, ...a]; } function r(o) { return o.binding && o.binding.path || o.id || ""; } function c() { return e && e.getRenderStates() || []; } return { getVariables: s, getControlName: r, getStateMachines: c }; } class ge { constructor(n) { f(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'" } ]); f(this, "expressionNames", { compute: "计算表达式", dependency: "依赖表达式", validate: "验证表达式", dataPicking: "帮助前表达式", visible: "可见表达式", readonly: "只读表达式", required: "必填表达式" }); f(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 o; if (i === "dataPicking" && (s != null && s.target)) { const A = `${s.target}_dataPicking`; ((o = s.rules) == null ? void 0 : o.some( (a) => a.id === A && a.value )) ? t.dictPickingExpressionId = A : 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 o, A; const s = this.createTreeNode(i, e); s.type = "entity"; const r = this.buildEntityFieldsTreeData((o = i.type) == null ? void 0 : o.fields, [...e, i.label]), c = this.buildChildEntityTreeData((A = i.type) == null ? void 0 : A.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, o = { id: `${n}_${t}`, type: t, value: s }; return (t === "validate" || t === "dataPicking" || t === "required") && (o.message = r), t === "dataPicking" && (o.messageType = c), t === "validate" && i && (o.elementId = i), o; } 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 o = this.getExpressionData().find((d) => d.targetType === e && d.target === s); const A = (d) => d.value.trim() === ""; if (o) { const d = o.rules.find((a) => a.id === r.id); if (d) A(r) ? o.rules = o.rules.filter((a) => a.id !== r.id) : (Object.assign(d, r), i === "validate" && n.type === "form-group" && (d.elementId = n.id)); else { if (A(r)) return null; o.rules = o.rules || [], o.rules.push(r); } } else { if (A(r)) return null; o = { target: `${s}`, rules: [r], targetType: e }; } return o; } getExpressionEditorOptions(n, e, t, i) { return t.reduce((s, r) => { var o, A; const c = e === "Field" ? (o = n == null ? void 0 : n.binding) == null ? void 0 : o.field : n.id; return s[r] = { hide: e === "Field" ? !!((A = n == null ? void 0 : n.binding) != null && A.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 p = this.buildRule(c, d, r); i(p); } 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) { var s; return { description: "表达式", title: "表达式", hide: !(n.binding && ((s = n.binding) == null ? void 0 : s.type) === "Form"), 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 me { constructor(n, e) { f(this, "componentId"); f(this, "viewModelId"); f(this, "eventsEditorUtils"); f(this, "formSchemaUtils"); f(this, "formMetadataConverter"); f(this, "designViewModelUtils"); f(this, "designViewModelField"); f(this, "controlCreatorUtils"); f(this, "designerHostService"); f(this, "designerContext"); f(this, "modalService", null); /** 表单规则 */ f(this, "formRule", null); f(this, "schemaService", null); f(this, "metadataService", null); f(this, "propertyConfig", { type: "object", categories: {} }); f(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 ge(this.formSchemaUtils); } /** * 是否在响应式表单中 */ inResponsiveForm() { var n; return !!((n = this.designerContext) != null && n.responsiveForm); } 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: l[n.type] && l[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": { P.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: o, getStateMachines: A } = pe(this.designerHostService), d = this.getRealTargetType(n), a = e && e.length > 0 ? e : ["Const", "Variable", "StateMachine", "Expression"], p = { type: "property-editor", propertyTypes: a }; return a.map((h) => { switch (h) { case "Const": Object.assign(p, { constType: "enum", constEnums: [{ id: !0, name: "是" }, { id: !1, name: "否" }] }, i); break; case "Expression": p.expressionConfig = this.getExpressionOptions(n, d, r || t); break; case "StateMachine": p.stateMachines = A(); break; case "Variable": Object.assign(p, { controlName: o(n), newVariablePrefix: "is", newVariableType: "Boolean", variables: c(this.viewModelId), parentComponentId: this.componentId === "root-component" ? "" : "root-component", onBeforeOpenVariables: (g) => { g.value = c(this.viewModelId); } }, s), this.designerContext.designerMode === "PC_RTC" && (p.newVariablePrefix = "ext_" + p.newVariablePrefix); break; } }), p; } 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", "Custom"] : e === "dataGrid" || e === "treeGrid" || e === "wizard" ? t = ["Const", "Variable", "Expression"] : (n.type.indexOf("toolbar-item") > -1 || e === "form-group") && (t = ["Const", "Variable", "StateMachine", "Custom", "Expression"]), { 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 o in t) r[o] = Object.assign(r[o] || {}, t[o]); const c = this; return { ...s, properties: { ...r }, setPropertyRelates(o, A) { if (o) { switch (o.propertyID) { case "disabled": case "readonly": case "visible": c.afterMutilEditorChanged(n, o); break; } i && i(o, A); } } }; } /** * 当多值编辑器变更时 * @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), de(); } /** * 属性编辑器,在编辑过程中会新增变量,此处需要将新增的变量追加到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: o, targetType: A, expressionType: d, value: a, message: p } = c, h = this.getExpressions(); let g = h.find((y) => y.target === o); g || (g = { target: o, rules: [], targetType: A }, h.push(g)); const m = g.rules.find((y) => y.type === d); if (m) m.id = r, m.value = a, m.message = p, (d === "minDate" || d === "maxDate" || d === "defaultTime") && (m.elementId = e.id); else { const y = { id: r, type: d, value: a, message: p, elementId: e.id }; g.rules.push(y); } 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, o = r.find((A) => A.target === c); !o || !o.rules || (o.rules = o.rules.filter((A) => A.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 I = class I { /** * 根据绑定字段类型获取可用的输入类控件 */ static getEditorTypesByMDataType(n, e = !1, t = "") { if (e) return [{ key: l["language-textbox"].type, value: l["language-textbox"].name }]; let i = I.fieldControlTypeMapping[n]; if (t === "data-grid-column" && (i != null && i.length)) { const s = [l["check-group"].type, l["radio-group"].type, l.image.type, l["rich-text-editor"].type, l.avatar.type]; i = i.filter((r) => !s.includes(r.key)); } return i; } /** * 获取所有输入类控件 */ static getAllInputTypes() { const n = []; for (const e in I.fieldControlTypeMapping) I.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 === l["data-grid-column"].type || n.type === l["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 === l["input-group"].type || t === l.textarea.type || t === l["number-spinner"].type) && i.push({ domField: "editor.maxLength", schemaField: "type.length" }), t === l["number-spinner"].type && i.push({ domField: "editor.precision", schemaField: "type.precision" }), (n.type === l["data-grid-column"].type || n.type === l["tree-grid-column"].type) && i.push({ domField: "formatter.precision", schemaField: "type.precision" }), (t === l["combo-list"].type || t === l["radio-group"].type) && i.push({ domField: "editor.data", schemaField: "type.enumValues" }), (n.type === l["data-grid-column"].type || n.type === l["tree-grid-column"].type) && i.push({ domField: "formatter.data", schemaField: "type.enumValues" }), t === l["date-picker"].type && (i.push({ domField: "editor.displayFormat", schemaField: "editor.format" }), i.push({ domField: "editor.fieldType", schemaField: "type.name" })), t === l["number-spinner"].type && (i.push({ domField: "editor.max", schemaField: "editor.maxValue" }), i.push({ domField: "editor.min", schemaField: "editor.minValue" })), t === l.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 === l["data-grid-column"].type || n.type === l["tree-grid-column"].type) && i.push({ domField: "field", schemaField: "bindingPath" }), i; } }; /** * <字段类型,可配置的控件类型列表>的映射 */ f(I, "fieldControlTypeMapping", { String: [ { key: l["input-group"].type, value: l["input-group"].name }, { key: l.lookup.type, value: l.lookup.name }, { key: l.image.type, value: l.image.name }, { key: l["date-picker"].type, value: l["date-picker"].name }, { key: l.switch.type, value: l.switch.name }, { key: l["check-box"].type, value: l["check-box"].name }, { key: l["check-group"].type, value: l["check-group"].name }, { key: l["radio-group"].type, value: l["radio-group"].name }, { key: l["combo-list"].type, value: l["combo-list"].name }, { key: l.textarea.type, value: l.textarea.name }, { key: l["time-picker"].type, value: l["time-picker"].name }, { key: l["rich-text-editor"].type, value: l["rich-text-editor"].name } ], Text: [ { key: l.textarea.type, value: l.textarea.name }, { key: l.lookup.type, value: l.lookup.name }, { key: l.image.type, value: l.image.name }, { key: l.avatar.type, value: l.avatar.name }, { key: l["rich-text-editor"].type, value: l["rich-text-editor"].name } ], Decimal: [ { key: l["number-spinner"].type, value: l["number-spinner"].name } ], Integer: [ { key: l["number-spinner"].type, value: l["number-spinner"].name } ], Number: [ { key: l["number-spinner"].type, value: l["number-spinner"].name }, { key: l.switch.type, value: l.switch.name }, { key: l["check-box"].type, value: l["check-box"].name } ], BigNumber: [ { key: l["number-spinner"].type, value: l["number-spinner"].name } ], Date: [ { key: l["date-picker"].type, value: l["date-picker"].name } ], DateTime: [ { key: l["date-picker"].type, value: l["date-picker"].name } ], Boolean: [ { key: l.switch.type, value: l.switch.name }, { key: l["check-box"].type, value: l["check-box"].name } ], Enum: [ { key: l["combo-list"].type, value: l["combo-list"].name }, { key: l["radio-group"].type, value: l["radio-group"].name } ], Object: [ { key: l.lookup.type, value: l.lookup.name }, { key: l["combo-list"].type, value: l["combo-list"].name } // { key: DgControl['radio-group'].type, value: DgControl['radio-group'].name }, ] }); let T = I; var B = /* @__PURE__ */ ((u) => (u.Form = "Form", u.Variable = "Variable", u))(B || {}); class N { constructor() { /** 控件标题 */ f(this, "label", ""); /** 控件id */ f(this, "id", ""); /** 每个控件占用的栅格数 */ f(this, "columnInSM", 12); f(this, "columnInMD", 6); f(this, "columnInLG", 3); f(this, "columnInEL", 2); /** 每个控件占用的列数 */ f(this, "displayWidthInSM", 1); f(this, "displayWidthInMD", 1); f(this, "displayWidthInLG", 1); f(this, "displayWidthInEL", 1); /** 编辑器内部默认显示的屏幕大小-----可以去掉 */ f(this, "displayColumnCountAtBreakPoint", "md"); /** 控件所在行,传0即可-----编辑器内部使用 */ f(this, "tagRow", 0); /** 控件是否显示上方空白:传0即可-----编辑器内部使用 */ f(this, "showTopBorder", 0); /** 区域,从1开始。卡片内的控件从上往下,从左往右划分区域,遇到分组fieldSet时group+1,分组结束后group+1 */ f(this, "group", 1); /** 控件是否符合标准的class配置(设计器用的) */ f(this, "isSupportedClass", !0); /** 控件所在分组id(设计器用的) */ f(this, "fieldSetId", ""); } } function fe(u) { let n, e; const t = /* @__PURE__ */ new Map(); let i = []; function s(d, a) { const h = (d || "").split(" ").filter((v) => v.startsWith("col-")); if (h.length === 0) { a.isSupportedClass = !1; return; } let g = h.find((v) => /^col-([1-9]|10|11|12)$/.test(v)), m = h.find((v) => /^col-md-([1-9]|10|11|12)$/.test(v)), y = h.find((v) => /^col-xl-([1-9]|10|11|12)$/.test(v)), C = h.find((v) => /^col-el-([1-9]|10|11|12)$/.test(v)); g = g || "col-12", a.columnInSM = parseInt(g.replace("col-", ""), 10), a.displayWidthInSM = a.columnInSM / 12, a.displayWidthInSM !== 1 && (a.isSupportedClass = !1), m = m || "col-md-" + a.columnInSM, a.columnInMD = parseInt(m.replace("col-md-", ""), 10), a.displayWidthInMD = a.columnInMD / 6, [1, 2].includes(a.displayWidthInMD) || (a.isSupportedClass = !1), y = y || "col-xl-" + a.columnInMD, a.columnInLG = parseInt(y.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, p, h = !1) { let g = !1; if (!d.contents || d.contents.length === 0) { const m = new N(); s(d.layout, m), a.push(m); return; } d.contents.forEach((m) => { if (m.type === "fieldset") { p += 1, r(m, a, p, !0), g = !0; return; } if (m.type === "dynamic-form") return; g && (p += 1, g = !1); const y = m.appearance && m.appearance.class, C = new N(); y ? s(y, C) : C.isSupportedClass = !1, C.label = m.label || m.id, C.id = m.id, C.group = p, h && (C.fieldSetId = d.id), e === m.id && (n = p), t.set(m.id, m), a.push(C); }); } function c(d) { const a = u.getComponentById(d); if (!a || !a.componentType || !a.componentType.startsWith("form")) return { result: !1, message: "只可以在响应式表单组件中调整响应式布局配置" }; const p = u.selectNode(a, (h) => h.type === l["response-form"].type); return !p || !p.contents || p.contents.length === 0 ? { result: !1, message: "Form区域内没有控件,请先添加控件" } : { result: !0, message: "", formNode: p }; } function o(d, a) { a = a || d.id; const { result: p, message: h, formNode: g } = c(a); if (!p) return { result: p, message: h }; e = d.id, i = [], t.clear(); const m = g.contents[0].type === l.fieldset.type ? 0 : 1; r(g, i, m); const y = i.find((v) => !v.isSupportedClass); return { defaultState: { defaultGroupNumber: n || 1, model: y ? "customize" : "standard" }, importData: i }; } function A(d, a) { a = a; const { result: p, formNode: h } = c(a); if (!p) return ""; const g = []; return d.forEach((m) => { var v; const y = t.get(m.id), C = y.appearance && y.appearance.class; if (C) { const V = C.split(" ").filter((z) => !z.startsWith("col-")), F = "col-" + m.columnInSM, j = "col-md-" + m.columnInMD, O = "col-xl-" + m.columnInLG, Z = "col-el-" + m.columnInEL, J = [F, j, O, Z].concat(V); y.appearance.class = J.join(" "); } if (m.fieldSetId) { const x = h.contents.find((F) => F.id === m.fieldSetId), V = g.find((F) => F.id === m.fieldSetId); V ? (v = V.contents) == null || v.push(y) : (g.push(x), x.contents = [y]); } else g.push(y); }), h.contents = g, h.id; } return { checkCanFindFormNode: c, checkCanOpenLayoutEditor: o, changeFormControlsByResponseLayoutConfig: A, getResonseFormLayoutConfig: r }; } const he = (u) => b(se, null, [b("h5", null, [re("代码示例")]), b("pre", { style: "background-color: #f5f5f5; padding: 10px; border-radius: 5px;" }, [b("code", null, [` <h3>Tips:</h3> <span style="color: blue;"> 自定义提示内容 </span> `])])]); class ye extends me { constructor(e, t) { super(e, t); f(this, "responseLayoutEditorFunction"); /** 控件绑定的变量 */ f(this, "bindingVarible"); f(this, "formGroupEvents", [ { label: "fieldValueChanging", name: "绑定字段值变化前事件" }, { label: "fieldValueChanged", name: "绑定字段值变化后事件" }, { label: "onClickLabel", name: "标签点击事件" } ]); f(this, "numberEditorOptions", { type: "number-spinner", useThousands: !1, keyboard: !1, showButton: !1 }); f(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 = fe(this.formSchemaUtils); } getCommonPropertyConfig(e, t, i = "Card") { if (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"), i === "Card") { const s = this.getTipsConfig(e); this.propertyConfig.categories.behavior.properties = { ...this.propertyConfig.categories.behavior.properties, ...s }, ["time-picker", "date-picker", "lookup", "combo-list", "number-spinner", "input-group", "language-textbox"].includes(e.editor.type) && (this.propertyConfig.categories.expansion = this.getExpandProperties(e, i)); } } 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 a; const s = this; this.setDesignViewModelField(e); const { canChangeControlType: r, editorTypeList: c } = this.getAvailableEditorType(e), o = this.getPropertyEditorParams(e, ["Variable"], "label", {}, { newVariablePrefix: "", newVariableType: "String" }); let A = c; this.formRule && (A = c.filter((p) => p.key !== "image" && p.key !== "rich-text-editor" && p.key !== "avatar")); const d = { 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: A, readonly: !r } }, titleSourceType: { description: "标签来源类型", title: "标签类型", type: "string", refreshPanelAfterChanged: !0, editor: { type: "combo-list", textField: "name", valueField: "id", idField: "id", editable: !1, data: [{ id: "static", name: "静态" }, { id: "dynamic", name: "动态" }] }, defaultValue: "static" }, label: { title: "标签", type: "string", $converter: "/converter/form-group-label.converter", visible: !e.titleSourceType || e.titleSourceType === "static" }, titleDataSource: { description: "标签", title: "标签", type: "string", editor: o, visible: e.titleSourceType === "dynamic" }, showLabelType: { description: "标签显示方式:1、显示:显示标签 2、占位:保留标签空间,但不显示文本 3、不显示:不显示标签", title: "标签显示", type: "enum", editor: { data: [{ id: "visible", name: "显示" }, { id: "reserve-space", name: "占位" }, { id: "none", name: "不显示" }] }, defaultValue: ((a = e.editor) == null ? void 0 : a.type) === "image" ? "none" : "visible" }, binding: { description: "绑定的表单字段", title: "绑定", editor: { type: "binding-selector", bindingType: { enable: !0 }, title: "绑定编辑器", 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(p, h, g) { if (p) switch (p && p.propertyID) { case "type": { s.changeControlType(e, p, t); break; } case "label": { p.needRefreshControlTree = !0; break; } case "binding": { s.changeBindingField(e, p, g); break; } case "titleDataSource": { s.afterMutilEditorChanged(e, p); break; } } } }; return i.toLocaleLowerCase() !== "card" && (d.hide = !0, delete d.properties.showLabelType), d; } getExpandProperties(e, t = "Card") { const i = this, s = ["Const", "Variable"], r = this.getPropertyEditorParams(e, s, "expandable"), c = this.getPropertyEditorParams(e, s, "expandDisabled"); return t === "Card" ? { description: "Expand Information", hide: !!this.formRule, title: "扩展区域", properties: { expandable: { description: "扩展区域是指输入框右侧的区域,常用于展示自定义按钮或者文本,以便于丰富输入控件的展示内容。", title: "启用扩展区域", refreshPanelAfterChanged: !0, $converter: "/converter/property-editor.converter", editor: r }, expandMode: { description: "静态文本:扩展内容不可点击;交互式按钮:扩展内容可以点击并配置交互事件。", title: "扩展模式", type: "enum", refreshPanelAfterChanged: !0, $converter: "/converter/property-editor.converter", editor: { data: [{ id: "text", name: "静态文本" }, { id: "button", name: "交互按钮" }] }, defaultValue: "text", visible: !!e.editor.expandable }, expandContent: { $converter: "/converter/property-editor.converter", description: "扩展区域内展示的文本内容", title: "扩展内容", type: "string", visible: !!e.editor.expandable, editor: { type: "code-editor", language: "html" } }, expandDisabled: { $converter: "/converter/property-editor.converter", description: "是否动态隐藏扩展区域,常用于根据变量或自定义条件配置扩展区域的隐藏状态。", title: "隐藏扩展区域", editor: c, visible: !!e.editor.expandable } }, setPropertyRelates(A, d) { if (A) switch (A.propertyID) { case "expandable": case "expandDisabled": i.afterMutilEditorChanged(e, A); break; } } } : { properties: {} }; } /** * 校验控件是否支持切换类型 * @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 !== Q.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 = l[e.editor.type]) == null ? void 0 : s.name) || e.editor.type }] }; let i = []; return this.designViewModelField && this.designViewModelField.$type === Q.SimpleField ? i = T.getEditorTypesByMDataType(this.designViewModelField.type.name, this.designViewModelField.multiLanguage) : this.bindingVarible && (i = T.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), P.value++; break; case "style": { P.value++; break; } } } }; } getEditorProperties(e) { return this.getComponentConfig(e); } /** * 卡片控件:切换控件类型后事件 * @param propertyData 控件DOM属性 * @param newControlType 新控件类型 */ changeControlType(e, t, i) { var g; const s = t.propertyValue, r = i && i.parent && i.parent.schema; if (!r) return; const c = r.contents.findIndex((m) => m.id === e.id); if (c === -1) return; const o = r.contents[c]; let A; if (this.designViewModelField) { const C = this.formSchemaUtils.getViewModelById(this.viewModelId).fields.find((x) => x.id === this.designViewModelField.id).fieldSchema || {}; C.editor || (C.editor = {}), C.editor.$type = s, this.designViewModelUtils.getDgViewModel(this.viewModelId).changeField(this.designViewModelField.id, C, !1), A = this.controlCreatorUtils.setFormFieldProperty(this.designViewModelField, s); } A || (A = this.controlCreatorUtils.createFormGroupWithoutField(s)), Object.assign(A, { id: o.id, appearance: o.appearance, size: o.size, label: o.label, binding: o.binding }), Object.prototype.hasOwnProperty.call(o, "visible") && Object.assign(A, { visible: o.visible }), o.editor && ["readonly", "required", "placeholder"].map((m) => { Object.prototype.hasOwnProperty.call(o.editor, m) && (A.editor[m] = o.editor[m]); }); const d = ["image", "avatar"], a = o.editor.type && d.indexOf(o.editor.type) > -1, p = ((g = A.editor) == null ? void 0 : g.type) && d.indexOf(A.editor.type) > -1; a && o.showLabelType === "none" && !p && (A.showLabelType = "visible"), i != null && i.updateContextSchema ? i.updateContextSchema(A) : (i.schema = Object.assign(o, A), Object.assign(e, A)), Array.from(document.getElementsByClassName("dgComponentSelected")).forEach( (m) => m.classList.remove("dgComponentSelected") ), Array.from(document.getElementsByClassName("dgComponentFocused")).forEach( (m) => m.classList.remove("dgComponentFocused") ), ["time-picker", "date-picker", "lookup", "combo-list", "number-spinner", "input-group", "textarea", "rich-text-editor", "language-textbox"].includes(e.editor.type) || (e.enableTips = !1), P.value++, oe(() => { this.getFormDesignerInstance().reloadPropertyPanel(); }); } getTipsConfig(e) { return ["time-picker", "date-picker", "lookup", "combo-list", "number-spinner", "input-group", "textarea", "rich-text-editor", "language-textbox"].includes(e.editor.type) ? { enableTips: { refreshPanelAfterChanged: !0, description: "", title: "启用提示", type: "boolean", default: !1, visible: !this.formRule }, tipsContent: { description: "提示内容", title: "提示内容", type: "string", editor: { type: "code-editor", language: "html", leftTemplate: he }, visible: !!e.enableTips && !this.formRule } } : {}; } getComponentConfig(e, t = {}, i = {}, s) { var p, h, g; const r = Object.assign({ description: "编辑器", title: "编辑器", type: "input-group", $converter: "/converter/property-editor.converter", parentPropertyID: "editor" }, t), c = (p = e.binding) != null && p.field ? ["Const", "Variable", "StateMachine", "Custom", "Expression"] : ["Const", "Variable", "StateMachine", "Custom"], o = this.getPropertyEditorParams(e, c, "readonly"), A = this.getPropertyEditorParams(e, c, "required"), d = { readonly: { description: "", title: "只读", editor: o }, required: { description: "", title: "必填", type: "boolean", editor: A, visible: !!((h = e.binding) != null && h.field) && ((g = e.binding) == null ? void 0 : g.type) === "Form" }, placeholder: { description: "当控件没有值时在输入框中显示的文本", title: "提示文本", type: "string" } }; for (const m in i) d[m] = Object.assign(d[m] || {}, i[m]); const a = this; return { ...r, properties: { ...d }, setPropertyRelates(m, y) { if (m) { switch (m.propertyID) { case "readonly": case "required": case "label": a.afterMutilEditorChanged(e, m); break; } s && s.bind(a)(m, e, y); } } }; } /** * 修改某一输入控件的样式后更新Form的统一布局配置 * @param controlClass 控件样式 * @param controlId 控件Id * @param componentId 控件所在组件id */ updateUnifiedLayoutAfterControlChanged(e, t, i) { const s = e.split(" "); let r = s.find((a) => /^col-([1-9]|10|11|12)$/.test(a)), c = s.find((a) => /^col-md-([1-9]|10|11|12)$/.test(a)), o = s.find((a) => /^col-xl-([1-9]|10|11|12)$/.test(a)), A = s.find((a) => /^col-el-([1-9]|10|11|12)$/.test(a)); r = r || "col-12", c = c || "col-md-" + r.replace("col-", ""), o = o || "col-xl-" + c.replace("col-md-", ""), A = A || "col-el-" + o.replace("col-xl-", ""); const d = { id: t, columnInSM: parseInt(r.replace("col-", ""), 10), columnInMD: parseInt(c.replace("col-md-", ""), 10), columnInLG: parseInt(o.replace("col-xl-", ""), 10), columnInEL: parseInt(A.replace("col-el-", ""), 10) }; this.updateUnifiedLayoutAfterResponseLayoutChanged(i, d); } /** * 修改控件布局配置后更新Form统一布局配置 * @param componentId 组件Id * @param controlLayoutConfig 某单独变动的控件配置项,FormResponseLayoutContext类型 */ updateUnifiedLayoutAfterResponseLayoutChanged(e, t) { const { formNode: i } = this.responseLayoutEditorFunction.checkCanFindFormNode(e); if (!i || !i.unifiedLayout) return; const s = []; if (this.responseLayoutEditorFunction.getResonseFormLayoutConfig(i, s, 1), t) { const g = s.find((m) => m.id === t.id); Object.assign(g || {}, t); } const r = s.map((g) => g.columnInSM), c = s.map((g) => g.columnInMD), o = s.map((g) => g.columnInLG), A = s.map((g) => g.columnInEL), d = this.checkIsUniqueColumn(r) ? r[0] : null, a = this.checkIsUniqueColumn(c) ? c[0] : null, p = this.checkIsUniqueColumn(o) ? o[0] : null, h = this.checkIsUniqueColumn(A) ? A[0] : null; Object.assign(i.unifiedLayout, { uniqueColClassInSM: d, uniqueColClassInMD: a, uniqueColClassInLG: p, uniqueColClassInEL: h }); } /** * 校验宽度样式值是否一致 */ checkIsUniqueColumn(e) { const t = new Set(e); return Array.from(t).length === 1; } /** * 枚举项编辑器 * @param propertyData * @param valueField * @param textField * @returns */ getItemCollectionEditor(e, t, i) { return t = t || "value", i = i || "name", { editor: { columns: [ { field: t, title: "值", dataType: "string" }, { field: i, title: "名称", dataType: "string" } // { field: 'disabled', title: '禁用', dataType: 'boolean', editor: { type: 'switch' } }, ], type: "item-collection-editor", valueField: t, nameField: i, requiredFields: [t, i], uniqueFields: [t, i], readonly: this.checkEnumDataReadonly(e) } }; } /** * 判断枚举数据是否只读 * 1、没有绑定信息或者绑定变量,可以新增、删除、修改 * 2、绑定类型为字段,且字段为枚举字段,则不可新增、删除、修改枚举值。只能从be修改然后同步到表单上。 * @param propertyData 下拉框控件属性值 */ checkEnumDataReadonly(e) { return !e.binding || e.binding.type !== "Form" ? !1 : !!(this.designViewModelField && this.designViewModelField.type && this.designViewModelField.type.$type === X.EnumType); } /** * 将字段值变化前事件、变化后事件追加到交互面板 * 注意:因为绑定字段值变化后事件与下拉框的值变化事件(valueChanged)重名,所以这里将事件label都重命名下 */ appendFieldValueChangeEvents(e, t) { e.binding && e.binding.type === B.Form && e.binding.field ? (t.find((i) => i.label === "fieldValueChanging"), t.find((i) => i.label === "fieldValueChanged"), this.designViewModelField && (e.fieldValueChanging = this.designViewModelField.valueChanging, e.fieldValueChanged = this.designViewModelField.valueChanged)) : t = t.filter((i) => i.label !== "fieldValueChanging" && i.label !== "fieldValueChanged"); } getControlMethodType(e) { if (!e.binding) return e.type; switch (e.binding.type) { case B.Form: return e.binding.path || e.type; case B.Variable: return e.binding.fullPath || e.type; } return e.type; } updateLinkedLabel(e, t) { if (e.boundEventsList && e