|
@@ -1,143 +1,143 @@
|
|
|
-import axios from 'axios'
|
|
|
-import qs from 'qs'
|
|
|
-
|
|
|
-var banruo_debug = false;//true测试环境false生产环境http://work.test.toktok.beer
|
|
|
-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.post['Content-Type'] = 'application/x-www-form-urlencoded;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.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('Auth-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请求)
|
|
|
- downloadPost(url, params) {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- axios.defaults.headers.post['Content-Type'] = 'multipart/form-data';
|
|
|
- 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
|
|
|
- },
|
|
|
- wxJSSDK(){
|
|
|
- var localUrl = encodeURIComponent(location.href.split('#')[0]);
|
|
|
- this.sendRequest('GET','/oa/jsapi/sign',{url:localUrl})
|
|
|
- .then((res) => {
|
|
|
- if(res.data.code == 200){
|
|
|
- //console.log(res);
|
|
|
- wx.config({
|
|
|
- beta: true,
|
|
|
- debug: false, // 默认为false 为true的时候是调试模式,会打印出日志
|
|
|
- appId: res.data.data.appid,
|
|
|
- timestamp: res.data.data.timestamp,
|
|
|
- nonceStr: res.data.data.noncestr,
|
|
|
- signature: res.data.data.signature,
|
|
|
- jsApiList: [
|
|
|
- 'getLocalImgData',
|
|
|
- 'chooseImage',
|
|
|
- 'previewImage',
|
|
|
- 'uploadImage'
|
|
|
- ]
|
|
|
- });
|
|
|
- wx.ready(function() {
|
|
|
-
|
|
|
- });
|
|
|
- }else{
|
|
|
- console.log(res)
|
|
|
- }
|
|
|
- })
|
|
|
- .catch((err)=>{
|
|
|
- console.log(err)
|
|
|
- });
|
|
|
- }
|
|
|
-}
|
|
|
+import axios from 'axios'
|
|
|
+import qs from 'qs'
|
|
|
+
|
|
|
+var banruo_debug = true;//true测试环境false生产环境http://work.test.toktok.beer
|
|
|
+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.post['Content-Type'] = 'application/x-www-form-urlencoded;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.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('Auth-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请求)
|
|
|
+ downloadPost(url, params) {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ axios.defaults.headers.post['Content-Type'] = 'multipart/form-data';
|
|
|
+ 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
|
|
|
+ },
|
|
|
+ wxJSSDK(){
|
|
|
+ var localUrl = encodeURIComponent(location.href.split('#')[0]);
|
|
|
+ this.sendRequest('GET','/oa/jsapi/sign',{url:localUrl})
|
|
|
+ .then((res) => {
|
|
|
+ if(res.data.code == 200){
|
|
|
+ //console.log(res);
|
|
|
+ wx.config({
|
|
|
+ beta: true,
|
|
|
+ debug: false, // 默认为false 为true的时候是调试模式,会打印出日志
|
|
|
+ appId: res.data.data.appid,
|
|
|
+ timestamp: res.data.data.timestamp,
|
|
|
+ nonceStr: res.data.data.noncestr,
|
|
|
+ signature: res.data.data.signature,
|
|
|
+ jsApiList: [
|
|
|
+ 'getLocalImgData',
|
|
|
+ 'chooseImage',
|
|
|
+ 'previewImage',
|
|
|
+ 'uploadImage'
|
|
|
+ ]
|
|
|
+ });
|
|
|
+ wx.ready(function() {
|
|
|
+
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ console.log(res)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((err)=>{
|
|
|
+ console.log(err)
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|