system.js 3.1 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1
import {
fxy060608's avatar
fxy060608 已提交
2
  callApiSync,
fxy060608's avatar
fxy060608 已提交
3
  isTabBarPage,
Q
qiang 已提交
4 5
  getLastWebview,
  getScreenInfo
fxy060608's avatar
fxy060608 已提交
6 7
} from '../util'

8
import { NAVBAR_HEIGHT } from 'uni-helpers/constants'
fxy060608's avatar
fxy060608 已提交
9

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

12 13
import { getStatusbarHeight } from 'uni-platform/helpers/status-bar'

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
  const platform = plus.os.name.toLowerCase()
  const ios = platform === 'ios'
Q
qiang 已提交
21 22 23 24 25 26 27 28 29 30
  const {
    screenWidth,
    screenHeight
  } = getScreenInfo()
  const statusBarHeight = getStatusbarHeight()

  let safeAreaInsets
  const titleNView = {
    height: 0,
    cover: false
31
  }
Q
qiang 已提交
32
  const webview = getLastWebview()
fxy060608's avatar
fxy060608 已提交
33 34
  if (webview) {
    let style = webview.getStyle()
Q
qiang 已提交
35 36
    style = style && style.titleNView
    if (style && style.type && style.type !== 'none') {
37
      titleNView.height = style.type === 'transparent' ? 0 : (statusBarHeight + NAVBAR_HEIGHT)
Q
qiang 已提交
38
      titleNView.cover = style.type === 'transparent' || style.type === 'float'
fxy060608's avatar
fxy060608 已提交
39
    }
Q
qiang 已提交
40
    safeAreaInsets = webview.getSafeAreaInsets()
41
  } else {
Q
qiang 已提交
42
    safeAreaInsets = plus.navigator.getSafeAreaInsets()
43
  }
Q
qiang 已提交
44 45 46 47 48 49 50 51 52 53
  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
54 55
  let windowHeight = screenHeight - titleNView.height - tabBarView.height
  let windowHeightReal = screenHeight - (titleNView.cover ? 0 : titleNView.height) - (tabBarView.cover ? 0 : tabBarView.height)
Q
qiang 已提交
56
  const windowWidth = screenWidth
57 58 59 60
  if ((!tabBarView.height || tabBarView.cover) && !safeAreaInsets.bottom && safeAreaInsets.deviceBottom) {
    windowHeight -= safeAreaInsets.deviceBottom
    windowHeightReal -= safeAreaInsets.deviceBottom
  }
Q
qiang 已提交
61 62 63 64 65 66 67
  safeAreaInsets = ios ? safeAreaInsets : {
    left: 0,
    right: 0,
    top: titleNView.height && !titleNView.cover ? 0 : statusBarHeight,
    bottom: 0
  }
  const safeArea = {
68 69 70
    left: safeAreaInsets.left,
    right: windowWidth - safeAreaInsets.right,
    top: safeAreaInsets.top,
Q
qiang 已提交
71
    bottom: windowHeightReal - safeAreaInsets.bottom,
72
    width: windowWidth - safeAreaInsets.left - safeAreaInsets.right,
Q
qiang 已提交
73
    height: windowHeightReal - safeAreaInsets.top - safeAreaInsets.bottom
fxy060608's avatar
fxy060608 已提交
74
  }
75

fxy060608's avatar
fxy060608 已提交
76 77
  return {
    errMsg: 'getSystemInfo:ok',
78
    brand: plus.device.vendor,
fxy060608's avatar
fxy060608 已提交
79 80 81 82
    model: plus.device.model,
    pixelRatio: plus.screen.scale,
    screenWidth,
    screenHeight,
83 84
    windowWidth,
    windowHeight,
fxy060608's avatar
fxy060608 已提交
85 86 87 88 89 90 91
    statusBarHeight,
    language: plus.os.language,
    system: plus.os.version,
    version: plus.runtime.innerVersion,
    fontSizeSetting: '',
    platform,
    SDKVersion: '',
Q
qiang 已提交
92
    windowTop,
Q
qiang 已提交
93
    windowBottom,
Q
qiang 已提交
94 95 96 97 98 99
    safeArea,
    safeAreaInsets: {
      top: safeAreaInsets.top,
      right: safeAreaInsets.right,
      bottom: safeAreaInsets.bottom,
      left: safeAreaInsets.left
100 101
    },
    uuid: plus.runtime.getDCloudId()
fxy060608's avatar
fxy060608 已提交
102
  }
103
}