index.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { ProjectName } from '@/config'
  2. // #ifdef MP-WEIXIN
  3. const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {}
  4. // #endif
  5. // 常量索引
  6. const envVal = {
  7. // #ifdef H5
  8. imgUrl: `${window.location.protocol}//img.${getFirstHost()}.com`,
  9. // #endif
  10. // #ifdef MP-WEIXIN
  11. imgUrl: extConfig.imgHost,
  12. // #endif
  13. env: process.env.NODE_ENV,
  14. // 本地连接地址
  15. hostUrl: null,
  16. // 请求接口地址
  17. formal: null,
  18. // 项目来源
  19. source: ProjectName,
  20. // 第一个host
  21. firstHost: getFirstHost()
  22. }
  23. // 项目配置
  24. // #ifdef H5
  25. envVal.formal = process.env.NODE_ENV == 'development' ? 'http://shop.theflorist.cn' : `${window.location.protocol}//${window.location.host}`
  26. envVal.hostUrl = process.env.NODE_ENV == 'development' ? `http://api.shop.theflorist.cn` : `${window.location.protocol}//api.${window.location.host}`
  27. // #endif
  28. // #ifdef MP-WEIXIN
  29. envVal.formal = process.env.NODE_ENV == 'development' ? extConfig.apiHost : extConfig.apiHost
  30. envVal.hostUrl = process.env.NODE_ENV == 'development' ? extConfig.apiHost : extConfig.apiHost
  31. // #endif
  32. function getFirstHost() {
  33. let host = ''
  34. // #ifdef H5
  35. host = window.location.host
  36. host = host.split('.')
  37. host = host.length == 3 ? host[1] : host[0]
  38. // #endif
  39. // #ifndef H5
  40. host = extConfig.apiHost
  41. // #endif
  42. return process.env.NODE_ENV == 'development' ? 'huaml' : host
  43. }
  44. export default envVal