siteConfig.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. // src/utils/site.ts
  2. // 开发环境:端口 → 站点
  3. const DEV_PORT_MAP: Record<string, any> = {
  4. '5101': 'www',
  5. '5102': 'b',
  6. '5103': 'mro',
  7. '5104': 'fuli',
  8. '5105': 'reg',
  9. '5106': 'breg',
  10. '5107': 'greg',
  11. '5108': 'passport',
  12. '5109': 'search',
  13. '5110': 'item',
  14. '5111': 'cart',
  15. '5112': 'trad',
  16. '5113': 'payc',
  17. '5114': 'order',
  18. '5115': 'plan',
  19. '5116': 'plan_info',
  20. '5117': 'i',
  21. '5118': 'easybuv'
  22. };
  23. // 每个站点允许的路由
  24. export const SITE_ROUTES: Record<any, string[]> = {
  25. www: ['/', '/index'], //优易365主站
  26. b: ['/indexB'], //企业购商城
  27. mro: ['/indexMro'], //工业品商城
  28. fuli: ['/indexFuli'], //福礼商城
  29. reg: ['/reg'], //个人注册
  30. breg: ['/breg'], //企业注册
  31. greg: ['/greg'], //供应商注册
  32. passport: ['/login'], //登录页
  33. search: ['/search'], //搜索
  34. item: ['/item'], //商品详情,
  35. cart: ['/cart'], //商品详情
  36. trad: ['/trad'], //确认订单信息
  37. payc: ['/payc'], //支付订单
  38. order: ['/order/orderManage', '/order/orderManage/detail', '/order/orderAudit', '/order/afterSale', '/order/batchOrder', '/order/orderEvaluation'], //订单列表
  39. plan: ['/plan'], //解决方案
  40. plan_info: ['/plan_info'], //信息展示
  41. i: ['/i'], //个人信息
  42. easybuv: ['/easybuv'] //地址管理
  43. };
  44. // 获取当前站点(开发用端口,线上用域名)
  45. export function getCurrentSite(): any {
  46. if (import.meta.env.PROD) {
  47. // 线上:根据域名判断
  48. const host = window.location.hostname;
  49. if (host === 'b.yoe365.com') return 'b';
  50. if (host === 'mro.yoe365.com') return 'mro';
  51. if (host === 'mro.yoe365.com') return 'fuli';
  52. if (host === 'mro.yoe365.com') return 'reg';
  53. if (host === 'mro.yoe365.com') return 'breg';
  54. if (host === 'mro.yoe365.com') return 'greg';
  55. if (host === 'mro.yoe365.com') return 'passport';
  56. if (host === 'mro.yoe365.com') return 'search';
  57. if (host === 'mro.yoe365.com') return 'item';
  58. if (host === 'mro.yoe365.com') return 'cart';
  59. if (host === 'mro.yoe365.com') return 'trad';
  60. if (host === 'mro.yoe365.com') return 'payc';
  61. if (host === 'mro.yoe365.com') return 'order';
  62. if (host === 'mro.yoe365.com') return 'plan';
  63. if (host === 'mro.yoe365.com') return 'plan_info';
  64. if (host === 'mro.yoe365.com') return 'i';
  65. if (host === 'mro.yoe365.com') return 'easybuv';
  66. return 'www';
  67. }
  68. // 本地:根据端口判断
  69. const port = window.location.port || '80';
  70. return DEV_PORT_MAP[port] || 'www';
  71. }
  72. // 根据站点返回 API 基地址
  73. export function getApiBase() {
  74. const site = getCurrentSite();
  75. const map: Record<any, string> = {
  76. www: 'https://www.yoe365.com',
  77. b: 'https://b.yoe365.com',
  78. mro: 'https://mro.yoe365.com',
  79. fuli: 'https://fuli.yoe365.com',
  80. reg: 'https://reg.yoe365.com',
  81. breg: 'https://breg.yoe365.com',
  82. greg: 'https://greg.yoe365.com',
  83. passport: 'https://passport.yoe365.com',
  84. search: 'https://search.yoe365.com',
  85. item: 'https://item.yoe365.com',
  86. cart: 'https://cart.yoe365.com',
  87. trad: 'https://trad.yoe365.com',
  88. payc: 'https://payc.yoe365.com',
  89. order: 'https://order.yoe365.com',
  90. plan: 'https://plan.yoe365.com',
  91. plan_info: 'https://plan_info.yoe365.com',
  92. i: 'https://i.yoe365.com',
  93. easybuv: 'https://easybuv.yoe365.com'
  94. };
  95. if (import.meta.env.PROD) {
  96. return map[site];
  97. } else {
  98. // return '/dev-api'
  99. // return 'http://192.168.1.52:8080';
  100. return 'https://ceshi.xiaoluwebsite.xyz';
  101. }
  102. }
  103. const PATH_TO_SITE_MAP: Record<string, any> = {};
  104. for (const [site, paths] of Object.entries(SITE_ROUTES)) {
  105. for (const path of paths) {
  106. PATH_TO_SITE_MAP[path] = site as any;
  107. }
  108. }
  109. export function getSiteByPath(path: string): any | null {
  110. // 支持带查询参数(如 /login?redirect=xxx)
  111. const cleanPath = path.split('?')[0];
  112. return PATH_TO_SITE_MAP[cleanPath] || null;
  113. }
  114. export function onPath(path: string) {
  115. const targetSite = getSiteByPath(path);
  116. if (!targetSite) {
  117. // window.open(url, '_blank');
  118. console.error(`[跨站跳转失败] 路径 "${path}" 未关联任何站点`);
  119. return;
  120. }
  121. let url = '';
  122. if (import.meta.env.PROD) {
  123. const domainMap: Record<any, string> = {
  124. www: 'https://www.yoe365.com',
  125. b: 'https://b.yoe365.com',
  126. mro: 'https://mro.yoe365.com',
  127. fuli: 'https://fuli.yoe365.com',
  128. reg: 'https://reg.yoe365.com',
  129. breg: 'https://breg.yoe365.com',
  130. greg: 'https://greg.yoe365.com',
  131. passport: 'https://passport.yoe365.com',
  132. search: 'https://search.yoe365.com',
  133. item: 'https://item.yoe365.com',
  134. cart: 'https://cart.yoe365.com',
  135. trad: 'https://trad.yoe365.com',
  136. payc: 'https://payc.yoe365.com',
  137. order: 'https://order.yoe365.com',
  138. plan: 'https://plan.yoe365.com',
  139. plan_info: 'https://plan_info.yoe365.com',
  140. i: 'https://i.yoe365.com',
  141. easybuv: 'https://easybuv.yoe365.com'
  142. };
  143. url = `${domainMap[targetSite]}${path}`;
  144. } else {
  145. const portMap: Record<any, string> = {
  146. www: 'http://localhost:5101',
  147. b: 'http://localhost:5102',
  148. mro: 'http://localhost:5103',
  149. fuli: 'http://localhost:5104',
  150. reg: 'http://localhost:5105',
  151. breg: 'http://localhost:5106',
  152. greg: 'http://localhost:5107',
  153. passport: 'http://localhost:5108',
  154. search: 'http://localhost:5109',
  155. item: 'http://localhost:5110',
  156. cart: 'http://localhost:5111',
  157. trad: 'http://localhost:5112',
  158. payc: 'http://localhost:5113',
  159. order: 'http://localhost:5114',
  160. plan: 'http://localhost:5115',
  161. plan_info: 'http://localhost:5116',
  162. i: 'http://localhost:5117',
  163. easybuv: 'http://localhost:5118'
  164. };
  165. url = `${portMap[targetSite]}${path}`;
  166. }
  167. window.open(url, '_blank');
  168. }