siteConfig.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // 每个站点允许的路由 (保持不变)
  2. export const SITE_ROUTES: Record<any, string[]> = {
  3. www: ['/', '/index', '/indexData'], //优易365主站
  4. b: ['/indexB'], //企业购商城
  5. mro: ['/indexMro'], //工业品商城
  6. fuli: ['/indexFuli'], //福礼商城
  7. reg: ['/reg'], //个人注册
  8. breg: ['/breg'], //企业注册
  9. greg: ['/greg'], //供应商注册
  10. passport: ['/login'], //登录页
  11. search: ['/search', '/search/special'], //搜索
  12. item: ['/item'], //商品详情,
  13. cart: ['/cart'], //商品详情
  14. trad: ['/trad'], //确认订单信息
  15. payc: ['/payc'], //支付订单
  16. plan: ['/plan', '/plan/procure', '/plan/guide', '/plan/project'], //解决方案
  17. plan_info: ['/plan_info', '/plan_info/procure', '/plan_info/guide', '/plan_info/project'], //信息展示
  18. order: [
  19. '/order/orderManage',
  20. '/order/orderManage/detail',
  21. '/order/orderAudit',
  22. '/order/afterSale',
  23. '/order/batchOrder',
  24. '/order/orderEvaluation',
  25. '/enterprise/companyInfo',
  26. '/enterprise/companyInfo/edit',
  27. '/enterprise/purchaseHabit',
  28. '/enterprise/invoiceManage',
  29. '/enterprise/agreementSupply',
  30. '/enterprise/companyInfo',
  31. '/enterprise/invoiceManage',
  32. '/enterprise/myCollection',
  33. '/enterprise/myFootprint',
  34. '/enterprise/purchaseHabit',
  35. '/enterprise/purchasePlan',
  36. '/enterprise/purchaseHistory',
  37. '/reconciliation/billManage',
  38. '/reconciliation/invoiceManage',
  39. '/organization/deptManage',
  40. '/organization/staffManage',
  41. '/organization/roleManage',
  42. '/valueAdded/maintenance',
  43. '/valueAdded/complaint',
  44. '/cost/itemExpense',
  45. '/cost/quotaControl',
  46. '/cost/quotaControl/apply',
  47. '/enterprise/purchasePlan',
  48. '/organization/approvalFlow',
  49. '/organization/approvalFlow/create',
  50. '/order/orderManage/detail/:orderNo',
  51. '/order/orderManage/applyAfter',
  52. '/valueAdded/maintenanceApply',
  53. '/enterprise/messageNotice',
  54. '/enterprise/securitySetting',
  55. '/enterprise/securitySetting/resetPassword',
  56. '/enterprise/securitySetting/changePhone',
  57. '/enterprise/changePerson',
  58. '/order/orderEvaluation/evaluation'
  59. ], //订单列表
  60. i: ['/i'], //个人信息
  61. easybuv: ['/easybuv'] //地址管理
  62. };
  63. // 获取当前站点
  64. export function getCurrentSite(): any {
  65. // 无论是生产还是开发,现在都统一通过域名判断
  66. const host = window.location.hostname;
  67. // 定义本地开发环境的域名映射关系
  68. // 确保你的 hosts 文件已经配置了这些域名指向 127.0.0.1
  69. if (host === 'www.xiaoluwebsite.xyz' || host === 'localhost') return 'www'; // 兼容未配hosts的情况
  70. if (host === 'b.xiaoluwebsite.xyz') return 'b';
  71. if (host === 'mro.xiaoluwebsite.xyz') return 'mro';
  72. if (host === 'fuli.xiaoluwebsite.xyz') return 'fuli';
  73. if (host === 'reg.xiaoluwebsite.xyz') return 'reg';
  74. if (host === 'breg.xiaoluwebsite.xyz') return 'breg';
  75. if (host === 'greg.xiaoluwebsite.xyz') return 'greg';
  76. if (host === 'passport.xiaoluwebsite.xyz') return 'passport';
  77. if (host === 'search.xiaoluwebsite.xyz') return 'search';
  78. if (host === 'item.xiaoluwebsite.xyz') return 'item';
  79. if (host === 'cart.xiaoluwebsite.xyz') return 'cart';
  80. if (host === 'trad.xiaoluwebsite.xyz') return 'trad';
  81. if (host === 'payc.xiaoluwebsite.xyz') return 'payc';
  82. if (host === 'order.xiaoluwebsite.xyz') return 'order';
  83. if (host === 'plan.xiaoluwebsite.xyz') return 'plan';
  84. if (host === 'plan_info.xiaoluwebsite.xyz') return 'plan_info';
  85. if (host === 'i.xiaoluwebsite.xyz') return 'i';
  86. if (host === 'easybuv.xiaoluwebsite.xyz') return 'easybuv';
  87. // 生产环境逻辑 (保持不变,或者合并到上面的判断中)
  88. if (import.meta.env.PROD) {
  89. // 如果上面没匹配到,且是生产环境,可以尝试原有的逻辑或默认返回 www
  90. // 这里建议直接复用上面的 hostname 判断,因为生产环境也是域名
  91. return 'www';
  92. }
  93. return 'www'; // 默认 fallback
  94. }
  95. // ... PATH_TO_SITE_MAP 和 getSiteByPath 保持不变 ...
  96. const PATH_TO_SITE_MAP: Record<string, any> = {};
  97. for (const [site, paths] of Object.entries(SITE_ROUTES)) {
  98. for (const path of paths) {
  99. PATH_TO_SITE_MAP[path] = site as any;
  100. }
  101. }
  102. export function getSiteByPath(path: string): any | null {
  103. const cleanPath = path.split('?')[0];
  104. return PATH_TO_SITE_MAP[cleanPath] || null;
  105. }
  106. // 跨站跳转逻辑
  107. import router from '@/router';
  108. export function onPath(path: string) {
  109. console.log('[跨站跳转]', path);
  110. // return
  111. if (import.meta.env.VITE_DOMAIN_NAME == 'true') {
  112. const targetSite = getSiteByPath(path);
  113. if (!targetSite) {
  114. console.error(`[跨站跳转失败] 路径 "${path}" 未关联任何站点`);
  115. return;
  116. }
  117. const currentSite = getCurrentSite();
  118. // 【新增】判断是否是同域名
  119. const isSameSite = currentSite === targetSite;
  120. let url = '';
  121. // 域名映射表 (保持不变)
  122. const domainMap: Record<string, string> = {
  123. www: 'www.xiaoluwebsite.xyz',
  124. b: 'b.xiaoluwebsite.xyz',
  125. mro: 'mro.xiaoluwebsite.xyz',
  126. fuli: 'fuli.xiaoluwebsite.xyz',
  127. reg: 'reg.xiaoluwebsite.xyz',
  128. breg: 'breg.xiaoluwebsite.xyz',
  129. greg: 'greg.xiaoluwebsite.xyz',
  130. passport: 'passport.xiaoluwebsite.xyz',
  131. search: 'search.xiaoluwebsite.xyz',
  132. item: 'item.xiaoluwebsite.xyz',
  133. cart: 'cart.xiaoluwebsite.xyz',
  134. trad: 'trad.xiaoluwebsite.xyz',
  135. payc: 'payc.xiaoluwebsite.xyz',
  136. order: 'order.xiaoluwebsite.xyz',
  137. plan: 'plan.xiaoluwebsite.xyz',
  138. plan_info: 'plan_info.xiaoluwebsite.xyz',
  139. i: 'i.xiaoluwebsite.xyz',
  140. easybuv: 'easybuv.xiaoluwebsite.xyz'
  141. };
  142. const baseDomain = domainMap[targetSite];
  143. if (import.meta.env.PROD) {
  144. url = `https://${baseDomain}${path}`;
  145. } else {
  146. const devPort = window.location.port || import.meta.env.VITE_APP_PORT;
  147. url = `https://${baseDomain}:${devPort}${path}`;
  148. }
  149. // 【修改】根据是否同域名决定跳转方式
  150. if (isSameSite) {
  151. // 同域名且传入了 router,使用 Vue Router 内部跳转
  152. router.push(path);
  153. } else {
  154. // 跨域名 或 未传入 router,使用 window.open 打开新窗口
  155. window.open(url, '_blank');
  156. }
  157. } else {
  158. router.push(path);
  159. }
  160. }