config.js 883 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * 应用全局配置
  3. * 环境自动检测(基于微信小程序官方 API)
  4. */
  5. // #ifdef H5
  6. // H5 端:走同域相对路径,由 nginx 将 /api 代理到后端 9083
  7. let API_BASE_URL = ''
  8. // #endif
  9. // #ifndef H5
  10. let API_BASE_URL = 'http://localhost:9083'
  11. try {
  12. const accountInfo = uni.getAccountInfoSync()
  13. const env = accountInfo && accountInfo.miniProgram && accountInfo.miniProgram.envVersion
  14. if (env) {
  15. switch (env) {
  16. case 'develop':
  17. API_BASE_URL = 'https://cmai.etotem.com.cn'
  18. break
  19. case 'trial':
  20. API_BASE_URL = 'https://cmai.etotem.com.cn'
  21. break
  22. case 'release':
  23. API_BASE_URL = 'https://cmai.etotem.com.cn'
  24. break
  25. }
  26. }
  27. } catch (e) {
  28. // 非小程序环境(H5/dev),使用默认地址
  29. }
  30. // #endif
  31. export default {
  32. API_BASE_URL,
  33. api(path) {
  34. return API_BASE_URL + path
  35. }
  36. }