import React from 'react'; import './index.less'; import { Switch } from 'antd'; import Page from '@src/containers/Page'; import { getMap, formatDate } from '@src/services/Tools'; import UserAction from '../../../components/UserAction'; import Tabs from '../../../components/Tabs'; import Filter from '../../../components/Filter'; import Icon from '../../../components/Icon'; import { DataItem } from '../../../components/Item'; import UserTable from '../../../components/UserTable'; import UserPagination from '../../../components/UserPagination'; import { FeedbackErrorDataModal, FinishModal } from '../../../components/OtherModal'; import { DataType } from '../../../../Constant'; import { Main } from '../../../stores/main'; import { Course } from '../../../stores/course'; import { My } from '../../../stores/my'; import { User } from '../../../stores/user'; const dataHistoryColumns = [ { title: '更新时间', key: 'time', width: 120 }, { title: '位置', key: 'position', width: 120 }, { title: '原内容', key: 'originContent', width: 120 }, { title: '更改为', key: 'content', width: 120 }, { title: '更新至', key: 'version', width: 90 }, ]; export default class extends Page { initState() { const dataTypeSelect = DataType.map((row) => { return { title: row.label, key: row.value, }; }); dataTypeSelect.unshift({ title: '全部', key: '', }); return { tab: '', filterMap: {}, sortMap: {}, list: [], dataStructSelect: [], dataTypeSelect, // type: [ // { title: '长难句', key: '1', open: true, children: [{ key: '1', title: 'OG19 语法千行' }] }, // { title: '语文 Verbal', key: '2', open: true, children: [{ key: '1', title: 'OG19 语法千行' }] }, // { title: '数学 Quant', key: '3', open: true, children: [{ key: '1', title: 'OG19 语法千行' }] }, // ], }; } init() { Main.dataStruct().then(result => { const dataStructSelect = result.filter(row => row.level === 1).map(row => { return { title: `${row.titleZh}${row.titleEn}`, key: `${row.id}`, }; }); dataStructSelect.unshift({ title: '全部', key: '', }); const dataStructMap = getMap(dataStructSelect, 'key'); this.setState({ dataStructSelect, dataStructMap }); }); } initData() { const data = Object.assign(this.state, this.state.search); if (data.order) { data.sortMap = { [data.order]: data.direction }; } data.filterMap = this.state.search; this.setState(data); switch (data.tab) { case 'history': this.refreshHistory(); break; default: this.refreshData(); } } refreshData() { Course.listData(Object.assign({}, this.state.search)) .then(result => { this.setState({ list: result.list, total: result.total }); }); } refreshHistory() { let { all, dataId } = this.state; dataId = Number(dataId); if (!all) { Course.listData({ page: 1, size: 1000 }) .then(result => { this.dataMap = getMap(result.list, 'id'); const allIds = []; result.list.forEach(row => { if (allIds.indexOf(row.structId) >= 0) return; allIds.push(row.structId); }); all = allIds.map(row => { return { id: row, children: [] }; }); result.list.forEach(row => { const index = allIds.indexOf(row.structId); all[index].children.push(row); if (row.id === dataId) all[index].open = true; }); if (!dataId) { dataId = result.list[0].id; all[0].open = true; } this.refreshHistoryList(dataId); this.setState({ all }); }); } else if (dataId) { this.refreshHistoryList(dataId); } } refreshHistoryList(dataId) { Course.historyData({ dataId, page: 1, size: 1000 }) .then(result => { result.list = result.list.map(row => { row.time = formatDate(row.time, 'YYYY-MM-DD\nHH:mm:ss'); return row; }); this.setState({ item: this.dataMap[dataId], list: result.list, dataId }); }); } onTabChange(tab) { const data = { tab }; this.refreshQuery(data); } onFilter(key, value) { const { filterMap } = this.state; filterMap[key] = value; this.search(filterMap, false); this.initData(); } onChangePage(page) { this.search({ page }, false); this.initData(); } onSort(value) { const keys = Object.keys(value); // this.search({ order: keys.length ? keys.join('|') : null, direction: keys.length ? Object.values(value).join('|') : null }); const { sortMap } = this.state; const index = keys.length > 1 && sortMap[keys[0]] ? 1 : 0; this.search({ order: keys.length && value[keys[index]] ? keys[index] : null, direction: keys.length ? value[keys[index]] : null }); } onOpen(index) { const { all } = this.state; all[index].open = !all[index].open; this.setState({ all }); } onSelect(dataId) { this.search({ dataId }, false); this.initData(); } subscribe(dataId, subscribe) { User.needLogin() .then(() => { My.subscribeData(dataId, subscribe) .then(() => { this.refresh(); }); }); } renderView() { const { tab } = this.state; return (
千行课堂 > 资料列表
我的资料
this.onTabChange(key)} /> {this[`renderTab${tab}`]()}
); } renderTab() { const { list = [], total, page, sortMap, filterMap, dataStructSelect, dataTypeSelect } = this.state; return [ this.onFilter(key, value)} />, this.onSort(value)} />,
{list.map(item => { return ; })}
, total > 0 && list.length > 0 && ( this.onChangePage(p)} /> ), ]; } renderTabhistory() { const { all = [], dataId, item = {}, list = [], dataStructMap = {}, showFeedbackError, feedbackError, showFinish } = this.state; return [
{/* */}
,
{all.map((node, index) => { const struct = dataStructMap[node.id] || {}; return (
this.onOpen(index)}> {struct.title}
{node.open ? : }
{node.children.map(child => { return
this.onSelect(child.id)}>{child.title}
; })}
); })}
, this.setState({ showFeedbackError: false, feedbackError: {}, showFinish: true })} onCancel={() => this.setState({ showFeedbackError: false, feedbackError: {} })} />, this.setState({ showFinish: false })} />, ]; } }