灵活用工项目

config.js 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /** 小程序直连 API(体验版/开发版统一;有正式 HTTPS 域名后再改 env) */
  2. // const MP_API = 'http://192.168.1.6:8081/api/v1/mp'
  3. const MP_API = 'https://img.ifarmcloud.com/deploymentApi/api/v1/mp'
  4. // const MP_API = 'http://115.238.57.190:5200/api/v1/mp'
  5. /** H5 开发走 devServer 代理,避免浏览器跨域 */
  6. const H5_DEV_PROXY_API = '/api/v1/mp'
  7. function resolveBaseApi() {
  8. // H5 开发:请求 /api/... 由 vue.config.js / manifest h5.devServer 转发
  9. if (process.env.UNI_PLATFORM === 'h5' && process.env.NODE_ENV !== 'production') {
  10. return H5_DEV_PROXY_API
  11. }
  12. return process.env.VUE_APP_BASE_API || MP_API
  13. }
  14. /** API 基础路径 */
  15. export const BASE_API = resolveBaseApi()
  16. /**
  17. * 公开 API 前缀:/api/v1/mp → /api/v1/public
  18. * 公开草稿详情等不走 JWT,也不能拼在 mp 前缀下。
  19. */
  20. export const PUBLIC_BASE_API = (() => {
  21. const base = (BASE_API || '').replace(/\/$/, '')
  22. if (!base) return ''
  23. if (/\/mp$/i.test(base)) return base.replace(/\/mp$/i, '/public')
  24. return `${base}/public`
  25. })()
  26. /**
  27. * 将后端返回的相对资源路径(如登记二维码)拼成可访问 URL。
  28. * BASE_API=https://host/deploymentApi/api/v1/mp
  29. * → 相对路径 /api/v1/public/... 拼成 https://host/deploymentApi/api/v1/public/...
  30. */
  31. export function resolveApiAssetUrl(path) {
  32. if (!path) return ''
  33. const raw = String(path).trim()
  34. if (!raw) return ''
  35. if (/^https?:\/\//i.test(raw)) return raw
  36. const normalized = raw.startsWith('/') ? raw : `/${raw}`
  37. const base = (BASE_API || '').replace(/\/$/, '')
  38. const originMatch = base.match(/^(https?:\/\/[^/]+)(\/.*)?$/i)
  39. if (!originMatch) {
  40. // H5 代理模式:BASE_API 为 /api/v1/mp,同源相对路径直接可用
  41. return normalized
  42. }
  43. const origin = originMatch[1]
  44. // 保留 /api 前的网关前缀(如 /deploymentApi)
  45. const pathPart = originMatch[2] || ''
  46. const apiIdx = pathPart.toLowerCase().indexOf('/api/')
  47. const gatewayPrefix = apiIdx >= 0 ? pathPart.slice(0, apiIdx) : ''
  48. if (gatewayPrefix && normalized.toLowerCase().indexOf(gatewayPrefix.toLowerCase()) === 0) {
  49. return `${origin}${normalized}`
  50. }
  51. return `${origin}${gatewayPrefix}${normalized}`
  52. }
  53. /** 本地存储 Token 键名 */
  54. export const TOKEN_KEY = 'fe_token'
  55. /** 后端统一响应成功码 */
  56. export const SUCCESS_CODE = 200
  57. /** 智能体 ID,对应请求头 X-Agent-Id */
  58. export const AI_AGENT_ID = process.env.VUE_APP_AI_AGENT_ID || 'default'