houjie 4 лет назад
Родитель
Сommit
084fd3c5b3

+ 2 - 1
API/Constant.js

@@ -5,5 +5,6 @@ export let BASEURL = '';
 if(process.env.NODE_ENV === 'development'){ // 开发环境
   BASEURL = 'https://test.ohplay.radio1964.net/';
 }else{ // 生产
-  BASEURL = 'https://ohplay.radio1964.net/';
+  // BASEURL = 'https://ohplay.radio1964.net/';
+  BASEURL = 'https://test.ohplay.radio1964.net/';
 };

+ 238 - 0
Lib/BleConfigNet.js

@@ -0,0 +1,238 @@
+const server_uuid = "0000FFE5-0000-1000-8000-00805F9B34FB";
+
+let callback = null
+
+let connecting = false
+
+let connected = false
+
+let deviceId = null
+
+let configTimeout = null
+
+let iccid = ''
+
+/**
+ * 连接ble设备
+ * @param {string} mac 设备mac地址
+ * @param {function} cb 连接的回调
+ */
+function connectBle(mac, cb) {
+    if (!connecting && !connected) {
+        deviceId = mac
+        connecting = true
+        callback = cb
+        iccid = ''
+        uni.createBLEConnection({
+            deviceId,
+            success(res) {
+                console.log('ble连接成功')
+                //console.log(res)
+                connected = true
+                connecting = false
+
+                //获取服务
+                getBleDeviceServices()
+            },
+            fail(err) {
+                console.log(`ble连接失败 code :${err.errCode}`)
+                connecting = false
+                connected = false
+                callback(err)
+                //errorText = '连接失败!请将手机靠近设备'
+            }
+        })
+    }
+}
+
+/**
+ * 获取ble的特征
+ * @param {string} deviceId 设备mac地址
+ */
+function getBleDeviceServices() {
+    setTimeout(() => {
+        uni.getBLEDeviceServices({
+            deviceId,
+            success(res) {
+                console.log('ble获取服务成功')
+                for (let service of res.services) {
+                    //console.log(service)
+                    if (server_uuid.toUpperCase() == service.uuid.toUpperCase()) {
+
+                        //获取特征
+                        getBLEDeviceCharacteristics()
+                        return
+                    }
+                }
+            },
+            fail(err) {
+                console.log(`ble获取服务失败 code :${err.errCode}`)
+                closeBLEConnection()
+                callback(err)
+            }
+        })
+    }, 1000)
+}
+
+/**
+ * 获取特征
+ */
+function getBLEDeviceCharacteristics() {
+    //setTimeout(() => {
+    uni.getBLEDeviceCharacteristics({
+        deviceId,
+        serviceId: server_uuid,
+        success(res) {
+            console.log('ble获取特征成功');
+
+            notifyBLECharacteristicValueChange(res.characteristics[0].uuid)
+        },
+        fail(err) {
+            console.log(`获取特征失败 code :${err.errCode}`);
+            //console.log(err);
+            closeBLEConnection()
+            callback(err)
+
+        }
+    })
+    //}, 1000)
+}
+
+/**
+ * 监听设备发送过来的数据
+ * @param {string} characteristicId 特征的uuid
+ */
+function notifyBLECharacteristicValueChange(characteristicId) {
+    setTimeout(() => {
+        //设置一个超时配网的时间
+        configTimeout = setTimeout(() => {
+            closeBLEConnection()
+            if (callback) {
+                callback({ errCode: -100 })
+            }
+        }, 20 * 1000)
+
+        uni.notifyBLECharacteristicValueChange({
+            state: true,
+            deviceId,
+            serviceId: server_uuid,
+            characteristicId: characteristicId,
+        })
+
+        //监听设备发送过来的数据
+        uni.onBLECharacteristicValueChange(function (res) {
+            let buf = Buffer.from(res.value);
+            let receiveStr = buf.toString()
+            console.log(`收到数据:${receiveStr}`);
+            if (receiveStr === 'connect_success') {
+                //配网成功
+                closeBLEConnection()
+                if (callback && iccid && iccid.length > 0) {
+                    callback({ errCode: 0, iccid })
+                }
+            } else if (receiveStr.indexOf('failure') >= 0) {
+                //'配网失败'
+                closeBLEConnection()
+                if (callback) {
+                    callback({ errCode: -101 })
+                }
+            } else if (receiveStr.indexOf('ic0:') >= 0) { //用来获取iccid的
+                iccid = receiveStr.substring(4, receiveStr.length);
+            } else if (receiveStr.indexOf('ic1:') >= 0) { //用来获取iccid的 把ic0 和ic1拼接起来
+                let ic1 = receiveStr.substring(4, receiveStr.length);
+                iccid = iccid + ic1;
+                //发送4G配网指令
+                let buf = Buffer.from('without_WiFi')
+                setTimeout(() => { sendCongifCmd(characteristicId, buf.buffer) }, 800)
+            } else if (receiveStr.indexOf('start_network') >= 0) {
+                //发送	AIrSMArT_CLOSE指令	
+                setTimeout(() => {
+                    let buf = Buffer.from('AIrSMArT_CLOSE')
+                    sendCongifCmd(characteristicId, buf.buffer)
+                }, 2000)
+            }
+            else if (receiveStr.indexOf('recv_finish') >= 0) {
+                //todo 设备这里流程没有统一,目前唯一的设备MW-V是收到recv_finish就配网结束了
+                setTimeout(() => {
+                    closeBLEConnection()
+                    if (callback && iccid && iccid.length > 0) {
+                        callback({ errCode: 0, iccid })
+                    }
+                }, 1000)
+            } else if (receiveStr.indexOf('without_WiFi_OK') >= 0) {
+                //配网成功
+                closeBLEConnection()
+                if (callback && iccid && iccid.length > 0) {
+                    callback({ errCode: 0, iccid })
+                }
+            }
+        })
+
+        //发送get_iccid数据给设备
+        setTimeout(() => {
+            //获取iccid
+            let buf = Buffer.from('get_iccid')
+            let buffer = buf.buffer
+            sendCongifCmd(characteristicId, buffer)
+        }, 800)
+    }, 1000)
+}
+
+/**
+ * 发送数据给设备
+ * @param {string} characteristicId 特征uuid
+ * @param {ArrayBuffer} buffer 发送的数据
+ */
+function sendCongifCmd(characteristicId, buffer) {
+    let count = Math.ceil(buffer.byteLength / 20)
+    //拆分成的ArrayBuffer数组,每个ArrayBuffer不超过20个字节
+    let buffers = []
+    for (var i = 0; i < count; i++) {
+        let size = Math.min(20, buffer.byteLength - i * 20)
+        let buf = buffer.slice(i * 20, size + i * 20)
+        buffers.push(buf)
+    }
+
+    //返回的是一个promise对象
+    function sendData(buffer) {
+        return uni.writeBLECharacteristicValue({
+            deviceId,
+            serviceId: server_uuid,
+            characteristicId,
+            value: buffer,
+        })
+    };
+
+    (async () => {
+        for (let b of buffers) {
+            let res = await sendData(b)
+            //console.log(res);
+            console.log(`发送的数据为:${Buffer.from(b)} errorCode: ${res[res.length - 1].errCode}`);
+        }
+        // let promises = buffers.map((b) => sendData(b))
+        // let res  = await Promise.all(promises)
+    })();
+}
+
+/**
+ * 关闭ble连接
+ */
+function closeBLEConnection() {
+    if (deviceId) {
+        uni.closeBLEConnection({
+            deviceId,
+            success(res) {
+                console.log('ble关闭连接成功');
+            },
+            fail(err) {
+                console.log(`ble关闭连接失败  code :${err.errCode}`);
+            }
+        })
+        //clearInterval(withoutWifiInterval)
+        clearTimeout(configTimeout)
+        connected = false
+    }
+}
+
+
+module.exports = { closeBLEConnection, connectBle };

