bluetooth.vue 14 KB

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