auth.ts 841 Bytes
import axios from 'axios';
import { SystemPermission } from '@/types/system-permission';
import { AttributeData } from '@/types/global';
import FileSaver from 'file-saver';

type AuthResponse = {
  user: { id?: number; nick_name?: string; real_name?: string; avatar?: string; email?: string };
  permissions: string[];
  menus: SystemPermission[];
};

export default class useAuthApi {
  static async info(): Promise<AuthResponse> {
    return axios.get('/auth/info').then((res) => Promise.resolve(res.data));
  }

  static async changePwd(data: AttributeData) {
    return axios.patch('/auth/change-pwd', data).then((res) => Promise.resolve(res.data));
  }

  static async downloadFile(url: string, fileName: string) {
    // ?response-content-type=Blob
    FileSaver.saveAs(`${url}`, fileName + url.substring(url.lastIndexOf('.')));
  }
}