+ 1 - 1
Lib/Request.js

@@ -144,7 +144,7 @@ function gotoLoginPage(){
 
 const defaultHeader = {
 	"X-Requested-With": "XMLHttpRequest",
-	"Content-Type": "application/x-protobuf",
+	"Content-Type": "application/json",
 }
 
 // 拦截器

+ 110 - 0
components/battery/battery.vue

@@ -0,0 +1,110 @@
+<template>
+  <view class="battery">
+    <view v-if="isCharging" class="bgc charg" ></view>
+    <view v-if="!isCharging" class="bgc" :style="{height: height,background:color}" ></view>
+    <image :src="icon" class="img"></image>
+  </view>
+</template>
+
+<script>
+
+export default {
+  props: {
+    battery:{
+      type:Number,
+      default:100
+    }
+
+  },
+  data: () => ({
+    // height:'30%',
+	  // color:'#85D1A9'
+  }),
+  computed: {
+    isCharging(){
+      return (this.battery > 100)
+    },
+
+    height(){
+      if(this.battery > 100 || this.battery<0){
+        return '0%'
+      }
+      return (this.battery*0.7)+'%'
+    },
+    color(){
+      if(this.battery > 20){
+        return '#85D1A9'
+      }else{
+        return '#C00000'
+      }
+    },
+    icon(){
+      if(this.battery > 100){
+        return '../../static/common/battery_charg.svg'
+      }else{
+        return '../../static/common/battery.svg'
+      }
+    }
+  },
+  methods: {},
+  watch: {},
+  
+  // 组件周期函数--监听组件挂载完毕
+  mounted() {
+  },
+  
+  // 组件周期函数--监听组件激活(显示)
+  activated() {},
+  // 组件周期函数--监听组件停用(隐藏)
+  deactivated() {},
+  // 组件周期函数--监听组件销毁之前
+  beforeDestroy() {},
+};
+</script>
+
+<style>
+.battery{
+  width: 13rpx;
+  height: 45rpx;
+  position: relative;
+  display: flex;
+  flex-direction: column;
+  justify-content: flex-end;
+  
+  
+}
+
+.img{
+  /* transform: translateY(-100%); */
+  width: 13rpx;
+  height: 45rpx;
+  position:absolute;
+  top: 0;
+
+  
+}
+
+.bgc{
+  width: 4rpx;
+  /* height: 70%; */
+  margin-left: auto;
+  margin-right: auto;
+  margin-bottom: 7rpx;
+  
+	background: #85D1A9;
+}
+
+.charg{
+  animation: charging 1500ms linear infinite;
+}
+
+@keyframes charging
+{
+	0%   {height: 0%;}
+	25%   {height: 17%;}
+	50%   {height: 35%;}
+	75%   {height: 53%;}
+	100%  {height: 70%;}
+}
+
+</style>

+ 83 - 0
components/btAlert/btAlert.vue

@@ -0,0 +1,83 @@
+<template>
+  <view class="bt-alert"> 
+    <view class="box">
+      <image class="img1" src="https://airsmart-photo1.oss-cn-shanghai.aliyuncs.com/wx/ic_bluetooth_permission.png" mode="aspectFit"/>
+      <text class="text1">蓝牙权限</text>
+      <text class="text2">请开启手机蓝牙功能进行连接</text>
+    </view>
+    <image class="ic-close" src="../../static/common/ic_close.svg" mode="aspectFit" @click.self="close"/>
+  </view>
+</template>
+
+<script>
+export default {
+  props: {},
+  data: () => ({}),
+  computed: {},
+  methods: {
+    close(){
+      this.$emit('close')
+    }
+  },
+  watch: {},
+
+  // 组件周期函数--监听组件挂载完毕
+  mounted() {},
+
+  // 组件周期函数--监听组件激活(显示)
+  activated() {},
+  // 组件周期函数--监听组件停用(隐藏)
+  deactivated() {},
+  // 组件周期函数--监听组件销毁之前
+  beforeDestroy() {},
+};
+</script>
+
+<style>
+.bt-alert {
+  position: fixed;
+  top: 0;
+  left: 0;
+  right: 0;
+  bottom: 0;
+  z-index: 999;
+  background: rgba(0, 0, 0, 0.6);
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+}
+.box {
+  margin-top: 14vh;
+  width: 69.33vw;
+  height: 70.4vw;
+  border-radius: 16rpx;
+  background: white;
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+}
+.img1 {
+  width: 38.4vw;
+  height: 39.7vw;
+  margin-top: 50rpx;
+}
+.text1 {
+  margin-top: 30rpx;
+  font-size: 36rpx;
+  font-family: PingFangSC-Semibold, PingFang SC;
+  font-weight: 600;
+  color: #353535;
+}
+.text2 {
+  margin-top: 10rpx;
+  font-size: 30rpx;
+  font-family: PingFangSC-Regular, PingFang SC;
+  font-weight: 400;
+  color: #999999;
+}
+.ic-close{
+  margin-top: 20rpx;
+  width: 88rpx;
+  height: 88rpx;
+}
+</style>

+ 2 - 1
manifest.json

@@ -52,7 +52,8 @@
     "mp-weixin" : {
         "appid" : "wx08f94a3e90881910",
         "setting" : {
-            "urlCheck" : false
+            "urlCheck" : false,
+            "minified" : false
         },
         "usingComponents" : true
     },

+ 63 - 1
pages.json

@@ -45,7 +45,51 @@
 			}
 		
 		}
