lock-test.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  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: uni.getStorageSync('testProjectId'),
  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: 3,
  77. building: 2,
  78. floor: 7,
  79. room: "7728"
  80. },
  81. gatewayDeviceId: uni.getStorageSync('gatewayDeviceId'),
  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. } else {
  304. this.$u.toast(`重置失败`)
  305. uni.showModal({
  306. title: '提示',
  307. content: '设备重置失败,点击确定继续重置',
  308. success: function(res) {
  309. if (res.confirm) {
  310. this.resetDevice()
  311. } else if (res.cancel) {
  312. console.log('用户点击取消');
  313. }
  314. }
  315. });
  316. }
  317. },
  318. uploadTestMsg() {
  319. if (this.flag == 1 || this.flag == 0) {
  320. console.log('失败的案例');
  321. console.log(this.uploadMsg);
  322. if (this.subType == 0 || this.subType == null) {
  323. this.$set(this.uploadMsg, 'subType', 0)
  324. }
  325. this.$set(this.uploadMsg, 'status', 0)
  326. this.$set(this.uploadMsg, 'signalRes', false)
  327. this.$set(this.uploadMsg, 'doorOpenRes', false)
  328. this.$set(this.uploadMsg, 'powerRes', false)
  329. this.$set(this.uploadMsg, 'cardOpenRes', false)
  330. this.$set(this.uploadMsg, 'signalNum', this.signalNum)
  331. this.uploadTest()
  332. }
  333. if (this.flag == 2) {
  334. if (this.subType == 0 || this.subType == null) {
  335. this.$set(this.uploadMsg, 'subType', 0)
  336. }
  337. this.$set(this.uploadMsg, 'status', 0)
  338. this.$set(this.uploadMsg, 'signalRes', true)
  339. this.$set(this.uploadMsg, 'signalNum', this.signalNum)
  340. this.$set(this.uploadMsg, 'doorOpenRes', false)
  341. this.$set(this.uploadMsg, 'powerRes', false)
  342. this.$set(this.uploadMsg, 'cardOpenRes', false)
  343. this.uploadTest()
  344. }
  345. if (this.flag == 3 || this.flag == 4) {
  346. if (this.subType == 0 || this.subType == null) {
  347. this.$set(this.uploadMsg, 'subType', 0)
  348. }
  349. this.$set(this.uploadMsg, 'status', 0)
  350. this.$set(this.uploadMsg, 'signalRes', true)
  351. this.$set(this.uploadMsg, 'doorOpenRes', true)
  352. this.$set(this.uploadMsg, 'signalNum', this.signalNum)
  353. this.$set(this.uploadMsg, 'powerRes', false)
  354. this.$set(this.uploadMsg, 'cardOpenRes', false)
  355. this.uploadTest()
  356. }
  357. if (this.flag == 5) {
  358. if (this.subType == 0 || this.subType == null) {
  359. this.$set(this.uploadMsg, 'subType', 0)
  360. }
  361. this.$set(this.uploadMsg, 'signalNum', this.signalNum)
  362. this.$set(this.uploadMsg, 'status', 0)
  363. this.$set(this.uploadMsg, 'signalRes', true)
  364. this.$set(this.uploadMsg, 'doorOpenRes', true)
  365. this.$set(this.uploadMsg, 'powerRes', false)
  366. this.$set(this.uploadMsg, 'cardOpenRes', true)
  367. console.log(this.uploadMsg);
  368. this.uploadTest()
  369. }
  370. if (this.flag == 6) {
  371. if (this.subType == 0 || this.subType == null) {
  372. this.$set(this.uploadMsg, 'subType', 0)
  373. }
  374. this.$set(this.uploadMsg, 'status', 1)
  375. this.$set(this.uploadMsg, 'signlRes', true)
  376. this.$set(this.uploadMsg, 'doorOpenRes', true)
  377. this.$set(this.uploadMsg, 'powerRes', true)
  378. this.$set(this.uploadMsg, 'cardOpenRes', true)
  379. this.$set(this.uploadMsg, 'powerNum', this.powerNum)
  380. console.log(this.uploadMsg);
  381. this.uploadTest()
  382. }
  383. // else {
  384. // console.log('失败的案例');
  385. // console.log(this.uploadMsg);
  386. // this.$set(this.uploadMsg, 'status', 0)
  387. // this.uploadTest()
  388. // }
  389. },
  390. doorCard() {
  391. uni.showLoading({
  392. title: "请刷卡",
  393. icon: "none"
  394. })
  395. this.swipe()
  396. let counter = 0
  397. this.timer = setInterval(() => {
  398. if (this.interrupt) {
  399. clearInterval(this.timer)
  400. return
  401. }
  402. console.log(counter);
  403. // 一分钟之后不再自动调取接口
  404. if (counter == 11) {
  405. uni.hideLoading()
  406. clearInterval(this.timer)
  407. this.$u.toast(`检测到未刷卡`)
  408. this.stepList[2].error = true
  409. return
  410. }
  411. if (this.cardPass == true) {
  412. uni.hideLoading()
  413. this.current1 = 3
  414. this.show7 = true
  415. clearInterval(this.timer)
  416. return
  417. }
  418. counter++
  419. this.swipe()
  420. }, 5000)
  421. }
  422. },
  423. onUnload() {
  424. console.log('我是页面卸载函数');
  425. this.flag = 22
  426. },
  427. onLoad(option) {
  428. console.log(option);
  429. let item = JSON.parse(option.item)
  430. console.log(item);
  431. this.subType = item.subType
  432. this.signalNum = item.signalNum
  433. this.uploadMsg.deviceId = item.deviceId
  434. this.uploadMsg.type = item.type
  435. this.room.deviceId = item.deviceId
  436. const obj = {
  437. testProjectId: uni.getStorageSync('testProjectId'),
  438. deviceId: item.deviceId
  439. }
  440. this.testGateway().then(() => {
  441. if (this.flag != 1 || this.interrupt) {
  442. return
  443. }
  444. this.testSignal(obj).then(() => {
  445. if (this.flag != 2 || this.interrupt) {
  446. return
  447. }
  448. this.openDoor().then(() => {
  449. if (this.flag != 3 || this.interrupt) {
  450. return
  451. }
  452. this.updataTime().then(() => {
  453. if (this.flag != 4 || this.interrupt) {
  454. return
  455. }
  456. this.doorCard()
  457. })
  458. })
  459. })
  460. })
  461. },
  462. }
  463. </script>
  464. <style lang="scss">
  465. .steps {
  466. display: flex;
  467. justify-content: center;
  468. align-items: center;
  469. .u-steps-item {
  470. height: 25vh;
  471. width: calc(100vw - 20px);
  472. margin: 30px 10px;
  473. // background-color: red;
  474. .u-steps-item__line {
  475. height: 100px !important;
  476. }
  477. }
  478. // .u-steps-item {
  479. // width: 100vw;
  480. // height: 25vh;
  481. // background-color: blue;
  482. // }
  483. }
  484. .upload {
  485. position: fixed;
  486. bottom: 0;
  487. width: 100vw;
  488. }
  489. .power {
  490. text-align: center;
  491. margin: 13px 0 20px 0;
  492. }
  493. .inputNum {
  494. display: flex;
  495. justify-content: center;
  496. align-items: center;
  497. padding: 0 20rpx;
  498. }
  499. .u-radio-group {
  500. margin-top: 20rpx;
  501. }
  502. </style>
  503. <!-- this.timer = setInterval(() => {
  504. this.current1++
  505. console.log(this.current1);
  506. if (this.current1 === 2) {
  507. this.btnShow = false
  508. }
  509. if (this.current1 === 3) {
  510. uni.showLoading({
  511. title: '加载中',
  512. mask: true
  513. });
  514. uni.hideLoading()
  515. this.stepList[3].error = true
  516. clearInterval(this.timer)
  517. }
  518. }, 3000) -->