Appearance
isThsPcYhClient
描述
判断当前环境是否为同花顺PC远航版客户端。通过检测 window.HevoCef.IsHevoCef 方法来判断是否为同花顺PC远航版客户端,并会排除期货通PC客户端。
语法
ts
isThsPcYhClient(): boolean返回值
boolean: 如果是同花顺PC远航版客户端返回true,否则返回false
异常
- 无异常抛出,在检测失败时会返回
false并输出警告信息
示例
基本用法
ts
import { isThsPcYhClient } from '@fu/matrix';
if (isThsPcYhClient()) {
// 在同花顺PC远航版客户端中的处理逻辑
console.log('当前在同花顺PC远航版客户端中');
// 可以使用远航版特有的功能
} else {
// 在其他环境中的处理逻辑
console.log('当前不在同花顺PC远航版客户端中');
}客户端类型判断
ts
import { isThsPcYhClient, isFuturesPcClient } from '@fu/matrix';
const getClientType = () => {
if (isThsPcYhClient()) {
return '同花顺PC远航版';
}
if (isFuturesPcClient()) {
return '期货通PC客户端';
}
return '其他环境';
};
console.log(`当前客户端类型: ${getClientType()}`);功能适配
ts
import { isThsPcYhClient } from '@fu/matrix';
// 根据客户端类型启用不同功能
const initializeApp = () => {
if (isThsPcYhClient()) {
// 远航版特有的初始化逻辑
enableAdvancedFeatures();
setupCustomUI();
configureHevoCefAPI();
} else {
// 通用初始化逻辑
enableBasicFeatures();
setupStandardUI();
}
};错误处理
ts
import { isThsPcYhClient } from '@fu/matrix';
const safeClientOperation = () => {
try {
if (isThsPcYhClient()) {
// 执行远航版特有操作
return performHevoCefOperation();
}
return performFallbackOperation();
} catch (error) {
console.warn('客户端操作失败:', error);
return null;
}
};实现原理
该函数通过以下步骤进行检测:
- 检查
window.HevoCef对象是否存在 - 检查
HevoCef对象是否包含IsHevoCef方法 - 排除期货通PC客户端(通过检查
window.external.IsQhtWin)
兼容性
- 浏览器支持: 所有现代浏览器
- Node.js 支持: 在服务端环境中返回
false - 移动端: 移动端环境返回
false
注意事项
- 该函数会排除期货通PC客户端,因为期货通环境中也可能存在
HevoCef对象 - 如果
window.HevoCef对象不存在或IsHevoCef方法不可用,函数会返回false - 该检测方法仅适用于同花顺PC远航版客户端
- 在服务端渲染时会返回
false
相关方法
- isThsPcTyClient - 检测同花顺PC统一客户端
- isFuturesPcClient - 检测期货通PC客户端
- isInThsApp - 检测同花顺移动端客户端
版本历史
- v1.0.0: 初始版本