import { Button, message } from 'antd'; import React, { useEffect } from 'react'; import { PageHeaderWrapper } from '@ant-design/pro-layout'; import { useSingleState } from 'nice-hooks'; import ReactQuill from 'react-quill'; import 'react-quill/dist/quill.snow.css'; import { Memory } from './data.d'; import service from './service'; enum Step { MAIN = 0, MEMORY = 1, ADD = 2, } interface State { remindCount: number; step: Step; showBack?: boolean; } const TableList: React.FC<{}> = () => { const [state, setState] = useSingleState({ remindCount: 0, step: Step.MAIN, // 0 主页,1 复习,2 添加 showBack: false, }); const [memory, setMemory] = useSingleState({ id: null, userId: null, front: '', back: '', tag: '', }); /** * 查询用户待提醒数量 * @param fields */ const countRemind = async () => { const hide = message.loading('正在查询'); try { const res = await service.countRemind({}); hide(); if (res.success) { setState({ remindCount: parseInt(res.data, 10) }); return true; } return false; } catch (error) { hide(); message.error('查询异常!'); return false; } }; useEffect(() => { countRemind(); }, []); useEffect(() => { // 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 }); } else { changStepMain(); } }; /** * 初次进入复习页面 */ const changStepMemory = async () => { if (state.remindCount <= 0) { message.info('已经复习完了哟!'); return; } setState({ step: Step.MEMORY }); await findNextLine(); }; const memorySuccess = async (factorInt: number) => { const res = await service.memorySuccess({ id: memory.id, factor: factorInt }); if (res.success) { setMemory({ ...memory, ...res.data }); } else { changStepMain(); } }; const changStepAdd = () => { setState({ step: Step.ADD }); }; /** * 清空memory */ const clearMemory = () => { setMemory({ id: null, front: '', back: '', }); }; return ( {state.step === Step.MAIN ? (
待复习: {state.remindCount}

) : null} {state.step === Step.MEMORY ? (
问题

{state.showBack ? (

) : (
)}
) : null} {state.step === Step.ADD ? (

正面

{ setMemory({ front: value }); }} />

反面

{ setMemory({ back: value }); }} />

) : null} ); }; export default TableList;