tagging.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import axios from './instance'
  2. import { params } from '@/env'
  3. import {
  4. TAGGING_LIST,
  5. DELETE_TAGGING,
  6. INSERT_TAGGING,
  7. UPDATE_TAGGING
  8. } from './constant'
  9. import type { FuseModel } from './fuse-model'
  10. import { TaggingPosition, TaggingPositionType } from './tagging-position'
  11. import type { TaggingStyle } from './tagging-style'
  12. import { Tagging3DProps } from '@/sdk'
  13. interface ServerTagging {
  14. "hotIconId": number,
  15. "hotIconUrl": string,
  16. "getMethod": string,
  17. "getUser": string,
  18. "tagId": number,
  19. "tagImgUrl": string,
  20. "leaveBehind": string,
  21. "tagDescribe": string,
  22. "tagTitle": string,
  23. show3dTitle: number
  24. audio: string
  25. fileName: string
  26. }
  27. export interface Tagging {
  28. id: string
  29. styleId: TaggingStyle['id']
  30. title: string,
  31. show3dTitle: boolean
  32. desc: string
  33. part: string
  34. method: string
  35. principal: string
  36. images: string[],
  37. audio: string
  38. audioName: string
  39. }
  40. export type Taggings = Tagging[]
  41. const serviceToLocal = (serviceTagging: ServerTagging): Tagging => ({
  42. id: serviceTagging.tagId.toString(),
  43. styleId: serviceTagging.hotIconId.toString(),
  44. title: serviceTagging.tagTitle,
  45. desc: serviceTagging.tagDescribe,
  46. part: serviceTagging.leaveBehind,
  47. // show3dTitle: true,
  48. audioName: serviceTagging.fileName,
  49. show3dTitle: Boolean(serviceTagging.show3dTitle),
  50. method: serviceTagging.getMethod,
  51. principal: serviceTagging.getUser,
  52. audio: serviceTagging.audio,
  53. images: JSON.parse(serviceTagging.tagImgUrl),
  54. })
  55. const localToService = (tagging: Tagging, update = false): PartialProps<ServerTagging, 'tagId' | 'hotIconUrl'> & { fusionId: number } => ({
  56. "hotIconId": Number(tagging.styleId),
  57. "fusionId": params.caseId,
  58. "getMethod": tagging.method,
  59. show3dTitle: Number(tagging.show3dTitle),
  60. "getUser": tagging.principal,
  61. fileName: tagging.audioName,
  62. "hotIconUrl": "static/img_default/lQLPDhrvVzvNvTswMLAOU-UNqYnnZQG1YPJUwLwA_48_48.png",
  63. "tagId": update ? Number(tagging.id) : undefined,
  64. "tagImgUrl": JSON.stringify(tagging.images),
  65. "leaveBehind": tagging.part,
  66. "tagDescribe": tagging.desc,
  67. "tagTitle": tagging.title,
  68. audio: tagging.audio
  69. })
  70. export const fetchTaggings = async () => {
  71. const staggings = await axios.get<ServerTagging[]>(TAGGING_LIST, { params: { fusionId: params.caseId } })
  72. return staggings.map(serviceToLocal)
  73. }
  74. export const postAddTagging = async (tagging: Tagging) => {
  75. const stagging = await axios.post<ServerTagging>(INSERT_TAGGING, { ...localToService(tagging), fusionId: params.caseId })
  76. return serviceToLocal(stagging, )
  77. }
  78. export const postUpdateTagging = (tagging: Tagging) => {
  79. return axios.post<undefined>(UPDATE_TAGGING, { ...localToService(tagging, true), fusionId: params.caseId })
  80. }
  81. export const postDeleteTagging = (id: Tagging['id']) => {
  82. return axios.post<undefined>(DELETE_TAGGING, { tagId: id })
  83. }