Commit 02cc76ce authored by aoobao's avatar aoobao

fix axios

parent f7ee02a5
......@@ -15,6 +15,7 @@ let baseAxios = axios.create({
})
let __token = null
let __http_one_only = false
// 发送信息钩子
baseAxios.interceptors.request.use(
......@@ -46,7 +47,9 @@ baseAxios.interceptors.response.use(
}
)
baseAxios.getUrl = (url, params = {}) => {
baseAxios.getUrl = (url, params = {}, {
showErrflag = true
}) => {
return new Promise(resolve => {
baseAxios
.get(url, {
......@@ -55,6 +58,13 @@ baseAxios.getUrl = (url, params = {}) => {
.then(
response => {
let retData = response.data
if (retData.code !== 0) {
console.warn(url, params, retData)
}
retData.isok = (retData.code === 0)
if (showErrflag) {
ifErr(retData)
}
resolve(retData)
},
error => {
......@@ -66,7 +76,10 @@ baseAxios.getUrl = (url, params = {}) => {
})
}
baseAxios.postUrl = (url, data = {}, showErrflag = true) => {
baseAxios.postUrl = (url, data = {}, {
showErrflag = true,
postOne = false
}) => {
let headers = {}
let opts = data
if (Object.prototype.toString.call(data) !== '[object FormData]') {
......@@ -76,6 +89,15 @@ baseAxios.postUrl = (url, data = {}, showErrflag = true) => {
headers['Content-Type'] = 'multipart/form-data'
}
if (postOne) {
// 已经有请求存在
if (__http_one_only) {
errMessage('请求中,请稍后...')
return
}
__http_one_only = true
}
return new Promise(resolve => {
baseAxios
.post(url, opts, {
......@@ -83,16 +105,23 @@ baseAxios.postUrl = (url, data = {}, showErrflag = true) => {
})
.then(
response => {
if (postOne) {
__http_one_only = false
}
let retData = response.data
if (retData.code != 0) {
console.warn(url, data, retData)
}
retData.isok = (retData.code === 0)
if (showErrflag) {
ifErr(retData)
}
resolve(retData)
},
error => {
if (postOne) {
__http_one_only = false
}
console.warn(error)
let errData = res.error('服务器错误', -1, error)
resolve(errData)
......
import {
AMAP_KEY,
AMAP_VERSION
AMAP_VERSION,
AMAP_PLUGIN
} from '@/assets/setting'
let _callback = []
......@@ -23,7 +24,8 @@ export default function requireAMap(callback) {
}
if (!isLoad) {
isLoad = true
let url = `https://webapi.amap.com/maps?v=${AMAP_VERSION}&key=${AMAP_KEY}&callback=__AMAP_CALLBACK`;
let url = `https://webapi.amap.com/maps?v=${AMAP_VERSION}&key=${AMAP_KEY}&plugin=${AMAP_PLUGIN}&callback=__AMAP_CALLBACK`;
let jsapi = document.createElement('script');
jsapi.charset = 'utf-8';
......
......@@ -2,6 +2,8 @@
export const AMAP_KEY = '104a0cc0ce15a396dde189f4f7d438ff'
// 高德地图版本号
export const AMAP_VERSION = '1.4.14'
// 高德地图插件
export const AMAP_PLUGIN = null // 'AMap.MarkerClusterer'
// 适配rem (用到宽和html默认font-size) rem 1 = 100px
export const SCREEN_WIDTH = 1920
export const SCREEN_HEIGHT = 1080
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment