|
@@ -1,107 +1,107 @@
|
|
-import axios from 'axios'
|
|
|
|
-import qs from 'qs'
|
|
|
|
-
|
|
|
|
-var banruo_debug = false;//true测试环境false生产环境
|
|
|
|
-axios.defaults.baseURL = banruo_debug ? 'http://work.test.toktok.beer' : 'http://work.toktok.beer';//配置接口地址
|
|
|
|
-axios.defaults.timeout = 15000;//响应时间
|
|
|
|
-axios.defaults.headers.get['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'; //此处是增加的代码,设置请求头的类型
|
|
|
|
-axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8';//配置请求头
|
|
|
|
-axios.defaults.headers.common["My-User-Agent"] = "H5#H5#201#201";
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-// POST传参序列化(添加请求拦截器)
|
|
|
|
-// axios.interceptors.request.use((config) => {
|
|
|
|
-// //在发送请求之前做某件事
|
|
|
|
-// if(config.method === 'post'){
|
|
|
|
-// config.data = qs.stringify(config.data);
|
|
|
|
-// }
|
|
|
|
-// return config;
|
|
|
|
-// },(error) =>{
|
|
|
|
-// console.log('错误的传参')
|
|
|
|
-// return Promise.reject(error);
|
|
|
|
-// });
|
|
|
|
-
|
|
|
|
-/* 请求拦截 */
|
|
|
|
-axios.interceptors.request.use(
|
|
|
|
- config => {
|
|
|
|
- if (localStorage.getItem("token") != null) {
|
|
|
|
- config.headers["Auth-Token"] = localStorage.getItem("token");
|
|
|
|
- }
|
|
|
|
- return config;
|
|
|
|
- },
|
|
|
|
- err => Promise.reject(err)
|
|
|
|
-);
|
|
|
|
-
|
|
|
|
-//返回状态判断(添加响应拦截器)
|
|
|
|
-axios.interceptors.response.use((res) =>{
|
|
|
|
- //对响应数据做些事
|
|
|
|
- if(!res.data.success){
|
|
|
|
- return Promise.resolve(res);
|
|
|
|
- }
|
|
|
|
- return res;
|
|
|
|
-}, (error) => {
|
|
|
|
- console.log('网络异常')
|
|
|
|
- return Promise.reject(error);
|
|
|
|
-});
|
|
|
|
-
|
|
|
|
-export default {
|
|
|
|
- banruo_debug,
|
|
|
|
- sendRequest(method, url, params) {
|
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
|
- // axios.defaults.headers.common["Auth-Token"] = localStorage.getItem('token')
|
|
|
|
- if(method == 'GET'){
|
|
|
|
- axios.get(url, {params: params})
|
|
|
|
- .then(response => {
|
|
|
|
- resolve(response)
|
|
|
|
- }, err => {
|
|
|
|
- reject(err)
|
|
|
|
- })
|
|
|
|
- .catch((error) => {
|
|
|
|
- reject(error)
|
|
|
|
- })
|
|
|
|
- }else if(method == 'POST'){
|
|
|
|
- axios.post(url, params)
|
|
|
|
- .then(response => {
|
|
|
|
- resolve(response);
|
|
|
|
- }, err => {
|
|
|
|
- reject(err);
|
|
|
|
- })
|
|
|
|
- .catch((error) => {
|
|
|
|
- reject(error)
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- })
|
|
|
|
- },
|
|
|
|
- //返回一个Promise(发送post请求)
|
|
|
|
- fetchPost(url, params) {
|
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
|
- axios.post(url, params)
|
|
|
|
- .then(response => {
|
|
|
|
- resolve(response);
|
|
|
|
- }, err => {
|
|
|
|
- reject(err);
|
|
|
|
- })
|
|
|
|
- .catch((error) => {
|
|
|
|
- reject(error)
|
|
|
|
- })
|
|
|
|
- })
|
|
|
|
- },
|
|
|
|
- //返回一个Promise(发送get请求)
|
|
|
|
- fetchGet(url, param) {
|
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
|
- axios.get(url, {params: param})
|
|
|
|
- .then(response => {
|
|
|
|
- resolve(response)
|
|
|
|
- }, err => {
|
|
|
|
- reject(err)
|
|
|
|
- })
|
|
|
|
- .catch((error) => {
|
|
|
|
- reject(error)
|
|
|
|
- })
|
|
|
|
- })
|
|
|
|
- },
|
|
|
|
- //获取URL参数
|
|
|
|
- getUrlKey (name) {
|
|
|
|
- return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+import axios from 'axios'
|
|
|
|
+import qs from 'qs'
|
|
|
|
+
|
|
|
|
+var banruo_debug = false;//true测试环境false生产环境
|
|
|
|
+axios.defaults.baseURL = banruo_debug ? 'http://work.test.toktok.beer' : 'http://work.toktok.beer';//配置接口地址
|
|
|
|
+axios.defaults.timeout = 15000;//响应时间
|
|
|
|
+axios.defaults.headers.get['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'; //此处是增加的代码,设置请求头的类型
|
|
|
|
+axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8';//配置请求头
|
|
|
|
+axios.defaults.headers.common["My-User-Agent"] = "H5#H5#201#201";
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+// POST传参序列化(添加请求拦截器)
|
|
|
|
+// axios.interceptors.request.use((config) => {
|
|
|
|
+// //在发送请求之前做某件事
|
|
|
|
+// if(config.method === 'post'){
|
|
|
|
+// config.data = qs.stringify(config.data);
|
|
|
|
+// }
|
|
|
|
+// return config;
|
|
|
|
+// },(error) =>{
|
|
|
|
+// console.log('错误的传参')
|
|
|
|
+// return Promise.reject(error);
|
|
|
|
+// });
|
|
|
|
+
|
|
|
|
+/* 请求拦截 */
|
|
|
|
+axios.interceptors.request.use(
|
|
|
|
+ config => {
|
|
|
|
+ if (localStorage.getItem("token") != null) {
|
|
|
|
+ config.headers["Auth-Token"] = localStorage.getItem("token");
|
|
|
|
+ }
|
|
|
|
+ return config;
|
|
|
|
+ },
|
|
|
|
+ err => Promise.reject(err)
|
|
|
|
+);
|
|
|
|
+
|
|
|
|
+//返回状态判断(添加响应拦截器)
|
|
|
|
+axios.interceptors.response.use((res) =>{
|
|
|
|
+ //对响应数据做些事
|
|
|
|
+ if(!res.data.success){
|
|
|
|
+ return Promise.resolve(res);
|
|
|
|
+ }
|
|
|
|
+ return res;
|
|
|
|
+}, (error) => {
|
|
|
|
+ console.log('网络异常')
|
|
|
|
+ return Promise.reject(error);
|
|
|
|
+});
|
|
|
|
+
|
|
|
|
+export default {
|
|
|
|
+ banruo_debug,
|
|
|
|
+ sendRequest(method, url, params) {
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
+ // axios.defaults.headers.common["Auth-Token"] = localStorage.getItem('token')
|
|
|
|
+ if(method == 'GET'){
|
|
|
|
+ axios.get(url, {params: params})
|
|
|
|
+ .then(response => {
|
|
|
|
+ resolve(response)
|
|
|
|
+ }, err => {
|
|
|
|
+ reject(err)
|
|
|
|
+ })
|
|
|
|
+ .catch((error) => {
|
|
|
|
+ reject(error)
|
|
|
|
+ })
|
|
|
|
+ }else if(method == 'POST'){
|
|
|
|
+ axios.post(url, params)
|
|
|
|
+ .then(response => {
|
|
|
|
+ resolve(response);
|
|
|
|
+ }, err => {
|
|
|
|
+ reject(err);
|
|
|
|
+ })
|
|
|
|
+ .catch((error) => {
|
|
|
|
+ reject(error)
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ //返回一个Promise(发送post请求)
|
|
|
|
+ fetchPost(url, params) {
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
+ axios.post(url, params)
|
|
|
|
+ .then(response => {
|
|
|
|
+ resolve(response);
|
|
|
|
+ }, err => {
|
|
|
|
+ reject(err);
|
|
|
|
+ })
|
|
|
|
+ .catch((error) => {
|
|
|
|
+ reject(error)
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ //返回一个Promise(发送get请求)
|
|
|
|
+ fetchGet(url, param) {
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
+ axios.get(url, {params: param})
|
|
|
|
+ .then(response => {
|
|
|
|
+ resolve(response)
|
|
|
|
+ }, err => {
|
|
|
|
+ reject(err)
|
|
|
|
+ })
|
|
|
|
+ .catch((error) => {
|
|
|
|
+ reject(error)
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ //获取URL参数
|
|
|
|
+ getUrlKey (name) {
|
|
|
|
+ return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null
|
|
|
|
+ }
|
|
|
|
+}
|