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) => {
|
||||
if (newVal && !isPreview.value) {
|
||||
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);
|
||||
|
||||
|
||||
@@ -73,12 +73,12 @@ const index = defineModel('index', {
|
||||
type: Number
|
||||
});
|
||||
|
||||
watch(
|
||||
() => index.value,
|
||||
(newVal) => {
|
||||
element.value.title = newVal + 1;
|
||||
}
|
||||
);
|
||||
// watch(
|
||||
// () => index.value,
|
||||
// (newVal) => {
|
||||
// element.value.title = newVal + 1;
|
||||
// }
|
||||
// );
|
||||
|
||||
// 获取题目选项
|
||||
const getQuestionType = (type) => {
|
||||
|
||||
@@ -110,7 +110,7 @@
|
||||
plain
|
||||
type="primary"
|
||||
:disabled="activeActionButton"
|
||||
@click="saveAs"
|
||||
@click="() => saveAs()"
|
||||
>
|
||||
保存
|
||||
</van-button>
|
||||
@@ -590,22 +590,56 @@ watch(
|
||||
);
|
||||
|
||||
// 保存 目前没有任何逻辑可以执行所有保存
|
||||
const saveAs = () => {
|
||||
sync({ sn: route.query.sn }).then(() => {
|
||||
// 保存所有
|
||||
showConfirmDialog({
|
||||
message: '问卷保存成功',
|
||||
showCancelButton: false
|
||||
const saveAs = (back) => {
|
||||
let questions = JSON.parse(JSON.stringify(questionInfo.value.questions));
|
||||
questions = questions.map((item, index) => {
|
||||
return {
|
||||
...item,
|
||||
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 = () => {
|
||||
router.push({ name: 'publish', query: { ...route.query } });
|
||||
saveAs(() => {
|
||||
router.push({ name: 'publish', query: { ...route.query } });
|
||||
});
|
||||
};
|
||||
// 预览
|
||||
const previewQuestion = () => {
|
||||
router.push({ name: 'preview', query: { ...route.query } });
|
||||
saveAs(() => {
|
||||
router.push({ name: 'preview', query: { ...route.query } });
|
||||
});
|
||||
};
|
||||
|
||||
const surveyDetailFun = (back) => {
|
||||
|
||||
Reference in New Issue
Block a user