Explorar o código

:sparkles: dict 修改

visuddhinanda %!s(int64=3) %!d(string=hai) anos
pai
achega
8b1f296bfd
Modificáronse 1 ficheiros con 38 adicións e 17 borrados
  1. 38 17
      dashboard/src/pages/studio/dict/list.tsx

+ 38 - 17
dashboard/src/pages/studio/dict/list.tsx

@@ -1,7 +1,7 @@
 import { useParams } from "react-router-dom";
 import { useParams } from "react-router-dom";
 import { ProTable } from "@ant-design/pro-components";
 import { ProTable } from "@ant-design/pro-components";
 import { useIntl } from "react-intl";
 import { useIntl } from "react-intl";
-import { Link } from "react-router-dom";
+
 import {
 import {
 	Button,
 	Button,
 	Layout,
 	Layout,
@@ -18,6 +18,7 @@ import DictCreate from "../../../components/studio/dict/DictCreate";
 import { IApiResponseDictList } from "../../../components/api/Dict";
 import { IApiResponseDictList } from "../../../components/api/Dict";
 import { get } from "../../../request";
 import { get } from "../../../request";
 import { useState } from "react";
 import { useState } from "react";
+import DictEdit from "../../../components/studio/dict/DictEdit";
 
 
 const onMenuClick: MenuProps["onClick"] = (e) => {
 const onMenuClick: MenuProps["onClick"] = (e) => {
 	console.log("click", e);
 	console.log("click", e);
@@ -48,6 +49,7 @@ const menu = (
 
 
 interface IItem {
 interface IItem {
 	id: number;
 	id: number;
+	wordId: number;
 	word: string;
 	word: string;
 	type: string;
 	type: string;
 	grammar: string;
 	grammar: string;
@@ -68,8 +70,10 @@ const valueEnum = {
 const Widget = () => {
 const Widget = () => {
 	const intl = useIntl();
 	const intl = useIntl();
 	const { studioname } = useParams();
 	const { studioname } = useParams();
-	const [isModalOpen, setIsModalOpen] = useState(false);
-	const dictCreate = <DictCreate studio={studioname ? studioname : ""} />;
+	const [isEditOpen, setIsEditOpen] = useState(false);
+	const [isCreateOpen, setIsCreateOpen] = useState(false);
+	const [wordId, setWordId] = useState(0);
+	const [drawerTitle, setDrawerTitle] = useState("New Word");
 
 
 	return (
 	return (
 		<>
 		<>
@@ -176,14 +180,15 @@ const Widget = () => {
 									key={index}
 									key={index}
 									type="link"
 									type="link"
 									overlay={menu}
 									overlay={menu}
+									onClick={() => {
+										setWordId(row.wordId);
+										setDrawerTitle(row.word);
+										setIsEditOpen(true);
+									}}
 								>
 								>
-									<Link
-										to={`/studio/${studioname}/dict/${row.id}/edit`}
-									>
-										{intl.formatMessage({
-											id: "buttons.edit",
-										})}
-									</Link>
+									{intl.formatMessage({
+										id: "buttons.edit",
+									})}
 								</Dropdown.Button>,
 								</Dropdown.Button>,
 							];
 							];
 						},
 						},
@@ -244,6 +249,7 @@ const Widget = () => {
 							1;
 							1;
 						return {
 						return {
 							id: id2,
 							id: id2,
+							wordId: item.id,
 							word: item.word,
 							word: item.word,
 							type: item.type,
 							type: item.type,
 							grammar: item.grammar,
 							grammar: item.grammar,
@@ -277,7 +283,8 @@ const Widget = () => {
 						icon={<PlusOutlined />}
 						icon={<PlusOutlined />}
 						type="primary"
 						type="primary"
 						onClick={() => {
 						onClick={() => {
-							setIsModalOpen(true);
+							setDrawerTitle("New word");
+							setIsCreateOpen(true);
 						}}
 						}}
 					>
 					>
 						{intl.formatMessage({ id: "buttons.create" })}
 						{intl.formatMessage({ id: "buttons.create" })}
@@ -286,18 +293,32 @@ const Widget = () => {
 			/>
 			/>
 
 
 			<Drawer
 			<Drawer
-				title="new word"
+				title={drawerTitle}
+				placement="right"
+				open={isCreateOpen}
+				onClose={() => {
+					setIsCreateOpen(false);
+				}}
+				key="create"
+				style={{ maxWidth: "100%" }}
+				contentWrapperStyle={{ overflowY: "auto" }}
+				footer={null}
+			>
+				<DictCreate studio={studioname ? studioname : ""} />
+			</Drawer>
+			<Drawer
+				title={drawerTitle}
 				placement="right"
 				placement="right"
-				open={isModalOpen}
+				open={isEditOpen}
 				onClose={() => {
 				onClose={() => {
-					setIsModalOpen(false);
+					setIsEditOpen(false);
 				}}
 				}}
-				size="large"
-				style={{ minWidth: 736, maxWidth: "100%" }}
+				key="edit"
+				style={{ maxWidth: "100%" }}
 				contentWrapperStyle={{ overflowY: "auto" }}
 				contentWrapperStyle={{ overflowY: "auto" }}
 				footer={null}
 				footer={null}
 			>
 			>
-				{dictCreate}
+				<DictEdit wordId={wordId} />
 			</Drawer>
 			</Drawer>
 		</>
 		</>
 	);
 	);