UNPKG

@morjs/runtime-web

Version:
95 lines 3.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const mobile_detect_1 = tslib_1.__importDefault(require("mobile-detect")); const my_1 = require("../my"); // 基于 mobile-detect 扩张,支持鸿蒙 class MobileDetect extends mobile_detect_1.default { os() { if (typeof this.ua === 'string') { if (this.ua.toLocaleLowerCase().indexOf('openharmony') > -1 || this.ua.toLocaleLowerCase().indexOf('hmos') > -1) { return 'OpenHarmony'; } } return super.os(); } } const md = new MobileDetect(navigator.userAgent); function contains(arr, needle) { for (const i in arr) { if (arr[i].indexOf(needle) > 0) return i; } return -1; } function systemInfo() { const info = { model: md.mobile(), pixelRatio: window.devicePixelRatio, windowWidth: document.body.clientWidth, windowHeight: document.body.clientHeight, language: (navigator.language || navigator.browserLanguage).toLowerCase(), version: my_1.my.SDKVersion, platform: 'ios', system: md.os(), titleBarHeight: 44, statusBarHeight: 0, screenWidth: screen.width, screenHeight: screen.height, brand: md.mobile(), fontSizeSetting: parseFloat(document.documentElement.style.fontSize), app: 'h5' }; const os = md.os(); let model = ''; let version = ''; if (os === 'iOS') { info.platform = 'iOS'; model = md.mobile() + ' ' + md.version('iPhone'); version = md.versionStr('iPhone'); } else if (os === 'AndroidOS') { info.platform = 'Android'; model = md.mobile() + ' ' + (md.version('iPhone') || md.version('iPad')); version = md.versionStr('iPhone') || md.versionStr('iPad'); const sss = md.userAgent() && md.userAgent().split(';'); //判断 UA 里边有没有 Build 信息,通过这个拿到安卓的具体机型 const i = contains(sss, 'Build/'); if (i > -1) { model = sss[i].substring(0, sss[i].indexOf('Build/')); } } else if (os === 'OpenHarmony') { info.platform = 'OpenHarmony'; info.brand = 'HUAWEI'; model = md.mobile(); if (md.ua.indexOf('Display/') > -1) { const matches = md.ua.match(/Display\/([^\s]+)/); model = matches && matches[1].split('_')[0]; } } else { info.platform = 'unkown'; } try { version = version.replace(/_/g, '.'); } catch (e) { } version ? (info.system = version) : null; info.model = model; return info; } exports.default = { // NOTE: 这里暂时以最新版本的支付宝小程序基础库为准 SDKVersion: '2.8.9', getSystemInfo() { return new Promise((resolve) => { resolve(systemInfo()); }); }, getSystemInfoSync() { return systemInfo(); } }; //# sourceMappingURL=systeminfo.js.map