request.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // uni-app请求封装
  2. // import {TOKEN_WEXIN} from '@/utils/common.js'
  3. import {TOKEN_KEYAuto} from '@/utils/courseTool.js'
  4. import store from '@/store/index.js'
  5. export default class Request {
  6. http(router, data = {}, method,contentType) {
  7. let that = this;
  8. let type = 0;
  9. <<<<<<< HEAD
  10. //let path = 'https://userapi.scrm.ylrzcloud.com'//云联融智
  11. //let path = 'https://userappkyt.ylrzcloud.com'//宽益堂
  12. =======
  13. // let path = 'https://user.test.ylrztop.com/api'//云联融智
  14. //let path = 'https://userappkyt.ylrzcloud.com'//宽益堂
  15. >>>>>>> b53250c80fab209f9c8ef79b7d9ca16abd04a782
  16. // let path = 'https://userapp.schstyl.cn'//鸿森堂
  17. // let path = 'https://userapp.myks8.com'//恒春来
  18. // let path = 'https://userapp.nmghysmytdyf.com'//蒙一堂
  19. // let path = 'https://usercourse.beliyostore.com'//倍力优
  20. // let path = 'https://app.bainian1000y.cn/prod-api'//百年康成
  21. // let path = 'http://a9e258d6.natappfree.cc'//百年康成本地
  22. // let path = 'https://userapp.zkhj6.com'//中康
  23. // let path = 'http://192.168.10.158:8007'//中康
  24. // let path = 'https://userapp.myks8.com' //恒春来
  25. // let path = 'https://userapp.jiuzhouzaixian.com'//九州
  26. // let path = 'https://userapp.bjyjbao.com'//医健宝
  27. let path = 'https://userapp.yytcdta.com'//晚景如春 鹤颜堂
  28. // let path = 'https://userapp.yixingjian.top'//宏医堂
  29. // let path = 'https://userapp.cqsft.vip'//四福堂
  30. // let path = 'https://userapp.ljhehualu.com'//济南联志健康
  31. // let path = 'https://yjb.mynatapp.cc'//本地
  32. // let path = 'https://hatuserapp.ylrzfs.com'//恒安图
  33. let path = 'https://ddgyuserapp.slxinxi.top'//叮当国医
  34. // let path = 'https://userapp.cykbja.cn/prod-api'//纯正堂
  35. // let path = 'https://userapp.moonxiang.com'//存在文化
  36. // let path = 'https://userapp.jilinmaoq.cn'//顺亿景
  37. <<<<<<< HEAD
  38. // let path = 'https://userapp.bjyjbao.com'//医健宝
  39. //let path = 'https://userapp.bainian1000y.cn'//百年康成
  40. =======
  41. //let path = 'https://userapp.bjyjbao.com'//医健宝
  42. // let path = 'https://userapp.bainian1000y.cn'//百年康成
  43. >>>>>>> b53250c80fab209f9c8ef79b7d9ca16abd04a782
  44. // let path = 'https://userapp.jilinmaoq.cn'//致医
  45. // let path = 'https://userapp.cfrytjkzx.cn'//润元堂
  46. uni.setStorageSync('requestPath',path)
  47. // uni.showLoading({
  48. // title: '加载中'
  49. // });
  50. let token = uni.getStorageSync('AppToken');
  51. if(router.indexOf("/companyapp")!=-1){
  52. type = 1;
  53. // router =router.replace('/companyapp','')
  54. // path = 'https://companyapp.ljhehualu.com'//济南联志
  55. token = uni.getStorageSync('ManageToken');
  56. }
  57. if(router.indexOf("/course_uniapp")!=-1){
  58. type = 2;
  59. router =router.replace('/course_uniapp','')
  60. token =uni.getStorageSync('TOKEN_WEXIN')
  61. }
  62. // 企微看课
  63. if(router.indexOf("/course_auto")!=-1){
  64. type = 3;
  65. router =router.replace('/course_auto','')
  66. // path = 'http://a9e258d6.natappfree.cc'//百年康成本地
  67. token =uni.getStorageSync(TOKEN_KEYAuto)
  68. }
  69. return new Promise((resolve, reject) => {
  70. // let token = uni.getStorageSync('AppToken');
  71. let usertoken = uni.getStorageSync("UserToken")
  72. var httpContentType='application/x-www-form-urlencoded';
  73. if(contentType!=undefined){
  74. //application/json;charset=UTF-8
  75. httpContentType=contentType;
  76. }
  77. var routers=router;
  78. // 请求
  79. uni.request({
  80. header: {
  81. // 'Content-Type': 'application/x-www-form-urlencoded',
  82. 'Content-Type': httpContentType,
  83. 'AppToken': token,
  84. 'UserToken':usertoken
  85. },
  86. url: `${path}${router}`,
  87. data: data,
  88. method: method,
  89. success: (res) => {
  90. if(type !==0&&(res.data.code == 401 || res.data.code == 4001||res.data.code == 4004)) {
  91. store.commit('setCoureLogin', 2);
  92. uni.removeStorageSync("userinfos")
  93. // uni.removeStorageSync('userInfo');
  94. uni.removeStorageSync('TOKEN_WEXIN');
  95. if(type==2) {
  96. uni.removeStorageSync(TOKEN_KEYAuto)
  97. }
  98. if(type==1) {
  99. uni.removeStorageSync('ManageToken');
  100. uni.navigateTo({
  101. url:'/pages_manage/login'
  102. })
  103. }
  104. resolve({ code: 401, data: null });
  105. return
  106. }
  107. //收到开发者服务器成功返回的回调函数
  108. if(res.data.code==401){//没有权限直接退出到登录界面
  109. let pages = getCurrentPages();
  110. let currentPage = pages[ pages.length - 1]; //当前页页面实例
  111. // 条件编译判断平台,设置不同登录页路径
  112. let loginPage = '';
  113. loginPage = '/pages/enterprise/enterprise';
  114. //如果登录界面已打开,自动关闭
  115. if (currentPage.route === loginPage.replace(/^\//, '')) {
  116. resolve(res.data);
  117. return;
  118. }
  119. uni.reLaunch({
  120. url:loginPage,
  121. success: () => {
  122. uni.hideLoading();
  123. },
  124. fail: () => {
  125. uni.hideLoading();
  126. }
  127. })
  128. return;
  129. }
  130. if (res.token&&type==0) {
  131. uni.setStorageSync(TOKEN_KEY,res.data.token)
  132. }
  133. resolve(res.data)
  134. },
  135. fail:(res) =>{
  136. //接口调用失败的回调函数
  137. },
  138. complete:(res) =>{
  139. //接口调用结束的回调函数(调用成功、失败都会执行)
  140. if (res.data&& res.data.code == 401) {
  141. return false
  142. }
  143. uni.hideLoading();
  144. }
  145. })
  146. })
  147. }
  148. }