import axios from './instance' import { params } from '@/env' import { TAGGING_LIST, DELETE_TAGGING, INSERT_TAGGING, UPDATE_TAGGING } from './constant' import type { FuseModel } from './fuse-model' import { TaggingPosition, TaggingPositionType } from './tagging-position' import type { TaggingStyle } from './tagging-style' import { Tagging3DProps } from '@/sdk' interface ServerTagging { "hotIconId": number, "hotIconUrl": string, "getMethod": string, "getUser": string, "tagId": number, "tagImgUrl": string, "leaveBehind": string, "tagDescribe": string, "tagTitle": string, show3dTitle: number audio: string fileName: string } export interface Tagging { id: string styleId: TaggingStyle['id'] title: string, show3dTitle: boolean desc: string part: string method: string principal: string images: string[], audio: string audioName: string } export type Taggings = Tagging[] const serviceToLocal = (serviceTagging: ServerTagging): Tagging => ({ id: serviceTagging.tagId.toString(), styleId: serviceTagging.hotIconId.toString(), title: serviceTagging.tagTitle, desc: serviceTagging.tagDescribe, part: serviceTagging.leaveBehind, // show3dTitle: true, audioName: serviceTagging.fileName, show3dTitle: Boolean(serviceTagging.show3dTitle), method: serviceTagging.getMethod, principal: serviceTagging.getUser, audio: serviceTagging.audio, images: JSON.parse(serviceTagging.tagImgUrl), }) const localToService = (tagging: Tagging, update = false): PartialProps & { fusionId: number } => ({ "hotIconId": Number(tagging.styleId), "fusionId": params.caseId, "getMethod": tagging.method, show3dTitle: Number(tagging.show3dTitle), "getUser": tagging.principal, fileName: tagging.audioName, "hotIconUrl": "static/img_default/lQLPDhrvVzvNvTswMLAOU-UNqYnnZQG1YPJUwLwA_48_48.png", "tagId": update ? Number(tagging.id) : undefined, "tagImgUrl": JSON.stringify(tagging.images), "leaveBehind": tagging.part, "tagDescribe": tagging.desc, "tagTitle": tagging.title, audio: tagging.audio }) export const fetchTaggings = async () => { const staggings = await axios.get(TAGGING_LIST, { params: { fusionId: params.caseId } }) return staggings.map(serviceToLocal) } export const postAddTagging = async (tagging: Tagging) => { const stagging = await axios.post(INSERT_TAGGING, { ...localToService(tagging), fusionId: params.caseId }) return serviceToLocal(stagging, ) } export const postUpdateTagging = (tagging: Tagging) => { return axios.post(UPDATE_TAGGING, { ...localToService(tagging, true), fusionId: params.caseId }) } export const postDeleteTagging = (id: Tagging['id']) => { return axios.post(DELETE_TAGGING, { tagId: id }) }