From 216b4435403734f1c6f0d37b7c043640ef9a9dc4 Mon Sep 17 00:00:00 2001 From: Huangzhe Date: Mon, 26 May 2025 14:09:59 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat(Survey):=20=E6=B7=BB=E5=8A=A0=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E6=A0=A1=E9=AA=8C=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增模板校验功能,检查问卷中是否包含移动端不支持的题型 - 在保存模板前进行校验,如果存在不支持的题型则弹出提示窗口 - 优化删除问卷和保存模板的逻辑 --- src/hooks/request/useQuestion.ts | 17 +++++++++++++++ src/views/Survey/hooks/useSurveyData.ts | 29 +++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 src/hooks/request/useQuestion.ts diff --git a/src/hooks/request/useQuestion.ts b/src/hooks/request/useQuestion.ts new file mode 100644 index 0000000..1b63b16 --- /dev/null +++ b/src/hooks/request/useQuestion.ts @@ -0,0 +1,17 @@ +import { getQuestionList } from "@/api/survey"; +import { ref } from "vue"; + +function fetchSingleQuestion(sn: string) { + const list = ref([]) + getQuestionList(sn).then(({ data }) => { + list.value = data.data; + }); + return { + list, + } +} + + +export { + fetchSingleQuestion +} \ No newline at end of file diff --git a/src/views/Survey/hooks/useSurveyData.ts b/src/views/Survey/hooks/useSurveyData.ts index 3cd7af7..dd2d05a 100644 --- a/src/views/Survey/hooks/useSurveyData.ts +++ b/src/views/Survey/hooks/useSurveyData.ts @@ -2,6 +2,8 @@ import { getSurveysPage, deleteSurveys, saveTemplates } from '@/api/home'; import { ref } from 'vue'; import { showDialog, showConfirmDialog, showFailToast, showToast } from 'vant'; import { getSurveysDetail } from '@/api/design'; +import { getQuestionList } from '@/api/survey'; +import { questionTypeMap } from '@/utils/question/typeMapping'; const searchValue = ref(''); const survey = ref([]); @@ -55,7 +57,7 @@ function deleteItem(item: SurveyItem, form: any) { showCancelButton: true, confirmButtonColor: '#03B03C' }) - .then(async() => { + .then(async () => { const res = await deleteSurveys(item.sn); if (res.data.message) { showToast(res.data.message); @@ -74,6 +76,15 @@ function deleteItem(item: SurveyItem, form: any) { // 保存为模板 async function saveTemplate(item: SurveyItem) { const data = JSON.parse(JSON.stringify(item)); + + // 如果没有通过校验, 弹出提示窗不进行下一步 + if (!(await validateSurvey(data))) { + showDialog({ + title: '模板校验失败', + message: '内部存在移动端不支持的题型' + }); + return; + } const res = await saveTemplates(item.sn, data); if (res.data.code === 200 || res.data.code === 201) { showConfirmDialog({ @@ -84,10 +95,24 @@ async function saveTemplate(item: SurveyItem) { showFailToast(res.data); } } - function clearSurveys() { survey.value = []; } +/** + * 校验问卷是否可以保存为模板 + * @param data + */ +async function validateSurvey(survey: SurveyItem): Promise { + const { data } = await getQuestionList(survey.sn); + const questions = data.data.questions; + + return questions.every((question: any) => { + if (!questionTypeMap.has(question.question_type)) { + return false; + } + return true; + }); +} export { fetchSurveys, From 0a91df64b574fbb3aec5d21df905d47dc86c18d4 Mon Sep 17 00:00:00 2001 From: Huangzhe Date: Mon, 26 May 2025 14:12:38 +0800 Subject: [PATCH 2/3] =?UTF-8?q?refactor(Survey):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E6=A0=A1=E9=AA=8C=E5=A4=B1=E8=B4=A5=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将"内部存在移动端不支持的 --- src/views/Survey/hooks/useSurveyData.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/views/Survey/hooks/useSurveyData.ts b/src/views/Survey/hooks/useSurveyData.ts index dd2d05a..5de5f44 100644 --- a/src/views/Survey/hooks/useSurveyData.ts +++ b/src/views/Survey/hooks/useSurveyData.ts @@ -81,7 +81,7 @@ async function saveTemplate(item: SurveyItem) { if (!(await validateSurvey(data))) { showDialog({ title: '模板校验失败', - message: '内部存在移动端不支持的题型' + message: '问卷内存在移动端不支持的题型' }); return; } @@ -105,7 +105,7 @@ function clearSurveys() { async function validateSurvey(survey: SurveyItem): Promise { const { data } = await getQuestionList(survey.sn); const questions = data.data.questions; - +return return questions.every((question: any) => { if (!questionTypeMap.has(question.question_type)) { return false; From f886a511101f34e5945107cb10b80312eb03fd8b Mon Sep 17 00:00:00 2001 From: Huangzhe Date: Mon, 26 May 2025 14:17:17 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=99=BA=E8=83=BD?= =?UTF-8?q?=E7=94=9F=E6=88=90=E9=97=AE=E5=8D=B7=20iframe=20=E9=80=82?= =?UTF-8?q?=E9=85=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 更新 iframe src 属性的拼接方式,使用 encodeURIComponent 对 token 进行编码 - 移除 encodeURI 函数的使用,直接使用拼接好的 url --- .../CreateSurvey/components/IntelligentGeneration/Index.vue | 6 +++--- src/views/Survey/hooks/useSurveyData.ts | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/views/Home/components/CreateSurvey/components/IntelligentGeneration/Index.vue b/src/views/Home/components/CreateSurvey/components/IntelligentGeneration/Index.vue index 25eed02..3c42071 100644 --- a/src/views/Home/components/CreateSurvey/components/IntelligentGeneration/Index.vue +++ b/src/views/Home/components/CreateSurvey/components/IntelligentGeneration/Index.vue @@ -2,15 +2,15 @@ import { escapeHTML } from '@/utils/stringTranslate'; const host = `https://yiligpt.x.digitalyili.com`; -const path = '/aiagent/assistant/78907182-cc42-4072-abae-86ef67c1ecd3/share'; -const param = `?token=${localStorage.getItem('plantToken')}&source=app`; +const path = '/aiagent/assistant/78907182-cc42-4072-abae-86ef67c1ecd3/share?'; +const param = `token=${encodeURIComponent(localStorage.getItem('plantToken') as string)}&source=app`; const url = host + path + param; // 字符串转义