Skip to content

Commit

Permalink
fix: 解决某些情况获取安卓手机型号出错的问题 dcloudio#134
Browse files Browse the repository at this point in the history
  • Loading branch information
dcloud-robot committed Jan 15, 2019
1 parent e17a154 commit 3cd4b6b
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/platforms/h5/service/api/device/get-system-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,26 @@ export function getSystemInfoSync () {
if (osversionFind) {
osversion = osversionFind[1]
}
model = ua.split(')')[0].split(';')
model = model[model.length - 1].split('Build')[0].replace(/^\s(.+)\s$/, '$1')
let infos = ua.match(/\((.+?)\)/)[1].split(';')
const otherInfo = [/^\s?Android/i, /^\s?Linux/i, /^\s?U/i, /^\s?[a-z][a-z]$/i, /^\s?[a-z][a-z]-[a-z][a-z]$/i, /^\s?wv/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 {
osname = 'Other'
osversion = '0'
Expand All @@ -59,11 +77,11 @@ export function getSystemInfoSync () {
windowHeight -= windowTop
windowHeight -= windowBottom

return {
windowTop,
return {
windowTop,
windowBottom,
windowWidth,
windowHeight,
windowHeight,
pixelRatio,
screenWidth,
screenHeight,
Expand All @@ -79,4 +97,4 @@ export function getSystemInfoSync () {
*/
export function getSystemInfo () {
return getSystemInfoSync()
}
}

0 comments on commit 3cd4b6b

Please sign in to comment.