| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- import axios from 'axios';
- import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
- import { message, notification } from 'ant-design-vue';
- import { h } from 'vue';
- const fetchApp = axios.create({
- baseURL: import.meta.env.VITE_API_APP_URL,
- headers: {
- 'Content-Type': 'application/json'
- }
- // timeout: 5000, // 请求超时时间
- });
- /**
- * 请求拦截器
- */
- fetchApp.interceptors.request.use(
- config => {
- // 可以在这里添加请求头等信息
- config.headers = {
- // token: localStorage.getItem("token"),
- 'Content-Type': 'application/json'
- };
- return config;
- },
- error => {
- // 请求错误处理
- console.log(error); // for debug
- Promise.reject(error);
- }
- );
- /**
- * 响应拦截器
- */
- fetchApp.interceptors.response.use(
- response => {
- const data = response.data;
- //console.log(response);
- // 对响应数据做处理,例如只返回data部分
- if (response.status === 200) {
- if (data.code === 0) {
- } else if (data.code === 401) {
- Promise.reject(data);
- } else if (data.code === -1) {
- message.error(data.errorMsg);
- }
- } else {
- notification.open({
- message: '提示',
- description: data.errorMsg,
- icon: () => h(ExclamationCircleOutlined, { style: 'color: #ff4d4f' }),
- onClick: () => {
- console.log('Notification Clicked!');
- }
- });
- }
- return data;
- },
- error => {
- // 响应错误处理
- console.log('err' + error); // for debug
- return Promise.reject(error);
- }
- );
- export default fetchApp;
|