|
@@ -1,10 +1,10 @@
|
|
import {Button, message, Modal} from 'antd';
|
|
import {Button, message, Modal} from 'antd';
|
|
import React, {useEffect, useState} from 'react';
|
|
import React, {useEffect, useState} from 'react';
|
|
-import { PageHeaderWrapper } from '@ant-design/pro-layout';
|
|
|
|
-import { useSingleState } from 'nice-hooks';
|
|
|
|
|
|
+import {PageHeaderWrapper} from '@ant-design/pro-layout';
|
|
|
|
+import {useSingleState} from 'nice-hooks';
|
|
import Quill from '@/pages/Memory/components/Quill';
|
|
import Quill from '@/pages/Memory/components/Quill';
|
|
import UpdateForm from '@/pages/Memory/components/UpdateForm';
|
|
import UpdateForm from '@/pages/Memory/components/UpdateForm';
|
|
-import { TableListItem } from '../MemoryList/data.d';
|
|
|
|
|
|
+import {TableListItem} from '../MemoryList/data.d';
|
|
import service from './service';
|
|
import service from './service';
|
|
import styles from './index.less';
|
|
import styles from './index.less';
|
|
import {ExclamationCircleOutlined} from "@ant-design/icons/lib";
|
|
import {ExclamationCircleOutlined} from "@ant-design/icons/lib";
|
|
@@ -23,8 +23,9 @@ interface State {
|
|
|
|
|
|
const TableList: React.FC<{}> = () => {
|
|
const TableList: React.FC<{}> = () => {
|
|
const [btnDisable, setBtnDisable] = useState(false);
|
|
const [btnDisable, setBtnDisable] = useState(false);
|
|
|
|
+ let counting = false;
|
|
|
|
|
|
- const { confirm } = Modal;
|
|
|
|
|
|
+ const {confirm} = Modal;
|
|
|
|
|
|
const [state, setState] = useSingleState<State>({
|
|
const [state, setState] = useSingleState<State>({
|
|
remindCount: 0,
|
|
remindCount: 0,
|
|
@@ -48,23 +49,31 @@ const TableList: React.FC<{}> = () => {
|
|
* @param fields
|
|
* @param fields
|
|
*/
|
|
*/
|
|
const countRemind = async () => {
|
|
const countRemind = async () => {
|
|
|
|
+ // 如果上一个查询还没有结束,则直接返回
|
|
|
|
+ console.log(counting);
|
|
|
|
+ if (counting) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ counting = true;
|
|
const hide = message.loading('正在查询');
|
|
const hide = message.loading('正在查询');
|
|
try {
|
|
try {
|
|
const res = await service.countRemind({});
|
|
const res = await service.countRemind({});
|
|
hide();
|
|
hide();
|
|
if (res.success) {
|
|
if (res.success) {
|
|
- setState({ remindCount: parseInt(res.data, 10) });
|
|
|
|
|
|
+ setState({remindCount: parseInt(res.data, 10)});
|
|
}
|
|
}
|
|
|
|
+ counting = false;
|
|
} catch (error) {
|
|
} catch (error) {
|
|
hide();
|
|
hide();
|
|
message.error('查询异常!');
|
|
message.error('查询异常!');
|
|
|
|
+ counting = false;
|
|
}
|
|
}
|
|
};
|
|
};
|
|
/**
|
|
/**
|
|
* 进入统计页面
|
|
* 进入统计页面
|
|
*/
|
|
*/
|
|
const changStepMain = () => {
|
|
const changStepMain = () => {
|
|
- setState({ step: Step.MAIN });
|
|
|
|
|
|
+ setState({step: Step.MAIN});
|
|
countRemind();
|
|
countRemind();
|
|
};
|
|
};
|
|
/**
|
|
/**
|
|
@@ -75,8 +84,8 @@ const TableList: React.FC<{}> = () => {
|
|
// 只要有返回值,就使按钮可见
|
|
// 只要有返回值,就使按钮可见
|
|
setBtnDisable(false);
|
|
setBtnDisable(false);
|
|
if (res.success) {
|
|
if (res.success) {
|
|
- setState({ showBack: false });
|
|
|
|
- setMemory({ ...memory, ...res.data });
|
|
|
|
|
|
+ setState({showBack: false});
|
|
|
|
+ setMemory({...memory, ...res.data});
|
|
} else {
|
|
} else {
|
|
changStepMain();
|
|
changStepMain();
|
|
}
|
|
}
|
|
@@ -84,26 +93,9 @@ const TableList: React.FC<{}> = () => {
|
|
|
|
|
|
const memorySuccess = async (factorInt: number) => {
|
|
const memorySuccess = async (factorInt: number) => {
|
|
setBtnDisable(true);
|
|
setBtnDisable(true);
|
|
- memoryRes(await service.memorySuccess({ id: memory.id, factor: factorInt }));
|
|
|
|
|
|
+ memoryRes(await service.memorySuccess({id: memory.id, factor: factorInt}));
|
|
};
|
|
};
|
|
|
|
|
|
- useEffect(() => {
|
|
|
|
- countRemind();
|
|
|
|
- setTimeout(() => {
|
|
|
|
- countRemind();
|
|
|
|
- }, 1000 * 60 * 60); // 每隔一个小时查询一次
|
|
|
|
-
|
|
|
|
- document.onkeydown = (ev) => {
|
|
|
|
- if (ev.key === ' ' && state.step === Step.MEMORY) {
|
|
|
|
- ev.preventDefault(); // 关闭浏览器快捷键
|
|
|
|
- if (state.showBack === false) {
|
|
|
|
- setState({ showBack: true });
|
|
|
|
- } else {
|
|
|
|
- memorySuccess(2);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
- }, []);
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* 清空memory
|
|
* 清空memory
|
|
@@ -119,7 +111,7 @@ const TableList: React.FC<{}> = () => {
|
|
* 每次修改step,都关闭背面
|
|
* 每次修改step,都关闭背面
|
|
*/
|
|
*/
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
- setState({ showBack: false });
|
|
|
|
|
|
+ setState({showBack: false});
|
|
clearMemory();
|
|
clearMemory();
|
|
}, [state.step]);
|
|
}, [state.step]);
|
|
|
|
|
|
@@ -131,7 +123,7 @@ const TableList: React.FC<{}> = () => {
|
|
const findNextLine = async () => {
|
|
const findNextLine = async () => {
|
|
const res = await service.findNext({});
|
|
const res = await service.findNext({});
|
|
if (res.success) {
|
|
if (res.success) {
|
|
- setMemory({ ...memory, ...res.data });
|
|
|
|
|
|
+ setMemory({...memory, ...res.data});
|
|
} else {
|
|
} else {
|
|
changStepMain();
|
|
changStepMain();
|
|
}
|
|
}
|
|
@@ -145,24 +137,54 @@ const TableList: React.FC<{}> = () => {
|
|
message.info('已经复习完了哟!');
|
|
message.info('已经复习完了哟!');
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- setState({ step: Step.MEMORY });
|
|
|
|
|
|
+ setState({step: Step.MEMORY});
|
|
await findNextLine();
|
|
await findNextLine();
|
|
};
|
|
};
|
|
|
|
|
|
const changStepAdd = () => {
|
|
const changStepAdd = () => {
|
|
- setState({ step: Step.ADD });
|
|
|
|
|
|
+ setState({step: Step.ADD});
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
+ countRemind();
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ countRemind();
|
|
|
|
+ }, 1000 * 60 * 60); // 每隔一个小时查询一次
|
|
|
|
+
|
|
|
|
+ document.onkeydown = (ev) => {
|
|
|
|
+ if (ev.key === ' ' && state.step === Step.MEMORY) {
|
|
|
|
+ ev.preventDefault(); // 关闭浏览器快捷键
|
|
|
|
+ if (state.showBack === false) {
|
|
|
|
+ setState({showBack: true});
|
|
|
|
+ } else {
|
|
|
|
+ memorySuccess(2);
|
|
|
|
+ }
|
|
|
|
+ } else if (ev.key === ' ' && state.step === Step.MAIN) {
|
|
|
|
+ // 如果待复习大于0,则直接进去
|
|
|
|
+ if (state.remindCount > 0) {
|
|
|
|
+ changStepMemory();
|
|
|
|
+ } else {
|
|
|
|
+ // 刷新一下,再判断是否应该去复习
|
|
|
|
+ countRemind();
|
|
|
|
+ if (state.remindCount > 0) {
|
|
|
|
+ changStepMemory();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ }, []);
|
|
|
|
+
|
|
return (
|
|
return (
|
|
<PageHeaderWrapper title={false}>
|
|
<PageHeaderWrapper title={false}>
|
|
{state.step === Step.MAIN ? (
|
|
{state.step === Step.MAIN ? (
|
|
<div>
|
|
<div>
|
|
<div>待复习: {state.remindCount}</div>
|
|
<div>待复习: {state.remindCount}</div>
|
|
- <p />
|
|
|
|
|
|
+ <p/>
|
|
<Button type="primary" size="large" onClick={changStepMemory}>
|
|
<Button type="primary" size="large" onClick={changStepMemory}>
|
|
复习
|
|
复习
|
|
</Button>
|
|
</Button>
|
|
- <p />
|
|
|
|
|
|
+ <p/>
|
|
<Button type="primary" size="large" onClick={changStepAdd}>
|
|
<Button type="primary" size="large" onClick={changStepAdd}>
|
|
添加
|
|
添加
|
|
</Button>
|
|
</Button>
|
|
@@ -172,13 +194,15 @@ const TableList: React.FC<{}> = () => {
|
|
{state.step === Step.MEMORY ? (
|
|
{state.step === Step.MEMORY ? (
|
|
<div>
|
|
<div>
|
|
问题:
|
|
问题:
|
|
- <p />
|
|
|
|
- <Quill readonly onChange={() => {}} value={memory.front} />
|
|
|
|
- <p />
|
|
|
|
|
|
+ <p/>
|
|
|
|
+ <Quill readonly onChange={() => {
|
|
|
|
+ }} value={memory.front}/>
|
|
|
|
+ <p/>
|
|
{state.showBack ? (
|
|
{state.showBack ? (
|
|
<div>
|
|
<div>
|
|
- <Quill readonly onChange={() => {}} value={memory.back} />
|
|
|
|
- <p />
|
|
|
|
|
|
+ <Quill readonly onChange={() => {
|
|
|
|
+ }} value={memory.back}/>
|
|
|
|
+ <p/>
|
|
<div className={styles.divBottom}>
|
|
<div className={styles.divBottom}>
|
|
<Button
|
|
<Button
|
|
type="primary"
|
|
type="primary"
|
|
@@ -219,7 +243,7 @@ const TableList: React.FC<{}> = () => {
|
|
>
|
|
>
|
|
搁置
|
|
搁置
|
|
</Button>
|
|
</Button>
|
|
- <p />
|
|
|
|
|
|
+ <p/>
|
|
<div>
|
|
<div>
|
|
<Button
|
|
<Button
|
|
type="primary"
|
|
type="primary"
|
|
@@ -247,7 +271,7 @@ const TableList: React.FC<{}> = () => {
|
|
onClick={async () => {
|
|
onClick={async () => {
|
|
confirm({
|
|
confirm({
|
|
title: '确定删除吗?',
|
|
title: '确定删除吗?',
|
|
- icon: <ExclamationCircleOutlined />,
|
|
|
|
|
|
+ icon: <ExclamationCircleOutlined/>,
|
|
content: '删除后无法恢复',
|
|
content: '删除后无法恢复',
|
|
okText: '确定',
|
|
okText: '确定',
|
|
okType: 'danger',
|
|
okType: 'danger',
|
|
@@ -264,7 +288,7 @@ const TableList: React.FC<{}> = () => {
|
|
删除
|
|
删除
|
|
</Button>
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
- <p />
|
|
|
|
|
|
+ <p/>
|
|
<div>
|
|
<div>
|
|
<Button
|
|
<Button
|
|
type="primary"
|
|
type="primary"
|
|
@@ -291,7 +315,7 @@ const TableList: React.FC<{}> = () => {
|
|
<Button
|
|
<Button
|
|
type="primary"
|
|
type="primary"
|
|
onClick={() => {
|
|
onClick={() => {
|
|
- setState({ showBack: true });
|
|
|
|
|
|
+ setState({showBack: true});
|
|
}}
|
|
}}
|
|
>
|
|
>
|
|
显示答案
|
|
显示答案
|