// 从 UA 获取设备相关信息并在全局初始化 export const initPlatform = () => { const UA = navigator.userAgent; console.log("UA", UA); const info = UA.match(/\s{1}DSBRIDGE[\w.]+$/g); const adapterMobileTest = /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i; const platformMes = { appVersion: "", systemVersion: "", platform: "h5", device: "browser", adapterMobile: adapterMobileTest.test(UA), }; if (info && info.length > 0) { // 判断是否在Android,IOS 上 const infoArray = info[0].split("_"); platformMes.appVersion = infoArray[1]; platformMes.systemVersion = infoArray[2]; platformMes.platform = infoArray[3]; platformMes.device = "app"; } else { const isWx = UA.toLowerCase().match(/MicroMessenger/i); const isWeibo = UA.toLowerCase().match(/WeiBo/i); const isHapApp = UA.toLowerCase().match(/com\.iask\.healthhap/i); if (isWx) { platformMes.platform = "weixin"; } else if (isWeibo) { platformMes.platform = "weibo"; } else if (isHapApp) { platformMes.platform = "hapApp"; } else { platformMes.platform = "h5"; } platformMes.device = "browser"; platformMes.appVersion = "1.0.0"; platformMes.systemVersion = ""; } console.log(platformMes, "platformMes"); return platformMes; }; // 初始化 eruda 控制台 export function initConsole() { const NO_ERUDA = window.location.protocol === "https:"; if (NO_ERUDA) return; const src = "https://cdn.jsdelivr.net/npm/eruda@1.5.8/eruda.min.js"; document.write(""); document.write("eruda.init();"); } export function setup() { return initPlatform(); }