You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
992 B
44 lines
992 B
import axios from 'axios'
|
|
import { baseConfig } from './config'
|
|
import { ElLoading } from 'element-plus';
|
|
let loading;
|
|
// 创建axios实例
|
|
export function requestService(config: any) {
|
|
const service = axios.create({
|
|
baseURL: baseConfig.baseURL,
|
|
timeout: baseConfig.requestTimeout,
|
|
})
|
|
// request拦截器
|
|
service.interceptors.request.use(
|
|
(config) => {
|
|
console.log(config.url)
|
|
if(config.url!='/api/block/getSearch'){
|
|
loading = ElLoading.service({
|
|
lock: true,
|
|
text: 'Requesting data',
|
|
background: 'rgba(0, 0, 0, 0.8)',
|
|
spinner: 'el-icon-loading'
|
|
})
|
|
}
|
|
|
|
return config
|
|
},
|
|
(error) => {
|
|
console.log(error)
|
|
Promise.reject(error)
|
|
}
|
|
)
|
|
|
|
// 响应拦截器
|
|
service.interceptors.response.use(
|
|
(res) => {
|
|
loading.close()
|
|
return res.data
|
|
},
|
|
(error) => {
|
|
loading.close()
|
|
return Promise.reject(error)
|
|
}
|
|
)
|
|
return service(config)
|
|
}
|
|
|