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