Files
labelmain/components/label/api/label/index.ts
2026-02-27 14:36:27 +08:00

133 lines
3.4 KiB
TypeScript

import httpFetch from "@/api/fetch"
import { BASE_LABEL_API } from "../const"
import {
LabelResult,
LoginInfo,
RequestLabelResult,
ServerResponse,
} from "./typing"
// 获取标注结果
export const getLabelResult = (task_id: number) => {
return httpFetch<{
task_id: number
results: LabelResult[]
}>({
url:
BASE_LABEL_API +
`/api/v1/label_server/task/label_result?task_id=${task_id}`,
method: "GET",
})
}
export const saveLabelResult = (data: RequestLabelResult) => {
return httpFetch({
url: BASE_LABEL_API + "/api/v1/label_server/task/label_result",
method: "POST",
body: JSON.stringify(data),
})
}
export const getServerImage = async (data: {
data_names: string[]
/**
* 0-图片 1-点云 2-视频
*/
data_type: number
flag?: number
project_id: number
}) => {
let data_type = data.data_type
return new Promise((resolve, reject) => {
httpFetch<ServerResponse>({
url: BASE_LABEL_API + "/api/v1/label_server/data/list",
method: "POST",
body: JSON.stringify(data),
}).then((res) => {
if (res.proxy) {
reject({ proxy: res.proxy, params: data })
} else {
if (res.data_list && res.data_list.length) {
const { image_data, video_data, pointcloud_data } = res.data_list[0]
resolve({
base64data:
data_type === 0
? image_data
: data_type === 2
? video_data
: pointcloud_data,
})
}
}
})
}).then(({ base64data }: any) => {
return base64data
})
// .catch(async ({ proxy, params }) => {
// try {
// const res = await httpFetch<ServerResponse>({
// url: `/http://${proxy}:9112/api/v1/label_sync/get_data_list`,
// method: "POST",
// body: JSON.stringify(params),
// })
// return res.data.data_list?.[0].image_data || ""
// } catch (error: unknown) {
// console.log(error)
// const res = await httpFetch<ServerResponse>({
// url: BASE_LABEL_API + "/api/v1/label_server/data/list",
// method: "POST",
// body: JSON.stringify({ ...params, flag: 1 }),
// })
// return res.data_list?.[0].image_data || ""
// }
// })
}
// 获取标注图片
export const getLabelImage = (activeImage: string, path: string) => {
return httpFetch<any>({
url:
BASE_LABEL_API +
`/api/v1/label_server/data/image?data_name=${encodeURIComponent(
activeImage
)}&project_path=${encodeURIComponent(path)}`,
method: "GET",
headerAttr: {
responseType: "blob",
},
})
}
// 辅助标注
export const getAuxiliaryAnnotation = (data: any) => {
return httpFetch<any>({
url: BASE_LABEL_API + "/api/model_server/sam2/sa",
method: "POST",
body: JSON.stringify(data),
headerAttr: {
responseType: "arraybuffer",
},
})
}
// 模型标注 追踪
export const getTrackingAuxiliaryAnnotation = (data: any) => {
return httpFetch<any>({
url: BASE_LABEL_API + "/api/model_server/sam2/vos",
method: "POST",
body: JSON.stringify(data),
headerAttr: {
responseType: "arraybuffer",
},
})
}
// 用户登录
export const userLogin = (data: { name: string; password: string }) => {
return httpFetch<LoginInfo>({
url: BASE_LABEL_API + "/api/v1/label_server/user/login",
method: "POST",
body: JSON.stringify(data),
})
}