123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- 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";
- import { ui18n } from "@/lang";
- interface ServiceStyle {
- iconId: number;
- iconTitle: string;
- iconUrl: string;
- isSystem: number;
- lastUse: 1 | 0;
- }
- export const defStyleType = {
- id: 8,
- name: ui18n.t('sys.other'),
- }
- export const styleTypes = [
- {
- id: 1,
- name: ui18n.t('tagging.type.1'),
- children: [
- { id: 2, name: ui18n.t('tagging.type.2') },
- { id: 3, name: ui18n.t('tagging.type.3') },
- { id: 4, name: ui18n.t('tagging.type.4') },
- { id: 5, name: ui18n.t('tagging.type.5') },
- { id: 6, name: ui18n.t('tagging.type.6') },
- ],
- },
- {
- id: 7,
- name: ui18n.t('tagging.type.7'),
- },
- defStyleType
- ];
- export const getStyleTypeName = (id: number, all = styleTypes): string => {
- for (const item of all) {
- if (id === item.id) {
- return item.name
- } else if ('children' in item && item.children) {
- const cname = getStyleTypeName(id, item.children)
- if (cname) {
- return cname
- }
- }
- }
- if (all === styleTypes) {
- return defStyleType.name
- } else {
- return ''
- }
- }
- export interface TaggingStyle {
- id: string;
- icon: string;
- typeId: number;
- lastUse: 1 | 0;
- default: boolean;
- }
- const toLocal = (serviceStyle: ServiceStyle): TaggingStyle => ({
- id: serviceStyle.iconId.toString(),
- lastUse: serviceStyle.lastUse,
- typeId: Number(serviceStyle.iconTitle) || defStyleType.id,
- icon: serviceStyle.iconUrl,
- default: Boolean(serviceStyle.isSystem),
- });
- const toService = (style: TaggingStyle): ServiceStyle => ({
- iconId: Number(style.id),
- iconTitle: style.typeId.toString(),
- 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.toString(),
- caseId: params.caseId,
- }),
- });
- return toLocal(data);
- };
- export const postDeleteTaggingStyle = async (id: TaggingStyle["id"]) => {
- await axios.post(DELETE_TAGGING_STYLE, { iconId: Number(id) });
- };
|