siteConfig.ts 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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', '/search/special'], //搜索
  34. item: ['/item'], //商品详情,
  35. cart: ['/cart'], //商品详情
  36. trad: ['/trad'], //确认订单信息
  37. payc: ['/payc'], //支付订单
  38. plan: ['/plan', '/plan/procure', '/plan/guide', '/plan/project'], //解决方案
  39. plan_info: ['/plan_info', '/plan_info/procure', '/plan_info/guide', '/plan_info/project'], //信息展示
  40. order: [
  41. '/order/orderManage',
  42. '/order/orderManage/detail',
  43. '/order/orderAudit',
  44. '/order/afterSale',
  45. '/order/batchOrder',
  46. '/order/orderEvaluation',
  47. '/enterprise/companyInfo',
  48. '/enterprise/companyInfo/edit',
  49. '/enterprise/purchaseHabit',
  50. '/enterprise/invoiceManage',
  51. '/enterprise/agreementSupply',
  52. '/enterprise/companyInfo',
  53. '/enterprise/invoiceManage',
  54. '/enterprise/myCollection',
  55. '/enterprise/myFootprint',
  56. '/enterprise/purchaseHabit',
  57. '/enterprise/purchasePlan',
  58. '/enterprise/purchaseHistory',
  59. '/reconciliation/billManage',
  60. '/reconciliation/invoiceManage',
  61. '/organization/deptManage',
  62. '/organization/staffManage',
  63. '/organization/roleManage',
  64. '/valueAdded/maintenance',
  65. '/valueAdded/complaint',
  66. '/cost/itemExpense',
  67. '/cost/quotaControl',
  68. '/cost/quotaControl/apply',
  69. '/enterprise/purchasePlan',
  70. '/organization/approvalFlow',
  71. '/organization/approvalFlow/create',
  72. '/order/orderManage/detail/:orderNo'
  73. ], //订单列表
  74. i: ['/i'], //个人信息
  75. easybuv: ['/easybuv'] //地址管理
  76. };
  77. // 获取当前站点(开发用端口,线上用域名)
  78. export function getCurrentSite(): any {
  79. if (import.meta.env.PROD) {
  80. // 线上:根据域名判断
  81. const host = window.location.hostname;
  82. if (host === 'b.yoe365.com') return 'b';
  83. if (host === 'mro.yoe365.com') return 'mro';
  84. if (host === 'mro.yoe365.com') return 'fuli';
  85. if (host === 'mro.yoe365.com') return 'reg';
  86. if (host === 'mro.yoe365.com') return 'breg';
  87. if (host === 'mro.yoe365.com') return 'greg';
  88. if (host === 'mro.yoe365.com') return 'passport';
  89. if (host === 'mro.yoe365.com') return 'search';
  90. if (host === 'mro.yoe365.com') return 'item';
  91. if (host === 'mro.yoe365.com') return 'cart';
  92. if (host === 'mro.yoe365.com') return 'trad';
  93. if (host === 'mro.yoe365.com') return 'payc';
  94. if (host === 'mro.yoe365.com') return 'order';
  95. if (host === 'mro.yoe365.com') return 'plan';
  96. if (host === 'mro.yoe365.com') return 'plan_info';
  97. if (host === 'mro.yoe365.com') return 'i';
  98. if (host === 'mro.yoe365.com') return 'easybuv';
  99. return 'www';
  100. }
  101. // 本地:根据端口判断
  102. const port = window.location.port || '80';
  103. return DEV_PORT_MAP[port] || 'www';
  104. }
  105. // 根据站点返回 API 基地址
  106. export function getApiBase() {
  107. const site = getCurrentSite();
  108. const map: Record<any, string> = {
  109. www: 'https://www.yoe365.com',
  110. b: 'https://b.yoe365.com',
  111. mro: 'https://mro.yoe365.com',
  112. fuli: 'https://fuli.yoe365.com',
  113. reg: 'https://reg.yoe365.com',
  114. breg: 'https://breg.yoe365.com',
  115. greg: 'https://greg.yoe365.com',
  116. passport: 'https://passport.yoe365.com',
  117. search: 'https://search.yoe365.com',
  118. item: 'https://item.yoe365.com',
  119. cart: 'https://cart.yoe365.com',
  120. trad: 'https://trad.yoe365.com',
  121. payc: 'https://payc.yoe365.com',
  122. order: 'https://order.yoe365.com',
  123. plan: 'https://plan.yoe365.com',
  124. plan_info: 'https://plan_info.yoe365.com',
  125. i: 'https://i.yoe365.com',
  126. easybuv: 'https://easybuv.yoe365.com'
  127. };
  128. if (import.meta.env.PROD) {
  129. return map[site];
  130. } else {
  131. // return '/dev-api'
  132. // return 'http://192.168.1.52:8080';
  133. // return 'https://ceshi.xiaoluwebsite.xyz';
  134. return 'http://localhost:8080';
  135. }
  136. }
  137. const PATH_TO_SITE_MAP: Record<string, any> = {};
  138. for (const [site, paths] of Object.entries(SITE_ROUTES)) {
  139. for (const path of paths) {
  140. PATH_TO_SITE_MAP[path] = site as any;
  141. }
  142. }
  143. export function getSiteByPath(path: string): any | null {
  144. // 支持带查询参数(如 /login?redirect=xxx)
  145. const cleanPath = path.split('?')[0];
  146. return PATH_TO_SITE_MAP[cleanPath] || null;
  147. }
  148. export function onPath(path: string) {
  149. const targetSite = getSiteByPath(path);
  150. if (!targetSite) {
  151. // window.open(url, '_blank');
  152. console.error(`[跨站跳转失败] 路径 "${path}" 未关联任何站点`);
  153. return;
  154. }
  155. let url = '';
  156. if (import.meta.env.PROD) {
  157. const domainMap: Record<any, string> = {
  158. www: 'https://www.yoe365.com',
  159. b: 'https://b.yoe365.com',
  160. mro: 'https://mro.yoe365.com',
  161. fuli: 'https://fuli.yoe365.com',
  162. reg: 'https://reg.yoe365.com',
  163. breg: 'https://breg.yoe365.com',
  164. greg: 'https://greg.yoe365.com',
  165. passport: 'https://passport.yoe365.com',
  166. search: 'https://search.yoe365.com',
  167. item: 'https://item.yoe365.com',
  168. cart: 'https://cart.yoe365.com',
  169. trad: 'https://trad.yoe365.com',
  170. payc: 'https://payc.yoe365.com',
  171. order: 'https://order.yoe365.com',
  172. plan: 'https://plan.yoe365.com',
  173. plan_info: 'https://plan_info.yoe365.com',
  174. i: 'https://i.yoe365.com',
  175. easybuv: 'https://easybuv.yoe365.com'
  176. };
  177. url = `${domainMap[targetSite]}${path}`;
  178. } else {
  179. const portMap: Record<any, string> = {
  180. www: 'http://localhost:5101',
  181. b: 'http://localhost:5102',
  182. mro: 'http://localhost:5103',
  183. fuli: 'http://localhost:5104',
  184. reg: 'http://localhost:5105',
  185. breg: 'http://localhost:5106',
  186. greg: 'http://localhost:5107',
  187. passport: 'http://localhost:5108',
  188. search: 'http://localhost:5109',
  189. item: 'http://localhost:5110',
  190. cart: 'http://localhost:5111',
  191. trad: 'http://localhost:5112',
  192. payc: 'http://localhost:5113',
  193. order: 'http://localhost:5114',
  194. plan: 'http://localhost:5115',
  195. plan_info: 'http://localhost:5116',
  196. i: 'http://localhost:5117',
  197. easybuv: 'http://localhost:5118'
  198. };
  199. url = `${portMap[targetSite]}${path}`;
  200. }
  201. window.open(url, '_blank');
  202. }