2024-08-06 09:40:20 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<view class="content">
|
2024-08-14 18:33:23 +08:00
|
|
|
|
<view v-if="!showConnect">
|
|
|
|
|
|
<button class="button" v-if="showAdd" @click="getList">添加设备</button>
|
|
|
|
|
|
<button class="button" v-else @click="stopGetList">停止搜索</button>
|
|
|
|
|
|
<view class="device-list" v-for="(item, index) in deviceList" :key="item.deviceId" @click="connect(item)">{{item.name}}</view>
|
|
|
|
|
|
</view>
|
|
|
|
|
|
<view v-else>
|
|
|
|
|
|
<button class="button">获取公钥</button>
|
|
|
|
|
|
<button class="button">获取私钥</button>
|
|
|
|
|
|
<button class="button">添加用户</button>
|
|
|
|
|
|
<view>名称:{{currentLockInfo.name}}</view>
|
|
|
|
|
|
<view>设备Id:{{currentLockInfo.deviceId}}</view>
|
|
|
|
|
|
<view v-if="currentLockInfo.serviceId">服务:{{currentLockInfo.serviceId}}</view>
|
|
|
|
|
|
<view v-if="currentLockInfo.writeCharacteristicId">写入特征值Id:{{currentLockInfo.writeCharacteristicId}}</view>
|
|
|
|
|
|
<view v-if="currentLockInfo.notifyCharacteristicId">监听特征值Id:{{currentLockInfo.notifyCharacteristicId}}</view>
|
|
|
|
|
|
</view>
|
2024-08-06 09:40:20 +08:00
|
|
|
|
</view>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2024-08-14 15:04:01 +08:00
|
|
|
|
import { useBluetoothStore } from '@/stores/bluetooth'
|
2024-08-06 10:20:56 +08:00
|
|
|
|
import { mapState, mapActions } from 'pinia'
|
|
|
|
|
|
|
2024-08-06 09:40:20 +08:00
|
|
|
|
export default {
|
|
|
|
|
|
data() {
|
2024-08-14 18:33:23 +08:00
|
|
|
|
return {
|
|
|
|
|
|
showAdd: true,
|
|
|
|
|
|
showConnect: false
|
|
|
|
|
|
}
|
2024-08-06 09:40:20 +08:00
|
|
|
|
},
|
2024-08-06 10:20:56 +08:00
|
|
|
|
computed: {
|
2024-08-14 18:33:23 +08:00
|
|
|
|
...mapState(useBluetoothStore, ['deviceList', 'currentLockInfo'])
|
2024-08-06 12:11:38 +08:00
|
|
|
|
},
|
2024-08-14 15:04:01 +08:00
|
|
|
|
async onLoad () {},
|
2024-08-06 09:40:20 +08:00
|
|
|
|
methods: {
|
2024-08-14 18:33:23 +08:00
|
|
|
|
...mapActions(useBluetoothStore, ['getBluetoothDevices', 'stopGetBluetoothDevices', 'updateCurrentLockInfo',
|
|
|
|
|
|
'connectBluetoothDevice']),
|
2024-08-14 15:04:01 +08:00
|
|
|
|
getList() {
|
|
|
|
|
|
this.getBluetoothDevices()
|
2024-08-14 18:33:23 +08:00
|
|
|
|
this.showAdd = false
|
2024-08-14 15:04:01 +08:00
|
|
|
|
},
|
|
|
|
|
|
stopGetList() {
|
|
|
|
|
|
this.stopGetBluetoothDevices()
|
2024-08-14 18:33:23 +08:00
|
|
|
|
this.showAdd = true
|
|
|
|
|
|
},
|
|
|
|
|
|
async connect(item) {
|
|
|
|
|
|
this.updateCurrentLockInfo({
|
|
|
|
|
|
name: item.name,
|
|
|
|
|
|
deviceId: item.deviceId
|
|
|
|
|
|
})
|
|
|
|
|
|
const result = await this.connectBluetoothDevice()
|
|
|
|
|
|
if(result) {
|
|
|
|
|
|
this.showConnect = true
|
|
|
|
|
|
this.stopGetBluetoothDevices()
|
|
|
|
|
|
}
|
2024-08-06 10:20:56 +08:00
|
|
|
|
}
|
2024-08-06 09:40:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
2024-08-14 15:04:01 +08:00
|
|
|
|
<style lang="scss" scoped>
|
2024-08-06 09:40:20 +08:00
|
|
|
|
.content {
|
2024-08-14 18:33:23 +08:00
|
|
|
|
padding-top: 160rpx;
|
2024-08-06 09:40:20 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-14 15:04:01 +08:00
|
|
|
|
.button {
|
2024-08-14 18:33:23 +08:00
|
|
|
|
margin-top: 40rpx;
|
2024-08-14 15:04:01 +08:00
|
|
|
|
width: 400rpx;
|
2024-08-14 18:33:23 +08:00
|
|
|
|
height: 108rpx;
|
|
|
|
|
|
line-height: 108rpx;
|
|
|
|
|
|
background: #3F536E;
|
|
|
|
|
|
color: #ffffff !important;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.device-list {
|
|
|
|
|
|
margin-top: 10rpx;
|
|
|
|
|
|
height: 100rpx;
|
|
|
|
|
|
width: 500rpx;
|
|
|
|
|
|
line-height: 100rpx;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
border: #dd524d solid 2rpx;
|
2024-08-06 10:20:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
</style>
|