board.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import axios from './instance'
  2. import { DELETE_DRAW_FILE, GET_DRAW_FILE, INSERT_DRAW_FILE, UPDATE_DRAW_FILE } from 'constant'
  3. import type {
  4. brokenLine,
  5. text,
  6. table,
  7. rect,
  8. circular,
  9. arrow,
  10. icon,
  11. cigarette,
  12. fireoint,
  13. footPrint,
  14. shoePrint,
  15. fingerPrint,
  16. corpse,
  17. theBlood,
  18. } from 'views/draw-file/board'
  19. export interface Pos {
  20. x: number,
  21. y: number
  22. }
  23. interface ShapeData {
  24. color: string
  25. }
  26. interface CurrencyShapeData extends ShapeData {
  27. pos: Pos,
  28. width: number,
  29. height: number
  30. }
  31. export interface BrokenLineShapeData extends ShapeData {
  32. type: typeof brokenLine
  33. points: Pos[]
  34. }
  35. export interface TextShapeData extends ShapeData {
  36. type: typeof text
  37. text: string
  38. fontSize: number
  39. }
  40. export type TableShapeContentItem = { width: number, height: number, value: string, rowIndex: number, colIndex: number }
  41. export interface TableShapeData extends CurrencyShapeData {
  42. type: typeof table
  43. fontSize: number
  44. content: TableShapeContentItem[]
  45. }
  46. export interface RectShapeData extends CurrencyShapeData {
  47. type: typeof rect
  48. }
  49. export interface CircularShapeData extends CurrencyShapeData {
  50. type: typeof circular
  51. }
  52. export interface ArrowShapeData extends CurrencyShapeData {
  53. type: typeof arrow
  54. direction: number
  55. }
  56. export interface IconShapeData extends CurrencyShapeData {
  57. type: typeof icon
  58. index: number
  59. }
  60. export interface CigaretteShapeData extends CurrencyShapeData {
  61. type: typeof cigarette
  62. }
  63. export interface FireointShapeData extends CurrencyShapeData {
  64. type: typeof fireoint
  65. }
  66. export interface FootPrintShapeData extends CurrencyShapeData {
  67. type: typeof footPrint
  68. }
  69. export interface ShoePrintShapeData extends CurrencyShapeData {
  70. type: typeof shoePrint
  71. }
  72. export interface FingerPrintShapeData extends CurrencyShapeData {
  73. type: typeof fingerPrint
  74. }
  75. export interface CorpseShapeData extends CurrencyShapeData {
  76. type: typeof corpse
  77. }
  78. export interface TheBloodShapeData extends CurrencyShapeData {
  79. type: typeof theBlood
  80. }
  81. export interface FootPrintShapeData extends CurrencyShapeData {
  82. type: typeof footPrint
  83. }
  84. export type BoardShapeData = BrokenLineShapeData | TextShapeData | TableShapeData | RectShapeData | CircularShapeData
  85. | ArrowShapeData | IconShapeData | CigaretteShapeData | FireointShapeData | FootPrintShapeData | ShoePrintShapeData
  86. | FingerPrintShapeData | CorpseShapeData | TheBloodShapeData
  87. export interface BoardData {
  88. id: number
  89. bgImage: string | null
  90. shapes: BoardShapeData[]
  91. }
  92. export enum BoardType {
  93. map = '0',
  94. scene = '1'
  95. }
  96. export const BoardTypeDesc = {
  97. [BoardType.map]: '方位图',
  98. [BoardType.scene]: '现场图',
  99. }
  100. export const getBoardById = (params: { id: number, type: BoardType }) => {
  101. axios.get<BoardData>(GET_DRAW_FILE, { params: params })
  102. return {
  103. id: params.id,
  104. shapes: [],
  105. bgImage: null
  106. }
  107. }
  108. export const delBoard = (params: { id: number }) => {
  109. axios.post<undefined>(DELETE_DRAW_FILE, params)
  110. }
  111. export const addBoard = (params: { type: BoardType, data: BoardData }) => {
  112. axios.post<BoardData>(INSERT_DRAW_FILE, params)
  113. return {
  114. ...params.data,
  115. id: 1,
  116. }
  117. }
  118. export const setBoard = (params: {id: number, data: BoardData}) => {
  119. axios.post<undefined>(UPDATE_DRAW_FILE, params)
  120. return params.data
  121. }