tianyunperfect %!s(int64=5) %!d(string=hai) anos
pai
achega
2750d5c8ef
Modificáronse 2 ficheiros con 60 adicións e 74 borrados
  1. 59 73
      src/pages/Memory/index.tsx
  2. 1 1
      src/pages/document.ejs

+ 59 - 73
src/pages/Memory/index.tsx

@@ -1,12 +1,12 @@
-import {Button, message} from 'antd';
-import React, {useEffect} from 'react';
-import {PageHeaderWrapper} from '@ant-design/pro-layout';
-import {useSingleState} from 'nice-hooks';
-import Quill from "@/pages/Memory/components/Quill";
-import {TableListItem} from '../MemoryList/data.d';
+import { Button, message } from 'antd';
+import React, { useEffect } from 'react';
+import { PageHeaderWrapper } from '@ant-design/pro-layout';
+import { useSingleState } from 'nice-hooks';
+import Quill from '@/pages/Memory/components/Quill';
+import UpdateForm from '@/pages/Memory/components/UpdateForm';
+import { TableListItem } from '../MemoryList/data.d';
 import service from './service';
-import UpdateForm from "@/pages/Memory/components/UpdateForm";
-import styles from './index.less'
+import styles from './index.less';
 
 enum Step {
   MAIN = 0,
@@ -28,17 +28,16 @@ const TableList: React.FC<{}> = () => {
   });
 
   const [memory, setMemory] = useSingleState<TableListItem>({
-    back: "",
-    front: "",
+    back: '',
+    front: '',
     id: undefined,
     period: 0,
     remindTime: new Date(),
-    tag: "",
-    updateTime: "",
-    userId: 0
+    tag: '',
+    updateTime: '',
+    userId: 0,
   });
 
-
   /**
    * 查询用户待提醒数量
    * @param fields
@@ -49,31 +48,53 @@ const TableList: React.FC<{}> = () => {
       const res = await service.countRemind({});
       hide();
       if (res.success) {
-        setState({remindCount: parseInt(res.data, 10)});
+        setState({ remindCount: parseInt(res.data, 10) });
       }
     } catch (error) {
       hide();
       message.error('查询异常!');
     }
   };
+  /**
+   * 进入统计页面
+   */
+  const changStepMain = () => {
+    setState({ step: Step.MAIN });
+    countRemind();
+  };
+  /**
+   * 处理返回值
+   * @param res
+   */
+  const memoryRes = (res: any) => {
+    if (res.success) {
+      setState({ showBack: false });
+      setMemory({ ...memory, ...res.data });
+    } else {
+      changStepMain();
+    }
+  };
+
+  const memorySuccess = async (factorInt: number) => {
+    memoryRes(await service.memorySuccess({ id: memory.id, factor: factorInt }));
+  };
+
   useEffect(() => {
     countRemind();
     setTimeout(() => {
       countRemind();
-    }, 1000 * 60 * 60)  // 每隔一个小时查询一次
+    }, 1000 * 60 * 60); // 每隔一个小时查询一次
 
-    document.onkeydown = (ev)=> {
+    document.onkeydown = (ev) => {
       if (ev.key === ' ' && state.step === Step.MEMORY) {
         ev.preventDefault(); // 关闭浏览器快捷键
-        if (state.showBack == false) {
-          setState({showBack: true});
+        if (state.showBack === false) {
+          setState({ showBack: true });
         } else {
           memorySuccess(2);
         }
-
       }
-
-    }
+    };
   }, []);
 
   /**
@@ -90,7 +111,7 @@ const TableList: React.FC<{}> = () => {
    * 每次修改step,都关闭背面
    */
   useEffect(() => {
-    setState({showBack: false});
+    setState({ showBack: false });
     clearMemory();
   }, [state.step]);
 
@@ -98,18 +119,11 @@ const TableList: React.FC<{}> = () => {
     // console.log(state)
     // console.log(memory)
   });
-  /**
-   * 进入统计页面
-   */
-  const changStepMain = () => {
-    setState({step: Step.MAIN});
-    countRemind();
-  };
 
   const findNextLine = async () => {
     const res = await service.findNext({});
     if (res.success) {
-      setMemory({...memory, ...res.data});
+      setMemory({ ...memory, ...res.data });
     } else {
       changStepMain();
     }
@@ -123,30 +137,12 @@ const TableList: React.FC<{}> = () => {
       message.info('已经复习完了哟!');
       return;
     }
-    setState({step: Step.MEMORY});
+    setState({ step: Step.MEMORY });
     await findNextLine();
   };
-  /**
-   * 处理返回值
-   * @param res
-   */
-  const memoryRes = (res: any) => {
-    if (res.success) {
-      setState({showBack: false});
-      setMemory({...memory, ...res.data});
-    } else {
-      changStepMain();
-    }
-
-  }
-  const memorySuccess = async (factorInt: number) => {
-    memoryRes(await service.memorySuccess({id: memory.id, factor: factorInt}));
-
-  };
-
 
   const changStepAdd = () => {
-    setState({step: Step.ADD});
+    setState({ step: Step.ADD });
   };
 
   return (
@@ -154,11 +150,11 @@ const TableList: React.FC<{}> = () => {
       {state.step === Step.MAIN ? (
         <div>
           <div>待复习: {state.remindCount}</div>
-          <p/>
+          <p />
           <Button type="primary" size="large" onClick={changStepMemory}>
             复习
           </Button>
-          <p/>
+          <p />
           <Button type="primary" size="large" onClick={changStepAdd}>
             添加
           </Button>
@@ -168,21 +164,13 @@ const TableList: React.FC<{}> = () => {
       {state.step === Step.MEMORY ? (
         <div>
           问题:
-          <p/>
-          <Quill
-            readonly
-            onChange={() => {
-            }}
-            value={memory.front}/>
-          <p/>
+          <p />
+          <Quill readonly onChange={() => {}} value={memory.front} />
+          <p />
           {state.showBack ? (
             <div>
-              <Quill
-                readonly
-                onChange={() => {
-                }}
-                value={memory.back}/>
-              <p/>
+              <Quill readonly onChange={() => {}} value={memory.back} />
+              <p />
               <div className={styles.divBottom}>
                 <Button
                   type="primary"
@@ -219,7 +207,7 @@ const TableList: React.FC<{}> = () => {
                 >
                   搁置
                 </Button>
-                <p/>
+                <p />
                 <div>
                   <Button
                     type="primary"
@@ -248,7 +236,7 @@ const TableList: React.FC<{}> = () => {
                     删除
                   </Button>
                 </div>
-                <p/>
+                <p />
                 <div>
                   <Button
                     type="primary"
@@ -269,14 +257,13 @@ const TableList: React.FC<{}> = () => {
                   </Button>
                 </div>
               </div>
-
             </div>
           ) : (
             <div>
               <Button
                 type="primary"
                 onClick={() => {
-                  setState({showBack: true});
+                  setState({ showBack: true });
                 }}
               >
                 显示答案(空格)
@@ -292,10 +279,9 @@ const TableList: React.FC<{}> = () => {
             changStepMain();
           }}
           modalVisible={state.step === Step.ADD}
-          values={memory}>
-        </UpdateForm>
+          values={memory}
+        />
       ) : null}
-
     </PageHeaderWrapper>
   );
 };

+ 1 - 1
src/pages/document.ejs

@@ -21,7 +21,7 @@
       name="viewport"
       content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"
     />
-    <title>Ant Design Pro</title>
+    <title>念念不忘</title>
     <link rel="icon" href="/favicon.png" type="image/x-icon" />
   </head>
   <body>