refactor(Design): 优化文件上传和答案处理逻辑
- 修改 FileUpload 组件,将答案直接赋值给 question.value.answer - 更新 useFileUploadHooks,使用 FileList | [] 类型 -移除 PreviewFileUpload 组件中的无用代码 - 优化 PreviewTextWithImages 组件的 watch监听 - 调整 Survey 预览中的表单验证逻辑
This commit is contained in:
@@ -34,7 +34,6 @@ const fileLimit = computed(() => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(fileLimit.value);
|
|
||||||
/**
|
/**
|
||||||
* 上传文件
|
* 上传文件
|
||||||
* @description 上传文件
|
* @description 上传文件
|
||||||
@@ -75,7 +74,7 @@ function handleFileUpload() {
|
|||||||
// 上传文件
|
// 上传文件
|
||||||
|
|
||||||
// 生成答案
|
// 生成答案
|
||||||
answer.value = files;
|
question.value.answer = files;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
|
|
||||||
const answer = ref<FileList>();
|
// const answer = ref<FileList>();
|
||||||
|
const answer = ref<FileList | []>([]);
|
||||||
/**
|
/**
|
||||||
* 文件限制
|
* 文件限制
|
||||||
* @property {number} max - 最大文件大小
|
* @property {number} max - 最大文件大小
|
||||||
|
|||||||
@@ -650,6 +650,12 @@ async function answer(callback, callbackBeforePage) {
|
|||||||
// 表单验证(当前页)
|
// 表单验证(当前页)
|
||||||
const errors = questions.value.filter((question) => {
|
const errors = questions.value.filter((question) => {
|
||||||
const { config, answer, question_type: questionType, error } = question;
|
const { config, answer, question_type: questionType, error } = question;
|
||||||
|
|
||||||
|
console.log(answer, questionType, error);
|
||||||
|
// 单独 处理 图文
|
||||||
|
if (questionType === 6) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let isError = false;
|
let isError = false;
|
||||||
// 如果问题没有答案还有是必须填空的,就往下处理
|
// 如果问题没有答案还有是必须填空的,就往下处理
|
||||||
// 2025/4/1新增 : 如果有 error 内容, 同样视为有错误
|
// 2025/4/1新增 : 如果有 error 内容, 同样视为有错误
|
||||||
@@ -687,6 +693,13 @@ async function answer(callback, callbackBeforePage) {
|
|||||||
question.error = translatedText.value.PleaseInputAValue;
|
question.error = translatedText.value.PleaseInputAValue;
|
||||||
} else if (answer && questionType === 2) {
|
} else if (answer && questionType === 2) {
|
||||||
// 多选题
|
// 多选题
|
||||||
|
// 选项数量
|
||||||
|
|
||||||
|
console.log(translatedText.value);
|
||||||
|
// isError = true;
|
||||||
|
// question.error = translatedText.value.PleaseSelectAtLeastOneOptions(
|
||||||
|
// config.min_select ? config.min_select : 0
|
||||||
|
// );
|
||||||
} else if (answer && questionType === 10) {
|
} else if (answer && questionType === 10) {
|
||||||
// 矩阵多选题
|
// 矩阵多选题
|
||||||
} else if (answer && questionType === 12) {
|
} else if (answer && questionType === 12) {
|
||||||
@@ -701,7 +714,9 @@ async function answer(callback, callbackBeforePage) {
|
|||||||
if (Object.keys(answer).length < (+config.min_select || 0)) {
|
if (Object.keys(answer).length < (+config.min_select || 0)) {
|
||||||
// 选项数量
|
// 选项数量
|
||||||
isError = true;
|
isError = true;
|
||||||
question.error = translatedText.value.PleaseSelectAtLeastOneOptions(config.min_select);
|
question.error = translatedText.value.PleaseSelectAtLeastOneOptions(
|
||||||
|
config.min_select ? config.min_select : 0
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else if (answer && questionType === 17) {
|
} else if (answer && questionType === 17) {
|
||||||
// 恒定总和题
|
// 恒定总和题
|
||||||
|
|||||||
@@ -3,16 +3,17 @@ import FileUpload from '@/views/Design/components/Questions/FileUpload.vue';
|
|||||||
const questionIndex = defineModel<number>('questionIndex', { default: NaN });
|
const questionIndex = defineModel<number>('questionIndex', { default: NaN });
|
||||||
const answerIndex = computed(() => question.value.title);
|
const answerIndex = computed(() => question.value.title);
|
||||||
const question = defineModel<question>('question', { default: () => {} });
|
const question = defineModel<question>('question', { default: () => {} });
|
||||||
import { answer } from '@/views/Design/components/Questions/hooks/useFileUploadHooks';
|
// import { answer } from '@/views/Design/components/Questions/hooks/useFileUploadHooks';
|
||||||
import { computed, watch } from 'vue';
|
import { computed, watch } from 'vue';
|
||||||
|
|
||||||
const emit = defineEmits(['changeAnswer']);
|
const emit = defineEmits(['changeAnswer']);
|
||||||
watch(answer, () => {
|
// watch(answer, () => {
|
||||||
// 暂时先将答案挂到 question,后续需要优化
|
// // 暂时先将答案挂到 question,后续需要优化
|
||||||
question.value.answer = answer.value;
|
// question.value.answer = answer.value;
|
||||||
// emit('changeAnswer', answer.value);
|
// console.log(question.value.answer);
|
||||||
// console.log(`question`, question.value);
|
// // emit('changeAnswer', answer.value);
|
||||||
});
|
// // console.log(`question`, question.value);
|
||||||
|
// });
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<!-- 文件上传题 -->
|
<!-- 文件上传题 -->
|
||||||
|
|||||||
@@ -1,15 +1,28 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import TextWithImages from '@/views/Design/components/Questions/TextWithImages.vue';
|
import TextWithImages from '@/views/Design/components/Questions/TextWithImages.vue';
|
||||||
import { computed } from 'vue';
|
import { computed, watch } from 'vue';
|
||||||
|
|
||||||
// 问题
|
// 问题
|
||||||
const question = defineModel<question>('question', { default: {} });
|
const question = defineModel<question>('question', { default: {} });
|
||||||
// question 序号
|
// question 序号
|
||||||
const answerIndex = computed(() => question.value?.title ?? 0);
|
const answerIndex = computed(() => question.value?.title ?? 0);
|
||||||
// 答案
|
// 答案
|
||||||
const answer = defineModel('answer', { default: {} });
|
const answer = defineModel('answer');
|
||||||
// answer 提供默认值
|
// answer 提供默认值
|
||||||
answer.value = {};
|
question.value.answer = '123';
|
||||||
|
|
||||||
|
watch(
|
||||||
|
answer,
|
||||||
|
(v) => {
|
||||||
|
console.log(v, 'sd');
|
||||||
|
console.log(question.value.answer, 'sd');
|
||||||
|
},
|
||||||
|
{ deep: true, immediate: true }
|
||||||
|
);
|
||||||
|
|
||||||
|
// setTimeout(() => {
|
||||||
|
// answer.value = '123';
|
||||||
|
// }, 300);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
Reference in New Issue
Block a user