refactor(Design): 优化文件上传和答案处理逻辑

- 修改 FileUpload 组件,将答案直接赋值给 question.value.answer
- 更新 useFileUploadHooks,使用 FileList | [] 类型
-移除 PreviewFileUpload 组件中的无用代码
- 优化 PreviewTextWithImages 组件的 watch监听
- 调整 Survey 预览中的表单验证逻辑
This commit is contained in:
陈昱达
2025-05-28 12:33:21 +08:00
parent fced5acf2f
commit e543896c2a
5 changed files with 43 additions and 15 deletions

View File

@@ -34,7 +34,6 @@ const fileLimit = computed(() => {
};
});
console.log(fileLimit.value);
/**
* 上传文件
* @description 上传文件
@@ -75,7 +74,7 @@ function handleFileUpload() {
// 上传文件
// 生成答案
answer.value = files;
question.value.answer = files;
}
}
}

View File

@@ -1,7 +1,7 @@
import { ref } from 'vue';
const answer = ref<FileList>();
// const answer = ref<FileList>();
const answer = ref<FileList | []>([]);
/**
* 文件限制
* @property {number} max - 最大文件大小

View File

@@ -650,6 +650,12 @@ async function answer(callback, callbackBeforePage) {
// 表单验证(当前页)
const errors = questions.value.filter((question) => {
const { config, answer, question_type: questionType, error } = question;
console.log(answer, questionType, error);
// 单独 处理 图文
if (questionType === 6) {
return;
}
let isError = false;
// 如果问题没有答案还有是必须填空的,就往下处理
// 2025/4/1新增 如果有 error 内容, 同样视为有错误
@@ -687,6 +693,13 @@ async function answer(callback, callbackBeforePage) {
question.error = translatedText.value.PleaseInputAValue;
} 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 === 12) {
@@ -701,7 +714,9 @@ async function answer(callback, callbackBeforePage) {
if (Object.keys(answer).length < (+config.min_select || 0)) {
// 选项数量
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) {
// 恒定总和题

View File

@@ -3,16 +3,17 @@ import FileUpload from '@/views/Design/components/Questions/FileUpload.vue';
const questionIndex = defineModel<number>('questionIndex', { default: NaN });
const answerIndex = computed(() => question.value.title);
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';
const emit = defineEmits(['changeAnswer']);
watch(answer, () => {
// 暂时先将答案挂到 question,后续需要优化
question.value.answer = answer.value;
// emit('changeAnswer', answer.value);
// console.log(`question`, question.value);
});
// watch(answer, () => {
// // 暂时先将答案挂到 question,后续需要优化
// question.value.answer = answer.value;
// console.log(question.value.answer);
// // emit('changeAnswer', answer.value);
// // console.log(`question`, question.value);
// });
</script>
<template>
<!-- 文件上传题 -->

View File

@@ -1,15 +1,28 @@
<script setup lang="ts">
import TextWithImages from '@/views/Design/components/Questions/TextWithImages.vue';
import { computed } from 'vue';
import { computed, watch } from 'vue';
// 问题
const question = defineModel<question>('question', { default: {} });
// question 序号
const answerIndex = computed(() => question.value?.title ?? 0);
// 答案
const answer = defineModel('answer', { default: {} });
const answer = defineModel('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>
<template>