| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- // uni-app请求封装
- export default class Request {
- http(router, data = {}, method, contentType) {
- let that = this;
- let path = 'https://userapp.zkhj6.com'; //app
- let token = uni.getStorageSync('AppToken');
- let live= uni.getStorageSync('AppToken')
- uni.setStorageSync('liveToken',live)
- // #ifdef H5
- path = 'https://userapp.zkhj6.com'; //h5接口
- // #endif
- // 看课模块
- if (router.indexOf("/app/course/getRealLink") != -1) {
- path = 'https://userapp.zkhj6.com';
- }
- if(router.indexOf("/appLive") !== -1) {
- router = router.replace('/appLive','')
- path ='https://userapp.zkhj6.com';
- // router = router.replace('/appLive','')
-
- // path ='http://z2fae9e9.natappfree.cc'
- }
- // 腕表模块
- if (router.indexOf("/watch-api") != -1) {
- router = router.replace('/watch-api', '')
- // path = 'http://42.194.245.189:8114'
- }
- // doctorAi模块
- if (router.indexOf("/doctorAi") != -1) {
- router = router.replace('/doctorAi', '')
- // path = 'http://doctor.ai.cdwjyyh.com'
- }
- // path = 'http://192.168.110.18:8113'
- // 手动发课
- // path = 'http://192.168.110.225:8113'
- if(router.indexOf("/companyapp") != -1 ) {
- // path = 'http://192.168.110.225:8007'
- // path ='https://userapp.zkhj6.com';
- path ='https://companyapi.zkhj6.com';
- router = router.replace('/companyapp','')
- token = uni.getStorageSync('ManageToken');
- }
- // path = 'http://192.168.110.18:8113'
- // path = 'https://70538sz006bj.vicp.fun'
- // path = 'https://userapp.jnmyunl.com'
- const pages = getCurrentPages();
- let curPath = ''
- if (pages) {
- const curPage = pages[pages.length - 1];
- curPath = curPage && curPage.route || '';
- }
- // 商城
- // let urlRouter = ['/app/product/getProductDetails', '/app/product/getProducts',
- // '/app/product/getProductCate', '/app/product/getProductCateByPid', '/app/product/getCarts',
- // '/app/product/getGoodsProducts', '/app/product/addCart', '/app/product/getCartCount',
- // '/app/address/getAddressList', '/app/storeOrder/confirm', '/app/common/getWeixinOrderTemps',
- // '/app/storeOrder/computed', '/app/storeOrder/create', '/app/storeOrder/getStoreOrderById',
- // '/app/coupon/getMyCouponList', '/app/user/getProductFoots', '/app/companyUser/getUserInfo',
- // '/app/companyOrder/getSalesProducts', '/app/coupon/getCompanyCouponIssueList',
- // '/app/storeOrder/getCompanyStoreOrderList', '/app/storeOrder/getMyStoreOrderById',
- // '/app/coupon/getMyEnableCouponList', '/app/fsInterestAi/getRecommendRoleList',
- // '/app/common/getStoreConfig', '/app/product/cartNum'
- // ]
- // const pay = ['/app/storeOrder/editPayType', '/app/storeOrder/pay',
- // '/app/storeAfterSales/getStoreAfterSalesList'
- // ]
- // urlRouter = [...urlRouter, ...pay]
- // if (urlRouter.includes(router) || curPath.indexOf("pages_shopping") != -1 || curPath.indexOf(
- // "pages_user") != -1 || curPath.indexOf("pages_company") != -1) {
- // // path = 'http://192.168.110.18:8113/store'
- // path = 'https://userapp.zkhj6.com/store'
- // }
- uni.setStorageSync('requestPath', path);
- // uni.showLoading({
- // title: '加载中'
- // });
- return new Promise((resolve, reject) => {
- let liveToken = uni.getStorageSync('liveToken');
- console.log('indexlogin)))))))))))',uni.getStorageSync('liveToken'))
- let CompanyUserToken = uni.getStorageSync('CompanyUserToken');
- var httpContentType = 'application/x-www-form-urlencoded';
- if (contentType != undefined) {
- httpContentType = contentType;
- }
- var routers = router;
- // 直播模块使用liveToken
- let useToken = token;
- // 检查是否为直播模块路径
- const isLiveApi = router.indexOf("/live") !== -1;
- if(isLiveApi) {
- useToken = liveToken
- }
- //console.log("---qxj request url",`${path}${router}`+" params:"+JSON.stringify(data)+" \n AppToken:"+token);
- // 请求
- uni.request({
- header: {
- // 'Content-Type': 'application/x-www-form-urlencoded',
- 'Content-Type': httpContentType,
- 'AppToken': token,
- 'CompanyUserToken': CompanyUserToken, //业务员token
- 'SourceType': 'APP'
- },
- url: `${path}${router}`,
- data: data,
- method: method,
- 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.data.code == 403) {
- // return uni.redirectTo({
- // url:'/pages_company/auth/login'
- // })
- }
- if (res.token) {
- uni.setStorageSync('AppToken', res.token)
- }
- resolve(res.data)
- },
- fail: (res) => {
- //接口调用失败的回调函数
- },
- complete: (res) => {
- // console.log("complete=======",path,router,res.data)
- //接口调用结束的回调函数(调用成功、失败都会执行)
- if (res.data && res.data.code == 401) {
- uni.$emit('loginOut');
- return false
- }
- uni.hideLoading();
- }
- });
- })
- }
- }
|