123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309 |
- import { getMap, formatTreeData } from '@src/services/Tools';
- import main from './main';
- import course from './course';
- import tools from './tools';
- import error from './error';
- import note from './note';
- import answer from './answer';
- import report from './report';
- import data from './data';
- import collect from './collect';
- import order from './order';
- import message from './message';
- import { TextbookMinYear, CourseModule } from '../../../Constant';
- import { Main } from '../../stores/main';
- export default [main, course, tools, error, note, answer, report, data, collect, order, message];
- export function refreshQuestionType(compontent, subject, questionType, { all, needSentence, allSubject, onlyPreview }) {
- return Main.getExercise().then(result => {
- const list = result.filter(row => (needSentence ? true : row.isExamination)).filter(row => (onlyPreview ? row.isData || ['ds', 'ps'].indexOf(row.extend) >= 0 : true)).map(row => {
- row.title = `${row.titleZh}${row.titleEn}`;
- row.key = row.extend;
- return row;
- });
- const tree = formatTreeData(list, 'id', 'title', 'parentId');
- compontent.questionSubjectMap = getMap(tree, 'key', 'children');
- compontent.questionSubjectSelect = tree.filter(row => row.level === 1 && (allSubject ? true : row.children.length > 1));
- if (all) {
- compontent.questionSubjectSelect.forEach(row => {
- if (row.children.length > 1) {
- row.children.unshift({
- title: '全部',
- key: '',
- });
- } else if (row.key === 'sentence') {
- row.children.unshift({
- title: '长难句',
- key: 'sentence',
- });
- }
- });
- compontent.questionSubjectSelect.unshift({
- title: '全部',
- key: '',
- });
- compontent.questionSubjectMap[''] = [{
- title: '全部',
- key: '',
- }];
- }
- if (questionType === subject) {
- questionType = null;
- }
- compontent.setState({
- questionSubjectSelect: compontent.questionSubjectSelect,
- questionSubjectMap: compontent.questionSubjectMap,
- });
- return {
- questionTypes: questionType || (subject ? compontent.questionSubjectMap[subject].map(row => row.key).filter(row => row) : null),
- selectSentence: subject === 'sentence',
- };
- });
- }
- export function refreshStruct(compontent, questionTypes, module, one, two, { all, needTextbook, needPreview, selectSentence }) {
- let oneSelectPlaceholder = '全部';
- let twoSelectPlaceholder = '全部';
- switch (module) {
- case 'exercise':
- return Main.getExerciseAll().then(result => {
- const tmp = result.filter(row => row.level > 2).map(row => {
- row.title = `${row.titleZh}`;
- row.key = `${row.titleEn}`;
- row.u = `${row.titleEn}${row.level}`;
- return row;
- });
- const idsMap = getMap(tmp, 'id', 'key');
- const map = {};
- tmp.forEach(row => {
- if (!map[row.key]) {
- map[row.key] = {
- title: row.title,
- key: row.key,
- structIds: [],
- parentId: row.level > 3 ? idsMap[row.parentId] : null,
- questionTypes: [],
- };
- }
- const item = map[row.key];
- item.structIds.push(row.id);
- if (item.questionTypes.indexOf(row.extend) < 0) {
- item.questionTypes.push(row.extend);
- }
- });
- let list = Object.values(map);
- if (questionTypes && questionTypes.length > 0) {
- list = list.filter(row => row.questionTypes.filter((v) => questionTypes.indexOf(v) >= 0).length);
- // 预习作业过滤
- if (needPreview) {
- const previewList = result.filter(row => row.level === 2).filter(row => questionTypes.indexOf(row.extend) >= 0).filter(row => row.isData || ['ds', 'ps'].indexOf(row.extend) >= 0);
- if (previewList.length === 0) needPreview = false;
- }
- }
- if (needPreview) {
- list.push({
- title: '预习作业',
- key: 'preview',
- id: 'preview',
- });
- CourseModule.forEach(row => {
- if (!row.hasPreview) return;
- list.push({
- title: row.label,
- key: row.value,
- parentId: 'preview',
- });
- });
- }
- let courseModules = null;
- let structIds = null;
- if (one === 'preview') {
- if (!two) {
- courseModules = CourseModule.map(row => row.value);
- } else {
- courseModules = [two];
- }
- } else if (one) {
- const resultMap = getMap(list, 'key', 'structIds');
- if (!two) {
- structIds = resultMap[one];
- } else {
- structIds = resultMap[two];
- }
- }
- const tree = formatTreeData(list, 'key', 'title', 'parentId');
- let oneSelect = tree;
- const twoSelectMap = getMap(tree, 'key', 'children');
- if (all) {
- oneSelect.forEach(row => {
- if (row.children.length > 1) {
- row.children.unshift({
- title: '全部',
- key: '',
- });
- } else if (row.children.length === 0) {
- row.children.unshift({
- title: row.title,
- key: '',
- });
- }
- });
- if (oneSelect.length > 1) {
- oneSelect.unshift({
- title: '全部',
- key: '',
- });
- } else if (oneSelect.length === 1) {
- oneSelectPlaceholder = null;
- }
- if (!one) {
- twoSelectMap[''] = [{
- title: '全部',
- key: '',
- }];
- }
- }
- if (one && twoSelectMap[one]) {
- if (twoSelectMap[one].length === 1) {
- twoSelectPlaceholder = null;
- } else if (twoSelectMap[one].length === 0 || !twoSelectMap[one]) {
- twoSelectMap[one] = [{
- title: '全部',
- key: '',
- }];
- }
- }
- if (selectSentence) {
- oneSelect = [{
- title: '千行长难句',
- key: '',
- }];
- twoSelectMap[''] = [{
- title: '千行长难句',
- key: '',
- }];
- oneSelectPlaceholder = null;
- twoSelectPlaceholder = '千行长难句';
- }
- compontent.setState({ oneSelect, twoSelectMap, oneSelectPlaceholder, twoSelectPlaceholder });
- return {
- structIds,
- courseModules,
- };
- });
- case 'examination':
- return Main.getExamination().then(result => {
- const list = result.map(row => {
- row.title = `${row.titleZh}${row.titleEn}`;
- row.key = `${row.id}`;
- return row;
- });
- if (needTextbook) {
- list.push({
- title: '数学机经',
- key: 'textbook',
- id: 'textbook',
- });
- list.push({
- title: '最新',
- key: 'latest',
- parentId: 'textbook',
- });
- const nowYear = new Date().getFullYear();
- for (let i = TextbookMinYear; i <= nowYear; i += 1) {
- list.push({
- title: i.toString(),
- key: i.toString(),
- parentId: 'textbook',
- });
- }
- }
- let latest = null;
- let year = null;
- let structIds = null;
- if (one === 'textbook') {
- if (!two) {
- latest = false;
- } else if (two === 'latest') {
- latest = true;
- } else {
- year = two;
- }
- } else if (one) {
- if (!two) {
- structIds = [Number(one)];
- } else {
- structIds = [Number(two)];
- }
- }
- const tree = formatTreeData(list, 'key', 'title', 'parentId');
- let oneSelect = tree;
- const twoSelectMap = getMap(tree, 'key', 'children');
- if (all) {
- oneSelect.forEach(row => {
- if (row.children.length > 1) {
- row.children.unshift({
- title: '全部',
- key: '',
- });
- } else if (row.children.length === 0) {
- row.children.unshift({
- title: row.title,
- key: '',
- });
- }
- });
- if (oneSelect.length > 1) {
- oneSelect.unshift({
- title: '全部',
- key: '',
- });
- } else if (oneSelect.length === 1) {
- oneSelectPlaceholder = null;
- }
- if (!one) {
- twoSelectMap[''] = [{
- title: '全部',
- key: '',
- }];
- }
- }
- if (one && twoSelectMap[one]) {
- if (twoSelectMap[one].length === 1) {
- twoSelectPlaceholder = null;
- } else if (twoSelectMap[one].length === 0 || !twoSelectMap[one]) {
- twoSelectMap[one] = [{
- title: '全部',
- key: '',
- }];
- }
- }
- if (selectSentence) {
- oneSelect = [{
- title: '千行长难句',
- key: '',
- }];
- twoSelectMap[''] = [{
- title: '千行长难句',
- key: '',
- }];
- oneSelectPlaceholder = null;
- twoSelectPlaceholder = null;
- }
- compontent.setState({ oneSelect, twoSelectMap, oneSelectPlaceholder, twoSelectPlaceholder });
- return {
- structIds,
- latest,
- year,
- };
- });
- default:
- return Promise.resolve({});
- }
- }
|