From b87d746cca12695a0dc58b7f07be1095b4cdda65 Mon Sep 17 00:00:00 2001 From: DCloud_LXH <283700113@qq.com> Date: Tue, 13 Apr 2021 18:51:22 +0800 Subject: [PATCH] fix(h5): getSystemInfo(system platform) --- .../src/service/api/base/getBaseSystemInfo.ts | 6 ++ .../service/api/device/getSystemInfoSync.ts | 62 +++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/packages/uni-h5/src/service/api/base/getBaseSystemInfo.ts b/packages/uni-h5/src/service/api/base/getBaseSystemInfo.ts index 2bc7ee4bb..d53d597a8 100644 --- a/packages/uni-h5/src/service/api/base/getBaseSystemInfo.ts +++ b/packages/uni-h5/src/service/api/base/getBaseSystemInfo.ts @@ -4,6 +4,12 @@ export const isAndroid = /android/i.test(ua) export const isIOS = /iphone|ipad|ipod/i.test(ua) +export const isWindows = ua.match(/Windows NT ([\d|\d.\d]*)/i) + +export const isMac = /Macintosh|Mac/i.test(ua) + +export const isLinux = /Linux|X11/i.test(ua) + export function getScreenFix() { return ( /^Apple/.test(navigator.vendor) && typeof window.orientation === 'number' diff --git a/packages/uni-h5/src/service/api/device/getSystemInfoSync.ts b/packages/uni-h5/src/service/api/device/getSystemInfoSync.ts index fb26d556d..116ccc3ba 100644 --- a/packages/uni-h5/src/service/api/device/getSystemInfoSync.ts +++ b/packages/uni-h5/src/service/api/device/getSystemInfoSync.ts @@ -8,6 +8,9 @@ import { ua, isIOS, isAndroid, + isWindows, + isMac, + isLinux, isLandscape, getScreenFix, getScreenWidth, @@ -85,6 +88,65 @@ export const getSystemInfoSync = defineSyncApi( break } } + } else if (isWindows || isMac || isLinux) { + model = 'PC' + osname = 'PC' + osversion = '0' + + let osversionFind = ua.match(/\((.+?)\)/)![1] + + if (isWindows) { + osname = 'Windows' + switch (isWindows[1]) { + case '5.1': + osversion = 'XP' + break + case '6.0': + osversion = 'Vista' + break + case '6.1': + osversion = '7' + break + case '6.2': + osversion = '8' + break + case '6.3': + osversion = '8.1' + break + case '10.0': + osversion = '10' + break + } + + const framework = + osversionFind && osversionFind.match(/[Win|WOW]([\d]+)/) + if (framework) { + osversion += ` x${framework[1]}` + } + } else if (isMac) { + osname = 'Mac' + osversion = + (osversionFind && osversionFind.match(/Mac OS X (.+)/)) || '' + + if (osversion) { + osversion = osversion[1].replace(/_/g, '.') + // '10_15_7' or '10.16; rv:86.0' + if (osversion.indexOf(';') !== -1) { + osversion = osversion.split(';')[0] + } + } + } else if (isLinux) { + osname = 'Linux' + osversion = (osversionFind && osversionFind.match(/Linux (.*)/)) || '' + + if (osversion) { + osversion = osversion[1] + // 'x86_64' or 'x86_64; rv:79.0' + if (osversion.indexOf(';') !== -1) { + osversion = osversion.split(';')[0] + } + } + } } else { osname = 'Other' osversion = '0' -- GitLab