Browse Source

Merge pull request #1236 from visuddhinanda/agile

术语 添加Card
visuddhinanda 2 years ago
parent
commit
51ca5816d7

+ 1 - 1
dashboard/src/components/article/ArticleView.tsx

@@ -96,7 +96,7 @@ const ArticleViewWidget = ({
         ? html.map((item, id) => {
         ? html.map((item, id) => {
             return (
             return (
               <div key={id}>
               <div key={id}>
-                <MdView html={item} />
+                <MdView className="pcd_article" html={item} />
               </div>
               </div>
             );
             );
           })
           })

+ 15 - 10
dashboard/src/components/article/article.css

@@ -1,4 +1,4 @@
-h1,
+.pcd_article h1,
 h2,
 h2,
 h3,
 h3,
 h4,
 h4,
@@ -6,25 +6,30 @@ h5,
 h6 {
 h6 {
   font-weight: 700;
   font-weight: 700;
 }
 }
-h2 {
+.pcd_article h2 {
   margin-top: 1em;
   margin-top: 1em;
-  font-size: 180%;
+  font-size: 200%;
   border-bottom: 1px solid gray;
   border-bottom: 1px solid gray;
 }
 }
-h3 {
-  margin-top: 0.5em;
+.pcd_article h2 {
+  margin-top: 1em;
   font-size: 150%;
   font-size: 150%;
+  border-bottom: 1px solid gray;
 }
 }
-h4 {
-  font-size: 120%;
+.pcd_article h3 {
+  margin-top: 0.5em;
+  font-size: 130%;
 }
 }
-h5 {
+.pcd_article h4 {
   font-size: 110%;
   font-size: 110%;
 }
 }
-h6 {
+.pcd_article h5 {
+  font-size: 100%;
+}
+.pcd_article h6 {
   font-size: 100%;
   font-size: 100%;
 }
 }
-blockquote {
+.pcd_article blockquote {
   margin-left: 1em;
   margin-left: 1em;
   border-left: 4px solid #dad9d9;
   border-left: 4px solid #dad9d9;
   padding-left: 0.5em;
   padding-left: 0.5em;

+ 4 - 2
dashboard/src/components/template/MdView.tsx

@@ -1,21 +1,23 @@
 import { Typography } from "antd";
 import { Typography } from "antd";
 import { TCodeConvertor, XmlToReact } from "./utilities";
 import { TCodeConvertor, XmlToReact } from "./utilities";
-const { Text } = Typography;
+const { Paragraph } = Typography;
 
 
 interface IWidget {
 interface IWidget {
   html?: string;
   html?: string;
+  className?: string;
   placeholder?: string;
   placeholder?: string;
   wordWidget?: boolean;
   wordWidget?: boolean;
   convertor?: TCodeConvertor;
   convertor?: TCodeConvertor;
 }
 }
 const Widget = ({
 const Widget = ({
   html,
   html,
+  className,
   wordWidget = false,
   wordWidget = false,
   placeholder,
   placeholder,
   convertor,
   convertor,
 }: IWidget) => {
 }: IWidget) => {
   const jsx = html ? XmlToReact(html, wordWidget, convertor) : placeholder;
   const jsx = html ? XmlToReact(html, wordWidget, convertor) : placeholder;
-  return <Text>{jsx}</Text>;
+  return <Paragraph className={className}>{jsx}</Paragraph>;
 };
 };
 
 
 export default Widget;
 export default Widget;

+ 1 - 1
dashboard/src/components/term/TermEdit.tsx

@@ -135,7 +135,7 @@ const TermEditWidget = ({
             newValue
             newValue
           );
           );
         }
         }
-        console.log("term ", res);
+
         if (res.ok) {
         if (res.ok) {
           message.success("提交成功");
           message.success("提交成功");
           if (typeof onUpdate !== "undefined") {
           if (typeof onUpdate !== "undefined") {

+ 75 - 9
dashboard/src/components/term/TermItem.tsx

@@ -1,20 +1,86 @@
-import { Typography } from "antd";
+import { Button, Card, Dropdown, Space, Typography } from "antd";
+import { MoreOutlined, EditOutlined } from "@ant-design/icons";
+
 import { ITermDataResponse } from "../api/Term";
 import { ITermDataResponse } from "../api/Term";
 import MdView from "../template/MdView";
 import MdView from "../template/MdView";
+import UserName from "../auth/UserName";
+import TimeShow from "../general/TimeShow";
+import TermModal from "./TermModal";
+import { useState } from "react";
 
 
-const { Title, Text, Paragraph } = Typography;
+const { Text } = Typography;
 
 
 interface IWidget {
 interface IWidget {
   data?: ITermDataResponse;
   data?: ITermDataResponse;
 }
 }
-const Widget = ({ data }: IWidget) => {
+const TermItemWidget = ({ data }: IWidget) => {
+  const [openTermModal, setOpenTermModal] = useState(false);
   return (
   return (
-    <Paragraph>
-      <Title level={4}>{data?.meaning}</Title>
-      <Text>{data?.other_meaning}</Text>
-      <MdView html={data?.html} />
-    </Paragraph>
+    <>
+      <Card
+        title={
+          <Space direction="vertical" size={3}>
+            <Space>
+              <Text strong>{data?.meaning}</Text>
+              <Text type="secondary">{data?.other_meaning}</Text>
+            </Space>
+            <Space style={{ fontSize: "80%" }}>
+              <Text type="secondary">
+                <UserName {...data?.editor} />
+              </Text>
+              <Text type="secondary">update at</Text>
+              <TimeShow time={data?.updated_at} />
+            </Space>
+          </Space>
+        }
+        extra={
+          <Dropdown
+            key={1}
+            trigger={["click"]}
+            menu={{
+              items: [
+                {
+                  key: "edit",
+                  label: "edit",
+                  icon: <EditOutlined />,
+                },
+                {
+                  key: "translate",
+                  label: "translate",
+                  icon: <EditOutlined />,
+                },
+              ],
+              onClick: (e) => {
+                console.log("click ", e);
+                switch (e.key) {
+                  case "edit":
+                    setOpenTermModal(true);
+                    break;
+
+                  default:
+                    break;
+                }
+              },
+            }}
+            placement="bottomRight"
+          >
+            <Button
+              size="small"
+              shape="circle"
+              icon={<MoreOutlined />}
+            ></Button>
+          </Dropdown>
+        }
+      >
+        <MdView html={data?.html} />
+      </Card>
+      <TermModal
+        id={data?.guid}
+        open={openTermModal}
+        onClose={() => setOpenTermModal(false)}
+      />
+    </>
   );
   );
 };
 };
 
 
-export default Widget;
+export default TermItemWidget;

+ 15 - 5
dashboard/src/components/term/TermModal.tsx

@@ -1,10 +1,11 @@
-import { useState } from "react";
+import { useEffect, useState } from "react";
 import { Modal } from "antd";
 import { Modal } from "antd";
 import TermEdit from "./TermEdit";
 import TermEdit from "./TermEdit";
 import { ITermDataResponse } from "../api/Term";
 import { ITermDataResponse } from "../api/Term";
 
 
 interface IWidget {
 interface IWidget {
   trigger?: React.ReactNode;
   trigger?: React.ReactNode;
+  open?: boolean;
   id?: string;
   id?: string;
   word?: string;
   word?: string;
   studioName?: string;
   studioName?: string;
@@ -16,6 +17,7 @@ interface IWidget {
 }
 }
 const TermModalWidget = ({
 const TermModalWidget = ({
   trigger,
   trigger,
+  open = false,
   id,
   id,
   word,
   word,
   studioName,
   studioName,
@@ -25,9 +27,17 @@ const TermModalWidget = ({
   onUpdate,
   onUpdate,
   onClose,
   onClose,
 }: IWidget) => {
 }: IWidget) => {
-  const [isModalOpen, setIsModalOpen] = useState(false);
+  const [isModalOpen, setIsModalOpen] = useState(open);
 
 
-  const modalClone = () => {
+  useEffect(() => {
+    if (open) {
+      showModal();
+    } else {
+      modalClose();
+    }
+  }, [open]);
+
+  const modalClose = () => {
     setIsModalOpen(false);
     setIsModalOpen(false);
     if (document.getElementsByTagName("body")[0].hasAttribute("style")) {
     if (document.getElementsByTagName("body")[0].hasAttribute("style")) {
       document.getElementsByTagName("body")[0].removeAttribute("style");
       document.getElementsByTagName("body")[0].removeAttribute("style");
@@ -38,14 +48,14 @@ const TermModalWidget = ({
   };
   };
 
 
   const handleOk = () => {
   const handleOk = () => {
-    modalClone();
+    modalClose();
     if (typeof onClose !== "undefined") {
     if (typeof onClose !== "undefined") {
       onClose();
       onClose();
     }
     }
   };
   };
 
 
   const handleCancel = () => {
   const handleCancel = () => {
-    modalClone();
+    modalClose();
     if (typeof onClose !== "undefined") {
     if (typeof onClose !== "undefined") {
       onClose();
       onClose();
     }
     }

+ 21 - 18
dashboard/src/components/term/TermSearch.tsx

@@ -1,5 +1,5 @@
 import { useState, useEffect } from "react";
 import { useState, useEffect } from "react";
-import { Col, List, Row } from "antd";
+import { Col, List, Row, Typography } from "antd";
 
 
 import { get } from "../../request";
 import { get } from "../../request";
 import {
 import {
@@ -8,6 +8,7 @@ import {
   ITermResponse,
   ITermResponse,
 } from "../api/Term";
 } from "../api/Term";
 import TermItem from "./TermItem";
 import TermItem from "./TermItem";
+const { Title } = Typography;
 
 
 interface IWidget {
 interface IWidget {
   word?: string;
   word?: string;
@@ -43,23 +44,25 @@ const TermSearchWidget = ({ word, wordId, compact = false }: IWidget) => {
   }, [word, wordId]);
   }, [word, wordId]);
 
 
   return (
   return (
-    <Row>
-      <Col flex="200px">{compact ? <></> : <></>}</Col>
-      <Col flex="760px">
-        <List
-          itemLayout="vertical"
-          size="large"
-          dataSource={tableData}
-          header={word}
-          renderItem={(item) => (
-            <List.Item>
-              <TermItem data={item} />
-            </List.Item>
-          )}
-        />
-      </Col>
-      <Col flex="200px"></Col>
-    </Row>
+    <>
+      <Row>
+        <Col flex="200px">{compact ? <></> : <></>}</Col>
+        <Col flex="760px">
+          <Title>{word}</Title>
+          <List
+            itemLayout="vertical"
+            size="large"
+            dataSource={tableData}
+            renderItem={(item) => (
+              <List.Item>
+                <TermItem data={item} />
+              </List.Item>
+            )}
+          />
+        </Col>
+        <Col flex="200px"></Col>
+      </Row>
+    </>
   );
   );
 };
 };
 
 

+ 4 - 8
dashboard/src/request.ts

@@ -93,19 +93,15 @@ export const patch = <Request, Response>(
   });
   });
 };
 };
 
 
-export const put = <Request, Response>(
+export const put = async <Request, Response>(
   path: string,
   path: string,
   body: Request
   body: Request
 ): Promise<Response> => {
 ): Promise<Response> => {
   const data = options("PUT");
   const data = options("PUT");
   data.body = JSON.stringify(body);
   data.body = JSON.stringify(body);
-  return fetch(backend(path), data).then((res) =>
-    res.status === 200
-      ? res.json()
-      : res.json().then((err) => {
-          throw err;
-        })
-  );
+  const response = await fetch(backend(path), data);
+  const res: Response = await response.json();
+  return res;
 };
 };
 
 
 export const download = (path: string, name: string) => {
 export const download = (path: string, name: string) => {