lock-test.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. <template>
  2. <view class="u-page">
  3. <view class="" style="height: 44px;margin-bottom: 88rpx;">
  4. <u-navbar bgColor="#3c9cff" title="门锁测试" @leftClick="leftClick">
  5. </u-navbar>
  6. </view>
  7. <view class="u-demo-block">
  8. <view class="u-demo-block__content steps">
  9. <u-steps :current="current1" direction="column">
  10. <u-steps-item class="steps-item" v-for="item in stepList" :key="item.id" :error="item.error"
  11. :title="item.title" :desc="item.desc">
  12. </u-steps-item>
  13. <!-- <u-steps-item title="测试开门" desc="10:35">
  14. </u-steps-item>
  15. <u-steps-item title="测试刷卡" desc="11:40">
  16. </u-steps-item>
  17. <u-steps-item title="输入功耗" desc="11:40">
  18. </u-steps-item> -->
  19. </u-steps>
  20. </view>
  21. </view>
  22. <view class="upload">
  23. <u-button :disabled="uploadBtn" type="primary" size="large" @click="uploadTestMsg">完成测试并上传信息</u-button>
  24. </view>
  25. <u-popup customStyle="width: 70vw" :round="10" mode="center" :show="show7" @close="close">
  26. <view class="popupView" style="height: 150px;">
  27. <view class="power">
  28. 功耗选择
  29. </view>
  30. <view class="inputNum" style="">
  31. <view class="">
  32. 功耗:
  33. </view>
  34. <u--input placeholder="请输入功耗" border="surround" v-model="powerNum" @change="changeInput"></u--input>
  35. </view>
  36. <u-radio-group placement="row">
  37. <u-radio :customStyle="{margin: '15px 30px'}" v-for="(item, index) in radiolist1" :key="index"
  38. :label="item.value" :name="item.powerRefs" @change="radioChange" iconPlacement="right">
  39. </u-radio>
  40. </u-radio-group>
  41. </view>
  42. </u-popup>
  43. </view>
  44. </template>
  45. <script>
  46. export default {
  47. data() {
  48. return {
  49. subType: null,
  50. signalNum: '',
  51. interrupt: false,
  52. powerNum: 160,
  53. uploadBtn: false,
  54. uploadMsg: {
  55. testProjectId: null,
  56. deviceId: "",
  57. type: null,
  58. },
  59. radiolist1: [{
  60. value: '通过',
  61. disabled: false,
  62. powerRefs: true
  63. },
  64. {
  65. value: '不通过',
  66. disabled: false,
  67. powerRefs: false
  68. }
  69. ],
  70. show7: false,
  71. flag: 0,
  72. timer: null,
  73. cardPass: false,
  74. room: {
  75. deviceId: "",
  76. hotelId: 257,
  77. building: 2,
  78. floor: 7,
  79. room: "7728"
  80. },
  81. gatewayDeviceId:null ,
  82. show: false,
  83. current1: null,
  84. stepList: [{
  85. id: 0,
  86. title: '测试信号',
  87. desc: '测试蓝牙设备信号值是否通过',
  88. error: false
  89. }, {
  90. id: 1,
  91. title: '蓝牙测试开门',
  92. desc: '测试蓝牙进行门锁开门',
  93. error: false
  94. },
  95. {
  96. id: 2,
  97. title: '测试刷卡',
  98. desc: '房间信息已经植入,请进行刷卡验证',
  99. error: false
  100. },
  101. {
  102. id: 3,
  103. title: '测试功率',
  104. desc: '验证功耗是否通过',
  105. error: false
  106. }
  107. ]
  108. }
  109. },
  110. methods: {
  111. changeInput(e) {
  112. console.log(e);
  113. },
  114. leftClick() {
  115. let a = this.stepList.every((item) => {
  116. return item.error == true
  117. })
  118. console.log(a);
  119. if (a) {
  120. console.log('模态框');
  121. uni.hideLoading()
  122. uni.showModal({
  123. title: '温馨提示',
  124. content: '确定取消上传本次测试信息吗?',
  125. success: res => {
  126. if (res.confirm) {
  127. // this.show1 = false
  128. this.$u.toast(`点击了确定`)
  129. this.interrupt = true
  130. // console.log(this.flag);
  131. uni.navigateBack({
  132. delta: 1
  133. })
  134. } else {
  135. // this.interrupt = true
  136. // this.$u.toast(`点击了取消`)
  137. }
  138. }
  139. })
  140. } else {
  141. // this.flag = 99
  142. uni.hideLoading()
  143. this.interrupt = true
  144. uni.reLaunch({
  145. url: "/pages/bluetooth/bluetooth"
  146. })
  147. }
  148. },
  149. // 测试网关连接
  150. async testGateway() {
  151. uni.showLoading({
  152. title: '正在测试网关连接',
  153. icon: 'none'
  154. })
  155. const {
  156. data: res
  157. } = await uni.$http.get(`/api/v1/test/gateway/connection/${this.gatewayDeviceId}`)
  158. uni.hideLoading()
  159. if (res.data.isConnect == true) {
  160. this.flag = 1
  161. console.log('网关连接成功');
  162. } else {
  163. console.log('网关连接失败');
  164. this.$u.toast(`网关连接失败`)
  165. }
  166. },
  167. // 测试信号
  168. async testSignal(obj) {
  169. uni.showLoading({
  170. title: '正在测试信号',
  171. icon: 'none'
  172. })
  173. const {
  174. data: res
  175. } = await uni.$http.post('/api/v1/test/bluetooth/checkSignal', obj)
  176. console.log(res);
  177. uni.hideLoading()
  178. if (res.data.isNormal == true) {
  179. this.current1 = 1
  180. this.flag = 2
  181. console.log('信号测试成功');
  182. } else {
  183. this.stepList[0].error = true
  184. console.log('信号测试失败');
  185. this.$u.toast(`信号测试失败`)
  186. }
  187. },
  188. // 下发房间号
  189. async updataTime() {
  190. uni.showLoading({
  191. icon: 'none',
  192. title: "正在下发房间号"
  193. })
  194. const {
  195. data: res
  196. } = await uni.$http.post('/api/v1/test/bluetooth/setRoom', this.room)
  197. uni.hideLoading()
  198. if (res.code == 200) {
  199. this.flag = 4
  200. console.log('时间更新成功');
  201. } else {
  202. this.$u.toast(`时间更新失败`)
  203. console.log('时间更新失败');
  204. }
  205. },
  206. // 测试开门
  207. async openDoor() {
  208. uni.showLoading({
  209. title: '蓝牙开门测试中',
  210. icon: 'none'
  211. })
  212. const {
  213. data: res
  214. } = await uni.$http.post('/api/v1/test/bluetooth/openDoor', {
  215. deviceId: this.room.deviceId
  216. })
  217. uni.hideLoading()
  218. if (res.code == 200) {
  219. this.current1 = 2
  220. this.flag = 3
  221. // uni.$u.toast(`开门成功`)
  222. console.log('开门成功');
  223. } else {
  224. this.stepList[1].error = true
  225. console.log('开门失败');
  226. // this.stepList[2].error = true
  227. }
  228. },
  229. // 测试刷卡
  230. async swipe() {
  231. const {
  232. data: res
  233. } = await uni.$http.post('/api/v1/test/bluetooth/queryOpenDoorRes', {
  234. deviceId: this.room.deviceId,
  235. type: 5,
  236. })
  237. // console.log(res);
  238. if (res.data.cardOpenDoorRes === true) {
  239. // this.current1 = 3
  240. this.cardPass = true
  241. this.flag = 5
  242. console.log('开门记录');
  243. // uni.$u.toast(`刷卡开门成功`)
  244. } else {
  245. // this.stepList[2].error = true
  246. }
  247. },
  248. radioChange(n) {
  249. console.log(n);
  250. if (n) {
  251. this.current1 = 4
  252. this.show7 = false
  253. this.flag = 6
  254. } else {
  255. this.stepList[3].error = true
  256. this.show7 = false
  257. }
  258. // this.show7 = false
  259. },
  260. async uploadTest() {
  261. uni.showLoading({
  262. title: "正在上传本次测试结果",
  263. icon: 'none'
  264. })
  265. let {
  266. data: res
  267. } = await uni.$http.post('/api/v1/test/testResult', this.uploadMsg)
  268. uni.hideLoading()
  269. console.log(res);
  270. if (res.code == 200) {
  271. // uni.showToast({
  272. // icon: 'none',
  273. // title: '上传成功',
  274. // duration: 2000
  275. // })
  276. this.$u.toast(`上传成功`)
  277. // this.uploadBtn = true
  278. setTimeout(() => {
  279. this.resetDevice()
  280. }, 2000)
  281. // uni.switchTab({
  282. // url: "/pages/bluetooth/bluetooth"
  283. // })
  284. } else {
  285. uni.$showMsg('上传失败')
  286. }
  287. },
  288. // 重置设备
  289. async resetDevice() {
  290. uni.showLoading({
  291. icon: 'none',
  292. title: '正在重置设备',
  293. })
  294. let {
  295. data: res
  296. } = await uni.$http.post('/api/v1/test/bluetooth/resetDevice', {
  297. deviceId: this.uploadMsg.deviceId
  298. })
  299. console.log(res);
  300. uni.hideLoading()
  301. if (res.code == 200) {
  302. this.$u.toast(`重置成功`)
  303. uni.switchTab({
  304. url:"/pages/bluetooth/bluetooth"
  305. })
  306. } else {
  307. // this.$u.toast(`重置失败`)
  308. this.resetDevice()
  309. // uni.showModal({
  310. // title: '提示',
  311. // content: '设备重置失败,点击确定继续重置',
  312. // success: function(res) {
  313. // if (res.confirm) {
  314. // this.resetDevice()
  315. // } else if (res.cancel) {
  316. // console.log('用户点击取消');
  317. // }
  318. // }
  319. // });
  320. }
  321. },
  322. uploadTestMsg() {
  323. if (this.flag == 1 || this.flag == 0) {
  324. console.log('失败的案例');
  325. console.log(this.uploadMsg);
  326. if (this.subType == 0 || this.subType == null) {
  327. this.$set(this.uploadMsg, 'subType', 0)
  328. }
  329. this.$set(this.uploadMsg, 'status', 0)
  330. this.$set(this.uploadMsg, 'signalRes', false)
  331. this.$set(this.uploadMsg, 'doorOpenRes', false)
  332. this.$set(this.uploadMsg, 'powerRes', false)
  333. this.$set(this.uploadMsg, 'cardOpenRes', false)
  334. this.$set(this.uploadMsg, 'signalNum', this.signalNum)
  335. this.uploadTest()
  336. }
  337. if (this.flag == 2) {
  338. if (this.subType == 0 || this.subType == null) {
  339. this.$set(this.uploadMsg, 'subType', 0)
  340. }
  341. this.$set(this.uploadMsg, 'status', 0)
  342. this.$set(this.uploadMsg, 'signalRes', true)
  343. this.$set(this.uploadMsg, 'signalNum', this.signalNum)
  344. this.$set(this.uploadMsg, 'doorOpenRes', false)
  345. this.$set(this.uploadMsg, 'powerRes', false)
  346. this.$set(this.uploadMsg, 'cardOpenRes', false)
  347. this.uploadTest()
  348. }
  349. if (this.flag == 3 || this.flag == 4) {
  350. if (this.subType == 0 || this.subType == null) {
  351. this.$set(this.uploadMsg, 'subType', 0)
  352. }
  353. this.$set(this.uploadMsg, 'status', 0)
  354. this.$set(this.uploadMsg, 'signalRes', true)
  355. this.$set(this.uploadMsg, 'doorOpenRes', true)
  356. this.$set(this.uploadMsg, 'signalNum', this.signalNum)
  357. this.$set(this.uploadMsg, 'powerRes', false)
  358. this.$set(this.uploadMsg, 'cardOpenRes', false)
  359. this.uploadTest()
  360. }
  361. if (this.flag == 5) {
  362. if (this.subType == 0 || this.subType == null) {
  363. this.$set(this.uploadMsg, 'subType', 0)
  364. }
  365. this.$set(this.uploadMsg, 'signalNum', this.signalNum)
  366. this.$set(this.uploadMsg, 'status', 0)
  367. this.$set(this.uploadMsg, 'signalRes', true)
  368. this.$set(this.uploadMsg, 'doorOpenRes', true)
  369. this.$set(this.uploadMsg, 'powerRes', false)
  370. this.$set(this.uploadMsg, 'cardOpenRes', true)
  371. console.log(this.uploadMsg);
  372. this.uploadTest()
  373. }
  374. if (this.flag == 6) {
  375. if (this.subType == 0 || this.subType == null) {
  376. this.$set(this.uploadMsg, 'subType', 0)
  377. }
  378. this.$set(this.uploadMsg, 'status', 1)
  379. this.$set(this.uploadMsg, 'signalRes', true)
  380. this.$set(this.uploadMsg, 'doorOpenRes', true)
  381. this.$set(this.uploadMsg, 'powerRes', true)
  382. this.$set(this.uploadMsg, 'cardOpenRes', true)
  383. this.$set(this.uploadMsg, 'powerNum', this.powerNum)
  384. console.log(this.uploadMsg);
  385. this.uploadTest()
  386. }
  387. // else {
  388. // console.log('失败的案例');
  389. // console.log(this.uploadMsg);
  390. // this.$set(this.uploadMsg, 'status', 0)
  391. // this.uploadTest()
  392. // }
  393. },
  394. doorCard() {
  395. uni.showLoading({
  396. title: "请刷卡",
  397. icon: "none"
  398. })
  399. this.swipe()
  400. let counter = 0
  401. this.timer = setInterval(() => {
  402. if (this.interrupt) {
  403. clearInterval(this.timer)
  404. return
  405. }
  406. console.log(counter);
  407. // 一分钟之后不再自动调取接口
  408. if (counter == 11) {
  409. uni.hideLoading()
  410. clearInterval(this.timer)
  411. this.$u.toast(`检测到未刷卡`)
  412. this.stepList[2].error = true
  413. return
  414. }
  415. if (this.cardPass == true) {
  416. uni.hideLoading()
  417. this.current1 = 3
  418. this.show7 = true
  419. clearInterval(this.timer)
  420. return
  421. }
  422. counter++
  423. this.swipe()
  424. }, 5000)
  425. }
  426. },
  427. onUnload() {
  428. console.log('我是页面卸载函数');
  429. this.flag = 22
  430. },
  431. onLoad(option) {
  432. this.uploadMsg.testProjectId=uni.getStorageSync('testProjectId')
  433. this.gatewayDeviceId=uni.getStorageSync('gatewayDeviceId')
  434. console.log(option);
  435. let item = JSON.parse(option.item)
  436. console.log(item);
  437. this.subType = item.subType
  438. this.signalNum = item.signalNum
  439. this.uploadMsg.deviceId = item.deviceId
  440. this.uploadMsg.type = item.type
  441. this.room.deviceId = item.deviceId
  442. const obj = {
  443. testProjectId: uni.getStorageSync('testProjectId'),
  444. deviceId: item.deviceId
  445. }
  446. this.testGateway().then(() => {
  447. if (this.flag != 1 || this.interrupt) {
  448. return
  449. }
  450. this.testSignal(obj).then(() => {
  451. if (this.flag != 2 || this.interrupt) {
  452. return
  453. }
  454. this.openDoor().then(() => {
  455. if (this.flag != 3 || this.interrupt) {
  456. return
  457. }
  458. this.updataTime().then(() => {
  459. if (this.flag != 4 || this.interrupt) {
  460. return
  461. }
  462. this.doorCard()
  463. })
  464. })
  465. })
  466. })
  467. },
  468. }
  469. </script>
  470. <style lang="scss">
  471. .steps {
  472. display: flex;
  473. justify-content: center;
  474. align-items: center;
  475. .u-steps-item {
  476. height: 25vh;
  477. width: calc(100vw - 20px);
  478. margin: 30px 10px;
  479. // background-color: red;
  480. .u-steps-item__line {
  481. height: 100px !important;
  482. }
  483. }
  484. // .u-steps-item {
  485. // width: 100vw;
  486. // height: 25vh;
  487. // background-color: blue;
  488. // }
  489. }
  490. .upload {
  491. position: fixed;
  492. bottom: 0;
  493. width: 100vw;
  494. }
  495. .power {
  496. text-align: center;
  497. margin: 13px 0 20px 0;
  498. }
  499. .inputNum {
  500. display: flex;
  501. justify-content: center;
  502. align-items: center;
  503. padding: 0 20rpx;
  504. }
  505. .u-radio-group {
  506. margin-top: 20rpx;
  507. }
  508. </style>
  509. <!-- this.timer = setInterval(() => {
  510. this.current1++
  511. console.log(this.current1);
  512. if (this.current1 === 2) {
  513. this.btnShow = false
  514. }
  515. if (this.current1 === 3) {
  516. uni.showLoading({
  517. title: '加载中',
  518. mask: true
  519. });
  520. uni.hideLoading()
  521. this.stepList[3].error = true
  522. clearInterval(this.timer)
  523. }
  524. }, 3000) -->