diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 3128e38..e29e48e 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -9,7 +9,8 @@ module.exports = { uni: 'writable', getApp: 'writable', wx: 'writable', - getCurrentPages: 'writable' + getCurrentPages: 'writable', + requirePlugin: 'writable' }, // 指定如何解析语法 parser: 'vue-eslint-parser', @@ -25,8 +26,7 @@ module.exports = { extends: [ 'plugin:vue/vue3-recommended', // 使用插件支持vue3 'airbnb-base', - 'plugin:prettier/recommended', - './.eslintrc-auto-import.json' + 'plugin:prettier/recommended' ], ignorePatterns: ['utils/log.js', 'unpackage/**/*'], /** @@ -45,11 +45,26 @@ module.exports = { 'no-use-before-define': 'off', // 禁止在 函数/类/变量 定义之前使用它们 'no-irregular-whitespace': 'off', // 禁止不规则的空白 'no-undef': 'error', // 禁止使用未声明的变量 - 'no-unused-vars': 'error', // 禁止出现未使用过的变量 + 'no-unused-vars': [ + 'error', + { + vars: 'all', + args: 'after-used', + ignoreRestSiblings: false, + caughtErrors: 'all' + } + ], // 禁止出现未使用过的变量 'vue/script-setup-uses-vars': 'error', // 确保script setup中的变量必须正确定义 'vue/no-undef-components': 'off', // 关闭组件未定义的检查 'vue/no-undef-properties': 'off', // 关闭属性未定义的检查 - 'vue/no-unused-vars': 'error', // 禁止Vue组件中出现未使用的变量 + 'vue/no-unused-vars': [ + 'error', + { + ignorePattern: '' + } + ], // 禁止Vue组件中出现未使用的变量 + 'vue/no-unused-refs': 'error', // 禁止定义但未使用的ref + 'vue/require-component-is': 'error', // 禁止模板中未使用的组件 'import/no-unused-modules': 'off', // 关闭模块导出检查 'import/no-cycle': 0, 'no-nested-ternary': 0, diff --git a/App.vue b/App.vue index 6b24e74..18c5e7f 100644 --- a/App.vue +++ b/App.vue @@ -16,6 +16,7 @@ appid: '', // 小程序版本 envVersion: '', + sn: '', // 获取环境配置 getEnvConfig() { const envVersionStorage = getStorage('envVersion') @@ -84,6 +85,13 @@ key: 'Call', routeType: 'switchTab' }) + + wmpfVoip.onVoipEvent(event => { + if (event.eventName === 'callPageOnShow') { + const query = wmpfVoip.getPluginOnloadOptions() + getApp().globalData.sn = query.callerId + } + }) }, // 强制升级 updateMiniProgram() { @@ -104,5 +112,5 @@ diff --git a/api/sdk.js b/api/sdk.js index 5ec215c..c4dc3f4 100644 --- a/api/sdk.js +++ b/api/sdk.js @@ -10,3 +10,21 @@ export function passthrough(data) { data }) } + +// 获取视频列表 +export function getVideoList(data) { + return request({ + url: '/lockCloudStorage/list', + method: 'POST', + data + }) +} + +// 删除视频 +export function deleteVideo(data) { + return request({ + url: '/lockCloudStorage/delete', + method: 'POST', + data + }) +} diff --git a/constant/transportType.js b/constant/transportType.js new file mode 100644 index 0000000..7effc3f --- /dev/null +++ b/constant/transportType.js @@ -0,0 +1,7 @@ +export const transportType = { + TRANSPORT_BLUETOOTH: 0, + TRANSPORT_OFFLINE: 10, + TRANSPORT_GATEWAY: 20, + TRANSPORT_WIFI: 30, + TRANSPORT_TENCENT_YUN: 40 +} diff --git a/pages.json b/pages.json index fbe944f..6107d0d 100644 --- a/pages.json +++ b/pages.json @@ -31,6 +31,24 @@ "navigationBarTitleText": "微信授权", "disableScroll": true } + }, + { + "path": "videoDetail", + "style": { + "navigationBarTitleText": "视频播放" + } + }, + { + "path": "videoLog", + "style": { + "navigationBarTitleText": "云存" + } + }, + { + "path": "videoEdit", + "style": { + "navigationBarTitleText": "视频编辑" + } } ], "plugins": { diff --git a/pages/addDevice/bindLock.vue b/pages/addDevice/bindLock.vue index 089cd87..6a5a722 100644 --- a/pages/addDevice/bindLock.vue +++ b/pages/addDevice/bindLock.vue @@ -9,7 +9,7 @@ placeholder-class="input-placeholder" @input="updateName" /> - 确定 + 确定 @@ -39,7 +39,7 @@ }, methods: { ...mapActions(useBluetoothStore, [ - 'addLockUser', + 'bindLock', 'closeBluetoothConnection', 'updateBindedDeviceName', 'closeAllBluetooth', @@ -50,7 +50,7 @@ updateName(data) { this.name = data.detail.value }, - async bindLock() { + async bindLockOperation() { if (this.name === '') { uni.showToast({ title: '请输入名称', @@ -69,7 +69,7 @@ this.updateBindedDeviceName(this.currentLockInfo.name) const timestamp = parseInt(new Date().getTime() / 1000, 10) const password = (Math.floor(Math.random() * 900000) + 100000).toString() - const { code: addUserCode } = await this.addLockUser({ + const { code: addUserCode } = await this.bindLock({ name: this.currentLockInfo.name, keyId: this.keyId, authUid: this.userInfo.uid.toString(), diff --git a/pages/addDevice/searchDevice.vue b/pages/addDevice/searchDevice.vue index abdb58f..b1f0689 100644 --- a/pages/addDevice/searchDevice.vue +++ b/pages/addDevice/searchDevice.vue @@ -67,7 +67,7 @@ 'getCommKey', 'connectBluetoothDevice', 'updateServerTimestamp', - 'getLockStatus' + 'getLockStatusInfo' ]), ...mapActions(useBasicStore, ['getDeviceInfo', 'routeJump', 'getNetworkType']), async connect(device) { @@ -123,7 +123,7 @@ } const date = new Date() const timestamp = this.serverTimestamp - date.getTimezoneOffset() * 60 - const { code } = await this.getLockStatus({ + const { code } = await this.getLockStatusInfo({ name: this.currentLockInfo.name, uid: this.userInfo.uid.toString(), nowTime: this.serverTimestamp, @@ -148,7 +148,8 @@ icon: 'none' }) } - } catch (res) { + } catch (error) { + console.log('连接失败', error) uni.hideLoading() uni.showToast({ title: '连接失败,请靠近设备并保持设备处于唤醒状态', diff --git a/pages/main/customBox.vue b/pages/main/customBox.vue index 2249512..c616fe2 100644 --- a/pages/main/customBox.vue +++ b/pages/main/customBox.vue @@ -1,5 +1,5 @@ + + + + diff --git a/pages/p2p/authorizeWechat.vue b/pages/p2p/authorizeWechat.vue index 5c957bb..75d6808 100644 --- a/pages/p2p/authorizeWechat.vue +++ b/pages/p2p/authorizeWechat.vue @@ -32,6 +32,7 @@ import { passthrough } from '@/api/sdk' import { useBluetoothStore } from '@/stores/bluetooth' import env from '@/config/env' + import { getStorage } from '@/utils/storage' const $bluetooth = useBluetoothStore() @@ -57,6 +58,17 @@ const data = list.value.find(item => item.sn === result.data.WXIoTDeviceInfo.SN) if (data) { if (data.status === 1) { + if (reject.value) { + passthrough({ + request_method: 'POST', + request_uri: '/api/v1/tencentYun/reportWechatAuthSuccess', + post_args: { + lockId: $bluetooth.currentLockInfo.lockId, + wxOpenid: getStorage('openid'), + wxDeviceSn: result.data.WXIoTDeviceInfo.SNTicket + } + }) + } reject.value = false } else if (data.status === 0) { reject.value = true @@ -116,10 +128,19 @@ snTicket: result.data.WXIoTDeviceInfo.SNTicket, modelId: result.data.WXIoTDeviceInfo.ModelId, deviceName: await env[await getApp().globalData.getEnvConfig()].appName, - success() { + async success() { isAuthorized.value = true uni.hideLoading() pending.value = false + passthrough({ + request_method: 'POST', + request_uri: '/api/v1/tencentYun/reportWechatAuthSuccess', + post_args: { + lockId: $bluetooth.currentLockInfo.lockId, + wxOpenid: getStorage('openid'), + wxDeviceSn: result.data.WXIoTDeviceInfo.SNTicket + } + }) uni.showToast({ title: '授权成功', icon: 'none' diff --git a/pages/p2p/videoDetail.vue b/pages/p2p/videoDetail.vue new file mode 100644 index 0000000..22ed03f --- /dev/null +++ b/pages/p2p/videoDetail.vue @@ -0,0 +1,38 @@ + + + diff --git a/pages/p2p/videoEdit.vue b/pages/p2p/videoEdit.vue new file mode 100644 index 0000000..3c255eb --- /dev/null +++ b/pages/p2p/videoEdit.vue @@ -0,0 +1,145 @@ + + + diff --git a/pages/p2p/videoLog.vue b/pages/p2p/videoLog.vue new file mode 100644 index 0000000..578a84d --- /dev/null +++ b/pages/p2p/videoLog.vue @@ -0,0 +1,51 @@ + + + diff --git a/stores/basic.js b/stores/basic.js index f74cac8..b8668ed 100644 --- a/stores/basic.js +++ b/stores/basic.js @@ -396,6 +396,21 @@ const pages = [ name: 'authorizeWechat', path: '/pages/p2p/authorizeWechat', tabBar: false + }, + { + name: 'videoDetail', + path: '/pages/p2p/videoDetail', + tabBar: false + }, + { + name: 'videoLog', + path: '/pages/p2p/videoLog', + tabBar: false + }, + { + name: 'videoEdit', + path: '/pages/p2p/videoEdit', + tabBar: false } ] diff --git a/stores/bluetooth.js b/stores/bluetooth.js index 1302e11..b5c5610 100644 --- a/stores/bluetooth.js +++ b/stores/bluetooth.js @@ -13,6 +13,8 @@ import { updateTimezoneOffsetRequest } from '@/api/user' import log from '@/utils/log' import { useUserStore } from '@/stores/user' import { getLastRecordTimeRequest, uploadRecordRequest } from '@/api/record' +import { transportType } from '@/constant/transportType' +import { passthrough } from '@/api/sdk' // 定时器 let timer @@ -1312,32 +1314,52 @@ export const useBluetoothStore = defineStore('ble', { return true }, // 写入特征值 - async writeBLECharacteristicValue(binaryData) { + async transportMessage(binaryData) { const that = this - console.log('设备ID:', that.currentLockInfo.deviceId) - console.log('设备名称:', that.currentLockInfo.name) - console.log('设备主服务:', that.currentLockInfo.serviceId) - console.log('设备写入特征值:', that.currentLockInfo.writeCharacteristicId) - console.log('设备写入数据:', Array.from(binaryData)) - - // 次数 - const count = Math.ceil(binaryData.length / 20) - for (let i = 0; i < count; i++) { - const writeData = binaryData.slice( - i * 20, - i === count - 1 ? binaryData.length : (i + 1) * 20 - ) - - uni.writeBLECharacteristicValue({ - deviceId: that.currentLockInfo.deviceId, - serviceId: that.currentLockInfo.serviceId, - characteristicId: that.currentLockInfo.writeCharacteristicId, - value: writeData.buffer, - fail(res) { - console.log('写入失败', res) + if (that.currentLockInfo.transport_type === transportType.TRANSPORT_TENCENT_YUN) { + const { code, data, message } = await passthrough({ + request_method: 'GET', + request_uri: '/api/v1/tencentYun/getTencentTriple', + post_args: { + lockId: that.currentLockInfo.lockId, + data: binaryData } }) + + if (code === 0) { + that.parsingCharacteristicValue(data) + } else { + characteristicValueCallback({ + code, + message + }) + } + } else { + console.log('设备ID:', that.currentLockInfo.deviceId) + console.log('设备名称:', that.currentLockInfo.name) + console.log('设备主服务:', that.currentLockInfo.serviceId) + console.log('设备写入特征值:', that.currentLockInfo.writeCharacteristicId) + console.log('设备写入数据:', Array.from(binaryData)) + + // 次数 + const count = Math.ceil(binaryData.length / 20) + for (let i = 0; i < count; i++) { + const writeData = binaryData.slice( + i * 20, + i === count - 1 ? binaryData.length : (i + 1) * 20 + ) + + uni.writeBLECharacteristicValue({ + deviceId: that.currentLockInfo.deviceId, + serviceId: that.currentLockInfo.serviceId, + characteristicId: that.currentLockInfo.writeCharacteristicId, + value: writeData.buffer, + fail(res) { + console.log('写入失败', res) + } + }) + } } }, /* @@ -1446,8 +1468,8 @@ export const useBluetoothStore = defineStore('ble', { const packageArray = this.createPackageEnd(headArray, contentArray) - await this.writeBLECharacteristicValue(packageArray) - return this.getWriteResult() + await this.transportMessage(packageArray) + return this.getResult() }, // 获取私钥 async getCommKey(name, keyId, authUid, nowTime) { @@ -1518,8 +1540,8 @@ export const useBluetoothStore = defineStore('ble', { const packageArray = this.createPackageEnd(headArray, cebArray) - await this.writeBLECharacteristicValue(packageArray) - return this.getWriteResult() + await this.transportMessage(packageArray) + return this.getResult() }, // md5加密 md5Encrypte(text, token, key) { @@ -1538,6 +1560,70 @@ export const useBluetoothStore = defineStore('ble', { }, // 获取锁状态 async getLockStatus(data) { + // 确认蓝牙状态正常 + if ( + this.bluetoothStatus !== 0 && + this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN + ) { + console.log('写入未执行', this.bluetoothStatus) + this.getBluetoothStatus() + return { + code: -1 + } + } + + // 确认设备连接正常 + if ( + !this.currentLockInfo.connected && + this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN + ) { + const searchResult = await this.searchAndConnectDevice() + if (searchResult.code !== 0) { + return searchResult + } + this.updateCurrentLockInfo({ + ...this.currentLockInfo, + deviceId: searchResult.data.deviceId + }) + console.log('设备ID:', this.currentLockInfo.deviceId) + const result = await this.connectBluetoothDevice() + console.log('连接结果', result) + if (!result) { + return { + code: -1 + } + } + } + + const { name, uid, nowTime, localTime } = data + const length = 2 + 40 + 20 + 4 + 4 + const headArray = this.createPackageHeader(3, length) + + const contentArray = new Uint8Array(length) + contentArray[0] = cmdIds.getLockStatus / 256 + contentArray[1] = cmdIds.getLockStatus % 256 + for (let i = 0; i < name.length; i++) { + contentArray[i + 2] = name.charCodeAt(i) + } + for (let i = 0; i < uid.length; i++) { + contentArray[i + 42] = uid.charCodeAt(i) + } + contentArray.set(this.timestampToArray(nowTime), 62) + contentArray.set(this.timestampToArray(localTime), 66) + + const cebArray = sm4.encrypt(contentArray, this.currentLockInfo.commKey, { + mode: 'ecb', + output: 'array' + }) + + const packageArray = this.createPackageEnd(headArray, cebArray) + + await this.transportMessage(packageArray) + + return this.getResult(this.getLockStatus, data) + }, + // 获取锁状态 + async getLockStatusInfo(data) { // 确认蓝牙状态正常 if (this.bluetoothStatus !== 0) { console.log('写入未执行', this.bluetoothStatus) @@ -1590,9 +1676,9 @@ export const useBluetoothStore = defineStore('ble', { const packageArray = this.createPackageEnd(headArray, cebArray) - await this.writeBLECharacteristicValue(packageArray) + await this.transportMessage(packageArray) - return this.getWriteResult(this.getLockStatus, data) + return this.getResult(this.getLockStatusInfo, data) }, // 获取Wi-Fi列表 async getWifiList(data) { @@ -1643,9 +1729,9 @@ export const useBluetoothStore = defineStore('ble', { const packageArray = this.createPackageEnd(headArray, cebArray) - await this.writeBLECharacteristicValue(packageArray) + await this.transportMessage(packageArray) - return this.getWriteResult(this.getWifiList, data) + return this.getResult(this.getWifiList, data) }, // 配网 async distributionNetwork(data) { @@ -1707,9 +1793,9 @@ export const useBluetoothStore = defineStore('ble', { const packageArray = this.createPackageEnd(headArray, cebArray) - await this.writeBLECharacteristicValue(packageArray) + await this.transportMessage(packageArray) - return this.getWriteResult(this.distributionNetwork, data) + return this.getResult(this.distributionNetwork, data) }, // 时间戳转二进制 timestampToArray(timestamp) { @@ -1727,6 +1813,128 @@ export const useBluetoothStore = defineStore('ble', { }, // 添加用户 async addLockUser(data) { + // 确认蓝牙状态正常 + if ( + this.bluetoothStatus !== 0 && + this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN + ) { + console.log('写入未执行', this.bluetoothStatus) + this.getBluetoothStatus() + return { + code: -1 + } + } + + // 确认设备连接正常 + if ( + !this.currentLockInfo.connected && + this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN + ) { + const searchResult = await this.searchAndConnectDevice() + if (searchResult.code !== 0) { + return searchResult + } + this.updateCurrentLockInfo({ + ...this.currentLockInfo, + deviceId: searchResult.data.deviceId + }) + console.log('设备ID:', this.currentLockInfo.deviceId) + const result = await this.connectBluetoothDevice() + console.log('连接结果', result) + if (!result) { + return { + code: -1 + } + } + } + + const { + name, + authUid, + uid, + keyId, + openMode, + keyType, + startDate, + expireDate, + useCountLimit, + isRound, + weekRound, + startHour, + startMin, + endHour, + endMin, + role, + password + } = data + const length = + 2 + 40 + 20 + 40 + 20 + 1 + 1 + 4 + 4 + 2 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 20 + 4 + 1 + 16 + const headArray = this.createPackageHeader(3, length) + const contentArray = new Uint8Array(length) + + contentArray[0] = cmdIds.addUser / 256 + contentArray[1] = cmdIds.addUser % 256 + + for (let i = 0; i < name.length; i++) { + contentArray[i + 2] = name.charCodeAt(i) + } + + for (let i = 0; i < authUid.length; i++) { + contentArray[i + 42] = authUid.charCodeAt(i) + } + + for (let i = 0; i < keyId.length; i++) { + contentArray[i + 62] = keyId.charCodeAt(i) + } + + for (let i = 0; i < uid.length; i++) { + contentArray[i + 102] = uid.charCodeAt(i) + } + + contentArray[122] = openMode + contentArray[123] = keyType + + contentArray.set(this.timestampToArray(startDate), 124) + contentArray.set(this.timestampToArray(expireDate), 128) + + contentArray[132] = useCountLimit / 256 + contentArray[133] = useCountLimit % 256 + + contentArray[134] = isRound + contentArray[135] = weekRound + contentArray[136] = startHour + contentArray[137] = startMin + contentArray[138] = endHour + contentArray[139] = endMin + contentArray[140] = role + + for (let i = 0; i < password.length; i++) { + contentArray[i + 141] = password.charCodeAt(i) + } + + contentArray.set(this.currentLockInfo.token || this.timestampToArray(startDate), 161) + + contentArray[165] = 16 + + const md5Array = this.md5Encrypte( + authUid + keyId, + this.currentLockInfo.token || this.timestampToArray(startDate), + this.currentLockInfo.publicKey + ) + + contentArray.set(md5Array, 166) + + const cebArray = sm4.encrypt(contentArray, this.currentLockInfo.commKey, { + mode: 'ecb', + output: 'array' + }) + + const packageArray = this.createPackageEnd(headArray, cebArray) + await this.transportMessage(packageArray, false) + return this.getResult(this.addLockUser, data) + }, + // 添加用户 + async bindLock(data) { // 确认蓝牙状态正常 if (this.bluetoothStatus !== 0) { console.log('写入未执行', this.bluetoothStatus) @@ -1838,14 +2046,14 @@ export const useBluetoothStore = defineStore('ble', { }) const packageArray = this.createPackageEnd(headArray, cebArray) - await this.writeBLECharacteristicValue(packageArray, false) - return this.getWriteResult(this.addLockUser, data) + await this.transportMessage(packageArray, false) + return this.getResult(this.bindLock, data) }, // 获取写入结果 - getWriteResult(request, params) { + getResult(request, params) { const $user = useUserStore() return new Promise(resolve => { - const getWriteResultTimer = setTimeout(() => { + const getResultTimer = setTimeout(() => { log.info({ code: -1, message: `操作失败,蓝牙操作超时`, @@ -1875,10 +2083,10 @@ export const useBluetoothStore = defineStore('ble', { email: $user.userInfo.email } }) - clearTimeout(getWriteResultTimer) + clearTimeout(getResultTimer) resolve(await request(params)) } else { - clearTimeout(getWriteResultTimer) + clearTimeout(getResultTimer) resolve(data) } } @@ -1901,7 +2109,10 @@ export const useBluetoothStore = defineStore('ble', { } }) // 确认蓝牙状态正常 - if (this.bluetoothStatus !== 0) { + if ( + this.bluetoothStatus !== 0 && + this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN + ) { console.log('写入未执行', this.bluetoothStatus) this.getBluetoothStatus() if (this.bluetoothStatus === -1) { @@ -1976,7 +2187,10 @@ export const useBluetoothStore = defineStore('ble', { }) // 确认设备连接正常 - if (!this.currentLockInfo.connected) { + if ( + !this.currentLockInfo.connected && + this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN + ) { const searchResult = await this.searchAndConnectDevice() if (searchResult.code === 0) { log.info({ @@ -2216,9 +2430,9 @@ export const useBluetoothStore = defineStore('ble', { email: $user.userInfo.email } }) - this.writeBLECharacteristicValue(packageArray) + this.transportMessage(packageArray) - return this.getWriteResult(this.openDoor, data) + return this.getResult(this.openDoor, data) } catch (e) { log.error({ code: -1, @@ -2233,7 +2447,10 @@ export const useBluetoothStore = defineStore('ble', { // 清理用户 async cleanLockUser(data) { // 确认蓝牙状态正常 - if (this.bluetoothStatus !== 0) { + if ( + this.bluetoothStatus !== 0 && + this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN + ) { console.log('写入未执行', this.bluetoothStatus) this.getBluetoothStatus() return { @@ -2242,7 +2459,10 @@ export const useBluetoothStore = defineStore('ble', { } // 确认设备连接正常 - if (!this.currentLockInfo.connected) { + if ( + !this.currentLockInfo.connected && + this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN + ) { const searchResult = await this.searchAndConnectDevice() if (searchResult.code !== 0) { return searchResult @@ -2315,14 +2535,17 @@ export const useBluetoothStore = defineStore('ble', { const packageArray = this.createPackageEnd(headArray, cebArray) - await this.writeBLECharacteristicValue(packageArray) + await this.transportMessage(packageArray) - return this.getWriteResult(this.cleanLockUser, data) + return this.getResult(this.cleanLockUser, data) }, // 恢复出厂设置 async resetDevice(data) { // 确认蓝牙状态正常 - if (this.bluetoothStatus !== 0) { + if ( + this.bluetoothStatus !== 0 && + this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN + ) { console.log('写入未执行', this.bluetoothStatus) this.getBluetoothStatus() return { @@ -2331,7 +2554,10 @@ export const useBluetoothStore = defineStore('ble', { } // 确认设备连接正常 - if (!this.currentLockInfo.connected) { + if ( + !this.currentLockInfo.connected && + this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN + ) { const searchResult = await this.searchAndConnectDevice() if (searchResult.code !== 0) { return searchResult @@ -2390,14 +2616,17 @@ export const useBluetoothStore = defineStore('ble', { const packageArray = this.createPackageEnd(headArray, cebArray) - await this.writeBLECharacteristicValue(packageArray) + await this.transportMessage(packageArray) - return this.getWriteResult(this.resetDevice, data) + return this.getResult(this.resetDevice, data) }, // 重置开锁密码 async resetLockPassword(data) { // 确认蓝牙状态正常 - if (this.bluetoothStatus !== 0) { + if ( + this.bluetoothStatus !== 0 && + this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN + ) { console.log('写入未执行', this.bluetoothStatus) this.getBluetoothStatus() return { @@ -2406,7 +2635,10 @@ export const useBluetoothStore = defineStore('ble', { } // 确认设备连接正常 - if (!this.currentLockInfo.connected) { + if ( + !this.currentLockInfo.connected && + this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN + ) { const searchResult = await this.searchAndConnectDevice() if (searchResult.code !== 0) { return searchResult @@ -2473,14 +2705,17 @@ export const useBluetoothStore = defineStore('ble', { const packageArray = this.createPackageEnd(headArray, cebArray) - await this.writeBLECharacteristicValue(packageArray) + await this.transportMessage(packageArray) - return this.getWriteResult(this.resetLockPassword, data) + return this.getResult(this.resetLockPassword, data) }, // 设置密码 async setLockPassword(data) { // 确认蓝牙状态正常 - if (this.bluetoothStatus !== 0) { + if ( + this.bluetoothStatus !== 0 && + this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN + ) { console.log('写入未执行', this.bluetoothStatus) this.getBluetoothStatus() return { @@ -2489,7 +2724,10 @@ export const useBluetoothStore = defineStore('ble', { } // 确认设备连接正常 - if (!this.currentLockInfo.connected) { + if ( + !this.currentLockInfo.connected && + this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN + ) { const searchResult = await this.searchAndConnectDevice() if (searchResult.code !== 0) { return searchResult @@ -2572,9 +2810,9 @@ export const useBluetoothStore = defineStore('ble', { const packageArray = this.createPackageEnd(headArray, cebArray) - await this.writeBLECharacteristicValue(packageArray) + await this.transportMessage(packageArray) - return this.getWriteResult(this.setLockPassword, data) + return this.getResult(this.setLockPassword, data) }, parseTimeToList(timeString) { let timeList = [0, 0, 0, 0] @@ -2590,7 +2828,10 @@ export const useBluetoothStore = defineStore('ble', { // 注册身份认证 async registerAuthentication(data) { // 确认蓝牙状态正常 - if (this.bluetoothStatus !== 0) { + if ( + this.bluetoothStatus !== 0 && + this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN + ) { console.log('写入未执行', this.bluetoothStatus) this.getBluetoothStatus() return { @@ -2599,7 +2840,10 @@ export const useBluetoothStore = defineStore('ble', { } // 确认设备连接正常 - if (!this.currentLockInfo.connected) { + if ( + !this.currentLockInfo.connected && + this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN + ) { const searchResult = await this.searchAndConnectDevice() if (searchResult.code !== 0) { return searchResult @@ -2719,9 +2963,9 @@ export const useBluetoothStore = defineStore('ble', { const packageArray = this.createPackageEnd(headArray, cebArray) - await this.writeBLECharacteristicValue(packageArray) + await this.transportMessage(packageArray) - return this.getWriteResult(this.registerAuthentication, data) + return this.getResult(this.registerAuthentication, data) }, // 注册身份认证取消 async registerAuthenticationCancel(data) { @@ -2776,14 +3020,17 @@ export const useBluetoothStore = defineStore('ble', { const packageArray = this.createPackageEnd(headArray, cebArray) - await this.writeBLECharacteristicValue(packageArray) + await this.transportMessage(packageArray) - return this.getWriteResult(this.registerAuthenticationCancel, data) + return this.getResult(this.registerAuthenticationCancel, data) }, // 获取操作记录 async syncRecord(params) { // 确认蓝牙状态正常 - if (this.bluetoothStatus !== 0) { + if ( + this.bluetoothStatus !== 0 && + this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN + ) { console.log('写入未执行', this.bluetoothStatus) this.getBluetoothStatus() return { @@ -2792,7 +3039,10 @@ export const useBluetoothStore = defineStore('ble', { } // 确认设备连接正常 - if (!this.currentLockInfo.connected) { + if ( + !this.currentLockInfo.connected && + this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN + ) { const searchResult = await this.searchAndConnectDevice() if (searchResult.code !== 0) { return searchResult @@ -2897,14 +3147,17 @@ export const useBluetoothStore = defineStore('ble', { const packageArray = this.createPackageEnd(headArray, cebArray) - await this.writeBLECharacteristicValue(packageArray) + await this.transportMessage(packageArray) - return this.getWriteResult(this.syncSingleRecord, data) + return this.getResult(this.syncSingleRecord, data) }, // 更新管理员密码 async updateAdminPassword(data) { // 确认蓝牙状态正常 - if (this.bluetoothStatus !== 0) { + if ( + this.bluetoothStatus !== 0 && + this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN + ) { console.log('写入未执行', this.bluetoothStatus) this.getBluetoothStatus() return { @@ -2913,7 +3166,10 @@ export const useBluetoothStore = defineStore('ble', { } // 确认设备连接正常 - if (!this.currentLockInfo.connected) { + if ( + !this.currentLockInfo.connected && + this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN + ) { const searchResult = await this.searchAndConnectDevice() if (searchResult.code !== 0) { return searchResult @@ -2993,14 +3249,17 @@ export const useBluetoothStore = defineStore('ble', { const packageArray = this.createPackageEnd(headArray, cebArray) - await this.writeBLECharacteristicValue(packageArray) + await this.transportMessage(packageArray) - return this.getWriteResult(this.updateAdminPassword, data) + return this.getResult(this.updateAdminPassword, data) }, // 更新设置 async updateSetting(data) { // 确认蓝牙状态正常 - if (this.bluetoothStatus !== 0) { + if ( + this.bluetoothStatus !== 0 && + this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN + ) { console.log('写入未执行', this.bluetoothStatus) this.getBluetoothStatus() return { @@ -3009,7 +3268,10 @@ export const useBluetoothStore = defineStore('ble', { } // 确认设备连接正常 - if (!this.currentLockInfo.connected) { + if ( + !this.currentLockInfo.connected && + this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN + ) { const searchResult = await this.searchAndConnectDevice() if (searchResult.code !== 0) { return searchResult @@ -3094,14 +3356,17 @@ export const useBluetoothStore = defineStore('ble', { const packageArray = this.createPackageEnd(headArray, cebArray) - await this.writeBLECharacteristicValue(packageArray) + await this.transportMessage(packageArray) - return this.getWriteResult(this.updateSetting, data) + return this.getResult(this.updateSetting, data) }, // 校准时间 async calibrationTime(data) { // 确认蓝牙状态正常 - if (this.bluetoothStatus !== 0) { + if ( + this.bluetoothStatus !== 0 && + this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN + ) { console.log('写入未执行', this.bluetoothStatus) this.getBluetoothStatus() return { @@ -3110,7 +3375,10 @@ export const useBluetoothStore = defineStore('ble', { } // 确认设备连接正常 - if (!this.currentLockInfo.connected) { + if ( + !this.currentLockInfo.connected && + this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN + ) { const searchResult = await this.searchAndConnectDevice() if (searchResult.code !== 0) { return searchResult @@ -3172,14 +3440,17 @@ export const useBluetoothStore = defineStore('ble', { }) const packageArray = this.createPackageEnd(headArray, cebArray) - this.writeBLECharacteristicValue(packageArray) + this.transportMessage(packageArray) - return this.getWriteResult(this.calibrationTime, data) + return this.getResult(this.calibrationTime, data) }, // 获取锁数据列表 async getLockDataList(data) { // 确认蓝牙状态正常 - if (this.bluetoothStatus !== 0) { + if ( + this.bluetoothStatus !== 0 && + this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN + ) { console.log('写入未执行', this.bluetoothStatus) this.getBluetoothStatus() return { @@ -3188,7 +3459,10 @@ export const useBluetoothStore = defineStore('ble', { } // 确认设备连接正常 - if (!this.currentLockInfo.connected) { + if ( + !this.currentLockInfo.connected && + this.currentLockInfo.transport_type !== transportType.TRANSPORT_TENCENT_YUN + ) { const searchResult = await this.searchAndConnectDevice() if (searchResult.code !== 0) { return searchResult @@ -3285,9 +3559,9 @@ export const useBluetoothStore = defineStore('ble', { }) const packageArray = this.createPackageEnd(headArray, cebArray) - this.writeBLECharacteristicValue(packageArray) + this.transportMessage(packageArray) - return this.getWriteResult(this.getLockDataList, data) + return this.getResult(this.getLockDataList, data) } } })