|
@@ -131,36 +131,46 @@ export default defineComponent({
|
|
|
|
|
|
// 切换学生状态
|
|
|
const onCheckStudents = () => {
|
|
|
- // state.selectStudents = [];
|
|
|
- if (state.checkboxIds.length <= 0 || state.tableList.length <= 0) {
|
|
|
+ if (state.tableList.length <= 0) {
|
|
|
state.indeterminate = false;
|
|
|
state.checkAllStatus = false;
|
|
|
return;
|
|
|
}
|
|
|
- let count = 0;
|
|
|
// 右边数据
|
|
|
state.tableList.forEach((item: any) => {
|
|
|
if (state.checkboxIds.includes(item.id)) {
|
|
|
- count++;
|
|
|
const index = state.selectStudents.findIndex(
|
|
|
- (select: any) => select.id === item.id
|
|
|
+ (select: any) => select.id == item.id
|
|
|
);
|
|
|
if (index === -1) state.selectStudents.push(item);
|
|
|
+ } else {
|
|
|
+ const index = state.selectStudents.findIndex(
|
|
|
+ (select: any) => select.id == item.id
|
|
|
+ );
|
|
|
+ if(index >= 0) state.selectStudents.splice(index, 1)
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+ let count = 0;
|
|
|
+ state.tableList.forEach((item: any) => {
|
|
|
+ const index = state.selectStudents.findIndex(
|
|
|
+ (select: any) => select.id === item.id
|
|
|
+ );
|
|
|
+ if(index >= 0) count++
|
|
|
+ })
|
|
|
+
|
|
|
if (count >= state.tableList.length) {
|
|
|
state.checkAllStatus = true;
|
|
|
state.indeterminate = false;
|
|
|
} else {
|
|
|
state.checkAllStatus = false;
|
|
|
- state.indeterminate = true;
|
|
|
+ state.indeterminate = count === 0 ? false : true;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
// 删除用户
|
|
|
const onRemove = (item: any) => {
|
|
|
- const index = state.checkboxIds.findIndex((id: any) => id === item.id);
|
|
|
+ const index = state.checkboxIds.findIndex((id: any) => id == item.id);
|
|
|
if (index !== -1) {
|
|
|
state.checkboxIds.splice(index, 1);
|
|
|
const sIndex = state.selectStudents.findIndex(
|
|
@@ -272,10 +282,22 @@ export default defineComponent({
|
|
|
state.tableList.forEach((item: any) => {
|
|
|
ids.push(item.id);
|
|
|
});
|
|
|
- state.checkboxIds = ids;
|
|
|
+ ids.forEach((id: any) => {
|
|
|
+ if(!state.checkboxIds.includes(id)) {
|
|
|
+ state.checkboxIds.push(id)
|
|
|
+ }
|
|
|
+ })
|
|
|
} else {
|
|
|
- state.checkboxIds = [];
|
|
|
- state.selectStudents = [];
|
|
|
+ const removeIds = state.tableList.map((item: any) => item.id)
|
|
|
+ console.log(removeIds, 'removeIds', state.checkboxIds)
|
|
|
+ removeIds.forEach((rid: any) => {
|
|
|
+ const index = state.checkboxIds.findIndex((id: any) => id == rid);
|
|
|
+ if(index !== -1) state.checkboxIds.splice(index, 1);
|
|
|
+ const sindex = state.selectStudents.findIndex(
|
|
|
+ (select: any) => select.id == rid
|
|
|
+ );
|
|
|
+ if(sindex !== -1) state.selectStudents.splice(sindex, 1)
|
|
|
+ })
|
|
|
state.indeterminate = false;
|
|
|
}
|
|
|
onCheckStudents();
|
|
@@ -305,7 +327,7 @@ export default defineComponent({
|
|
|
<NCheckboxGroup
|
|
|
v-model:value={state.checkboxIds}
|
|
|
onUpdate:value={() => {
|
|
|
- state.selectStudents = [];
|
|
|
+ // state.selectStudents = [];
|
|
|
onCheckStudents();
|
|
|
}}>
|
|
|
{state.tableList.map((item: any) => (
|