|
@@ -1,64 +1,39 @@
|
|
|
-import axios from 'axios';
|
|
|
-import qs from 'qs';
|
|
|
-import { Message } from 'element-ui';
|
|
|
+import axios from 'axios'
|
|
|
+import qs from 'qs'
|
|
|
+import storageUtil from '../util/storageUtil'
|
|
|
+
|
|
|
+export default function ajax (url, data={}, type='GET') {
|
|
|
|
|
|
-axios.defaults.headers.common['Content-Type'] = 'application/json; charset=UTF-8';
|
|
|
-axios.defaults.baseURL = 'https://ccss.windd.cn/screen/';
|
|
|
-// axios.defaults.baseURL = 'http://114.55.254.203/screen/';
|
|
|
-// axios.defaults.baseURL = 'http://10.16.4.3:7001/';
|
|
|
-//网络请求
|
|
|
-export default function ajax(url, data = {}, type = 'GET', isupload) {
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
- let promise;
|
|
|
+ let promise
|
|
|
if (type === 'GET') {
|
|
|
- let dataStr = '';
|
|
|
+ let dataStr = ''
|
|
|
Object.keys(data).forEach(key => {
|
|
|
- dataStr += key + '=' + data[key] + '&';
|
|
|
- });
|
|
|
+ dataStr += key + '=' + data[key] + '&'
|
|
|
+ })
|
|
|
if (dataStr !== '') {
|
|
|
- dataStr = dataStr.substring(0, dataStr.lastIndexOf('&'));
|
|
|
+ dataStr = dataStr.substring(0, dataStr.lastIndexOf('&'))
|
|
|
url = url + '?' + dataStr;
|
|
|
- }
|
|
|
- promise = axios.get(url);
|
|
|
- } else if (type === 'DELETE') {
|
|
|
- let dataString = '';
|
|
|
- Object.keys(data).forEach(key => {
|
|
|
- dataString += key + '=' + data[key] + '&';
|
|
|
- });
|
|
|
- if (dataString !== '') {
|
|
|
- dataString = dataString.substring(0, dataString.lastIndexOf('&'));
|
|
|
- url = url + '?' + dataString;
|
|
|
- }
|
|
|
- promise = axios.delete(url);
|
|
|
- } else {
|
|
|
- if (isupload) {
|
|
|
- promise = axios.post(url, data, {
|
|
|
- headers: {
|
|
|
- 'Content-Type': 'multipart/form-data',
|
|
|
- },
|
|
|
- transformRequest: [
|
|
|
- function (data) {
|
|
|
- return data;
|
|
|
- },
|
|
|
- ],
|
|
|
- });
|
|
|
} else {
|
|
|
- promise = axios.post(url, qs.stringify(data));
|
|
|
+ url = url;
|
|
|
}
|
|
|
- }
|
|
|
- promise
|
|
|
- .then(function (response) {
|
|
|
|
|
|
- resolve(response.data);
|
|
|
+ promise = axios.get(url, {
|
|
|
+ headers: {
|
|
|
+ 'cipherText': storageUtil.read("userInfo")
|
|
|
+ }
|
|
|
})
|
|
|
- .catch(function (error) {
|
|
|
- Message({
|
|
|
- message: '系统异常,请联系管理员',
|
|
|
- type: 'error',
|
|
|
- duration: 5000,
|
|
|
- });
|
|
|
- console.error("异常", error);
|
|
|
- reject(error);
|
|
|
+ } else {
|
|
|
+ promise = axios.post(url, qs.stringify(data), {
|
|
|
+ headers: {
|
|
|
+ 'cipherText': storageUtil.read("userInfo")
|
|
|
+ }
|
|
|
});
|
|
|
- });
|
|
|
+ }
|
|
|
+ promise.then(function (response) {
|
|
|
+ resolve(response.data);
|
|
|
+ }).catch(function (error) {
|
|
|
+ reject(error);
|
|
|
+ })
|
|
|
+ })
|
|
|
}
|