mqttDemo.js 2.4 KB

1
  1. (global["webpackJsonp"]=global["webpackJsonp"]||[]).push([["pages/views/demo/mqttDemo"],{1297:function(t,n,e){"use strict";e.d(n,"b",(function(){return o})),e.d(n,"c",(function(){return i})),e.d(n,"a",(function(){}));var o=function(){var t=this.$createElement;this._self._c},i=[]},"199c":function(t,n,e){"use strict";e.r(n);var o=e("1297"),i=e("b984");for(var c in i)["default"].indexOf(c)<0&&function(t){e.d(n,t,(function(){return i[t]}))}(c);e("da69");var s=e("828b"),u=Object(s["a"])(i["default"],o["b"],o["c"],!1,null,"fa359b94",null,!1,o["a"],void 0);n["default"]=u.exports},"6b4e":function(t,n,e){},"6e09":function(t,n,e){"use strict";(function(t){var o=e("47a9");Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;var i=o(e("0ac6")),c={data:function(){return{client:{},mtopic:"iot/device/sensor/sub/",mtopicOne:"iot/hardware/all/sub/",subId:"101093843117597548",mqttData:""}},onLoad:function(t){},onShow:function(){this.offMQTT("on")},mounted:function(){},methods:{sensorMQTT:function(){var n=this,e=this;this.client=i.default.connect("wxs://"+t.getStorageSync("mqttUrl"),{username:t.getStorageSync("mqttUser"),password:t.getStorageSync("mqttPassword")}),this.client.on("connect",(function(t){n.client.subscribe(n.mtopic+e.subId,(function(t){t?console.log("连接错误:"+t):console.log("传感器订阅成功:"+n.mtopic+e.subId)})),n.client.subscribe(n.mtopicOne+e.subId,(function(t){t?console.log("连接错误:"+t):console.log("智能控制订阅成功:"+n.mtopicOne+e.subId)}))})),this.client.on("message",(function(t,e){if(e){var o=JSON.parse(e);console.log("data",o),n.$set(n,"mqttData",JSON.stringify(o))}}))},offMQTT:function(t){this.client.unsubscribe&&(this.client.unsubscribe(this.mtopicOne+this.subId,(function(t){})),this.client.end(),this.$set(this,"client",{})),t&&this.sensorMQTT()}},onHide:function(){this.offMQTT()},beforeDestroy:function(){this.offMQTT()}};n.default=c}).call(this,e("df3c")["default"])},"8f28":function(t,n,e){"use strict";(function(t,n){var o=e("47a9");e("e7a6");o(e("3240"));var i=o(e("199c"));t.__webpack_require_UNI_MP_PLUGIN__=e,n(i.default)}).call(this,e("3223")["default"],e("df3c")["createPage"])},b984:function(t,n,e){"use strict";e.r(n);var o=e("6e09"),i=e.n(o);for(var c in o)["default"].indexOf(c)<0&&function(t){e.d(n,t,(function(){return o[t]}))}(c);n["default"]=i.a},da69:function(t,n,e){"use strict";var o=e("6b4e"),i=e.n(o);i.a}},[["8f28","common/runtime","common/vendor"]]]);