system.js 3.4 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'

Q
qiang 已提交
14
import deviceId from 'uni-platform/helpers/uuid'
Q
qiang 已提交
15

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

Q
qiang 已提交
20
export function getSystemInfo () {
D
DCloud_LXH 已提交
21 22 23 24 25 26
  const { getSystemInfoSync } = weex.requireModule('plus')
  const info = getSystemInfoSync()
  const { deviceBrand, deviceModel, osName, osVersion, osLanguage } = info
  const brand = deviceBrand.toLowerCase()
  const _osName = osName.toLowerCase()
  const ios = _osName === 'ios'
Q
qiang 已提交
27 28 29 30 31 32 33 34 35 36
  const {
    screenWidth,
    screenHeight
  } = getScreenInfo()
  const statusBarHeight = getStatusbarHeight()

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

D
DCloud_LXH 已提交
82
  return Object.assign({
fxy060608's avatar
fxy060608 已提交
83
    errMsg: 'getSystemInfo:ok',
D
DCloud_LXH 已提交
84 85
    brand: brand,
    model: deviceModel,
fxy060608's avatar
fxy060608 已提交
86 87 88
    pixelRatio: plus.screen.scale,
    screenWidth,
    screenHeight,
89 90
    windowWidth,
    windowHeight,
fxy060608's avatar
fxy060608 已提交
91
    statusBarHeight,
D
DCloud_LXH 已提交
92 93
    language: osLanguage,
    system: `${osName} ${osVersion}`,
fxy060608's avatar
fxy060608 已提交
94 95
    version: plus.runtime.innerVersion,
    fontSizeSetting: '',
D
DCloud_LXH 已提交
96
    platform: _osName,
fxy060608's avatar
fxy060608 已提交
97
    SDKVersion: '',
Q
qiang 已提交
98
    windowTop,
Q
qiang 已提交
99
    windowBottom,
Q
qiang 已提交
100 101 102 103 104 105
    safeArea,
    safeAreaInsets: {
      top: safeAreaInsets.top,
      right: safeAreaInsets.right,
      bottom: safeAreaInsets.bottom,
      left: safeAreaInsets.left
106
    },
Q
qiang 已提交
107
    deviceId: deviceId()
D
DCloud_LXH 已提交
108 109 110 111 112
  }, info, {
    deviceBrand: brand,
    osName: _osName
  })
}