-	],
+	    ,{
+            "path" : "pages/addDevice/selectDevice/selectDevice",
+            "style" :                                                                                    
+            {
+                "navigationBarTitleText": "选择设备型号",
+                "enablePullDownRefresh": false
+            }
+        }
+		,{
+            "path" : "pages/addDevice/connectDevice/connectDevice",
+            "style" :                                                                                    
+            {
+                "navigationBarTitleText": "连接设备",
+                "enablePullDownRefresh": false
+            }
+        }
+        ,{
+            "path" : "pages/webview/webview",
+            "style" :                                                                                    
+            {
+                "navigationBarTitleText": "",
+                "enablePullDownRefresh": false
+            }
+            
+        }
+        
+        ,{
+            "path" : "pages/mine/device/deviceManager/deviceManager",
+            "style" :                                                                                    
+            {
+                "navigationBarTitleText": "",
+                "enablePullDownRefresh": false
+            }
+            
+        }
+        ,{
+            "path" : "pages/mine/device/deviceDetail/deviceDetail",
+            "style" :                                                                                    
+            {
+                "navigationBarTitleText": "",
+                "enablePullDownRefresh": false
+            }
+            
+        }
+    ],
 	"globalStyle": {
 		"navigationBarTextStyle": "black",
 		"navigationBarTitleText": "猫王妙播",
@@ -81,6 +125,24 @@
 			"current": 0,
 			"list": [
 				{
+					"name": "管理设备",
+					"path": "pages/mine/device/deviceManager/deviceManager"
+				},
+				{
+					"name": "webview",
+					"path": "pages/webview/webview",
+					"query": "path=help"
+				},
+				{
+					"name": "connectDevice",
+					"path": "pages/addDevice/connectDevice/connectDevice",
+					"query": "model=MW-M3&name=猫王·MW-M3"
+				},
+				{
+					"name": "device",
+					"path": "pages/addDevice/selectDevice/selectDevice"
+				},
+				{
 					"name": "mqtt",
 					"path": "pages/demo/mqtt/mqttDemo"
 				},

+ 374 - 0
pages/addDevice/connectDevice/connectDevice.vue

@@ -0,0 +1,374 @@
+<template>
+  <view class="content">
+    <image class="img" :src="productUrl" mode="aspectFit" />
+    <view class="hint mt1">
+      <image
+        class="img1"
+        :src="stateIcon"
+        mode="aspectFit"
+        v-if="showStateIcon"
+      />
+      <text class="text1">{{ hintText }}</text>
+    </view>
+    <view class="hint mt1" v-if="showLink">
+      <image
+        class="img2"
+        src="../../../static/common/ic_smile.svg"
+        mode="aspectFit"
+      />
+      <text class="text2">{{ productHint }}</text>
+    </view>
+    <view class="bottom content">
+      <button :loading="isloading" :class="buttonClass" @click="btnClick">
+        {{ buttonText }}
+      </button>
+    </view>
+    <bt-alert v-if="showAlert" @close="btAlertClose" />
+  </view>
+</template>
+
+<script>
+import BleConfigNet from "../../../Lib/BleConfigNet.js";
+import BtAlert from "../../../components/btAlert/btAlert.vue";
+export default {
+  components: { BtAlert },
+  data: () => ({
+    /** 产品型号*/
+    model: "MW-M3",
+    /** 产品名称 */
+    productName: "",
+    /** 是否显示界面上提示的icon*/
+    showStateIcon: true,
+    /** 界面上提示icon的图片*/
+    stateIcon: "../../../static/common/ic_green_success.svg",
+    /** 界面上提示文字内容*/
+    hintText: "正在扫描设备,请保持设备开机状态",
+    /** 是否显示如何连接设备的提示*/
+    showLink: true,
+    /** 按钮的name*/
+    btnName: "scan",
+    /** 是否显示蓝牙开关弹窗 */
+    showAlert: false,
+    /** 超时扫描的定时器*/
+    stopScanTimer: null,
+    /** 要连接的设备*/
+    device: null,
+  }),
+  computed: {
+    buttonText() {
+      if (this.btnName == "scaning") {
+        return "正在搜索设备...";
+      } else if (this.btnName == "rescan") {
+        return "重新搜索";
+      } else if (this.btnName == "connect") {
+        return "连接";
+      } else if (this.btnName == "reconnect") {
+        return "重新连接";
+      } else if (this.btnName == "finish") {
+        return "完成";
+      } else if (this.btnName == "connecting") {
+        return "正在连接...";
+      } else if (this.btnName == "scan") {
+        return "搜索";
+      } else {
+        return this.btnName;
+      }
+    },
+    buttonClass() {
+      if (this.btnName == "scaning" || this.btnName == "connecting") {
+        return "btn disabled";
+      } else if (this.btnName == "finish") {
+        return "btn finish";
+      } else {
+        return "btn";
+      }
+    },
+    productUrl() {
+      return `https://airsmart-photo1.oss-cn-shanghai.aliyuncs.com/wx/productModel/3X/${this.model}.png`;
+    },
+    productHint() {
+      return `如何连接${this.productName}设备?`;
+    },
+    isloading() {
+      return this.btnName == "scaning" || this.btnName == "connecting";
+    },
+  },
+  methods: {
+    //关闭弹窗
+    btAlertClose() {
+      this.showAlert = false;
+    },
+    /**
+     * 按钮点击事件
+     */
+    btnClick() {
+      if (this.btnName == "rescan" || this.btnName == "scan") {
+        //搜索
+        this.init();
+      } else if (this.btnName == "connect" || this.btnName == "reconnect") {
+        //连接
+        this.btnName = "connecting";
+        if (this.device) {
+          BleConfigNet.connectBle(this.device.mac, this.bleConfigNetCallback);
+        } else {
+          that.hintText = "沒有搜索到设备";
+          that.btnName = "rescan";
+          that.showStateIcon = false;
+          that.showLink = true;
+        }
+      } else if (this.btnName == "finish") {
+        //完成
+        if (this.device && this.device.uuid) {
+          //添加设备
+          this.$store.dispatch({
+            type: "moduleMqtt/addDevice",
+            clientId: `wx_${getApp().globalData.uid}`,
+            device: {
+              devName: this.productName,
+              uuid: this.device.uuid,
+            },
+          });
+          //返回上上一级页面
+          uni.navigateBack({
+            delta: 2,
+          });
+        } else {
+          uni.showToast({
+            title: "iccid获取失败",
+            icon: "none",
+          });
+        }
+      }
+    },
+    //初始化蓝牙
+    init() {
+      const that = this;
+      uni.openBluetoothAdapter({
+        success: (res) => {
+          console.log(`初始化蓝牙模块成功 ${res}`);
+          that.startBleScan();
+        },
+        fail: (error) => {
+          if (error.errCode === 10001) {
+            //在用户蓝牙开关未开启或者手机不支持蓝牙功能的情况下
+            this.showAlert = true;
+
+            //蓝牙状态监听
+            that.lisenBtState();
+          } else {
+            //其他错误
+            uni.showToast({
+              title: `查看手机蓝牙是否打开`,
+              icon: "none",
+            });
+            console.log(error);
+          }
+        },
+      });
+    },
+    //蓝牙开关的监听
+    lisenBtState() {
+      //监听蓝牙是否打开
+      let that = this;
+      uni.onBluetoothAdapterStateChange(function (res) {
+        console.log(
+          `onBluetoothAdapterStateChange available = ${res.available}`
+        );
+        //console.log(res);
+        if (res.available) {
+          //蓝牙已打开
+          //开始扫描设备
+          that.startBleScan();
+        }
+      });
+    },
+    //扫描蓝牙设备
+    startBleScan() {
+      this.showAlert = false;
+      this.btnName = "scaning";
+      this.hintText = "正在扫描设备,请保持设备开机状态";
+      this.showStateIcon = false;
+      this.showLink = true;
+      this.device = null;
+      const that = this;
+      clearTimeout(this.stopScanTimer);
+      //开始扫描
+      uni.startBluetoothDevicesDiscovery({
+        success: (res) => {
+          //设置扫描的超时时间
+          that.setStopScanTimeout();
+          //扫描到的设备的回调
+          uni.onBluetoothDeviceFound(function (res) {
+            let devices = res.devices;
+            for (var i = 0; i < devices.length; i++) {
+              console.log(devices[i]);
+              //todo 到时候要更具名称/型号来判断
+              if (
+                devices[i].name &&
+                devices[i].name.startsWith("AIrSMArT") &&
+                that.device == null
+              ) {
+                //停止扫描
+                that.stopScan();
+                that.device = {
+                  name: devices[i].name,
+                  mac: devices[i].deviceId,
+                };
+                that.showStateIcon = false;
+                that.hintText = "以搜索到MW-M4设备";
+                that.showLink = true;
+                that.btnName = "connect";
+                break;
+              }
+            }
+          });
+        },
+        fail: (err) => {
+          console.warn(err);
+          that.hintText = "搜索设备失败";
+          that.btnName = "rescan";
+          that.showStateIcon = false;
+          that.showLink = true;
+        },
+      });
+    },
+    //设置超时扫描的定时器
+    setStopScanTimeout() {
+      const that = this;
+      //N秒之后停止扫描
+      that.stopScanTimer = setTimeout(() => {
+        //停止扫描
+        uni.stopBluetoothDevicesDiscovery({
+          complete() {
+            if (that.device == null) {
+              that.hintText = "沒有搜索到设备";
+              that.btnName = "rescan";
+              that.showStateIcon = false;
+              that.showLink = true;
+            }
+          },
+        });
+      }, 15 * 1000);
+    },
+    //停止蓝牙的扫描
+    stopScan() {
+      uni.stopBluetoothDevicesDiscovery({});
+      clearTimeout(this.stopScanTimer);
+    },
+    //ble配网的回调
+    bleConfigNetCallback(res) {
+      console.log(res);
+      if (res.errCode == 0) {
+        if (this.device) {
+          this.device.uuid = res.iccid;
+        }
+        //配网成功
+        this.hintText = "连接成功";
+        this.btnName = "finish";
+        this.showStateIcon = true;
+        this.showLink = false;
+        this.stateIcon = "../../../static/common/ic_green_success.svg";
+      } else {
+        this.hintText = "连接失败,请确保设备开机状态";
+        this.btnName = "reconnect";
+        this.showStateIcon = true;
+        this.showLink = true;
+        this.stateIcon = "../../../static/common/ic_red_fail.svg";
+      }
+    },
+  },
+  watch: {},
+
+  // 页面周期函数--监听页面加载
+  onLoad(options) {
+    this.model = options.model;
+    this.productName = options.name;
+    if (this.productName && this.productName.length > 0) {
+      uni.setNavigationBarTitle({
+        title: `连接${this.productName}`,
+      });
+    }
+    this.init();
+  },
+  // 页面周期函数--监听页面初次渲染完成
+  onReady() {},
+  // 页面周期函数--监听页面显示(not-nvue)
+  onShow() {},
+  // 页面周期函数--监听页面隐藏
+  onHide() {},
+  // 页面周期函数--监听页面卸载
+  onUnload() {
+    this.stopScan();
+    BleConfigNet.closeBLEConnection();
+  },
+};
+</script>
+
+<style>
+.content {
+  display: flex;
+  flex-direction: column;
+  justify-content: flex-start;
+  align-items: center;
+}
+.img {
+  margin-top: 19.79vh;
+  width: 37.33vw;
+  height: 34.4vw;
+}
+.img1 {
+  width: 32rpx;
+  height: 32rpx;
+  margin-right: 8rpx;
+}
+.img2 {
+  width: 24rpx;
+  height: 22rpx;
+  margin-right: 8rpx;
+}
+.hint {
+  height: 40rpx;
+  display: flex;
+  flex-direction: row;
+  justify-content: center;
+  align-items: center;
+}
+.mt1 {
+  margin-top: 30rpx;
+}
+.text1 {
+  font-size: 24rpx;
+  font-weight: 700;
+  color: #353535;
+}
+.text2 {
+  font-size: 24rpx;
+  font-weight: 500;
+  color: #684bbe;
+}
+.btn {
+  background-color: #353535;
+  width: 69.33vw;
+  border-radius: 50rpx;
+  color: white;
+  padding-top: 24rpx;
+  padding-bottom: 24rpx;
+  font-size: 32rpx;
+  line-height: 1;
+}
+
+.disabled {
+  background-color: #999999;
+  cursor: not-allowed;
+}
+.finish {
+  background-color: #684bbe;
+}
+.bottom {
+  position: fixed;
+  top: 73.8vh;
+  left: 0;
+  right: 0;
+  bottom: 0;
+}
+</style>

+ 103 - 0
pages/addDevice/selectDevice/selectDevice.vue

@@ -0,0 +1,103 @@
+<template>
+	<view class="content">
+		<view class="box bottom" @click="deviceClick('MW-M3')">
+			<image src="https://airsmart-photo1.oss-cn-shanghai.aliyuncs.com/wx/productModel/3X/MW-M3.png"
+				mode="aspectFit" class="img" />
+			<text class="text">猫王·MW-M3</text>
+		</view>
+		<view class="line"></view>
+		<view class="box top" @click="deviceClick('MW-M4')">
+			<image src="https://airsmart-photo1.oss-cn-shanghai.aliyuncs.com/wx/productModel/3X/MW-M4.png"
+				mode="aspectFit" class="img" />
+			<text class="text">猫王·MW-M4</text>
+		</view>
+		<view style="height: 60rpx"></view>
+		<bt-alert v-if="show" @close="btAlertClose" />
+
+
+	</view>
+</template>
+
+<script>
+	import BtAlert from '../../../components/btAlert/btAlert.vue';
+	export default {
+		components: {
+			BtAlert
+		},
+		data() {
+			return {
+				show: false,
+			};
+		},
+		methods: {
+			deviceClick(model) {
+				if (model == 'MW-M3') {
+					uni.navigateTo({
+						url: `../connectDevice/connectDevice?model=MW-M3&name=猫王·MW-M3`,
+					})
+				} else if (model == 'MW-M4') {
+					uni.navigateTo({
+						url: `../connectDevice/connectDevice?model=MW-M4&name=猫王·MW-M4`,
+					})
+				}
+			},
+			btAlertClose() {
+				this.show = false
+			}
+		},
+	};
+</script>
+
+<style>
+	.content {
+		display: flex;
+		flex-direction: column;
+		width: 100vw;
+		height: 100vh;
+		justify-content: center;
+	}
+
+	.line {
+		width: 56vw;
+		height: 1px;
+		opacity: 0.2;
+		margin-left: auto;
+		margin-right: auto;
+		background-image: linear-gradient(to right, #c8c8c8, #484848, #979797);
+	}
+
+	.box {
+		display: flex;
+		flex-direction: column;
+		width: 50vw;
+		height: 50vw;
+		margin-left: auto;
+		margin-right: auto;
+		align-items: center;
+	}
+
+	.img {
+		width: 37.33vw;
+		height: 34.4vw;
+	}
+
+	.top {
+		margin-top: 3.3vh;
+		justify-content: flex-start;
+	}
+
+	.bottom {
+		margin-bottom: 3.3vh;
+		justify-content: flex-end;
+	}
+
+	.text {
+		margin-top: 30rpx;
+		font-size: 24rpx;
+	}
+
+	.location {
+		position: fixed;
+		top: 0;
+	}
+</style>

+ 12 - 8
pages/demo/mqtt/mqttDemo.vue

@@ -60,14 +60,18 @@
 			addDevice() {
 				if (getApp().globalData.uid) {
 					//添加设备
-					this.$store.dispatch({
-						type: "moduleMqtt/addDevice",
-						clientId: `wx_${getApp().globalData.uid}`,
-						device: {
-							devName: "MW-V",
-							uuid: "89860474192070498495",
-						},
-					});
+					// this.$store.dispatch({
+					// 	type: "moduleMqtt/addDevice",
+					// 	clientId: `wx_${getApp().globalData.uid}`,
+					// 	device: {
+					// 		devName: "MW-V",
+					// 		uuid: "89860474192070498495",
+					// 	},
+					// });
+
+					uni.navigateTo({
+						url:'../../addDevice/selectDevice/selectDevice'
+					})
 				}else{
 					uni.showModal({
 						title:"温馨提示",

+ 40 - 38
pages/index/index.vue

@@ -1,49 +1,51 @@
 <template>
-	<view class="content">
-		
-	</view>
+  <view class="content">
+    <button type="primary" @click="addDevice">添加设备</button>
+  </view>
 </template>
 
 <script>
-	export default {
-		data() {
-			return {
-				title: 'Hello'
-			}
-		},
-		onLoad() {
-
-		},
-		methods: {
-
-		}
-	}
+export default {
+  data() {
+    return {
+      title: "Hello",
+    };
+  },
+  onLoad() {},
+  methods: {
+    addDevice() {
+      uni.navigateTo({
+        url: "../addDevice/selectDevice/selectDevice",
+      });
+    },
+  },
+};
 </script>
 
 <style>
-	.content {
-		display: flex;
-		flex-direction: column;
-		align-items: center;
-		justify-content: center;
-	}
+.content {
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+  justify-content: center;
+}
 
-	.logo {
-		height: 200rpx;
-		width: 200rpx;
-		margin-top: 200rpx;
-		margin-left: auto;
-		margin-right: auto;
-		margin-bottom: 50rpx;
-	}
+.logo {
+  height: 200rpx;
+  width: 200rpx;
+  margin-top: 200rpx;
+  margin-left: auto;
+  margin-right: auto;
+  margin-bottom: 50rpx;
+}
 
-	.text-area {
-		display: flex;
-		justify-content: center;
-	}
+.text-area {
+  display: flex;
+  justify-content: center;
+}
 
-	.title {
-		font-size: 36rpx;
-		color: #8f8f94;
-	}
+.title {
+  font-size: 36rpx;
+  color: #8f8f94;
+}
 </style>

+ 22 - 0
pages/mine/device/deviceDetail/deviceDetail.vue

@@ -0,0 +1,22 @@
+<template>
+	<view>
+		
+	</view>
+</template>
+
+<script>
+	export default {
+		data() {
+			return {
+				
+			}
+		},
+		methods: {
+			
+		}
+	}
+</script>
+
+<style>
+
+</style>

+ 32 - 0
pages/mine/device/deviceManager/deviceManager.vue

@@ -0,0 +1,32 @@
+<template>
+	<view class="content">
+		
+		<battery :battery='battery'></battery>
+		
+	</view>
+</template>
+
+<script>
+import battery from '../../../../components/battery/battery.vue'
+	export default {
+  components: { battery },
+		data() {
+			return {
+				battery:101
+			}
+		},
+		methods: {
+			
+		}
+	}
+</script>
+
+<style>
+.content{
+	display: flex;
+	flex-direction: column;
+	align-items: center;
+	margin: 20rpx;
+}
+
+</style>

+ 8 - 1
pages/mine/mine.vue

@@ -1,5 +1,8 @@
 <template>
 	<view>
+		<button type="primary" @click="goWebview('product/manual')">产品手册</button>
+		<button type="primary" @click="goWebview('help')">帮助与反馈</button>
+		<button type="primary" @click="goWebview('about')">关于</button>
 		
 	</view>
 </template>
@@ -12,7 +15,11 @@
 			}
 		},
 		methods: {
-			
+			goWebview(path){
+				uni.navigateTo({
+					url:`../webview/webview?path=${path}`
+				})
+			}
 		}
 	}
 </script>

+ 44 - 0
pages/webview/webview.vue

@@ -0,0 +1,44 @@
+<template>
+	<view>
+		<view>
+			<!-- <web-view :webview-styles="webviewStyles" src="https://uniapp.dcloud.io/static/web-view.html" @message='getMessage'></web-view> -->
+			<web-view :webview-styles="webviewStyles" :src="url" @message='getMessage'></web-view>
+		</view>
+	</view>
+</template>
+
+<script>
+	import { BASEURL } from '../../API/Constant.js' ;
+	
+	export default {
+		data() {
+			return {
+				path:'product/manual',
+				webviewStyles: {
+					progress: {
+						color: '#FF3333'
+					}
+				}
+			}
+		},
+		methods: {
+			getMessage(event){
+				console.log(event);
+			}
+		},
+		computed:{
+			url(){
+				return `${BASEURL}${this.path}`
+			}
+		},
+		onLoad(option){
+			if(option.path && option.path.length > 0){
+				this.path = option.path
+			}
+		}
+	}
+</script>
+
+<style>
+
+</style>

+ 20 - 0
static/common/battery.svg

@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg width="8px" height="25px" viewBox="0 0 8 25" version="1.1" xmlns="http://www.w3.org/2000/svg"
+    xmlns:xlink="http://www.w3.org/1999/xlink">
+    <title>电量备份 2</title>
+    <g id="页面-2" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
+        <g id="画板" transform="translate(-215.000000, -15.000000)" fill-rule="nonzero">
+            <g id="电量备份-3" transform="translate(215.769231, 15.230769)">
+                <g id="电量备份"
+                    transform="translate(3.230769, 12.000000) rotate(-90.000000) translate(-3.230769, -12.000000) translate(-8.769231, 8.769231)">
+                    <path
+                        d="M23.5401953,4.84615385 C23.2862606,4.84615385 23.0803907,4.53618462 23.0803907,4.15384615 L23.0803907,2.30769231 C23.0803907,1.92535385 23.2862606,1.61538462 23.5401953,1.61538462 C23.7941301,1.61538462 24,1.92535385 24,2.30769231 L24,4.15384615 C24,4.53618462 23.7941301,4.84615385 23.5401953,4.84615385 Z"
+                        id="路径" fill="#111111"></path>
+                    <!-- <rect id="矩形" fill="#85D1A9" x="0.577009767" y="0.923076923" width="21" height="4.61538462"></rect> -->
+                    <rect id="矩形" stroke="#111111" stroke-width="1.5" x="0.75" y="0.75" width="21.0033809"
+                        height="4.96153846" rx="2"></rect>
+                </g>
+            </g>
+        </g>
+    </g>
+</svg>

Разница между файлами не показана из-за своего большого размера
+ 13 - 0
static/common/battery_charg.svg


Разница между файлами не показана из-за своего большого размера
+ 11 - 0
static/common/ic_close.svg


+ 12 - 0
static/common/ic_green_success.svg

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg width="16px" height="16px" viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+    <title>路径 2</title>
+    <g id="页面-2" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
+        <g id="首页-设备连接-4" transform="translate(-155.000000, -368.000000)" fill-rule="nonzero">
+            <g id="路径-2" transform="translate(155.000000, 368.000000)">
+                <path d="M0,8 L0,8 C0,12.4182812 3.58171875,16 8,16 C12.4182813,16 16,12.4182812 16,8 L16,8 C16,3.58171875 12.4182813,0 8,0 C3.58171875,0 0,3.58171875 0,8 L0,8 Z" id="路径" fill="#6DD400"></path>
+                <polygon id="路径" fill="#FFFFFF" points="11.3215937 4.79999879 12.1142797 5.64639879 7.04662344 10.5142894 6.20548125 9.70468942 6.20776695 9.70263228 4.11428258 7.69166353 4.92159664 6.74012134 7.07222164 8.87384009 11.3213623 4.80001196"></polygon>
+            </g>
+        </g>
+    </g>
+</svg>

Разница между файлами не показана из-за своего большого размера
+ 11 - 0
static/common/ic_red_fail.svg


Разница между файлами не показана из-за своего большого размера
+ 13 - 0
static/common/ic_smile.svg


+ 111 - 72
store/modules/moduleMqtt.js

@@ -1,6 +1,6 @@
 import mqtt from '../../common/mqtt.js'
 import Vue from 'vue'
-import parse from './mqttParse.js'
+import {messageParse,indexOfUuid} from './mqttParse.js'
 //import mqtt from 'mqtt/dist/mqtt.js'
 
 const options = {
@@ -19,20 +19,20 @@ url = 'wxs://mqtt.test.radio1964.com'
 
 
 //订阅设备在线状态
-function subscribeDevicesStatus(dispatch,deviceList){
-	deviceList.forEach((value) =>{
+function subscribeDevicesStatus(dispatch, deviceList) {
+	deviceList.forEach((value) => {
 		let topic = `/${value.uuid}/status/onoffline`
-		dispatch('subscribe',topic)
+		dispatch('subscribe', topic)
 	})
 }
 
 //订阅消息
-function subscribeCurrDevice(dispatch,device){
-	if(device){
-		let topic = `/${device.uuid}/user/pub_response`
-		dispatch('subscribe',topic)
-	}
-}
+// function subscribeCurrDevice(dispatch, device) {
+// 	if (device) {
+// 		let topic = `/${device.uuid}/user/pub_response`
+// 		dispatch('subscribe', topic)
+// 	}
+// }
 
 export default {
 	namespaced: true,
@@ -44,19 +44,19 @@ export default {
 		//mqtt客户端
 		mqttClient: null,
 		//收到的消息的历史记录
-		msgList:[],
+		msgList: [],
 		//设备的播放信息
-		playInfo:{
-			title:"",
-			artist:"",
-			albumURI:"",
-			songInfoID:"",
-			songAlbumID:"",
-			Duration:0,
-			channel:1,
-			audioType:1,
-			PlayState:3,
-			PlayMode:0
+		playInfo: {
+			title: "",
+			artist: "",
+			albumURI: "",
+			songInfoID: "",
+			songAlbumID: "",
+			Duration: 0,
+			channel: 1,
+			audioType: 1,
+			PlayState: 3,
+			PlayMode: 0
 
 		}
 
@@ -76,7 +76,7 @@ export default {
 		//设置当前选择的设备
 		setCurrentDevice(state, device) {
 			//state.currentDevice = device
-			Vue.set(state,'currentDevice',device)
+			Vue.set(state, 'currentDevice', device)
 		},
 		//移除设备
 		removeDevice(state, device) {
@@ -96,77 +96,77 @@ export default {
 			state.mqttClient = null
 		},
 		//更新设备信息
-		updateDevice(state,data){
-			Vue.set(state.deviceList,data.index,data.device)
+		updateDevice(state, data) {
+			Vue.set(state.deviceList, data.index, data.device)
 		},
 		//更新播放信息
-		updatePlayInfo(state,playinfo){
+		updatePlayInfo(state, playinfo) {
 			state.playInfo = playinfo
 		}
 
 	},
 	actions: {
 		//添加设备
-		addDevice({state, dispatch,commit, getters },data){
+		addDevice({ state, dispatch, commit, getters }, data) {
 			let clientId = (data.clientId) ? data.clientId : options.clientId
 			let device = data.device
 
 			console.log(`deviceList = ${state.deviceList} device = ${device}`);
 			//判断设备是否存在deviceList中
-			let findDevice = state.deviceList.find((item) =>{
+			let findDevice = state.deviceList.find((item) => {
 				return item.uuid === device.uuid
 			})
-			if(findDevice == null){
-				if(state.deviceList.length === 0){
+			if (findDevice == null) {
+				if (state.deviceList.length === 0) {
 					//设置当前的设备为添加的设备
-					commit('setCurrentDevice',device)
+					commit('setCurrentDevice', device)
 				}
 				//添加设备
 				state.deviceList.push(device)
 				//如果已经连接
-				if(getters.connected){
+				if (getters.connected) {
 					//订阅设备是否在线
-					subscribeDevicesStatus(dispatch,[device])
-					if(state.currentDevice && state.currentDevice.uuid === device.uuid){
+					subscribeDevicesStatus(dispatch, [device])
+					//if (state.currentDevice && state.currentDevice.uuid === device.uuid) {
 						//订阅当前设备的消息
-						subscribeCurrDevice(dispatch,state.currentDevice)
-					}
+						//subscribeCurrDevice(dispatch, state.currentDevice)
+					//}
 
-				}else{//如果没有连接
+				} else {//如果没有连接
 					//连接服务器
-					dispatch('connect',clientId)
+					dispatch('connect', clientId)
 				}
-				
+
 			}
 		},
 		//删除设备
-		removeDevice({state, dispatch,commit, getters },device){
+		removeDevice({ state, dispatch, commit, getters }, device) {
 			//判断设备是否存在deviceList中
-			let findDevice = state.deviceList.find((item) =>{
+			let findDevice = state.deviceList.find((item) => {
 				return item.uuid === device.uuid
 			})
-			if(findDevice){
+			if (findDevice) {
 				//取消此设备的订阅
 				let topic = `/${device.uuid}/status/onoffline`
-				dispatch('unsubscribe',topic)
+				dispatch('unsubscribe', topic)
 				topic = `/${device.uuid}/status/pub_response`
-				dispatch('unsubscribe',topic)
+				dispatch('unsubscribe', topic)
 				//在设备列表中删除此设备
-				commit('removeDevice',findDevice)
+				commit('removeDevice', findDevice)
 				//如果删除的是选中的设备
-				if(currentDevice && state.currentDevice.uuid == device.uuid){
+				if (currentDevice && state.currentDevice.uuid == device.uuid) {
 					//清除当前选中的设备 todo 还是自动选中在线的设备
-					commit('setCurrentDevice',null)
+					commit('setCurrentDevice', null)
 				}
-				
-				if(state.deviceList.length === 0 ){//所有的设备都已经删除,关闭连接
+
+				if (state.deviceList.length === 0) {//所有的设备都已经删除,关闭连接
 					dispatch('disconnect')
 				}
 			}
 		},
 
 		//连接设备
-		connect({ state, dispatch,commit, getters }, clientId) {
+		connect({ state, dispatch, commit, getters }, clientId) {
 			if (state.mqttClient == null) {
 				//连接服务器
 				commit('connect', clientId)
@@ -174,9 +174,9 @@ export default {
 				state.mqttClient.on("connect", function () {
 					console.log("connect success!");
 					//订阅设备是否在线
-					subscribeDevicesStatus(dispatch,state.deviceList)
+					subscribeDevicesStatus(dispatch, state.deviceList)
 					//订阅当前设备的消息
-					subscribeCurrDevice(dispatch,state.currentDevice)
+					//subscribeCurrDevice(dispatch, state.currentDevice)
 				});
 
 				//异常回调
@@ -201,71 +201,110 @@ export default {
 				state.mqttClient.on('message', function (topic, message) {
 					console.log(`message = ${message.toString()}`);
 					//解析收到的消息
-					parse({state, dispatch,commit, getters },topic,message)
-					
+					messageParse({ state, dispatch, commit, getters }, topic, message)
+
 					//这是测试的
 					state.msgList.push({
 						topic: topic.toString(),
 						msg: message.toString(),
 					});
-					
+
 
 
 				})
-			}else{
-				if(!state.mqttClient.connected){
+			} else {
+				if (!state.mqttClient.connected) {
 					console.log("reconnect");
 					state.mqttClient.reconnect()
 					//重连成功的回调
-					state.mqttClient.on("reconnect", function() {
+					state.mqttClient.on("reconnect", function () {
 						console.log("reconnect success!");
-						
+
 					});
 				}
 			}
 		},
 		//断开mqtt的连接
-		disconnect({state,commit},isRelease) {
+		disconnect({ state, commit }, isRelease) {
 			console.log('disconnect')
 			if (state.mqttClient) {
-				state.mqttClient.end(false,() =>{
+				state.mqttClient.end(false, () => {
 					console.log(`state.mqttClient.connected = ${state.mqttClient.connected}`);
 				})
 			}
-			if(isRelease){
+			if (isRelease) {
 				//清除数据
 				commit('release')
 			}
 		},
 		//发布消息
-		publishWithType({state, dispatch,getters},payload){
+		publishMsg({ state, dispatch, getters }, msg) {
+			let uuid = msg.uuid
+			let type = msg.mqttType;
+			let other = msg.other;
+			if (!getters.connected) {
+				return new Promise((resolve, reject) => {
+					reject('连接已断开')
+				});
+			} else {
+				let index = indexOfUuid(state.deviceList,uuid)
+				if (index >= 0) {
+					let device = state.deviceList[index];
+					if(device.online){
+						let topic = `/${uuid}/user/sub_control`;
+						let json = {
+							'DstDeviceName': uuid,
+							'SrcDeviceName': options.clientId,
+							'type': type,
+						}
+						if (other) {
+							json.other = other
+						}
+						let payload = JSON.stringify(json)
+						console.log(`publishWithType topic = ${topic} payload = ${payload}`);
+						return dispatch('publish', { topic, payload })
+					}else{
+						return new Promise((resolve, reject) => {
+							reject('设备已经离线')
+						});
+					}
+				}else{
+					return new Promise((resolve, reject) => {
+						reject('没有此设备')
+					});
+				}
+			}
+		},
+
+		//发布消息
+		publishWithType({ state, dispatch, getters }, payload) {
 			//console.log(payload);
 			//console.log(options);
 			let type = payload.mqttType;
 			let other = payload.other;
-			if(!getters.connected){
+			if (!getters.connected) {
 				return new Promise((resolve, reject) => {
 					reject('连接已断开')
 				});
-			}else if(!(state.currentDevice && state.currentDevice.online)){
+			} else if (!(state.currentDevice && state.currentDevice.online)) {
 				return new Promise((resolve, reject) => {
 					reject('设备已经离线')
 				});
-			}else{
+			} else {
 				let topic = `/${state.currentDevice.uuid}/user/sub_control`;
 				//console.log(payload);
 				//console.log(payload.mqttType);
 				let json = {
-				  'DstDeviceName':state.currentDevice.uuid,
-				  'SrcDeviceName':options.clientId,
-				  'type':type,
+					'DstDeviceName': state.currentDevice.uuid,
+					'SrcDeviceName': options.clientId,
+					'type': type,
 				}
-				if(other){
+				if (other) {
 					json.other = other
 				}
 				let payload = JSON.stringify(json)
 				console.log(`publishWithType topic = ${topic} payload = ${payload}`);
-				return dispatch('publish',{topic,payload})
+				return dispatch('publish', { topic, payload })
 
 			}
 
@@ -311,7 +350,7 @@ export default {
 			})
 		},
 		//解除订阅消息
-		unsubscribe({ state, commit, getters }, topic){
+		unsubscribe({ state, commit, getters }, topic) {
 			console.log(`unsubscribe topic = ${topic}`);
 			return new Promise((resolve, reject) => {
 				if (getters.connected) {

+ 50 - 29
store/modules/mqttParse.js

@@ -12,6 +12,51 @@ function isEmpty(str) {
 
 }
 
+function sleep(time) {
+    return new Promise((resolve) => setTimeout(resolve, time))
+}
+
+function indexOfUuid(deviceList,uuid){
+    let index = -1
+    if(deviceList == null || uuid == null){
+        return index
+    }
+    for (var i = 0; i < deviceList.length; i++) {
+        if (deviceList[i].uuid === uuid) {
+            index = i;
+            break
+        }
+    }
+    return index
+}
+
+/**
+ * 当设备在线
+ * @param {*} param0 
+ * @param {*} fromDeviceUuid 
+ */
+async function onDeviceOnline({ state, dispatch }, fromDeviceUuid){
+    try{
+        //订阅消息
+        await  dispatch('subscribe',`/${fromDeviceUuid}/user/pub_response`)
+        await sleep(200)
+        //获取设备信息
+        await dispatch({
+            type: "publishWithType",
+            mqttType: "get_dev_info",
+        })
+        if(state.currentDevice && state.currentDevice.uuid == fromDeviceUuid){
+            //获取播放信息
+            dispatch({
+                type: "publishWithType",
+                mqttType: "get_position",
+            })
+        }
+    }catch(e){
+        console.warn(e);
+    }
+}
+
 /**
  * 收到设备在线和离线的消息
  * @param {*} param0 
@@ -20,13 +65,7 @@ function isEmpty(str) {
  */
 function receiveOnOffline({ state, dispatch, commit }, fromDeviceUuid, message) {
 
-    let index = -1
-    for (var i = 0; i < state.deviceList.length; i++) {
-        if (state.deviceList[i].uuid === fromDeviceUuid) {
-            index = i;
-            break
-        }
-    }
+    let index = indexOfUuid(state.deviceList,fromDeviceUuid)
     console.log(`state index = ${index}`);
     if (index >= 0) {
         let stateJson = JSON.parse(message)
@@ -37,20 +76,8 @@ function receiveOnOffline({ state, dispatch, commit }, fromDeviceUuid, message)
             device.online = true
             //更新设备状态信息
             commit('updateDevice', { index, device })
-            if (state.currentDevice && state.currentDevice.uuid == device.uuid) { //当前设备在线
-                //延时获取设备信息和播放信息
-                setTimeout(async function () {
-                    await dispatch({
-                        type: 'publishWithType',
-                        mqttType: 'get_dev_info',
-                    })
-                    dispatch({
-                        type: "publishWithType",
-                        mqttType: "get_position",
-                    })
-                }, 200);
-
-            }
+            //设备在线订阅获取设备信息等
+            onDeviceOnline({state, dispatch},fromDeviceUuid)
         } else {
             device.online = false
             //更新设备状态信息
@@ -128,13 +155,7 @@ function messageParse({ state, dispatch, commit, getters }, topic, message) {
 }
 
 function updateDeviceInfo({ state, commit }, jsonPayload) {
-    let index = -1
-    for (var i = 0; i < state.deviceList.length; i++) {
-        if (state.deviceList[i].uuid === jsonPayload.SrcDeviceName) {
-            index = i;
-            break
-        }
-    }
+    let index = indexOfUuid(state.deviceList,jsonPayload.SrcDeviceName)
     console.log(`state index = ${index}`);
     if (index >= 0 && jsonPayload.other) {
         let device = state.deviceList[index];
@@ -157,4 +178,4 @@ function updateDeviceInfo({ state, commit }, jsonPayload) {
 
 
 
-module.exports = messageParse
+module.exports = {messageParse,indexOfUuid}