优化useIsExistenceDuplicateSelection
parent
2c1417109d
commit
ac49cf7b3d
|
|
@ -10,9 +10,14 @@ interface UseIsExistenceDuplicateSelectionOptions<T> {
|
|||
message?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查数组中是否存在重复项的函数
|
||||
*/
|
||||
interface IsExistenceDuplicateSelectionFunction {
|
||||
<T>(options: UseIsExistenceDuplicateSelectionOptions<T>): Promise<void>;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查数组中是否存在重复项
|
||||
*/
|
||||
export default function useIsExistenceDuplicateSelection<T>(
|
||||
options: UseIsExistenceDuplicateSelectionOptions<T>
|
||||
): Promise<void>;
|
||||
export default function useIsExistenceDuplicateSelection(): IsExistenceDuplicateSelectionFunction;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ import { uniqBy } from "lodash-es";
|
|||
/**
|
||||
* 检查数组中是否存在重复项
|
||||
*/
|
||||
export default function useIsExistenceDuplicateSelection(options) {
|
||||
export default function useIsExistenceDuplicateSelection() {
|
||||
const IsExistenceDuplicateSelection = (options) => {
|
||||
const { data, key, message = "存在重复项,请勿重复选择" } = options;
|
||||
return new Promise((resolve, reject) => {
|
||||
if (uniqBy(data, key).length !== data.length) {
|
||||
|
|
@ -16,3 +17,5 @@ export default function useIsExistenceDuplicateSelection(options) {
|
|||
}
|
||||
});
|
||||
}
|
||||
return IsExistenceDuplicateSelection;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue