door-lock-module.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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"
  35. @change="changeInput"></u--input>
  36. </view>
  37. <u-radio-group placement="row">
  38. <u-radio :customStyle="{margin: '15px 30px'}" v-for="(item, index) in radiolist1" :key="index"
  39. :label="item.value" :name="item.powerRefs" @change="radioChange" iconPlacement="right">
  40. </u-radio>
  41. </u-radio-group>
  42. </view>
  43. </u-popup>
  44. </view>
  45. </template>
  46. <script>
  47. export default {
  48. data() {
  49. return {
  50. powerNum: 160,
  51. subType:null,
  52. uploadBtn: false,
  53. uploadMsg: {
  54. testProjectId: uni.getStorageSync('testProjectId'),
  55. deviceId: "",
  56. type: null
  57. },
  58. radiolist1: [{
  59. value: '通过',
  60. disabled: false,
  61. powerRefs: true
  62. },
  63. {
  64. value: '不通过',
  65. disabled: false,
  66. powerRefs: false
  67. }
  68. ],
  69. show7: false,
  70. flag: 0,
  71. timer: null,
  72. signalNum: '',
  73. gatewayDeviceId: uni.getStorageSync('gatewayDeviceId'),
  74. show: false,
  75. current1: null,
  76. stepList: [{
  77. id: 0,
  78. title: '测试信号',
  79. desc: '测试蓝牙设备信号值是否通过',
  80. error: false
  81. }, {
  82. id: 1,
  83. title: '蓝牙测试开门',
  84. desc: '测试蓝牙进行门锁开门',
  85. error: false
  86. },
  87. {
  88. id: 2,
  89. title: '测试功率',
  90. desc: '验证功耗是否通过',
  91. error: false
  92. }
  93. ]
  94. }
  95. },
  96. methods: {
  97. changeInput(e) {
  98. console.log(e);
  99. },
  100. leftClick() {
  101. let a = this.stepList.every((item) => {
  102. return item.error == true
  103. })
  104. console.log(a);
  105. if (a) {
  106. console.log('模态框');
  107. uni.hideLoading()
  108. uni.showModal({
  109. title: '温馨提示',
  110. content: '确定取消上传本次测试信息吗?',
  111. success: res => {
  112. if (res.confirm) {
  113. // this.show1 = false
  114. this.$u.toast(`点击了确定`)
  115. this.flag = 99
  116. // console.log(this.flag);
  117. uni.navigateBack({
  118. delta: 1
  119. })
  120. } else {
  121. // this.$u.toast(`点击了取消`)
  122. }
  123. }
  124. })
  125. } else {
  126. uni.navigateBack({
  127. delta: 1
  128. })
  129. }
  130. },
  131. // 测试网关连接
  132. async testGateway() {
  133. uni.showLoading({
  134. mask: true,
  135. title: '正在测试网关连接',
  136. icon: 'none'
  137. })
  138. const {
  139. data: res
  140. } = await uni.$http.get(`/api/v1/test/gateway/connection/${this.gatewayDeviceId}`)
  141. uni.hideLoading()
  142. if (res.data.isConnect == true) {
  143. this.flag = 1
  144. console.log('网关连接成功');
  145. } else {
  146. console.log('网关连接失败');
  147. this.$u.toast(`网关连接失败`)
  148. }
  149. },
  150. // 测试信号
  151. async testSignal(obj) {
  152. uni.showLoading({
  153. mask: true,
  154. title: '正在测试信号',
  155. icon: 'none'
  156. })
  157. const {
  158. data: res
  159. } = await uni.$http.post('/api/v1/test/bluetooth/checkSignal', obj)
  160. uni.hideLoading()
  161. if (res.data.isNormal == true) {
  162. this.current1 = 1
  163. this.flag = 2
  164. console.log('信号测试成功');
  165. } else {
  166. this.stepList[0].error = true
  167. console.log('信号测试失败');
  168. this.$u.toast(`信号测试失败`)
  169. }
  170. },
  171. // 测试开门
  172. async openDoor() {
  173. uni.showLoading({
  174. mask: true,
  175. title: '蓝牙开门测试中',
  176. icon: 'none'
  177. })
  178. const {
  179. data: res
  180. } = await uni.$http.post('/api/v1/test/bluetooth/openDoor', {
  181. deviceId: this.uploadMsg.deviceId
  182. })
  183. uni.hideLoading()
  184. if (res.code == 200) {
  185. this.current1 = 2
  186. this.flag = 3
  187. // uni.$u.toast(`开门成功`)
  188. this.show7 = true
  189. console.log('开门成功');
  190. } else {
  191. this.stepList[1].error = true
  192. console.log('开门失败');
  193. }
  194. },
  195. radioChange(n) {
  196. console.log(n);
  197. if (n) {
  198. this.current1 = 3
  199. this.show7 = false
  200. this.flag = 4
  201. } else {
  202. this.stepList[2].error = true
  203. this.show7 = false
  204. }
  205. // this.show7 = false
  206. },
  207. async uploadTest() {
  208. uni.showLoading({
  209. mask: true,
  210. title: "正在上传本次测试结果",
  211. icon: 'none'
  212. })
  213. let {
  214. data: res
  215. } = await uni.$http.post('/api/v1/test/testResult', this.uploadMsg)
  216. uni.hideLoading()
  217. console.log(res);
  218. if (res.code == 200) {
  219. uni.$showMsg('上传成功')
  220. // this.uploadBtn = true
  221. setTimeout(() => {
  222. this.resetDevice()
  223. }, 1500)
  224. // uni.switchTab({
  225. // url: "/pages/bluetooth/bluetooth"
  226. // })
  227. } else {
  228. uni.$showMsg('上传失败')
  229. }
  230. },
  231. uploadTestMsg() {
  232. if (this.flag == 1 || this.flag == 0) {
  233. console.log('失败的案例');
  234. console.log(this.uploadMsg);
  235. if(this.subType==1){
  236. this.$set(this.uploadMsg, 'subType', this.subType)
  237. }
  238. this.$set(this.uploadMsg, 'signalNum', this.signalNum)
  239. this.$set(this.uploadMsg, 'status', 0)
  240. this.$set(this.uploadMsg, 'signalRes', false)
  241. this.$set(this.uploadMsg, 'doorOpenRes', false)
  242. this.$set(this.uploadMsg, 'powerRes', false)
  243. this.uploadTest()
  244. }
  245. if (this.flag == 2) {
  246. if(this.subType==1){
  247. this.$set(this.uploadMsg, 'subType', this.subType)
  248. }
  249. this.$set(this.uploadMsg, 'signalNum', this.signalNum)
  250. this.$set(this.uploadMsg, 'status', 0)
  251. this.$set(this.uploadMsg, 'signalRes', true)
  252. this.$set(this.uploadMsg, 'doorOpenRes', false)
  253. this.$set(this.uploadMsg, 'powerRes', false)
  254. this.uploadTest()
  255. }
  256. if (this.flag == 3) {
  257. if(this.subType==1){
  258. this.$set(this.uploadMsg, 'subType', this.subType)
  259. }
  260. this.$set(this.uploadMsg, 'signalNum', this.signalNum)
  261. this.$set(this.uploadMsg, 'status', 0)
  262. this.$set(this.uploadMsg, 'signlRes', true)
  263. this.$set(this.uploadMsg, 'doorOpenRes', true)
  264. this.$set(this.uploadMsg, 'powerRes', false)
  265. this.uploadTest()
  266. }
  267. if (this.flag == 4) {
  268. if(this.subType==1){
  269. this.$set(this.uploadMsg, 'subType', this.subType)
  270. }
  271. this.$set(this.uploadMsg, 'signalNum', this.signalNum)
  272. this.$set(this.uploadMsg, 'status', 1)
  273. this.$set(this.uploadMsg, 'signlRes', true)
  274. this.$set(this.uploadMsg, 'doorOpenRes', true)
  275. this.$set(this.uploadMsg, 'powerRes', true)
  276. this.$set(this.uploadMsg, 'powerNum', this.powerNum)
  277. console.log(this.uploadMsg);
  278. this.uploadTest()
  279. }
  280. // else {
  281. // console.log('失败的案例');
  282. // console.log(this.uploadMsg);
  283. // this.$set(this.uploadMsg, 'status', 0)
  284. // this.uploadTest()
  285. // }
  286. },
  287. async resetDevice() {
  288. uni.showLoading({
  289. icon: 'none',
  290. title: '正在重置设备',
  291. })
  292. let {
  293. data: res
  294. } = await uni.$http.post('/api/v1/test/bluetooth/resetDevice', {
  295. deviceId: this.uploadMsg.deviceId
  296. })
  297. console.log(res);
  298. uni.hideLoading()
  299. if (res.code == 200) {
  300. this.$u.toast(`重置成功`)
  301. } else {
  302. this.$u.toast(`重置失败`)
  303. }
  304. },
  305. },
  306. onLoad(option) {
  307. let item = JSON.parse(option.item)
  308. console.log(item);
  309. this.subType=item.subType
  310. this.signalNum = item.signalNum
  311. this.uploadMsg.deviceId = item.deviceId
  312. this.uploadMsg.type = item.type
  313. // this.room.deviceId = item.deviceId
  314. const obj = {
  315. testProjectId: uni.getStorageSync('testProjectId'),
  316. deviceId: item.deviceId
  317. }
  318. this.testGateway().then(() => {
  319. if (this.flag != 1) {
  320. return
  321. }
  322. this.testSignal(obj).then(() => {
  323. if (this.flag != 2) {
  324. return
  325. }
  326. this.openDoor().then(() => {
  327. // if (this.flag != 3) {
  328. // return
  329. // }
  330. })
  331. })
  332. })
  333. },
  334. }
  335. </script>
  336. <style lang="scss">
  337. .steps {
  338. display: flex;
  339. justify-content: center;
  340. align-items: center;
  341. .u-steps-item {
  342. height: 25vh;
  343. width: calc(100vw - 20px);
  344. margin: 30px 10px;
  345. // background-color: red;
  346. .u-steps-item__line {
  347. height: 100px !important;
  348. }
  349. }
  350. // .u-steps-item {
  351. // width: 100vw;
  352. // height: 25vh;
  353. // background-color: blue;
  354. // }
  355. }
  356. .upload {
  357. position: fixed;
  358. bottom: 0;
  359. width: 100vw;
  360. }
  361. .power {
  362. text-align: center;
  363. margin: 13px 0 20px 0;
  364. }
  365. .inputNum {
  366. display: flex;
  367. justify-content: center;
  368. align-items: center;
  369. padding: 0 20rpx;
  370. }
  371. .u-radio-group {
  372. margin-top: 20rpx;
  373. }
  374. </style>
  375. <!-- this.timer = setInterval(() => {
  376. this.current1++
  377. console.log(this.current1);
  378. if (this.current1 === 2) {
  379. this.btnShow = false
  380. }
  381. if (this.current1 === 3) {
  382. uni.showLoading({
  383. title: '加载中',
  384. mask: true
  385. });
  386. uni.hideLoading()
  387. this.stepList[3].error = true
  388. clearInterval(this.timer)
  389. }
  390. }, 3000) -->