dashboard.ts 2.03 KB
import { QueryForParams, ServiceResponse } from '@/types/global';
import axios, { AxiosRequestConfig } from 'axios';
import FileSaver from 'file-saver';

export default class useDashboardApi {
  static userCertify() {
    return axios.get('dashboard/user-certify').then((res) => Promise.resolve(res.data));
  }

  static userTotal() {
    return axios.get('dashboard/user-total').then((res) => Promise.resolve(res.data));
  }

  static userSkill() {
    return axios.get('dashboard/user-skill').then((res) => Promise.resolve(res.data));
  }

  static userStyle() {
    return axios.get('dashboard/user-style').then((res) => Promise.resolve(res.data));
  }

  static activityTotal() {
    return axios.get('dashboard/activity-total').then((res) => Promise.resolve(res.data));
  }

  static activityStyle() {
    return axios.get('dashboard/activity-style').then((res) => Promise.resolve(res.data));
  }

  static activityLike() {
    return axios.get('dashboard/activity-like').then((res) => Promise.resolve(res.data));
  }

  static activityListen() {
    return axios.get('dashboard/activity-listen').then((res) => Promise.resolve(res.data));
  }

  static overview(params?: QueryForParams) {
    return axios.get('dashboard/overview', { params }).then((res) => Promise.resolve(res.data));
  }

  static getOverviewExport(fileName: string, params?: QueryForParams) {
    const config = { params: { ...params, fetchType: 'excel' }, timeout: 60000, responseType: 'blob' } as AxiosRequestConfig;
    return axios.get('dashboard/overview', config).then(({ data }) => FileSaver.saveAs(data, `${fileName}.xlsx`));
  }

  static submitWork(params?: QueryForParams): Promise<ServiceResponse> {
    return axios.get('dashboard/submit-work', { params });
  }

  static getSubmitWorkExport(fileName: string, params?: QueryForParams) {
    const config = { params: { ...params, fetchType: 'excel' }, timeout: 60000, responseType: 'blob' } as AxiosRequestConfig;
    return axios.get('dashboard/submit-work', config).then(({ data }) => FileSaver.saveAs(data, `${fileName}.xlsx`));
  }
}