goview_vue/src/api/path/project.api.ts

100 lines
2.3 KiB
TypeScript
Raw Normal View History

2022-05-20 16:12:27 +08:00
import { http } from '@/api/http'
import { httpErrorHandle } from '@/utils'
2022-05-24 15:05:51 +08:00
import { ContentTypeEnum, RequestHttpEnum, ModuleTypeEnum } from '@/enums/httpEnum'
import { ProjectItem, ProjectDetail } from './project'
2022-05-20 16:12:27 +08:00
2022-05-22 14:05:57 +08:00
// * 项目列表
export const projectListApi = async (data: object) => {
2022-11-27 12:16:32 +08:00
try {
const res = await http(RequestHttpEnum.GET)<ProjectItem[]>(`${ModuleTypeEnum.PROJECT}/list`, data)
return res
2022-05-22 14:05:57 +08:00
} catch {
2022-11-27 12:16:32 +08:00
httpErrorHandle()
2022-05-22 14:05:57 +08:00
}
}
// * 新增项目
export const createProjectApi = async (data: object) => {
2022-11-27 12:16:32 +08:00
try {
const res = await http(RequestHttpEnum.POST)<{
/**
* id
*/
id: number
}>(`${ModuleTypeEnum.PROJECT}/create`, data)
return res
2022-05-20 16:12:27 +08:00
} catch {
2022-11-27 12:16:32 +08:00
httpErrorHandle()
2022-05-20 16:12:27 +08:00
}
2022-05-22 15:25:07 +08:00
}
2022-05-22 22:11:56 +08:00
// * 获取项目
export const fetchProjectApi = async (data: object) => {
2022-11-27 12:16:32 +08:00
try {
const res = await http(RequestHttpEnum.GET)<ProjectDetail>(`${ModuleTypeEnum.PROJECT}/getData`, data)
2022-11-27 12:16:32 +08:00
return res
2022-05-22 22:11:56 +08:00
} catch {
2022-11-27 12:16:32 +08:00
httpErrorHandle()
2022-05-22 22:11:56 +08:00
}
}
// * 保存项目
export const saveProjectApi = async (data: object) => {
2022-11-27 12:16:32 +08:00
try {
const res = await http(RequestHttpEnum.POST)(
`${ModuleTypeEnum.PROJECT}/save/data`,
data,
ContentTypeEnum.FORM_URLENCODED
)
return res
} catch {
2022-11-27 12:16:32 +08:00
httpErrorHandle()
}
}
2022-05-26 01:01:59 +08:00
// * 修改项目基础信息
export const updateProjectApi = async (data: object) => {
try {
2022-11-27 12:16:32 +08:00
const res = await http(RequestHttpEnum.POST)(`${ModuleTypeEnum.PROJECT}/edit`, data)
return res
} catch {
2022-11-27 12:16:32 +08:00
httpErrorHandle()
}
}
2022-05-22 15:25:07 +08:00
// * 删除项目
export const deleteProjectApi = async (data: object) => {
2022-11-27 12:16:32 +08:00
try {
const res = await http(RequestHttpEnum.DELETE)(`${ModuleTypeEnum.PROJECT}/delete`, data)
return res
2022-05-22 15:25:07 +08:00
} catch {
2022-11-27 12:16:32 +08:00
httpErrorHandle()
2022-05-22 15:25:07 +08:00
}
}
// * 修改发布状态 [-1未发布,1发布]
export const changeProjectReleaseApi = async (data: object) => {
2022-11-27 12:16:32 +08:00
try {
const res = await http(RequestHttpEnum.PUT)(`${ModuleTypeEnum.PROJECT}/publish`, data)
return res
2022-05-27 20:09:48 +08:00
} catch {
2022-11-27 12:16:32 +08:00
httpErrorHandle()
2022-05-27 20:09:48 +08:00
}
}
// * 上传文件
export const uploadFile = async (data: object) => {
2022-11-27 12:16:32 +08:00
try {
const res = await http(RequestHttpEnum.POST)<{
/**
*
*/
2023-05-01 21:49:08 +08:00
fileName: string,
fileurl: string,
2022-11-27 12:16:32 +08:00
}>(`${ModuleTypeEnum.PROJECT}/upload`, data, ContentTypeEnum.FORM_DATA)
return res
} catch {
2022-11-27 12:16:32 +08:00
httpErrorHandle()
}
2022-11-27 12:16:32 +08:00
}