import * as informationServices from '@12333/services/api/Information';
|
import { Message } from '@12333/utils';
|
|
type UseInformationActionsOptions = {
|
onDeleteSuccess?: () => void;
|
onAttentOrNotSuccess?: () => void;
|
};
|
|
export function useInformationActions(options: UseInformationActionsOptions = {}) {
|
const { onDeleteSuccess, onAttentOrNotSuccess } = options;
|
|
async function handleDelete(id: string) {
|
try {
|
await Message.confirm();
|
let res = await informationServices.deleteInformation({
|
id: id,
|
});
|
if (res) {
|
Message.success('操作成功');
|
onDeleteSuccess?.();
|
}
|
} catch (error) {}
|
}
|
|
async function handleCancelAttention(id: string) {
|
try {
|
await Message.confirm({ message: '是否取消收藏' });
|
let params: API.APIattentOrNotParams = {
|
informationId: id,
|
};
|
let res = await informationServices.attentOrNot(params);
|
if (res) {
|
Message.success('已取消收藏');
|
onAttentOrNotSuccess?.();
|
}
|
} catch (error) {}
|
}
|
|
return { handleDelete, handleCancelAttention };
|
}
|