2025-10-22 14:43:42 +08:00
|
|
|
import { message as antdMessage } from "antd";
|
|
|
|
|
import { uniqBy } from "lodash-es";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 检查数组中是否存在重复项
|
|
|
|
|
*/
|
2025-11-18 15:26:31 +08:00
|
|
|
export default function useIsExistenceDuplicateSelection() {
|
|
|
|
|
const IsExistenceDuplicateSelection = (options) => {
|
|
|
|
|
const { data, key, message = "存在重复项,请勿重复选择" } = options;
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
if (uniqBy(data, key).length !== data.length) {
|
|
|
|
|
antdMessage.error(message);
|
|
|
|
|
reject(new Error(message));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
resolve();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return IsExistenceDuplicateSelection;
|
2025-10-22 14:43:42 +08:00
|
|
|
}
|