device-diag.html 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8"/>
  5. <meta name="description" content=""/>
  6. <meta name="keywords" content="扫码支付,线上投币,运营数据,物联网"/>
  7. <meta name="format-detection" content="telphone=no,email=no"/>
  8. <meta name="viewport"
  9. content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
  10. <meta http-equiv="pragma" content="no-cache">
  11. <meta http-equiv="cache-control" content="no-cache">
  12. <meta http-equiv="expires" content="0">
  13. <title>设备调测</title>
  14. <link rel="stylesheet" href="https://cdn.washpayer.com/components/lib/mui.min.css"/>
  15. <link rel="stylesheet" href="../components/custom/css/common.css"/>
  16. <link rel="stylesheet" href="css/xyf.common.min.css">
  17. <style>
  18. .mui-input-group .mui-input-row label {
  19. color: #666;
  20. }
  21. .mui-input-group .mui-input-row label ~ input {
  22. color: #000;
  23. font-size: inherit;
  24. }
  25. .msg-item {
  26. font-size: 14px;
  27. white-space: normal;
  28. word-break: break-all;
  29. }
  30. .btn-fixed {
  31. position: fixed;
  32. top: 0;
  33. background: #fff;
  34. width: 100%;
  35. z-index: 9;
  36. box-shadow: 0 0 10px #aaa;
  37. }
  38. .btn-fixed:after {
  39. display: none;
  40. }
  41. .fixed-close {
  42. color: #666;
  43. font-size: 26px;
  44. position: fixed;
  45. width: 32px;
  46. height: 32px;
  47. line-height: 32px;
  48. text-align: center;
  49. z-index: 1;
  50. bottom: 10px;
  51. left: 50%;
  52. -webkit-transform: translateX(-50%);
  53. transform: translateX(-50%);
  54. }
  55. .close-msg {
  56. padding: 10px;
  57. margin-top: -10px;
  58. margin-right: -10px;
  59. color: #555;
  60. font-size: 18px;
  61. }
  62. </style>
  63. </head>
  64. <body>
  65. <h4 class="param-title" id="device">设备</h4>
  66. <div id="app">
  67. </div>
  68. <script src="https://cdn.washpayer.com/npm/mqtt@2.18.8/dist/mqtt.min.js"></script>
  69. <script type="text/javascript" src="https://cdn.washpayer.com/components/lib/vue.min.js"></script>
  70. <script src="https://cdn.washpayer.com/components/lib/jquery.min.js"></script>
  71. <script src="https://cdn.washpayer.com/components/lib/moment.min.js"></script>
  72. <script src="https://cdn.washpayer.com/components/lib/mui.min.js"></script>
  73. <script src="/components/custom/js/common.js"></script>
  74. <script src="js/xyf.common.js"></script>
  75. <script>
  76. var logicalCode = getQueryString("logicalCode")
  77. var devType = getQueryString("devType");
  78. $("#device").html("<i class='c-primary iconfont " + getDevIconName(devType) + "'></i> " + devType + logicalCode);
  79. sendRequest({
  80. url: "/device/getDiagCommands",
  81. type: "GET",
  82. data: {'logicalCode': logicalCode},
  83. mask: "正在获取命令列表...",
  84. success: function (response) {
  85. if (response.result == 1) {
  86. var cmds = response.payload;
  87. initPage(cmds)
  88. } else {
  89. mui.toast(res.description);
  90. }
  91. }
  92. });
  93. function initPage(cmdlist) {
  94. var app = new Vue({
  95. el: "#app",
  96. template: '<div>' +
  97. ' <div class="mui-content">'
  98. + ' <ul class="mui-table-view" >'
  99. + ' <li class="mui-table-view-cell" v-for="cmd in cmdList" :class="{\'btn-fixed c-primary\':nowCmd.id==cmd.id&&msgList.length>0}" @click="openDialog(cmd)"><a class="mui-navigate-right" href="javascript:void 0">{{cmd.name}}</a></li>'
  100. + ' </ul>'
  101. + ' <h4 class="param-title" v-if="client">消息 <span @click="clearMsg()" class="iconfont icon-close mui-pull-right close-msg"></span></h4>'
  102. + ' <ul class="mui-table-view custom-top" v-if="msgList.length>0" >'
  103. + ' <li class="mui-table-view-cell msg-item" v-for="item in msgList"><span class="font-b-6">{{item.time}}</span> {{item.message}}</li>'
  104. + ' </ul>'
  105. + ' </div>'
  106. + ' <div class="fixed-close iconfont icon-stop" v-show="client" @click="closeMqtt()"></div>'
  107. + ' <div class="edit-back" v-show="dialogShow" >'
  108. + ' <form class="edit-content">'
  109. + ' <div class="edit-box">'
  110. + ' <div v-for="param in nowCmd.params" class="mui-input-row"><label class="">{{param.name}} </label><div class="mui-pull-right edit-row"><input v-model="param.value" type="text"/></div></div>'
  111. + ' </div>'
  112. + ' <div class="mui-popup-buttons ">'
  113. + ' <span class="mui-popup-button" @click="cancel">取消</span>'
  114. + ' <span class="mui-popup-button mui-popup-button-bold"><input type="submit" value="发送" @click="submit($event)"'
  115. + ' /></span>'
  116. + ' </div>'
  117. + ' </form>'
  118. + ' </div>'
  119. + '</div>'
  120. ,
  121. data: {
  122. dialogShow: false,
  123. cmdList: cmdlist,
  124. msgList: [],
  125. nowCmd: [],
  126. client: null,
  127. },
  128. mounted: function () {
  129. },
  130. methods: {
  131. openDialog: function (cmd) {
  132. this.dialogShow = true
  133. this.nowCmd = cmd
  134. },
  135. boot_mqtt(broker_url, topic, callback) {
  136. var that = this
  137. if (!broker_url) {
  138. console.error('broker_url not supplied');
  139. return
  140. }
  141. console.info('broker is: ' + broker_url);
  142. console.info('subscribed to topic: ' + topic);
  143. var client = mqtt.connect('ws://' + broker_url);
  144. client.subscribe(topic);
  145. client.on("message", function (topic, payload) {
  146. var message = payload.toString()
  147. console.log('received:' + message);
  148. if (callback) {
  149. callback(message)
  150. } else {
  151. that.msgList.unshift({message:message,time:moment().format("HH:mm:ss")});
  152. // 界面显示最多不超过100条
  153. if (that.msgList.length > 100) {
  154. that.msgList.pop()
  155. }
  156. }
  157. })
  158. that.client = client
  159. },
  160. submit: function (evt) {
  161. //阻止submit表单提交
  162. evt.preventDefault();
  163. var that = this
  164. var cmd = that.nowCmd
  165. if (that.client) {
  166. mui.toast("请先关闭当前连接,再发送新的命令");
  167. return
  168. }
  169. sendRequest({
  170. url: "/device/diagDevice",
  171. type: "POST",
  172. contentType: "json",
  173. data: {
  174. logicalCode: logicalCode,
  175. commandId: cmd.id,
  176. params: cmd.params
  177. },
  178. mask: "正在发送命令...",
  179. success: function (res) {
  180. if (res.result === 1) {
  181. mui.toast("发送成功");
  182. that.dialogShow = false;
  183. that.boot_mqtt(res.payload.pushBrokerUrl, res.payload.topic);
  184. } else {
  185. mui.toast(res.description);
  186. }
  187. }
  188. });
  189. },
  190. clearMsg() {
  191. this.msgList = []
  192. },
  193. closeMqtt() {
  194. var that = this
  195. var btnArray = ['取消', '确定'];
  196. mui.confirm('确定关闭当前连接?', '温馨提示', btnArray, function (e) {
  197. if (e.index === 1) {
  198. if (that.client) {
  199. that.client.end(true, function () {
  200. that.nowCmd = []
  201. that.client = null
  202. })
  203. }
  204. }
  205. });
  206. },
  207. cancel: function () {
  208. this.dialogShow = false
  209. }
  210. }
  211. });
  212. }
  213. </script>
  214. </body>
  215. </html>