env.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * 小程序环境开关 —— **只改这一处** 即可切换本机 / 测试 / 生产 / 本机联调 H5
  3. *
  4. * | APP_ENV 值 | 用途 |
  5. * |------------------|------|
  6. * | `local` | 本机 backend + 本机 web-admin |
  7. * | `test` | 测试门户(API / H5 / 静态 均 9911) |
  8. * | `testLocalH5` | 测试 API + 本机 H5(仅联调 webview 样式;需本机 `pnpm dev` 且代理到测试 API) |
  9. * | `production` | 生产门户 https://w.shanxiachem.com |
  10. *
  11. * 上生产:改成 `export const APP_ENV = 'production'`,再执行 `npm run release:check-api`
  12. */
  13. export const APP_ENV = 'production'
  14. /** 微信小程序 AppID(生产正式号;测试号若不同可按环境再拆) */
  15. export const WECHAT_MP_APPID = 'wx7db1ddb2a90c9425'
  16. /**
  17. * 环境预设(由生产 Web https://w.shanxiachem.com/ 与部署文档核对)
  18. *
  19. * | 项 | 生产实测 |
  20. * |----|----------|
  21. * | Web | https://w.shanxiachem.com/ |
  22. * | API | https://w.shanxiachem.com/api |
  23. * | 静态资源 | https://w.shanxiachem.com/shanxia-static/ |
  24. * | MinIO 反代 | https://w.shanxiachem.com/ruoyi |
  25. */
  26. export const ENV_PRESETS = {
  27. local: {
  28. key: 'local',
  29. label: '本机',
  30. apiBaseUrl: 'http://127.0.0.1:8000/api',
  31. staticAssetsBaseUrl: 'http://121.43.228.102:9911/shanxia-static/',
  32. webOrigin: 'http://127.0.0.1:3006',
  33. minioBaseUrl: 'http://47.99.164.66:20004/zkxw'
  34. },
  35. test: {
  36. key: 'test',
  37. label: '测试',
  38. apiBaseUrl: 'http://121.43.228.102:9911/api',
  39. staticAssetsBaseUrl: 'http://121.43.228.102:9911/shanxia-static/',
  40. webOrigin: 'http://121.43.228.102:9911',
  41. minioBaseUrl: 'http://121.43.228.102:9911/ruoyi'
  42. },
  43. /** 测试业务数据 + 本机 H5 资源(改样式时用,不用于发测试包) */
  44. testLocalH5: {
  45. key: 'testLocalH5',
  46. label: '测试API+本机H5',
  47. apiBaseUrl: 'http://121.43.228.102:9911/api',
  48. staticAssetsBaseUrl: 'http://121.43.228.102:9911/shanxia-static/',
  49. webOrigin: 'http://127.0.0.1:3006',
  50. minioBaseUrl: 'http://121.43.228.102:9911/ruoyi'
  51. },
  52. production: {
  53. key: 'production',
  54. label: '生产',
  55. apiBaseUrl: 'https://w.shanxiachem.com/api',
  56. staticAssetsBaseUrl: 'https://w.shanxiachem.com/shanxia-static/',
  57. webOrigin: 'https://w.shanxiachem.com',
  58. minioBaseUrl: 'https://w.shanxiachem.com/ruoyi'
  59. }
  60. }
  61. const preset = ENV_PRESETS[APP_ENV] || ENV_PRESETS.local
  62. export const CURRENT_ENV = preset
  63. export const IS_PRODUCTION = preset.key === 'production'
  64. export const IS_TEST = preset.key === 'test'
  65. export const IS_TEST_LOCAL_H5 = preset.key === 'testLocalH5'
  66. export const IS_LOCAL = preset.key === 'local'
  67. export const API_BASE_URL = preset.apiBaseUrl
  68. export const STATIC_ASSETS_BASE_URL = preset.staticAssetsBaseUrl
  69. export const WEB_ORIGIN = preset.webOrigin
  70. export const MINIO_BASE_URL = preset.minioBaseUrl
  71. /** 每次调用按当前 APP_ENV 取值,避免热更新后 api.js 里拷贝的常量仍指向旧环境 */
  72. export function resolveApiBase() {
  73. return (ENV_PRESETS[APP_ENV] || ENV_PRESETS.local).apiBaseUrl
  74. }
  75. export function resolveWebOrigin() {
  76. return (ENV_PRESETS[APP_ENV] || ENV_PRESETS.local).webOrigin
  77. }