import axios from './instance' import { TAGGING_LIST, DELETE_TAGGING, INSERT_TAGGING, UPDATE_TAGGING } from './constant' import type { Model } from './model' interface ServerTagging { "hotIconId": number, "hotIconUrl": string, "getMethod": string, "getUser": string, "id": number, "meta": { "name": string, "url": string } [], "remark": string, "tagDescribe": string, "tagTitle": string, } export interface TaggingPosition { modelId: Model['id'] localPos: SceneLocalPos } export interface Tagging { id: string styleId: string title: string, desc: string part: string method: string principal: string images: string[], positions: TaggingPosition[] } export type Taggings = Tagging[] const serviceToLocal = (serviceTagging: ServerTagging): Tagging => ({ id: serviceTagging.id.toString(), styleId: serviceTagging.hotIconId.toString(), title: serviceTagging.tagTitle, desc: serviceTagging.tagDescribe, part: serviceTagging.remark, method: serviceTagging.getMethod, principal: serviceTagging.getUser, images: serviceTagging.meta.map(({url}) => url), positions: [] }) const localToService = (tagging: Tagging): ServerTagging => ({ "hotIconId": Number(tagging.styleId), "hotIconUrl": tagging.styleId, "getMethod": tagging.method, "getUser": tagging.principal, "id": Number(tagging.id), "meta": tagging.images.map(((item, i) => ({ "name": item, "url": item }))), "remark": tagging.part, "tagDescribe": tagging.desc, "tagTitle": tagging.title, }) export const fetchTaggings = async () => { const staggings = await axios.post(TAGGING_LIST, {}) return staggings.map(serviceToLocal) } export const postAddTagging = async (tagging: Tagging) => { const stagging = await axios.post(INSERT_TAGGING, tagging) return serviceToLocal(stagging) } export const postUpdateTagging = (tagging: Tagging) => { return axios.post(UPDATE_TAGGING, localToService(tagging)) } export const postDeleteTagging = (id: Tagging['id']) => { return axios.post(DELETE_TAGGING, { ids: [id] }) }