config.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * 应用全局配置
  3. *
  4. * 环境自动检测(基于微信小程序官方 API):
  5. * uni.getAccountInfoSync().miniProgram.envVersion
  6. * 'develop' → 开发版(工具内预览)
  7. * 'trial' → 体验版(上传到体验版)
  8. * 'release' → 正式版(线上发布)
  9. *
  10. * 无需手动修改任何变量,发布到对应环境自动生效。
  11. */
  12. // 默认值(兜底)
  13. let API_BASE_URL = 'http://localhost:9082'
  14. let DANSHOP_BASE_URL = 'http://localhost:8081'
  15. try {
  16. const accountInfo = uni.getAccountInfoSync()
  17. const env = accountInfo && accountInfo.miniProgram && accountInfo.miniProgram.envVersion
  18. if (env) {
  19. switch (env) {
  20. case 'develop':
  21. // 开发版 - 本地开发
  22. API_BASE_URL = 'http://localhost:9082'
  23. DANSHOP_BASE_URL = 'http://localhost:9081'
  24. break
  25. case 'trial':
  26. // 体验版
  27. API_BASE_URL = 'https://cfc.iwintrue.com'
  28. DANSHOP_BASE_URL = 'https://dev.iwintrue.com/danshop'
  29. break
  30. case 'release':
  31. // 正式版
  32. API_BASE_URL = 'https://cfc.etotem.com.cn'
  33. DANSHOP_BASE_URL = 'https://danshop.etotem.com.cn'
  34. break
  35. }
  36. }
  37. } catch (e) {
  38. // uni.getAccountInfoSync() 不可用(非小程序环境),使用默认值
  39. }
  40. export default {
  41. API_BASE_URL,
  42. DANSHOP_BASE_URL,
  43. /** 构建 API 完整 URL */
  44. api(path) {
  45. return API_BASE_URL + path
  46. },
  47. /** 构建 DAN 测评 API URL */
  48. danshop(path) {
  49. return DANSHOP_BASE_URL + path
  50. }
  51. }