import axios from '../config/axiosConfig' import { AxiosRequestConfig, CustomSuccessData } from 'axios'; import { getValue } from '@/utils/common'; import { message } from 'ant-design-vue'; // 泛型接口 export interface Get { (url: string, params?: unknown, config?: AxiosRequestConfig): Promise>; } axios.interceptors.response.use((response)=>{ return response; },(error)=>{ message.error(error.response.data.message) return Promise.reject(error) }) const get: Get = async function (url: string, data?: unknown) { const res = await axios.get(url, {params:data}); return res.data; } const post: Get = async function (url: string, data?: unknown) { const res = await axios.post(url, data) return res.data; } const del: Get = async function (url: string, data?: unknown){ const res = await axios.delete(url, {params:data}) return res.data; } function setToken(){ axios.defaults.headers.common['Authorization'] = "Bearer " + getValue("token"); } export { get, post, del, setToken }