siteConfig.ts 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. '/order/orderManage/applyAfter',
  74. '/valueAdded/maintenanceApply'
  75. ], //订单列表
  76. i: ['/i'], //个人信息
  77. easybuv: ['/easybuv'] //地址管理
  78. };
  79. // 获取当前站点(开发用端口,线上用域名)
  80. export function getCurrentSite(): any {
  81. if (import.meta.env.PROD) {
  82. // 线上:根据域名判断
  83. const host = window.location.hostname;
  84. if (host === 'b.yoe365.com') return 'b';
  85. if (host === 'mro.yoe365.com') return 'mro';
  86. if (host === 'mro.yoe365.com') return 'fuli';
  87. if (host === 'mro.yoe365.com') return 'reg';
  88. if (host === 'mro.yoe365.com') return 'breg';
  89. if (host === 'mro.yoe365.com') return 'greg';
  90. if (host === 'mro.yoe365.com') return 'passport';
  91. if (host === 'mro.yoe365.com') return 'search';
  92. if (host === 'mro.yoe365.com') return 'item';
  93. if (host === 'mro.yoe365.com') return 'cart';
  94. if (host === 'mro.yoe365.com') return 'trad';
  95. if (host === 'mro.yoe365.com') return 'payc';
  96. if (host === 'mro.yoe365.com') return 'order';
  97. if (host === 'mro.yoe365.com') return 'plan';
  98. if (host === 'mro.yoe365.com') return 'plan_info';
  99. if (host === 'mro.yoe365.com') return 'i';
  100. if (host === 'mro.yoe365.com') return 'easybuv';
  101. return 'www';
  102. }
  103. // 本地:根据端口判断
  104. const port = window.location.port || '80';
  105. return DEV_PORT_MAP[port] || 'www';
  106. }
  107. // 根据站点返回 API 基地址
  108. export function getApiBase() {
  109. const site = getCurrentSite();
  110. const map: Record<any, string> = {
  111. www: 'https://www.yoe365.com',
  112. b: 'https://b.yoe365.com',
  113. mro: 'https://mro.yoe365.com',
  114. fuli: 'https://fuli.yoe365.com',
  115. reg: 'https://reg.yoe365.com',
  116. breg: 'https://breg.yoe365.com',
  117. greg: 'https://greg.yoe365.com',
  118. passport: 'https://passport.yoe365.com',
  119. search: 'https://search.yoe365.com',
  120. item: 'https://item.yoe365.com',
  121. cart: 'https://cart.yoe365.com',
  122. trad: 'https://trad.yoe365.com',
  123. payc: 'https://payc.yoe365.com',
  124. order: 'https://order.yoe365.com',
  125. plan: 'https://plan.yoe365.com',
  126. plan_info: 'https://plan_info.yoe365.com',
  127. i: 'https://i.yoe365.com',
  128. easybuv: 'https://easybuv.yoe365.com'
  129. };
  130. if (import.meta.env.PROD) {
  131. return map[site];
  132. } else {
  133. // return '/dev-api'
  134. // return 'http://192.168.1.52:8080';
  135. // return 'https://ceshi.xiaoluwebsite.xyz';
  136. return 'http://localhost:8080';
  137. }
  138. }
  139. const PATH_TO_SITE_MAP: Record<string, any> = {};
  140. for (const [site, paths] of Object.entries(SITE_ROUTES)) {
  141. for (const path of paths) {
  142. PATH_TO_SITE_MAP[path] = site as any;
  143. }
  144. }
  145. export function getSiteByPath(path: string): any | null {
  146. // 支持带查询参数(如 /login?redirect=xxx)
  147. const cleanPath = path.split('?')[0];
  148. return PATH_TO_SITE_MAP[cleanPath] || null;
  149. }
  150. export function onPath(path: string) {
  151. const targetSite = getSiteByPath(path);
  152. if (!targetSite) {
  153. // window.open(url, '_blank');
  154. console.error(`[跨站跳转失败] 路径 "${path}" 未关联任何站点`);
  155. return;
  156. }
  157. let url = '';
  158. if (import.meta.env.PROD) {
  159. const domainMap: Record<any, string> = {
  160. www: 'https://www.yoe365.com',
  161. b: 'https://b.yoe365.com',
  162. mro: 'https://mro.yoe365.com',
  163. fuli: 'https://fuli.yoe365.com',
  164. reg: 'https://reg.yoe365.com',
  165. breg: 'https://breg.yoe365.com',
  166. greg: 'https://greg.yoe365.com',
  167. passport: 'https://passport.yoe365.com',
  168. search: 'https://search.yoe365.com',
  169. item: 'https://item.yoe365.com',
  170. cart: 'https://cart.yoe365.com',
  171. trad: 'https://trad.yoe365.com',
  172. payc: 'https://payc.yoe365.com',
  173. order: 'https://order.yoe365.com',
  174. plan: 'https://plan.yoe365.com',
  175. plan_info: 'https://plan_info.yoe365.com',
  176. i: 'https://i.yoe365.com',
  177. easybuv: 'https://easybuv.yoe365.com'
  178. };
  179. url = `${domainMap[targetSite]}${path}`;
  180. } else {
  181. const portMap: Record<any, string> = {
  182. www: 'http://localhost:5101',
  183. b: 'http://localhost:5102',
  184. mro: 'http://localhost:5103',
  185. fuli: 'http://localhost:5104',
  186. reg: 'http://localhost:5105',
  187. breg: 'http://localhost:5106',
  188. greg: 'http://localhost:5107',
  189. passport: 'http://localhost:5108',
  190. search: 'http://localhost:5109',
  191. item: 'http://localhost:5110',
  192. cart: 'http://localhost:5111',
  193. trad: 'http://localhost:5112',
  194. payc: 'http://localhost:5113',
  195. order: 'http://localhost:5114',
  196. plan: 'http://localhost:5115',
  197. plan_info: 'http://localhost:5116',
  198. i: 'http://localhost:5117',
  199. easybuv: 'http://localhost:5118'
  200. };
  201. url = `${portMap[targetSite]}${path}`;
  202. }
  203. window.open(url, '_blank');
  204. }