123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- import { getHashQuery } from '../utils/index.js'
- var url='http://'+getHashQuery('url')+'/'
- //const baseUrl = url
- console.log(getHashQuery('url'))
- if(getHashQuery('url')){
- var baseUrl =url
- }else{
- var baseUrl = 'http://api.dms.66km.com.cn/'
- }
- const burl2=url
- import md5 from './MD5.js'
- var token=getHashQuery('token')
- console.log(token)
- var uid=getHashQuery('uid')
- console.log(uid)
- const http = (url = '', date = {}, type = 'POST', header = {
- }) => {
- return new Promise((resolve, reject) => {
- header={};
-
- if(token){
- header['accessToken']=token;
- header['uid']=uid;
- }else{
- header['accessToken']='';
- header['uid']='';
- }
-
- //header['token']='98A9FED8814B457288166BDF623F33D1';
- //header['uid']='795957B6-8F4B-4E7F-96FE-1F26E5BA21A1';
- header['Content-Type']='application/x-www-form-urlencoded';
- //console.log(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==1){
- uni.showToast({
- title: res.data.msg,
- icon:'none',
- duration: 3000,
- });
- // uni.clearStorageSync()
-
- }else if(res.data.code==409){
- // getToken(url,date,type,header)
- }
- resolve(res.data);
- }).catch(error => {
- let [err, res] = error;
- reject(err)
- })
- });
- }
- function getToken(url,date,type,header){
- var header={};
- //var userId=uni.getStorageSync("devData").userId;
- //var devData=uni.getStorageSync("devData")
- header['Content-Type']='application/x-www-form-urlencoded';
- uni.request({
- method: "POST",
- url: burl2 + '/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) //刷新接口
- }
- });
- // console.log(accessToken)
- }).catch(error => {
-
- })
- }
- function refresh(url,date,type,header){
- uni.request({
- method: type,
- url: burl2 + 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
- }
|