Selaa lähdekoodia

支持新的 json from

visuddhinanda 2 vuotta sitten
vanhempi
sitoutus
993a81958f

+ 98 - 8
dashboard/src/components/admin/relation/RelationEdit.tsx

@@ -1,6 +1,7 @@
 import {
 import {
   ModalForm,
   ModalForm,
   ProForm,
   ProForm,
+  ProFormDependency,
   ProFormInstance,
   ProFormInstance,
   ProFormSelect,
   ProFormSelect,
   ProFormText,
   ProFormText,
@@ -32,7 +33,50 @@ const RelationEditWidget = ({
   const formRef = useRef<ProFormInstance>();
   const formRef = useRef<ProFormInstance>();
   const intl = useIntl();
   const intl = useIntl();
 
 
-  const _verb = ["v", "pass", "caus", "ger", "fpp", "pp", "n", "adv"];
+  const _verb = [
+    "n",
+    "ti",
+    "v",
+    "v:ind",
+    "ind",
+    "sg",
+    "pl",
+    "nom",
+    "acc",
+    "gen",
+    "dat",
+    "inst",
+    "voc",
+    "abl",
+    "loc",
+    "base",
+    "imp",
+    "opt",
+    "pres",
+    "aor",
+    "fut",
+    "1p",
+    "2p",
+    "3p",
+    "prp",
+    "pp",
+    "grd",
+    "fpp",
+    "vdn",
+    "ger",
+    "inf",
+    "adj",
+    "pron",
+    "caus",
+    "num",
+    "adv",
+    "conj",
+    "pre",
+    "suf",
+    "ti:base",
+    "n:base",
+    "v:base",
+  ];
   const verbOptions = _verb.map((item) => {
   const verbOptions = _verb.map((item) => {
     return {
     return {
       value: item,
       value: item,
@@ -50,21 +94,24 @@ const RelationEditWidget = ({
       autoFocusFirstInput
       autoFocusFirstInput
       modalProps={{
       modalProps={{
         destroyOnClose: true,
         destroyOnClose: true,
-        onCancel: () => console.log("run"),
+        onCancel: () => console.log("onCancel"),
       }}
       }}
-      submitTimeout={2000}
+      submitTimeout={3000}
       onFinish={async (values) => {
       onFinish={async (values) => {
         console.log("submit", values);
         console.log("submit", values);
+        let data = values;
+        data.from = { spell: values.fromSpell, case: values.fromCase };
+        console.log("data", data);
         let res: IRelationResponse;
         let res: IRelationResponse;
         if (typeof id === "undefined") {
         if (typeof id === "undefined") {
           res = await post<IRelationRequest, IRelationResponse>(
           res = await post<IRelationRequest, IRelationResponse>(
             `/v2/relation`,
             `/v2/relation`,
-            values
+            data
           );
           );
         } else {
         } else {
           res = await put<IRelationRequest, IRelationResponse>(
           res = await put<IRelationRequest, IRelationResponse>(
             `/v2/relation/${id}`,
             `/v2/relation/${id}`,
-            values
+            data
           );
           );
         }
         }
         console.log(res);
         console.log(res);
@@ -91,6 +138,7 @@ const RelationEditWidget = ({
                   id: id,
                   id: id,
                   name: res.data.name,
                   name: res.data.name,
                   case: res.data.case,
                   case: res.data.case,
+                  from: res.data.from,
                   to: res.data.to,
                   to: res.data.to,
                 };
                 };
               } else {
               } else {
@@ -111,8 +159,50 @@ const RelationEditWidget = ({
         />
         />
       </ProForm.Group>
       </ProForm.Group>
       <ProForm.Group>
       <ProForm.Group>
-        <CaseSelect width="md" name="case" />
-
+        <ProFormSelect
+          options={[
+            {
+              value: "case",
+              label: intl.formatMessage({ id: "forms.fields.case.label" }),
+            },
+            {
+              value: "spell",
+              label: intl.formatMessage({ id: "buttons.spell" }),
+            },
+          ]}
+          width="md"
+          name="fromType"
+          allowClear={false}
+          label={intl.formatMessage({ id: "forms.fields.from.label" })}
+        />
+        <ProFormDependency name={["fromType"]}>
+          {({ fromType }) => {
+            console.log("from type", fromType);
+            return (
+              <>
+                <ProFormSelect
+                  hidden={fromType === "spell"}
+                  options={verbOptions}
+                  fieldProps={{
+                    mode: "tags",
+                  }}
+                  width="md"
+                  name="fromCase"
+                  allowClear={false}
+                  label={intl.formatMessage({ id: "forms.fields.case.label" })}
+                />
+                <ProFormText
+                  hidden={fromType === "case"}
+                  width="md"
+                  name="fromSpell"
+                  label={intl.formatMessage({ id: "buttons.spell" })}
+                />
+              </>
+            );
+          }}
+        </ProFormDependency>
+      </ProForm.Group>
+      <ProForm.Group>
         <ProFormSelect
         <ProFormSelect
           options={verbOptions}
           options={verbOptions}
           fieldProps={{
           fieldProps={{
@@ -121,7 +211,7 @@ const RelationEditWidget = ({
           width="md"
           width="md"
           name="to"
           name="to"
           allowClear={false}
           allowClear={false}
-          label={intl.formatMessage({ id: "forms.fields.case.label" })}
+          label={intl.formatMessage({ id: "forms.fields.to.label" })}
         />
         />
       </ProForm.Group>
       </ProForm.Group>
     </ModalForm>
     </ModalForm>

+ 28 - 5
dashboard/src/pages/admin/relation/list.tsx

@@ -68,6 +68,7 @@ export interface IRelationRequest {
   id?: string;
   id?: string;
   name: string;
   name: string;
   case?: string | null;
   case?: string | null;
+  from?: IFrom | null;
   to?: string[];
   to?: string[];
   editor?: IUser;
   editor?: IUser;
   updated_at?: string;
   updated_at?: string;
@@ -86,11 +87,18 @@ export interface IRelationResponse {
   message: string;
   message: string;
   data: IRelationRequest;
   data: IRelationRequest;
 }
 }
+interface IFrom {
+  spell?: string;
+  case?: string[];
+}
 export interface IRelation {
 export interface IRelation {
   sn?: number;
   sn?: number;
   id?: string;
   id?: string;
   name: string;
   name: string;
   case?: string | null;
   case?: string | null;
+  from?: IFrom | null;
+  fromCase?: string[];
+  fromSpell?: string;
   to?: string[];
   to?: string[];
   updatedAt?: number;
   updatedAt?: number;
   createdAt?: number;
   createdAt?: number;
@@ -186,12 +194,26 @@ const Widget = () => {
           },
           },
           {
           {
             title: intl.formatMessage({
             title: intl.formatMessage({
-              id: "forms.fields.case.label",
+              id: "forms.fields.from.label",
             }),
             }),
-            dataIndex: "case",
-            key: "case",
-            filters: true,
-            valueEnum: CaseValueEnum(),
+            dataIndex: "from",
+            key: "from",
+            render: (text, row, index, action) => {
+              const spell = row.from?.spell;
+              const fromCase = row.from?.case?.map((item, id) => (
+                <Tag key={id}>
+                  {intl.formatMessage({
+                    id: `dict.fields.type.${item}.label`,
+                  })}
+                </Tag>
+              ));
+              return (
+                <>
+                  {spell}
+                  {fromCase}
+                </>
+              );
+            },
           },
           },
           {
           {
             title: intl.formatMessage({
             title: intl.formatMessage({
@@ -288,6 +310,7 @@ const Widget = () => {
               id: item.id,
               id: item.id,
               name: item.name,
               name: item.name,
               case: item.case,
               case: item.case,
+              from: item.from,
               to: item.to,
               to: item.to,
               createdAt: date.getTime(),
               createdAt: date.getTime(),
               updatedAt: date2.getTime(),
               updatedAt: date2.getTime(),