feat(Design): 更新问卷题目编号和保存逻辑
- 移除 ChooseQuestion 组件中的 watch 函数 - 在 Design/Index.vue 中添加更新所有题目编号的逻辑 - 修改 Survey/views/Create/Index.vue 中的保存方法,增加自动更新题目编号的功能 - 优化 publishQuestion 和 previewQuestion 方法,保存问卷后再进行跳转
This commit is contained in:
@@ -262,6 +262,16 @@ if (previewQuestionInfo.value?.answer) {
|
|||||||
const debouncedSaveQueItem = debounce((logics, newVal) => {
|
const debouncedSaveQueItem = debounce((logics, newVal) => {
|
||||||
if (newVal && !isPreview.value) {
|
if (newVal && !isPreview.value) {
|
||||||
saveQueItem(logics, newVal);
|
saveQueItem(logics, newVal);
|
||||||
|
|
||||||
|
let questionCopy = JSON.parse(JSON.stringify(questionInfo.value.questions));
|
||||||
|
questionCopy = questionCopy.map((item, index) => {
|
||||||
|
return {
|
||||||
|
...item,
|
||||||
|
title: index + 1
|
||||||
|
};
|
||||||
|
});
|
||||||
|
// 保存全部 更新title
|
||||||
|
saveQueItem(questionInfo.value.logics, questionCopy);
|
||||||
}
|
}
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
|
|||||||
@@ -73,12 +73,12 @@ const index = defineModel('index', {
|
|||||||
type: Number
|
type: Number
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(
|
// watch(
|
||||||
() => index.value,
|
// () => index.value,
|
||||||
(newVal) => {
|
// (newVal) => {
|
||||||
element.value.title = newVal + 1;
|
// element.value.title = newVal + 1;
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
|
|
||||||
// 获取题目选项
|
// 获取题目选项
|
||||||
const getQuestionType = (type) => {
|
const getQuestionType = (type) => {
|
||||||
|
|||||||
@@ -110,7 +110,7 @@
|
|||||||
plain
|
plain
|
||||||
type="primary"
|
type="primary"
|
||||||
:disabled="activeActionButton"
|
:disabled="activeActionButton"
|
||||||
@click="saveAs"
|
@click="() => saveAs()"
|
||||||
>
|
>
|
||||||
保存
|
保存
|
||||||
</van-button>
|
</van-button>
|
||||||
@@ -590,22 +590,56 @@ watch(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// 保存 目前没有任何逻辑可以执行所有保存
|
// 保存 目前没有任何逻辑可以执行所有保存
|
||||||
const saveAs = () => {
|
const saveAs = (back) => {
|
||||||
sync({ sn: route.query.sn }).then(() => {
|
let questions = JSON.parse(JSON.stringify(questionInfo.value.questions));
|
||||||
// 保存所有
|
questions = questions.map((item, index) => {
|
||||||
showConfirmDialog({
|
return {
|
||||||
message: '问卷保存成功',
|
...item,
|
||||||
showCancelButton: false
|
title: index + 1
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
let query = {
|
||||||
|
sn: route.query.sn,
|
||||||
|
|
||||||
|
data: {
|
||||||
|
logics: questionInfo.value.logics,
|
||||||
|
questions: questions,
|
||||||
|
survey: {
|
||||||
|
local_pages: [],
|
||||||
|
pages: getPages(
|
||||||
|
questionInfo.value.questions,
|
||||||
|
questionInfo.value.survey.is_one_page_one_question
|
||||||
|
),
|
||||||
|
version: Base64.encode(`${new Date().getTime()}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
saveQuestion(query).then(() => {
|
||||||
|
sync({ sn: route.query.sn }).then(() => {
|
||||||
|
if (back) {
|
||||||
|
back();
|
||||||
|
} else {
|
||||||
|
// 保存所有
|
||||||
|
showConfirmDialog({
|
||||||
|
message: '问卷保存成功',
|
||||||
|
showCancelButton: false
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
// 投放
|
// 投放
|
||||||
const publishQuestion = () => {
|
const publishQuestion = () => {
|
||||||
router.push({ name: 'publish', query: { ...route.query } });
|
saveAs(() => {
|
||||||
|
router.push({ name: 'publish', query: { ...route.query } });
|
||||||
|
});
|
||||||
};
|
};
|
||||||
// 预览
|
// 预览
|
||||||
const previewQuestion = () => {
|
const previewQuestion = () => {
|
||||||
router.push({ name: 'preview', query: { ...route.query } });
|
saveAs(() => {
|
||||||
|
router.push({ name: 'preview', query: { ...route.query } });
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const surveyDetailFun = (back) => {
|
const surveyDetailFun = (back) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user