|
@@ -6,23 +6,16 @@ module.exports = {
|
|
|
|
|
|
// 新添加Wifi设备 猫王小王子OTR-X
|
|
// 新添加Wifi设备 猫王小王子OTR-X
|
|
// [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online"}]
|
|
// [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online"}]
|
|
-function addWifiDevice(device, deviceList) {
|
|
|
|
|
|
+function addWifiDevice(device) {
|
|
// 同一个设备处理
|
|
// 同一个设备处理
|
|
|
|
+ var deviceList = getCurrentPages()[0].getDeviceList();
|
|
var tempList = deviceList.filter((v) => v.deviceId === device.deviceId);
|
|
var tempList = deviceList.filter((v) => v.deviceId === device.deviceId);
|
|
const strings = require('../strings');
|
|
const strings = require('../strings');
|
|
if (!strings.isEmpty(tempList)) {
|
|
if (!strings.isEmpty(tempList)) {
|
|
deviceList = deviceList.filter((v) => v.deviceId !== device.deviceId);
|
|
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",
|
|
|
|
- });
|
|
|
|
|
|
+ deviceList.unshift(device);
|
|
return deviceList;
|
|
return deviceList;
|
|
};
|
|
};
|
|
|
|
|
|
@@ -31,14 +24,14 @@ function addWifiDevice(device, deviceList) {
|
|
/// clientType 连接方式:bt-0,ble-1,upnp-2,mqtt-3
|
|
/// clientType 连接方式:bt-0,ble-1,upnp-2,mqtt-3
|
|
// [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online","ProdModel":"MW-2AX(WIFI-N)","devName":"猫王小王子OTR-X"}]
|
|
// [{"deviceId":"BLUFI_7cdfa1fcbb24","name":"BLUFI_7cdfa1fcbb24","state":"online","ProdModel":"MW-2AX(WIFI-N)","devName":"猫王小王子OTR-X"}]
|
|
///新添加蓝牙设备
|
|
///新添加蓝牙设备
|
|
-function addBlueDevice(device, deviceList) {
|
|
|
|
|
|
+function addBlueDevice(device) {
|
|
// 同一个设备处理
|
|
// 同一个设备处理
|
|
|
|
+ var deviceList = getCurrentPages()[0].getDeviceList();
|
|
var tempList = deviceList.filter((v) => v.deviceId === device.deviceId);
|
|
var tempList = deviceList.filter((v) => v.deviceId === device.deviceId);
|
|
const strings = require('../strings');
|
|
const strings = require('../strings');
|
|
if (!strings.isEmpty(tempList)) {
|
|
if (!strings.isEmpty(tempList)) {
|
|
deviceList = deviceList.filter((v) => v.deviceId !== device.deviceId);
|
|
deviceList = deviceList.filter((v) => v.deviceId !== device.deviceId);
|
|
}
|
|
}
|
|
-
|
|
|
|
/// 添加到第一个
|
|
/// 添加到第一个
|
|
deviceList.unshift({
|
|
deviceList.unshift({
|
|
connectType: 1,
|
|
connectType: 1,
|
|
@@ -55,22 +48,21 @@ function addBlueDevice(device, deviceList) {
|
|
};
|
|
};
|
|
|
|
|
|
///更新列表排序
|
|
///更新列表排序
|
|
-function updateDeviceList(deviceList, isInit, closeAllBlue) {
|
|
|
|
|
|
+function updateDeviceList(list, isInit, closeAllBlue) {
|
|
const strings = require('../strings');
|
|
const strings = require('../strings');
|
|
- if (strings.isEmpty(deviceList)) {
|
|
|
|
|
|
+ if (strings.isEmpty(list)) {
|
|
return [];
|
|
return [];
|
|
}
|
|
}
|
|
|
|
|
|
const app = getApp();
|
|
const app = getApp();
|
|
-
|
|
|
|
var finalList = [];
|
|
var finalList = [];
|
|
if (isInit) {
|
|
if (isInit) {
|
|
- deviceList[0].state = "offline";
|
|
|
|
|
|
+ list[0].state = "offline";
|
|
}
|
|
}
|
|
|
|
|
|
/// 让所有蓝牙设备离线
|
|
/// 让所有蓝牙设备离线
|
|
if (closeAllBlue) {
|
|
if (closeAllBlue) {
|
|
- deviceList.forEach(element => {
|
|
|
|
|
|
+ list.forEach(element => {
|
|
if (element.connectType != 3) {
|
|
if (element.connectType != 3) {
|
|
element.state = "offline";
|
|
element.state = "offline";
|
|
}
|
|
}
|
|
@@ -79,15 +71,15 @@ function updateDeviceList(deviceList, isInit, closeAllBlue) {
|
|
|
|
|
|
///挑选出第一个在线设备
|
|
///挑选出第一个在线设备
|
|
var isFirstOnline = false;
|
|
var isFirstOnline = false;
|
|
- if (deviceList[0].state == "online") {
|
|
|
|
|
|
+ if (list[0].state == "online") {
|
|
isFirstOnline = true;
|
|
isFirstOnline = true;
|
|
- finalList.push(deviceList[0]);
|
|
|
|
|
|
+ finalList.push(list[0]);
|
|
}
|
|
}
|
|
|
|
|
|
///区分在线和离线
|
|
///区分在线和离线
|
|
- for (var i = isFirstOnline ? 1 : 0; i < deviceList.length; i++) {
|
|
|
|
|
|
+ for (var i = isFirstOnline ? 1 : 0; i < list.length; i++) {
|
|
if (isInit) {
|
|
if (isInit) {
|
|
- deviceList[i].state = "offline";
|
|
|
|
|
|
+ list[i].state = "offline";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -95,16 +87,16 @@ function updateDeviceList(deviceList, isInit, closeAllBlue) {
|
|
var onNoLineList = [];
|
|
var onNoLineList = [];
|
|
|
|
|
|
///添加在线的
|
|
///添加在线的
|
|
- for (var i = isFirstOnline ? 1 : 0; i < deviceList.length; i++) {
|
|
|
|
- var device = deviceList[i];
|
|
|
|
|
|
+ for (var i = isFirstOnline ? 1 : 0; i < list.length; i++) {
|
|
|
|
+ var device = list[i];
|
|
if (device.state == "online") {
|
|
if (device.state == "online") {
|
|
onLineList.push(device)
|
|
onLineList.push(device)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
///添加离线的
|
|
///添加离线的
|
|
- for (var i = isFirstOnline ? 1 : 0; i < deviceList.length; i++) {
|
|
|
|
- var device = deviceList[i];
|
|
|
|
|
|
+ for (var i = isFirstOnline ? 1 : 0; i < list.length; i++) {
|
|
|
|
+ var device = list[i];
|
|
if (device.state != "online") {
|
|
if (device.state != "online") {
|
|
onNoLineList.push(device)
|
|
onNoLineList.push(device)
|
|
}
|
|
}
|