| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- // src/utils/site.ts
- // 开发环境:端口 → 站点
- const DEV_PORT_MAP: Record<string, any> = {
- '5101': 'www',
- '5102': 'b',
- '5103': 'mro',
- '5104': 'fuli',
- '5105': 'reg',
- '5106': 'breg',
- '5107': 'greg',
- '5108': 'passport',
- '5109': 'search',
- '5110': 'item',
- '5111': 'cart',
- '5112': 'trad',
- '5113': 'payc',
- '5114': 'order',
- '5115': 'plan',
- '5116': 'plan_info',
- '5117': 'i',
- '5118': 'easybuv'
- };
- // 每个站点允许的路由
- export const SITE_ROUTES: Record<any, string[]> = {
- www: ['/', '/index'], //优易365主站
- b: ['/indexB'], //企业购商城
- mro: ['/indexMro'], //工业品商城
- fuli: ['/indexFuli'], //福礼商城
- reg: ['/reg'], //个人注册
- breg: ['/breg'], //企业注册
- greg: ['/greg'], //供应商注册
- passport: ['/login'], //登录页
- search: ['/search'], //搜索
- item: ['/item'], //商品详情,
- cart: ['/cart'], //商品详情
- trad: ['/trad'], //确认订单信息
- payc: ['/payc'], //支付订单
- order: ['/order/orderManage', '/order/orderManage/detail', '/order/orderAudit', '/order/afterSale', '/order/batchOrder', '/order/orderEvaluation'], //订单列表
- plan: ['/plan'], //解决方案
- plan_info: ['/plan_info'], //信息展示
- i: ['/i'], //个人信息
- easybuv: ['/easybuv'] //地址管理
- };
- // 获取当前站点(开发用端口,线上用域名)
- export function getCurrentSite(): any {
- if (import.meta.env.PROD) {
- // 线上:根据域名判断
- const host = window.location.hostname;
- if (host === 'b.yoe365.com') return 'b';
- if (host === 'mro.yoe365.com') return 'mro';
- if (host === 'mro.yoe365.com') return 'fuli';
- if (host === 'mro.yoe365.com') return 'reg';
- if (host === 'mro.yoe365.com') return 'breg';
- if (host === 'mro.yoe365.com') return 'greg';
- if (host === 'mro.yoe365.com') return 'passport';
- if (host === 'mro.yoe365.com') return 'search';
- if (host === 'mro.yoe365.com') return 'item';
- if (host === 'mro.yoe365.com') return 'cart';
- if (host === 'mro.yoe365.com') return 'trad';
- if (host === 'mro.yoe365.com') return 'payc';
- if (host === 'mro.yoe365.com') return 'order';
- if (host === 'mro.yoe365.com') return 'plan';
- if (host === 'mro.yoe365.com') return 'plan_info';
- if (host === 'mro.yoe365.com') return 'i';
- if (host === 'mro.yoe365.com') return 'easybuv';
- return 'www';
- }
- // 本地:根据端口判断
- const port = window.location.port || '80';
- return DEV_PORT_MAP[port] || 'www';
- }
- // 根据站点返回 API 基地址
- export function getApiBase() {
- const site = getCurrentSite();
- const map: Record<any, string> = {
- www: 'https://www.yoe365.com',
- b: 'https://b.yoe365.com',
- mro: 'https://mro.yoe365.com',
- fuli: 'https://fuli.yoe365.com',
- reg: 'https://reg.yoe365.com',
- breg: 'https://breg.yoe365.com',
- greg: 'https://greg.yoe365.com',
- passport: 'https://passport.yoe365.com',
- search: 'https://search.yoe365.com',
- item: 'https://item.yoe365.com',
- cart: 'https://cart.yoe365.com',
- trad: 'https://trad.yoe365.com',
- payc: 'https://payc.yoe365.com',
- order: 'https://order.yoe365.com',
- plan: 'https://plan.yoe365.com',
- plan_info: 'https://plan_info.yoe365.com',
- i: 'https://i.yoe365.com',
- easybuv: 'https://easybuv.yoe365.com'
- };
- if (import.meta.env.PROD) {
- return map[site];
- } else {
- // return '/dev-api'
- // return 'http://192.168.1.52:8080';
- return 'https://ceshi.xiaoluwebsite.xyz';
- }
- }
- const PATH_TO_SITE_MAP: Record<string, any> = {};
- for (const [site, paths] of Object.entries(SITE_ROUTES)) {
- for (const path of paths) {
- PATH_TO_SITE_MAP[path] = site as any;
- }
- }
- export function getSiteByPath(path: string): any | null {
- // 支持带查询参数(如 /login?redirect=xxx)
- const cleanPath = path.split('?')[0];
- return PATH_TO_SITE_MAP[cleanPath] || null;
- }
- export function onPath(path: string) {
- const targetSite = getSiteByPath(path);
- if (!targetSite) {
- // window.open(url, '_blank');
- console.error(`[跨站跳转失败] 路径 "${path}" 未关联任何站点`);
- return;
- }
- let url = '';
- if (import.meta.env.PROD) {
- const domainMap: Record<any, string> = {
- www: 'https://www.yoe365.com',
- b: 'https://b.yoe365.com',
- mro: 'https://mro.yoe365.com',
- fuli: 'https://fuli.yoe365.com',
- reg: 'https://reg.yoe365.com',
- breg: 'https://breg.yoe365.com',
- greg: 'https://greg.yoe365.com',
- passport: 'https://passport.yoe365.com',
- search: 'https://search.yoe365.com',
- item: 'https://item.yoe365.com',
- cart: 'https://cart.yoe365.com',
- trad: 'https://trad.yoe365.com',
- payc: 'https://payc.yoe365.com',
- order: 'https://order.yoe365.com',
- plan: 'https://plan.yoe365.com',
- plan_info: 'https://plan_info.yoe365.com',
- i: 'https://i.yoe365.com',
- easybuv: 'https://easybuv.yoe365.com'
- };
- url = `${domainMap[targetSite]}${path}`;
- } else {
- const portMap: Record<any, string> = {
- www: 'http://localhost:5101',
- b: 'http://localhost:5102',
- mro: 'http://localhost:5103',
- fuli: 'http://localhost:5104',
- reg: 'http://localhost:5105',
- breg: 'http://localhost:5106',
- greg: 'http://localhost:5107',
- passport: 'http://localhost:5108',
- search: 'http://localhost:5109',
- item: 'http://localhost:5110',
- cart: 'http://localhost:5111',
- trad: 'http://localhost:5112',
- payc: 'http://localhost:5113',
- order: 'http://localhost:5114',
- plan: 'http://localhost:5115',
- plan_info: 'http://localhost:5116',
- i: 'http://localhost:5117',
- easybuv: 'http://localhost:5118'
- };
- url = `${portMap[targetSite]}${path}`;
- }
- window.open(url, '_blank');
- }
|