tagging.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. TAGGING_TYPE_LIST
  9. } from './constant'
  10. import type { FuseModel } from './fuse-model'
  11. import { TaggingPosition, TaggingPositionType } from './tagging-position'
  12. import { getStyleDictId, type TaggingStyle } from './tagging-style'
  13. import { Tagging3DProps } from '@/sdk'
  14. interface ServerTagging {
  15. "hotIconId": number,
  16. "hotIconUrl": string,
  17. "getMethod": string,
  18. dictId?: string
  19. "getUser": string,
  20. "tagId": number,
  21. "tagImgUrl": string,
  22. "leaveBehind": string,
  23. "tagDescribe": string,
  24. "tagTitle": string,
  25. show3dTitle: number
  26. audio: string
  27. fileName: string
  28. // 提取状态
  29. tqStatus?: tqStatusEnum,
  30. // 提取时间
  31. tqTime?: string
  32. }
  33. export interface Tagging {
  34. id: string
  35. styleId: TaggingStyle['id']
  36. title: string,
  37. show3dTitle: boolean
  38. desc: string
  39. part: string
  40. method: string
  41. principal: string
  42. images: string[],
  43. audio: string
  44. audioName: string
  45. // 提取状态
  46. tqStatus?: tqStatusEnum,
  47. // 提取时间
  48. tqTime?: string
  49. }
  50. export enum tqStatusEnum {
  51. UN = '未送检',
  52. ING = '送检中',
  53. END = '完成检验'
  54. }
  55. export type Taggings = Tagging[]
  56. const serviceToLocal = (serviceTagging: ServerTagging): Tagging => ({
  57. id: serviceTagging.tagId.toString(),
  58. styleId: serviceTagging.hotIconId.toString(),
  59. title: serviceTagging.tagTitle,
  60. desc: serviceTagging.tagDescribe,
  61. part: serviceTagging.leaveBehind,
  62. // show3dTitle: true,
  63. audioName: serviceTagging.fileName,
  64. show3dTitle: Boolean(serviceTagging.show3dTitle),
  65. method: serviceTagging.getMethod,
  66. principal: serviceTagging.getUser,
  67. audio: serviceTagging.audio,
  68. images: JSON.parse(serviceTagging.tagImgUrl),
  69. // 提取状态
  70. tqStatus: serviceTagging.tqStatus,
  71. // 提取时间
  72. tqTime: serviceTagging.tqTime
  73. })
  74. const localToService = (tagging: Tagging, update = false): PartialProps<ServerTagging, 'tagId' | 'hotIconUrl'> & { fusionId: number } => ({
  75. "hotIconId": Number(tagging.styleId),
  76. "fusionId": params.caseId,
  77. "getMethod": tagging.method,
  78. show3dTitle: Number(tagging.show3dTitle),
  79. dictId: getStyleDictId(Number(tagging.styleId))?.toString(),
  80. "getUser": tagging.principal,
  81. fileName: tagging.audioName,
  82. "hotIconUrl": "static/img_default/lQLPDhrvVzvNvTswMLAOU-UNqYnnZQG1YPJUwLwA_48_48.png",
  83. "tagId": update ? Number(tagging.id) : undefined,
  84. "tagImgUrl": JSON.stringify(tagging.images),
  85. "leaveBehind": tagging.part,
  86. "tagDescribe": tagging.desc,
  87. "tagTitle": tagging.title,
  88. audio: tagging.audio,
  89. // 提取状态
  90. tqStatus: tagging.tqStatus,
  91. // 提取时间
  92. tqTime: tagging.tqTime
  93. })
  94. export const fetchTaggings = async () => {
  95. axios.get(TAGGING_TYPE_LIST)
  96. const staggings = await axios.get<ServerTagging[]>(TAGGING_LIST, { params: { fusionId: params.caseId } })
  97. return staggings.map(serviceToLocal)
  98. }
  99. export const postAddTagging = async (tagging: Tagging) => {
  100. const stagging = await axios.post<ServerTagging>(INSERT_TAGGING, { ...localToService(tagging), fusionId: params.caseId })
  101. return serviceToLocal(stagging, )
  102. }
  103. export const postUpdateTagging = (tagging: Tagging) => {
  104. return axios.post<undefined>(UPDATE_TAGGING, { ...localToService(tagging, true), fusionId: params.caseId })
  105. }
  106. export const postDeleteTagging = (id: Tagging['id']) => {
  107. return axios.post<undefined>(DELETE_TAGGING, { tagId: id })
  108. }