Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
Element
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
林焕东
Element
Commits
8f7e7a21
Commit
8f7e7a21
authored
Jun 18, 2019
by
hetech
Committed by
island205
Jun 21, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Table: fix current-row-key and select event bug (#15983)
parent
0fffcda6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
29 deletions
+53
-29
packages/table/src/store/current.js
packages/table/src/store/current.js
+39
-15
packages/table/src/store/index.js
packages/table/src/store/index.js
+1
-6
packages/table/src/store/watcher.js
packages/table/src/store/watcher.js
+6
-5
packages/table/src/table.vue
packages/table/src/table.vue
+7
-3
No files found.
packages/table/src/store/current.js
View file @
8f7e7a21
...
@@ -5,7 +5,10 @@ export default {
...
@@ -5,7 +5,10 @@ export default {
data
()
{
data
()
{
return
{
return
{
states
:
{
states
:
{
current
:
null
// 不可响应的,设置 currentRowKey 时,data 不一定存在,也许无法算出正确的 currentRow
// 把该值缓存一下,当用户点击修改 currentRow 时,把该值重置为 null
_currentRowKey
:
null
,
currentRow
:
null
}
}
};
};
},
},
...
@@ -13,31 +16,52 @@ export default {
...
@@ -13,31 +16,52 @@ export default {
methods
:
{
methods
:
{
setCurrentRowKey
(
key
)
{
setCurrentRowKey
(
key
)
{
this
.
assertRowKey
();
this
.
assertRowKey
();
this
.
states
.
_currentRowKey
=
key
;
this
.
setCurrentRowByKey
(
key
);
},
restoreCurrentRowKey
()
{
this
.
states
.
_currentRowKey
=
null
;
},
setCurrentRowByKey
(
key
)
{
const
{
states
}
=
this
;
const
{
states
}
=
this
;
const
{
data
=
[],
rowKey
}
=
states
;
const
{
data
=
[],
rowKey
}
=
states
;
const
currentRow
=
arrayFind
(
data
,
item
=>
getRowIdentity
(
item
,
rowKey
)
===
key
);
let
currentRow
=
null
;
states
.
currentRow
=
currentRow
?
currentRow
:
null
;
if
(
rowKey
)
{
currentRow
=
arrayFind
(
data
,
item
=>
getRowIdentity
(
item
,
rowKey
)
===
key
);
}
states
.
currentRow
=
currentRow
;
},
},
updateCurrentRow
()
{
updateCurrentRow
(
currentRow
)
{
const
{
states
,
table
}
=
this
;
const
{
states
,
table
}
=
this
;
const
{
rowKey
}
=
states
;
const
{
rowKey
,
_currentRowKey
}
=
states
;
// data 为 null 时,结构时的默认值会被忽略
// data 为 null 时,结构时的默认值会被忽略
const
data
=
states
.
data
||
[];
const
data
=
states
.
data
||
[];
const
oldCurrentRow
=
states
.
currentRow
;
const
oldCurrentRow
=
states
.
currentRow
;
// 当 currentRow 不在 data 中时尝试更新数据
if
(
currentRow
)
{
if
(
data
.
indexOf
(
oldCurrentRow
)
===
-
1
&&
oldCurrentRow
)
{
this
.
restoreCurrentRowKey
();
let
newCurrentRow
=
null
;
states
.
currentRow
=
currentRow
;
if
(
rowKey
)
{
if
(
oldCurrentRow
!==
currentRow
)
{
newCurrentRow
=
arrayFind
(
data
,
item
=>
{
this
.
table
.
$emit
(
'
current-change
'
,
currentRow
,
oldCurrentRow
);
return
getRowIdentity
(
item
,
rowKey
)
===
getRowIdentity
(
oldCurrentRow
,
rowKey
);
});
}
}
states
.
currentRow
=
newCurrentRow
;
}
else
{
if
(
newCurrentRow
!==
oldCurrentRow
)
{
// 当 currentRow 不在 data 中时尝试更新数据
table
.
$emit
(
'
current-change
'
,
null
,
oldCurrentRow
);
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
);
}
}
}
}
}
}
...
...
packages/table/src/store/index.js
View file @
8f7e7a21
...
@@ -130,12 +130,7 @@ Watcher.prototype.mutations = {
...
@@ -130,12 +130,7 @@ Watcher.prototype.mutations = {
},
},
setCurrentRow
(
states
,
row
)
{
setCurrentRow
(
states
,
row
)
{
const
oldCurrentRow
=
states
.
currentRow
;
this
.
updateCurrentRow
(
row
);
states
.
currentRow
=
row
;
if
(
oldCurrentRow
!==
row
)
{
this
.
table
.
$emit
(
'
current-change
'
,
row
,
oldCurrentRow
);
}
}
}
};
};
...
...
packages/table/src/store/watcher.js
View file @
8f7e7a21
...
@@ -68,8 +68,7 @@ export default Vue.extend({
...
@@ -68,8 +68,7 @@ export default Vue.extend({
sortProp
:
null
,
sortProp
:
null
,
sortOrder
:
null
,
sortOrder
:
null
,
hoverRow
:
null
,
hoverRow
:
null
currentRow
:
null
}
}
};
};
},
},
...
@@ -165,11 +164,14 @@ export default Vue.extend({
...
@@ -165,11 +164,14 @@ export default Vue.extend({
}
}
},
},
toggleRowSelection
(
row
,
selected
)
{
toggleRowSelection
(
row
,
selected
,
emitChange
=
true
)
{
const
changed
=
toggleRowStatus
(
this
.
states
.
selection
,
row
,
selected
);
const
changed
=
toggleRowStatus
(
this
.
states
.
selection
,
row
,
selected
);
if
(
changed
)
{
if
(
changed
)
{
const
newSelection
=
this
.
states
.
selection
?
this
.
states
.
selection
.
slice
()
:
[];
const
newSelection
=
this
.
states
.
selection
?
this
.
states
.
selection
.
slice
()
:
[];
this
.
table
.
$emit
(
'
select
'
,
newSelection
,
row
);
// 调用 API 修改选中值,不触发 select 事件
if
(
emitChange
)
{
this
.
table
.
$emit
(
'
select
'
,
newSelection
,
row
);
}
this
.
table
.
$emit
(
'
selection-change
'
,
newSelection
);
this
.
table
.
$emit
(
'
selection-change
'
,
newSelection
);
}
}
},
},
...
@@ -296,7 +298,6 @@ export default Vue.extend({
...
@@ -296,7 +298,6 @@ export default Vue.extend({
});
});
states
.
filteredData
=
data
;
states
.
filteredData
=
data
;
// states.data = data;
},
},
execSort
()
{
execSort
()
{
...
...
packages/table/src/table.vue
View file @
8f7e7a21
...
@@ -355,7 +355,7 @@
...
@@ -355,7 +355,7 @@
},
},
toggleRowSelection
(
row
,
selected
)
{
toggleRowSelection
(
row
,
selected
)
{
this
.
store
.
toggleRowSelection
(
row
,
selected
);
this
.
store
.
toggleRowSelection
(
row
,
selected
,
false
);
this
.
store
.
updateAllSelected
();
this
.
store
.
updateAllSelected
();
},
},
...
@@ -585,8 +585,12 @@
...
@@ -585,8 +585,12 @@
}
}
},
},
currentRowKey
(
newVal
)
{
currentRowKey
:
{
this
.
store
.
setCurrentRowKey
(
newVal
);
immediate
:
true
,
handler
(
value
)
{
if
(
!
this
.
rowKey
)
return
;
this
.
store
.
setCurrentRowKey
(
value
);
}
},
},
data
:
{
data
:
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment