import React from 'react'; import './index.less'; import Page from '@src/containers/Page'; import { formatDate, formatSeconds, formatPercent } from '@src/services/Tools'; import Icon from '../../../components/Icon'; import { My } from '../../../stores/my'; export default class extends Page { init() { } initData() { My.getStudyTotal().then(total => { this.setState({ total }); }); My.getStudyWeek(0).then(latest => { const diff = latest.time - latest.avgTime; const diffPercent = diff > 0 ? formatPercent(latest.time - latest.avgTime, latest.avgTime, true) : formatPercent(latest.avgTime - latest.time, latest.avgTime, true); this.setState({ latest, diff, diffPercent }); My.getStudyWeek(1).then(last => { const diffLast = latest.time - last.time; const diffLastPercent = diffLast > 0 ? formatPercent(latest.time - last.time, last.time, true) : formatPercent(last.time - latest.time, last.time, true); this.setState({ last, diffLast, diffLastPercent }); }); }); } renderView() { const { total = {}, latest = {}, diff = 0, diffPercent = 0, diffLast = 0, diffLastPercent = 0 } = this.state; return (