123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- // pages/search/search.js
- const tqlSDK = getApp().globalData.tqlSDK
- const app = getApp()
- import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast'
- const event = require('../../tqlsdk/event')
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- blueToothList: [],
- refreshFlag: false,
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.searchBlueTooth();
- event.remove('foundDevices')
- event.on('foundDevices', this, data => {
- this.setData({
- blueToothList: data
- })
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- // 搜索附近的蓝牙
- searchBlueTooth() {
- tqlSDK.searchBlueTooth(this.blueToothList)
- },
- // 查找到的设备列表
- blueToothList() {
- tqlSDK.showBlueToothList(this)
- },
- // 连接蓝牙
- connectBlueTooth(e) {
- Toast.clear()
- Toast.loading({
- message: '正在连接',
- forbidClick: true,
- duration: 0
- })
- tqlSDK.stopBlueToothSearch(() => {})
- console.log(e)
- let deviceId = e.currentTarget.dataset.deviceid
- let penName = e.currentTarget.dataset.devicename
- let mac = e.currentTarget.dataset.mac
- setTimeout(() => {
- tqlSDK.createBlueToothConnection(deviceId, () => {
- app.globalData.deviceId = deviceId
- app.globalData.deviceName = penName
- app.globalData.deviceMac = mac
- // event.emit('blueToothConnect', true)
- this.getBlueToothService(deviceId)
- }, () => {
- Toast.clear()
- })
- }, 1000)
- },
- // 获取蓝牙设备服务
- getBlueToothService(deviceId) {
- tqlSDK.getBlueToothService(deviceId, () => {
- setTimeout(() => {
- Toast.clear();
- Toast.success({
- message: "连接成功",
- duration: 2500,
- onClose: () => {
- wx.navigateBack({
- delta: 0,
- success: () => {
- // setTimeout(() => {
- tqlSDK.getPenOfflineDataSize()
- // },100)
- }
- })
- }
- })
- }, 500);
- })
- },
- //刷新列表
- refreshList() {
- setTimeout(() => {
- this.setData({
- refreshFlag: false
- })
- tqlSDK.allDevices.foundDevices = [];
- this.searchBlueTooth();
- }, 1500)
- }
- })
|