赞
踩
import request from '@/utils/request' import poxyArray from "./poxyArray" import { Message } from 'element-ui' let UUID = []; let EXECUTE = new poxyArray(); let EXECUTESTATE = false; let delay = 1000; function queryParams(data, isPrefix) { isPrefix = isPrefix ? isPrefix : false let prefix = isPrefix ? '?' : '' let _result = [] for (let key in data) { let value = data[key] // 去掉为空的参数 if (['', undefined, null].includes(value)) { continue } if (value.constructor === Array) { value.forEach(_value => { _result.push(encodeURIComponent(key) + '[]=' + encodeURIComponent(_value)) }) } else if (value.constructor === Object) { Object.keys(value).forEach(function (keys) { _result.push(encodeURIComponent(key) + '.' + encodeURIComponent(keys) + '=' + encodeURIComponent(value[keys])) }); } else { _result.push(encodeURIComponent(key) + '=' + encodeURIComponent(value)) } } return _result.length ? prefix + _result.join('&') : '' } function executeXMLHttpRequest() { if (EXECUTESTATE) return EXECUTESTATE = true let { resolve, reject } = EXECUTE[0]; request(EXECUTE.shift()).then(res => { resolve(res); EXECUTESTATE = false EXECUTE.length && executeXMLHttpRequest() }, error => { reject(error) Message({ message: error, type: 'error', duration: 5 * 1000 }) EXECUTESTATE = false EXECUTE.length && executeXMLHttpRequest() }) } function awaitXMLHttpRequest() { return new Promise(function (resolve, reject) { EXECUTE.push({ resolve, reject, ...UUID.shift() }) executeXMLHttpRequest() }); } export default function request_qs(option) { if (option.qsdata) { option.url += queryParams(option.qsdata, true); } if (option.method == 'get') { option.params = option.data } else if (option.method == 'post') { } UUID.push({ ...option }) return awaitXMLHttpRequest().then(response => { return response; }) }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。