blueDemos.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // pages/blueDemos/blueDemos.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. },
  8. onLoad(options) {
  9. console.log("gadsfadfqwerqr====00==");
  10. wx.getSetting({
  11. success(res) {
  12. console.log("gadsfadfqwerqr====00==" + JSON.stringify(res));
  13. if (res.authSetting['scope.userInfo']) {
  14. // 已经授权,可以直接调用 getUserInfo 获取头像昵称
  15. wx.getUserInfo({
  16. success: function (res) {
  17. console.log("获取用户信息成功", res.userInfo)
  18. }
  19. })
  20. } else {
  21. // 否则,先通过 wx.createUserInfoButton 接口发起授权
  22. let button = wx.createUserInfoButton({
  23. type: 'text',
  24. text: '获取用户信息',
  25. style: {
  26. left: 10,
  27. top: 160,
  28. width: 200,
  29. height: 40,
  30. lineHeight: 40,
  31. backgroundColor: '#ff0000',
  32. color: '#ffffff',
  33. textAlign: 'center',
  34. fontSize: 16,
  35. borderRadius: 4
  36. }
  37. })
  38. button.onTap((res) => {
  39. console.log(res)
  40. })
  41. }
  42. },
  43. fail(err) {
  44. console.log("gadsfadfqwerqr====11==" + JSON.stringify(err));
  45. console.log("获取用户信息失败", err)
  46. }
  47. });
  48. ///获取定位权限
  49. wx.authorize({
  50. scope: 'scope.userFuzzyLocation',
  51. success(res) {
  52. console.log("gadsfadfqwerqr====22==" + JSON.stringify(res));
  53. },
  54. fail(err) {
  55. console.log("gadsfadfqwerqr====333==" + JSON.stringify(err));
  56. }
  57. });
  58. ///获取蓝牙权限
  59. wx.authorize({
  60. scope: 'scope.bluetooth',
  61. success(res) {
  62. console.log("gadsfadfqwerqr====444==" + JSON.stringify(res));
  63. },
  64. fail(err) {
  65. console.log("gadsfadfqwerqr====555==" + JSON.stringify(err));
  66. }
  67. });
  68. },
  69. /**
  70. * 生命周期函数--监听页面初次渲染完成
  71. */
  72. onReady() {
  73. },
  74. /**
  75. * 生命周期函数--监听页面显示
  76. */
  77. onShow() {
  78. },
  79. /**
  80. * 生命周期函数--监听页面隐藏
  81. */
  82. onHide() {
  83. },
  84. /**
  85. * 生命周期函数--监听页面卸载
  86. */
  87. onUnload() {
  88. },
  89. /**
  90. * 页面相关事件处理函数--监听用户下拉动作
  91. */
  92. onPullDownRefresh() {
  93. },
  94. /**
  95. * 页面上拉触底事件的处理函数
  96. */
  97. onReachBottom() {
  98. },
  99. /**
  100. * 用户点击右上角分享
  101. */
  102. onShareAppMessage() {
  103. }
  104. })