Merge remote-tracking branch 'origin/feature/feature-20250430-h5' into feature/feature-20250430-h5
This commit is contained in:
17
src/hooks/request/useQuestion.ts
Normal file
17
src/hooks/request/useQuestion.ts
Normal file
@@ -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
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
// 字符串转义
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<iframe style="height: 100%; width: 100%" :src="encodeURI(url)" frameborder="0" />
|
||||
<iframe style="height: 100%; width: 100%" :src="url" frameborder="0" />
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss"></style>
|
||||
|
||||
@@ -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<SurveyItem[]>([]);
|
||||
@@ -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<boolean> {
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user