123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- import axios from './instance'
- import { TAGGING_STYLE_LIST, INSERT_TAGGING_STYLE, DELETE_TAGGING_STYLE, UPLOAD_HEADS } from './constant'
- import { jsonToForm } from '@/utils'
- import { params } from '@/env'
- interface ServiceStyle {
- iconId: number,
- iconTitle: string,
- iconUrl: string,
- isSystem: number
- lastUse: 1 | 0
- }
- export interface TaggingStyle {
- id: string
- icon: string
- name: string
- lastUse: 1 | 0
- default: boolean
- }
- const toLocal = (serviceStyle: ServiceStyle) : TaggingStyle => ({
- id: serviceStyle.iconId.toString(),
- lastUse: serviceStyle.lastUse,
- name: serviceStyle.iconTitle,
- icon: serviceStyle.iconUrl,
- default: Boolean(serviceStyle.isSystem)
- })
- const toService = (style: TaggingStyle): ServiceStyle => ({
- iconId: Number(style.id),
- iconTitle: style.name,
- lastUse: style.lastUse,
- iconUrl: style.icon,
- isSystem: Number(style.default)
- })
- export type TaggingStyles = TaggingStyle[]
- export const fetchTaggingStyles = async () => {
- const reqParams = params.share ? { caseId: params.caseId } : { }
- const data = await axios.get<ServiceStyle[]>(TAGGING_STYLE_LIST, { params: reqParams })
- return data.map(toLocal)
- }
- export const postAddTaggingStyle = async (props: {file: Blob, iconTitle: string}) => {
-
- const data = await axios<ServiceStyle>({
- method: 'POST',
- headers: UPLOAD_HEADS,
- url: INSERT_TAGGING_STYLE,
- data: jsonToForm({
- file: new File([props.file], `${props.iconTitle}.png`),
- iconTitle: props.iconTitle,
- caseId: params.caseId
- })
- })
- return toLocal(data)
- }
- export const postDeleteTaggingStyle = async (id: TaggingStyle['id']) => {
- await axios.post(DELETE_TAGGING_STYLE, { iconId: Number(id) })
- }
|