import React, { Component } from 'react'; import './index.less'; import Page from '@src/containers/Page'; import Assets from '@src/components/Assets'; import { getMap, formatDate } from '@src/services/Tools'; import { QuestionType } from '../../../../Constant'; import { My } from '../../../stores/my'; const QuestionTypeMap = getMap(QuestionType, 'value', 'label'); export default class extends Page { initState() { this.today = formatDate(new Date(), 'YYYY-MM-DD'); return { list: [], }; } initData() { My.listSearchHistory() .then(result => { const map = {}; const dateList = []; result.forEach((row) => { const date = formatDate(row.createTime, 'YYYY-MM-DD'); if (!map[date]) { map[date] = { date, list: [] }; dateList.push(date); } const item = map[date]; item.list.push(row); }); const list = dateList.map(row => { return map[row]; }); this.setState({ list }); }); } clearHistory(date) { My.clearSearchHistory(date) .then(() => { this.refresh(); }); } renderView() { const { list = [] } = this.state; return (
题库 > 浏览记录
{list.map(item => { if (item.date === this.today) item.today = true; return this.clearHistory(item.date)} />; })}
); } } class DayList extends Component { render() { const { data = {}, onClear } = this.props; return (
{data.today ? '今天' : data.date} onClear()}> 清空记录
{data.list.map(item => { return { }} />; })}
); } } class LogItem extends Component { render() { const { data, onClick } = this.props; return (
{QuestionTypeMap[data.question.questionType]} onClick()}>{data.questionNo.title} {data.question.description}
); } }