const BASE_URL = 'https://brain.zjhyai.com/chat/' import axios from "axios"; const request = ({ url, data = {}, method = 'get', header = { ContentType: 'application/json' }, }) => { let token = localStorage.getItem('token') || ''; if (!url) return; return new Promise((resolve, reject) => { axios({ url: BASE_URL + url, method, data, header: { token, ...header }, success: (res) => { console.log(res) if (res.statusCode === 200 && res.data.msg === 'success') { return resolve(res.data) } else if (res.statusCode === 403) { this.$notify.error({ title: '错误', message: res.data }); } else if (res.data.code === 8000) { this.$router.push({path:'/'}) // #endif // #ifdef H5 let ua = navigator.userAgent.toLowerCase(); if (ua.match(/MicroMessenger/i) == "micromessenger") { //是 this.$router.push({path:'/'}) } else { //不是 this.$router.push({path:'/'}) } this.$router.push({path:'/'}) } else { this.$notify.error({ title: '错误', message: res.data.msg }); } }, fail: (err) => { reject(err); } }); }) } export default request;