123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- import $store from '../store'
- const extConfig = uni.getExtConfigSync();
- console.log(extConfig)
- const baseUrl=extConfig.url+'/'
- const webUrl = 'https://webwx.66km.com/'
- console.log(baseUrl)
- const http = (url = '', date = {}, type = 'POST', header = {
- }) => {
- return new Promise((resolve, reject) => {
- header={};
-
- console.log($store.state.wxOpenData.loginInfo)
-
- var wxOpenData=$store.state.wxOpenData
- if(wxOpenData.loginInfo){
- header['token']=wxOpenData.loginInfo.token;
- header['uid']=wxOpenData.loginInfo.uid;
- }
-
-
-
- header['Content-Type']='application/x-www-form-urlencoded';
-
- uni.request({
- method: type,
- url: baseUrl + url,
- data: date,
- header: header,
- dataType: 'json',
- }).then((response) => {
-
- let [error, res] = response;
-
- if(res.data.code==401||res.data.code==403){
-
-
-
-
-
-
-
-
-
- }else if(res.data.code==409){
-
- }
- if(res.data.code==1){
- uni.showToast({
- title: res.data.msg,
- icon:'none',
- duration: 4000,
- });
- }
- resolve(res.data);
- }).catch(error => {
- let [err, res] = error;
- reject(err)
- })
- });
- }
- const httpBinary = (url = '', date = {}, type = 'POST', header = {
- }) => {
- return new Promise((resolve, reject) => {
- header={};
-
- var wxOpenData=$store.state.wxOpenData
- if(wxOpenData){
- header['token']=wxOpenData.loginInfo.token;
- header['uid']=wxOpenData.loginInfo.uid;
- }
-
-
- header['Content-Type']='application/x-www-form-urlencoded';
-
- uni.request({
- method: type,
- url: baseUrl + url,
- data: date,
- header: header,
- dataType: 'json',
- responseType: "arraybuffer",
- }).then((response) => {
-
- let [error, res] = response;
-
- if(res.data.code==401||res.data.code==403){
- uni.showToast({
- title: res.data.msg,
- icon:'none',
- duration: 3000,
- });
- uni.clearStorageSync()
- uni.navigateTo({
- url:'../login/login'
- })
- }else if(res.data.code==409){
-
- }
-
- resolve(res.data);
- }).catch(error => {
- uni.hideLoading();
- let [err, res] = error;
- reject(err)
- })
- });
- }
- function getToken(url,date,type,header){
- var header={};
-
-
- header['Content-Type']='application/x-www-form-urlencoded';
- uni.request({
- method: "POST",
- url: baseUrl + '/sys/getTokenByUserID',
- data: {
- userId:userId
- },
- header: header,
- dataType: 'json',
- }).then((response) => {
- let [error, res] = response;
- var accessToken=res.data.data.accessToken.accessToken;
- devData.accessToken=accessToken;
- uni.setStorage({
- key: 'devData',
- data:devData,
- success: function () {
- refresh(url,date,type,header)
- }
- });
-
- }).catch(error => {
-
- })
- }
- function refresh(url,date,type,header){
- uni.request({
- method: type,
- url: baseUrl + url,
- data: date,
- header: header,
- dataType: 'json',
- }).then((response) => {
- setTimeout(function() {
- uni.hideLoading();
- }, 200);
- let [error, res] = response;
-
- if(res.data.code==403){
- uni.showToast({
- title: res.data.msg,
- icon:'none',
- duration: 3000,
- });
- uni.navigateTo({
- url:'../login/login'
- })
- }
- resolve(res.data);
- }).catch(error => {
- let [err, res] = error;
- reject(err)
- })
- }
- export default {
- http,baseUrl,httpBinary,webUrl
- }
|