request.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import Vue from 'vue'
  2. import $store from '@/store'
  3. import $config from '@/config'
  4. import uni_request from './uni_request.js'
  5. /*
  6. 线上appid wxd684a5cf4af0a810
  7. 线上接口地址 http://api.woaidakele.cn
  8. *** index 页面中跳转的url 对应页面 每次上线之前查看 onLoad 中是否注释判断pifashang才能注释的代码
  9. */
  10. // const host = 'http://fuzai.woaidakele.cn' //测试
  11. const host = 'http://api.app.cliu.cc' //正式环境
  12. // const host = 'http://app.jiuweiyun.cn' //App测
  13. // const host = 'http://test.woaidakele.cn' //测试环境
  14. const port = 80 //正式环境
  15. // const port =8081 //测
  16. const url = '/api'
  17. // uni.onNetworkStatusChange(res => { $store.commit('device/NETWORKTYPE_CHANGE', res.networkType) }) // 网络类型变化监听
  18. // uni.getNetworkType({ success(res) { $store.commit('device/NETWORKTYPE_CHANGE', res.networkType) }}) // 获取网络类型
  19. const request = uni_request({
  20. timeout: 123456,
  21. baseURL: `${host}:${port}${url}`,
  22. })
  23. request.interceptors.request.use(config => {
  24. config.header.Authorization = 'Bearer ' + $store.state.app.token
  25. config.header.helper = $store.state.app.helper
  26. return config
  27. })
  28. request.interceptors.response.use((response, ...args) => { // 拦截器
  29. uni.hideLoading()
  30. uni.$emit('HIDELOADING') // 隐藏加载
  31. uni.stopPullDownRefresh() // 停止下拉刷新
  32. if (response.data.code == 451101) { // 助手请求验证
  33. uni.showModal({
  34. content: response.data.message || '操作失败',
  35. showCancel: false,
  36. success: function (res) {
  37. if (res.confirm) {
  38. $store.commit('app/LOGOUT')
  39. toWxchatLogin("/pages/login-reg/login-reg", null)
  40. uni.removeStorageSync('isHelper')
  41. }
  42. }
  43. })
  44. return
  45. }
  46. if (response.statusCode === 200) {
  47. if (+response.data.code === 202) {
  48. uni.$emit('TOAST', response.data.message)
  49. }
  50. } else if (response.statusCode === 401) { // 服务器响应不为 200 的统一处理方法
  51. uni.showModal({
  52. content: '登录状态过期,请重新登录',
  53. showCancel: false,
  54. success: function (e) {
  55. if (e.confirm) {
  56. $store.commit('app/LOGOUT')
  57. toWxchatLogin("/pages/login-reg/login-reg", null)
  58. }
  59. }
  60. })
  61. return
  62. uni.$emit('TOAST', '登录信息过期,请重新登录')
  63. uni.$emit('RELAUNCH')
  64. } else {
  65. uni.$emit('TOAST', `网络好像出了点问题:${response.statusCode}/${args[1]}`)
  66. }
  67. return response
  68. })
  69. request.onerror = (...args) => { // 请求失败统一处理方法
  70. uni.hideLoading()
  71. uni.$emit('HIDELOADING') // 隐藏加载
  72. uni.stopPullDownRefresh() // 停止下拉刷新
  73. // uni.$emit('TOAST', `网络好像出了点问题`)
  74. }
  75. function toWxchatLogin(url, state) {
  76. url = url || '/pages/index/index';
  77. state = state || 'cli';
  78. const redirect_uri = encodeURIComponent(`${$config.redirect_uri}/api/gzh#${url}`);
  79. const auth = () =>
  80. (window.location.href = `${$config.wxURL}?appid=${
  81. $config.appid
  82. }&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=${state}#wechat_redirect`);
  83. auth();
  84. };
  85. export const AddQrCode = `${host}:${port}${url}/AddQrCode` //邀请客户链接(线下注册)
  86. export const AddQrCodeUp = `${host}:${port}${url}/AddQrCodeUp` //邀请客户链接(微店注册)
  87. export const QYInfo = `${host}:${port}${url}/QYInfo/Pdf` //获取合同详情
  88. export default request
  89. export const FlashScreenUrl = 'https://api.jiuweiyun.cn/public/uploads/images/topics/420.jpg' // app 闪屏固定url
  90. export const ArticleURL = `${host}:${port}${url}/article/show_article` // 文章固定链接
  91. export const UploadApplyImgUrl = `${host}:${port}${url}/apply/UploadApplyImg` //客户升降级上传图片
  92. export const uploadCollectionImg = `${host}:${port}${url}/sharon/sharon/uploadCollectionImg` //沙龙添加收款图片
  93. export const uploadSharonImg = `${host}:${port}${url}/sharon/sharon/uploadSharonImg` //添加沙龙图片
  94. export const hostUrl = `${host}:${port}${url}` //添加沙龙图片
  95. export const uploadFiveImage = `${host}:${port}${url}/team/uploadFiveImage` //上传申请人零售的收款凭证
  96. export const UploadSzyImg = `${host}:${port}${url}/HuiFuSZ/ImageEnroll` //实战营人脸照片上传