Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
2830a507
U
uni-app
项目概览
DCloud
/
uni-app
2 个月 前同步成功
通知
716
Star
38705
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2830a507
编写于
5月 31, 2022
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'dev' into alpha
上级
cafb4dc6
35158472
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
121 addition
and
138 deletion
+121
-138
src/platforms/app-plus/service/api/device/system.js
src/platforms/app-plus/service/api/device/system.js
+16
-29
src/platforms/h5/service/api/base/get-browser-info.js
src/platforms/h5/service/api/base/get-browser-info.js
+8
-22
src/platforms/h5/service/api/device/get-system-info.js
src/platforms/h5/service/api/device/get-system-info.js
+25
-29
src/platforms/mp-weixin/helpers/enhance-system-info.js
src/platforms/mp-weixin/helpers/enhance-system-info.js
+39
-38
src/platforms/mp-weixin/helpers/get-app-base-info.js
src/platforms/mp-weixin/helpers/get-app-base-info.js
+15
-14
src/platforms/mp-weixin/helpers/get-device-info.js
src/platforms/mp-weixin/helpers/get-device-info.js
+4
-3
src/platforms/mp-weixin/helpers/get-window-info.js
src/platforms/mp-weixin/helpers/get-window-info.js
+3
-2
src/shared/util.js
src/shared/util.js
+11
-1
未找到文件。
src/platforms/app-plus/service/api/device/system.js
浏览文件 @
2830a507
import
{
callApiSync
}
from
'
../util
'
import
{
callApiSync
}
from
'
../util
'
import
{
getWindowInfo
}
from
'
./get-window-info
'
import
deviceId
from
'
uni-platform/helpers/uuid
'
import
{
sortObject
}
from
'
uni-shared
'
let
systemInfo
=
{}
let
_initSystemInfo
=
true
...
...
@@ -26,16 +23,16 @@ export function getDeviceInfo () {
const
_osName
=
osName
.
toLowerCase
()
return
{
brand
,
deviceBrand
:
brand
,
deviceModel
,
devicePixelRatio
:
plus
.
screen
.
scale
,
deviceId
:
deviceId
(),
deviceOrientation
,
deviceType
,
brand
,
model
:
deviceModel
,
system
:
`
${
_osName
===
'
ios
'
?
'
iOS
'
:
'
Android
'
}
${
osVersion
}
`
,
platform
:
_osName
platform
:
_osName
,
system
:
`
${
_osName
===
'
ios
'
?
'
iOS
'
:
'
Android
'
}
${
osVersion
}
`
}
}
...
...
@@ -54,23 +51,23 @@ export function getAppBaseInfo () {
:
hostLanguage
return
{
SDKVersion
:
''
,
hostSDKVersion
:
''
,
enableDebug
:
false
,
appId
,
appName
,
appVersion
,
appVersionCode
,
appLanguage
,
version
:
plus
.
runtime
.
innerVersion
,
language
:
osLanguage
,
theme
:
''
,
enableDebug
:
false
,
hostSDKVersion
:
undefined
,
hostPackageName
,
hostName
,
hostVersion
,
hostLanguage
,
hostTheme
,
hostFontSizeSetting
:
undefined
hostFontSizeSetting
:
undefined
,
language
:
osLanguage
,
SDKVersion
:
''
,
theme
:
undefined
,
version
:
plus
.
runtime
.
innerVersion
}
}
...
...
@@ -87,24 +84,14 @@ export function getSystemInfo () {
const
appBaseInfo
=
getAppBaseInfo
()
_initSystemInfo
=
true
const
{
osName
,
osLanguage
,
osVersion
}
=
systemInfo
const
_osName
=
osName
.
toLowerCase
()
const
osLanguageSplit
=
osLanguage
.
split
(
'
-
'
)
const
osLanguageSplitLast
=
osLanguageSplit
[
osLanguageSplit
.
length
-
1
]
const
_osLanguage
=
`
${
osLanguageSplit
[
0
]}${
osLanguageSplitLast
?
'
-
'
+
osLanguageSplitLast
:
''
}
`
const
extraData
=
{
errMsg
:
'
getSystemInfo:ok
'
,
fontSizeSetting
:
appBaseInfo
.
hostFontSizeSetting
,
uniCompileVersion
:
__uniConfig
.
compilerVersion
,
uniRuntimeVersion
:
__uniConfig
.
compilerVersion
,
osLanguage
:
_osLanguage
,
osName
:
_osName
osName
:
systemInfo
.
osName
.
toLowerCase
()
}
if
(
_osName
===
'
ios
'
)
{
extraData
.
romName
=
_osName
extraData
.
romVersion
=
osVersion
if
(
systemInfo
.
hostName
)
{
extraData
.
hostSDKVersion
=
systemInfo
.
uniRuntimeVersion
}
const
_systemInfo
=
Object
.
assign
(
...
...
@@ -120,5 +107,5 @@ export function getSystemInfo () {
delete
_systemInfo
.
enableDebug
delete
_systemInfo
.
theme
return
_systemInfo
return
sortObject
(
_systemInfo
)
}
src/platforms/h5/service/api/base/get-browser-info.js
浏览文件 @
2830a507
...
...
@@ -21,11 +21,6 @@ function IEVersion () {
}
}
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
/**
* 是否安卓设备
...
...
@@ -165,15 +160,15 @@ export function getBrowserInfo () {
}
else
{
osname
=
'
Other
'
osversion
=
'
0
'
deviceType
=
'
other
'
deviceType
=
'
unknown
'
}
var
system
=
`
${
osname
}
${
osversion
}
`
var
platform
=
osname
.
toLocaleLowerCase
()
let
browserName
=
''
let
browseVersion
=
String
(
IEVersion
())
if
(
browseVersion
!==
'
-1
'
)
{
browserName
=
'
IE
'
}
else
{
let
browse
r
Version
=
String
(
IEVersion
())
if
(
browse
r
Version
!==
'
-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
++
)
{
...
...
@@ -181,40 +176,31 @@ export function getBrowserInfo () {
const
reg
=
new
RegExp
(
`(
${
vendor
}
)/(\\S*)\\b`
)
if
(
reg
.
test
(
ua
))
{
browserName
=
vendors
[
index
]
browseVersion
=
ua
.
match
(
reg
)[
2
]
browse
r
Version
=
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
,
deviceBrand
:
undefined
,
brand
:
undefined
,
deviceModel
:
model
,
deviceOrientation
,
brand
:
deviceBrand
,
model
,
system
,
platform
,
browserName
:
browserName
.
toLocaleLowerCase
(),
browseVersion
,
browse
r
Version
,
language
,
deviceType
,
ua
,
osname
,
osversion
,
theme
:
''
theme
:
undefined
}
}
src/platforms/h5/service/api/device/get-system-info.js
浏览文件 @
2830a507
import
{
getWindowInfo
}
from
'
./get-window-info
'
import
deviceId
from
'
uni-platform/helpers/uuid
'
import
{
getBrowserInfo
}
from
'
../base/get-browser-info
'
import
{
sortObject
}
from
'
uni-shared
'
let
browserInfo
=
{}
let
_initBrowserInfo
=
true
...
...
@@ -24,27 +25,22 @@ export function getDeviceInfo () {
}
=
browserInfo
return
{
brand
,
deviceBrand
,
deviceModel
,
devicePixelRatio
:
window
.
devicePixelRatio
,
deviceId
:
deviceId
(),
deviceOrientation
,
deviceType
,
brand
,
model
,
syste
m
,
platfor
m
platfor
m
,
syste
m
}
}
export
function
getAppBaseInfo
()
{
initBrowserInfo
()
const
{
theme
,
browserName
,
browseVersion
,
language
}
=
browserInfo
const
{
theme
,
language
}
=
browserInfo
const
appLanguage
=
uni
?
uni
.
getLocale
...
...
@@ -53,23 +49,23 @@ export function getAppBaseInfo () {
:
language
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
,
version
:
__uniConfig
.
appVersion
enableDebug
:
false
,
hostSDKVersion
:
undefined
,
hostPackageName
:
undefined
,
hostFontSizeSetting
:
undefined
,
hostName
:
undefined
,
hostVersion
:
undefined
,
hostTheme
:
undefined
,
hostLanguage
:
undefined
,
language
,
SDKVersion
:
''
,
theme
,
version
:
''
}
}
...
...
@@ -85,7 +81,7 @@ export function getSystemInfoSync () {
const
appBaseInfo
=
getAppBaseInfo
()
_initBrowserInfo
=
true
const
{
ua
,
browserName
,
browseVersion
,
osname
,
osversion
}
=
browserInfo
const
{
ua
,
browserName
,
browse
r
Version
,
osname
,
osversion
}
=
browserInfo
const
systemInfo
=
Object
.
assign
(
{},
...
...
@@ -93,17 +89,17 @@ export function getSystemInfoSync () {
deviceInfo
,
appBaseInfo
,
{
ua
,
browserName
,
browseVersion
,
uniPlatform
:
'
web
'
,
uniCompileVersion
:
__uniConfig
.
compilerVersion
,
uniRuntimeVersion
:
__uniConfig
.
compilerVersion
,
browserVersion
,
fontSizeSetting
:
appBaseInfo
.
hostFontSizeSetting
,
osName
:
osname
.
toLocaleLowerCase
(),
osVersion
:
osversion
,
osLanguage
:
undefined
,
osTheme
:
undefined
osTheme
:
undefined
,
uniPlatform
:
'
web
'
,
uniCompileVersion
:
__uniConfig
.
compilerVersion
,
uniRuntimeVersion
:
__uniConfig
.
compilerVersion
,
ua
}
)
...
...
@@ -111,7 +107,7 @@ export function getSystemInfoSync () {
delete
systemInfo
.
enableDebug
delete
systemInfo
.
theme
return
s
ystemInfo
return
s
ortObject
(
systemInfo
)
}
/**
* 获取系统信息-异步
...
...
src/platforms/mp-weixin/helpers/enhance-system-info.js
浏览文件 @
2830a507
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
'
}
return
''
}
import
{
getLocale
}
from
'
uni-core/runtime/locale
'
const
UUID_KEY
=
'
__DC_STAT_UUID
'
let
deviceId
...
...
@@ -34,11 +30,10 @@ export function populateParameters (result) {
const
{
brand
=
''
,
model
=
''
,
system
=
''
,
language
=
''
,
theme
,
version
,
hostName
,
platform
,
fontSizeSetting
,
SDKVersion
,
pixelRatio
,
deviceOrientation
,
environment
platform
,
fontSizeSetting
,
SDKVersion
,
pixelRatio
,
deviceOrientation
}
=
result
const
isQuickApp
=
__PLATFORM__
.
indexOf
(
'
quickapp-webview
'
)
!==
-
1
//
const isQuickApp = __PLATFORM__.indexOf('quickapp-webview') !== -1
// osName osVersion
let
osName
=
''
...
...
@@ -63,22 +58,10 @@ export function populateParameters (result) {
const
deviceType
=
getGetDeviceType
(
result
,
model
)
// deviceModel
const
deviceBrand
=
getDeviceBrand
(
brand
,
model
,
isQuickApp
)
const
deviceBrand
=
getDeviceBrand
(
brand
)
// hostName
const
_platform
=
__PLATFORM__
===
'
mp-weixin
'
?
'
WeChat
'
:
__PLATFORM__
.
split
(
'
-
'
)[
1
]
let
_hostName
=
hostName
||
_platform
// mp-jd
if
(
__PLATFORM__
===
'
mp-weixin
'
)
{
if
(
environment
)
{
_hostName
=
environment
}
else
if
(
result
.
host
&&
result
.
host
.
env
)
{
_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
const
_hostName
=
getHostName
(
result
)
// deviceOrientation
let
_deviceOrientation
=
deviceOrientation
// 仅 微信 百度 支持
...
...
@@ -92,6 +75,9 @@ export function populateParameters (result) {
let
_SDKVersion
=
SDKVersion
if
(
__PLATFORM__
===
'
mp-alipay
'
)
{
_SDKVersion
=
my
.
SDKVersion
}
// hostLanguage
const
hostLanguage
=
language
.
replace
(
/_/g
,
'
-
'
)
// wx.getAccountInfoSync
const
parameters
=
{
...
...
@@ -99,6 +85,7 @@ export function populateParameters (result) {
appName
:
process
.
env
.
UNI_APP_NAME
,
appVersion
:
process
.
env
.
UNI_APP_VERSION_NAME
,
appVersionCode
:
process
.
env
.
UNI_APP_VERSION_CODE
,
appLanguage
:
getAppLanguage
(
hostLanguage
),
uniCompileVersion
:
process
.
env
.
UNI_COMPILER_VERSION
,
uniRuntimeVersion
:
process
.
env
.
UNI_COMPILER_VERSION
,
uniPlatform
:
process
.
env
.
UNI_SUB_PLATFORM
||
process
.
env
.
UNI_PLATFORM
,
...
...
@@ -111,7 +98,7 @@ export function populateParameters (result) {
osVersion
,
hostTheme
:
theme
,
hostVersion
,
hostLanguage
:
language
.
replace
(
'
_
'
,
'
-
'
)
,
hostLanguage
,
hostName
:
_hostName
,
hostSDKVersion
:
_SDKVersion
,
hostFontSizeSetting
:
fontSizeSetting
,
...
...
@@ -123,7 +110,7 @@ export function populateParameters (result) {
ua
:
undefined
,
hostPackageName
:
undefined
,
browserName
:
undefined
,
browseVersion
:
undefined
browse
r
Version
:
undefined
}
Object
.
assign
(
result
,
parameters
)
...
...
@@ -150,20 +137,34 @@ export function getGetDeviceType (result, model) {
return
deviceType
}
export
function
getDeviceBrand
(
brand
,
model
,
isQuickApp
=
false
)
{
let
deviceBrand
=
model
.
split
(
'
'
)[
0
].
toLocaleLowerCase
()
if
(
__PLATFORM__
===
'
mp-toutiao
'
||
__PLATFORM__
===
'
mp-lark
'
||
isQuickApp
)
{
export
function
getDeviceBrand
(
brand
)
{
let
deviceBrand
=
brand
if
(
deviceBrand
)
{
deviceBrand
=
brand
.
toLocaleLowerCase
()
}
else
{
deviceBrand
=
_getDeviceBrand
(
deviceBrand
)
}
return
deviceBrand
}
export
function
getAppLanguage
(
defaultLanguage
)
{
return
getLocale
?
getLocale
()
:
defaultLanguage
}
export
function
getHostName
(
result
)
{
const
_platform
=
__PLATFORM__
===
'
mp-weixin
'
?
'
WeChat
'
:
__PLATFORM__
.
split
(
'
-
'
)[
1
]
let
_hostName
=
result
.
hostName
||
_platform
// mp-jd
if
(
__PLATFORM__
===
'
mp-weixin
'
)
{
if
(
result
.
environment
)
{
_hostName
=
result
.
environment
}
else
if
(
result
.
host
&&
result
.
host
.
env
)
{
_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
return
_hostName
}
src/platforms/mp-weixin/helpers/get-app-base-info.js
浏览文件 @
2830a507
import
{
getAppLanguage
,
getHostName
}
from
'
./enhance-system-info
'
import
{
sortObject
}
from
'
uni-shared
'
export
default
{
returnValue
:
function
(
result
)
{
const
{
version
,
language
,
SDKVersion
,
theme
}
=
result
let
_hostName
=
__PLATFORM__
.
split
(
'
-
'
)[
1
]
// mp-jd
if
(
__PLATFORM__
===
'
mp-weixin
'
)
{
if
(
result
.
host
&&
result
.
host
.
env
)
{
_hostName
=
result
.
host
.
env
}
}
const
_hostName
=
getHostName
(
result
)
Object
.
assign
(
result
,
{
hostVersion
:
version
,
hostLanguage
:
language
.
replace
(
'
_
'
,
'
-
'
),
hostName
:
_hostName
,
hostSDKVersion
:
SDKVersion
,
hostTheme
:
theme
,
const
hostLanguage
=
language
.
replace
(
'
_
'
,
'
-
'
)
result
=
sortObject
(
Object
.
assign
(
result
,
{
appId
:
process
.
env
.
UNI_APP_ID
,
appName
:
process
.
env
.
UNI_APP_NAME
,
appVersion
:
process
.
env
.
UNI_APP_VERSION_NAME
,
appVersionCode
:
process
.
env
.
UNI_APP_VERSION_CODE
})
appVersionCode
:
process
.
env
.
UNI_APP_VERSION_CODE
,
appLanguage
:
getAppLanguage
(
hostLanguage
),
hostVersion
:
version
,
hostLanguage
,
hostName
:
_hostName
,
hostSDKVersion
:
SDKVersion
,
hostTheme
:
theme
}))
}
}
src/platforms/mp-weixin/helpers/get-device-info.js
浏览文件 @
2830a507
import
{
useDeviceId
,
getGetDeviceType
,
getDeviceBrand
}
from
'
./enhance-system-info
'
import
{
sortObject
}
from
'
uni-shared
'
export
default
{
returnValue
:
function
(
result
)
{
const
{
brand
,
model
}
=
result
const
deviceType
=
getGetDeviceType
(
result
,
model
)
const
deviceBrand
=
getDeviceBrand
(
brand
,
model
)
const
deviceBrand
=
getDeviceBrand
(
brand
)
useDeviceId
(
result
)
Object
.
assign
(
result
,
{
result
=
sortObject
(
Object
.
assign
(
result
,
{
deviceType
,
deviceBrand
,
deviceModel
:
model
})
})
)
}
}
src/platforms/mp-weixin/helpers/get-window-info.js
浏览文件 @
2830a507
import
{
addSafeAreaInsets
}
from
'
./enhance-system-info
'
import
{
sortObject
}
from
'
uni-shared
'
export
default
{
returnValue
:
function
(
result
)
{
addSafeAreaInsets
(
result
)
Object
.
assign
(
result
,
{
result
=
sortObject
(
Object
.
assign
(
result
,
{
windowTop
:
0
,
windowBottom
:
0
})
})
)
}
}
src/shared/util.js
浏览文件 @
2830a507
...
...
@@ -25,7 +25,7 @@ export function hasOwn (obj, key) {
return
hasOwnProperty
.
call
(
obj
,
key
)
}
export
function
noop
()
{}
export
function
noop
()
{
}
export
function
toRawType
(
val
)
{
return
_toString
.
call
(
val
).
slice
(
8
,
-
1
)
...
...
@@ -195,3 +195,13 @@ export function deepClone (vnodes, createElement) {
}
export
*
from
'
./uni-id-mixin
'
export
function
sortObject
(
obj
)
{
const
sortObj
=
{}
if
(
isPlainObject
(
obj
))
{
Object
.
keys
(
obj
).
sort
().
forEach
(
key
=>
{
sortObj
[
key
]
=
obj
[
key
]
})
}
return
!
Object
.
keys
(
sortObj
)
?
obj
:
sortObj
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录