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
6dd3f632
Commit
6dd3f632
authored
Jun 25, 2019
by
hetech
Committed by
Zhi Cun
Jun 25, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Table: fix reserve-selection not work (#16135)
* Table: fix reserve-selection not work * fix
parent
ac00b28c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
27 deletions
+17
-27
packages/table/src/store/index.js
packages/table/src/store/index.js
+4
-4
packages/table/src/store/watcher.js
packages/table/src/store/watcher.js
+13
-23
No files found.
packages/table/src/store/index.js
View file @
6dd3f632
...
...
@@ -12,15 +12,15 @@ Watcher.prototype.mutations = {
// 没有使用 computed,而是手动更新部分数据 https://github.com/vuejs/vue/issues/6660#issuecomment-331417140
this
.
updateCurrentRow
();
this
.
updateExpandRows
();
if
(
!
states
.
reserveSelection
)
{
if
(
states
.
reserveSelection
)
{
this
.
assertRowKey
();
this
.
updateSelectionByRowKey
();
}
else
{
if
(
dataInstanceChanged
)
{
this
.
clearSelection
();
}
else
{
this
.
cleanSelection
();
}
}
else
{
this
.
assertRowKey
();
this
.
updateSelectionByRowKey
();
}
this
.
updateAllSelected
();
...
...
packages/table/src/store/watcher.js
View file @
6dd3f632
...
...
@@ -127,18 +127,15 @@ export default Vue.extend({
const
states
=
this
.
states
;
states
.
isAllSelected
=
false
;
const
oldSelection
=
states
.
selection
;
if
(
states
.
s
election
.
length
)
{
if
(
oldS
election
.
length
)
{
states
.
selection
=
[];
}
if
(
oldSelection
.
length
>
0
)
{
this
.
table
.
$emit
(
'
selection-change
'
,
states
.
selection
?
states
.
selection
.
slice
()
:
[]);
this
.
table
.
$emit
(
'
selection-change
'
,
[]);
}
},
cleanSelection
()
{
const
selection
=
this
.
states
.
selection
||
[];
const
data
=
this
.
states
.
data
;
const
rowKey
=
this
.
states
.
rowKey
;
const
states
=
this
.
states
;
const
{
data
,
rowKey
,
selection
}
=
states
;
let
deleted
;
if
(
rowKey
)
{
deleted
=
[];
...
...
@@ -150,24 +147,19 @@ export default Vue.extend({
}
}
}
else
{
deleted
=
selection
.
filter
((
item
)
=>
{
return
data
.
indexOf
(
item
)
===
-
1
;
});
deleted
=
selection
.
filter
(
item
=>
data
.
indexOf
(
item
)
===
-
1
);
}
deleted
.
forEach
((
deletedItem
)
=>
{
selection
.
splice
(
selection
.
indexOf
(
deletedItem
),
1
);
});
if
(
deleted
.
length
)
{
this
.
table
.
$emit
(
'
selection-change
'
,
selection
?
selection
.
slice
()
:
[]);
const
newSelection
=
selection
.
filter
(
item
=>
deleted
.
indexOf
(
item
)
===
-
1
);
states
.
selection
=
newSelection
;
this
.
table
.
$emit
(
'
selection-change
'
,
newSelection
.
slice
());
}
},
toggleRowSelection
(
row
,
selected
,
emitChange
=
true
)
{
const
changed
=
toggleRowStatus
(
this
.
states
.
selection
,
row
,
selected
);
if
(
changed
)
{
const
newSelection
=
this
.
states
.
selection
?
this
.
states
.
selection
.
slice
()
:
[]
;
const
newSelection
=
(
this
.
states
.
selection
||
[]).
slice
()
;
// 调用 API 修改选中值,不触发 select 事件
if
(
emitChange
)
{
this
.
table
.
$emit
(
'
select
'
,
newSelection
,
row
);
...
...
@@ -207,17 +199,15 @@ export default Vue.extend({
updateSelectionByRowKey
()
{
const
states
=
this
.
states
;
const
{
selection
,
rowKey
,
data
=
[]
}
=
states
;
const
{
selection
,
rowKey
,
data
}
=
states
;
const
selectedMap
=
getKeysMap
(
selection
,
rowKey
);
// TODO:这里的代码可以优化
states
.
selection
=
data
.
reduce
((
prev
,
row
)
=>
{
data
.
forEach
(
row
=>
{
const
rowId
=
getRowIdentity
(
row
,
rowKey
);
const
rowInfo
=
selectedMap
[
rowId
];
if
(
rowInfo
)
{
prev
.
push
(
row
)
;
selection
[
rowInfo
.
index
]
=
row
;
}
return
prev
;
},
[]);
});
},
updateAllSelected
()
{
...
...
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