bluetooth.vue 13 KB

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