system.js 2.5 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1
import {
fxy060608's avatar
fxy060608 已提交
2
  callApiSync,
fxy060608's avatar
fxy060608 已提交
3 4 5 6 7 8 9 10
  isTabBarPage,
  getLastWebview
} from '../util'

import {
  TITLEBAR_HEIGHT
} from '../../constants'

fxy060608's avatar
fxy060608 已提交
11
import tabBar from '../../framework/tab-bar'
fxy060608's avatar
fxy060608 已提交
12

fxy060608's avatar
fxy060608 已提交
13
export function getSystemInfoSync () {
fxy060608's avatar
fxy060608 已提交
14 15
  return callApiSync(getSystemInfo, Object.create(null), 'getSystemInfo', 'getSystemInfoSync')
}
fxy060608's avatar
fxy060608 已提交
16 17

export function getSystemInfo () {
fxy060608's avatar
fxy060608 已提交
18 19 20 21 22 23 24
  const platform = plus.os.name.toLowerCase()
  const ios = platform === 'ios'
  // 安卓 plus 接口获取的屏幕大小值不为整数,iOS js 获取的屏幕大小横屏时颠倒
  const screenWidth = plus.screen.resolutionWidth
  const screenHeight = plus.screen.resolutionHeight
  // 横屏时 iOS 获取的状态栏高度错误,进行纠正
  var landscape = Math.abs(plus.navigator.getOrientation()) === 90
25
  var statusBarHeight = Math.round(plus.navigator.getStatusbarHeight())
fxy060608's avatar
fxy060608 已提交
26 27 28
  if (ios && landscape) {
    statusBarHeight = Math.min(20, statusBarHeight)
  }
29 30 31 32 33 34 35 36 37
  var safeAreaInsets
  function getSafeAreaInsets () {
    return {
      left: 0,
      right: 0,
      top: titleNView ? 0 : statusBarHeight,
      bottom: 0
    }
  }
fxy060608's avatar
fxy060608 已提交
38 39 40 41 42 43 44 45 46
  // 判断是否存在 titleNView
  var titleNView
  var webview = getLastWebview()
  if (webview) {
    let style = webview.getStyle()
    if (style) {
      titleNView = style && style.titleNView
      titleNView = titleNView && titleNView.type === 'default'
    }
47 48 49 50 51
    safeAreaInsets = ios ? webview.getSafeAreaInsets() : getSafeAreaInsets()
  } else {
    safeAreaInsets = ios ? plus.navigator.getSafeAreaInsets() : getSafeAreaInsets()
  }
  var windowHeight = Math.min(screenHeight - (titleNView ? (statusBarHeight + TITLEBAR_HEIGHT)
52
    : 0) - (isTabBarPage() && tabBar.visible ? tabBar.height : 0), screenHeight)
53 54 55 56 57 58 59 60
  var windowWidth = screenWidth
  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
fxy060608's avatar
fxy060608 已提交
61
  }
62

fxy060608's avatar
fxy060608 已提交
63 64
  return {
    errMsg: 'getSystemInfo:ok',
65
    brand: plus.device.vendor,
fxy060608's avatar
fxy060608 已提交
66 67 68 69
    model: plus.device.model,
    pixelRatio: plus.screen.scale,
    screenWidth,
    screenHeight,
70 71
    windowWidth,
    windowHeight,
fxy060608's avatar
fxy060608 已提交
72 73 74 75 76 77 78 79
    statusBarHeight,
    language: plus.os.language,
    system: plus.os.version,
    version: plus.runtime.innerVersion,
    fontSizeSetting: '',
    platform,
    SDKVersion: '',
    windowTop: 0,
80 81
    windowBottom: 0,
    safeArea
fxy060608's avatar
fxy060608 已提交
82
  }
83
}