project.api.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { http } from '@/api/http'
  2. import { httpErrorHandle } from '@/utils'
  3. import { ContentTypeEnum, RequestHttpEnum, ModuleTypeEnum } from '@/enums/httpEnum'
  4. import { ProjectItem, ProjectDetail } from './project'
  5. // * 项目列表
  6. export const projectListApi = async (data: object) => {
  7. try {
  8. const res = await http(RequestHttpEnum.GET)<ProjectItem[]>(`${ModuleTypeEnum.PROJECT}/list`, data)
  9. return res
  10. } catch {
  11. httpErrorHandle()
  12. }
  13. }
  14. // * 新增项目
  15. export const createProjectApi = async (data: object) => {
  16. try {
  17. const res = await http(RequestHttpEnum.POST)<{
  18. /**
  19. * 项目id
  20. */
  21. id: number
  22. }>(`${ModuleTypeEnum.PROJECT}/create`, data)
  23. return res
  24. } catch {
  25. httpErrorHandle()
  26. }
  27. }
  28. // * 获取项目
  29. export const fetchProjectApi = async (data: object) => {
  30. try {
  31. const res = await http(RequestHttpEnum.GET)<ProjectDetail>(`${ModuleTypeEnum.PROJECT}/getData`, data)
  32. return res
  33. } catch {
  34. httpErrorHandle()
  35. }
  36. }
  37. // * 保存项目
  38. export const saveProjectApi = async (data: object) => {
  39. try {
  40. const res = await http(RequestHttpEnum.POST)(
  41. `${ModuleTypeEnum.PROJECT}/save/data`,
  42. data,
  43. ContentTypeEnum.FORM_URLENCODED
  44. )
  45. return res
  46. } catch {
  47. httpErrorHandle()
  48. }
  49. }
  50. // * 修改项目基础信息
  51. export const updateProjectApi = async (data: object) => {
  52. try {
  53. const res = await http(RequestHttpEnum.POST)(`${ModuleTypeEnum.PROJECT}/edit`, data)
  54. return res
  55. } catch {
  56. httpErrorHandle()
  57. }
  58. }
  59. // * 删除项目
  60. export const deleteProjectApi = async (data: object) => {
  61. try {
  62. const res = await http(RequestHttpEnum.DELETE)(`${ModuleTypeEnum.PROJECT}/delete`, data)
  63. return res
  64. } catch {
  65. httpErrorHandle()
  66. }
  67. }
  68. // * 修改发布状态 [-1未发布,1发布]
  69. export const changeProjectReleaseApi = async (data: object) => {
  70. try {
  71. const res = await http(RequestHttpEnum.PUT)(`${ModuleTypeEnum.PROJECT}/publish`, data)
  72. return res
  73. } catch {
  74. httpErrorHandle()
  75. }
  76. }
  77. // * 上传文件
  78. export const uploadFile = async (data: object) => {
  79. try {
  80. const res = await http(RequestHttpEnum.POST)<{
  81. /**
  82. * 文件地址
  83. */
  84. fileName: string
  85. }>(`${ModuleTypeEnum.PROJECT}/upload`, data, ContentTypeEnum.FORM_DATA)
  86. return res
  87. } catch {
  88. httpErrorHandle()
  89. }
  90. }