From 946378ec41abbbb551fc1587c8b6ee006bfd62c8 Mon Sep 17 00:00:00 2001 From: DCloud_LXH <283700113@qq.com> Date: Tue, 10 May 2022 12:23:56 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20shared=20IEVersion=E3=80=81getDeviceBr?= =?UTF-8?q?and?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../h5/service/api/device/get-system-info.js | 29 ++++++++++++++++++- .../mp-weixin/helpers/enhance-system-info.js | 7 +++-- .../quickapp-webview/runtime/api/protocols.js | 2 +- src/shared/util.js | 28 ------------------ 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/src/platforms/h5/service/api/device/get-system-info.js b/src/platforms/h5/service/api/device/get-system-info.js index 78c6a21b8..332538d3a 100644 --- a/src/platforms/h5/service/api/device/get-system-info.js +++ b/src/platforms/h5/service/api/device/get-system-info.js @@ -1,7 +1,34 @@ import getWindowOffset from 'uni-platform/helpers/get-window-offset' import deviceId from 'uni-platform/helpers/uuid' import safeAreaInsets from 'safe-area-insets' -import { IEVersion, getDeviceBrand } from 'uni-shared' + +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) { + if (/iphone/gi.test(model) || /ipad/gi.test(model) || /mac/gi.test(model)) { return 'apple' } + if (/windows/gi.test(model)) { return 'microsoft' } +} const ua = navigator.userAgent /** diff --git a/src/platforms/mp-weixin/helpers/enhance-system-info.js b/src/platforms/mp-weixin/helpers/enhance-system-info.js index 05317a3f2..1faaa9b33 100644 --- a/src/platforms/mp-weixin/helpers/enhance-system-info.js +++ b/src/platforms/mp-weixin/helpers/enhance-system-info.js @@ -1,4 +1,7 @@ -import { getDeviceBrand } from 'uni-shared' +function getDeviceBrand (model) { + 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 @@ -28,7 +31,7 @@ export function addSafeAreaInsets (result) { export function populateParameters (result) { const { brand, model, system, language, theme, version, hostName = '', platform } = result - const isQuickApp = __PLATFORM__.indexOf('quickapp-webview') !== -1 + const isQuickApp = __PLATFORM__.indexOf('quickapp-webview') !== -1 // osName osVersion let osName = '' diff --git a/src/platforms/quickapp-webview/runtime/api/protocols.js b/src/platforms/quickapp-webview/runtime/api/protocols.js index c4fcebe84..a8c537751 100644 --- a/src/platforms/quickapp-webview/runtime/api/protocols.js +++ b/src/platforms/quickapp-webview/runtime/api/protocols.js @@ -8,7 +8,7 @@ export const protocols = { redirectTo, previewImage, getSystemInfo, - getSystemInfoSync: getSystemInfo, + getSystemInfoSync: getSystemInfo } export const todos = [ 'preloadPage', diff --git a/src/shared/util.js b/src/shared/util.js index 5ce89a600..e62e68952 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -195,31 +195,3 @@ export function deepClone (vnodes, createElement) { } export * from './uni-id-mixin' - -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) { - if (/iphone/gi.test(model) || /ipad/gi.test(model) || /mac/gi.test(model)) { return 'apple' } - if (/windows/gi.test(model)) { return 'microsoft' } -} -- GitLab