mh-two-thousand-and-two
2024-04-12 3d2ec2fd0578d3ba0a414b0cc4e4a2ae60878596
1
2
3
4
5
6
7
8
9
10
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import { callApiSync } from '../util'
import { getWindowInfo } from './get-window-info'
import { sortObject } from 'uni-shared'
 
let systemInfo = {}
let _initSystemInfo = true
 
export function weexGetSystemInfoSync () {
  if (!_initSystemInfo) return
  const { getSystemInfoSync } = weex.requireModule('plus')
  systemInfo = getSystemInfoSync()
  if (typeof systemInfo === 'string') {
    try {
      systemInfo = JSON.parse(systemInfo)
    } catch (error) { }
  }
  return systemInfo
}
 
export function getDeviceInfo () {
  weexGetSystemInfoSync()
  const {
    deviceBrand = '', deviceModel, osName,
    osVersion, deviceOrientation, deviceType,
    deviceId
  } = systemInfo
 
  const brand = deviceBrand.toLowerCase()
  const _osName = osName.toLowerCase()
 
  return {
    brand,
    deviceBrand: brand,
    deviceModel,
    devicePixelRatio: plus.screen.scale,
    deviceId,
    deviceOrientation,
    deviceType,
    model: deviceModel,
    platform: _osName,
    system: `${_osName === 'ios' ? 'iOS' : 'Android'} ${osVersion}`
  }
}
 
export function getAppBaseInfo () {
  weexGetSystemInfoSync()
  const {
    hostPackageName, hostName, osLanguage,
    hostVersion, hostLanguage, hostTheme,
    appId, appName, appVersion, appVersionCode,
    appWgtVersion
  } = systemInfo
 
  const appLanguage = uni
    ? uni.getLocale
      ? uni.getLocale()
      : hostLanguage
    : hostLanguage
 
  return {
    appId,
    appName,
    appVersion,
    appVersionCode,
    appWgtVersion,
    appLanguage,
    enableDebug: false,
    hostSDKVersion: undefined,
    hostPackageName,
    hostName,
    hostVersion,
    hostLanguage,
    hostTheme,
    hostFontSizeSetting: undefined,
    language: osLanguage,
    SDKVersion: '',
    theme: plus.navigator.getUIStyle(),
    version: plus.runtime.innerVersion
  }
}
 
export function getSystemInfoSync () {
  return callApiSync(getSystemInfo, Object.create(null), 'getSystemInfo', 'getSystemInfoSync')
}
 
export function getSystemInfo () {
  _initSystemInfo = true
  weexGetSystemInfoSync()
  _initSystemInfo = false
  const windowInfo = getWindowInfo()
  const deviceInfo = getDeviceInfo()
  const appBaseInfo = getAppBaseInfo()
  _initSystemInfo = true
 
  const extraData = {
    errMsg: 'getSystemInfo:ok',
    fontSizeSetting: appBaseInfo.hostFontSizeSetting,
    osName: systemInfo.osName.toLowerCase()
  }
 
  if (systemInfo.hostName) {
    extraData.hostSDKVersion = systemInfo.uniRuntimeVersion
  }
 
  const _systemInfo = Object.assign(
    {},
    systemInfo,
    windowInfo,
    deviceInfo,
    appBaseInfo,
    extraData
  )
 
  delete _systemInfo.screenTop
  delete _systemInfo.enableDebug
  if (!__uniConfig.darkmode) {
    delete _systemInfo.theme
  }
 
  return sortObject(_systemInfo)
}