西藏巴青项目

index.js 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * 接口根地址(与 ruoyi-ui 的 VUE_APP_BASE_API 对齐)
  3. *
  4. * - 开发:.env.development → /dev-api(H5 代理)或 VITE_APP_API_HOST 直连
  5. * - 生产:.env.production → /prod-api(与 ruoyi-ui/.env.production 一致,由 Nginx 转发)
  6. *
  7. * 打包 H5:uni build -p h5
  8. */
  9. const apiHost = String(import.meta.env.VITE_APP_API_HOST || 'http://192.168.1.6:8010').replace(/\/$/, '')
  10. /** 与 ruoyi-ui 的 VUE_APP_BASE_API 同源配置(dev/prod 由 .env 注入) */
  11. const envBaseApi = String(import.meta.env.VITE_APP_BASE_API || '').trim()
  12. /**
  13. * H5 开发是否走 /dev-api 代理(需 vite.config.js rewrite)
  14. * 默认 false:直连 VITE_APP_API_HOST
  15. */
  16. export const H5_USE_PROXY = false
  17. function resolveBaseApi() {
  18. if (import.meta.env.PROD) {
  19. return envBaseApi || '/prod-api'
  20. }
  21. const devBase = envBaseApi || '/dev-api'
  22. // #ifdef H5
  23. return H5_USE_PROXY ? devBase : apiHost
  24. // #endif
  25. // #ifndef H5
  26. return apiHost
  27. // #endif
  28. }
  29. export const BASE_API = resolveBaseApi()
  30. /**
  31. * 拼接接口或静态资源地址(/login、/profile/...)
  32. * @param {string} path
  33. */
  34. export function joinApiUrl(path) {
  35. if (!path) {
  36. return BASE_API
  37. }
  38. if (/^https?:\/\//i.test(path)) {
  39. return path
  40. }
  41. const p = path.startsWith('/') ? path : '/' + path
  42. const base = String(BASE_API).replace(/\/$/, '')
  43. return base + p
  44. }
  45. /** 交易市场项目专用,与 ruoyi-ui-app 的 Admin-Token 隔离,避免同端登录态串用 */
  46. export const TOKEN_KEY = 'Jiaoyi-Admin-Token'
  47. export const REMEMBER_USERNAME_KEY = 'jiaoyi_login_username'