123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- 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<ServerTagging[]>(TAGGING_LIST, {})
- return staggings.map(serviceToLocal)
- }
- export const postAddTagging = async (tagging: Tagging) => {
- const stagging = await axios.post<ServerTagging>(INSERT_TAGGING, tagging)
- return serviceToLocal(stagging)
- }
- export const postUpdateTagging = (tagging: Tagging) => {
- return axios.post<undefined>(UPDATE_TAGGING, localToService(tagging))
- }
-
- export const postDeleteTagging = (id: Tagging['id']) => {
- return axios.post<undefined>(DELETE_TAGGING, { ids: [id] })
- }
-
|