mirror of
https://github.com/zuiidea/antd-admin
synced 2026-11-17 21:25:06 +00:00
adjust request
This commit is contained in:
@@ -7,4 +7,7 @@ module.exports = {
|
||||
needLogin: true,
|
||||
iconFontUrl: '//at.alicdn.com/t/font_c4y7asse3q1cq5mi.js',
|
||||
baseURL: 'http://47.92.30.98:7001/api',
|
||||
crossDomains: [
|
||||
'http://www.zuimeitianqi.com',
|
||||
],
|
||||
}
|
||||
|
||||
+13
-6
@@ -10,7 +10,7 @@ const fetch = (options) => {
|
||||
} = options
|
||||
switch (method.toLowerCase()) {
|
||||
case 'get':
|
||||
return axios.get(url, data)
|
||||
return axios.get(`${url}${options.data ? `?${qs.stringify(options.data)}` : ''}`)
|
||||
case 'delete':
|
||||
return axios.delete(url, { data })
|
||||
case 'head':
|
||||
@@ -28,17 +28,24 @@ const fetch = (options) => {
|
||||
|
||||
export default function request (options) {
|
||||
if (options.url.indexOf('//') > -1) {
|
||||
const origin = `${options.url.split('//')[0]}//${options.url.split('//')[1].split('/')[0]}`
|
||||
if (window.location.origin !== origin && config.baseURL.indexOf(origin) < 0) {
|
||||
if (config.crossDomains && config.crossDomains.indexOf(`${options.url.split('//')[0]}//${options.url.split('//')[1].split('/')[0]}`) > -1) {
|
||||
options.isCross = true
|
||||
options.url = `http://query.yahooapis.com/v1/public/yql?q=select * from json where url='${options.url}?${qs.stringify(options.data)}'&format=json`
|
||||
delete options.data
|
||||
}
|
||||
}
|
||||
|
||||
return fetch(options).then((response) => {
|
||||
return response.data
|
||||
const { statusText, status } = response
|
||||
let data = options.isCross ? response.data.query.results.json : response.data
|
||||
return {
|
||||
code: 0,
|
||||
status,
|
||||
message: statusText,
|
||||
...data,
|
||||
}
|
||||
}).catch((error) => {
|
||||
console.log(error)
|
||||
return Promise.reject(error)
|
||||
const { response = { statusText: 'Network Error' } } = error
|
||||
return { code: 1, message: response.statusText }
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user