bluetooth.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. <template>
  2. <view class="content">
  3. <view class="tabs">
  4. <u-tabs :list="tabList" @click="change" lineWidth="30" lineColor="#02A7F0" :activeStyle="{
  5. color: '#02A7F0',
  6. fontWeight: 'bold',
  7. transform:'scale(1.05)'
  8. }" :inactiveStyle="{
  9. color: '#000000',
  10. transform:'scale(1)'}" itemStyle="height: 50px; width: 33.3%;padding:0;border-bottom:1px solid #a0a0a0"></u-tabs>
  11. </view>
  12. <u-skeleton :animate="true" rows="17" title :loading='loading_skeleton'>
  13. <scroll-view scroll-y="true" :style="'height:'+wh+'px;'" @scrolltolower="scrolltolower">
  14. <u-swipe-action btn-width="500">
  15. <u-swipe-action-item :options="options1" @click="click(item.id)"
  16. v-for="(item,index) in productList" :key="index">
  17. <view class="list-items">
  18. <view class="list-item" @click="toText(item)">
  19. <view class="left">
  20. <!-- 左 -->
  21. <view class="icon">
  22. <u-icon v-if="item.type!==0" name="lock-opened-fill" color="#3c9cff"
  23. size="25"></u-icon>
  24. <u-icon v-else name="eye-fill" color="#3c9cff" size="25"></u-icon>
  25. </view>
  26. <!-- 中 -->
  27. <view class="msg">
  28. <view class="id">
  29. {{item.deviceId}}
  30. </view>
  31. <view class="type">
  32. <text style="margin-right: 5px;">{{item.testTime|date}}</text>
  33. <text>信号值:{{item.signalNum}}</text>
  34. </view>
  35. </view>
  36. </view>
  37. <!-- 后 -->
  38. <view class="button" @click.stop="textBtn(item)">
  39. <u-button v-if="item.type==0" type="primary" size="small">风鸣</u-button>
  40. <u-button v-else type="primary" size="small">开门</u-button>
  41. </view>
  42. </view>
  43. </view>
  44. </u-swipe-action-item>
  45. <!-- <view v-else class="noData" style="text-align: center;">
  46. 无数据
  47. </view> -->
  48. </u-swipe-action>
  49. </scroll-view>
  50. </u-skeleton>
  51. <view class="btn">
  52. <u-button size="large" type="primary" @click="search"> 点击进行蓝牙设备搜索</u-button>
  53. </view>
  54. <view class="scan" @click="scan">
  55. <img src="@/static/scan.png" alt="" style="width: 100rpx;height: 80rpx;">
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. export default {
  61. data() {
  62. return {
  63. loading_skeleton: false,
  64. gatewayFlag: 0,
  65. options1: [{
  66. text: '删除',
  67. style: {
  68. backgroundColor: '#f56c6c'
  69. }
  70. }],
  71. wh: '',
  72. active: 0,
  73. tabList: [{
  74. name: '未检测',
  75. badge: {
  76. value: null,
  77. }
  78. }, {
  79. name: '检测失败',
  80. badge: {
  81. value: null,
  82. }
  83. }, {
  84. name: '检测成功',
  85. badge: {
  86. value: null,
  87. }
  88. },
  89. ],
  90. parameter: {
  91. testProjectId: null,
  92. pageSize: 1000,
  93. pageNo: 1,
  94. status:2
  95. },
  96. total: 0,
  97. productList: [
  98. ]
  99. }
  100. },
  101. methods: {
  102. scrolltolower() {
  103. // console.log('触底了');
  104. if (this.parameter.pageNo * this.parameter.pageSize >= this.total) {
  105. return uni.$showMsg('数据加载完毕')
  106. }
  107. this.parameter.pageNo++
  108. this.getBluetoothList()
  109. },
  110. toText(item) {
  111. console.log(item);
  112. uni.showModal({
  113. title: '温馨提示',
  114. content: "点击确定进入测试阶段",
  115. success: res => {
  116. if (res.confirm) {
  117. // this.show1 = false
  118. // this.$u.toast(`点击了确定`)
  119. let currentSite = JSON.stringify(item)
  120. // console.log(item);
  121. if (item.type === 0) {
  122. console.log('猫眼');
  123. console.log(item);
  124. uni.navigateTo({
  125. url: "/pages/cat-eye-test/cat-eye-test?item=" + currentSite
  126. })
  127. } else if (item.type == 1 && item.subType == 0 || item.subType == null) {
  128. uni.navigateTo({
  129. url: "/pages/lock-test/lock-test?item=" + currentSite
  130. })
  131. } else {
  132. uni.navigateTo({
  133. url: "/pages/door-lock-module/door-lock-module?item=" +
  134. currentSite
  135. })
  136. }
  137. } else {
  138. // this.$u.toast(`点击了取消`)
  139. }
  140. }
  141. })
  142. },
  143. async textBtn(item) {
  144. uni.showLoading({
  145. mask: true,
  146. title: '命令执行中',
  147. })
  148. if (item.type === 0) {
  149. console.log('我是猫眼');
  150. const {
  151. data: res
  152. } = await uni.$http.post('/api/v1/test/bluetooth/testCam', {
  153. deviceId: item.deviceId
  154. })
  155. if (res.code === 200) {
  156. uni.$showMsg('风鸣测试成功')
  157. } else {
  158. uni.$showMsg('测试失败')
  159. }
  160. } else {
  161. const {
  162. data: res
  163. } = await uni.$http.post('/api/v1/test/bluetooth/openDoor', {
  164. deviceId: item.deviceId
  165. })
  166. if (res.code === 200) {
  167. this.$u.toast(`开门测试成功`)
  168. } else {
  169. uni.$showMsg('测试失败')
  170. }
  171. }
  172. },
  173. change(index) {
  174. // this.current = index;
  175. // console.log(index.index);
  176. let current = index.index
  177. if (current == 0) {
  178. this.productList = []
  179. this.parameter.pageNo = 1
  180. this.parameter.status = 2
  181. // delete this.parameter.status
  182. this.getBluetoothList()
  183. console.log('待检查');
  184. } else if (current == 1) {
  185. this.productList = []
  186. this.parameter.pageNo = 1
  187. this.parameter.status = 0
  188. this.getBluetoothList()
  189. } else {
  190. this.productList = []
  191. this.parameter.pageNo = 1
  192. this.parameter.status = 1
  193. this.getBluetoothList()
  194. }
  195. },
  196. async scan() {
  197. uni.showLoading({
  198. title: "正在获取蓝牙设备",
  199. icon: 'none'
  200. })
  201. console.log('扫一扫');
  202. let arr = []
  203. const {
  204. data: res
  205. } = await uni.$http.post('/api/v1/test/testResult/queryByCondition', {
  206. testProjectId: uni.getStorageSync("testProjectId"),
  207. pageSize: 100,
  208. pageNo: 1,
  209. status: 2
  210. }, )
  211. uni.hideLoading()
  212. let that = this
  213. if (res.code == 200) {
  214. arr = res.data.records
  215. console.log(arr);
  216. uni.scanCode({
  217. scanType: ['barCode', 'qrCode'],
  218. success: function(res) {
  219. console.log('条码类型:' + res.scanType);
  220. console.log('条码内容:' + res.result);
  221. console.log(arr, 'arr的数据');
  222. let arr1 = arr.find((item) => {
  223. return item.deviceId == res.result.toLowerCase()
  224. })
  225. console.log(arr1, 'arr1的msg');
  226. let scanDeviced = JSON.stringify(arr1)
  227. if (!arr1) {
  228. return that.$u.toast(`未获取到设备信息`)
  229. } else {
  230. if (arr1.type == 0) {
  231. console.log('我是猫眼');
  232. uni.navigateTo({
  233. url: "/pages/cat-eye-test/cat-eye-test?item=" +
  234. scanDeviced
  235. })
  236. } else if (arr1.type == 1 && arr1.subType == 0 || arr1.subType ==
  237. null) {
  238. console.log('我是门锁');
  239. uni.navigateTo({
  240. url: "/pages/lock-test/lock-test?item=" + scanDeviced
  241. })
  242. } else {
  243. console.log('我是模块');
  244. uni.navigateTo({
  245. url: "/pages/door-lock-module/door-lock-module?item=" +
  246. scanDeviced
  247. })
  248. }
  249. }
  250. // if (arr1) {
  251. // uni.showToast({
  252. // icon: "error",
  253. // title: "未找到该设备"
  254. // })
  255. // } else {
  256. // if (arr1.type == 0) {
  257. // console.log(2);
  258. // uni.navigateTo({
  259. // url: "/pages/cat-eye-test/cat-eye-test?item=" +
  260. // scanDeviced
  261. // })
  262. // } else if (arr1.type == 1 && arr1.subType == 0 || arr1.subType ==
  263. // null) {
  264. // uni.navigateTo({
  265. // url: "/pages/lock-test/lock-test?item=" + scanDeviced
  266. // })
  267. // } else {
  268. // uni.navigateTo({
  269. // url: "/pages/door-lock-module/door-lock-module?item=" +
  270. // scanDeviced
  271. // })
  272. // }
  273. // }
  274. }
  275. });
  276. } else {
  277. this.$u.toast(`请重新获取蓝牙设备`)
  278. }
  279. },
  280. search() {
  281. this.searchBluetooth().then(() => {
  282. this.parameter.pageNo = 1
  283. this.productList = []
  284. this.getBluetoothList()
  285. })
  286. // console.log('点击了搜索');
  287. // this.productList = []
  288. // this.parameter.pageNo = 1
  289. // this.getBluetoothList()
  290. },
  291. // 右滑删除
  292. click(index) {
  293. console.log('click', index);
  294. uni.showModal({
  295. title: '温馨提示',
  296. content: '确定要删除吗?',
  297. success: async res => {
  298. if (res.confirm) {
  299. // this.show1 = false
  300. // this.$u.toast(`点击了确定`)
  301. uni.showLoading({
  302. mask: true,
  303. title: '正在删除中'
  304. })
  305. let {
  306. data: res
  307. } = await uni.$http.delete(`/api/v1/test/testResult/${index}`)
  308. console.log(res);
  309. if (res.code == 200) {
  310. this.productList = []
  311. this.getBluetoothList().then(() => {
  312. this.getNum()
  313. })
  314. } else {
  315. this.$u.toast(`删除失败`)
  316. }
  317. } else {
  318. // this.$u.toast(`点击了取消`)
  319. }
  320. }
  321. })
  322. },
  323. async getBluetoothList() {
  324. if (!uni.getStorageSync('testProjectId')) {
  325. return this.$u.toast(`未查询到测试项目,请前往后台添加测试项目`)
  326. }
  327. this.loading_skeleton = true
  328. console.log(11);
  329. this.gatewayFlag = 0
  330. // uni.showLoading({
  331. // mask: true,
  332. // title: '数据加载中'
  333. // })
  334. const {
  335. data: res
  336. } = await uni.$http.post('/api/v1/test/testResult/queryByCondition', this.parameter)
  337. uni.hideLoading()
  338. console.log(res);
  339. if (res.code === 200) {
  340. // this.getNum()
  341. // let badge1 = res.data.records.filter((item) => {
  342. // return item.status = 2
  343. // })
  344. // console.log(badge1);
  345. // this.total = res.data.total
  346. // if (this.parameter.status == 2) {
  347. // this.tabList[0].badge.value = res.data.total
  348. // } else if (this.parameter.status == 0) {
  349. // this.tabList[1].badge.value = res.data.total
  350. // } else if (this.parameter.status == 1) {
  351. // this.tabList[2].badge.value = res.data.total
  352. // }
  353. uni.$showMsg('数据加载成功')
  354. this.loading_skeleton = false
  355. this.productList = []
  356. this.productList = [
  357. ...this.productList,
  358. ...res.data.records
  359. ]
  360. } else {
  361. // uni.$showMsg('数据加载失败')
  362. console.log('数据加载失败');
  363. this.loading_skeleton = false
  364. }
  365. // console.log(this.productList);
  366. },
  367. async searchBluetooth() {
  368. this.productList = []
  369. uni.showLoading({
  370. mask: true,
  371. title: "网关扫描中",
  372. icon: 'none'
  373. })
  374. console.log(this.parameter.testProjectId);
  375. const {
  376. data: res
  377. } = await uni.$http.post('/api/v1/test/testProject/bluetooth/search', {
  378. testProjectId: this.parameter.testProjectId
  379. })
  380. if (res.code == 200) {
  381. this.gatewayFlag = 1
  382. uni.hideLoading()
  383. // this.$u.toast(`网关扫描成功`)
  384. } else {
  385. this.$u.toast(`网关失败,点击按钮重新扫描`)
  386. }
  387. console.log(res);
  388. },
  389. async getNum() {
  390. if (!uni.getStorageSync('testProjectId')) {
  391. return this.$u.toast(`未查询到测试项目,请前往后台添加测试项目`)
  392. }
  393. const {
  394. data: res
  395. } = await uni.$http.post('/api/v1/test/testResult/queryByCondition', {
  396. testProjectId: uni.getStorageSync("testProjectId"),
  397. pageSize: 100,
  398. pageNo: 1
  399. }, )
  400. this.gatewayFlag = 1
  401. let badge1 = res.data.records.filter((item) => {
  402. return item.status == 2
  403. })
  404. console.log(res.data.total, 'sea')
  405. let badge2 = res.data.records.filter((item) => {
  406. return item.status == 1
  407. })
  408. let badge3 = res.data.records.filter((item) => {
  409. return item.status == 0
  410. })
  411. this.tabList[0].badge.value = badge1.length
  412. this.tabList[1].badge.value = badge3.length
  413. this.tabList[2].badge.value = badge2.length
  414. }
  415. },
  416. onShow() {
  417. this.parameter.testProjectId = uni.getStorageSync('testProjectId')
  418. this.getNum().then(() => {
  419. if (this.gatewayFlag == 1) {
  420. this.getBluetoothList()
  421. }
  422. })
  423. },
  424. onLoad() {
  425. let btn = uni.createSelectorQuery().in(this).select('.btn')
  426. btn.boundingClientRect(data => {
  427. let btnH = data.height
  428. // console.log(this.searchH)
  429. console.log(sysInfo.windowHeight - btnH - 50);
  430. this.wh = sysInfo.windowHeight - btnH - 50
  431. // console.log(this.wh);
  432. }).exec()
  433. const sysInfo = uni.getSystemInfoSync()
  434. console.log(this.parameter.testProjectId);
  435. // this.getNum()
  436. // this.searchBluetooth().then(() => {
  437. // if (this.gatewayFlag = 1) {
  438. // this.getBluetoothList()
  439. // }
  440. // })
  441. },
  442. }
  443. </script>
  444. <style lang="scss">
  445. // .tabs {
  446. // height: 100rpx;
  447. // display: flex;
  448. // justify-content: space-around;
  449. // align-items: center;
  450. // border-bottom: 1px solid #a0a0a0;
  451. // // background-color: red;
  452. // .tab-item {
  453. // border: 3px solid transparent;
  454. // padding-bottom: 10rpx;
  455. // // background-color: red;
  456. // &.active {
  457. // border-bottom: 3px solid #24acf2;
  458. // color: #1296db;
  459. // }
  460. // }
  461. // }
  462. .tabs {
  463. .u-tabs__wrapper__nav__line {
  464. display: none;
  465. // margin-left: -40rpx;
  466. }
  467. }
  468. .btn {
  469. position: fixed;
  470. bottom: 0;
  471. width: 100%;
  472. }
  473. .scan {
  474. z-index: 9999;
  475. position: fixed;
  476. width: 120rpx;
  477. height: 120rpx;
  478. background-color: #3c9cff;
  479. bottom: 200rpx;
  480. right: 20vw;
  481. border-radius: 50%;
  482. display: flex;
  483. justify-content: center;
  484. align-items: center;
  485. }
  486. .u-page__tag-item {
  487. margin-right: 40px;
  488. margin-top: 10px;
  489. }
  490. .u-demo-block__content {
  491. flex-direction: row;
  492. flex-wrap: wrap;
  493. align-items: center;
  494. }
  495. .list-item {
  496. width: calc(100vw - 20px);
  497. // margin: 28rpx 10px;
  498. // padding-bottom: 10rpx;
  499. padding: 28rpx 10px;
  500. display: flex;
  501. justify-content: space-between;
  502. align-items: center;
  503. border-bottom: 1px solid #a0a0a0;
  504. .left {
  505. display: flex;
  506. justify-content: center;
  507. align-items: center;
  508. .id {
  509. font-size: 14px
  510. }
  511. .type {
  512. text {
  513. margin-right: 5rpx;
  514. color: #a0a0a0;
  515. font-size: 12px
  516. }
  517. }
  518. .icon {
  519. margin-right: 10rpx;
  520. }
  521. }
  522. }
  523. </style>