@farris/ui-vue
Version:
Farris Vue, a Farris Design based Vue3 component library.
750 lines (749 loc) • 23.1 kB
JavaScript
var T = Object.defineProperty;
var R = (c, e, t) => e in c ? T(c, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : c[e] = t;
var p = (c, e, t) => R(c, typeof e != "symbol" ? e + "" : e, t);
import { defineComponent as M, ref as F, inject as V, onMounted as k, computed as N, createVNode as U } from "vue";
import { createPropsResolver as P, getPropsResolverGenerator as S } from "../dynamic-resolver/index.esm.js";
import { withInstall as B } from "../common/index.esm.js";
import { DgControl as I, canvasChanged as O, refreshCanvas as $, useDesignerComponent as A } from "../designer-canvas/index.esm.js";
import { cloneDeep as q } from "lodash-es";
const H = "https://json-schema.org/draft/2020-12/schema", _ = "https://farris-design.gitee.io/html-template.schema.json", j = "html-template", L = "A Farris Component", G = "object", z = {
id: {
description: "The unique identifier for a html-template",
type: "string"
},
type: {
description: "The type string of html-template",
type: "string",
default: "html-template"
},
html: {
description: "",
type: "string",
default: ""
},
renderFunction: {
description: "",
type: "function",
default: null
}
}, D = [
"id",
"type"
], J = [], b = {
$schema: H,
$id: _,
title: j,
description: L,
type: G,
properties: z,
required: D,
ignore: J
}, E = /* @__PURE__ */ new Map([]);
function y(c, e, t) {
return e;
}
const C = {
/** 渲染函数 */
renderFunction: { type: Function }
}, ae = P(C, b, E, y), w = {
/** html模板 */
html: { type: String, default: "" }
}, de = P(w, b, E, y), K = S(
C,
b,
E,
y
), Q = S(
w,
b,
E,
y
), v = /* @__PURE__ */ M({
name: "FHtmlTemplate",
props: C,
emits: [],
setup(c) {
return () => {
var e;
return (e = c.renderFunction) == null ? void 0 : e.call(c);
};
}
});
function W(c) {
const { formSchemaUtils: e, formStateMachineUtils: t } = c;
function i(o, a = "") {
return {
path: a + o.code,
field: o.id,
fullPath: o.code
};
}
function s(o, a = "") {
const d = e.getViewModelById(o);
return d ? d.states.map((u) => i(u, a)) : [];
}
function r(o) {
const a = e.getRootViewModelId(), d = s(o);
if (o === a)
return d;
const u = s(a, "root-component.");
return [...d, ...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 X {
constructor(e) {
p(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'"
}
]);
p(this, "expressionNames", {
compute: "计算表达式",
dependency: "依赖表达式",
validate: "验证表达式",
dataPicking: "帮助前表达式",
visible: "可见表达式",
readonly: "只读表达式",
required: "必填表达式"
});
p(this, "getExpressionConverter", (e, t) => ({
convertFrom: (i, s, r, n) => {
const l = r.getExpressionRuleValue(e, t || s);
return l && l.value || "";
},
convertTo: (i, s, r, n, l) => {
var o;
if (s === "dataPicking" && (r != null && r.target)) {
const a = `${r.target}_dataPicking`;
((o = r.rules) == null ? void 0 : o.some(
(u) => u.id === a && u.value
)) ? i.dictPickingExpressionId = a : delete i.dictPickingExpressionId;
}
n.updateExpression(r);
}
}));
this.formSchemaService = e;
}
getExpressionRule(e, t) {
const i = this.getExpressionData();
if (!i)
return "";
const s = i.find((n) => n.target === e);
if (!s)
return "";
const r = s.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(), i = this.formSchemaService.getViewModelById(t);
if (!i || !i.states || i.states.length === 0)
return [];
const s = [];
return i.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, i = "label") {
return {
id: e.id,
name: e.name,
bindingPath: e[i],
parents: t,
type: "field"
};
}
buildEntityFieldsTreeData(e = null, t) {
const i = [];
return e == null || e.forEach((s) => {
var l;
const r = this.createTreeNode(s, t);
let n = [];
(l = s.type) != null && l.fields && (n = this.buildEntityFieldsTreeData(s.type.fields, [...t, s.label])), i.push({
data: r,
children: n,
expanded: !0
});
}), i;
}
buildChildEntityTreeData(e = null, t) {
const i = [];
return e == null || e.forEach((s) => {
var o, a;
const r = this.createTreeNode(s, t);
r.type = "entity";
const n = this.buildEntityFieldsTreeData((o = s.type) == null ? void 0 : o.fields, [...t, s.label]), l = this.buildChildEntityTreeData((a = s.type) == null ? void 0 : a.entities, [...t, s.label]);
l != null && l.length && (n == null || n.push(...l)), i.push({
data: r,
children: n || [],
// 空值回退
expanded: !0
});
}), i;
}
getEntitiesTreeData() {
const e = this.formSchemaService.getSchemaEntities();
if (!(e != null && e.length))
return [];
const t = e[0];
if (!(t != null && t.type))
return [];
const i = this.buildEntityFieldsTreeData(t.type.fields, [t.code]), s = this.buildChildEntityTreeData(t.type.entities, [t.code]);
return s != null && s.length && (i == null || i.push(...s)), {
entityCode: t.code,
fields: [{
data: this.createTreeNode(t, [], "code"),
children: i || []
}]
};
}
getEntitiesAndVariables() {
return {
entities: this.getEntitiesTreeData(),
variables: {
session: {
name: "系统变量",
items: this.sessionVariables,
visible: !1
},
forms: {
name: "表单变量",
items: this.getContextFormVariables(),
visible: !0
}
}
};
}
onBeforeOpenExpression(e, t, i) {
const s = i === "Field" ? e.binding.field : e.id, r = this.getExpressionRule(s, 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, i, s) {
const { expression: r, message: n, messageType: l } = t, o = {
id: `${e}_${i}`,
type: i,
value: r
};
return (i === "validate" || i === "dataPicking" || i === "required") && (o.message = n), i === "dataPicking" && (o.messageType = l), i === "validate" && s && (o.elementId = s), o;
}
getExpressionData() {
const { expressions: e } = this.formSchemaService.getFormSchema().module;
return e || [];
}
updateExpression(e, t, i, s) {
const r = t === "Field" ? e.binding.field : e.id, n = this.buildRule(r, i, s, e.type === "form-group" ? e.id : "");
let o = this.getExpressionData().find((d) => d.targetType === t && d.target === r);
const a = (d) => d.value.trim() === "";
if (o) {
const d = o.rules.find((u) => u.id === n.id);
if (d)
a(n) ? o.rules = o.rules.filter((u) => u.id !== n.id) : (Object.assign(d, n), s === "validate" && e.type === "form-group" && (d.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, i, s) {
return i.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: (d) => {
const u = this.updateExpression(e, t, d, n);
if (s) {
const m = this.buildRule(l, d, n);
s(m);
}
return u;
}
}
}, r;
}, {});
}
getExpressionInfo(e, t, i) {
const s = t === "Field" ? e.binding.field : e.id, r = this.getExpressionRule(s, i), n = {
value: r && r.value,
targetId: s,
targetType: t,
expressionType: i
};
return r && r.message && (n.message = r.message), n;
}
getExpressionConfig(e, t, i = ["compute", "dependency", "validate"], s) {
return {
description: "表达式",
title: "表达式",
hide: !e.binding,
properties: {
...this.getExpressionEditorOptions(e, t, i, s)
}
};
}
getExpressionOptions(e, t, i) {
const s = this.getExpressionInfo(e, t, i);
return {
dialogTitle: `${this.expressionNames[i] || "表达式"}编辑器`,
singleExpand: !1,
showMessage: i === "required",
beforeOpen: () => this.onBeforeOpenExpression(e, i, t),
expressionInfo: s
};
}
}
class Y {
constructor(e, t) {
p(this, "componentId");
p(this, "viewModelId");
p(this, "eventsEditorUtils");
p(this, "formSchemaUtils");
p(this, "formMetadataConverter");
p(this, "designViewModelUtils");
p(this, "designViewModelField");
p(this, "controlCreatorUtils");
p(this, "designerHostService");
p(this, "designerContext");
p(this, "modalService", null);
/** 表单规则 */
p(this, "formRule", null);
p(this, "schemaService", null);
p(this, "metadataService", null);
p(this, "propertyConfig", {
type: "object",
categories: {}
});
p(this, "expressionProperty");
var i;
this.componentId = e, this.designerHostService = t, this.eventsEditorUtils = t.eventsEditorUtils, this.formSchemaUtils = t.formSchemaUtils, this.formMetadataConverter = t.formMetadataConverter, this.viewModelId = ((i = this.formSchemaUtils) == null ? void 0 : i.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 X(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 i;
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 = (i = this.designViewModelField) == null ? void 0 : i.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: I[e.type] && I[e.type].name }]
}
}
}
};
}
getAppearanceConfig(e = null, t = {}, i) {
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 n in t)
r[n] = Object.assign(r[n] || {}, t[n]);
return {
...s,
properties: { ...r },
setPropertyRelates(n, l) {
if (n) {
switch (n && n.propertyID) {
case "class":
case "style": {
O.value++;
break;
}
}
i && i(n, e, l);
}
}
};
}
/**
*
* @param propertyData
* @param propertyTypes
* @param propertyName
* @param constInfos
* @param variableInfos
* @param expressionType 指定表达式类型,存在属性和表达式类型不一致的情况
* @returns
*/
getPropertyEditorParams(e, t = [], i = "visible", s = {}, r = {}, n = "") {
const { getVariables: l, getControlName: o, getStateMachines: a } = W(this.designerHostService), d = this.getRealTargetType(e), u = t && t.length > 0 ? t : ["Const", "Variable", "StateMachine", "Expression"], m = {
type: "property-editor",
propertyTypes: u
};
return u.map((f) => {
switch (f) {
case "Const":
Object.assign(m, {
constType: "enum",
constEnums: [{ id: !0, name: "是" }, { id: !1, name: "否" }]
}, s);
break;
case "Expression":
m.expressionConfig = this.getExpressionOptions(e, d, n || i);
break;
case "StateMachine":
m.stateMachines = a();
break;
case "Variable":
Object.assign(m, {
controlName: o(e),
newVariablePrefix: "is",
newVariableType: "Boolean",
variables: l(this.viewModelId),
parentComponentId: this.componentId === "root-component" ? "" : "root-component",
onBeforeOpenVariables: (g) => {
g.value = l(this.viewModelId);
}
}, r), this.designerContext.designerMode === "PC_RTC" && (m.newVariablePrefix = "ext_" + m.newVariablePrefix);
break;
}
}), m;
}
getVisibleProperty(e, t = "") {
var r;
let i = ["Const", "Variable", "StateMachine", "Expression"];
return t === "gridFieldEditor" ? i = ["Const", "Expression"] : t === "form-group" && !((r = e.binding) != null && r.field) && (i = ["Const", "Variable", "StateMachine"]), {
visible: {
title: "是否可见",
type: "boolean",
description: "运行时组件是否可见",
editor: this.getPropertyEditorParams(e, i, "visible")
}
};
}
/**
* 获取行为
* @param propertyData
* @param viewModelId
* @returns
*/
getBehaviorConfig(e, t = "", i = {}, s) {
const r = {
title: "行为",
description: ""
}, n = this.getVisibleProperty(e, t);
for (const o in i)
n[o] = Object.assign(n[o] || {}, i[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;
}
s && s(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 i = t && t.parent && t.parent.schema;
if (!i)
return;
const s = i.contents.findIndex((n) => n.id === e), r = q(i.contents[s]);
i.contents.splice(s, 1), i.contents.splice(s, 0, r), $();
}
/**
* 属性编辑器,在编辑过程中会新增变量,此处需要将新增的变量追加到ViewModel中
* @param changeObject
* @param viewModelId
* @returns
*/
addNewVariableToViewModel(e, t) {
const i = e.propertyValue;
if (!(i && typeof i == "object") || !(i.type === "Variable" && i.isNewVariable))
return;
const n = {
id: i.field,
category: "locale",
code: i.fullPath,
name: i.fullPath,
type: i.newVariableType || "String",
isRtcVariable: this.designerContext.designerMode === "PC_RTC" ? !0 : void 0
};
delete i.newVariableType, delete i.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 i = e.propertyValue;
if (!((i && i.type) === "Expression" && i.expressionInfo))
return;
const { expressionId: n, expressionInfo: l } = i, { targetId: o, targetType: a, expressionType: d, value: u, message: m } = l, f = this.getExpressions();
let g = f.find((h) => h.target === o);
g || (g = { target: o, rules: [], targetType: a }, f.push(g));
const x = g.rules.find((h) => h.type === d);
if (x)
x.value = u, x.message = m, (d === "minDate" || d === "maxDate" || d === "defaultTime") && (x.elementId = t.id);
else {
const h = { id: n, type: d, value: u, message: m, elementId: t.id };
g.rules.push(h);
}
delete i.expressionInfo;
}
/**
* 属性类型切换为非表达式后,清除原表达式
* @param changeObject
* @param propertyData
* @returns
*/
clearExpression(e, t) {
const i = e.propertyValue;
if (i && i.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, i) {
return this.expressionProperty.getExpressionOptions(e, t, i);
}
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: (i) => {
var s;
((s = i.controller) == null ? void 0 : s.label.indexOf(this.formSchemaUtils.getModule().code)) > -1 && this.eventsEditorUtils.jumpToMethod(i);
}
}
}, t;
}
}
class Z extends Y {
constructor(e, t) {
super(e, t);
}
getPropertyConfig(e) {
return this.propertyConfig.categories.basic = this.getBasicPropConfig(e), this.propertyConfig.categories.template = this.getTemplateProperties(e), this.propertyConfig;
}
getTemplateProperties(e) {
return {
title: "模板",
description: "",
properties: {
html: {
title: "html",
type: "string",
description: "HTML模板",
refreshPanelAfterChanged: !0,
editor: {
type: "code-editor",
language: "html"
}
}
}
};
}
}
function ee(c, e) {
function t() {
return !1;
}
function i() {
return !0;
}
function s() {
return !0;
}
function r() {
return !0;
}
function n(o) {
return new Z(o, e).getPropertyConfig(c);
}
function l() {
return "";
}
return {
canAccepts: t,
hideNestedPaddingInDesginerView: r,
getPropsConfig: n,
checkCanDeleteComponent: i,
checkCanMoveComponent: s,
getDesignerClass: l
};
}
const te = /* @__PURE__ */ M({
name: "FHtmlTemplateDesign",
props: w,
emits: [],
setup(c, e) {
const t = F(), i = V("designer-host-service"), s = V("design-item-context"), r = ee(s.schema, i), n = A(t, s, r);
k(() => {
t.value.componentInstance = n;
}), e.expose(n.value);
const o = '<div class="fv-html-template-design-placeholder">请在属性面板中配置模板</div>', a = N(() => c.html ? c.html : o);
return () => U("div", {
ref: t,
class: "fv-html-template-design",
innerHTML: a.value
}, null);
}
});
v.register = (c, e, t, i, s) => {
c["html-template"] = v, e["html-template"] = K(s);
};
v.registerDesigner = (c, e, t, i) => {
c["html-template"] = te, e["html-template"] = Q(i);
};
const ce = B(v);
export {
v as FHtmlTemplate,
ce as default,
de as designPropsResolver,
Q as designPropsResolverGenerator,
w as htmlTemplateDesignProps,
C as htmlTemplateProps,
ae as propsResolver,
K as propsResolverGenerator
};