From 13c8eddb5b795984c10d45413e3fe66efe4ac7f4 Mon Sep 17 00:00:00 2001 From: DCloud_LXH <283700113@qq.com> Date: Tue, 10 May 2022 12:20:14 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20uni-shared=20IEVersion=E3=80=81getDevi?= =?UTF-8?q?ceBrand?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/api/device/getSystemInfoSync.ts | 35 ++++++++++++++++++- .../src/api/protocols/enhanceSystemInfo.ts | 10 +++++- packages/uni-shared/src/utils.ts | 34 ------------------ 3 files changed, 43 insertions(+), 36 deletions(-) diff --git a/packages/uni-h5/src/service/api/device/getSystemInfoSync.ts b/packages/uni-h5/src/service/api/device/getSystemInfoSync.ts index b3f0c3248..b3d9e0348 100644 --- a/packages/uni-h5/src/service/api/device/getSystemInfoSync.ts +++ b/packages/uni-h5/src/service/api/device/getSystemInfoSync.ts @@ -3,7 +3,6 @@ import safeAreaInsets from 'safe-area-insets' import { defineSyncApi } from '@dcloudio/uni-api' import { getWindowOffset } from '@dcloudio/uni-core' -import { IEVersion, getDeviceBrand } from '@dcloudio/uni-shared' import { ua, @@ -22,6 +21,40 @@ import { import deviceId from '../../../helpers/uuid' +function IEVersion() { + const userAgent = navigator.userAgent + const isIE = + userAgent.indexOf('compatible') > -1 && userAgent.indexOf('MSIE') > -1 + const isEdge = userAgent.indexOf('Edge') > -1 && !isIE + const isIE11 = + userAgent.indexOf('Trident') > -1 && userAgent.indexOf('rv:11.0') > -1 + if (isIE) { + const reIE = new RegExp('MSIE (\\d+\\.\\d+);') + reIE.test(userAgent) + const fIEVersion = parseFloat(RegExp.$1) + if (fIEVersion > 6) { + return fIEVersion + } else { + return 6 + } + } else if (isEdge) { + return -1 + } else if (isIE11) { + return 11 + } else { + return -1 + } +} + +function getDeviceBrand(model: string) { + if (/iphone/gi.test(model) || /ipad/gi.test(model) || /mac/gi.test(model)) { + return 'apple' + } + if (/windows/gi.test(model)) { + return 'microsoft' + } +} + /** * 获取系统信息-同步 */ diff --git a/packages/uni-mp-core/src/api/protocols/enhanceSystemInfo.ts b/packages/uni-mp-core/src/api/protocols/enhanceSystemInfo.ts index 9c31da7f9..2d3dc8015 100644 --- a/packages/uni-mp-core/src/api/protocols/enhanceSystemInfo.ts +++ b/packages/uni-mp-core/src/api/protocols/enhanceSystemInfo.ts @@ -1,5 +1,13 @@ import { extend } from '@vue/shared' -import { getDeviceBrand } from '@dcloudio/uni-shared' + +function getDeviceBrand(model: string) { + if (/iphone/gi.test(model) || /ipad/gi.test(model) || /mac/gi.test(model)) { + return 'apple' + } + if (/windows/gi.test(model)) { + return 'microsoft' + } +} const UUID_KEY = '__DC_STAT_UUID' let deviceId: string diff --git a/packages/uni-shared/src/utils.ts b/packages/uni-shared/src/utils.ts index d57a8f981..e0b3b4a55 100644 --- a/packages/uni-shared/src/utils.ts +++ b/packages/uni-shared/src/utils.ts @@ -129,37 +129,3 @@ export function getValueByDataPath(obj: any, path: string): unknown { } return getValueByDataPath(obj[key], parts.slice(1).join('.')) } - -export function IEVersion() { - const userAgent = navigator.userAgent - const isIE = - userAgent.indexOf('compatible') > -1 && userAgent.indexOf('MSIE') > -1 - const isEdge = userAgent.indexOf('Edge') > -1 && !isIE - const isIE11 = - userAgent.indexOf('Trident') > -1 && userAgent.indexOf('rv:11.0') > -1 - if (isIE) { - const reIE = new RegExp('MSIE (\\d+\\.\\d+);') - reIE.test(userAgent) - const fIEVersion = parseFloat(RegExp.$1) - if (fIEVersion > 6) { - return fIEVersion - } else { - return 6 - } - } else if (isEdge) { - return -1 - } else if (isIE11) { - return 11 - } else { - return -1 - } -} - -export function getDeviceBrand(model: string) { - if (/iphone/gi.test(model) || /ipad/gi.test(model) || /mac/gi.test(model)) { - return 'apple' - } - if (/windows/gi.test(model)) { - return 'microsoft' - } -} -- GitLab