Fix answer transformation

This commit is contained in:
HoshinoKoji 2025-03-05 16:51:49 +08:00
parent 95dc8be6e8
commit 110de95650

View File

@ -177,14 +177,18 @@ export default {
this.updateItem(); this.updateItem();
} }
}, },
transformAnswer(answer) {
return isProxy(answer) ? [...answer]
: (answer === undefined ? null : answer);
},
submit() { submit() {
const results = this.items.map(item => ({ const results = this.items.map(item => ({
title: item.title, title: item.title,
key: item.key ? item.key : item.title, key: item.key ? item.key : item.title,
type: item.type, type: item.type,
answer: isProxy(item.answer) ? [...item.answer] : (item.answer || null), answer: this.transformAnswer(item.answer),
answerText: isProxy(item.answerText) ? [...item.answerText] : (item.answerText || null), answerText: this.transformAnswer(item.answerText),
answerValue: isProxy(item.answerValue) ? [...item.answerValue] : (item.answerValue || null), answerValue: this.transformAnswer(item.answerValue),
refilled: item.refilled, refilled: item.refilled,
responseTime: item.responseTime, responseTime: item.responseTime,
})); }));
@ -216,14 +220,13 @@ export default {
:placeholder="lang[settings.lang].input" /> :placeholder="lang[settings.lang].input" />
</template> </template>
<template v-else-if="itemStatus.item.type === 'radio'"> <template v-else-if="itemStatus.item.type === 'radio'">
<el-radio-group v-model="itemStatus.answer" v-for="[index, optText] in iterOptions()" :key="index" <el-radio-group v-model="itemStatus.answer" @change="autoNext">
@change="autoNext"> <el-radio-button v-for="[index, optText] in iterOptions()" :key="index" :label="optText" :value="index" />
<el-radio-button :label="optText" :value="index" />
</el-radio-group> </el-radio-group>
</template> </template>
<template v-else-if="itemStatus.item.type === 'checkbox'"> <template v-else-if="itemStatus.item.type === 'checkbox'">
<el-checkbox-group v-model="itemStatus.answer" v-for="[index, optText] in iterOptions()" :key="index"> <el-checkbox-group v-model="itemStatus.answer">
<el-checkbox-button :label="optText" :value="index" /> <el-checkbox-button v-for="[index, optText] in iterOptions()" :key="index" :label="optText" :value="index" />
</el-checkbox-group> </el-checkbox-group>
</template> </template>
<template v-else-if="itemStatus.item.type === 'scale'"> <template v-else-if="itemStatus.item.type === 'scale'">