ibeacon.js 990 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. Page({
  2. onShareAppMessage() {
  3. return {
  4. title: 'iBeacon',
  5. path: 'packageAPI/pages/device/ibeacon/ibeacon'
  6. }
  7. },
  8. data: {
  9. theme: 'light',
  10. uuid: '',
  11. beacons: []
  12. },
  13. onUnload() {
  14. this.stopSearch()
  15. },
  16. enterUuid(e) {
  17. this.setData({
  18. uuid: e.detail.value
  19. })
  20. },
  21. startSearch() {
  22. if (this._searching) return
  23. this._searching = true
  24. wx.startBeaconDiscovery({
  25. uuids: [this.data.uuid],
  26. success: (res) => {
  27. console.log(res)
  28. wx.onBeaconUpdate(({beacons}) => {
  29. this.setData({
  30. beacons
  31. })
  32. })
  33. },
  34. fail: (err) => {
  35. console.error(err)
  36. }
  37. })
  38. },
  39. stopSearch() {
  40. this._searching = false
  41. wx.stopBeaconDiscovery()
  42. },
  43. onLoad() {
  44. this.setData({
  45. theme: wx.getSystemInfoSync().theme || 'light'
  46. })
  47. if (wx.onThemeChange) {
  48. wx.onThemeChange(({theme}) => {
  49. this.setData({theme})
  50. })
  51. }
  52. }
  53. })