Commit 794bcbeb authored by 邓超's avatar 邓超

fix: 修复测试推送搜索bug

parent 554e0920
......@@ -25,58 +25,90 @@ const CardCheck = props => {
setIndeterminate(cardMsg.indeterminate);
setCheckAll(cardMsg.checkAll);
}, []);
useEffect(() => {
if (prevAmount) {
let newCheckList = [...checkList];
console.log(newCheckList);
// 当前选中的
let currentArr = checkedList;
// 上一次选中的
let preArr = prevAmount.checkedList;
currentArr = new Set(currentArr);
preArr = new Set(preArr);
// 找出相同的部分
let someArr = [...new Set([...currentArr].filter(x => preArr.has(x)))];
// 复选框事选中还是取消选中 add or del
let checkType;
if ([...currentArr].length > [...preArr].length) {
checkType = 'add';
} else if ([...currentArr].length < [...preArr].length) {
checkType = 'del';
}
if (checkType === 'add') {
// 添加新选中的元素
currentArr.forEach(item => {
if (someArr.indexOf(item) === -1) {
let checkName = plainOptions.find(ele => ele.value === item);
newCheckList.push(checkName);
}
});
} else if (checkType === 'del') {
// 删除取消勾选的元素
preArr.forEach(item => {
if (someArr.indexOf(item) === -1) {
newCheckList.splice(
newCheckList.findIndex(ele => ele.value === item),
1,
);
}
});
}
callback(checkedList, newCheckList);
}
}, [checkedList]);
// useEffect(() => {
// if (prevAmount) {
// let newCheckList = [...checkList];
// console.log(newCheckList);
// // 当前选中的
// let currentArr = checkedList;
// // 上一次选中的
// let preArr = prevAmount.checkedList;
// currentArr = new Set(currentArr);
// preArr = new Set(preArr);
// // 找出相同的部分
// let someArr = [...new Set([...currentArr].filter(x => preArr.has(x)))];
// // 复选框事选中还是取消选中 add or del
// let checkType;
// if ([...currentArr].length > [...preArr].length) {
// checkType = 'add';
// } else if ([...currentArr].length < [...preArr].length) {
// checkType = 'del';
// }
// if (checkType === 'add') {
// // 添加新选中的元素
// currentArr.forEach(item => {
// if (someArr.indexOf(item) === -1) {
// let checkName = plainOptions.find(ele => ele.value === item);
// newCheckList.push(checkName);
// }
// });
// } else if (checkType === 'del') {
// // 删除取消勾选的元素
// preArr.forEach(item => {
// if (someArr.indexOf(item) === -1) {
// newCheckList.splice(newCheckList.findIndex(ele => ele.value === item), 1);
// }
// });
// }
// callback(checkedList, newCheckList);
// }
// }, [checkedList]);
// 获取勾选新增得数据
const addData = (arr1, arr2) => arr2.filter(val => arr1.indexOf(val) === -1);
// 获取勾选删除得数据
const delData = (arr1, arr2) => arr1.filter(val => arr2.indexOf(val) === -1);
// 单选监听
const onChange = list => {
let newCheckList = [...checkList];
let arr;
if (checkedList.length > list.length) {
// 取消勾选
arr = delData(checkedList, list);
arr.forEach(item => {
newCheckList.splice(newCheckList.findIndex(ele => ele.value === item), 1);
});
} else {
// 勾选元素
arr = addData(checkedList, list);
arr.forEach(item => {
let checkName = plainOptions.find(ele => ele.value === item);
newCheckList.push(checkName);
});
}
callback(newCheckList);
setCheckedList(list);
setIndeterminate(!!list.length && list.length < plainOptions.length);
setCheckAll(list.length === plainOptions.length);
};
// 全选监听
const onCheckAllChange = e => {
setCheckedList(
e.target.checked ? plainOptions.map(item => item.value) : [],
);
let newCheckList = [...checkList];
let arr;
if (e.target.checked) {
// 全选
arr = addData(checkedList, plainOptions.map(item => item.value));
arr.forEach(item => {
let checkName = plainOptions.find(ele => ele.value === item);
newCheckList.push(checkName);
});
} else {
arr = delData(checkedList, []);
arr.forEach(item => {
newCheckList.splice(newCheckList.findIndex(ele => ele.value === item), 1);
});
}
callback(newCheckList);
setCheckedList(e.target.checked ? plainOptions.map(item => item.value) : []);
setIndeterminate(false);
setCheckAll(e.target.checked);
};
......
......@@ -26,8 +26,8 @@ const PushTest = props => {
}
}, [visible]);
// 选中后得回调函数
const checkCallBack = useCallback((val, newCheckList) => {
if (val) {
const checkCallBack = useCallback(newCheckList => {
if (newCheckList) {
setCheckList(newCheckList);
}
});
......@@ -43,9 +43,7 @@ const PushTest = props => {
theme: pushTestMsg.ThemeName,
msgType: pushTestMsg.MsgType,
tousers: checkList.map(item => item.value),
pushPath: pushTestMsg.item.AgentConfig
? pushTestMsg.item.AgentConfig.Url
: '',
pushPath: pushTestMsg.item.AgentConfig ? pushTestMsg.item.AgentConfig.Url : '',
msgTypeId: pushTestMsg.ID.toString(),
})
.then(res => {
......@@ -103,10 +101,7 @@ const PushTest = props => {
value: val.userId,
};
});
if (
checkedList.length === options.length &&
checkedList.length > 0
) {
if (checkedList.length === options.length && checkedList.length > 0) {
checkAll = true;
}
if (checkedList.length < options.length && checkedList.length > 0) {
......@@ -181,9 +176,7 @@ const PushTest = props => {
<CardCheck
cardMsg={item}
cardIndex={index}
callback={(val, newCheckList) =>
checkCallBack(val, newCheckList)
}
callback={(val, newCheckList) => checkCallBack(val, newCheckList)}
checkList={checkList}
/>
</div>
......@@ -193,9 +186,7 @@ const PushTest = props => {
{/* 分页 */}
<Pagination
total={total}
showTotal={(totals, range) =>
`第${range[0]}-${range[1]} 条/共 ${totals} 条`
}
showTotal={(totals, range) => `第${range[0]}-${range[1]} 条/共 ${totals} 条`}
defaultPageSize={pageSize}
defaultCurrent={1}
current={currentPage}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment