lst619247

wx.getSystemInfo()

获取系统信息

函数参数:

在这里插入图片描述

返回值:

在这里插入图片描述
例如:
写法一
index.js

 1 /*
 2   brand   设备品牌  
 3   model   设备型号
 4   pixelRatio     设备像素比
 5   screenWidth    屏幕宽度,单位px  
 6   screenHeight   屏幕高度,单位px  
 7   windowWidth    可使用窗口宽度,单位px
 8   windowHeight   可使用窗口高度,单位px
 9   statusBarHeight    状态栏的高度,单位px  
10   language   微信设置的语言
11   version    微信版本号
12   system     操作系统及版本
13   platform   客户端平台
14   fontSizeSetting    用户字体大小(单位px)。以微信客户端「我-设置-通用-字体大小」中的设置为准   
15   SDKVersion         客户端基础库版本  
16   benchmarkLevel     设备性能等级(仅Android小游戏)。取值为:-2 或 0(该设备无法运行小游戏),-1(性能未知),>=1(设备性能值,该值越高,设备性能越好,目前最高不到50)
17 */
18 Page({
19   onLoad: function (options) {
20     wx.getSystemInfo({
21       success(res) {
22         console.log(\'设备品牌:\',res.brand)
23         console.log(\'设备型号:\',res.model)
24         console.log(\'设备像素比:\',res.pixelRatio)
25         console.log(\'屏幕宽度:\',res.windowWidth)
26         console.log(\'屏幕高度:\',res.windowHeight)
27         console.log(\'状态栏的高度:\', res.statusBarHeight)
28         console.log(\'微信设置的语言:\',res.language)
29         console.log(\'微信版本号:\',res.version)
30         console.log(\'操作系统及版本:\', res.system)
31         console.log(\'客户端平台:\',res.platform)
32         console.log(\'用户字体大小:\', res.fontSizeSetting)
33         console.log(\'客户端基础库版本 :\', res.SDKVersion)
34         console.log(\'设备性能等级:\', res.benchmarkLevel)
35       }
36     }) 
37   }
38 })

打印结果:

 

设备品牌: devtools

设备型号: iPhone 6

设备像素比: 2

屏幕宽度: 375

屏幕高度: 603

状态栏的高度: 20

微信设置的语言: zh

微信版本号: 6.6.3

操作系统及版本: iOS 10.0.1

客户端平台: devtools

用户字体大小: 16

客户端基础库版本 : 2.4.3

设备性能等级: undefined

————————————————

wx.getSystemInfoSync()

同步获取系统信息

返回值:在这里插入图片描述

例如:
写法一
index.js

 1 /*
 2   brand   设备品牌  
 3   model   设备型号
 4   pixelRatio     设备像素比
 5   screenWidth    屏幕宽度,单位px  
 6   screenHeight   屏幕高度,单位px  
 7   windowWidth    可使用窗口宽度,单位px
 8   windowHeight   可使用窗口高度,单位px
 9   statusBarHeight    状态栏的高度,单位px  
10   language   微信设置的语言
11   version    微信版本号
12   system     操作系统及版本
13   platform   客户端平台
14   fontSizeSetting    用户字体大小(单位px)。以微信客户端「我-设置-通用-字体大小」中的设置为准   
15   SDKVersion         客户端基础库版本  
16   benchmarkLevel     设备性能等级(仅Android小游戏)。取值为:-2 或 0(该设备无法运行小游戏),-1(性能未知),>=1(设备性能值,该值越高,设备性能越好,目前最高不到50)
17 */
18 Page({
19   onLoad: function (options) {
20     const res = wx.getSystemInfoSync()
21     console.log(\'设备品牌:\', res.brand)
22     console.log(\'设备型号:\', res.model)
23     console.log(\'设备像素比:\', res.pixelRatio)
24     console.log(\'屏幕宽度:\', res.windowWidth)
25     console.log(\'屏幕高度:\', res.windowHeight)
26     console.log(\'状态栏的高度:\', res.statusBarHeight)
27     console.log(\'微信设置的语言:\', res.language)
28     console.log(\'微信版本号:\', res.version)
29     console.log(\'操作系统及版本:\', res.system)
30     console.log(\'客户端平台:\', res.platform)
31     console.log(\'用户字体大小:\', res.fontSizeSetting)
32     console.log(\'客户端基础库版本 :\', res.SDKVersion)
33     console.log(\'设备性能等级:\', res.benchmarkLevel)
34   }
35 })

打印结果:

 

设备品牌: devtools

设备型号: iPhone 6

设备像素比: 2

屏幕宽度: 375

屏幕高度: 603

状态栏的高度: 20

微信设置的语言: zh

微信版本号: 6.6.3

操作系统及版本: iOS 10.0.1

客户端平台: devtools

用户字体大小: 16

客户端基础库版本 : 2.4.3

设备性能等级: undefined

 

写法二

index.js

 1 try {
 2       const res = wx.getSystemInfoSync()
 3       console.log(\'设备品牌:\', res.brand)
 4       console.log(\'设备型号:\', res.model)
 5       console.log(\'设备像素比:\', res.pixelRatio)
 6       console.log(\'屏幕宽度:\', res.windowWidth)
 7       console.log(\'屏幕高度:\', res.windowHeight)
 8       console.log(\'状态栏的高度:\', res.statusBarHeight)
 9       console.log(\'微信设置的语言:\', res.language)
10       console.log(\'微信版本号:\', res.version)
11       console.log(\'操作系统及版本:\', res.system)
12       console.log(\'客户端平台:\', res.platform)
13       console.log(\'用户字体大小:\', res.fontSizeSetting)
14       console.log(\'客户端基础库版本 :\', res.SDKVersion)
15       console.log(\'设备性能等级:\', res.benchmarkLevel)
16     } catch (e) {
17 
18     } finally {
19       console.log(\'=============\')
20     }

打印结果:

 

设备品牌: devtools

设备型号: iPhone 6

设备像素比: 2

屏幕宽度: 375

屏幕高度: 603

状态栏的高度: 20

微信设置的语言: zh

微信版本号: 6.6.3

操作系统及版本: iOS 10.0.1

客户端平台: devtools

用户字体大小: 16

客户端基础库版本 : 2.4.3

设备性能等级: undefined

=============

————————————————

原文链接:https://blog.csdn.net/jackjia2015/article/details/86533678



分类:

技术点:

相关文章:

  • 2021-08-13
  • 2021-11-28
  • 2021-12-04
  • 2021-10-28
  • 2021-05-17
  • 2022-03-01
  • 2021-09-29
猜你喜欢
  • 2021-12-13
  • 2022-01-07
  • 2021-08-31
  • 2022-12-23
  • 2021-12-29
  • 2021-12-13
相关资源
相似解决方案