|
@@ -1,5 +1,6 @@
|
|
|
import {
|
|
|
getExplainChildren,
|
|
|
+ getFillQuesitons,
|
|
|
getNewPage,
|
|
|
getTopicHead,
|
|
|
getElementId
|
|
@@ -11,6 +12,7 @@ const state = {
|
|
|
curDragElement: {},
|
|
|
curPageNo: 0,
|
|
|
pages: [],
|
|
|
+ topicNos: [],
|
|
|
cardConfig: {},
|
|
|
openElementEditDialog: false
|
|
|
};
|
|
@@ -25,6 +27,9 @@ const mutations = {
|
|
|
setPages(state, pages) {
|
|
|
state.pages = pages;
|
|
|
},
|
|
|
+ setTopicNos(state, topicNos) {
|
|
|
+ state.topicNos = topicNos;
|
|
|
+ },
|
|
|
setCardConfig(state, cardConfig) {
|
|
|
state.cardConfig = Object.assign({}, state.cardConfig, cardConfig);
|
|
|
},
|
|
@@ -40,6 +45,10 @@ const mutations = {
|
|
|
setOpenElementEditDialog(state, openElementEditDialog) {
|
|
|
state.openElementEditDialog = openElementEditDialog;
|
|
|
},
|
|
|
+ initTopicNos(state) {
|
|
|
+ state.topicNos = getPageTopicNos(state.pages);
|
|
|
+ console.log(state.topicNos);
|
|
|
+ },
|
|
|
initState(state) {
|
|
|
state.curElement = {};
|
|
|
state.curDragElement = {};
|
|
@@ -47,6 +56,7 @@ const mutations = {
|
|
|
state.pages = [];
|
|
|
state.cardConfig = {};
|
|
|
state.openElementEditDialog = false;
|
|
|
+ state.topicNos = [];
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -100,6 +110,19 @@ const fetchFirstSubjectiveTopicPositionInfo = pages => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+const getPageTopicNos = pages => {
|
|
|
+ let topicNos = [];
|
|
|
+ pages.forEach(page => {
|
|
|
+ page.columns.forEach(column => {
|
|
|
+ column.elements.forEach(element => {
|
|
|
+ if (element["topicNo"] && !topicNos.includes(element["topicNo"]))
|
|
|
+ topicNos.push(element["topicNo"]);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+ return topicNos;
|
|
|
+};
|
|
|
+
|
|
|
const fetchPageLastColumnPositionInfo = pages => {
|
|
|
return {
|
|
|
_pageNo: pages.length - 1,
|
|
@@ -157,6 +180,34 @@ const actions = {
|
|
|
} else {
|
|
|
dispatch("addElement", element);
|
|
|
}
|
|
|
+ } else if (element.type === "FILL_QUESTION") {
|
|
|
+ const positionInfos = fetchAllRelateParentElementPositionInfos(
|
|
|
+ element,
|
|
|
+ state.pages
|
|
|
+ );
|
|
|
+ if (positionInfos.length) {
|
|
|
+ // 删除所有相关选择题
|
|
|
+ positionInfos.reverse().forEach(pos => {
|
|
|
+ const elems =
|
|
|
+ state.pages[pos._pageNo].columns[pos._columnNo].elements;
|
|
|
+ elems.splice(pos._elementNo, 1);
|
|
|
+ });
|
|
|
+ // 创建新的选择题元素
|
|
|
+ const newElements = getFillQuesitons(
|
|
|
+ element,
|
|
|
+ state.cardConfig.columnNumber
|
|
|
+ );
|
|
|
+ const pos = positionInfos.pop();
|
|
|
+ newElements.forEach((newElement, index) => {
|
|
|
+ state.pages[pos._pageNo].columns[pos._columnNo].elements.splice(
|
|
|
+ pos._elementNo + index,
|
|
|
+ 0,
|
|
|
+ newElement
|
|
|
+ );
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ dispatch("addElement", element);
|
|
|
+ }
|
|
|
} else {
|
|
|
const positionInfos = fetchElementPositionInfos(element, state.pages);
|
|
|
if (positionInfos.length) {
|
|
@@ -182,8 +233,14 @@ const actions = {
|
|
|
}
|
|
|
|
|
|
const elements = state.pages[pos._pageNo].columns[pos._columnNo].elements;
|
|
|
- const preElements =
|
|
|
- element.type === "EXPLAIN" ? getExplainChildren(element) : [element];
|
|
|
+ let preElements = [];
|
|
|
+ if (element.type === "EXPLAIN") {
|
|
|
+ preElements = getExplainChildren(element);
|
|
|
+ } else if (element.type === "FILL_QUESTION") {
|
|
|
+ preElements = getFillQuesitons(element, state.cardConfig.columnNumber);
|
|
|
+ } else {
|
|
|
+ preElements = [element];
|
|
|
+ }
|
|
|
preElements.forEach(preElement => {
|
|
|
elements.push(preElement);
|
|
|
});
|
|
@@ -195,7 +252,10 @@ const actions = {
|
|
|
},
|
|
|
removeElement({ state, commit }, element) {
|
|
|
// 解答题时,删除所有小题。
|
|
|
- if (element.type === "EXPLAIN_CHILDREN") {
|
|
|
+ if (
|
|
|
+ element.type === "EXPLAIN_CHILDREN" ||
|
|
|
+ element.type === "FILL_QUESTION"
|
|
|
+ ) {
|
|
|
const positionInfos = fetchAllRelateParentElementPositionInfos(
|
|
|
element.parent,
|
|
|
state.pages
|