feat[design]: 矩阵优化

- 样式调整
- 显示调整, 当行和列都没有的时候取消显示
This commit is contained in:
Huangzhe
2025-03-24 19:22:32 +08:00
parent 8450d87c35
commit 1b6b59a0c0

View File

@@ -18,7 +18,7 @@ const element = defineModel<question>('element', {
} }
}); });
// table 宽度 // table 宽度
const tableWidth = defineModel<number>('tableWidth', { required: false, default: 110 }); const tableWidth = defineModel<number | string>('tableWidth', { required: false, default: 110 });
// 行记录(相关答案的记录) // 行记录(相关答案的记录)
const rowRecord = defineModel<unknown[]>('rowRecord', { required: false, default: () => [] }); const rowRecord = defineModel<unknown[]>('rowRecord', { required: false, default: () => [] });
// 是否是预览状态 // 是否是预览状态
@@ -127,53 +127,64 @@ const errorMessage = defineModel('errorMessage', {
</template> </template>
<template #input> <template #input>
<el-table :data="rows" style="width: 90vw" border stripe> <div style="border-left: 1px solid #f4f4f4">
<el-table-column :width="tableWidth"> <el-table
<template #header></template> :data="rows"
<template #default="{ row /*, column, $index*/ }"> style="width: 85vw"
<div style="position: relative"> row-class-name="table-row"
<el-text truncated :style="{ width: `${tableWidth}px` }"> empty-text=""
<contenteditable v-model="row.option" :active="active" @blur="emitValue" /> v-if="rows.length || cols.length"
</el-text> >
<van-popover <el-table-column width="130px">
v-model="row.showAction" <template #header></template>
placement="left-end" <template #default="{ row /*, column, $index*/ }">
trigger="click" <div style="position: relative">
:actions="popoverActions" <el-text truncated>
@select="handleActionSelect($event, row, 'row')" <contenteditable v-model="row.option" :active="active" @blur="emitValue" />
> </el-text>
<template #reference> <van-popover
<div v-if="active" class="icon"> v-model="row.showAction"
<Io5EllipsisVerticalSharp /> placement="left-end"
</div> trigger="click"
</template> :actions="popoverActions"
</van-popover> @select="handleActionSelect($event, row, 'row')"
</div> >
</template> <template #reference>
</el-table-column> <div v-if="active" class="icon">
<el-table-column v-for="(col, colIndex) in cols" :key="col.option" :width="tableWidth"> <Io5EllipsisVerticalSharp />
<template #header> </div>
<div style="position: relative"> </template>
<el-text truncated :style="{ width: `${tableWidth}px` }"> </van-popover>
<contenteditable v-model="col.option" :active="active" @blur="emitValue" /> </div>
</el-text> </template>
<van-popover </el-table-column>
v-model="col.showAction" <el-table-column
placement="left-end" v-for="(col, colIndex) in cols"
trigger="click" :key="col.option"
:actions="popoverActions" :width="130"
@select="handleActionSelect($event, col, 'col')" style="position: relative"
> >
<template #reference> <template #header>
<div v-if="active" class="icon"> <div>
<Io5EllipsisVerticalSharp /> <el-text truncated :style="{ width: `${tableWidth}px` }">
</div> <contenteditable v-model="col.option" :active="active" @blur="emitValue" />
</template> </el-text>
</van-popover> <van-popover
</div> v-model="col.showAction"
</template> placement="left-end"
<template #default="{ /*row, column, */ $index: rowIndex }"> trigger="click"
<div> :actions="popoverActions"
@select="handleActionSelect($event, col, 'col')"
>
<template #reference>
<div v-if="active" class="icon">
<Io5EllipsisVerticalSharp />
</div>
</template>
</van-popover>
</div>
</template>
<template #default="{ /*row, column, */ $index: rowIndex }">
<component <component
:is="activeComponent" :is="activeComponent"
:element="element" :element="element"
@@ -181,21 +192,19 @@ const errorMessage = defineModel('errorMessage', {
:colIndex="colIndex" :colIndex="colIndex"
v-model:rowRecord="rowRecord" v-model:rowRecord="rowRecord"
/> />
</div> </template>
</template> </el-table-column>
</el-table-column> </el-table>
</el-table> </div>
</template> </template>
</van-field> </van-field>
</template> </template>
<style lang="scss" scoped> <style lang="scss" scoped>
@import '@/assets/css/theme'; @import '@/assets/css/theme';
.matrix-table {
text-align: left;
}
input[type='text'] { input[type='text'] {
width: 70%; width: 100%;
padding: 0 5px; padding: 0 5px;
border: none; border: none;
border-radius: 4px; border-radius: 4px;
@@ -205,40 +214,77 @@ input[type='text'] {
outline: 1px solid $theme-color; outline: 1px solid $theme-color;
} }
} }
.matrix-radio {
position: relative;
overflow: hidden;
width: 15px;
height: 15px;
border: 1px solid #f4f4f4;
border-radius: 50%;
outline: none;
cursor: pointer;
appearance: none; /* 去除默认样式 */
//transition: border-color 0.3s;
}
.matrix-radio:checked {
border-color: transparent; /* 选中时边框颜色 */
}
.matrix-radio:checked::before {
content: '\e728';
position: absolute;
width: 15px;
height: 15px;
background-color: $theme-color; /* 选中颜色 */
color: #fff;
line-height: 15px;
text-align: center;
}
.icon { .icon {
position: absolute; position: absolute;
top: 3px; top: 15%;
right: -10px; right: 0;
& > svg { & > svg {
height: 15px; height: 15px;
} }
} }
:deep(.el-table) {
// Remove horizontal borders
.el-table__inner-wrapper::before {
display: none;
}
// Remove all borders first
.el-table__cell {
border: none;
}
// Add only vertical borders
.el-table__cell::after {
content: '';
position: absolute;
right: 0;
top: 0;
bottom: 0;
width: 1px;
background-color: #ebeef5;
height: 100%;
}
// Add left vertical border to the first cell in each row
.el-table__cell:first-child::before {
content: '';
position: absolute;
left: 0;
top: 0;
bottom: 0;
width: 1px;
background-color: #ebeef5;
height: 100%;
}
// Add horizontal line at the top of the table
.el-table__header-wrapper .el-table__cell {
border-top: 1px solid #ebeef5;
}
// Remove the border between header and body
.el-table__header-wrapper tr.el-table__row th.el-table__cell.is-leaf {
border-bottom: none;
}
.el-table__body-wrapper tr:first-child td.el-table__cell {
border-top: none;
}
// Add horizontal line at the bottom of the table
.el-table__row:last-child .el-table__cell {
border-bottom: 1px solid #ebeef5;
}
// Center all content
.cell {
text-align: center;
display: flex;
align-items: center;
justify-content: center;
}
}
</style> </style>