From 5fd7efd61c32544a25062388dc050c681eb9ff7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=98=B1=E8=BE=BE?= Date: Fri, 21 Mar 2025 17:01:54 +0800 Subject: [PATCH] =?UTF-8?q?feat(Design):=20=E6=9B=B4=E6=96=B0=E9=97=AE?= =?UTF-8?q?=E5=8D=B7=E9=A2=98=E7=9B=AE=E7=BC=96=E5=8F=B7=E5=92=8C=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除 ChooseQuestion 组件中的 watch 函数 - 在 Design/Index.vue 中添加更新所有题目编号的逻辑 - 修改 Survey/views/Create/Index.vue 中的保存方法,增加自动更新题目编号的功能 - 优化 publishQuestion 和 previewQuestion 方法,保存问卷后再进行跳转 --- src/views/Design/Index.vue | 10 ++++ .../Design/components/ChooseQuestion.vue | 12 ++--- src/views/Survey/views/Create/Index.vue | 52 +++++++++++++++---- 3 files changed, 59 insertions(+), 15 deletions(-) diff --git a/src/views/Design/Index.vue b/src/views/Design/Index.vue index 7574f84..780c631 100644 --- a/src/views/Design/Index.vue +++ b/src/views/Design/Index.vue @@ -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); diff --git a/src/views/Design/components/ChooseQuestion.vue b/src/views/Design/components/ChooseQuestion.vue index 93ef3a1..b554564 100644 --- a/src/views/Design/components/ChooseQuestion.vue +++ b/src/views/Design/components/ChooseQuestion.vue @@ -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) => { diff --git a/src/views/Survey/views/Create/Index.vue b/src/views/Survey/views/Create/Index.vue index 6df78df..3f948b3 100644 --- a/src/views/Survey/views/Create/Index.vue +++ b/src/views/Survey/views/Create/Index.vue @@ -110,7 +110,7 @@ plain type="primary" :disabled="activeActionButton" - @click="saveAs" + @click="() => saveAs()" > 保存 @@ -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) => {