config.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * 应用全局配置
  3. *
  4. * 环境自动检测(基于微信小程序官方 API):
  5. * uni.getAccountInfoSync().miniProgram.envVersion
  6. * 'develop' → 开发版(工具内预览)
  7. * 'trial' → 体验版(上传到体验版)
  8. * 'release' → 正式版(线上发布)
  9. *
  10. * 无需手动修改任何变量,发布到对应环境自动生效。
  11. */
  12. let API_BASE_URL = 'https://cfc.etotem.com.cn'
  13. try {
  14. const accountInfo = uni.getAccountInfoSync()
  15. const env = accountInfo && accountInfo.miniProgram && accountInfo.miniProgram.envVersion
  16. if (env) {
  17. switch (env) {
  18. case 'develop':
  19. //API_BASE_URL = 'http://cfc.iwintrue.com'
  20. //API_BASE_URL = 'http://192.168.1.57:9082'
  21. API_BASE_URL = 'https://cfc.etotem.com.cn'
  22. break
  23. case 'trial':
  24. API_BASE_URL = 'https://cfc.etotem.com.cn'
  25. break
  26. case 'release':
  27. API_BASE_URL = 'https://cfc.etotem.com.cn'
  28. break
  29. }
  30. }
  31. } catch (e) {
  32. // 非小程序环境(H5/dev):使用默认地址。
  33. // 关键:H5 页面部署在 cfc.iwintrue.com(HTTPS 反代),若 API_BASE_URL 指向 http:// 会触发
  34. // Mixed Content 被浏览器拦截;故 H5 下按页面当前协议自动选择(同源,避免跨域+CSP 问题)。
  35. try {
  36. if (typeof window !== 'undefined' && window.location && window.location.protocol) {
  37. const proto = window.location.protocol // 'https:' | 'http:'
  38. API_BASE_URL = proto + '//cfc.iwintrue.com'
  39. }
  40. } catch (e2) {
  41. // 保底:维持模块顶部默认值
  42. }
  43. }
  44. export default {
  45. API_BASE_URL,
  46. api(path) {
  47. return API_BASE_URL + path
  48. }
  49. }