|
@@ -1,28 +1,4 @@
|
|
|
-// 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[]> = {
|
|
export const SITE_ROUTES: Record<any, string[]> = {
|
|
|
www: ['/', '/index'], //优易365主站
|
|
www: ['/', '/index'], //优易365主站
|
|
|
b: ['/indexB'], //企业购商城
|
|
b: ['/indexB'], //企业购商城
|
|
@@ -75,148 +51,120 @@ export const SITE_ROUTES: Record<any, string[]> = {
|
|
|
'/organization/approvalFlow/create',
|
|
'/organization/approvalFlow/create',
|
|
|
'/order/orderManage/detail/:orderNo',
|
|
'/order/orderManage/detail/:orderNo',
|
|
|
'/order/orderManage/applyAfter',
|
|
'/order/orderManage/applyAfter',
|
|
|
- '/valueAdded/maintenanceApply',
|
|
|
|
|
- '/enterprise/messageNotice',
|
|
|
|
|
- '/enterprise/securitySetting',
|
|
|
|
|
- '/enterprise/securitySetting/resetPassword',
|
|
|
|
|
- '/enterprise/securitySetting/changePhone'
|
|
|
|
|
|
|
+ '/valueAdded/maintenanceApply'
|
|
|
], //订单列表
|
|
], //订单列表
|
|
|
|
|
|
|
|
i: ['/i'], //个人信息
|
|
i: ['/i'], //个人信息
|
|
|
easybuv: ['/easybuv'] //地址管理
|
|
easybuv: ['/easybuv'] //地址管理
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-// 获取当前站点(开发用端口,线上用域名)
|
|
|
|
|
|
|
+// 获取当前站点
|
|
|
export function getCurrentSite(): any {
|
|
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 host = window.location.hostname;
|
|
|
|
|
|
|
|
- // 本地:根据端口判断
|
|
|
|
|
- const port = window.location.port || '80';
|
|
|
|
|
- return DEV_PORT_MAP[port] || 'www';
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ // 定义本地开发环境的域名映射关系
|
|
|
|
|
+ // 确保你的 hosts 文件已经配置了这些域名指向 127.0.0.1
|
|
|
|
|
+ if (host === 'www.yingpai365.com' || host === 'localhost') return 'www'; // 兼容未配hosts的情况
|
|
|
|
|
+ if (host === 'b.yingpai365.com') return 'b';
|
|
|
|
|
+ if (host === 'mro.yingpai365.com') return 'mro';
|
|
|
|
|
+ if (host === 'fuli.yingpai365.com') return 'fuli';
|
|
|
|
|
+ if (host === 'reg.yingpai365.com') return 'reg';
|
|
|
|
|
+ if (host === 'breg.yingpai365.com') return 'breg';
|
|
|
|
|
+ if (host === 'greg.yingpai365.com') return 'greg';
|
|
|
|
|
+ if (host === 'passport.yingpai365.com') return 'passport';
|
|
|
|
|
+ if (host === 'search.yingpai365.com') return 'search';
|
|
|
|
|
+ if (host === 'item.yingpai365.com') return 'item';
|
|
|
|
|
+ if (host === 'cart.yingpai365.com') return 'cart';
|
|
|
|
|
+ if (host === 'trad.yingpai365.com') return 'trad';
|
|
|
|
|
+ if (host === 'payc.yingpai365.com') return 'payc';
|
|
|
|
|
+ if (host === 'order.yingpai365.com') return 'order';
|
|
|
|
|
+ if (host === 'plan.yingpai365.com') return 'plan';
|
|
|
|
|
+ if (host === 'plan_info.yingpai365.com') return 'plan_info';
|
|
|
|
|
+ if (host === 'i.yingpai365.com') return 'i';
|
|
|
|
|
+ if (host === 'easybuv.yingpai365.com') return 'easybuv';
|
|
|
|
|
|
|
|
-// 根据站点返回 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) {
|
|
if (import.meta.env.PROD) {
|
|
|
- return map[site];
|
|
|
|
|
- } else {
|
|
|
|
|
- // return '/dev-api'
|
|
|
|
|
- // return 'http://192.168.1.52:8080';
|
|
|
|
|
- // return 'https://ceshi.xiaoluwebsite.xyz';
|
|
|
|
|
- return 'http://localhost:8080';
|
|
|
|
|
|
|
+ // 如果上面没匹配到,且是生产环境,可以尝试原有的逻辑或默认返回 www
|
|
|
|
|
+ // 这里建议直接复用上面的 hostname 判断,因为生产环境也是域名
|
|
|
|
|
+ return 'www';
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ return 'www'; // 默认 fallback
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// ... PATH_TO_SITE_MAP 和 getSiteByPath 保持不变 ...
|
|
|
const PATH_TO_SITE_MAP: Record<string, any> = {};
|
|
const PATH_TO_SITE_MAP: Record<string, any> = {};
|
|
|
for (const [site, paths] of Object.entries(SITE_ROUTES)) {
|
|
for (const [site, paths] of Object.entries(SITE_ROUTES)) {
|
|
|
for (const path of paths) {
|
|
for (const path of paths) {
|
|
|
PATH_TO_SITE_MAP[path] = site as any;
|
|
PATH_TO_SITE_MAP[path] = site as any;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
export function getSiteByPath(path: string): any | null {
|
|
export function getSiteByPath(path: string): any | null {
|
|
|
- // 支持带查询参数(如 /login?redirect=xxx)
|
|
|
|
|
const cleanPath = path.split('?')[0];
|
|
const cleanPath = path.split('?')[0];
|
|
|
return PATH_TO_SITE_MAP[cleanPath] || null;
|
|
return PATH_TO_SITE_MAP[cleanPath] || null;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+// 跨站跳转逻辑
|
|
|
|
|
+import router from '@/router';
|
|
|
export function onPath(path: string) {
|
|
export function onPath(path: string) {
|
|
|
- const targetSite = getSiteByPath(path);
|
|
|
|
|
- if (!targetSite) {
|
|
|
|
|
- // window.open(url, '_blank');
|
|
|
|
|
- console.error(`[跨站跳转失败] 路径 "${path}" 未关联任何站点`);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ console.log('[跨站跳转]', path);
|
|
|
|
|
+ // return
|
|
|
|
|
+ if (import.meta.env.VITE_DOMAIN_NAME == 'true') {
|
|
|
|
|
+ const targetSite = getSiteByPath(path);
|
|
|
|
|
|
|
|
- let url = '';
|
|
|
|
|
|
|
+ if (!targetSite) {
|
|
|
|
|
+ console.error(`[跨站跳转失败] 路径 "${path}" 未关联任何站点`);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- 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'
|
|
|
|
|
|
|
+ const currentSite = getCurrentSite();
|
|
|
|
|
+
|
|
|
|
|
+ // 【新增】判断是否是同域名
|
|
|
|
|
+ const isSameSite = currentSite === targetSite;
|
|
|
|
|
+
|
|
|
|
|
+ let url = '';
|
|
|
|
|
+ // 域名映射表 (保持不变)
|
|
|
|
|
+ const domainMap: Record<string, string> = {
|
|
|
|
|
+ www: 'www.yingpai365.com',
|
|
|
|
|
+ b: 'b.yingpai365.com',
|
|
|
|
|
+ mro: 'mro.yingpai365.com',
|
|
|
|
|
+ fuli: 'fuli.yingpai365.com',
|
|
|
|
|
+ reg: 'reg.yingpai365.com',
|
|
|
|
|
+ breg: 'breg.yingpai365.com',
|
|
|
|
|
+ greg: 'greg.yingpai365.com',
|
|
|
|
|
+ passport: 'passport.yingpai365.com',
|
|
|
|
|
+ search: 'search.yingpai365.com',
|
|
|
|
|
+ item: 'item.yingpai365.com',
|
|
|
|
|
+ cart: 'cart.yingpai365.com',
|
|
|
|
|
+ trad: 'trad.yingpai365.com',
|
|
|
|
|
+ payc: 'payc.yingpai365.com',
|
|
|
|
|
+ order: 'order.yingpai365.com',
|
|
|
|
|
+ plan: 'plan.yingpai365.com',
|
|
|
|
|
+ plan_info: 'plan_info.yingpai365.com',
|
|
|
|
|
+ i: 'i.yingpai365.com',
|
|
|
|
|
+ easybuv: 'easybuv.yingpai365.com'
|
|
|
};
|
|
};
|
|
|
- url = `${domainMap[targetSite]}${path}`;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ const baseDomain = domainMap[targetSite];
|
|
|
|
|
+
|
|
|
|
|
+ if (import.meta.env.PROD) {
|
|
|
|
|
+ url = `https://${baseDomain}${path}`;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const devPort = window.location.port || import.meta.env.VITE_APP_PORT;
|
|
|
|
|
+ url = `http://${baseDomain}:${devPort}${path}`;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 【修改】根据是否同域名决定跳转方式
|
|
|
|
|
+ if (isSameSite) {
|
|
|
|
|
+ // 同域名且传入了 router,使用 Vue Router 内部跳转
|
|
|
|
|
+ router.push(path);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 跨域名 或 未传入 router,使用 window.open 打开新窗口
|
|
|
|
|
+ window.open(url, '_blank');
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} 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}`;
|
|
|
|
|
|
|
+ router.push(path);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- window.open(url, '_blank');
|
|
|
|
|
}
|
|
}
|