config.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. * 应用全局配置
  3. *
  4. * 环境切换方式:
  5. * 1. 开发环境(默认):从 VUE_APP_API_BASE 环境变量读取,或回退到默认值
  6. * 2. 测试环境:配置 VUE_APP_API_BASE=https://test-api.xxx.com
  7. * 3. 生产环境:配置 VUE_APP_API_BASE=https://api.xxx.com
  8. *
  9. * uni-app vue-cli 项目通过 .env 文件设置环境变量:
  10. * .env.development — VUE_APP_API_BASE=http://localhost:9080
  11. * .env.production — VUE_APP_API_BASE=https://api.xxx.com
  12. * .env.staging — VUE_APP_API_BASE=https://staging-api.xxx.com
  13. *
  14. * 如果未配置环境变量,默认使用开发环境地址。
  15. */
  16. // #ifndef VUE_APP_API_BASE
  17. const API_BASE_URL = process.env.VUE_APP_API_BASE || 'http://localhost:9080'
  18. // #endif
  19. // #ifdef VUE_APP_API_BASE
  20. const API_BASE_URL = VUE_APP_API_BASE
  21. // #endif
  22. // DAN测评服务(独立服务,可能不同端口)
  23. const DANSHOP_BASE_URL = process.env.VUE_APP_DANSHOP_BASE || 'http://localhost:8081'
  24. export default {
  25. API_BASE_URL,
  26. DANSHOP_BASE_URL,
  27. /** 构建 API 完整 URL */
  28. api(path) {
  29. return API_BASE_URL + path
  30. },
  31. /** 构建 DAN 测评 API URL */
  32. danshop(path) {
  33. return DANSHOP_BASE_URL + path
  34. }
  35. }