Skip to content

Commit 191375e

Browse files
committed
feat: 可编辑表格样式优化
1 parent 5bf571e commit 191375e

File tree

2 files changed

+42
-29
lines changed

2 files changed

+42
-29
lines changed

src/components/editTable/index.vue

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
this.$emit('update:table-data', this.copyData);
6666
// 暴露编辑完成事件,将修改的信息传回
6767
this.$emit('edit-ok', { row, column, index, newValue });
68+
this.$message.success('保存成功');
6869
},
6970
onBlur ({ row, column, index }) {
7071
this.copyData[index][column.prop] = row[column.prop];
@@ -77,32 +78,37 @@
7778
const render = (h, { row, column, index }) => {
7879
const isEditing = this.editIds.includes(`${column.prop}_${index}`);
7980
return (
80-
<div class="edit-col">
81-
{
82-
(isEditing || trigger === 'blur')
83-
?
84-
<col.editable.widget
85-
vModel={row[column.prop]}
86-
on-input={this.onInput.bind(this, { row, column, index })}
87-
on-blur={
88-
trigger === 'blur' ? this.onBlur.bind(this, { row, column, index }) : () => {}
89-
}
90-
{...{ attrs: rest }}
81+
<el-row type="flex" align="middle" gutter={16} class="edit-col">
82+
<el-col span={14}>
83+
{
84+
(isEditing || trigger === 'blur')
85+
?
86+
<col.editable.widget
87+
vModel={row[column.prop]}
88+
on-input={this.onInput.bind(this, { row, column, index })}
89+
on-blur={
90+
trigger === 'blur' ? this.onBlur.bind(this, { row, column, index }) : () => {}
91+
}
92+
{...{ attrs: rest }}
93+
>
94+
</col.editable.widget>
95+
:
96+
<span>{row[column.prop]}</span>
97+
}
98+
</el-col>
99+
<el-col span={8}>
100+
{
101+
trigger !== 'blur' &&
102+
<el-button
103+
size="small"
104+
on-click={this.onClick.bind(this, { row, column, index })}
105+
className="edit-button"
91106
>
92-
</col.editable.widget>
93-
:
94-
<span>{row[column.prop]}</span>
95-
}
96-
{
97-
trigger !== 'blur' &&
98-
<el-button
99-
on-click={this.onClick.bind(this, { row, column, index })}
100-
className="edit-button"
101-
>
102-
{isEditing ? '保存' : '编辑'}
103-
</el-button>
104-
}
105-
</div>
107+
{isEditing ? '保存' : '编辑'}
108+
</el-button>
109+
}
110+
</el-col>
111+
</el-row>
106112
);
107113
};
108114
return { ...col, render };
@@ -118,9 +124,17 @@
118124
<style lang="scss" scoped>
119125
.edit-table {
120126
/deep/ .edit-col {
121-
display: flex;
122-
justify-content: space-between;
123-
align-items: center;
127+
.el-input__inner {
128+
height: 32px;
129+
line-height: 32px;
130+
}
131+
.el-input-number .el-input__inner {
132+
text-align: left;
133+
}
134+
.el-input-number {
135+
width: 100%;
136+
line-height: 32px;
137+
}
124138
}
125139
}
126140
</style>

src/views/editTable/index.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
prop: 'name', width: '200', label: '姓名',
2121
editable: {
2222
widget: 'el-input',
23-
style: { width: '100px' },
2423
required: false,
2524
trigger: 'blur'
2625
}

0 commit comments

Comments
 (0)