Skip to content

Commit a202ace

Browse files
author
黄书伟
committed
单元格编辑功能优化
1 parent 9cd4411 commit a202ace

File tree

5 files changed

+36
-38
lines changed

5 files changed

+36
-38
lines changed

libs/v-table/src/cell-edit-mixin.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,20 @@ exports.default = {
7575

7676
_utils2.default.bind(editInput, 'blur', _actionFun);
7777
_utils2.default.bind(editInput, 'keydown', _actionFun);
78+
},
79+
cellEditClick: function cellEditClick(e, isEdit, rowData, field, rowIndex) {
80+
81+
if (isEdit) {
82+
83+
var self = this;
84+
85+
var onCellEditCallBack = function onCellEditCallBack(newValue, oldVal) {
86+
87+
self.cellEditDone(newValue, oldVal, rowData, field, rowIndex);
88+
};
89+
90+
this.cellEdit(e, onCellEditCallBack);
91+
}
7892
}
7993
}
8094
};

libs/v-table/src/table-empty.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
npm <template>
1+
<template>
22

33
<div class="v-table-empty">
44
<!--表格无数据的提示信息-->

libs/v-table/src/table.vue

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
<div :class="['v-table-body-cell',showVerticalBorder ? 'vertical-border':'',showHorizontalBorder?'horizontal-border':'']"
6868
:style="{'width':col.width+'px','height': rowHeight+'px','line-height':rowHeight+'px','text-align':col.columnAlign}"
6969
:title="col.overflowTitle ? overflowTitle(item,col) :''"
70-
@click.stop="onCellClick(rowIndex,item,col);onCellEdit($event,col.isEdit,item,col.field,rowIndex)"
70+
@click.stop="onCellClick(rowIndex,item,col);cellEditClick($event,col.isEdit,item,col.field,rowIndex)"
7171
>
7272
<template
7373
v-if="typeof col.componentName ==='string' && col.componentName.length > 0">
@@ -160,7 +160,7 @@
160160
<div :class="['v-table-body-cell',showVerticalBorder ? 'vertical-border':'',showHorizontalBorder?'horizontal-border':'']"
161161
:style="{'width':col.width+'px','height': rowHeight+'px','line-height':rowHeight+'px','text-align':col.columnAlign}"
162162
:title="col.overflowTitle ? overflowTitle(item,col) :''"
163-
@click.stop="onCellClick(rowIndex,item,col);onCellEdit($event,col.isEdit,item,col.field,rowIndex)"
163+
@click.stop="onCellClick(rowIndex,item,col);cellEditClick($event,col.isEdit,item,col.field,rowIndex)"
164164
>
165165
<template v-if="typeof col.componentName ==='string' && col.componentName.length > 0">
166166
<component :rowData="item" :field="col.field ? col.field : ''" :index="rowIndex"
@@ -455,22 +455,6 @@
455455
},
456456
methods: {
457457
458-
// 单元格编辑
459-
onCellEdit(e,isEdit,rowData,field,rowIndex){
460-
461-
if (isEdit){
462-
463-
let self = this;
464-
// 单元格内容变化后的回调
465-
let onCellEditCallBack = function (newValue,oldVal) {
466-
467-
self.cellEditDone(newValue,oldVal,rowData,field,rowIndex);
468-
}
469-
470-
this.cellEdit(e,onCellEditCallBack)
471-
}
472-
},
473-
474458
setRowHoverColor(isMouseenter){
475459
476460
if (this.rowHoverColor && this.rowHoverColor.length > 0 && isMouseenter) {

packages/v-table/src/cell-edit-mixin.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,22 @@ export default {
7070

7171
utils.bind(editInput, 'blur', actionFun);
7272
utils.bind(editInput, 'keydown',actionFun);
73-
}
73+
},
74+
75+
// 单元格点击
76+
cellEditClick(e,isEdit,rowData,field,rowIndex){
77+
78+
if (isEdit){
79+
80+
let self = this;
81+
// 单元格内容变化后的回调
82+
let onCellEditCallBack = function (newValue,oldVal) {
83+
84+
self.cellEditDone(newValue,oldVal,rowData,field,rowIndex);
85+
}
86+
87+
this.cellEdit(e,onCellEditCallBack)
88+
}
89+
},
7490
}
7591
}

packages/v-table/src/table.vue

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
<div :class="['v-table-body-cell',showVerticalBorder ? 'vertical-border':'',showHorizontalBorder?'horizontal-border':'']"
6868
:style="{'width':col.width+'px','height': rowHeight+'px','line-height':rowHeight+'px','text-align':col.columnAlign}"
6969
:title="col.overflowTitle ? overflowTitle(item,col) :''"
70-
@click.stop="onCellClick(rowIndex,item,col);onCellEdit($event,col.isEdit,item,col.field,rowIndex)"
70+
@click.stop="onCellClick(rowIndex,item,col);cellEditClick($event,col.isEdit,item,col.field,rowIndex)"
7171
>
7272
<template
7373
v-if="typeof col.componentName ==='string' && col.componentName.length > 0">
@@ -160,7 +160,7 @@
160160
<div :class="['v-table-body-cell',showVerticalBorder ? 'vertical-border':'',showHorizontalBorder?'horizontal-border':'']"
161161
:style="{'width':col.width+'px','height': rowHeight+'px','line-height':rowHeight+'px','text-align':col.columnAlign}"
162162
:title="col.overflowTitle ? overflowTitle(item,col) :''"
163-
@click.stop="onCellClick(rowIndex,item,col);onCellEdit($event,col.isEdit,item,col.field,rowIndex)"
163+
@click.stop="onCellClick(rowIndex,item,col);cellEditClick($event,col.isEdit,item,col.field,rowIndex)"
164164
>
165165
<template v-if="typeof col.componentName ==='string' && col.componentName.length > 0">
166166
<component :rowData="item" :field="col.field ? col.field : ''" :index="rowIndex"
@@ -455,22 +455,6 @@
455455
},
456456
methods: {
457457
458-
// 单元格编辑
459-
onCellEdit(e,isEdit,rowData,field,rowIndex){
460-
461-
if (isEdit){
462-
463-
let self = this;
464-
// 单元格内容变化后的回调
465-
let onCellEditCallBack = function (newValue,oldVal) {
466-
467-
self.cellEditDone(newValue,oldVal,rowData,field,rowIndex);
468-
}
469-
470-
this.cellEdit(e,onCellEditCallBack)
471-
}
472-
},
473-
474458
setRowHoverColor(isMouseenter){
475459
476460
if (this.rowHoverColor && this.rowHoverColor.length > 0 && isMouseenter) {

0 commit comments

Comments
 (0)