import axios from 'axios';
import { MessagePlugin } from 'tdesign-vue-next';

const instance = axios.create({
  timeout: 6000000,
  // withCredentials: mode == 'development' ? false : true,
  withCredentials: false,
});
// 请求头
instance.interceptors.request.use((config: any) => {
  return config;
});
instance.interceptors.response.use(
  (response) => {
    const { data } = response;
    if (data.code === 0) {
      return data;
    } else {
      MessagePlugin.error(data.msg || '请求错误');
      return Promise.reject(data.msg);
    }
  },
  (err) => {
    console.log(err);
    if ('response' in err) {
      const { message: msg } = err.response.data;
      MessagePlugin.error(msg || '请求错误');
      return err.response;
    }
  }
);

export default instance;
