system.js 1.9 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 11
  isTabBarPage,
  getLastWebview
} from '../util'

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

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

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

export function getSystemInfo () {
fxy060608's avatar
fxy060608 已提交
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
  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
  var statusBarHeight = plus.navigator.getStatusbarHeight()
  if (ios && landscape) {
    statusBarHeight = Math.min(20, statusBarHeight)
  }
  // 判断是否存在 titleNView
  var titleNView
  var webview = getLastWebview()
  if (webview) {
    let style = webview.getStyle()
    if (style) {
      titleNView = style && style.titleNView
      titleNView = titleNView && titleNView.type === 'default'
    }
  }
  return {
    errMsg: 'getSystemInfo:ok',
    brand: '',
    model: plus.device.model,
    pixelRatio: plus.screen.scale,
    screenWidth,
    screenHeight,
    // 安卓端 webview 宽度有时比屏幕多 1px,相比取最小值
    // TODO screenWidth,screenHeight
    windowWidth: screenWidth,
    windowHeight: Math.min(screenHeight - (titleNView ? (statusBarHeight + TITLEBAR_HEIGHT)
fxy060608's avatar
fxy060608 已提交
51
      : 0) - (isTabBarPage() && tabBar.visible ? TABBAR_HEIGHT : 0), screenHeight),
fxy060608's avatar
fxy060608 已提交
52 53 54 55 56 57 58 59 60 61 62
    statusBarHeight,
    language: plus.os.language,
    system: plus.os.version,
    version: plus.runtime.innerVersion,
    fontSizeSetting: '',
    platform,
    SDKVersion: '',
    windowTop: 0,
    windowBottom: 0
  }
}