123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- import { getMap, formatTreeData } from '@src/services/Tools';
- import detail from './detail';
- import search from './search';
- import searchHistory from './searchHistory';
- import { CourseModule } from '../../../Constant';
- import { Main } from '../../stores/main';
- export default [detail, search, searchHistory];
- export function refreshQuestionType(compontent, subject, questionType, { all, needSentence, allSubject, excludeAwa }) {
- return Main.getExercise().then(result => {
- const list = result.filter(row => (needSentence ? true : row.isExamination)).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) && (excludeAwa ? row.extend !== 'awa' : true));
- if (all) {
- compontent.questionSubjectSelect.forEach(row => {
- row.children.unshift({
- title: '全部',
- key: '',
- });
- });
- compontent.questionSubjectSelect.unshift({
- title: '全部',
- key: '',
- });
- }
- compontent.setState({
- questionSubjectSelect: compontent.questionSubjectSelect,
- questionSubjectMap: compontent.questionSubjectMap,
- });
- return {
- questionTypes: questionType || (subject ? compontent.questionSubjectMap[subject].map(row => row.key).filter(row => row) : null),
- };
- });
- }
- export function refreshStruct(compontent, questionTypes, module, one, two, { all }) {
- 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;
- 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);
- }
- 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');
- const oneSelect = tree;
- const twoSelectMap = getMap(tree, 'key', 'children');
- if (all) {
- oneSelect.forEach(row => {
- row.children.unshift({
- title: '全部',
- key: '',
- });
- });
- oneSelect.unshift({
- title: '全部',
- key: '',
- });
- }
- compontent.setState({ oneSelect, twoSelectMap });
- return {
- structIds,
- courseModules,
- };
- });
- default:
- return Promise.resolve({});
- }
- }
|