123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- module.exports = {
- addWifiDevice: addWifiDevice,
- updateDeviceList: updateDeviceList,
- }
- // 新添加Wifi设备 猫王小王子OTR-X
- // [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online"}]
- function addWifiDevice(device, deviceList) {
- // 同一个设备处理
- var tempList = deviceList.filter((v) => v.deviceId === device.deviceId);
- const strings = require('../strings');
- if (!strings.isEmpty(tempList)) {
- deviceList = deviceList.filter((v) => v.deviceId !== device.deviceId);
- }
- /// 添加到第一个
- deviceList.unshift({
- connectType: 3,
- devName: "",
- state: "online",
- name: device.deviceId,
- deviceId: device.deviceId,
- mac: device.deviceId,
- image: "./../../img/min.png",
- });
- return deviceList;
- };
- ///更新列表排序
- function updateDeviceList(deviceList, isInit, closeAllBlue) {
- const strings = require('../strings');
- if (strings.isEmpty(deviceList)) {
- return [];
- }
- const app = getApp();
- var finalList = [];
- if (isInit) {
- deviceList[0].state = "offline";
- }
- /// 让所有蓝牙设备离线
- if (closeAllBlue) {
- deviceList.forEach(element => {
- if (element.connectType != 3) {
- element.state = "offline";
- }
- });
- }
- ///挑选出第一个在线设备
- var isFirstOnline = false;
- if (deviceList[0].state == "online") {
- isFirstOnline = true;
- finalList.push(deviceList[0]);
- }
- ///区分在线和离线
- for (var i = isFirstOnline ? 1 : 0; i < deviceList.length; i++) {
- if (isInit) {
- deviceList[i].state = "offline";
- }
- }
- var onLineList = [];
- var onNoLineList = [];
- ///添加在线的
- for (var i = isFirstOnline ? 1 : 0; i < deviceList.length; i++) {
- var device = deviceList[i];
- if (device.state == "online") {
- onLineList.push(device)
- }
- }
- ///添加离线的
- for (var i = isFirstOnline ? 1 : 0; i < deviceList.length; i++) {
- var device = deviceList[i];
- if (device.state != "online") {
- onNoLineList.push(device)
- }
- }
- // 区分在线wifi和蓝牙 wifi在前 离线在后
- var onLineWifiList = [];
- var onLineBlueList = [];
- ///添加在线wifi
- onLineList.forEach(element => {
- if (element.connectType == 3) {
- onLineWifiList.push(element);
- }
- });
- ///添加在线蓝牙
- onLineList.forEach(element => {
- if (element.connectType != 3) {
- onLineBlueList.push(element)
- }
- });
- finalList = finalList.concat(onLineWifiList);
- finalList = finalList.concat(onLineBlueList);
- ///只需要蓝牙和wifi在线的
- var mDeviceList = []
- mDeviceList = mDeviceList.concat(onLineWifiList);
- mDeviceList = mDeviceList.concat(onLineBlueList);
- app.globalData.mDeviceList = mDeviceList;
- ///区分离线wifi和蓝牙 wifi在前 离线在后
- var onNoLineWifiList = [];
- var onNoLineBlueList = [];
- ///添加离线wifi
- onNoLineList.forEach(element => {
- if (element.connectType == 3) {
- onNoLineWifiList.push(element)
- }
- });
- ///添加离线蓝牙
- onNoLineList.forEach(element => {
- if (element.connectType != 3) {
- onNoLineBlueList.push(element)
- }
- });
- finalList = finalList.concat(onNoLineWifiList);
- finalList = finalList.concat(onNoLineBlueList);
- return finalList;
- };
|