testdevice.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>设备调试</title>
  7. <style>
  8. * {
  9. padding: 0;
  10. margin: 0;
  11. }
  12. #main {
  13. padding: 0 .4rem;
  14. }
  15. #main .bianhao {
  16. font-size: 0.5rem;
  17. font-weight: bold;
  18. color: black;
  19. padding: .4rem;
  20. }
  21. button {
  22. width: 2.3rem;
  23. background-color: #fff;
  24. outline: none;
  25. border: 0.01rem solid #efefef;
  26. padding: 0.2rem;
  27. }
  28. .redbtn {
  29. background-color: red !important;
  30. color: white !important;
  31. }
  32. .whitebtn {
  33. background-color: white;
  34. color: black;
  35. }
  36. input {
  37. /*width: 2.3rem;*/
  38. background-color: #fff;
  39. outline: none;
  40. border: 0.01rem solid #efefef;
  41. padding: 0.22rem;
  42. }
  43. select {
  44. background-color: #fff;
  45. outline: none;
  46. border: 0.01rem solid #efefef;
  47. padding: 0.22rem;
  48. }
  49. </style>
  50. </head>
  51. <body>
  52. <div id="main" style="margin-bottom: 2rem;">
  53. <div v-if="findBox" style="margin-top: 1rem; text-align: center">
  54. <h1 style="font-size: 0.7rem;text-align: center">绿色地球定时定点设备调试</h1>
  55. <input type="text" v-model="value" placeholder="请输入设备编号">
  56. <button @click="btnfun()">搜索</button>
  57. <div v-for="(item,index) in list" style="font-size: .5rem;margin-top: .3rem;" @click="tapvalue(item)">
  58. {{item}}
  59. </div>
  60. </div>
  61. <!-- <div v-if="isshezhi" style="margin-top: 1rem; text-align: center">
  62. <h1 style="font-size: 0.7rem;text-align: center">绿色地球定时定点设备调试</h1>
  63. <input type="text" disabled v-model="value" placeholder="">
  64. <input type="text" v-model="phone" placeholder="请输入DTU绑定手机卡号">
  65. <br />
  66. <select v-model="typevalue" @change="changeProduct($event)">
  67. <option value="1">四箱</option>
  68. <option value="2">五箱</option>
  69. <option value="3">四箱可回收</option>
  70. <option value="4">五箱可回收</option>
  71. </select>
  72. <button @click="shezhi">立即设置</button>
  73. </div> -->
  74. <div v-if="isbox">
  75. <nav class="bianhao">
  76. 设备编号:{{arrdata.device_name}}
  77. </nav>
  78. <article>
  79. <div class="bianhao" style="padding-top: 0;">
  80. 设备型号:{{xiangti}}
  81. </div>
  82. <div class="bianhao" style="padding-top: 0;display: flex;justify-content: space-between;">
  83. <span> 在线情况:{{isstatus}}</span> <span>版本号:{{arrdata.version}}</span>
  84. </div>
  85. <div class="bianhao" style="padding-top: 0;">
  86. 示意图:
  87. </div>
  88. <div style="text-align: center;">
  89. <img v-bind:src="devceImg" alt="" style="width: 7rem;height: 4rem;">
  90. </div>
  91. <div class="bianhao" style="padding-top: 0;">
  92. 全部箱体
  93. </div>
  94. <div class="bianhao" style="padding-top: 0; border-bottom: 0.01rem solid #efefef;">
  95. <button @click="startbtn(arrdata)" :class="classbtn" :disabled="startbtndib">{{mssage}}</button>
  96. <div style="font-size: .3rem;padding-top: .1rem;padding-bottom: .1rem;">
  97. 点击【开始测试】,全部箱体立即锁死,每15秒锁位状态改变一次
  98. </div>
  99. </div>
  100. <div class="bianhao" style="padding-top: 0; margin-top: .4rem; border-bottom: 0.01rem solid #efefef;">
  101. <button v-preventclick @click="dingshi(arrdata)" class="" :disabled="dingshibtn">定时测试</button>
  102. <div style="font-size: .3rem;padding-top: .1rem;padding-bottom: .1rem;">
  103. 点击【定时测试】,5-6秒之内锁位关闭,约4分钟左右锁位开启,1分钟后锁位关闭,测试按钮可再次点击。<br>注:设备配置后,无法点击调试</div>
  104. </div>
  105. <div v-for="(item,index) in boxarr" :key="index">
  106. <div class="bianhao"
  107. style="font-size: 0.4rem;display: flex; align-items: center; justify-content: space-between;">
  108. <div>{{item.name}}</div>
  109. <button @click="suowei(item,index)" :data-index="index" :data-id="item.id"
  110. :data-name="item.name" v-preventclick class="suoweiList" :disabled="allbtn">定时测试</button>
  111. </div>
  112. </div>
  113. </article>
  114. </div>
  115. </div>
  116. <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.9/vue.min.js"></script>
  117. <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.20.0/axios.min.js"></script>
  118. <script src="./auto-size.js"></script>
  119. <script>
  120. Vue.directive('preventclick', {
  121. inserted: function (button, bind) {
  122. button.addEventListener('click', () => {
  123. if (!button.disabled) {
  124. button.disabled = true;
  125. setTimeout(() => {
  126. button.disabled = false
  127. }, 180000)
  128. }
  129. })
  130. }
  131. })
  132. const vm = new Vue({
  133. el: '#main',
  134. data: {
  135. isstart: false,
  136. mssage: "开始测试",
  137. classbtn: "",
  138. findBox: true,
  139. isShow: false,
  140. time: 180,
  141. allbtn: false,
  142. startbtndib: false,
  143. dingshibtn: false,
  144. devceImg: '',
  145. id: '',
  146. arrdata: {},
  147. boxarr: [],
  148. boxnamearr: ["四箱", "五箱", "四箱可回收", "五箱可回收"],
  149. type: 1,
  150. dingshitype: 3,
  151. alltype: 4,
  152. startdata: "",
  153. xiangti: "",
  154. value: "",
  155. phone: "",
  156. typevalue: "1",
  157. isbox: false,
  158. isshezhi: false,
  159. isstatus: "",
  160. Numarr: [],
  161. list: []
  162. },
  163. mounted() {
  164. // this.getData("866222053211317")
  165. // console.log("111111")
  166. this.getNum()
  167. },
  168. watch: {
  169. value(newdata, jiu) {
  170. if (typeof newdata === 'string') {
  171. if (newdata.trim().length !== 0) {
  172. this.debounce(this.changeStr, 1500);
  173. } else { }
  174. }
  175. if (newdata == "") {
  176. this.list = []
  177. }
  178. }
  179. },
  180. methods: {
  181. tapvalue(item) {
  182. this.value = item
  183. this.list = []
  184. },
  185. changeStr() {
  186. this.list = []
  187. this.Numarr.forEach(item => {
  188. if (item.substr(item.length - 4) == this.value) {
  189. this.list.push(item)
  190. }
  191. })
  192. console.log(this.list)
  193. },
  194. debounce(fn, wait) {
  195. if (this.fun !== null) {
  196. clearTimeout(this.fun)
  197. }
  198. this.fun = setTimeout(fn, wait)
  199. },
  200. changeProduct(e) {
  201. console.log(e)
  202. this.type = e.target.value
  203. },
  204. btnfun() {
  205. if (this.value != "") {
  206. axios.get("/getDevice?id=" + this.value).then(res => {
  207. console.log(res)
  208. if (res.data.status == 200) {
  209. this.phone = res.data.data.phone
  210. this.typevalue = res.data.data.device_type
  211. this.findBox = false;
  212. this.isbox = true
  213. this.getData()
  214. }
  215. })
  216. }
  217. },
  218. // shezhi() {
  219. // if (this.phone != "") {
  220. // axios.get("/updateDevice?id=" + this.value + "&type=" + this.type + "&phone=" + this.phone).then(res => {
  221. // console.log(res)
  222. // if (res.data.status == 200) {
  223. // this.isbox = true
  224. // }
  225. // })
  226. // } else {
  227. // alert("请输入手机号")
  228. // }
  229. // },
  230. startbtn(e) {
  231. //开始测试
  232. axios.get("/send_protocol?id=" + this.value + "&type=" + this.type + "&status" + this.isstatus).then(res => {
  233. if (res.data.code == 603) {
  234. alert(res.data.msg)
  235. } else if (res.data.code == 604) {
  236. alert(res.data.msg)
  237. } else {
  238. this.allbtn = !this.allbtn
  239. this.dingshibtn = !this.dingshibtn
  240. this.isstart = !this.isstart
  241. if (this.isstart) {
  242. this.mssage = "停止测试"
  243. this.classbtn = "redbtn"
  244. this.type = 2
  245. } else {
  246. this.mssage = "开始测试"
  247. this.classbtn = ""
  248. this.type = 1
  249. }
  250. console.log(this.type)
  251. }
  252. })
  253. },
  254. dingshi() {
  255. this.startbtndib = true
  256. this.allbtn = true
  257. let timestop = setInterval(() => {
  258. this.time--
  259. if (this.time == 0) {
  260. clearInterval(timestop)
  261. this.time = 180
  262. this.startbtndib = false
  263. this.allbtn = false
  264. }
  265. }, 1000)
  266. axios.get("/send_protocol?id=" + this.value + "&type=" + this.dingshitype + "&status" + this.isstatus).then(res => {
  267. if (res.data.code == 603) {
  268. alert(res.data.msg)
  269. } else if (res.data.code == 604) {
  270. alert(res.data.msg)
  271. }
  272. })
  273. },
  274. suowei(e, index) {
  275. let el = document.querySelectorAll('.suoweiList')
  276. el.forEach(item => {
  277. if (item.dataset.index != index && !item.disabled) {
  278. item.disabled = true
  279. setTimeout(() => {
  280. item.disabled = false
  281. }, 20000);
  282. }
  283. });
  284. axios.get("/send_protocol?id=" + this.value + "&type=" + this.alltype + "&box_name=" + e.id + "&status" + this.isstatus).then(res => {
  285. if (res.data.code == 603) {
  286. alert(res.data.msg)
  287. } else if (res.data.code == 604) {
  288. alert(res.data.msg)
  289. } else {
  290. this.reduceCount(index)
  291. }
  292. })
  293. },
  294. getData: function (id) {
  295. axios.get("/get_boxname?id=" + this.value).then(res => {
  296. console.log(res)
  297. if (res.data.code == 200) {
  298. let type = res.data.data.device_type
  299. switch (parseInt(type)) {
  300. case 1:
  301. num = 4;
  302. break;
  303. case 2:
  304. num = 5;
  305. break;
  306. case 3:
  307. num = 5;
  308. break;
  309. case 4:
  310. num = 6;
  311. break;
  312. default:
  313. console.log('defige', type)
  314. num = 4;
  315. }
  316. this.arrdata = res.data.data
  317. if (this.arrdata.length == 0) {
  318. alert('异常设备请重新输入');
  319. return;
  320. }
  321. this.devceImg = '/' + res.data.data.device_image
  322. // this.xiangti = this.arrdata.device_type == "1" ? '四箱' : '五箱'
  323. this.isshezhi = false
  324. this.isstatus = this.arrdata.status
  325. this.xiangti = this.boxnamearr[res.data.data.device_type - 1];
  326. if ((res.data.data.device_type - 1) < 0) {
  327. this.xiangti = '四箱';
  328. }
  329. for (let i = 0; i < num; i++) {
  330. let obj = {
  331. time: 180,
  332. status: false,
  333. name: i + 1 + "号箱体",
  334. id: i + 1
  335. }
  336. this.boxarr.push(obj)
  337. }
  338. }
  339. })
  340. },
  341. reduceCount(index) {
  342. let _index = index;
  343. let time = setInterval(() => {
  344. if (this.boxarr[_index].time > 0) {
  345. this.boxarr[_index].time--;
  346. } else {
  347. clearInterval(time)
  348. this.boxarr[_index].time = 180;
  349. }
  350. Vue.set(this.boxarr[_index], this.boxarr[_index].time, this.boxarr[_index].time)
  351. }, 1000);
  352. },
  353. getNum() {
  354. axios.get("/getDevcielist").then(res => {
  355. this.Numarr = res.data.data
  356. })
  357. }
  358. },
  359. })
  360. </script>
  361. </body>
  362. </html>