system.js 2.7 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1
import {
2
  callApiSync
fxy060608's avatar
fxy060608 已提交
3 4
} from '../util'

5
import { getWindowInfo } from './get-window-info'
fxy060608's avatar
fxy060608 已提交
6

7
import deviceId from 'uni-platform/helpers/uuid'
fxy060608's avatar
fxy060608 已提交
8

9 10
let systemInfo = {}
let _initSystemInfo = true
11

12 13 14 15 16 17 18 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 51 52 53 54 55 56 57 58 59 60 61 62 63 64
function weexGetSystemInfoSync () {
  if (!_initSystemInfo) return
  const { getSystemInfoSync } = weex.requireModule('plus')
  systemInfo = getSystemInfoSync()
}

export function getDeviceInfo () {
  weexGetSystemInfoSync()
  const {
    deviceBrand, deviceModel, osName,
    osVersion
  } = systemInfo

  const brand = deviceBrand.toLowerCase()

  return {
    deviceBrand: brand,
    deviceModel,
    brand,
    model: deviceModel,
    system: `${osName === 'ios' ? 'iOS' : 'Android'} ${osVersion}`,
    platform: osName
  }
}

export function getAppBaseInfo () {
  weexGetSystemInfoSync()
  const {
    hostPackageName, hostName, osLanguage,
    hostVersion, hostLanguage, hostTheme,
    appId, appName, appVersion, appVersionCode
  } = systemInfo

  return {
    SDKVersion: '',
    hostSDKVersion: '',
    enableDebug: false,
    appId,
    appName,
    appVersion,
    appVersionCode,
    appLanguage: uni.getLocale(),
    version: plus.runtime.innerVersion,
    language: osLanguage,
    theme: '',
    hostPackageName,
    hostName,
    hostVersion,
    hostLanguage,
    hostTheme,
    hostFontSizeSetting: undefined
  }
}
Q
qiang 已提交
65

Q
qiang 已提交
66
export function getSystemInfoSync () {
fxy060608's avatar
fxy060608 已提交
67 68
  return callApiSync(getSystemInfo, Object.create(null), 'getSystemInfo', 'getSystemInfoSync')
}
fxy060608's avatar
fxy060608 已提交
69

Q
qiang 已提交
70
export function getSystemInfo () {
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
  _initSystemInfo = true
  weexGetSystemInfoSync()
  _initSystemInfo = false
  const deviceInfo = getDeviceInfo()
  const appBaseInfo = getAppBaseInfo()
  _initSystemInfo = true

  const { osName, osLanguage, osVersion, pixelRatio } = systemInfo
  const osLanguageSplit = osLanguage.split('-')
  const osLanguageSplitLast = osLanguageSplit[osLanguageSplit.length - 1]
  let _osLanguage = `${osLanguageSplit[0]}${osLanguageSplitLast ? '-'+ osLanguageSplitLast : ''}`

  let extraData = {
    errMsg: 'getSystemInfo:ok',
    fontSizeSetting: appBaseInfo.hostFontSizeSetting,
    devicePixelRatio: pixelRatio,
    deviceId: deviceId(),
    uniCompileVersion: __uniConfig.compilerVersion,
    uniRuntimeVersion: __uniConfig.compilerVersion,
    osLanguage: _osLanguage
Q
qiang 已提交
91
  }
92 93 94 95

  if (osName === 'ios') {
    extraData.romName = osName
    extraData.romVersion = osVersion
fxy060608's avatar
fxy060608 已提交
96
  }
97

98 99 100 101 102 103 104 105 106 107 108 109 110 111
  const _systemInfo = Object.assign(
    {},
    systemInfo,
    getWindowInfo(),
    deviceInfo,
    appBaseInfo,
    extraData
  )

  delete _systemInfo.screenTop
  delete _systemInfo.enableDebug
  delete _systemInfo.theme

  return _systemInfo
D
DCloud_LXH 已提交
112
}