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 type { TaggingPosition } from './tagging-position' import type { TaggingStyle } from './tagging-style' interface ServerTagging { "hotIconId": number, "hotIconUrl": string, "getMethod": string, "getUser": string, "tagId": number, "tagImgUrl": string, "leaveBehind": string, "tagDescribe": string, "tagTitle": string, } export interface Tagging { id: string styleId: TaggingStyle['id'] title: string, desc: string part: string method: string principal: string images: 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, method: serviceTagging.getMethod, principal: serviceTagging.getUser, images: JSON.parse(serviceTagging.tagImgUrl) }) const localToService = (tagging: Tagging, update = false): PartialProps & { fusionId: number } => ({ "hotIconId": Number(tagging.styleId), "fusionId": params.caseId, "getMethod": tagging.method, "getUser": tagging.principal, "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, }) export const fetchTaggings = async () => { const staggings = await axios.get(TAGGING_LIST, { params: { caseId: params.caseId } }) return staggings.map(serviceToLocal) } export const postAddTagging = async (tagging: Tagging) => { const stagging = await axios.post(INSERT_TAGGING, { ...localToService(tagging), caseId: params.caseId }) return serviceToLocal(stagging, ) } export const postUpdateTagging = (tagging: Tagging) => { return axios.post(UPDATE_TAGGING, { ...localToService(tagging, true), caseId: params.caseId }) } export const postDeleteTagging = (id: Tagging['id']) => { return axios.post(DELETE_TAGGING, { tagId: id }) }