zhengyiming
2025-02-10 0f686ea1fe4700a909a6159efcf1fcb0e1f88a17
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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 };
}