UNPKG

ilead-ibpmp-design-new

Version:

基于 `vue` 和 `bpmn.io@7.0` ,实现 flowable 的 modeler 模型设计器

86 lines (84 loc) 2.43 kB
/* * @Author: your name * @Date: 2021-01-04 17:19:45 * @LastEditTime: 2021-01-04 17:27:56 * @LastEditors: Please set LastEditors * @Description: In User Settings Edit * @FilePath: \cud-workflow-uid:\work\workflow\ilead-ibpmp-design\package\views\common\http\axios.js */ import axios from 'axios' const addErrorLog = errorInfo => { // const { statusText, status, request: { responseURL }} = errorInfo // const info = { // type: 'ajax', // code: status, // mes: statusText, // url: responseURL // } // if (!responseURL.includes('save_error_logger')) store.dispatch('addErrorLog', info) } class HttpRequest { // eslint-disable-next-line no-undef constructor(baseUrl = baseURL) { this.baseUrl = baseUrl this.queue = {} } getInsideConfig() { // TODO 放到Config统一配置 const config = { baseURL: this.baseUrl, headers: { 'Content-Type': 'application/json;charset=UTF-8', 'X-Requested-With': 'XMLHttpRequest' }, timeout: 50000, withCredentials: true } return config } destroy(url) { delete this.queue[url] if (!Object.keys(this.queue).length) { // Spin.hide() } } interceptors(instance, url) { // 请求拦截 instance.interceptors.request.use(config => { // 添加全局的loading... if (!Object.keys(this.queue).length) { // Spin.show() // 不建议开启,因为界面不友好 } this.queue[url] = true return config }, error => { return Promise.reject(error) }) // 响应拦截 instance.interceptors.response.use(res => { this.destroy(url) const { data, status } = res return { data, status, res } }, error => { this.destroy(url) let errorInfo = error.response if (!errorInfo) { const { request: { statusText, status }, config } = JSON.parse(JSON.stringify(error)) errorInfo = { statusText, status, request: { responseURL: config.url } } } addErrorLog(errorInfo) return Promise.reject(error) }) } request(options) { const instance = axios.create() options = Object.assign(this.getInsideConfig(), options) this.interceptors(instance, options.url) return instance(options) } } export default HttpRequest