|
@@ -222,13 +222,19 @@ export default function AICreator(props: {
|
|
|
|
|
|
// 替换节点文本内容
|
|
|
const handleReplace = (labelMap: LabelMap, data: Record<string, string>) => {
|
|
|
- Object.keys(data).forEach((key) => {
|
|
|
+ const keyMap: Record<string, string> = data;
|
|
|
+ if(Array.isArray(data)) {
|
|
|
+ data.forEach(item => {
|
|
|
+ keyMap[item.original] = item.value
|
|
|
+ })
|
|
|
+ }
|
|
|
+ Object.keys(keyMap).forEach((key) => {
|
|
|
if (labelMap[key]) {
|
|
|
labelMap[key].forEach((item) => {
|
|
|
const cell = graph?.getCellById(item.cell);
|
|
|
if (cell && cell.shape !== "edge") {
|
|
|
cell.setData({
|
|
|
- [item.key]: data[key],
|
|
|
+ [item.key]: keyMap[key],
|
|
|
});
|
|
|
graph?.select(cell);
|
|
|
} else if (cell?.isEdge()) {
|
|
@@ -239,7 +245,7 @@ export default function AICreator(props: {
|
|
|
...item,
|
|
|
attrs: {
|
|
|
label: {
|
|
|
- text: data?.[(item.attrs?.label?.text as string)?.trim()] || item.attrs?.label?.text
|
|
|
+ text: keyMap?.[(item.attrs?.label?.text as string)?.trim()] || item.attrs?.label?.text
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -290,10 +296,7 @@ export default function AICreator(props: {
|
|
|
const data = JSON.stringify(Object.keys(labelMap));
|
|
|
let result = "";
|
|
|
onRequest(
|
|
|
- `修复语法错误,并返回修复后的键对值,要求:
|
|
|
-1、仅返回修复后的JSON数据,不展示其他内容
|
|
|
-2、以键值对展示 如: {'大有做为': '大有作为'}
|
|
|
-需要修复的数据:${data}`,
|
|
|
+ `修复语法错误,需要修复的数据:${data}`,
|
|
|
{
|
|
|
onUpdate: (data) => {
|
|
|
result += data.answer;
|
|
@@ -361,10 +364,7 @@ export default function AICreator(props: {
|
|
|
const data = JSON.stringify(Object.keys(labelMap));
|
|
|
let result = "";
|
|
|
onRequest(
|
|
|
- `翻译成${lang === 'en' ? '英文' : '中文'},并返回翻译后的键对值,要求:
|
|
|
- 1、仅返回修复后的JSON数据,不展示其他内容
|
|
|
- 2、以键值对展示 如: {'中文': 'Chinese'}
|
|
|
- 需要翻译的数据:${data}`,
|
|
|
+ `翻译成${lang === 'en' ? '英文' : '中文'},需要翻译的数据:${data}`,
|
|
|
{
|
|
|
onUpdate: (data) => {
|
|
|
result += data.answer;
|