usePush.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { ref } from 'vue';
  2. import { RobotType, getRobot, addRobot, editRobot, delRobot } from '@/api/push/push';
  3. import { useRequest } from 'vue-hooks-plus';
  4. export const usePush = () => {
  5. const robotPushList = ref<RobotType[]>([]);
  6. const total = ref(0);
  7. const page = ref(1);
  8. const size = ref(10);
  9. // 查询
  10. const robotSearch = () => {
  11. const params = {
  12. pageNumber: page.value,
  13. pageSize: size.value,
  14. };
  15. return getRobot(params).then((res) => {
  16. return res;
  17. });
  18. };
  19. const { loading, run: getRobotList } = useRequest(robotSearch, {
  20. manual: true,
  21. onSuccess: (res) => {
  22. robotPushList.value = [...res.records];
  23. total.value = res.totalRow;
  24. },
  25. });
  26. const robotAdd = (data: RobotType) => {
  27. return addRobot(data).then(() => {
  28. getRobotList();
  29. });
  30. };
  31. const robotDel = (id: number) => {
  32. return delRobot(id).then(() => {
  33. getRobotList();
  34. });
  35. };
  36. const robotEdit = (data: RobotType) => {
  37. return editRobot(data).then(() => {
  38. getRobotList();
  39. });
  40. };
  41. return {
  42. robotPushList,
  43. total,
  44. page,
  45. size,
  46. loading,
  47. robotSearch,
  48. getRobotList,
  49. robotAdd,
  50. robotDel,
  51. robotEdit,
  52. };
  53. };
  54. export default usePush;