Tag.ts 1.64 KB
import { AnyObject, Option, QueryForParams, ServiceResponse } from '@/types/global';

import { Tag } from '@/types/tag';
import axios from 'axios';

export default class useTagApi {
  static typeOption = [
    { label: '歌曲标签', value: 1 },
    { label: '身份标签', value: 2 },
    { label: '声音标签', value: 3 },
    { label: '认证标签', value: 4 },
  ];

  static showOption = [
    { label: '显示', value: 1 },
    { label: '隐藏', value: 0 },
  ];

  static filterOption = [
    { label: '允许', value: 1 },
    { label: '禁止', value: 0 },
  ];

  static certifyPermissionOption = [
    { label: '听', value: 1 },
    { label: '唱', value: 2 },
  ];

  static async get(params?: QueryForParams): Promise<ServiceResponse<Tag[]>> {
    return axios.get('system/tags', { params });
  }

  static async create(data: AnyObject): Promise<Tag> {
    return axios.post('system/tags', data).then((res) => Promise.resolve(res.data));
  }

  static async show(id: number, params?: QueryForParams): Promise<Tag> {
    return axios.get(`system/tags/${id}`, { params }).then((res) => Promise.resolve(res.data));
  }

  static async update(id: number, data: AnyObject): Promise<Tag> {
    return axios.put(`system/tags/${id}`, data).then((res) => Promise.resolve(res.data));
  }

  static async destroy(id: number) {
    return axios.delete(`system/tags/${id}`).then((res) => Promise.resolve(res.data));
  }

  static async getOption(params?: QueryForParams): Promise<Option[]> {
    return useTagApi.get({ ...params, fetchType: 'all' }).then(({ data }) =>
      data?.map((item) => {
        return { value: item.id, label: item.name };
      })
    );
  }
}