UNPKG

@farris/ui-vue

Version:

Farris Vue, a Farris Design based Vue3 component library.

1,345 lines 68.1 kB
var K = Object.defineProperty; var D = (u, n, e) => n in u ? K(u, n, { enumerable: !0, configurable: !0, writable: !0, value: e }) : u[n] = e; var h = (u, n, e) => D(u, typeof n != "symbol" ? n + "" : n, e); import { FormSchemaEntityField$Type as R, FormSchemaEntityFieldType$Type as ee, EVENT_PROPERTY_TAB_IDS as L, getCustomClass as O, getCustomStyle as q, withInstall as te } from "../../components/common/index.esm.js"; import { createVNode as C, Fragment as ie, createTextVNode as B, nextTick as ne, defineComponent as G, ref as w, inject as U, onMounted as se, watch as P, computed as k } from "vue"; import { DgControl as l, canvasChanged as S, refreshCanvas as re, useDesignerComponent as oe } from "../../components/designer-canvas/index.esm.js"; import { cloneDeep as ae } from "lodash-es"; import { resolveAppearance as W, createPropsResolver as z } from "../../components/dynamic-resolver/index.esm.js"; import { FNotifyService as le } from "../../components/notify/index.esm.js"; function de(u) { const { formSchemaUtils: n, formStateMachineUtils: e } = u; function t(a, g = "") { return { path: g + a.code, field: a.id, fullPath: a.code }; } function i(a, g = "") { const f = n.getViewModelById(a); return f ? f.states.map((o) => t(o, g)) : []; } function s(a) { const g = n.getRootViewModelId(), f = i(a); if (a === g) return f; const o = i(g, "root-component."); return [...f, ...o]; } function r(a) { return a.binding && a.binding.path || a.id || ""; } function c() { return e && e.getRenderStates() || []; } return { getVariables: s, getControlName: r, getStateMachines: c }; } class ce { constructor(n) { h(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'" } ]); h(this, "expressionNames", { compute: "计算表达式", dependency: "依赖表达式", validate: "验证表达式", dataPicking: "帮助前表达式", visible: "可见表达式", readonly: "只读表达式", required: "必填表达式" }); h(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 a; if (i === "dataPicking" && (s != null && s.target)) { const g = `${s.target}_dataPicking`; ((a = s.rules) == null ? void 0 : a.some( (o) => o.id === g && o.value )) ? t.dictPickingExpressionId = g : 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 a, g; const s = this.createTreeNode(i, e); s.type = "entity"; const r = this.buildEntityFieldsTreeData((a = i.type) == null ? void 0 : a.fields, [...e, i.label]), c = this.buildChildEntityTreeData((g = i.type) == null ? void 0 : g.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, a = { id: `${n}_${t}`, type: t, value: s }; return (t === "validate" || t === "dataPicking" || t === "required") && (a.message = r), t === "dataPicking" && (a.messageType = c), t === "validate" && i && (a.elementId = i), a; } 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 a = this.getExpressionData().find((f) => f.targetType === e && f.target === s); const g = (f) => f.value.trim() === ""; if (a) { const f = a.rules.find((o) => o.id === r.id); if (f) g(r) ? a.rules = a.rules.filter((o) => o.id !== r.id) : (Object.assign(f, r), i === "validate" && n.type === "form-group" && (f.elementId = n.id)); else { if (g(r)) return null; a.rules = a.rules || [], a.rules.push(r); } } else { if (g(r)) return null; a = { target: `${s}`, rules: [r], targetType: e }; } return a; } getExpressionEditorOptions(n, e, t, i) { return t.reduce((s, r) => { var a, g; const c = e === "Field" ? (a = n == null ? void 0 : n.binding) == null ? void 0 : a.field : n.id; return s[r] = { hide: e === "Field" ? !!((g = n == null ? void 0 : n.binding) != null && g.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: (f) => { const o = this.updateExpression(n, e, f, r); if (i) { const d = this.buildRule(c, f, r); i(d); } return o; } } }, 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 ue { constructor(n, e) { h(this, "componentId"); h(this, "viewModelId"); h(this, "eventsEditorUtils"); h(this, "formSchemaUtils"); h(this, "formMetadataConverter"); h(this, "designViewModelUtils"); h(this, "designViewModelField"); h(this, "controlCreatorUtils"); h(this, "designerHostService"); h(this, "designerContext"); h(this, "modalService", null); /** 表单规则 */ h(this, "formRule", null); h(this, "schemaService", null); h(this, "metadataService", null); h(this, "propertyConfig", { type: "object", categories: {} }); h(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 ce(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": { S.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: a, getStateMachines: g } = de(this.designerHostService), f = this.getRealTargetType(n), o = e && e.length > 0 ? e : ["Const", "Variable", "StateMachine", "Expression"], d = { type: "property-editor", propertyTypes: o }; return o.map((v) => { switch (v) { case "Const": Object.assign(d, { constType: "enum", constEnums: [{ id: !0, name: "是" }, { id: !1, name: "否" }] }, i); break; case "Expression": d.expressionConfig = this.getExpressionOptions(n, f, r || t); break; case "StateMachine": d.stateMachines = g(); break; case "Variable": Object.assign(d, { controlName: a(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" && (d.newVariablePrefix = "ext_" + d.newVariablePrefix); break; } }), d; } 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 a in t) r[a] = Object.assign(r[a] || {}, t[a]); const c = this; return { ...s, properties: { ...r }, setPropertyRelates(a, g) { if (a) { switch (a.propertyID) { case "disabled": case "readonly": case "visible": c.afterMutilEditorChanged(n, a); break; } i && i(a, g); } } }; } /** * 当多值编辑器变更时 * @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 = ae(t.contents[i]); t.contents.splice(i, 1), t.contents.splice(i, 0, s), re(); } /** * 属性编辑器,在编辑过程中会新增变量,此处需要将新增的变量追加到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: a, targetType: g, expressionType: f, value: o, message: d } = c, v = this.getExpressions(); let m = v.find((y) => y.target === a); m || (m = { target: a, rules: [], targetType: g }, v.push(m)); const p = m.rules.find((y) => y.type === f); if (p) p.id = r, p.value = o, p.message = d, (f === "minDate" || f === "maxDate" || f === "defaultTime") && (p.elementId = e.id); else { const y = { id: r, type: f, value: o, message: d, elementId: e.id }; m.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, a = r.find((g) => g.target === c); !a || !a.rules || (a.rules = a.rules.filter((g) => g.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 E = class E { /** * 根据绑定字段类型获取可用的输入类控件 */ static getEditorTypesByMDataType(n, e = !1, t = "") { if (e) return [{ key: l["language-textbox"].type, value: l["language-textbox"].name }]; let i = E.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)); } if (t === "tree-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, l.switch.type]; i = i.filter((r) => !s.includes(r.key)); } return i; } /** * 获取所有输入类控件 */ static getAllInputTypes() { const n = []; for (const e in E.fieldControlTypeMapping) E.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; } }; /** * <字段类型,可配置的控件类型列表>的映射 */ h(E, "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 = E; var V = /* @__PURE__ */ ((u) => (u.Form = "Form", u.Variable = "Variable", u))(V || {}); class $ { constructor() { /** 控件标题 */ h(this, "label", ""); /** 控件id */ h(this, "id", ""); /** 每个控件占用的栅格数 */ h(this, "columnInSM", 12); h(this, "columnInMD", 6); h(this, "columnInLG", 3); h(this, "columnInEL", 2); /** 每个控件占用的列数 */ h(this, "displayWidthInSM", 1); h(this, "displayWidthInMD", 1); h(this, "displayWidthInLG", 1); h(this, "displayWidthInEL", 1); /** 编辑器内部默认显示的屏幕大小-----可以去掉 */ h(this, "displayColumnCountAtBreakPoint", "md"); /** 控件所在行,传0即可-----编辑器内部使用 */ h(this, "tagRow", 0); /** 控件是否显示上方空白:传0即可-----编辑器内部使用 */ h(this, "showTopBorder", 0); /** 区域,从1开始。卡片内的控件从上往下,从左往右划分区域,遇到分组fieldSet时group+1,分组结束后group+1 */ h(this, "group", 1); /** 控件是否符合标准的class配置(设计器用的) */ h(this, "isSupportedClass", !0); /** 控件所在分组id(设计器用的) */ h(this, "fieldSetId", ""); } } function pe(u) { let n, e; const t = /* @__PURE__ */ new Map(); let i = []; function s(f, o) { const v = (f || "").split(" ").filter((x) => x.startsWith("col-")); if (v.length === 0) { o.isSupportedClass = !1; return; } let m = v.find((x) => /^col-([1-9]|10|11|12)$/.test(x)), p = v.find((x) => /^col-md-([1-9]|10|11|12)$/.test(x)), y = v.find((x) => /^col-xl-([1-9]|10|11|12)$/.test(x)), b = v.find((x) => /^col-el-([1-9]|10|11|12)$/.test(x)); m = m || "col-12", o.columnInSM = parseInt(m.replace("col-", ""), 10), o.displayWidthInSM = o.columnInSM / 12, o.displayWidthInSM !== 1 && (o.isSupportedClass = !1), p = p || "col-md-" + o.columnInSM, o.columnInMD = parseInt(p.replace("col-md-", ""), 10), o.displayWidthInMD = o.columnInMD / 6, [1, 2].includes(o.displayWidthInMD) || (o.isSupportedClass = !1), y = y || "col-xl-" + o.columnInMD, o.columnInLG = parseInt(y.replace("col-xl-", ""), 10), o.displayWidthInLG = o.columnInLG / 3, [1, 2, 3, 4].includes(o.displayWidthInLG) || (o.isSupportedClass = !1), b = b || "col-el-" + o.columnInLG, o.columnInEL = parseInt(b.replace("col-el-", ""), 10), o.displayWidthInEL = o.columnInEL / 2, [1, 2, 3, 4, 5, 6].includes(o.displayWidthInEL) || (o.isSupportedClass = !1); } function r(f, o, d, v = !1) { let m = !1; if (!f.contents || f.contents.length === 0) { const p = new $(); s(f.layout, p), o.push(p); return; } f.contents.forEach((p) => { if (p.type === "fieldset") { d += 1, r(p, o, d, !0), m = !0; return; } if (p.type === "dynamic-form") return; m && (d += 1, m = !1); const y = p.appearance && p.appearance.class, b = new $(); y ? s(y, b) : b.isSupportedClass = !1, b.label = p.label || p.id, b.id = p.id, b.group = d, v && (b.fieldSetId = f.id), e === p.id && (n = d), t.set(p.id, p), o.push(b); }); } function c(f) { const o = u.getComponentById(f); if (!o || !o.componentType || !o.componentType.startsWith("form")) return { result: !1, message: "只可以在响应式表单组件中调整响应式布局配置" }; const d = u.selectNode(o, (v) => v.type === l["response-form"].type); return !d || !d.contents || d.contents.length === 0 ? { result: !1, message: "Form区域内没有控件,请先添加控件" } : { result: !0, message: "", formNode: d }; } function a(f, o) { o = o || f.id; const { result: d, message: v, formNode: m } = c(o); if (!d) return { result: d, message: v }; e = f.id, i = [], t.clear(); const p = m.contents[0].type === l.fieldset.type ? 0 : 1; r(m, i, p); const y = i.find((x) => !x.isSupportedClass); return { defaultState: { defaultGroupNumber: n || 1, model: y ? "customize" : "standard" }, importData: i }; } function g(f, o) { o = o; const { result: d, formNode: v } = c(o); if (!d) return ""; const m = []; return f.forEach((p) => { var x; const y = t.get(p.id), b = y.appearance && y.appearance.class; if (b) { const M = b.split(" ").filter((Z) => !Z.startsWith("col-")), I = "col-" + p.columnInSM, Y = "col-md-" + p.columnInMD, H = "col-xl-" + p.columnInLG, J = "col-el-" + p.columnInEL, Q = [I, Y, H, J].concat(M); y.appearance.class = Q.join(" "); } if (p.fieldSetId) { const F = v.contents.find((I) => I.id === p.fieldSetId), M = m.find((I) => I.id === p.fieldSetId); M ? (x = M.contents) == null || x.push(y) : (m.push(F), F.contents = [y]); } else m.push(y); }), v.contents = m, v.id; } return { checkCanFindFormNode: c, checkCanOpenLayoutEditor: a, changeFormControlsByResponseLayoutConfig: g, getResonseFormLayoutConfig: r }; } const ge = (u) => C(ie, null, [C("h5", null, [B("代码示例")]), C("pre", { style: "background-color: #f5f5f5; padding: 10px; border-radius: 5px;" }, [C("code", null, [` <h3>Tips:</h3> <span style="color: blue;"> 自定义提示内容 </span> `])])]); class me extends ue { constructor(e, t) { super(e, t); h(this, "responseLayoutEditorFunction"); /** 控件绑定的变量 */ h(this, "bindingVarible"); h(this, "formGroupEvents", [ { label: "fieldValueChanging", name: "绑定字段值变化前事件" }, { label: "fieldValueChanged", name: "绑定字段值变化后事件" }, { label: "onClickLabel", name: "标签点击事件" } ]); h(this, "numberEditorOptions", { type: "number-spinner", useThousands: !1, keyboard: !1, showButton: !1 }); h(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 = pe(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 o; const s = this; this.setDesignViewModelField(e); const { canChangeControlType: r, editorTypeList: c } = this.getAvailableEditorType(e), a = this.getPropertyEditorParams(e, ["Variable"], "label", {}, { newVariablePrefix: "", newVariableType: "String" }); let g = c; this.formRule && (g = c.filter((d) => d.key !== "image" && d.key !== "rich-text-editor" && d.key !== "avatar")); const f = { 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: g, 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: a, 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: ((o = e.editor) == null ? void 0 : o.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(d, v, m) { if (d) switch (d && d.propertyID) { case "type": { s.changeControlType(e, d, t); break; } case "label": { d.needRefreshControlTree = !0; break; } case "binding": { s.changeBindingField(e, d, m); break; } case "titleDataSource": { s.afterMutilEditorChanged(e, d); break; } } } }; return i.toLocaleLowerCase() !== "card" && (f.hide = !0, delete f.properties.showLabelType), f; } 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(g, f) { if (g) switch (g.propertyID) { case "expandable": case "expandDisabled": i.afterMutilEditorChanged(e, g); 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 !== R.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 === R.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), S.value++; break; case "style": { S.value++; break; } } } }; } getEditorProperties(e) { return this.getComponentConfig(e); } /** * 卡片控件:切换控件类型后事件 * @param propertyData 控件DOM属性 * @param newControlType 新控件类型 */ changeControlType(e, t, i) { var m; const s = t.propertyValue, r = i && i.parent && i.parent.schema; if (!r) return; const c = r.contents.findIndex((p) => p.id === e.id); if (c === -1) return; const a = r.contents[c]; let g; if (this.designViewModelField) { const b = this.formSchemaUtils.getViewModelById(this.viewModelId).fields.find((F) => F.id === this.designViewModelField.id).fieldSchema || {}; b.editor || (b.editor = {}), b.editor.$type = s, this.designViewModelUtils.getDgViewModel(this.viewModelId).changeField(this.designViewModelField.id, b, !1), g = this.controlCreatorUtils.setFormFieldProperty(this.designViewModelField, s); } g || (g = this.controlCreatorUtils.createFormGroupWithoutField(s)), Object.assign(g, { id: a.id, appearance: a.appearance, size: a.size, label: a.label, binding: a.binding }), Object.prototype.hasOwnProperty.call(a, "visible") && Object.assign(g, { visible: a.visible }), a.editor && ["readonly", "required", "placeholder"].map((p) => { Object.prototype.hasOwnProperty.call(a.editor, p) && (g.editor[p] = a.editor[p]); }); const f = ["image", "avatar"], o = a.editor.type && f.indexOf(a.editor.type) > -1, d = ((m = g.editor) == null ? void 0 : m.type) && f.indexOf(g.editor.type) > -1; o && a.showLabelType === "none" && !d && (g.showLabelType = "visible"), i != null && i.updateContextSchema ? i.updateContextSchema(g) : (i.schema = Object.assign(a, g), Object.assign(e, g)), Array.from(document.getElementsByClassName("dgComponentSelected")).forEach( (p) => p.classList.remove("dgComponentSelected") ), Array.from(document.getElementsByClassName("dgComponentFocused")).forEach( (p) => p.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), S.value++, ne(() => { 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: ge }, visible: !!e.enableTips && !this.formRule } } : {}; } getComponentConfig(e, t = {}, i = {}, s) { var d, v, m; const r = Object.assign({ description: "编辑器", title: "编辑器", type: "input-group", $converter: "/converter/property-editor.converter", parentPropertyID: "editor" }, t), c = (d = e.binding) != null && d.field ? ["Const", "Variable", "StateMachine", "Custom", "Expression"] : ["Const", "Variable", "StateMachine", "Custom"], a = this.getPropertyEditorParams(e, c, "readonly"), g = this.getPropertyEditorParams(e, c, "required"), f = { readonly: { description: "", title: "只读", editor: a }, required: { description: "", title: "必填", type: "boolean", editor: g, visible: !!((v = e.binding) != null && v.field) && ((m = e.binding) == null ? void 0 : m.type) === "Form" }, placeholder: { description: "当控件没有值时在输入框中显示的文本", title: "提示文本", type: "string" } }; for (const p in i) f[p] = Object.assign(f[p] || {}, i[p]); const o = this; return { ...r, properties: { ...f }, setPropertyRelates(p, y) { if (p) { switch (p.propertyID) { case "readonly": case "required": case "label": o.afterMutilEditorChanged(e, p); break; } s && s.bind(o)(p, e, y); } } }; } /** * 修改某一输入控件的样式后更新Form的统一布局配置 * @param controlClass 控件样式 * @param controlId 控件Id * @param componentId 控件所在组件id */ updateUnifiedLayoutAfterControlChanged(e, t, i) { const s = e.split(" "); let r = s.find((o) => /^col-([1-9]|10|11|12)$/.test(o)), c = s.find((o) => /^col-md-([1-9]|10|11|12)$/.test(o)), a = s.find((o) => /^col-xl-([1-9]|10|11|12)$/.test(o)), g = s.find((o) => /^col-el-([1-9]|10|11|12)$/.test(o)); r = r || "col-12", c = c || "col-md-" + r.replace("col-", ""), a = a || "col-xl-" + c.replace("col-md-", ""), g = g || "col-el-" + a.replace("col-xl-", ""); const f = { id: t, columnInSM: parseInt(r.replace("col-", ""), 10), columnInMD: parseInt(c.replace("col-md-", ""), 10), columnInLG: parseInt(a.replace("col-xl-", ""), 10), columnInEL: parseInt(g.replace("col-el-", ""), 10) }; this.updateUnifiedLayoutAfterResponseLayoutChanged(i, f); } /** * 修改控件布局配置后更新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 m = s.find((p) => p.id === t.id); Object.assign(m || {}, t); } const r = s.map((m) => m.columnInSM), c = s.map((m) => m.columnInMD), a = s.map((m) => m.columnInLG), g = s.map((m) => m.columnInEL), f = this.checkIsUniqueColumn(r) ? r[0] : null, o = this.checkIsUniqueColumn(c) ? c[0] : null, d = this.checkIsUniqueColumn(a) ? a[0] : null, v = this.checkIsUniqueColumn(g) ? g[0] : null; Object.assign(i.unifiedLayout, { uniqueColClassInSM: f, uniqueColClassInMD: o, uniqueColClassInLG: d, uniqueColClassInEL: v }); } /** * 校验宽度样式值是否一致 */ 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 === ee.EnumType); } /** * 将字段值变化前事件、变化后事件追加到交互面板 * 注意:因为绑定字段值变化后事件与下拉框的值变化事件(valueChanged)重名,所以这里将事件label都重命名下 */ appendFieldValueChangeEvents(e, t) { e.binding && e.binding.type === V.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 V.Form: return e.binding.path || e.type; case V.Variable: return e.binding