Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复客户端多选题传参失败的问题 #102

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/pages/View/checkbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
<div class="flex-col">
<div class="flex items-center gap-20">
<span class="lg:text-xl md:text-md">{{ props.serial_num }}</span>
<span class="lg:text-xl md:text-md flex gap-5 items-center" >{{ props.title }} <el-tag type="primary" class="ml-5">多选</el-tag> <el-tag type="warning" v-if="!required">选答</el-tag> <el-tag type="danger" v-if="localUnique">唯一</el-tag></span>
<span class="lg:text-xl md:text-md flex gap-5 items-center" >{{ props.title }}
<el-tag type="primary" class="ml-5">多选</el-tag>
<el-tag type="warning" v-if="!required">选答</el-tag>
<el-tag type="danger" v-if="localUnique">唯一</el-tag>
</span>
</div>
<div class="flex items-center mt-15 ml-10">
<pre class="text-sm text-gray-500 break-all">{{ props.describe }}</pre>
Expand All @@ -25,7 +29,7 @@
</div>
</div>
<div class="flex gap-10 mt-10" v-if="localOtherOption">
<input type="checkbox" :name="props.serial_num" class="my-5" style="zoom: 140%" :value="otherAnswer" id='other' @click='otherAnswerChecked = !otherAnswerChecked'/>
<input ref="otherCheckbox" type="checkbox" :name="props.serial_num" class="my-5" style="zoom: 140%" :value="otherAnswer" @click='otherAnswerChecked = !otherAnswerChecked'/>
<input type="text" class="input-sm w-150" placeholder="其他" v-model="otherAnswer" @input="updateOtherAnswer" />
</div>
</div>
Expand Down Expand Up @@ -57,15 +61,17 @@ const otherAnswer = ref<string>('');
const answerArr = ref<string[]>([]);
const emits = defineEmits(['update:answer']);
const otherAnswerChecked = ref(false)
const otherCheckbox = ref<HTMLInputElement | null>(null);

const deleteOldAnswer = () => {
const otherIndex = answerArr.value.indexOf(otherAnswer.value);
if (otherIndex !== -1) {
answerArr.value.splice(otherIndex, 1);
}
}

const updateOtherAnswer = (event: Event) => {
if(document.getElementById("other").checked === true) {
if (otherCheckbox.value && otherCheckbox.value.checked) {
const value = (event.target as HTMLInputElement).value;
deleteOldAnswer();
otherAnswer.value = value;
Expand All @@ -78,7 +84,7 @@ const filteredAnswerArr = computed(() => {
})

watch(filteredAnswerArr, () => {
if(document.getElementById("other").checked === true && !answerArr.value.includes(otherAnswer.value)) {
if (otherCheckbox.value && otherCheckbox.value.checked && !answerArr.value.includes(otherAnswer.value)) {
answerArr.value.push(otherAnswer.value)
}
console.log(filteredAnswerArr.value)
Expand All @@ -88,14 +94,15 @@ watch(filteredAnswerArr, () => {
});

watch(otherAnswer, (newOtherAnswer, oldOtherAnswer) => {
if (newOtherAnswer !== oldOtherAnswer && document.getElementById("other").checked === true) {
if (newOtherAnswer !== oldOtherAnswer && otherCheckbox.value && otherCheckbox.value.checked) {
const otherIndex = answerArr.value.indexOf(oldOtherAnswer);
if (otherIndex !== -1) {
answerArr.value.splice(otherIndex, 1);
}
answerArr.value.push(newOtherAnswer);
}
})

watch(otherAnswerChecked,() => {
if(otherAnswerChecked.value) {
if (!answerArr.value.includes(otherAnswer.value)) {
Expand Down
Loading