| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- import axios from './instance'
- import { VIEW_LIST, INSERT_VIEW, DELETE_VIEW, UPDATE_VIEW } from './constant'
- import type { Scene } from './scene'
- import { params } from '@/env'
- export type View = {
- id: string
- cover: string
- title: string
- sort: number
- flyData: string,
- } & ({ fusionId: number, num: null, numType: null } | { fusionId: null, num: string, numType: Scene['type'] })
- type ServiceView = {
- viewId: number
- viewTitle: string
- viewPoint: string
- viewImg: string
- sort: number
- } & ({ fusionId: string, num: null, numType: null } | { fusionId: null, num: string, numType: Scene['type'] })
- const toLocal = (serviceView: ServiceView) : View => ({
- id: serviceView.viewId.toString(),
- cover: serviceView.viewImg,
- title: serviceView.viewTitle,
- sort: serviceView.sort,
- flyData: JSON.parse(serviceView.viewPoint),
- num: serviceView.num,
- numType: serviceView.numType,
- fusionId: serviceView.fusionId ? Number(serviceView.fusionId) : null
- } as View)
- const toService = (view: View, isUpdate = true): PartialProps<ServiceView, 'viewId'> => ({
- viewId: isUpdate ? Number(view.id) : undefined,
- viewTitle: view.title,
- viewPoint: JSON.stringify(view.flyData),
- viewImg: view.cover,
- sort: view.sort,
- num: view.num,
- numType: view.numType,
- fusionId: view.fusionId ? view.fusionId.toString() : null
- })
- export type Views = View[]
- export const fetchViews = async () => {
- const data = await axios.get<ServiceView[]>(VIEW_LIST, { params: { caseId: params.caseId } })
- return data.map(toLocal)
- }
- export const postAddView = async (view: View) => {
- const serviceView = await axios.post<ServiceView>(INSERT_VIEW, { ...toService(view, false), caseId: params.caseId })
- return toLocal(serviceView)
- }
- export const postUpdateView = async (view: View) => {
- await axios.post(UPDATE_VIEW, toService(view))
- }
- export const postDeleteView = async (id: View['id']) => {
- await axios.post(DELETE_VIEW, { viewId: Number(id) })
- }
|