UNPKG

@farris/ui-vue

Version:

Farris Vue, a Farris Design based Vue3 component library.

884 lines (883 loc) 27.6 kB
var S = Object.defineProperty; var P = (d, e, t) => e in d ? S(d, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : d[e] = t; var f = (d, e, t) => P(d, typeof e != "symbol" ? e + "" : e, t); import { defineComponent as M, ref as h, computed as x, createVNode as p, inject as V, onMounted as N } from "vue"; import { getCustomClass as R } from "../common/index.esm.js"; import { resolveAppearance as T, createPropsResolver as F } from "../dynamic-resolver/index.esm.js"; import { DgControl as E, canvasChanged as k, refreshCanvas as U, UseTemplateDragAndDropRules as B, useDragulaCommonRule as $, useDesignerComponent as A } from "../designer-canvas/index.esm.js"; import { cloneDeep as O } from "lodash-es"; function z(d, e) { return { size: e.width || e.height || "" }; } const q = /* @__PURE__ */ new Map([ ["appearance", T], ["size", z] ]); function D(d, e, t) { return e; } const j = "https://json-schema.org/draft/2020-12/schema", L = "https://farris-design.gitee.io/list-nav.schema.json", _ = "list-nav", H = "A Farris Container Component", G = "object", J = { id: { description: "The unique identifier for a list-nav", type: "string" }, type: { description: "The type string of list-nav component", type: "string", default: "list-nav" }, 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 }, position: { description: "", type: "string", default: "left" } }, K = [ "id", "type", "contents" ], Q = { $schema: j, $id: L, title: _, description: H, type: G, properties: J, required: K }, w = { /** 自定义样式 */ customClass: { type: String, default: "" }, customStyle: { type: String, default: "" }, /** 位置 */ position: { Type: String, default: "left" }, /** listNav名称 */ title: { Type: String, default: "" }, /** 宽度或者高度 */ size: { Type: Number || String, default: 218 }, /** 是否启用收折 */ collapsible: { Type: Boolean, default: !0 }, /** 初始收折状态 */ folded: { Type: Boolean, default: !1 }, /** 控件禁用状态 */ disabled: { Type: Boolean, default: !1 }, /** 是否启用拖拽 TODO */ draggable: { Type: Boolean, default: !1 } }, I = F(w, Q, q, D), C = /* @__PURE__ */ M({ name: "FListNav", props: w, emits: ["collapse"], setup(d, e) { const t = h(d.position), s = h(d.title), i = h(d.folded), r = h(!1); function n(a) { a && a.stopPropagation(), !d.disabled && (r.value = !0, i.value = !i.value, e.emit("collapse", i.value)); } const l = x(() => { const a = {}, c = ["top", "bottom"].indexOf(t.value) > -1 ? "height" : "width"; return a[c] = i.value ? "0px" : d.size + "px", a; }), o = x(() => { const a = { "f-list-nav": !0, "f-list-nav-top": t.value === "top", "f-list-nav-left": t.value === "left", "f-list-nav-right": t.value === "right", "f-list-nav-bottom": t.value === "bottom" }; return R(a, d.customClass); }); return () => p("div", { class: o.value, style: d.customStyle }, [p("div", { class: "f-list-nav-in", style: l.value }, [p("div", { class: "f-list-nav-main" }, [e.slots.navHeader && p("div", { class: "f-list-nav-header" }, [e.slots.navHeader()]), !e.slots.navHeader && s.value && p("div", { class: "f-list-nav-header" }, [p("div", { class: "f-list-nav-title" }, [s.value])]), e.slots.default && p("div", { class: "f-list-nav-content" }, [e.slots.default()]), e.slots.navContent && p("div", { class: "f-list-nav-content" }, [e.slots.navContent()]), e.slots.navFooter && p("div", { class: "f-list-nav-footer" }, [e.slots.navFooter()])]), d.collapsible && p("div", { class: ["f-list-nav-toggle-sidebar", { disabled: d.disabled, active: i.value, "splitter-pane-collapse-animate": r.value }], onClick: (a) => n(a) }, [p("span", { class: "triangle" }, null)])])]); } }), W = h(0); function X(d) { const { formSchemaUtils: e, formStateMachineUtils: t } = d; function s(o, a = "") { return { path: a + o.code, field: o.id, fullPath: o.code }; } function i(o, a = "") { const c = e.getViewModelById(o); return c ? c.states.map((u) => s(u, a)) : []; } function r(o) { const a = e.getRootViewModelId(), c = i(o); if (o === a) return c; const u = i(a, "root-component."); return [...c, ...u]; } function n(o) { return o.binding && o.binding.path || o.id || ""; } function l() { return t && t.getRenderStates() || []; } return { getVariables: r, getControlName: n, getStateMachines: l }; } class Y { constructor(e) { 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", (e, t) => ({ convertFrom: (s, i, r, n) => { const l = r.getExpressionRuleValue(e, t || i); return l && l.value || ""; }, convertTo: (s, i, r, n, l) => { var o; if (i === "dataPicking" && (r != null && r.target)) { const a = `${r.target}_dataPicking`; ((o = r.rules) == null ? void 0 : o.some( (u) => u.id === a && u.value )) ? s.dictPickingExpressionId = a : delete s.dictPickingExpressionId; } n.updateExpression(r); } })); this.formSchemaService = e; } getExpressionRule(e, t) { const s = this.getExpressionData(); if (!s) return ""; const i = s.find((n) => n.target === e); if (!i) return ""; const r = i.rules.find((n) => n.type === t); return r || ""; } // 获取上下文表单变量 getContextFormVariables() { const { module: e } = this.formSchemaService.getFormSchema(); if (!e.viewmodels || e.viewmodels.length === 0) return []; const t = this.formSchemaService.getRootViewModelId(), s = this.formSchemaService.getViewModelById(t); if (!s || !s.states || s.states.length === 0) return []; const i = []; return s.states.filter((r) => r.category === "remote").forEach((r) => { i.push({ key: r.code, name: r.name, description: r.name, category: r.category }); }), i; } createTreeNode(e, t, s = "label") { return { id: e.id, name: e.name, bindingPath: e[s], parents: t, type: "field" }; } buildEntityFieldsTreeData(e = null, t) { const s = []; return e == null || e.forEach((i) => { var l; const r = this.createTreeNode(i, t); let n = []; (l = i.type) != null && l.fields && (n = this.buildEntityFieldsTreeData(i.type.fields, [...t, i.label])), s.push({ data: r, children: n, expanded: !0 }); }), s; } buildChildEntityTreeData(e = null, t) { const s = []; return e == null || e.forEach((i) => { var o, a; const r = this.createTreeNode(i, t); r.type = "entity"; const n = this.buildEntityFieldsTreeData((o = i.type) == null ? void 0 : o.fields, [...t, i.label]), l = this.buildChildEntityTreeData((a = i.type) == null ? void 0 : a.entities, [...t, i.label]); l != null && l.length && (n == null || n.push(...l)), s.push({ data: r, children: n || [], // 空值回退 expanded: !0 }); }), s; } getEntitiesTreeData() { const e = this.formSchemaService.getSchemaEntities(); if (!(e != null && e.length)) return []; const t = e[0]; if (!(t != null && t.type)) return []; const s = this.buildEntityFieldsTreeData(t.type.fields, [t.code]), i = this.buildChildEntityTreeData(t.type.entities, [t.code]); return i != null && i.length && (s == null || s.push(...i)), { entityCode: t.code, fields: [{ data: this.createTreeNode(t, [], "code"), children: s || [] }] }; } getEntitiesAndVariables() { return { entities: this.getEntitiesTreeData(), variables: { session: { name: "系统变量", items: this.sessionVariables, visible: !1 }, forms: { name: "表单变量", items: this.getContextFormVariables(), visible: !0 } } }; } onBeforeOpenExpression(e, t, s) { const i = s === "Field" ? e.binding.field : e.id, r = this.getExpressionRule(i, t), n = this.getEntitiesAndVariables(), l = { message: ["validate", "required", "dataPicking"].includes(t) && r ? r.message : "", ...n }; return r.messageType != null && (l.messageType = r.messageType), l; } buildRule(e, t, s, i) { const { expression: r, message: n, messageType: l } = t, o = { id: `${e}_${s}`, type: s, value: r }; return (s === "validate" || s === "dataPicking" || s === "required") && (o.message = n), s === "dataPicking" && (o.messageType = l), s === "validate" && i && (o.elementId = i), o; } getExpressionData() { const { expressions: e } = this.formSchemaService.getFormSchema().module; return e || []; } updateExpression(e, t, s, i) { const r = t === "Field" ? e.binding.field : e.id, n = this.buildRule(r, s, i, e.type === "form-group" ? e.id : ""); let o = this.getExpressionData().find((c) => c.targetType === t && c.target === r); const a = (c) => c.value.trim() === ""; if (o) { const c = o.rules.find((u) => u.id === n.id); if (c) a(n) ? o.rules = o.rules.filter((u) => u.id !== n.id) : (Object.assign(c, n), i === "validate" && e.type === "form-group" && (c.elementId = e.id)); else { if (a(n)) return null; o.rules = o.rules || [], o.rules.push(n); } } else { if (a(n)) return null; o = { target: `${r}`, rules: [n], targetType: t }; } return o; } getExpressionEditorOptions(e, t, s, i) { return s.reduce((r, n) => { var o, a; const l = t === "Field" ? (o = e == null ? void 0 : e.binding) == null ? void 0 : o.field : e.id; return r[n] = { hide: t === "Field" ? !!((a = e == null ? void 0 : e.binding) != null && a.field) : !1, description: "", title: this.expressionNames[n], type: "string", $converter: this.getExpressionConverter(l), refreshPanelAfterChanged: !0, editor: { type: "expression-editor", singleExpand: !1, dialogTitle: `${this.expressionNames[n]}编辑器`, showMessage: n === "validate" || n === "dataPicking" || n === "required", showMessageType: n === "dataPicking", beforeOpen: () => this.onBeforeOpenExpression(e, n, t), onSubmitModal: (c) => { const u = this.updateExpression(e, t, c, n); if (i) { const g = this.buildRule(l, c, n); i(g); } return u; } } }, r; }, {}); } getExpressionInfo(e, t, s) { const i = t === "Field" ? e.binding.field : e.id, r = this.getExpressionRule(i, s), n = { value: r && r.value, targetId: i, targetType: t, expressionType: s }; return r && r.message && (n.message = r.message), n; } getExpressionConfig(e, t, s = ["compute", "dependency", "validate"], i) { return { description: "表达式", title: "表达式", hide: !e.binding, properties: { ...this.getExpressionEditorOptions(e, t, s, i) } }; } getExpressionOptions(e, t, s) { const i = this.getExpressionInfo(e, t, s); return { dialogTitle: `${this.expressionNames[s] || "表达式"}编辑器`, singleExpand: !1, showMessage: s === "required", beforeOpen: () => this.onBeforeOpenExpression(e, s, t), expressionInfo: i }; } } class Z { constructor(e, t) { 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 s; this.componentId = e, this.designerHostService = t, this.eventsEditorUtils = t.eventsEditorUtils, this.formSchemaUtils = t.formSchemaUtils, this.formMetadataConverter = t.formMetadataConverter, this.viewModelId = ((s = this.formSchemaUtils) == null ? void 0 : s.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 Y(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 s; const t = e.binding && e.binding.type === "Form" && e.binding.field; if (t) { if (!this.designViewModelField) { const i = this.designViewModelUtils.getDgViewModel(this.viewModelId); this.designViewModelField = i.fields.find((r) => r.id === t); } e.updateOn = (s = this.designViewModelField) == null ? void 0 : s.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: E[e.type] && E[e.type].name }] } } } }; } getAppearanceConfig(e = null, t = {}, s) { const i = { 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 n in t) r[n] = Object.assign(r[n] || {}, t[n]); return { ...i, properties: { ...r }, setPropertyRelates(n, l) { if (n) { switch (n && n.propertyID) { case "class": case "style": { k.value++; break; } } s && s(n, e, l); } } }; } /** * * @param propertyData * @param propertyTypes * @param propertyName * @param constInfos * @param variableInfos * @param expressionType 指定表达式类型,存在属性和表达式类型不一致的情况 * @returns */ getPropertyEditorParams(e, t = [], s = "visible", i = {}, r = {}, n = "") { const { getVariables: l, getControlName: o, getStateMachines: a } = X(this.designerHostService), c = this.getRealTargetType(e), u = t && t.length > 0 ? t : ["Const", "Variable", "StateMachine", "Expression"], g = { type: "property-editor", propertyTypes: u }; return u.map((m) => { switch (m) { case "Const": Object.assign(g, { constType: "enum", constEnums: [{ id: !0, name: "是" }, { id: !1, name: "否" }] }, i); break; case "Expression": g.expressionConfig = this.getExpressionOptions(e, c, n || s); break; case "StateMachine": g.stateMachines = a(); break; case "Variable": Object.assign(g, { controlName: o(e), newVariablePrefix: "is", newVariableType: "Boolean", variables: l(this.viewModelId), parentComponentId: this.componentId === "root-component" ? "" : "root-component", onBeforeOpenVariables: (v) => { v.value = l(this.viewModelId); } }, r), this.designerContext.designerMode === "PC_RTC" && (g.newVariablePrefix = "ext_" + g.newVariablePrefix); break; } }), g; } getVisibleProperty(e, t = "") { var r; let s = ["Const", "Variable", "StateMachine", "Expression"]; return t === "gridFieldEditor" ? s = ["Const", "Expression"] : t === "form-group" && !((r = e.binding) != null && r.field) && (s = ["Const", "Variable", "StateMachine"]), { visible: { title: "是否可见", type: "boolean", description: "运行时组件是否可见", editor: this.getPropertyEditorParams(e, s, "visible") } }; } /** * 获取行为 * @param propertyData * @param viewModelId * @returns */ getBehaviorConfig(e, t = "", s = {}, i) { const r = { title: "行为", description: "" }, n = this.getVisibleProperty(e, t); for (const o in s) n[o] = Object.assign(n[o] || {}, s[o]); const l = this; return { ...r, properties: { ...n }, setPropertyRelates(o, a) { if (o) { switch (o.propertyID) { case "disabled": case "readonly": case "visible": l.afterMutilEditorChanged(e, o); break; } i && i(o, a); } } }; } /** * 当多值编辑器变更时 * @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 s = t && t.parent && t.parent.schema; if (!s) return; const i = s.contents.findIndex((n) => n.id === e), r = O(s.contents[i]); s.contents.splice(i, 1), s.contents.splice(i, 0, r), U(); } /** * 属性编辑器,在编辑过程中会新增变量,此处需要将新增的变量追加到ViewModel中 * @param changeObject * @param viewModelId * @returns */ addNewVariableToViewModel(e, t) { const s = e.propertyValue; if (!(s && typeof s == "object") || !(s.type === "Variable" && s.isNewVariable)) return; const n = { id: s.field, category: "locale", code: s.fullPath, name: s.fullPath, type: s.newVariableType || "String", isRtcVariable: this.designerContext.designerMode === "PC_RTC" ? !0 : void 0 }; delete s.newVariableType, delete s.isNewVariable, this.formSchemaUtils.getVariableByCode(n.code) || this.formSchemaUtils.getViewModelById("root-viewmodel").states.push(n); } 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 s = e.propertyValue; if (!((s && s.type) === "Expression" && s.expressionInfo)) return; const { expressionId: n, expressionInfo: l } = s, { targetId: o, targetType: a, expressionType: c, value: u, message: g } = l, m = this.getExpressions(); let v = m.find((y) => y.target === o); v || (v = { target: o, rules: [], targetType: a }, m.push(v)); const b = v.rules.find((y) => y.type === c); if (b) b.value = u, b.message = g, (c === "minDate" || c === "maxDate" || c === "defaultTime") && (b.elementId = t.id); else { const y = { id: n, type: c, value: u, message: g, elementId: t.id }; v.rules.push(y); } delete s.expressionInfo; } /** * 属性类型切换为非表达式后,清除原表达式 * @param changeObject * @param propertyData * @returns */ clearExpression(e, t) { const s = e.propertyValue; if (s && s.type === "Expression") return; const r = e.propertyID, n = this.getExpressions(), l = t.binding ? t.binding.field : t.id, o = n.find((a) => a.target === l); !o || !o.rules || (o.rules = o.rules.filter((a) => a.type !== r)); } getExpressionOptions(e, t, s) { return this.expressionProperty.getExpressionOptions(e, t, s); } 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: (s) => { var i; ((i = s.controller) == null ? void 0 : i.label.indexOf(this.formSchemaUtils.getModule().code)) > -1 && this.eventsEditorUtils.jumpToMethod(s); } } }, t; } } class ee extends Z { getPropertyConfig(e) { return this.propertyConfig.categories.basic = this.getBasicPropConfig(e), this.propertyConfig.categories.appearance = this.getAppearanceConfig(e), this.propertyConfig; } getAppearanceConfig(e) { return super.getAppearanceConfig(e, { width: { title: "宽度", type: "number", editor: { nullable: !0, min: 0, precision: 0, needValid: !0 }, $converter: "/converter/size.converter", parentPropertyID: "size" }, height: { title: "高度", type: "number", editor: { nullable: !0, min: 0, precision: 0, needValid: !0 }, $converter: "/converter/size.converter", parentPropertyID: "size", visible: !1 } }, (s, i, r) => { switch (s.propertyID) { case "width": case "height": W.value++; break; } }); } } function te(d, e) { const t = new B(), { canAccept: s } = t.getTemplateRule(d, e); function i(c) { var g, m, v; return !(!$().basalDragulaRuleForContainer(c, e) || !s || ((g = d.schema.contents) == null ? void 0 : g.length) === 1 && ((v = (m = d.schema) == null ? void 0 : m.contents[0]) == null ? void 0 : v.type) === E["external-container"].type); } function r() { return "display: flex;flex-direction:column;height:100%"; } function n() { return !1; } function l() { return !1; } function o() { return !0; } function a(c) { const u = new ee(c, e), { schema: g } = d; return u.getPropertyConfig(g); } return { canAccepts: i, getStyles: r, checkCanMoveComponent: n, checkCanDeleteComponent: l, hideNestedPaddingInDesginerView: o, getPropsConfig: a }; } const se = /* @__PURE__ */ M({ name: "FListNavDesign", props: w, emits: [], setup(d, e) { const t = h(), s = V("designer-host-service"), i = V("design-item-context"), r = te(i, s), n = A(t, i, r), l = h(d.position), o = h(d.title), a = h(!1), c = h(!1), u = x(() => { const v = {}, b = ["top", "bottom"].indexOf(l.value) > -1 ? "height" : "width"; return v[b] = a.value ? "0px" : d.size + "px", v; }); N(() => { t.value.componentInstance = n; }), e.expose(n.value); function g(v) { v && v.stopPropagation(), !d.disabled && (c.value = !0, a.value = !a.value); } const m = x(() => ({ "f-list-nav-main": !0, "d-none": a.value })); return () => p("div", { class: `f-list-nav f-list-nav-${l.value}` }, [p("div", { class: "f-list-nav-in", style: u.value }, [p("div", { class: m.value }, [e.slots.navHeader && p("div", { class: "f-list-nav-header" }, [e.slots.navHeader()]), !e.slots.navHeader && o.value && p("div", { class: "f-list-nav-header" }, [p("div", { class: "f-list-nav-title" }, [o.value])]), e.slots.default && p("div", { class: "f-list-nav-content drag-container", ref: t, "data-dragref": `${i.schema.id}-container` }, [e.slots.default()]), e.slots.navContent && p("div", { class: "f-list-nav-content" }, [e.slots.navContent()]), e.slots.navFooter && p("div", { class: "f-list-nav-footer" }, [e.slots.navFooter()])]), d.collapsible && p("div", { class: ["f-list-nav-toggle-sidebar", { disabled: d.disabled, active: a.value, "splitter-pane-collapse-animate": c.value }], onClick: (v) => g(v) }, [p("span", { class: "triangle" }, null)])])]); } }), de = { install(d) { d.component(C.name, C); }, register(d, e, t, s) { d["list-nav"] = C, e["list-nav"] = I; }, registerDesigner(d, e, t) { d["list-nav"] = se, e["list-nav"] = I; } }; export { C as FListNav, de as default, w as listNavProps, I as propsResolver };