tagging.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 type { TaggingPosition } from './tagging-position'
  11. import type { TaggingStyle } from './tagging-style'
  12. interface ServerTagging {
  13. "hotIconId": number,
  14. "hotIconUrl": string,
  15. "getMethod": string,
  16. "getUser": string,
  17. "tagId": number,
  18. "tagImgUrl": string,
  19. "leaveBehind": string,
  20. "tagDescribe": string,
  21. "tagTitle": string,
  22. }
  23. export interface Tagging {
  24. id: string
  25. styleId: TaggingStyle['id']
  26. title: string,
  27. desc: string
  28. part: string
  29. method: string
  30. principal: string
  31. images: string[],
  32. }
  33. export type Taggings = Tagging[]
  34. const serviceToLocal = (serviceTagging: ServerTagging): Tagging => ({
  35. id: serviceTagging.tagId.toString(),
  36. styleId: serviceTagging.hotIconId.toString(),
  37. title: serviceTagging.tagTitle,
  38. desc: serviceTagging.tagDescribe,
  39. part: serviceTagging.leaveBehind,
  40. method: serviceTagging.getMethod,
  41. principal: serviceTagging.getUser,
  42. images: JSON.parse(serviceTagging.tagImgUrl)
  43. })
  44. const localToService = (tagging: Tagging, update = false): PartialProps<ServerTagging, 'tagId' | 'hotIconUrl'> & { fusionId: number } => ({
  45. "hotIconId": Number(tagging.styleId),
  46. "fusionId": params.caseId,
  47. "getMethod": tagging.method,
  48. "getUser": tagging.principal,
  49. "hotIconUrl": "static/img_default/lQLPDhrvVzvNvTswMLAOU-UNqYnnZQG1YPJUwLwA_48_48.png",
  50. "tagId": update ? Number(tagging.id) : undefined,
  51. "tagImgUrl": JSON.stringify(tagging.images),
  52. "leaveBehind": tagging.part,
  53. "tagDescribe": tagging.desc,
  54. "tagTitle": tagging.title,
  55. })
  56. export const fetchTaggings = async () => {
  57. const staggings = await axios.get<ServerTagging[]>(TAGGING_LIST, { params: { caseId: params.caseId } })
  58. return staggings.map(serviceToLocal)
  59. }
  60. export const postAddTagging = async (tagging: Tagging) => {
  61. const stagging = await axios.post<ServerTagging>(INSERT_TAGGING, { ...localToService(tagging), caseId: params.caseId })
  62. return serviceToLocal(stagging, )
  63. }
  64. export const postUpdateTagging = (tagging: Tagging) => {
  65. return axios.post<undefined>(UPDATE_TAGGING, { ...localToService(tagging, true), caseId: params.caseId })
  66. }
  67. export const postDeleteTagging = (id: Tagging['id']) => {
  68. return axios.post<undefined>(DELETE_TAGGING, { tagId: id })
  69. }