123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- const app = getApp();
- import strings from '../../../utils/strings.js';
- import routeUtil from '../../../utils/routeUtil.js';
- import routeRoot from '../../../utils/routeRoot.js'
- const {
- BleUtil
- } = require('../../../utils/blue_ble/util');
- let percentIn = null;
- ///君正方案
- Page({
- data: {
- nvabarData: {
- showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
- title: '连接配网', //导航栏 中间的标题
- },
- scopeBluetooth: app.globalData.scopeBluetooth,
- ssid: app.globalData.ssid,
- password: app.globalData.pwdData,
- version: '2.0',
- name: '',
- connectedDeviceId: '',
- connected: true,
- deviceInfo: null,
- isInitOK: false,
- customData: '',
- percent: 0,
- ruterStatus: 0, // 0 连接中 // 1 成功 // 2失败
- imageUrl: "./../../../img/g.png",
- },
- onLoad: function (options) {
- var that = this;
- var param = options.param;
- if (!strings.isEmpty(param)) {
- param = JSON.parse(param);
- that.setData({
- imageUrl: param.img,
- });
- }
- // AIrSMArT_861210052356337===D0:31:10:86:AC:9A
- /// 纯蓝牙:MW_BLE CC:90:DD:88:C7:E8
- var name = options.name;
- var deviceId = options.deviceId;
- that.setData({
- name: name,
- connectedDeviceId: deviceId,
- });
- var device = {
- "mac": name,
- "deviceId": deviceId
- };
- // var device = {
- // "mac": "MW_BLE",
- // "deviceId": "CC:90:DD:88:C7:E8"
- // };
- percentIn = setInterval(() => {
- if (that.data.percent === 100) {
- clearInterval(percentIn);
- ///失败
- that.setData({
- ruterStatus: 2
- });
- return;
- };
- that.data.percent++;
- that.setData({
- percent: that.data.percent
- });
- }, 600);
- BleUtil.getInstance().startConnect(device, function (changed) {
- if (changed) {
- BleUtil.getInstance().sendData(device, app.globalData.ssid, app.globalData.pwdData);
- } else {
- that.setData({
- ruterStatus: 2
- });
- clearInterval(percentIn);
- }
- }, function (connected) {
- var deviceId = that.data.name;
- var device = {
- connectType: 3,
- devName: "",
- state: "online",
- name: deviceId,
- deviceId: deviceId,
- mac: deviceId,
- imageUrl: that.data.imageUrl,
- }
- getCurrentPages()[0].addWifiDevice(device);
- // [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online"}]
- // 记住密码
- wx.setStorage({
- key: "wifiInfo",
- data: JSON.stringify({
- "password": app.globalData.pwdData,
- "ssid": app.globalData.ssid
- }),
- });
- setTimeout(() => {
- if (percentIn != null) {
- clearInterval(percentIn);
- that.setData({
- percent: 100,
- ruterStatus: 1,
- });
- }
- }, 1000);
- });
- },
- egen() {
- wx.navigateBack({
- delta: 1
- })
- },
- goIndex() {
- routeUtil.goBackRoute(routeRoot.index);
- },
- })
|