AI销管
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

501 lignes
11 KiB

  1. <template>
  2. <view class="bt">
  3. <view class="bt-t1">工牌开机后,须开启手机蓝牙和位置定位搜索</view>
  4. <view class="bt-c1">
  5. <text>蓝牙</text>
  6. <view @click="openBlue()" :class="['bt-sw',connectState?'bt-sw-ac':'']"></view>
  7. </view>
  8. <view class="bt-t2">
  9. 智能工牌开机后2分钟内会发送蓝牙信号,请先开机后并2分钟内搜索设备;如超时请重新开机搜索!或者请重新进入小程序并开启定位功能!
  10. </view>
  11. <!-- <view class="bt-t3">
  12. 输入或搜索需要查询的SN
  13. </view>
  14. <view class="bt-input1">
  15. <view class="bt-input1-c">
  16. <image src="/static/images/bluetooth-search.png" />
  17. <input v-model="keyword" @confirm="getBluetoothDevices" placeholder="请输入设备SN" />
  18. </view>
  19. <image class="scan" @click="ermScan" src="/static/images/bluetooth-scan.png" />
  20. </view> -->
  21. <view class="bt-c2">
  22. <view class="bt-c2-l">我的工牌</view>
  23. <image @click="startBluetoothDevicesDiscovery" src="/static/images/bluetooth-sx.png"
  24. :class="['bt-c2-r',isSearch?'bt-c2-r-ani':'']" />
  25. </view>
  26. <view v-for="(item,index) in blist" :key="index" @click="goDetail(item)" class="bt-c3">
  27. <view class="bt-c3-l">{{item.name}}</view>
  28. <image src="/static/images/jiantop.png" />
  29. </view>
  30. <view class="bt-c2">
  31. <view class="bt-c2-l">已绑定的工牌</view>
  32. </view>
  33. <view v-for="(item,index) in savelist" :key="index" @click="goDetail(item)" @longpress="delOld(index)" class="bt-c3">
  34. <view class="bt-c3-l">
  35. {{item.name}}
  36. <image mode="heightFix" v-if="item.isConnect && item.isConnect == 1" src="/static/images/bluetooth-con.png" />
  37. </view>
  38. <image src="/static/images/jiantop.png" />
  39. </view>
  40. <view v-if="savelist.length > 0" class="bt-c2" style="margin-top: 20rpx;">
  41. <view class="bt-c2-l">长按删除</view>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. import {
  47. serviceId,
  48. closeBlueAdapter,
  49. readCharacteristicId,
  50. writeCharacteristicId
  51. } from "@/utils/blue.js";
  52. import {
  53. mapState,
  54. } from 'vuex';
  55. export default {
  56. data() {
  57. return {
  58. privacyVisible: false,
  59. open: false,
  60. serviceId,
  61. readCharacteristicId,
  62. writeCharacteristicId,
  63. blist: [],
  64. keyword: "",
  65. savelist: [],
  66. isSearch: false
  67. }
  68. },
  69. computed: {
  70. ...mapState(['connectDev', 'connectState']),
  71. },
  72. watch: {
  73. connectDev(newVal) {
  74. this.savelist = this.savelist.filter(v => {
  75. v.isConnect = '0';
  76. if (newVal && v.deviceId == newVal.deviceId) v.isConnect = '1';
  77. if (v.name && v.deviceId) return v;
  78. })
  79. }
  80. },
  81. onShow() {
  82. this.keyword = uni.getStorageSync("imeiCode");
  83. if (this.connectState == true) {
  84. this.getBluetoothDevices();
  85. } else {
  86. this.savelist = this.savelist.filter(v => {
  87. v.isConnect = '0';
  88. if (that.connectDev && v.deviceId == that.connectDev.deviceId) v.isConnect = '1';
  89. if (v.name && v.deviceId) return v;
  90. })
  91. }
  92. },
  93. methods: {
  94. //搜索
  95. ermScan() {
  96. var that = this
  97. uni.scanCode({
  98. success: (res) => {
  99. that.keyword = res.result
  100. that.getBluetoothDevices();
  101. },
  102. fail: (err) => {
  103. console.error('扫码失败:' + err);
  104. }
  105. });
  106. },
  107. //打开蓝牙
  108. openBlue() {
  109. var that = this
  110. if (!that.connectState) {
  111. uni.showLoading({
  112. title: "链接中...",
  113. icon: "none"
  114. })
  115. uni.authorize({
  116. scope: 'scope.bluetooth',
  117. success: () => {
  118. uni.openBluetoothAdapter({
  119. success: (res) => {
  120. uni.hideLoading();
  121. that.$store.commit('setConnectState', true);
  122. that.getBluetoothAdapterState();
  123. },
  124. fail: (res) => {
  125. uni.hideLoading();
  126. uni.showToast({
  127. title: "蓝牙适配器打开失败",
  128. icon: "none"
  129. })
  130. }
  131. });
  132. },
  133. fail: () => {
  134. uni.hideLoading();
  135. uni.showModal({
  136. title: '提示',
  137. content: '需要使用蓝牙功能,请授权使用',
  138. showCancel: false,
  139. success: () => {
  140. uni.openSetting();
  141. }
  142. })
  143. }
  144. })
  145. } else {
  146. that.blist = [];
  147. that.savelist = [];
  148. closeBlueAdapter();
  149. }
  150. },
  151. //搜索蓝牙
  152. getBluetoothAdapterState() {
  153. var that = this;
  154. that.blist = [];
  155. uni.getBluetoothAdapterState({
  156. success: function(res) {
  157. if (!res.discovering) {
  158. that.startBluetoothDevicesDiscovery();
  159. }
  160. if (!res.available) {
  161. uni.showModal({
  162. title: '提示',
  163. content: '当前蓝牙适配器不可用',
  164. confirmColor: '#00b6b5',
  165. showCancel: false,
  166. success(res) {}
  167. })
  168. }
  169. },
  170. fail: function(res) {
  171. uni.showModal({
  172. title: '提示',
  173. content: '适配蓝牙失败',
  174. confirmColor: '#00b6b5',
  175. showCancel: false,
  176. success(res) {}
  177. })
  178. }
  179. });
  180. },
  181. //搜索蓝牙
  182. startBluetoothDevicesDiscovery() {
  183. var that = this;
  184. that.isSearch = true
  185. uni.startBluetoothDevicesDiscovery({
  186. allowDuplicatesKey: false,
  187. success: function(res) {
  188. setTimeout(() => {
  189. that.isSearch = false
  190. that.lanya5()
  191. }, 5000)
  192. that.onBluetoothDeviceFound();
  193. },
  194. fail: function(res) {
  195. that.isSearch = false
  196. uni.showModal({
  197. title: '提示',
  198. content: '搜索蓝牙设备失败'
  199. })
  200. }
  201. })
  202. },
  203. //获取所有已发现的设备
  204. getBluetoothDevices() {
  205. var that = this;
  206. that.savelist = [];
  207. let islist = uni.getStorageSync("connectDevList")?uni.getStorageSync("connectDevList"):[]
  208. that.savelist = islist.filter(v => {
  209. v.isConnect = '0';
  210. if (that.connectDev && v.deviceId == that.connectDev.deviceId) v.isConnect = '1';
  211. if (v.name && v.deviceId) return v;
  212. })
  213. uni.getBluetoothDevices({
  214. success(res){
  215. res.devices.filter(v => {
  216. if (!that.blist.find(v2 => v2.deviceId == v.deviceId)) {
  217. if (v.name.toLowerCase() == that.keyword.toLowerCase()) that.blist.push(v);
  218. }
  219. })
  220. }
  221. })
  222. },
  223. // 获取所有已发现的设备
  224. onBluetoothDeviceFound() {
  225. var that = this;
  226. that.savelist = [];
  227. let islist = uni.getStorageSync("connectDevList")?uni.getStorageSync("connectDevList"):[]
  228. that.savelist = islist.filter(v => {
  229. v.isConnect = '0';
  230. if (that.connectDev && v.deviceId == that.connectDev.deviceId) v.isConnect = '1';
  231. if (v.name && v.deviceId) return v;
  232. })
  233. uni.onBluetoothDeviceFound((res) => {
  234. res.devices.filter(v => {
  235. //判断blist中如果没有就添加
  236. if (!that.blist.find(v2 => v2.deviceId == v.deviceId)) {
  237. if (v.name.toLowerCase() == that.keyword.toLowerCase()) that.blist.push(v);
  238. }
  239. })
  240. })
  241. },
  242. //停止搜索周边设备
  243. lanya5() {
  244. uni.getBluetoothAdapterState({
  245. success: function(res) {
  246. if (res.discovering) {
  247. uni.stopBluetoothDevicesDiscovery({
  248. success: function(res) {
  249. console.log("蓝牙停止搜索")
  250. }
  251. })
  252. }
  253. }
  254. })
  255. },
  256. //关闭蓝牙
  257. closeBluetoothAdapter() {
  258. var that = this
  259. uni.closeBluetoothAdapter({
  260. complete() {}
  261. })
  262. },
  263. delOld(index){
  264. var that = this;
  265. uni.showModal({
  266. title: '提示',
  267. content: '确定要删除该工牌吗?',
  268. success(res) {
  269. if (res.confirm) {
  270. let item = that.savelist[index];
  271. if (item.isConnect == 1) {
  272. uni.setStorageSync("lyDetail", item)
  273. uni.showToast({
  274. title: '该工牌蓝牙已连接,请先进入"蓝牙详情"页面断开蓝牙',
  275. duration: 3000,
  276. icon: "none",
  277. })
  278. setTimeout(() => {
  279. uni.navigateTo({
  280. url: '/pages/bluetooth/detail'
  281. })
  282. }, 3000)
  283. return
  284. }
  285. that.savelist.splice(index,1);
  286. uni.setStorageSync("connectDevList",that.savelist);
  287. }
  288. }
  289. })
  290. },
  291. //去详情页
  292. goDetail(item) {
  293. uni.setStorageSync("lyDetail", item)
  294. uni.navigateTo({
  295. url: "/pages/bluetooth/detail"
  296. })
  297. }
  298. }
  299. }
  300. </script>
  301. <style scoped lang="scss">
  302. .bt {
  303. background-color: #F1F2F4;
  304. min-height: 100vh;
  305. width: 100%;
  306. box-sizing: border-box;
  307. padding: 40rpx 28rpx;
  308. .bt-t1 {
  309. font-weight: 400;
  310. font-size: 26rpx;
  311. color: #666666;
  312. margin-bottom: 20rpx;
  313. }
  314. .bt-c1 {
  315. height: 88rpx;
  316. background: #FFFFFF;
  317. border-radius: 12rpx;
  318. display: flex;
  319. align-items: center;
  320. justify-content: space-between;
  321. font-size: 28rpx;
  322. color: #333333;
  323. box-sizing: border-box;
  324. padding: 0 28rpx;
  325. }
  326. .bt-sw {
  327. width: 60rpx;
  328. height: 36rpx;
  329. background: #D8D8D8;
  330. box-shadow: 0rpx 2rpx 4rpx 0rpx rgba(9, 23, 44, 0.3);
  331. border-radius: 18rpx;
  332. display: flex;
  333. align-items: center;
  334. transition: all 0.3s linear;
  335. position: relative;
  336. }
  337. .bt-sw::after {
  338. content: " ";
  339. position: absolute;
  340. left: 8rpx;
  341. width: 20rpx;
  342. height: 20rpx;
  343. background: #FFFFFF;
  344. border-radius: 16rpx;
  345. transition: all 0.3s linear;
  346. }
  347. .bt-sw-ac {
  348. background: #2671E2;
  349. }
  350. .bt-sw-ac::after {
  351. left: 32rpx;
  352. }
  353. .bt-t2 {
  354. font-size: 30rpx;
  355. color: #999999;
  356. margin-top: 20rpx;
  357. line-height: 1.6;
  358. }
  359. .bt-t3 {
  360. margin-top: 60rpx;
  361. font-size: 26rpx;
  362. color: #666666;
  363. }
  364. .bt-input1 {
  365. width: 100%;
  366. background: #FFFFFF;
  367. border-radius: 12rpx;
  368. box-sizing: border-box;
  369. padding: 20rpx;
  370. display: flex;
  371. align-items: center;
  372. justify-content: space-between;
  373. margin-top: 20rpx;
  374. &-c {
  375. width: 100%;
  376. height: 66rpx;
  377. background: #F1F2F4;
  378. border-radius: 8rpx;
  379. display: flex;
  380. align-items: center;
  381. box-sizing: border-box;
  382. padding: 0 20rpx;
  383. image {
  384. width: 36rpx;
  385. height: 36rpx;
  386. margin-right: 10rpx;
  387. flex-shrink: 0;
  388. }
  389. input {
  390. width: 100%;
  391. font-weight: 400;
  392. font-size: 26rpx;
  393. color: #333;
  394. }
  395. }
  396. .scan {
  397. width: 30rpx;
  398. height: 30rpx;
  399. margin-left: 28rpx;
  400. flex-shrink: 0;
  401. }
  402. }
  403. .bt-c2 {
  404. width: 100%;
  405. display: flex;
  406. align-items: center;
  407. justify-content: space-between;
  408. margin-top: 60rpx;
  409. .bt-c2-l {
  410. font-weight: 400;
  411. font-size: 26rpx;
  412. color: #666666;
  413. transform: translateY(-2rpx);
  414. }
  415. .bt-c2-r {
  416. width: 32rpx;
  417. height: 32rpx;
  418. }
  419. .bt-c2-r-ani {
  420. animation: spin 2.5s linear infinite;
  421. }
  422. @keyframes spin {
  423. 0% {
  424. transform: rotate(0deg);
  425. }
  426. 100% {
  427. transform: rotate(360deg);
  428. }
  429. }
  430. }
  431. .bt-c3 {
  432. box-sizing: border-box;
  433. padding: 32rpx;
  434. background: #FFFFFF;
  435. border-radius: 12rpx;
  436. display: flex;
  437. align-items: center;
  438. justify-content: space-between;
  439. margin-top: 20rpx;
  440. .bt-c3-l {
  441. display: flex;
  442. align-items: center;
  443. font-weight: 400;
  444. font-size: 28rpx;
  445. color: #333333;
  446. image {
  447. height: 36rpx;
  448. margin-left: 12rpx;
  449. flex-shrink: 0;
  450. }
  451. }
  452. image {
  453. width: 12rpx;
  454. height: 28rpx;
  455. margin-left: 20rpx;
  456. flex-shrink: 0;
  457. }
  458. }
  459. }
  460. </style>