// uni-app请求封装 export default class Request { http(router, data = {}, method,contentType,timeout=60000, hideLoading=true) { let that = this; // let path ='https://api.cdwjyyh.com';//app正式环境 let path ='https://userapp.hshsyy.com';//河山正式环境 //let path = 'http://192.168.110.247:8113' // #ifdef H5 //path = 'http://192.168.110.245:8113' path ='https://h5api.his.cdwjyyh.com';//h5接口 //path = 'http://192.168.110.247:8113' // path ='http://z2fae9e9.natappfree.cc';//直播余红奇本地 // path ='https://api.fhhx.runtzh.com';//直播余红奇线上 // #endif // 看课模块 if(router.indexOf("/course_auto") != -1 ) { router = router.replace('/course_auto', '') path ='https://h5api.his.cdwjyyh.com'; } // 直播模块 if(router.indexOf("/appLive") !== -1) { // router = router.replace('/appLive','') path ='https://api.fhhx.runtzh.com'; router = router.replace('/appLive','') } // 直播用户 if(router.indexOf("/liveUser") !== -1) { // router = router.replace('/appLive','') path ='https://api.fhhx.runtzh.com'; } //直播静默登录配置 if(router.indexOf("/liveAPP") !== -1 ){ path ='https://api.fhhx.runtzh.com'; router = router.replace('/liveAPP', '') } // 腕表模块 if(router.indexOf("/watch-api") != -1 ) { router = router.replace('/watch-api','') // path = 'http://192.168.10.155:8114' // path = 'http://192.168.10.135:8114' path = 'http://42.194.245.189:8114' } // doctorAi模块 if(router.indexOf("/doctorAi") != -1 ) { router = router.replace('/doctorAi','') path = 'http://doctor.ai.cdwjyyh.com' } uni.setStorageSync('requestPath',path); // uni.showLoading({ // title: '加载中' // }); return new Promise((resolve, reject) => { let token = uni.getStorageSync('AppToken'); let liveToken = uni.getStorageSync('liveToken'); //console.log('indexlogin)))))))))))',uni.getStorageSync('liveToken')) //console.log('userData)))))))))))',uni.getStorageSync('userData')) let CompanyUserToken = uni.getStorageSync('CompanyUserToken'); var httpContentType='application/x-www-form-urlencoded'; if(contentType!=undefined){ httpContentType=contentType; } var routers=router; // 直播模块使用liveToken let useToken = token; // 检查是否为直播模块路径 //console.log('router',router) const isLiveApi = router.indexOf("/live") !== -1 || router.indexOf("/liveUser/app/user/getUserInfo") !== -1 || router.indexOf("/app/address/getAddressByDefault") !== -1; if(isLiveApi) { useToken = liveToken if(router.indexOf("/liveUser") !== -1){ router = router.replace('/liveUser','') } }else{ useToken = token } // 请求 uni.request({ header: { // 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': httpContentType, 'AppToken': useToken, 'liveToken':liveToken, 'CompanyUserToken':CompanyUserToken //业务员token }, url: `${path}${router}`, data: data, method: method, timeout: timeout, success: (res) => { //收到开发者服务器成功返回的回调函数 if(res.data.code==401){ //没有权限直接退出到登录界面 let pages = getCurrentPages(); let url = pages[ pages.length - 1]; //当前页页面实例 //如果登录界面已打开,自动关闭 if(url!=undefined&&url.route=="pages/auth/login"){ resolve(res.data) return; } } // if(res.token) { // uni.setStorageSync('AppToken',res.token) // } resolve(res.data) }, fail:(res) =>{ //接口调用失败的回调函数 reject(res); }, complete:(res) =>{ //console.log("complete==",`${path}${router}`,res) if (res.data&&res.data.code == 401) { uni.$emit('loginOut'); return false } if(hideLoading){ uni.hideLoading(); } } }); }) } }