You've already forked DataMate
feat(template): 添加标签显示名称映射功能
- 引入 COMMON_TAG_DISPLAY_NAMES 映射表,为常用标签提供中文显示名称 - 更新布局控件选项以使用中文显示名称 - 修改容器选项以使用中文显示名称 - 添加 getTagDisplayName 回调函数,统一处理标签名称显示逻辑 - 优化节点标题显示,结合标签类型和属性值展示更友好的名称 - 更新依赖数组以包含新的显示名称函数
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { useEffect, useMemo, useRef, useState } from "react";
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||||
import {
|
import {
|
||||||
Alert,
|
Alert,
|
||||||
Button,
|
Button,
|
||||||
@@ -204,9 +204,20 @@ const isDescendant = (node: XmlNode, targetId: string): boolean => {
|
|||||||
return node.children.some((child) => isDescendant(child, targetId));
|
return node.children.some((child) => isDescendant(child, targetId));
|
||||||
};
|
};
|
||||||
|
|
||||||
const getNodeLabel = (node: XmlNode) => {
|
const COMMON_TAG_DISPLAY_NAMES: Record<string, string> = {
|
||||||
const name = node.attrs.name || node.attrs.value;
|
View: "容器",
|
||||||
return name ? `${node.tag} (${name})` : node.tag;
|
Header: "标题",
|
||||||
|
Style: "样式",
|
||||||
|
Label: "标签项",
|
||||||
|
Choice: "选项",
|
||||||
|
Relation: "关系",
|
||||||
|
Relations: "关系组",
|
||||||
|
Item: "列表项",
|
||||||
|
Path: "路径",
|
||||||
|
Channel: "通道",
|
||||||
|
Collapse: "折叠面板",
|
||||||
|
Filter: "过滤器",
|
||||||
|
Shortcut: "快捷键",
|
||||||
};
|
};
|
||||||
|
|
||||||
const getDefaultName = (tag: string) => {
|
const getDefaultName = (tag: string) => {
|
||||||
@@ -478,7 +489,10 @@ const TemplateConfigurationTreeEditor = ({
|
|||||||
.map(([tag]) => ({ value: tag, label: getControlDisplayName(tag) }));
|
.map(([tag]) => ({ value: tag, label: getControlDisplayName(tag) }));
|
||||||
const layout = Object.entries(config.controls)
|
const layout = Object.entries(config.controls)
|
||||||
.filter(([, item]) => item.category === "layout")
|
.filter(([, item]) => item.category === "layout")
|
||||||
.map(([tag]) => ({ value: tag, label: tag }));
|
.map(([tag]) => ({
|
||||||
|
value: tag,
|
||||||
|
label: COMMON_TAG_DISPLAY_NAMES[tag] || tag,
|
||||||
|
}));
|
||||||
return { labeling, layout };
|
return { labeling, layout };
|
||||||
}, [config]);
|
}, [config]);
|
||||||
|
|
||||||
@@ -497,7 +511,7 @@ const TemplateConfigurationTreeEditor = ({
|
|||||||
}[];
|
}[];
|
||||||
options.push({
|
options.push({
|
||||||
label: "容器",
|
label: "容器",
|
||||||
options: [{ value: "View", label: "View" }],
|
options: [{ value: "View", label: COMMON_TAG_DISPLAY_NAMES.View }],
|
||||||
});
|
});
|
||||||
if (objectOptions.length > 0) {
|
if (objectOptions.length > 0) {
|
||||||
options.push({ label: "数据对象", options: objectOptions });
|
options.push({ label: "数据对象", options: objectOptions });
|
||||||
@@ -510,11 +524,23 @@ const TemplateConfigurationTreeEditor = ({
|
|||||||
}
|
}
|
||||||
options.push({
|
options.push({
|
||||||
label: "子标签",
|
label: "子标签",
|
||||||
options: CHILD_TAGS.map((tag) => ({ value: tag, label: tag })),
|
options: CHILD_TAGS.map((tag) => ({
|
||||||
|
value: tag,
|
||||||
|
label: COMMON_TAG_DISPLAY_NAMES[tag] || tag,
|
||||||
|
})),
|
||||||
});
|
});
|
||||||
return options;
|
return options;
|
||||||
}, [objectOptions, controlOptions]);
|
}, [objectOptions, controlOptions]);
|
||||||
|
|
||||||
|
const getTagDisplayName = useCallback(
|
||||||
|
(tag: string) => {
|
||||||
|
if (config?.objects?.[tag]) return getObjectDisplayName(tag);
|
||||||
|
if (config?.controls?.[tag]) return getControlDisplayName(tag);
|
||||||
|
return COMMON_TAG_DISPLAY_NAMES[tag] || tag;
|
||||||
|
},
|
||||||
|
[config]
|
||||||
|
);
|
||||||
|
|
||||||
const handleAddNode = (tag: string, mode: "child" | "sibling") => {
|
const handleAddNode = (tag: string, mode: "child" | "sibling") => {
|
||||||
if (isStructureLocked) return;
|
if (isStructureLocked) return;
|
||||||
const newNode = createNode(tag, config || null, objectNames);
|
const newNode = createNode(tag, config || null, objectNames);
|
||||||
@@ -630,12 +656,16 @@ const TemplateConfigurationTreeEditor = ({
|
|||||||
const issue = validationIssues[node.id];
|
const issue = validationIssues[node.id];
|
||||||
const hasError = issue?.errors?.length > 0;
|
const hasError = issue?.errors?.length > 0;
|
||||||
const hasWarning = issue?.warnings?.length > 0;
|
const hasWarning = issue?.warnings?.length > 0;
|
||||||
|
const name = node.attrs.name || node.attrs.value;
|
||||||
|
const title = name
|
||||||
|
? `${getTagDisplayName(node.tag)} (${name})`
|
||||||
|
: getTagDisplayName(node.tag);
|
||||||
return {
|
return {
|
||||||
key: node.id,
|
key: node.id,
|
||||||
title: (
|
title: (
|
||||||
<Space size={6}>
|
<Space size={6}>
|
||||||
<span className={hasError ? "text-red-600" : undefined}>
|
<span className={hasError ? "text-red-600" : undefined}>
|
||||||
{getNodeLabel(node)}
|
{title}
|
||||||
</span>
|
</span>
|
||||||
{hasError && <Tag color="red">错误</Tag>}
|
{hasError && <Tag color="red">错误</Tag>}
|
||||||
{!hasError && hasWarning && <Tag color="gold">提示</Tag>}
|
{!hasError && hasWarning && <Tag color="gold">提示</Tag>}
|
||||||
@@ -646,7 +676,7 @@ const TemplateConfigurationTreeEditor = ({
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
return [build(tree)];
|
return [build(tree)];
|
||||||
}, [tree, validationIssues, isStructureLocked]);
|
}, [tree, validationIssues, isStructureLocked, getTagDisplayName]);
|
||||||
|
|
||||||
const onDrop: TreeProps["onDrop"] = (info) => {
|
const onDrop: TreeProps["onDrop"] = (info) => {
|
||||||
if (isStructureLocked) return;
|
if (isStructureLocked) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user