UNPKG

@farris/ui-vue

Version:

Farris Vue, a Farris Design based Vue3 component library.

826 lines (825 loc) 26.8 kB
var D = Object.defineProperty; var q = (a, e, t) => e in a ? D(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t; var g = (a, e, t) => q(a, typeof e != "symbol" ? e + "" : e, t); import { defineComponent as F, createVNode as U, ref as G, inject as S, computed as j, onMounted as L } from "vue"; import { resolveAppearance as _, createPropsResolver as z, getPropsResolverGenerator as Q } from "../dynamic-resolver/index.esm.js"; import { getCustomClass as J } from "../common/index.esm.js"; import { DgControl as w, canvasChanged as K, refreshCanvas as W, UseTemplateDragAndDropRules as X, useDragulaCommonRule as Y, useDesignerComponent as Z } from "../designer-canvas/index.esm.js"; import { cloneDeep as H } from "lodash-es"; const N = /* @__PURE__ */ new Map([ ["appearance", _] ]), ee = "https://json-schema.org/draft/2020-12/schema", te = "https://farris-design.gitee.io/content-container.schema.json", ne = "content-container", se = "A Farris Container Component", ie = "object", re = { id: { description: "The unique identifier for a Section", type: "string" }, type: { description: "The type string of Section component", type: "string", default: "content-container" }, appearance: { description: "", type: "object", properties: { class: { type: "string" }, style: { type: "string" } }, default: {} }, contents: { description: "", type: "array", default: [] }, size: { description: "", type: "object", properties: { width: { type: "number" }, height: { type: "number" } }, default: null }, visible: { description: "", type: "boolean", default: !0 } }, oe = [ "id", "type", "contents" ], B = { $schema: ee, $id: te, title: ne, description: se, type: ie, properties: re, required: oe }; function O(a, e, t) { return e; } const R = { customClass: { type: String, default: "" }, customStyle: { type: String, default: "" }, /** 控制是否可见 */ visible: { type: Boolean, default: !0 } }, Ce = z(R, B, N, O), k = Q( R, B, N, O ), T = /* @__PURE__ */ F({ name: "FContentContainer", props: R, emits: [], setup(a, e) { return () => a.visible && U("div", { class: a.customClass, style: a.customStyle }, [e.slots.default && e.slots.default()]); } }); function ae(a) { const { formSchemaUtils: e, formStateMachineUtils: t } = a; function n(o, d = "") { return { path: d + o.code, field: o.id, fullPath: o.code }; } function s(o, d = "") { const u = e.getViewModelById(o); return u ? u.states.map((m) => n(m, d)) : []; } function r(o) { const d = e.getRootViewModelId(), u = s(o); if (o === d) return u; const m = s(d, "root-component."); return [...u, ...m]; } function i(o) { return o.binding && o.binding.path || o.id || ""; } function c() { return t && t.getRenderStates() || []; } return { getVariables: r, getControlName: i, getStateMachines: c }; } class ce { constructor(e) { g(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'" } ]); g(this, "expressionNames", { compute: "计算表达式", dependency: "依赖表达式", validate: "验证表达式", dataPicking: "帮助前表达式", visible: "可见表达式", readonly: "只读表达式", required: "必填表达式" }); g(this, "getExpressionConverter", (e, t) => ({ convertFrom: (n, s, r, i) => { const c = r.getExpressionRuleValue(e, t || s); return c && c.value || ""; }, convertTo: (n, s, r, i, c) => { var o; if (s === "dataPicking" && (r != null && r.target)) { const d = `${r.target}_dataPicking`; ((o = r.rules) == null ? void 0 : o.some( (m) => m.id === d && m.value )) ? n.dictPickingExpressionId = d : delete n.dictPickingExpressionId; } i.updateExpression(r); } })); this.formSchemaService = e; } getExpressionRule(e, t) { const n = this.getExpressionData(); if (!n) return ""; const s = n.find((i) => i.target === e); if (!s) return ""; const r = s.rules.find((i) => i.type === t); return r || ""; } // 获取上下文表单变量 getContextFormVariables() { const { module: e } = this.formSchemaService.getFormSchema(); if (!e.viewmodels || e.viewmodels.length === 0) return []; const t = this.formSchemaService.getRootViewModelId(), n = this.formSchemaService.getViewModelById(t); if (!n || !n.states || n.states.length === 0) return []; const s = []; return n.states.filter((r) => r.category === "remote").forEach((r) => { s.push({ key: r.code, name: r.name, description: r.name, category: r.category }); }), s; } createTreeNode(e, t, n = "label") { return { id: e.id, name: e.name, bindingPath: e[n], parents: t, type: "field" }; } buildEntityFieldsTreeData(e = null, t) { const n = []; return e == null || e.forEach((s) => { var c; const r = this.createTreeNode(s, t); let i = []; (c = s.type) != null && c.fields && (i = this.buildEntityFieldsTreeData(s.type.fields, [...t, s.label])), n.push({ data: r, children: i, expanded: !0 }); }), n; } buildChildEntityTreeData(e = null, t) { const n = []; return e == null || e.forEach((s) => { var o, d; const r = this.createTreeNode(s, t); r.type = "entity"; const i = this.buildEntityFieldsTreeData((o = s.type) == null ? void 0 : o.fields, [...t, s.label]), c = this.buildChildEntityTreeData((d = s.type) == null ? void 0 : d.entities, [...t, s.label]); c != null && c.length && (i == null || i.push(...c)), n.push({ data: r, children: i || [], // 空值回退 expanded: !0 }); }), n; } getEntitiesTreeData() { const e = this.formSchemaService.getSchemaEntities(); if (!(e != null && e.length)) return []; const t = e[0]; if (!(t != null && t.type)) return []; const n = this.buildEntityFieldsTreeData(t.type.fields, [t.code]), s = this.buildChildEntityTreeData(t.type.entities, [t.code]); return s != null && s.length && (n == null || n.push(...s)), { entityCode: t.code, fields: [{ data: this.createTreeNode(t, [], "code"), children: n || [] }] }; } getEntitiesAndVariables() { return { entities: this.getEntitiesTreeData(), variables: { session: { name: "系统变量", items: this.sessionVariables, visible: !1 }, forms: { name: "表单变量", items: this.getContextFormVariables(), visible: !0 } } }; } onBeforeOpenExpression(e, t, n) { const s = n === "Field" ? e.binding.field : e.id, r = this.getExpressionRule(s, t), i = this.getEntitiesAndVariables(), c = { message: ["validate", "required", "dataPicking"].includes(t) && r ? r.message : "", ...i }; return r.messageType != null && (c.messageType = r.messageType), c; } buildRule(e, t, n, s) { const { expression: r, message: i, messageType: c } = t, o = { id: `${e}_${n}`, type: n, value: r }; return (n === "validate" || n === "dataPicking" || n === "required") && (o.message = i), n === "dataPicking" && (o.messageType = c), n === "validate" && s && (o.elementId = s), o; } getExpressionData() { const { expressions: e } = this.formSchemaService.getFormSchema().module; return e || []; } updateExpression(e, t, n, s) { const r = t === "Field" ? e.binding.field : e.id, i = this.buildRule(r, n, s, e.type === "form-group" ? e.id : ""); let o = this.getExpressionData().find((u) => u.targetType === t && u.target === r); const d = (u) => u.value.trim() === ""; if (o) { const u = o.rules.find((m) => m.id === i.id); if (u) d(i) ? o.rules = o.rules.filter((m) => m.id !== i.id) : (Object.assign(u, i), s === "validate" && e.type === "form-group" && (u.elementId = e.id)); else { if (d(i)) return null; o.rules = o.rules || [], o.rules.push(i); } } else { if (d(i)) return null; o = { target: `${r}`, rules: [i], targetType: t }; } return o; } getExpressionEditorOptions(e, t, n, s) { return n.reduce((r, i) => { var o, d; const c = t === "Field" ? (o = e == null ? void 0 : e.binding) == null ? void 0 : o.field : e.id; return r[i] = { hide: t === "Field" ? !!((d = e == null ? void 0 : e.binding) != null && d.field) : !1, description: "", title: this.expressionNames[i], type: "string", $converter: this.getExpressionConverter(c), refreshPanelAfterChanged: !0, editor: { type: "expression-editor", singleExpand: !1, dialogTitle: `${this.expressionNames[i]}编辑器`, showMessage: i === "validate" || i === "dataPicking" || i === "required", showMessageType: i === "dataPicking", beforeOpen: () => this.onBeforeOpenExpression(e, i, t), onSubmitModal: (u) => { const m = this.updateExpression(e, t, u, i); if (s) { const b = this.buildRule(c, u, i); s(b); } return m; } } }, r; }, {}); } getExpressionInfo(e, t, n) { const s = t === "Field" ? e.binding.field : e.id, r = this.getExpressionRule(s, n), i = { value: r && r.value, targetId: s, targetType: t, expressionType: n }; return r && r.message && (i.message = r.message), i; } getExpressionConfig(e, t, n = ["compute", "dependency", "validate"], s) { return { description: "表达式", title: "表达式", hide: !e.binding, properties: { ...this.getExpressionEditorOptions(e, t, n, s) } }; } getExpressionOptions(e, t, n) { const s = this.getExpressionInfo(e, t, n); return { dialogTitle: `${this.expressionNames[n] || "表达式"}编辑器`, singleExpand: !1, showMessage: n === "required", beforeOpen: () => this.onBeforeOpenExpression(e, n, t), expressionInfo: s }; } } class le { constructor(e, t) { g(this, "componentId"); g(this, "viewModelId"); g(this, "eventsEditorUtils"); g(this, "formSchemaUtils"); g(this, "formMetadataConverter"); g(this, "designViewModelUtils"); g(this, "designViewModelField"); g(this, "controlCreatorUtils"); g(this, "designerHostService"); g(this, "designerContext"); g(this, "modalService", null); /** 表单规则 */ g(this, "formRule", null); g(this, "schemaService", null); g(this, "metadataService", null); g(this, "propertyConfig", { type: "object", categories: {} }); g(this, "expressionProperty"); var n; this.componentId = e, this.designerHostService = t, this.eventsEditorUtils = t.eventsEditorUtils, this.formSchemaUtils = t.formSchemaUtils, this.formMetadataConverter = t.formMetadataConverter, this.viewModelId = ((n = this.formSchemaUtils) == null ? void 0 : n.getViewModelIdByComponentId(e)) || "", this.designViewModelUtils = t.designViewModelUtils, this.controlCreatorUtils = t.controlCreatorUtils, this.metadataService = t.metadataService, this.schemaService = t.schemaService, this.designerContext = t.designerContext, this.modalService = t.modalService, this.expressionProperty = new ce(this.formSchemaUtils); } getFormDesignerInstance() { var e, t; return (t = (e = this.designerContext) == null ? void 0 : e.instances) == null ? void 0 : t.formDesigner.value; } getTableInfo() { var e; return (e = this.schemaService) == null ? void 0 : e.getTableInfoByViewModelId(this.viewModelId); } setDesignViewModelField(e) { var n; const t = e.binding && e.binding.type === "Form" && e.binding.field; if (t) { if (!this.designViewModelField) { const s = this.designViewModelUtils.getDgViewModel(this.viewModelId); this.designViewModelField = s.fields.find((r) => r.id === t); } e.updateOn = (n = this.designViewModelField) == null ? void 0 : n.updateOn; } } getBasicPropConfig(e) { 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: e.type, name: w[e.type] && w[e.type].name }] } } } }; } getAppearanceConfig(e = null, t = {}, n) { const s = { title: "外观", description: "Appearance" }, r = { 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 i in t) r[i] = Object.assign(r[i] || {}, t[i]); return { ...s, properties: { ...r }, setPropertyRelates(i, c) { if (i) { switch (i && i.propertyID) { case "class": case "style": { K.value++; break; } } n && n(i, e, c); } } }; } /** * * @param propertyData * @param propertyTypes * @param propertyName * @param constInfos * @param variableInfos * @param expressionType 指定表达式类型,存在属性和表达式类型不一致的情况 * @returns */ getPropertyEditorParams(e, t = [], n = "visible", s = {}, r = {}, i = "") { const { getVariables: c, getControlName: o, getStateMachines: d } = ae(this.designerHostService), u = this.getRealTargetType(e), m = t && t.length > 0 ? t : ["Const", "Variable", "StateMachine", "Expression"], b = { type: "property-editor", propertyTypes: m }; return m.map((M) => { switch (M) { case "Const": Object.assign(b, { constType: "enum", constEnums: [{ id: !0, name: "是" }, { id: !1, name: "否" }] }, s); break; case "Expression": b.expressionConfig = this.getExpressionOptions(e, u, i || n); break; case "StateMachine": b.stateMachines = d(); break; case "Variable": Object.assign(b, { controlName: o(e), newVariablePrefix: "is", newVariableType: "Boolean", variables: c(this.viewModelId), parentComponentId: this.componentId === "root-component" ? "" : "root-component", onBeforeOpenVariables: (E) => { E.value = c(this.viewModelId); } }, r), this.designerContext.designerMode === "PC_RTC" && (b.newVariablePrefix = "ext_" + b.newVariablePrefix); break; } }), b; } getVisibleProperty(e, t = "") { var r; let n = ["Const", "Variable", "StateMachine", "Expression"]; return t === "gridFieldEditor" ? n = ["Const", "Expression"] : t === "form-group" && !((r = e.binding) != null && r.field) && (n = ["Const", "Variable", "StateMachine"]), { visible: { title: "是否可见", type: "boolean", description: "运行时组件是否可见", editor: this.getPropertyEditorParams(e, n, "visible") } }; } /** * 获取行为 * @param propertyData * @param viewModelId * @returns */ getBehaviorConfig(e, t = "", n = {}, s) { const r = { title: "行为", description: "" }, i = this.getVisibleProperty(e, t); for (const o in n) i[o] = Object.assign(i[o] || {}, n[o]); const c = this; return { ...r, properties: { ...i }, setPropertyRelates(o, d) { if (o) { switch (o.propertyID) { case "disabled": case "readonly": case "visible": c.afterMutilEditorChanged(e, o); break; } s && s(o, d); } } }; } /** * 当多值编辑器变更时 * @param propertyData * @param changeObject */ afterMutilEditorChanged(e, t) { this.addNewVariableToViewModel(t, this.viewModelId), this.updateExpressionValue(t, e), this.clearExpression(t, e); } /** * * @param propertyId * @param componentInstance * @returns */ updateElementByParentContainer(e, t) { const n = t && t.parent && t.parent.schema; if (!n) return; const s = n.contents.findIndex((i) => i.id === e), r = H(n.contents[s]); n.contents.splice(s, 1), n.contents.splice(s, 0, r), W(); } /** * 属性编辑器,在编辑过程中会新增变量,此处需要将新增的变量追加到ViewModel中 * @param changeObject * @param viewModelId * @returns */ addNewVariableToViewModel(e, t) { const n = e.propertyValue; if (!(n && typeof n == "object") || !(n.type === "Variable" && n.isNewVariable)) return; const i = { id: n.field, category: "locale", code: n.fullPath, name: n.fullPath, type: n.newVariableType || "String", isRtcVariable: this.designerContext.designerMode === "PC_RTC" ? !0 : void 0 }; delete n.newVariableType, delete n.isNewVariable, this.formSchemaUtils.getVariableByCode(i.code) || this.formSchemaUtils.getViewModelById("root-viewmodel").states.push(i); } getExpressions() { let e = []; return this.formRule ? (this.formRule.expressions = this.formRule.expressions || [], e = this.formRule.expressions || []) : e = this.formSchemaUtils.getExpressions(), e; } /** * 更新表达式到expressions节点 * @param changeObject */ updateExpressionValue(e, t) { const n = e.propertyValue; if (!((n && n.type) === "Expression" && n.expressionInfo)) return; const { expressionId: i, expressionInfo: c } = n, { targetId: o, targetType: d, expressionType: u, value: m, message: b } = c, M = this.getExpressions(); let E = M.find((V) => V.target === o); E || (E = { target: o, rules: [], targetType: d }, M.push(E)); const P = E.rules.find((V) => V.type === u); if (P) P.value = m, P.message = b, (u === "minDate" || u === "maxDate" || u === "defaultTime") && (P.elementId = t.id); else { const V = { id: i, type: u, value: m, message: b, elementId: t.id }; E.rules.push(V); } delete n.expressionInfo; } /** * 属性类型切换为非表达式后,清除原表达式 * @param changeObject * @param propertyData * @returns */ clearExpression(e, t) { const n = e.propertyValue; if (n && n.type === "Expression") return; const r = e.propertyID, i = this.getExpressions(), c = t.binding ? t.binding.field : t.id, o = i.find((d) => d.target === c); !o || !o.rules || (o.rules = o.rules.filter((d) => d.type !== r)); } getExpressionOptions(e, t, n) { return this.expressionProperty.getExpressionOptions(e, t, n); } getRealTargetType(e) { return ["response-toolbar-item", "tab-toolbar-item", "section-toolbar-item", "drawer-toolbar-item"].indexOf(e.type) > -1 ? "Button" : e.binding && e.binding.field ? "Field" : "Container"; } createBaseEventProperty(e) { const t = {}; return t[this.viewModelId] = { type: "events-editor", editor: { initialData: e, viewSourceHandle: (n) => { var s; ((s = n.controller) == null ? void 0 : s.label.indexOf(this.formSchemaUtils.getModule().code)) > -1 && this.eventsEditorUtils.jumpToMethod(n); } } }, t; } } class de extends le { constructor(e, t) { super(e, t); } getPropertyConfig(e) { return this.propertyConfig.categories.basic = this.getBasicPropConfig(e), this.propertyConfig.categories.appearance = this.getAppearanceConfig(e), this.propertyConfig.categories.behavior = this.getBehaviorConfig(e), this.propertyConfig; } } function ue(a, e) { const t = a.schema, n = new X(); function s(l) { var f; const { componentType: p, sourceType: h, sourceElement: y } = l; return !!(h === "control" && p === w["query-solution"].type || h === "move" && p === w.section.type && ((f = y == null ? void 0 : y.className) != null && f.includes("f-section-scheme"))); } function r(l, p) { var f, x; const y = (e == null ? void 0 : e.schemaService).getTreeGridUdtFields(l); if (y) { const C = y.find((I) => I.key === p), v = C && C.field; if ((x = (f = v == null ? void 0 : v.type) == null ? void 0 : f.name) != null && x.includes("PathHierarchyInfo")) return !0; } } function i() { const l = e == null ? void 0 : e.formSchemaUtils, p = l.getComponentById("root-component"); return l.selectNode(p, (y) => { if (y.type === "component-ref") { const f = l.getComponentById(y.component), x = l.getViewModelById(f == null ? void 0 : f.viewModel); if ((f == null ? void 0 : f.componentType) === "data-grid" && (x == null ? void 0 : x.bindTo) === "/") { const C = l.selectNode(f, (v) => v.type === "tree-grid"); return C ? r(f == null ? void 0 : f.viewModel, C.udtField) : !0; } } }); } function c() { const l = e == null ? void 0 : e.formSchemaUtils; return l.selectNode(t, (h) => { if (h.type === "component-ref") { const y = l.getComponentById(h.component); if ((y == null ? void 0 : y.componentType) === "data-grid" && l.selectNode(y, (x) => x.contents && x.contents.find((C) => C.type === w["filter-bar"].type))) return !0; } }); } function o() { const l = e == null ? void 0 : e.formSchemaUtils, p = l.getComponentById("root-component"); return !!l.selectNode(p, (y) => y.type === w["query-solution"].type); } function d(l) { var f; const p = (f = t.appearance) == null ? void 0 : f.class, { sourceType: h } = l; return p && p.split(" ").includes("f-page") ? h === "control" ? !o() && !c() && i() : h === "move" : !1; } function u(l) { const { componentType: p, sourceType: h } = l; return h === "control" && p === w.drawer.type; } function m(l) { var x, C, v, I; const p = (x = t.appearance) == null ? void 0 : x.class, { sourceType: h } = l; return !(p && p.split(" ").includes("f-page")) || ((I = (v = (C = a == null ? void 0 : a.parent) == null ? void 0 : C.schema) == null ? void 0 : v.appearance) == null ? void 0 : I.class) === "f-page-content-main" ? !1 : h === "control" ? !(t.contents && t.contents.find(($) => $.type === w.drawer.type)) : h === "move"; } function b(l) { if (s(l)) return d(l); if (u(l)) return m(l); if (!Y().basalDragulaRuleForContainer(l, e)) return !1; const { canAccept: h } = n.getTemplateRule(a, e); return h; } function M() { return t.componentType ? "display:inherit;flex-direction:inherit;margin-bottom:10px" : ""; } function E() { if (a.schema.appearance && a.schema.appearance.class && a.schema.appearance.class.includes("fm-page-footer-container")) return !1; const { canMove: l } = n.getTemplateRule(a, e); return l; } function P() { if (a.schema.appearance && a.schema.appearance.class && a.schema.appearance.class.includes("fm-page-footer-container")) return !1; const { canDelete: l } = n.getTemplateRule(a, e); return l; } function V() { const { canMove: l, canDelete: p } = n.getTemplateRule(a, e); return !l && !p; } function A(l) { const p = new de(l, e), { schema: h } = a; return p.getPropertyConfig(h); } return { canAccepts: b, getStyles: M, checkCanMoveComponent: E, checkCanDeleteComponent: P, hideNestedPaddingInDesginerView: V, getPropsConfig: A }; } const pe = /* @__PURE__ */ F({ name: "FContentContainerDesign", props: R, emits: [], setup(a, e) { const t = G(), n = S("designer-host-service"), s = S("design-item-context"), r = ue(s, n), i = Z(t, s, r), c = j(() => J({ "drag-container": !0 }, a == null ? void 0 : a.customClass)); return L(() => { t.value.componentInstance = i; }), e.expose(i.value), () => U("div", { ref: t, class: c.value, style: a.customStyle, "data-dragref": `${s.schema.id}-container` }, [e.slots.default && e.slots.default()]); } }), Ee = { install(a) { a.component(T.name, T); }, register(a, e, t, n, s) { a["content-container"] = T, e["content-container"] = k(s); }, registerDesigner(a, e, t, n) { a["content-container"] = pe, e["content-container"] = k(n); } }; export { T as ContentContainer, pe as ContentContainerDesign, R as contentContainerProps, Ee as default, Ce as propsResolver, k as propsResolverGenerator };