Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小浣熊撸代码
uni-app
提交
97d48006
U
uni-app
项目概览
小浣熊撸代码
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
97d48006
编写于
5月 24, 2022
作者:
D
DCloud_LXH
提交者:
qiang
5月 27, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: getWindowInfo、getDeviceInfo、getAppBaseInfo
上级
5f623e11
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
594 addition
and
363 deletion
+594
-363
lib/apis.js
lib/apis.js
+3
-0
src/core/helpers/promise.js
src/core/helpers/promise.js
+1
-1
src/platforms/app-plus/service/api/device/get-window-info.js
src/platforms/app-plus/service/api/device/get-window-info.js
+89
-0
src/platforms/app-plus/service/api/device/system.js
src/platforms/app-plus/service/api/device/system.js
+96
-96
src/platforms/app-plus/service/api/index.js
src/platforms/app-plus/service/api/index.js
+1
-0
src/platforms/h5/service/api/base/get-browser-info.js
src/platforms/h5/service/api/base/get-browser-info.js
+220
-0
src/platforms/h5/service/api/device/get-system-info.js
src/platforms/h5/service/api/device/get-system-info.js
+89
-255
src/platforms/h5/service/api/device/get-window-info.js
src/platforms/h5/service/api/device/get-window-info.js
+51
-0
src/platforms/mp-weixin/helpers/enhance-system-info.js
src/platforms/mp-weixin/helpers/enhance-system-info.js
+44
-11
未找到文件。
lib/apis.js
浏览文件 @
97d48006
...
...
@@ -74,6 +74,9 @@ const media = [
const
device
=
[
'
getSystemInfo
'
,
'
getSystemInfoSync
'
,
'
getWindowInfo
'
,
'
getDeviceInfo
'
,
'
getAppBaseInfo
'
,
'
canIUse
'
,
'
onMemoryWarning
'
,
'
getNetworkType
'
,
...
...
src/core/helpers/promise.js
浏览文件 @
97d48006
...
...
@@ -8,7 +8,7 @@ import {
}
from
'
./interceptor
'
const
SYNC_API_RE
=
/^
\$
|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|requireGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale|invokePushCallback/
/^
\$
|Window$|WindowStyle$|sendHostEvent|sendNativeEvent|restoreGlobal|requireGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64|getLocale|setLocale|invokePushCallback
|getWindowInfo|getDeviceInfo|getAppBaseInfo
/
const
CONTEXT_API_RE
=
/^create|Manager$/
...
...
src/platforms/app-plus/service/api/device/get-window-info.js
0 → 100644
浏览文件 @
97d48006
import
{
NAVBAR_HEIGHT
}
from
'
uni-helpers/constants
'
import
tabBar
from
'
../../framework/tab-bar
'
import
{
getStatusbarHeight
}
from
'
uni-platform/helpers/status-bar
'
import
{
isTabBarPage
,
getLastWebview
,
getScreenInfo
}
from
'
../util
'
export
function
getWindowInfo
()
{
const
ios
=
plus
.
os
.
name
.
toLowerCase
()
===
'
ios
'
const
{
screenWidth
,
screenHeight
}
=
getScreenInfo
()
const
statusBarHeight
=
getStatusbarHeight
()
let
safeAreaInsets
const
titleNView
=
{
height
:
0
,
cover
:
false
}
const
webview
=
getLastWebview
()
if
(
webview
)
{
let
style
=
webview
.
getStyle
()
style
=
style
&&
style
.
titleNView
if
(
style
&&
style
.
type
&&
style
.
type
!==
'
none
'
)
{
titleNView
.
height
=
style
.
type
===
'
transparent
'
?
0
:
(
statusBarHeight
+
NAVBAR_HEIGHT
)
titleNView
.
cover
=
style
.
type
===
'
transparent
'
||
style
.
type
===
'
float
'
}
safeAreaInsets
=
webview
.
getSafeAreaInsets
()
}
else
{
safeAreaInsets
=
plus
.
navigator
.
getSafeAreaInsets
()
}
const
tabBarView
=
{
height
:
0
,
cover
:
false
}
if
(
isTabBarPage
())
{
tabBarView
.
height
=
tabBar
.
visible
?
tabBar
.
height
:
0
tabBarView
.
cover
=
tabBar
.
cover
}
const
windowTop
=
titleNView
.
cover
?
titleNView
.
height
:
0
const
windowBottom
=
tabBarView
.
cover
?
tabBarView
.
height
:
0
let
windowHeight
=
screenHeight
-
titleNView
.
height
-
tabBarView
.
height
let
windowHeightReal
=
screenHeight
-
(
titleNView
.
cover
?
0
:
titleNView
.
height
)
-
(
tabBarView
.
cover
?
0
:
tabBarView
.
height
)
const
windowWidth
=
screenWidth
if
((
!
tabBarView
.
height
||
tabBarView
.
cover
)
&&
!
safeAreaInsets
.
bottom
&&
safeAreaInsets
.
deviceBottom
)
{
windowHeight
-=
safeAreaInsets
.
deviceBottom
windowHeightReal
-=
safeAreaInsets
.
deviceBottom
}
safeAreaInsets
=
ios
?
safeAreaInsets
:
{
left
:
0
,
right
:
0
,
top
:
titleNView
.
height
&&
!
titleNView
.
cover
?
0
:
statusBarHeight
,
bottom
:
0
}
const
safeArea
=
{
left
:
safeAreaInsets
.
left
,
right
:
windowWidth
-
safeAreaInsets
.
right
,
top
:
safeAreaInsets
.
top
,
bottom
:
windowHeightReal
-
safeAreaInsets
.
bottom
,
width
:
windowWidth
-
safeAreaInsets
.
left
-
safeAreaInsets
.
right
,
height
:
windowHeightReal
-
safeAreaInsets
.
top
-
safeAreaInsets
.
bottom
}
return
{
pixelRatio
:
plus
.
screen
.
scale
,
screenWidth
,
screenHeight
,
windowWidth
,
windowHeight
,
statusBarHeight
,
safeArea
,
safeAreaInsets
:
{
top
:
safeAreaInsets
.
top
,
right
:
safeAreaInsets
.
right
,
bottom
:
safeAreaInsets
.
bottom
,
left
:
safeAreaInsets
.
left
},
windowTop
,
windowBottom
,
screenTop
:
screenHeight
-
windowHeight
}
}
src/platforms/app-plus/service/api/device/system.js
浏览文件 @
97d48006
import
{
callApiSync
,
isTabBarPage
,
getLastWebview
,
getScreenInfo
callApiSync
}
from
'
../util
'
import
{
NAVBAR_HEIGHT
}
from
'
uni-helpers/constants
'
import
{
getWindowInfo
}
from
'
./get-window-info
'
import
tabBar
from
'
../../framework/tab-bar
'
import
deviceId
from
'
uni-platform/helpers/uuid
'
import
{
getStatusbarHeight
}
from
'
uni-platform/helpers/status-bar
'
let
systemInfo
=
{}
let
_initSystemInfo
=
true
import
deviceId
from
'
uni-platform/helpers/uuid
'
function
weexGetSystemInfoSync
()
{
if
(
!
_initSystemInfo
)
return
const
{
getSystemInfoSync
}
=
weex
.
requireModule
(
'
plus
'
)
systemInfo
=
getSystemInfoSync
()
}
export
function
getDeviceInfo
()
{
weexGetSystemInfoSync
()
const
{
deviceBrand
,
deviceModel
,
osName
,
osVersion
}
=
systemInfo
const
brand
=
deviceBrand
.
toLowerCase
()
return
{
deviceBrand
:
brand
,
deviceModel
,
brand
,
model
:
deviceModel
,
system
:
`
${
osName
===
'
ios
'
?
'
iOS
'
:
'
Android
'
}
${
osVersion
}
`
,
platform
:
osName
}
}
export
function
getAppBaseInfo
()
{
weexGetSystemInfoSync
()
const
{
hostPackageName
,
hostName
,
osLanguage
,
hostVersion
,
hostLanguage
,
hostTheme
,
appId
,
appName
,
appVersion
,
appVersionCode
}
=
systemInfo
return
{
SDKVersion
:
''
,
hostSDKVersion
:
''
,
enableDebug
:
false
,
appId
,
appName
,
appVersion
,
appVersionCode
,
appLanguage
:
uni
.
getLocale
(),
version
:
plus
.
runtime
.
innerVersion
,
language
:
osLanguage
,
theme
:
''
,
hostPackageName
,
hostName
,
hostVersion
,
hostLanguage
,
hostTheme
,
hostFontSizeSetting
:
undefined
}
}
export
function
getSystemInfoSync
()
{
return
callApiSync
(
getSystemInfo
,
Object
.
create
(
null
),
'
getSystemInfo
'
,
'
getSystemInfoSync
'
)
}
export
function
getSystemInfo
()
{
const
{
getSystemInfoSync
}
=
weex
.
requireModule
(
'
plus
'
)
const
info
=
getSystemInfoSync
()
const
{
deviceBrand
,
deviceModel
,
osName
,
osVersion
,
osLanguage
}
=
info
const
brand
=
deviceBrand
.
toLowerCase
()
const
_osName
=
osName
.
toLowerCase
()
const
ios
=
_osName
===
'
ios
'
const
{
screenWidth
,
screenHeight
}
=
getScreenInfo
()
const
statusBarHeight
=
getStatusbarHeight
()
let
safeAreaInsets
const
titleNView
=
{
height
:
0
,
cover
:
false
}
const
webview
=
getLastWebview
()
if
(
webview
)
{
let
style
=
webview
.
getStyle
()
style
=
style
&&
style
.
titleNView
if
(
style
&&
style
.
type
&&
style
.
type
!==
'
none
'
)
{
titleNView
.
height
=
style
.
type
===
'
transparent
'
?
0
:
(
statusBarHeight
+
NAVBAR_HEIGHT
)
titleNView
.
cover
=
style
.
type
===
'
transparent
'
||
style
.
type
===
'
float
'
}
safeAreaInsets
=
webview
.
getSafeAreaInsets
()
}
else
{
safeAreaInsets
=
plus
.
navigator
.
getSafeAreaInsets
()
}
const
tabBarView
=
{
height
:
0
,
cover
:
false
}
if
(
isTabBarPage
())
{
tabBarView
.
height
=
tabBar
.
visible
?
tabBar
.
height
:
0
tabBarView
.
cover
=
tabBar
.
cover
}
const
windowTop
=
titleNView
.
cover
?
titleNView
.
height
:
0
const
windowBottom
=
tabBarView
.
cover
?
tabBarView
.
height
:
0
let
windowHeight
=
screenHeight
-
titleNView
.
height
-
tabBarView
.
height
let
windowHeightReal
=
screenHeight
-
(
titleNView
.
cover
?
0
:
titleNView
.
height
)
-
(
tabBarView
.
cover
?
0
:
tabBarView
.
height
)
const
windowWidth
=
screenWidth
if
((
!
tabBarView
.
height
||
tabBarView
.
cover
)
&&
!
safeAreaInsets
.
bottom
&&
safeAreaInsets
.
deviceBottom
)
{
windowHeight
-=
safeAreaInsets
.
deviceBottom
windowHeightReal
-=
safeAreaInsets
.
deviceBottom
}
safeAreaInsets
=
ios
?
safeAreaInsets
:
{
left
:
0
,
right
:
0
,
top
:
titleNView
.
height
&&
!
titleNView
.
cover
?
0
:
statusBarHeight
,
bottom
:
0
_initSystemInfo
=
true
weexGetSystemInfoSync
()
_initSystemInfo
=
false
const
deviceInfo
=
getDeviceInfo
()
const
appBaseInfo
=
getAppBaseInfo
()
_initSystemInfo
=
true
const
{
osName
,
osLanguage
,
osVersion
,
pixelRatio
}
=
systemInfo
const
osLanguageSplit
=
osLanguage
.
split
(
'
-
'
)
const
osLanguageSplitLast
=
osLanguageSplit
[
osLanguageSplit
.
length
-
1
]
let
_osLanguage
=
`
${
osLanguageSplit
[
0
]}${
osLanguageSplitLast
?
'
-
'
+
osLanguageSplitLast
:
''
}
`
let
extraData
=
{
errMsg
:
'
getSystemInfo:ok
'
,
fontSizeSetting
:
appBaseInfo
.
hostFontSizeSetting
,
devicePixelRatio
:
pixelRatio
,
deviceId
:
deviceId
(),
uniCompileVersion
:
__uniConfig
.
compilerVersion
,
uniRuntimeVersion
:
__uniConfig
.
compilerVersion
,
osLanguage
:
_osLanguage
}
const
safeArea
=
{
left
:
safeAreaInsets
.
left
,
right
:
windowWidth
-
safeAreaInsets
.
right
,
top
:
safeAreaInsets
.
top
,
bottom
:
windowHeightReal
-
safeAreaInsets
.
bottom
,
width
:
windowWidth
-
safeAreaInsets
.
left
-
safeAreaInsets
.
right
,
height
:
windowHeightReal
-
safeAreaInsets
.
top
-
safeAreaInsets
.
bottom
if
(
osName
===
'
ios
'
)
{
extraData
.
romName
=
osName
extraData
.
romVersion
=
osVersion
}
return
Object
.
assign
({
errMsg
:
'
getSystemInfo:ok
'
,
brand
:
brand
,
model
:
deviceModel
,
pixelRatio
:
plus
.
screen
.
scale
,
screenWidth
,
screenHeight
,
windowWidth
,
windowHeight
,
statusBarHeight
,
language
:
osLanguage
,
system
:
`
${
osName
}
${
osVersion
}
`
,
version
:
plus
.
runtime
.
innerVersion
,
fontSizeSetting
:
''
,
platform
:
_osName
,
SDKVersion
:
''
,
windowTop
,
windowBottom
,
safeArea
,
safeAreaInsets
:
{
top
:
safeAreaInsets
.
top
,
right
:
safeAreaInsets
.
right
,
bottom
:
safeAreaInsets
.
bottom
,
left
:
safeAreaInsets
.
left
},
deviceId
:
deviceId
()
},
info
,
{
deviceBrand
:
brand
,
osName
:
_osName
})
const
_systemInfo
=
Object
.
assign
(
{},
systemInfo
,
getWindowInfo
(),
deviceInfo
,
appBaseInfo
,
extraData
)
delete
_systemInfo
.
screenTop
delete
_systemInfo
.
enableDebug
delete
_systemInfo
.
theme
return
_systemInfo
}
src/platforms/app-plus/service/api/index.js
浏览文件 @
97d48006
...
...
@@ -18,6 +18,7 @@ export * from './device/scan-code'
export
*
from
'
./device/soter-authentication
'
export
*
from
'
./device/system
'
export
*
from
'
./device/vibrate
'
export
*
from
'
./device/get-window-info
'
export
*
from
'
./file/file
'
export
*
from
'
./file/open-document
'
...
...
src/platforms/h5/service/api/base/get-browser-info.js
0 → 100644
浏览文件 @
97d48006
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
/**
* 是否安卓设备
*/
const
isAndroid
=
/android/i
.
test
(
ua
)
/**
* 是否iOS设备
*/
const
isIOS
=
/iphone|ipad|ipod/i
.
test
(
ua
)
/**
* 是否是Windows设备
*/
const
isWindows
=
ua
.
match
(
/Windows NT
([\d
|
\d
.
\d]
*
)
/i
)
/**
* 是否是Mac设备
*/
const
isMac
=
/Macintosh|Mac/i
.
test
(
ua
)
/**
* 是否是Linux设备
*/
const
isLinux
=
/Linux|X11/i
.
test
(
ua
)
/**
* 是否是iPadOS
*/
const
isIPadOS
=
isMac
&&
navigator
.
maxTouchPoints
>
0
/**
* 获取系统信息-同步
*/
export
function
getBrowserInfo
()
{
var
language
=
navigator
.
language
var
osname
var
osversion
var
model
let
deviceType
=
'
phone
'
if
(
isIOS
)
{
osname
=
'
iOS
'
const
osversionFind
=
ua
.
match
(
/OS
\s([\w
_
]
+
)\s
like/
)
if
(
osversionFind
)
{
osversion
=
osversionFind
[
1
].
replace
(
/_/g
,
'
.
'
)
}
const
modelFind
=
ua
.
match
(
/
\(([
a-zA-Z
]
+
)
;/
)
if
(
modelFind
)
{
model
=
modelFind
[
1
]
}
}
else
if
(
isAndroid
)
{
osname
=
'
Android
'
// eslint-disable-next-line no-useless-escape
const
osversionFind
=
ua
.
match
(
/Android
[\s/]([\w\.]
+
)[
;
\s]
/
)
if
(
osversionFind
)
{
osversion
=
osversionFind
[
1
]
}
const
infoFind
=
ua
.
match
(
/
\((
.+
?)\)
/
)
const
infos
=
infoFind
?
infoFind
[
1
].
split
(
'
;
'
)
:
ua
.
split
(
'
'
)
// eslint-disable-next-line no-useless-escape
const
otherInfo
=
[
/
\b
Android
\b
/i
,
/
\b
Linux
\b
/i
,
/
\b
U
\b
/i
,
/^
\s?[
a-z
][
a-z
]
$/i
,
/^
\s?[
a-z
][
a-z
]
-
[
a-z
][
a-z
]
$/i
,
/
\b
wv
\b
/i
,
/
\/[\d\.
,
]
+$/
,
/^
\s?[\d\.
,
]
+$/
,
/
\b
Browser
\b
/i
,
/
\b
Mobile
\b
/i
]
for
(
let
i
=
0
;
i
<
infos
.
length
;
i
++
)
{
const
info
=
infos
[
i
]
if
(
info
.
indexOf
(
'
Build
'
)
>
0
)
{
model
=
info
.
split
(
'
Build
'
)[
0
].
trim
()
break
}
let
other
for
(
let
o
=
0
;
o
<
otherInfo
.
length
;
o
++
)
{
if
(
otherInfo
[
o
].
test
(
info
))
{
other
=
true
break
}
}
if
(
!
other
)
{
model
=
info
.
trim
()
break
}
}
}
else
if
(
isIPadOS
)
{
model
=
'
iPad
'
osname
=
'
iOS
'
osversion
=
typeof
window
.
BigInt
===
'
function
'
?
'
14.0
'
:
'
13.0
'
deviceType
=
'
pad
'
}
else
if
(
isWindows
||
isMac
||
isLinux
)
{
model
=
'
PC
'
osname
=
'
PC
'
deviceType
=
'
pc
'
const
osversionFind
=
ua
.
match
(
/
\((
.+
?)\)
/
)[
1
]
if
(
isWindows
)
{
osname
=
'
Windows
'
osversion
=
''
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
.
match
(
/
[
Win|WOW
]([\d]
+
)
/
)
if
(
framework
)
{
osversion
+=
` x
${
framework
[
1
]}
`
}
}
else
if
(
isMac
)
{
osname
=
'
macOS
'
osversion
=
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
.
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
'
deviceType
=
'
other
'
}
var
system
=
`
${
osname
}
${
osversion
}
`
var
platform
=
osname
.
toLocaleLowerCase
()
let
browserName
let
browseVersion
=
String
(
IEVersion
())
if
(
browseVersion
!==
'
-1
'
)
{
browserName
=
'
IE
'
}
else
{
const
browseVendors
=
[
'
Version
'
,
'
Firefox
'
,
'
Chrome
'
,
'
Edge{0,1}
'
]
const
vendors
=
[
'
Safari
'
,
'
Firefox
'
,
'
Chrome
'
,
'
Edge
'
]
for
(
let
index
=
0
;
index
<
browseVendors
.
length
;
index
++
)
{
const
vendor
=
browseVendors
[
index
]
const
reg
=
new
RegExp
(
`(
${
vendor
}
)/(\\S*)\\b`
)
if
(
reg
.
test
(
ua
))
{
browserName
=
vendors
[
index
]
browseVersion
=
ua
.
match
(
reg
)[
2
]
}
}
}
// deviceBrand
let
deviceBrand
=
''
if
(
model
)
{
const
_model
=
model
.
toLocaleLowerCase
()
deviceBrand
=
getDeviceBrand
(
_model
)
||
getDeviceBrand
(
osname
.
toLocaleLowerCase
())
||
_model
.
split
(
'
'
)[
0
]
}
// deviceOrientation
let
deviceOrientation
=
'
portrait
'
const
orientation
=
typeof
window
.
screen
.
orientation
===
'
undefined
'
?
window
.
orientation
:
window
.
screen
.
orientation
.
angle
deviceOrientation
=
Math
.
abs
(
orientation
)
===
90
?
'
landscape
'
:
'
portrait
'
return
{
deviceBrand
,
deviceModel
:
model
,
deviceOrientation
,
brand
:
deviceBrand
,
model
,
system
,
platform
,
browserName
:
browserName
.
toLocaleLowerCase
(),
browseVersion
,
language
,
deviceType
,
ua
,
osname
,
osversion
,
theme
:
''
}
}
src/platforms/h5/service/api/device/get-system-info.js
浏览文件 @
97d48006
import
getWindowOffset
from
'
uni-platform/helpers/get-window-offset
'
import
{
getWindowInfo
}
from
'
./get-window-info
'
import
deviceId
from
'
uni-platform/helpers/uuid
'
import
safeAreaInsets
from
'
safe-area-insets
'
import
{
getBrowserInfo
}
from
'
../base/get-browser-info
'
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
}
}
let
browserInfo
=
{}
let
_initBrowserInfo
=
true
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
'
}
function
initBrowserInfo
(
)
{
if
(
!
_initBrowserInfo
)
return
browserInfo
=
getBrowserInfo
()
}
const
ua
=
navigator
.
userAgent
/**
* 是否安卓设备
*/
const
isAndroid
=
/android/i
.
test
(
ua
)
/**
* 是否iOS设备
*/
const
isIOS
=
/iphone|ipad|ipod/i
.
test
(
ua
)
/**
* 是否是Windows设备
*/
const
isWindows
=
ua
.
match
(
/Windows NT
([\d
|
\d
.
\d]
*
)
/i
)
/**
* 是否是Mac设备
*/
const
isMac
=
/Macintosh|Mac/i
.
test
(
ua
)
/**
* 是否是Linux设备
*/
const
isLinux
=
/Linux|X11/i
.
test
(
ua
)
/**
* 是否是iPadOS
*/
const
isIPadOS
=
isMac
&&
navigator
.
maxTouchPoints
>
0
/**
* 获取系统信息-同步
*/
export
function
getSystemInfoSync
()
{
var
screen
=
window
.
screen
var
pixelRatio
=
window
.
devicePixelRatio
// 横屏时 iOS 获取的屏幕宽高颠倒,进行纠正
const
screenFix
=
/^Apple/
.
test
(
navigator
.
vendor
)
&&
typeof
window
.
orientation
===
'
number
'
const
landscape
=
screenFix
&&
Math
.
abs
(
window
.
orientation
)
===
90
var
screenWidth
=
screenFix
?
Math
[
landscape
?
'
max
'
:
'
min
'
](
screen
.
width
,
screen
.
height
)
:
screen
.
width
var
screenHeight
=
screenFix
?
Math
[
landscape
?
'
min
'
:
'
max
'
](
screen
.
height
,
screen
.
width
)
:
screen
.
height
var
windowWidth
=
Math
.
min
(
window
.
innerWidth
,
document
.
documentElement
.
clientWidth
,
screenWidth
)
||
screenWidth
var
windowHeight
=
window
.
innerHeight
var
language
=
navigator
.
language
var
statusBarHeight
=
safeAreaInsets
.
top
var
osname
var
osversion
var
model
let
deviceType
=
'
phone
'
if
(
isIOS
)
{
osname
=
'
iOS
'
const
osversionFind
=
ua
.
match
(
/OS
\s([\w
_
]
+
)\s
like/
)
if
(
osversionFind
)
{
osversion
=
osversionFind
[
1
].
replace
(
/_/g
,
'
.
'
)
}
const
modelFind
=
ua
.
match
(
/
\(([
a-zA-Z
]
+
)
;/
)
if
(
modelFind
)
{
model
=
modelFind
[
1
]
}
}
else
if
(
isAndroid
)
{
osname
=
'
Android
'
// eslint-disable-next-line no-useless-escape
const
osversionFind
=
ua
.
match
(
/Android
[\s/]([\w\.]
+
)[
;
\s]
/
)
if
(
osversionFind
)
{
osversion
=
osversionFind
[
1
]
}
const
infoFind
=
ua
.
match
(
/
\((
.+
?)\)
/
)
const
infos
=
infoFind
?
infoFind
[
1
].
split
(
'
;
'
)
:
ua
.
split
(
'
'
)
// eslint-disable-next-line no-useless-escape
const
otherInfo
=
[
/
\b
Android
\b
/i
,
/
\b
Linux
\b
/i
,
/
\b
U
\b
/i
,
/^
\s?[
a-z
][
a-z
]
$/i
,
/^
\s?[
a-z
][
a-z
]
-
[
a-z
][
a-z
]
$/i
,
/
\b
wv
\b
/i
,
/
\/[\d\.
,
]
+$/
,
/^
\s?[\d\.
,
]
+$/
,
/
\b
Browser
\b
/i
,
/
\b
Mobile
\b
/i
]
for
(
let
i
=
0
;
i
<
infos
.
length
;
i
++
)
{
const
info
=
infos
[
i
]
if
(
info
.
indexOf
(
'
Build
'
)
>
0
)
{
model
=
info
.
split
(
'
Build
'
)[
0
].
trim
()
break
}
let
other
for
(
let
o
=
0
;
o
<
otherInfo
.
length
;
o
++
)
{
if
(
otherInfo
[
o
].
test
(
info
))
{
other
=
true
break
}
}
if
(
!
other
)
{
model
=
info
.
trim
()
break
}
}
}
else
if
(
isIPadOS
)
{
model
=
'
iPad
'
osname
=
'
iOS
'
osversion
=
typeof
window
.
BigInt
===
'
function
'
?
'
14.0
'
:
'
13.0
'
deviceType
=
'
pad
'
}
else
if
(
isWindows
||
isMac
||
isLinux
)
{
model
=
'
PC
'
osname
=
'
PC
'
deviceType
=
'
pc
'
const
osversionFind
=
ua
.
match
(
/
\((
.+
?)\)
/
)[
1
]
if
(
isWindows
)
{
osname
=
'
Windows
'
osversion
=
''
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
.
match
(
/
[
Win|WOW
]([\d]
+
)
/
)
if
(
framework
)
{
osversion
+=
` x
${
framework
[
1
]}
`
}
}
else
if
(
isMac
)
{
osname
=
'
Mac
'
osversion
=
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
.
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
'
deviceType
=
'
other
'
}
export
function
getDeviceInfo
()
{
initBrowserInfo
()
const
{
deviceBrand
,
deviceModel
,
brand
,
model
,
platform
,
system
}
=
browserInfo
var
system
=
`
${
osname
}
${
osversion
}
`
var
platform
=
osname
.
toLocaleLowerCase
()
var
safeArea
=
{
left
:
safeAreaInsets
.
left
,
right
:
windowWidth
-
safeAreaInsets
.
right
,
top
:
safeAreaInsets
.
top
,
bottom
:
windowHeight
-
safeAreaInsets
.
bottom
,
width
:
windowWidth
-
safeAreaInsets
.
left
-
safeAreaInsets
.
right
,
height
:
windowHeight
-
safeAreaInsets
.
top
-
safeAreaInsets
.
bottom
return
{
deviceBrand
,
deviceModel
,
brand
,
model
,
system
,
platform
}
}
export
function
getAppBaseInfo
()
{
initBrowserInfo
()
const
{
top
:
windowTop
,
bottom
:
windowBottom
}
=
getWindowOffset
()
windowHeight
-=
windowTop
windowHeight
-=
windowBottom
theme
,
browserName
,
browseVersion
,
language
}
=
browserInfo
let
browserName
let
browseVersion
=
String
(
IEVersion
())
if
(
browseVersion
!==
'
-1
'
)
{
browserName
=
'
IE
'
}
else
{
const
browseVendors
=
[
'
Version
'
,
'
Firefox
'
,
'
Chrome
'
,
'
Edge{0,1}
'
]
const
vendors
=
[
'
Safari
'
,
'
Firefox
'
,
'
Chrome
'
,
'
Edge
'
]
for
(
let
index
=
0
;
index
<
browseVendors
.
length
;
index
++
)
{
const
vendor
=
browseVendors
[
index
]
const
reg
=
new
RegExp
(
`(
${
vendor
}
)/(\\S*)\\b`
)
if
(
reg
.
test
(
ua
))
{
browserName
=
vendors
[
index
]
browseVersion
=
ua
.
match
(
reg
)[
2
]
}
}
return
{
SDKVersion
:
''
,
hostSDKVersion
:
''
,
enableDebug
:
false
,
hostPackageName
:
''
,
hostFontSizeSetting
:
undefined
,
language
,
hostName
:
browserName
,
hostVersion
:
browseVersion
,
hostTheme
:
theme
,
hostLanguage
:
language
,
theme
,
appId
:
__uniConfig
.
appId
,
appName
:
__uniConfig
.
appName
,
appVersion
:
__uniConfig
.
appVersion
,
appVersionCode
:
__uniConfig
.
appVersionCode
,
appLanguage
:
uni
.
getLocale
(),
version
:
__uniConfig
.
appVersion
}
}
// deviceBrand
let
deviceBrand
=
''
if
(
model
)
{
const
_model
=
model
.
toLocaleLowerCase
()
deviceBrand
=
getDeviceBrand
(
_model
)
||
getDeviceBrand
(
osname
.
toLocaleLowerCase
())
||
_model
.
split
(
'
'
)[
0
]
}
/**
* 获取系统信息-同步
*/
export
function
getSystemInfoSync
()
{
_initBrowserInfo
=
true
initBrowserInfo
()
_initBrowserInfo
=
false
const
windowInfo
=
getWindowInfo
()
const
deviceInfo
=
getDeviceInfo
()
const
appBaseInfo
=
getAppBaseInfo
()
_initBrowserInfo
=
true
return
{
windowTop
,
windowBottom
,
windowWidth
,
windowHeight
,
pixelRatio
,
screenWidth
,
screenHeight
,
language
,
statusBarHeight
,
system
,
platform
,
deviceBrand
,
deviceType
,
model
,
deviceModel
:
model
,
safeArea
,
safeAreaInsets
:
{
top
:
safeAreaInsets
.
top
,
right
:
safeAreaInsets
.
right
,
bottom
:
safeAreaInsets
.
bottom
,
left
:
safeAreaInsets
.
left
},
deviceId
:
deviceId
(),
SDKVersion
:
''
,
const
{
ua
,
deviceType
,
browserName
,
browseVersion
,
osname
,
osversion
,
deviceOrientation
}
=
browserInfo
const
{
pixelRatio
}
=
windowInfo
const
systemInfo
=
Object
.
assign
(
{},
windowInfo
,
deviceInfo
,
appBaseInfo
,
{
ua
,
uniPlatform
:
'
web
'
,
deviceType
,
browserName
,
browseVersion
,
osLanguage
:
language
,
osName
:
osname
.
toLocaleLowerCase
(),
osVersion
:
osversion
,
hostLanguage
:
language
,
version
:
__uniConfig
.
appVersion
,
deviceId
:
deviceId
(),
devicePixelRatio
:
pixelRatio
,
deviceOrientation
,
uniPlatform
:
'
web
'
,
uniCompileVersion
:
__uniConfig
.
compilerVersion
,
uniRuntimeVersion
:
__uniConfig
.
compilerVersion
,
appId
:
__uniConfig
.
appId
,
appName
:
__uniConfig
.
appName
,
appVersion
:
__uniConfig
.
appVersion
,
appVersionCode
:
__uniConfig
.
appVersionCode
,
hostName
:
browserName
,
hostVersion
:
browseVersion
,
osTheme
:
''
,
hostTheme
:
''
,
hostPackageName
:
''
fontSizeSetting
:
appBaseInfo
.
hostFontSizeSetting
,
osName
:
osname
.
toLocaleLowerCase
(),
osVersion
:
osversion
,
osLanguage
:
undefined
,
osTheme
:
undefined
}
)
delete
systemInfo
.
screenTop
delete
systemInfo
.
enableDebug
delete
systemInfo
.
theme
return
systemInfo
}
/**
* 获取系统信息-异步
...
...
src/platforms/h5/service/api/device/get-window-info.js
0 → 100644
浏览文件 @
97d48006
import
getWindowOffset
from
'
uni-platform/helpers/get-window-offset
'
import
safeAreaInsets
from
'
safe-area-insets
'
export
function
getWindowInfo
()
{
var
screen
=
window
.
screen
var
pixelRatio
=
window
.
devicePixelRatio
// 横屏时 iOS 获取的屏幕宽高颠倒,进行纠正
const
screenFix
=
/^Apple/
.
test
(
navigator
.
vendor
)
&&
typeof
window
.
orientation
===
'
number
'
const
landscape
=
screenFix
&&
Math
.
abs
(
window
.
orientation
)
===
90
var
screenWidth
=
screenFix
?
Math
[
landscape
?
'
max
'
:
'
min
'
](
screen
.
width
,
screen
.
height
)
:
screen
.
width
var
screenHeight
=
screenFix
?
Math
[
landscape
?
'
min
'
:
'
max
'
](
screen
.
height
,
screen
.
width
)
:
screen
.
height
var
windowWidth
=
Math
.
min
(
window
.
innerWidth
,
document
.
documentElement
.
clientWidth
,
screenWidth
)
||
screenWidth
var
windowHeight
=
window
.
innerHeight
var
statusBarHeight
=
safeAreaInsets
.
top
var
safeArea
=
{
left
:
safeAreaInsets
.
left
,
right
:
windowWidth
-
safeAreaInsets
.
right
,
top
:
safeAreaInsets
.
top
,
bottom
:
windowHeight
-
safeAreaInsets
.
bottom
,
width
:
windowWidth
-
safeAreaInsets
.
left
-
safeAreaInsets
.
right
,
height
:
windowHeight
-
safeAreaInsets
.
top
-
safeAreaInsets
.
bottom
}
const
{
top
:
windowTop
,
bottom
:
windowBottom
}
=
getWindowOffset
()
windowHeight
-=
windowTop
windowHeight
-=
windowBottom
return
{
windowTop
,
windowBottom
,
windowWidth
,
windowHeight
,
pixelRatio
,
screenWidth
,
screenHeight
,
statusBarHeight
,
safeArea
,
safeAreaInsets
:
{
top
:
safeAreaInsets
.
top
,
right
:
safeAreaInsets
.
right
,
bottom
:
safeAreaInsets
.
bottom
,
left
:
safeAreaInsets
.
left
},
screenTop
:
screenHeight
-
windowHeight
}
}
src/platforms/mp-weixin/helpers/enhance-system-info.js
浏览文件 @
97d48006
...
...
@@ -30,7 +30,13 @@ export function addSafeAreaInsets (result) {
}
export
function
populateParameters
(
result
)
{
const
{
brand
,
model
,
system
,
language
,
theme
,
version
,
hostName
=
''
,
platform
}
=
result
const
{
brand
,
model
,
system
,
language
,
theme
,
version
,
hostName
,
platform
,
fontSizeSetting
,
SDKVersion
,
pixelRatio
,
deviceOrientation
,
environment
}
=
result
const
isQuickApp
=
__PLATFORM__
.
indexOf
(
'
quickapp-webview
'
)
!==
-
1
// osName osVersion
...
...
@@ -46,7 +52,10 @@ export function populateParameters (result) {
let
hostVersion
=
version
// host 枚举值 https://smartprogram.baidu.com/docs/develop/api/device_sys/hostlist/
if
(
__PLATFORM__
===
'
mp-baidu
'
)
{
hostVersion
=
result
.
swanNativeVersion
||
version
hostVersion
=
result
.
swanNativeVersion
}
if
(
__PLATFORM__
===
'
mp-jd
'
)
{
hostVersion
=
result
.
hostVersionName
}
// deviceType
...
...
@@ -77,13 +86,31 @@ export function populateParameters (result) {
}
// hostName
let
_hostName
=
hostName
// mp-jd
if
(
__PLATFORM__
===
'
mp-weixin
'
)
_hostName
=
(
result
.
host
||
{}).
env
let
_hostName
=
hostName
||
__PLATFORM__
.
split
(
'
-
'
)[
1
]
// mp-jd
if
(
__PLATFORM__
===
'
mp-weixin
'
)
{
if
(
environment
)
{
_hostName
=
environment
}
else
if
(
result
.
host
)
{
_hostName
=
result
.
host
.
env
}
}
if
(
__PLATFORM__
===
'
mp-baidu
'
||
__PLATFORM__
===
'
mp-kuaishou
'
)
{
_hostName
=
result
.
host
}
if
(
__PLATFORM__
===
'
mp-qq
'
)
_hostName
=
result
.
AppPlatform
if
(
__PLATFORM__
===
'
mp-toutiao
'
||
__PLATFORM__
===
'
mp-lark
'
)
{
_hostName
=
result
.
appName
}
if
(
__PLATFORM__
===
'
mp-alipay
'
)
_hostName
=
result
.
app
// deviceOrientation
let
_deviceOrientation
=
deviceOrientation
// 仅 微信 百度 支持
if
(
__PLATFORM__
===
'
mp-baidu
'
)
{
_deviceOrientation
=
result
.
orientation
}
// devicePixelRatio
let
_devicePixelRatio
=
pixelRatio
if
(
__PLATFORM__
===
'
mp-baidu
'
)
{
_devicePixelRatio
=
result
.
devicePixelRatio
}
// SDKVersion
let
_SDKVersion
=
SDKVersion
if
(
__PLATFORM__
===
'
mp-alipay
'
)
{
_SDKVersion
=
my
.
SDKVersion
}
// wx.getAccountInfoSync
const
parameters
=
{
...
...
@@ -97,19 +124,25 @@ export function populateParameters (result) {
deviceBrand
,
deviceModel
:
model
,
deviceType
,
devicePixelRatio
:
_devicePixelRatio
,
deviceOrientation
:
_deviceOrientation
,
osName
:
osName
.
toLocaleLowerCase
(),
osVersion
,
osLanguage
:
language
,
osTheme
:
theme
,
hostTheme
:
theme
,
hostVersion
,
hostLanguage
:
language
,
hostLanguage
:
language
.
split
(
'
_
'
,
'
-
'
)
,
hostName
:
_hostName
,
hostSDKVersion
:
_SDKVersion
,
hostFontSizeSetting
:
fontSizeSetting
,
windowTop
:
0
,
windowBottom
:
0
,
// TODO
ua
:
''
,
hostPackageName
:
''
,
browserName
:
''
,
browseVersion
:
''
osLanguage
:
undefined
,
osTheme
:
undefined
,
ua
:
undefined
,
hostPackageName
:
undefined
,
browserName
:
undefined
,
browseVersion
:
undefined
}
Object
.
assign
(
result
,
parameters
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录