From 5af784a18d9a070a833b54afd6c5628491eb5b50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E9=B9=8F?= Date: Fri, 11 Apr 2025 14:04:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8D=E5=BC=95=E7=94=A8bug?= =?UTF-8?q?+=E4=BC=98=E5=8C=96=E7=9B=91=E6=8E=A7=E5=92=8C=E6=8E=88?= =?UTF-8?q?=E6=9D=83=E6=97=B6=E7=9A=84UI=E5=8F=8A=E6=96=87=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/feature/createAdmin.vue | 2 +- pages/feature/createCard.vue | 2 +- pages/feature/createFace.vue | 2 +- pages/feature/createFingerprint.vue | 2 +- pages/feature/createPalmVein.vue | 2 +- pages/feature/createRemote.vue | 2 +- pages/p2p/authorizeWechat.vue | 19 ++-- pages/p2p/p2pPlayer.vue | 131 ++++++++++++++++++++++++++-- 8 files changed, 142 insertions(+), 20 deletions(-) diff --git a/pages/feature/createAdmin.vue b/pages/feature/createAdmin.vue index 078007e..e526422 100644 --- a/pages/feature/createAdmin.vue +++ b/pages/feature/createAdmin.vue @@ -103,7 +103,7 @@ import { useBasicStore } from '@/stores/basic' import { createKeyRequest } from '@/api/key' import { useBluetoothStore } from '@/stores/bluetooth' - import { transportType } from '@/utils/constants' + import { transportType } from '@/constant/transportType' const instance = getCurrentInstance().proxy const eventChannel = instance.getOpenerEventChannel() diff --git a/pages/feature/createCard.vue b/pages/feature/createCard.vue index d1bcbf1..c4dc32c 100644 --- a/pages/feature/createCard.vue +++ b/pages/feature/createCard.vue @@ -127,7 +127,7 @@ import { useUserStore } from '@/stores/user' import { useBluetoothStore } from '@/stores/bluetooth' import { checkCardNameRequest } from '@/api/card' - import { transportType } from '@/utils/constants' + import { transportType } from '@/constant/transportType' const instance = getCurrentInstance().proxy const eventChannel = instance.getOpenerEventChannel() diff --git a/pages/feature/createFace.vue b/pages/feature/createFace.vue index 36a9d6c..6a06ad4 100644 --- a/pages/feature/createFace.vue +++ b/pages/feature/createFace.vue @@ -104,7 +104,7 @@ import { useUserStore } from '@/stores/user' import { useBluetoothStore } from '@/stores/bluetooth' import { checkFaceNameRequest } from '@/api/face' - import { transportType } from '@/utils/constants' + import { transportType } from '@/constant/transportType' const instance = getCurrentInstance().proxy const eventChannel = instance.getOpenerEventChannel() diff --git a/pages/feature/createFingerprint.vue b/pages/feature/createFingerprint.vue index 8d035c4..fbad371 100644 --- a/pages/feature/createFingerprint.vue +++ b/pages/feature/createFingerprint.vue @@ -127,7 +127,7 @@ import { useUserStore } from '@/stores/user' import { useBluetoothStore } from '@/stores/bluetooth' import { checkFingerprintNameRequest } from '@/api/fingerprint' - import { transportType } from '@/utils/constants' + import { transportType } from '@/constant/transportType' const instance = getCurrentInstance().proxy const eventChannel = instance.getOpenerEventChannel() diff --git a/pages/feature/createPalmVein.vue b/pages/feature/createPalmVein.vue index 9bf176c..d44d15c 100644 --- a/pages/feature/createPalmVein.vue +++ b/pages/feature/createPalmVein.vue @@ -128,7 +128,7 @@ import { useUserStore } from '@/stores/user' import { useBluetoothStore } from '@/stores/bluetooth' import { checkPalmVeinNameRequest } from '@/api/palmVein' - import { transportType } from '@/utils/constants' + import { transportType } from '@/constant/transportType' const instance = getCurrentInstance().proxy const eventChannel = instance.getOpenerEventChannel() diff --git a/pages/feature/createRemote.vue b/pages/feature/createRemote.vue index fc2f954..d17dd86 100644 --- a/pages/feature/createRemote.vue +++ b/pages/feature/createRemote.vue @@ -83,7 +83,7 @@ import { useUserStore } from '@/stores/user' import { useBluetoothStore } from '@/stores/bluetooth' import { checkRemoteNameRequest } from '@/api/remote' - import { transportType } from '@/utils/constants' + import { transportType } from '@/constant/transportType' const instance = getCurrentInstance().proxy const eventChannel = instance.getOpenerEventChannel() diff --git a/pages/p2p/authorizeWechat.vue b/pages/p2p/authorizeWechat.vue index 75d6808..6d3c9bd 100644 --- a/pages/p2p/authorizeWechat.vue +++ b/pages/p2p/authorizeWechat.vue @@ -1,19 +1,20 @@ diff --git a/pages/p2p/p2pPlayer.vue b/pages/p2p/p2pPlayer.vue index 0a07bbc..3ae152b 100644 --- a/pages/p2p/p2pPlayer.vue +++ b/pages/p2p/p2pPlayer.vue @@ -54,9 +54,9 @@ - + - + - 长按说话 + 长按说话 - 挂断 + 挂断 @@ -99,7 +99,7 @@ class="w-60 h-60" > - 开锁 + 开锁 @@ -123,13 +123,23 @@ import { onUnload } from '@dcloudio/uni-app' import { useBluetoothStore } from '@/stores/bluetooth' import { useBasicStore } from '@/stores/basic' + import { useUserStore } from '@/stores/user' import { passthrough } from '@/api/sdk' + import { getLockNetTokenRequest } from '@/api/lock' const $bluetooth = useBluetoothStore() const $basic = useBasicStore() - + const $user = useUserStore() const buttonInfo = ref(null) + const onlineToken = ref('0') + + const lockId = ref() + + const time = ref(0) + + const pending = ref(false) + const index = ref(1) const range = ref([ { name: '标清', value: 'standard' }, @@ -166,6 +176,8 @@ } else { $basic.backAndToast(message) } + + await getServeTime() }) onUnload(() => { @@ -213,7 +225,110 @@ } const handleLock = () => { - console.log('handleLock') + uni.showModal({ + title: '提示', + content: '是否确认开锁?', + success: res => { + if (res.confirm) { + openDoorOperate() + } + } + }) + } + + const getServeTime = async () => { + const { code, data } = await $bluetooth.updateServerTimestamp() + if (code === 0) { + time.value = parseInt((data.date - new Date().getTime()) / 1000, 10) + } + } + + const openDoorOperate = async () => { + const timestamp = new Date().getTime() + if (pending.value) { + return + } + + const netWork = await $basic.getNetworkType() + if (!netWork) { + return + } + + if ($bluetooth.currentLockInfo.appUnlockOnline) { + const result = await getNetToken() + if (!result) { + pending.value = false + return + } + } + + uni.showLoading({ + title: '开锁中' + }) + uni.vibrateLong() + pending.value = true + const openMode = $bluetooth.currentLockInfo.appUnlockOnline ? 1 : 0 + + const { code } = await $bluetooth.openDoor({ + name: $bluetooth.currentLockInfo.lockName, + uid: $user.userInfo.uid.toString(), + openMode, + openTime: parseInt(new Date().getTime() / 1000, 10) + time.value, + onlineToken: onlineToken.value + }) + + $bluetooth + .syncRecord({ + keyId: $bluetooth.keyId.toString(), + uid: $user.userInfo.uid.toString() + }) + .then(() => { + $bluetooth.closeBluetoothConnection() + }) + + uni.reportEvent('open_door', { + result: code, + duration: new Date().getTime() - timestamp + }) + + if (code === 0) { + uni.showToast({ + title: `开门成功`, + icon: 'none' + }) + } else if (code === 7) { + uni.showToast({ + title: `钥匙过期`, + icon: 'none' + }) + } else if (code === 13) { + uni.showToast({ + title: `钥匙当前不可用`, + icon: 'none' + }) + } else if (code === -1) { + uni.showToast({ + title: `开锁失败`, + icon: 'none' + }) + } + uni.hideLoading() + pending.value = false + } + + const getNetToken = async () => { + const { code, data, message } = await getLockNetTokenRequest({ + lockId: lockId.value + }) + if (code === 0) { + onlineToken.value = data.token + return true + } + uni.showToast({ + title: message, + icon: 'none' + }) + return false } const startVoice = () => {