|
@@ -35,34 +35,41 @@ export default {
|
|
|
},
|
|
|
|
|
|
updateCurrentRow(currentRow) {
|
|
|
+ const { states, table } = this;
|
|
|
+ const oldCurrentRow = states.currentRow;
|
|
|
+ if (currentRow && currentRow !== oldCurrentRow) {
|
|
|
+ states.currentRow = currentRow;
|
|
|
+ table.$emit('current-change', currentRow, oldCurrentRow);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!currentRow && oldCurrentRow) {
|
|
|
+ states.currentRow = null;
|
|
|
+ table.$emit('current-change', null, oldCurrentRow);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ updateCurrentRowData() {
|
|
|
const { states, table } = this;
|
|
|
const { rowKey, _currentRowKey } = states;
|
|
|
// data 为 null 时,结构时的默认值会被忽略
|
|
|
const data = states.data || [];
|
|
|
const oldCurrentRow = states.currentRow;
|
|
|
|
|
|
- if (currentRow) {
|
|
|
- this.restoreCurrentRowKey();
|
|
|
- states.currentRow = currentRow;
|
|
|
- if (oldCurrentRow !== currentRow) {
|
|
|
- this.table.$emit('current-change', currentRow, oldCurrentRow);
|
|
|
+ // 当 currentRow 不在 data 中时尝试更新数据
|
|
|
+ if (data.indexOf(oldCurrentRow) === -1 && oldCurrentRow) {
|
|
|
+ if (rowKey) {
|
|
|
+ const currentRowKey = getRowIdentity(oldCurrentRow, rowKey);
|
|
|
+ this.setCurrentRowByKey(currentRowKey);
|
|
|
+ } else {
|
|
|
+ states.currentRow = null;
|
|
|
}
|
|
|
- } else {
|
|
|
- // 当 currentRow 不在 data 中时尝试更新数据
|
|
|
- if (data.indexOf(oldCurrentRow) === -1 && oldCurrentRow) {
|
|
|
- this.restoreCurrentRowKey();
|
|
|
- if (rowKey) {
|
|
|
- const currentRowKey = getRowIdentity(oldCurrentRow, rowKey);
|
|
|
- this.setCurrentRowByKey(currentRowKey);
|
|
|
- } else {
|
|
|
- states.currentRow = null;
|
|
|
- }
|
|
|
- if (states.currentRow !== oldCurrentRow) {
|
|
|
- table.$emit('current-change', null, oldCurrentRow);
|
|
|
- }
|
|
|
- } else if (_currentRowKey) {
|
|
|
- this.setCurrentRowByKey(_currentRowKey);
|
|
|
+ if (states.currentRow === null) {
|
|
|
+ table.$emit('current-change', null, oldCurrentRow);
|
|
|
}
|
|
|
+ } else if (_currentRowKey) {
|
|
|
+ // 把初始时下设置的 rowKey 转化成 rowData
|
|
|
+ this.setCurrentRowByKey(_currentRowKey);
|
|
|
+ this.restoreCurrentRowKey();
|
|
|
}
|
|
|
}
|
|
|
}
|