forked from Gitlink/forgeplus-react
246 lines
6.0 KiB
TypeScript
Executable File
246 lines
6.0 KiB
TypeScript
Executable File
import { Effect, Reducer, Subscription } from 'umi';
|
|
import {
|
|
getDisciplines,
|
|
getItemBanks,
|
|
setPrivate,
|
|
setPublic,
|
|
handleDelete,
|
|
startExperience,
|
|
cancel,
|
|
getBasketList,
|
|
select,
|
|
basketDelete,
|
|
unselectAll,
|
|
examUnselectAll,
|
|
addKnowledge,
|
|
editProblemset,
|
|
addProblemset,
|
|
getEditData,
|
|
getGroupList,
|
|
getTeachGroupData
|
|
} from '@/service/problemset';
|
|
import { formatCourseOptions } from './util';
|
|
|
|
export interface IBasketData {
|
|
completion_questions_count: number;
|
|
judgement_questions_count: number;
|
|
multiple_questions_count: number;
|
|
practical_questions_count: number;
|
|
program_questions_count: number;
|
|
single_questions_count: number;
|
|
subjective_questions_count: number;
|
|
}
|
|
|
|
interface IEditData {
|
|
analysis: string;
|
|
choices: { choice_text: string, is_answer: boolean }[];
|
|
difficulty: number;
|
|
discipline: { id: number; name: string; };
|
|
id: number;
|
|
item_type: string;
|
|
name: string;
|
|
sub_discipline: { id: number; name: string };
|
|
tag_disciplines: { id: number, name: string }[];
|
|
standard_answer: { position: number, answer_text: string[] }[];
|
|
is_ordered: boolean;
|
|
answer_texts: string[];
|
|
item_banks_group_id: { id: number, name: string }[];
|
|
}
|
|
|
|
interface IGroup {
|
|
id: number;
|
|
name: string;
|
|
joined: boolean;
|
|
}
|
|
|
|
interface IGroupData {
|
|
item_banks_groups: IGroup[];
|
|
}
|
|
|
|
export interface ProblemsetModelState {
|
|
disciplinesData: any;
|
|
courseOptions: any[];
|
|
basketData: IBasketData;
|
|
editData: IEditData;
|
|
groupData: IGroupData;
|
|
teachGroupData: any;
|
|
actionTabs: { key: string; params: any };
|
|
}
|
|
|
|
export interface ProblemsetModelType {
|
|
namespace: 'problemset';
|
|
state: ProblemsetModelState;
|
|
effects: {
|
|
getDisciplines: Effect;
|
|
getEditDisciplines: Effect;
|
|
getItemBanks: Effect;
|
|
getGroupData: Effect;
|
|
setActionTabs: Effect;
|
|
setPrivate: Effect;
|
|
setPublic: Effect;
|
|
handleDelete: Effect;
|
|
startExperience: Effect;
|
|
cancel: Effect;
|
|
getBasketList: Effect;
|
|
select: Effect;
|
|
basketDelete: Effect;
|
|
unselectAll: Effect;
|
|
examUnselectAll: Effect;
|
|
addKnowledge: Effect;
|
|
editProblemset: Effect;
|
|
addProblemset: Effect;
|
|
getEditData: Effect;
|
|
getTeachGroupData: Effect;
|
|
};
|
|
reducers: {
|
|
save: Reducer<ProblemsetModelState>;
|
|
};
|
|
subscriptions: { setup: Subscription };
|
|
}
|
|
|
|
const ProblemsetModel: ProblemsetModelType = {
|
|
namespace: 'problemset',
|
|
state: {
|
|
disciplinesData: undefined,
|
|
courseOptions: [],
|
|
basketData: undefined,
|
|
editData: undefined,
|
|
groupData: undefined,
|
|
teachGroupData: undefined,
|
|
actionTabs: {
|
|
key: '',
|
|
params: {},
|
|
},
|
|
},
|
|
effects: {
|
|
*getDisciplines({ payload }, { call, put }) {
|
|
const response = yield call(getDisciplines, payload);
|
|
yield put({
|
|
type: 'save',
|
|
payload: { disciplinesData: { ...response } },
|
|
});
|
|
|
|
return response;
|
|
},
|
|
*getEditDisciplines({ payload }, { call, put }) {
|
|
const response = yield call(getDisciplines, payload);
|
|
const disciplines = response?.disciplines;
|
|
const courseOptions = formatCourseOptions(disciplines);
|
|
yield put({
|
|
type: 'save',
|
|
payload: {
|
|
courseOptions,
|
|
disciplinesData: { ...response }
|
|
},
|
|
});
|
|
|
|
return response;
|
|
},
|
|
*getBasketList({ payload }, { call, put }) {
|
|
const response = yield call(getBasketList, payload);
|
|
yield put({
|
|
type: 'save',
|
|
payload: { basketData: { ...response } },
|
|
});
|
|
|
|
return response;
|
|
},
|
|
*getTeachGroupData({ payload }, { call, put }) {
|
|
const response = yield call(getTeachGroupData, payload);
|
|
yield put({
|
|
type: 'save',
|
|
payload: { teachGroupData: { ...response } },
|
|
});
|
|
|
|
return response;
|
|
},
|
|
*getEditData({ payload }, { call, put }) {
|
|
const response = yield call(getEditData, payload);
|
|
|
|
yield put({
|
|
type: 'save',
|
|
payload: { editData: { ...response } },
|
|
});
|
|
|
|
return response;
|
|
},
|
|
*getGroupData({ payload }, { call, put }) {
|
|
const response = yield call(getGroupList, payload);
|
|
|
|
yield put({
|
|
type: 'save',
|
|
payload: { groupData: { ...response } },
|
|
});
|
|
|
|
return response;
|
|
},
|
|
*getItemBanks({ payload }, { call, put }) {
|
|
return yield call(getItemBanks, payload);
|
|
},
|
|
*setPrivate({ payload }, { call, put }) {
|
|
return yield call(setPrivate, payload);
|
|
},
|
|
*setPublic({ payload }, { call, put }) {
|
|
return yield call(setPublic, payload);
|
|
},
|
|
*handleDelete({ payload }, { call, put }) {
|
|
return yield call(handleDelete, payload);
|
|
},
|
|
*startExperience({ payload }, { call, put }) {
|
|
return yield call(startExperience, payload);
|
|
},
|
|
*cancel({ payload }, { call, put }) {
|
|
return yield call(cancel, payload);
|
|
},
|
|
*select({ payload }, { call, put }) {
|
|
return yield call(select, payload);
|
|
},
|
|
*examUnselectAll({ payload }, { call, put }) {
|
|
return yield call(examUnselectAll, payload);
|
|
},
|
|
*basketDelete({ payload }, { call, put }) {
|
|
return yield call(basketDelete, payload);
|
|
},
|
|
*unselectAll({ payload }, { call, put }) {
|
|
return yield call(unselectAll, payload);
|
|
},
|
|
*addKnowledge({ payload }, { call, put }) {
|
|
return yield call(addKnowledge, payload);
|
|
},
|
|
*editProblemset({ payload }, { call, put }) {
|
|
return yield call(editProblemset, payload);
|
|
},
|
|
*addProblemset({ payload }, { call, put }) {
|
|
return yield call(addProblemset, payload);
|
|
},
|
|
*setActionTabs({ payload }, { call, put }) {
|
|
yield put({
|
|
type: 'save',
|
|
payload: { actionTabs: { ...payload } },
|
|
});
|
|
},
|
|
},
|
|
reducers: {
|
|
save(state, action) {
|
|
return {
|
|
...state,
|
|
...action.payload,
|
|
};
|
|
},
|
|
},
|
|
subscriptions: {
|
|
setup({ dispatch, history }) {
|
|
// console.log("subscriptions:", dispatch, history)
|
|
return history.listen(({ pathname }) => {
|
|
if (pathname === '/') {
|
|
dispatch({
|
|
type: 'query',
|
|
});
|
|
}
|
|
});
|
|
},
|
|
},
|
|
};
|
|
|
|
export default ProblemsetModel;
|