Explorar o código

按照 箭头左 + relation + 分类分组

visuddhinanda %!s(int64=2) %!d(string=hai) anos
pai
achega
93f309ca7d
Modificáronse 1 ficheiros con 34 adicións e 26 borrados
  1. 34 26
      dashboard/src/components/general/NissayaCardTable.tsx

+ 34 - 26
dashboard/src/components/general/NissayaCardTable.tsx

@@ -2,6 +2,10 @@ import { Button, Space, Table, Tag } from "antd";
 import lodash from "lodash";
 import lodash from "lodash";
 import { useEffect, useState } from "react";
 import { useEffect, useState } from "react";
 import { ArrowRightOutlined } from "@ant-design/icons";
 import { ArrowRightOutlined } from "@ant-design/icons";
+
+const randomString = () =>
+  lodash.times(20, () => lodash.random(35).toString(36)).join("");
+
 interface ICaseItem {
 interface ICaseItem {
   label: string;
   label: string;
   link: string;
   link: string;
@@ -18,6 +22,7 @@ interface DataType {
   from?: IRelationNode;
   from?: IRelationNode;
   category?: { name: string; note: string; meaning: string };
   category?: { name: string; note: string; meaning: string };
   translation?: string;
   translation?: string;
+  isChildren?: boolean;
   children?: DataType[];
   children?: DataType[];
 }
 }
 export interface INissayaRelation {
 export interface INissayaRelation {
@@ -44,44 +49,47 @@ const NissayaCardTableWidget = ({ data }: IWidget) => {
     let newData: DataType[] = [];
     let newData: DataType[] = [];
     data.forEach((item, index) => {
     data.forEach((item, index) => {
       if (item.category && item.category.name) {
       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);
           console.log("category", category);
           //处理children
           //处理children
           const children = data
           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) => {
             .map((item, index) => {
               return {
               return {
-                key: lodash
-                  .times(20, () => lodash.random(35).toString(36))
-                  .join(""),
+                key: randomString(),
                 relation: item.relation,
                 relation: item.relation,
                 localRelation: item.local_relation,
                 localRelation: item.local_relation,
                 from: item.from,
                 from: item.from,
                 to: item.to,
                 to: item.to,
                 category: item.category,
                 category: item.category,
                 translation: item.local_ending,
                 translation: item.local_ending,
+                isChildren: true,
               };
               };
             });
             });
           console.log("children", children);
           console.log("children", children);
           newData.push({
           newData.push({
-            key: lodash
-              .times(20, () => lodash.random(35).toString(36))
-              .join(""),
+            key: randomString(),
             relation: item.relation,
             relation: item.relation,
             localRelation: item.local_relation,
             localRelation: item.local_relation,
-            to: item.to,
             from: item.from,
             from: item.from,
+            to: item.to,
             category: item.category,
             category: item.category,
             translation: item.local_ending,
             translation: item.local_ending,
-            children: [...children],
+            children: children.length > 1 ? [...children] : undefined,
           });
           });
         }
         }
       } else {
       } else {
         newData.push({
         newData.push({
-          key: lodash.times(20, () => lodash.random(35).toString(36)).join(""),
+          key: randomString(),
           relation: item.relation,
           relation: item.relation,
           localRelation: item.local_relation,
           localRelation: item.local_relation,
           from: item.to,
           from: item.to,
@@ -125,7 +133,7 @@ const NissayaCardTableWidget = ({ data }: IWidget) => {
           title: "关系",
           title: "关系",
           dataIndex: "relation",
           dataIndex: "relation",
           key: "relation",
           key: "relation",
-          width: "12%",
+          width: "16%",
           render: (value, record, index) => {
           render: (value, record, index) => {
             return (
             return (
               <Space direction="vertical">
               <Space direction="vertical">
@@ -140,14 +148,7 @@ const NissayaCardTableWidget = ({ data }: IWidget) => {
           dataIndex: "to",
           dataIndex: "to",
           key: "to",
           key: "to",
           render: (value, record, index) => {
           render: (value, record, index) => {
-            if (record.children) {
-              return (
-                <Space>
-                  <ArrowRightOutlined />
-                  {record.category?.meaning}
-                </Space>
-              );
-            } else {
+            if (record.isChildren) {
               return (
               return (
                 <Space>
                 <Space>
                   <ArrowRightOutlined />
                   <ArrowRightOutlined />
@@ -166,6 +167,13 @@ const NissayaCardTableWidget = ({ data }: IWidget) => {
                   {record.to?.spell}
                   {record.to?.spell}
                 </Space>
                 </Space>
               );
               );
+            } else {
+              return (
+                <Space>
+                  <ArrowRightOutlined />
+                  {record.category?.meaning}
+                </Space>
+              );
             }
             }
           },
           },
         },
         },
@@ -175,10 +183,10 @@ const NissayaCardTableWidget = ({ data }: IWidget) => {
           width: "30%",
           width: "30%",
           key: "address",
           key: "address",
           render: (value, record, index) => {
           render: (value, record, index) => {
-            if (record.children) {
-              return <>{record.category?.note}</>;
-            } else {
+            if (record.isChildren) {
               return undefined;
               return undefined;
+            } else {
+              return <>{record.category?.note}</>;
             }
             }
           },
           },
         },
         },