Merge remote-tracking branch 'origin/feature/feature-20250331-h5' into feature/feature-20250331-h5
This commit is contained in:
@@ -1,79 +1,79 @@
|
||||
<template>
|
||||
<table class="matrix-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<td v-for="col in columns" :key="col.option">
|
||||
<!-- 编辑状态,单次点击出输入框,失焦后关闭 -->
|
||||
<input
|
||||
v-if="col.editor"
|
||||
v-model="col.option"
|
||||
v-focus
|
||||
type="text"
|
||||
@focusout="col.editor = false"
|
||||
@click="handleRowNameChange(col.option!)"
|
||||
/>
|
||||
<span v-else @click="handleRowNameChange(col.option!)" v-html="col.option"></span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th></th>
|
||||
<td v-for="col in columns" :key="col.option">
|
||||
<!-- 编辑状态,单次点击出输入框,失焦后关闭 -->
|
||||
<input
|
||||
v-if="col.editor"
|
||||
v-model="col.option"
|
||||
v-focus
|
||||
type="text"
|
||||
@focusout="col.editor = false"
|
||||
@click="handleRowNameChange(col.option!)"
|
||||
/>
|
||||
<span v-else @click="handleRowNameChange(col.option!)" v-html="col.option"></span>
|
||||
</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(row, rowIndex) in rows" :key="rowIndex">
|
||||
<th v-html="row.option"></th>
|
||||
<td v-for="(col, colIndex) in columns" :key="colIndex">
|
||||
<input
|
||||
type="radio"
|
||||
:name="`R${rowIndex + 1}`"
|
||||
:value="`${rowIndex + 1}_${colIndex + 1}`"
|
||||
:checked="isOptionChecked(rowIndex, colIndex)"
|
||||
@change="handleColNameChange(row.option, col.option, $event)"
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-for="(row, rowIndex) in rows" :key="rowIndex">
|
||||
<th v-html="row.option"></th>
|
||||
<td v-for="(col, colIndex) in columns" :key="colIndex">
|
||||
<input
|
||||
type="radio"
|
||||
:name="`R${rowIndex + 1}`"
|
||||
:value="`${rowIndex + 1}_${colIndex + 1}`"
|
||||
:checked="isOptionChecked(rowIndex, colIndex)"
|
||||
@change="handleColNameChange(row.option, col.option, $event)"
|
||||
/>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, defineProps, defineEmits } from 'vue';
|
||||
import {vFocus} from '@/utils/directives/useVFocus';
|
||||
import { defineProps } from 'vue';
|
||||
import { vFocus } from '@/utils/directives/useVFocus';
|
||||
|
||||
let props = defineProps<{
|
||||
const props = defineProps<{
|
||||
rows: { option: string }[];
|
||||
columns: { option: string, editor?: boolean }[];
|
||||
columns: { option: string; editor?: boolean }[];
|
||||
questionType: number;
|
||||
matrixAnswer: { [key: string]: any };
|
||||
rowRecord: (number | string)[];
|
||||
rowRecord:(number | string)[];
|
||||
}>();
|
||||
|
||||
const emits = defineEmits(['update:matrixAnswer', 'update:rowRecord']);
|
||||
/* const emits = */ defineEmits(['update:matrixAnswer', 'update:rowRecord']);
|
||||
|
||||
const isOptionChecked = (rowIndex: number, colIndex: number): boolean => {
|
||||
const key = `R${rowIndex + 1}_C${colIndex + 1}`;
|
||||
return !!props.matrixAnswer[key];
|
||||
};
|
||||
|
||||
const handleRowNameChange = (value: string) => {
|
||||
console.log(`row change: ${value}`);
|
||||
const handleRowNameChange = (/* value: string */) => {
|
||||
// console.log(`row change: ${value}`);
|
||||
// 你可以在这里添加其他逻辑
|
||||
};
|
||||
|
||||
const handleColNameChange = (rowOption: string, colOption: string, e: Event) => {
|
||||
const target = e.target as HTMLInputElement;
|
||||
const col = props.columns.findIndex(option => option.option === colOption);
|
||||
const row = props.rows.findIndex(option => option.option === rowOption);
|
||||
|
||||
if (props.questionType === 9) {
|
||||
props.rowRecord[col] = row + 1;
|
||||
props.matrixAnswer = {};
|
||||
props.rowRecord.forEach((row, index) => {
|
||||
props.matrixAnswer[`${index + 1}_${row}`] = 1;
|
||||
});
|
||||
}
|
||||
|
||||
emits('update:matrixAnswer', props.matrixAnswer);
|
||||
emits('update:rowRecord', props.rowRecord);
|
||||
};
|
||||
// const handleColNameChange = (rowOption: string, colOption: string) => {
|
||||
// // const target = e.target as HTMLInputElement;
|
||||
// const col = props.columns.findIndex((option) => option.option === colOption);
|
||||
// const row = props.rows.findIndex((option) => option.option === rowOption);
|
||||
//
|
||||
// if (props.questionType === 9) {
|
||||
// props.rowRecord[col] = row + 1;
|
||||
// props.matrixAnswer = {};
|
||||
// props.rowRecord.forEach((row, index) => {
|
||||
// props.matrixAnswer[`${index + 1}_${row}`] = 1;
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// emits('update:matrixAnswer', props.matrixAnswer);
|
||||
// emits('update:rowRecord', props.rowRecord);
|
||||
// };
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@@ -88,4 +88,4 @@ const handleColNameChange = (rowOption: string, colOption: string, e: Event) =>
|
||||
border: 1px solid #ddd;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user