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/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;
// 字符串转义
-
+
diff --git a/src/views/Survey/hooks/useSurveyData.ts b/src/views/Survey/hooks/useSurveyData.ts
index 3cd7af7..fd92fd3 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,23 @@ 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,