|
|
@@ -1,6 +1,10 @@
|
|
|
-import { recordKeyToString } from "@ant-design/pro-components";
|
|
|
import { Button, Space, Table, Tag } from "antd";
|
|
|
+import lodash from "lodash";
|
|
|
import { useEffect, useState } from "react";
|
|
|
+import { ArrowRightOutlined } from "@ant-design/icons";
|
|
|
+
|
|
|
+const randomString = () =>
|
|
|
+ lodash.times(20, () => lodash.random(35).toString(36)).join("");
|
|
|
|
|
|
interface ICaseItem {
|
|
|
label: string;
|
|
|
@@ -11,13 +15,14 @@ interface IRelationNode {
|
|
|
spell?: string;
|
|
|
}
|
|
|
interface DataType {
|
|
|
- key: React.ReactNode;
|
|
|
+ key: string;
|
|
|
relation: string;
|
|
|
localRelation?: string;
|
|
|
to?: IRelationNode;
|
|
|
from?: IRelationNode;
|
|
|
category?: { name: string; note: string; meaning: string };
|
|
|
translation?: string;
|
|
|
+ isChildren?: boolean;
|
|
|
children?: DataType[];
|
|
|
}
|
|
|
export interface INissayaRelation {
|
|
|
@@ -39,50 +44,61 @@ const NissayaCardTableWidget = ({ data }: IWidget) => {
|
|
|
setTableData(undefined);
|
|
|
return;
|
|
|
}
|
|
|
+ console.log("data", data);
|
|
|
let category: string[] = [];
|
|
|
let newData: DataType[] = [];
|
|
|
- let id = 0;
|
|
|
- for (const item of data) {
|
|
|
- id++;
|
|
|
+ data.forEach((item, index) => {
|
|
|
if (item.category && item.category.name) {
|
|
|
- if (category.includes(item.category.name)) {
|
|
|
- continue;
|
|
|
- } else {
|
|
|
- category.push(item.category.name);
|
|
|
+ const key = `${item.from?.spell}-${item.from?.case
|
|
|
+ ?.map((item) => item.label)
|
|
|
+ .join()}-${item.relation}-${item.category}`;
|
|
|
+ if (!category.includes(key)) {
|
|
|
+ category.push(key);
|
|
|
+ console.log("category", category);
|
|
|
//处理children
|
|
|
const children = data
|
|
|
- .filter((value) => value.category?.name === item.category?.name)
|
|
|
+ .filter(
|
|
|
+ (value) =>
|
|
|
+ `${value.from?.spell}-${value.from?.case
|
|
|
+ ?.map((item) => item.label)
|
|
|
+ .join()}-${value.relation}-${value.category}` === key
|
|
|
+ )
|
|
|
.map((item, index) => {
|
|
|
return {
|
|
|
- key: `c_${index}`,
|
|
|
+ key: randomString(),
|
|
|
relation: item.relation,
|
|
|
+ localRelation: item.local_relation,
|
|
|
from: item.from,
|
|
|
to: item.to,
|
|
|
category: item.category,
|
|
|
translation: item.local_ending,
|
|
|
+ isChildren: true,
|
|
|
};
|
|
|
});
|
|
|
+ console.log("children", children);
|
|
|
newData.push({
|
|
|
- key: id,
|
|
|
+ key: randomString(),
|
|
|
relation: item.relation,
|
|
|
- to: item.to,
|
|
|
+ localRelation: item.local_relation,
|
|
|
from: item.from,
|
|
|
+ to: item.to,
|
|
|
category: item.category,
|
|
|
translation: item.local_ending,
|
|
|
- children: children,
|
|
|
+ children: children.length > 1 ? [...children] : undefined,
|
|
|
});
|
|
|
}
|
|
|
} else {
|
|
|
newData.push({
|
|
|
- key: id,
|
|
|
+ key: randomString(),
|
|
|
relation: item.relation,
|
|
|
+ localRelation: item.local_relation,
|
|
|
from: item.to,
|
|
|
to: item.to,
|
|
|
category: item.category,
|
|
|
translation: item.local_ending,
|
|
|
});
|
|
|
}
|
|
|
- }
|
|
|
+ });
|
|
|
|
|
|
setTableData(newData);
|
|
|
}, [data]);
|
|
|
@@ -90,7 +106,7 @@ const NissayaCardTableWidget = ({ data }: IWidget) => {
|
|
|
<Table
|
|
|
columns={[
|
|
|
{
|
|
|
- title: "本词",
|
|
|
+ title: "本词特征",
|
|
|
dataIndex: "from",
|
|
|
key: "from",
|
|
|
render: (value, record, index) => {
|
|
|
@@ -117,9 +133,14 @@ const NissayaCardTableWidget = ({ data }: IWidget) => {
|
|
|
title: "关系",
|
|
|
dataIndex: "relation",
|
|
|
key: "relation",
|
|
|
- width: "12%",
|
|
|
+ width: "16%",
|
|
|
render: (value, record, index) => {
|
|
|
- return <>{record.relation}</>;
|
|
|
+ return (
|
|
|
+ <Space direction="vertical">
|
|
|
+ {record.relation}
|
|
|
+ {record.localRelation}
|
|
|
+ </Space>
|
|
|
+ );
|
|
|
},
|
|
|
},
|
|
|
{
|
|
|
@@ -127,11 +148,10 @@ const NissayaCardTableWidget = ({ data }: IWidget) => {
|
|
|
dataIndex: "to",
|
|
|
key: "to",
|
|
|
render: (value, record, index) => {
|
|
|
- if (record.children) {
|
|
|
- return <>{record.category?.meaning}</>;
|
|
|
- } else {
|
|
|
+ if (record.isChildren) {
|
|
|
return (
|
|
|
<Space>
|
|
|
+ <ArrowRightOutlined />
|
|
|
{record.to?.case?.map((item, id) => {
|
|
|
return (
|
|
|
<Button
|
|
|
@@ -147,6 +167,13 @@ const NissayaCardTableWidget = ({ data }: IWidget) => {
|
|
|
{record.to?.spell}
|
|
|
</Space>
|
|
|
);
|
|
|
+ } else {
|
|
|
+ return (
|
|
|
+ <Space>
|
|
|
+ <ArrowRightOutlined />
|
|
|
+ {record.category?.meaning}
|
|
|
+ </Space>
|
|
|
+ );
|
|
|
}
|
|
|
},
|
|
|
},
|
|
|
@@ -156,10 +183,10 @@ const NissayaCardTableWidget = ({ data }: IWidget) => {
|
|
|
width: "30%",
|
|
|
key: "address",
|
|
|
render: (value, record, index) => {
|
|
|
- if (record.children) {
|
|
|
- return <>{record.category?.note}</>;
|
|
|
- } else {
|
|
|
+ if (record.isChildren) {
|
|
|
return undefined;
|
|
|
+ } else {
|
|
|
+ return <>{record.category?.note}</>;
|
|
|
}
|
|
|
},
|
|
|
},
|