request.js 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 中是否注释判断批发商才能注释的代码
  9. */
  10. // const host = 'http://fuzai.woaidakele.cn' //测试
  11. const host = 'http://tw.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.reLaunch({
  41. url: 'pages/login-reg/login-reg'
  42. });
  43. uni.removeStorageSync('isHelper')
  44. }
  45. }
  46. })
  47. return
  48. }
  49. if (response.statusCode === 200) {
  50. if (+response.data.code === 202) {
  51. uni.$emit('TOAST', response.data.message)
  52. }
  53. } else if (response.statusCode === 401) { // 服务器响应不为 200 的统一处理方法
  54. uni.$emit('TOAST', '登录信息过期,请重新登录')
  55. uni.$emit('RELAUNCH')
  56. } else {
  57. // uni.$emit('TOAST', `网络好像出了点问题:${response.statusCode}/${args[1]}`)
  58. }
  59. return response
  60. })
  61. request.onerror = (...args) => { // 请求失败统一处理方法
  62. uni.hideLoading()
  63. uni.$emit('HIDELOADING') // 隐藏加载
  64. uni.stopPullDownRefresh() // 停止下拉刷新
  65. // uni.$emit('TOAST', `网络好像出了点问题`)
  66. }
  67. function toWxchatLogin(url, state) {
  68. url = url || '/pages/index/index';
  69. state = state || 'cli';
  70. const redirect_uri = encodeURIComponent(`${$config.redirect_uri}/api/gzh#${url}`);
  71. const auth = () =>
  72. (window.location.href = `${$config.wxURL}?appid=${
  73. $config.appid
  74. }&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=${state}#wechat_redirect`);
  75. auth();
  76. };
  77. export const AddQrCode = `${host}:${port}${url}/AddQrCode` //邀请客户链接(线下注册)
  78. export const AddQrCodeUp = `${host}:${port}${url}/AddQrCodeUp` //邀请客户链接(微店注册)
  79. export const QYInfo = `${host}:${port}${url}/QYInfo/Pdf` //获取合同详情
  80. export default request
  81. export const FlashScreenUrl = 'https://api.jiuweiyun.cn/public/uploads/images/topics/420.jpg' // app 闪屏固定url
  82. export const ArticleURL = `${host}:${port}${url}/article/show_article` // 文章固定链接
  83. export const UploadApplyImgUrl = `${host}:${port}${url}/apply/UploadApplyImg` //客户升降级上传图片
  84. export const uploadCollectionImg = `${host}:${port}${url}/sharon/sharon/uploadCollectionImg` //沙龙添加收款图片
  85. export const uploadSharonImg = `${host}:${port}${url}/sharon/sharon/uploadSharonImg` //添加沙龙图片
  86. export const hostUrl = `${host}:${port}${url}` //添加沙龙图片
  87. export const uploadFiveImage = `${host}:${port}${url}/team/uploadFiveImage` //上传申请人零售的收款凭证