request.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // uni-app请求封装
  2. import {TOKEN_WEXIN} from '@/utils/common.js'
  3. import {TOKEN_KEYAuto} from '@/utils/courseTool.js'
  4. console.log("TOKEN_KEYAuto====",TOKEN_KEYAuto)
  5. export default class Request {
  6. http(router, data = {}, method,contentType) {
  7. let that = this;
  8. //曹丽芹
  9. // let path = 'http://192.168.10.131:7015'
  10. //涂小龙
  11. // let path = 'http://192.168.10.125:7015'
  12. //刘明欣
  13. // let path = 'http://192.168.10.150:8080'
  14. //张玉朋
  15. // let path = 'http://192.168.10.158:7014'//
  16. //刘明欣
  17. // let path = 'http://x8489c8e.natappfree.cc'//
  18. // let path = 'https://userapp.fbylive.com'//福本源
  19. // let path = 'https://userapp.zkhj6.com'//中康
  20. // let path = 'https://company.h5.test.ylrztop.com/api'//云融融智
  21. // let path = 'https://userapp.ashyisheng.com'//蜂巢快药
  22. // let path = 'https://userapp.whhm.ylrzcloud.com/prod-api'//惠名大药房
  23. // let path = 'https://userapp.xdtongshuntang.top'//同顺堂
  24. // let path = 'https://userapp.liangmiaoedu.com'//良苗
  25. // let path = 'https://usercourse.beliyostore.com'//倍力优
  26. // let path = 'https://userapp.bainian1000y.cn/prod-api'//百年康城
  27. let path = 'https://userapp.drkzyy.cn/prod-api'//青岛市德瑞康
  28. // let path = 'https://companyapp.gjh2024.com/apis'//金康键
  29. // let path = 'https://userapp.cqsft.vip'//四福堂
  30. uni.setStorageSync('requestPath',path)
  31. // uni.showLoading({
  32. // title: '加载中'
  33. // });
  34. let token = uni.getStorageSync('AppToken');
  35. // if(router.indexOf("/companyapp")!=-1){
  36. // router =router.replace('/companyapp','')
  37. // path = 'http://192.168.10.158:7015'//
  38. // token = uni.getStorageSync('AppToken');
  39. // }
  40. if(router.indexOf("/course_uniapp")!=-1){
  41. router =router.replace('/course_uniapp','')
  42. // path = 'https://userapp.fbylive.com'//福本源
  43. // // path = 'https://scrm.gjh2024.com'//金康键
  44. //张玉朋
  45. // let path = 'http://192.168.10.158:7014'//
  46. // path = 'https://userapp.zkhj6.com'//中康
  47. // path = 'https://company.h5.test.ylrztop.com/api'//云融融智
  48. // path = 'https://userapp.ashyisheng.com'//蜂巢快药(爱上嘉园)
  49. // path = 'https://userapp.liangmiaoedu.com'//良苗
  50. // path = 'https://usercourse.beliyostore.com'//倍力优
  51. // path = 'https://userapp.bainian1000y.cn/prod-api'//百年康城
  52. // path = 'https://userapp.whhm.ylrzcloud.com/prod-api'//惠名大药房
  53. // path = 'https://userapp.cqsft.vip'//四福堂
  54. path = 'https://userapp.drkzyy.cn/prod-api'//青岛市德瑞康
  55. // path = 'https://userapp.gjh2024.com/apis'//金康键
  56. // path = 'http://192.168.10.131:7014'
  57. //#ifdef MP-WEIXIN
  58. token =uni.getStorageSync('TOKEN_WEXIN')
  59. //#endif
  60. // #ifdef H5
  61. token =uni.getStorageSync('TOKEN_KEY')
  62. // #endif
  63. }
  64. // 自动发课
  65. if(router.indexOf("/course_auto")!=-1){
  66. router =router.replace('/course_auto','')
  67. // path = 'https://userapp.gjh2024.com/apis'//金康键
  68. path = 'https://userapp.drkzyy.cn/prod-api'//青岛市德瑞康
  69. token =uni.getStorageSync(TOKEN_KEYAuto)
  70. console.log("TOKEN_KEYAuto===",TOKEN_KEYAuto,token)
  71. }
  72. if(router.indexOf("/QWcourse")!=-1){
  73. router =router.replace('/QWcourse','')
  74. token = uni.getStorageSync('TOKEN_KEYQW');
  75. }
  76. return new Promise((resolve, reject) => {
  77. // let token = uni.getStorageSync('AppToken');
  78. let usertoken = uni.getStorageSync("TOKEN_WEXIN")
  79. var httpContentType='application/x-www-form-urlencoded';
  80. if(contentType!=undefined){
  81. //application/json;charset=UTF-8
  82. httpContentType=contentType;
  83. }
  84. var routers=router;
  85. // 请求
  86. uni.request({
  87. header: {
  88. // 'Content-Type': 'application/x-www-form-urlencoded',
  89. 'Content-Type': httpContentType,
  90. 'AppToken': token,
  91. // 'UserToken':usertoken
  92. },
  93. url: `${path}${router}`,
  94. data: data,
  95. method: method,
  96. success: (res) => {
  97. //收到开发者服务器成功返回的回调函数
  98. if(res.data.code==401){//没有权限直接退出到登录界面
  99. let pages = getCurrentPages();
  100. let currentPage = pages[ pages.length - 1]; //当前页页面实例
  101. // 条件编译判断平台,设置不同登录页路径
  102. let loginPage = '';
  103. // #ifdef H5
  104. loginPage = '/pages/auth/login';
  105. // #endif
  106. // #ifdef MP-WEIXIN
  107. loginPage = '/pages/enterprise/enterprise';
  108. // #endif
  109. //如果登录界面已打开,自动关闭
  110. if (currentPage.route === loginPage.replace(/^\//, '')) {
  111. resolve(res.data);
  112. return;
  113. }
  114. uni.reLaunch({
  115. url:loginPage,
  116. success: () => {
  117. uni.hideLoading();
  118. },
  119. fail: () => {
  120. uni.hideLoading();
  121. }
  122. })
  123. return;
  124. }
  125. // if (res.token) {
  126. // uni.setStorageSync(TOKEN_KEY,res.data.token)
  127. // }
  128. resolve(res.data)
  129. },
  130. fail:(res) =>{
  131. //接口调用失败的回调函数
  132. },
  133. complete:(res) =>{
  134. //接口调用结束的回调函数(调用成功、失败都会执行)
  135. console.log('1111'+router+'1111',res)
  136. if (res.data&& res.data.code == 401) {
  137. return false
  138. }
  139. uni.hideLoading();
  140. }
  141. })
  142. })
  143. }
  144. }