Merge branch 'fanpeng' into 'develop'

Fanpeng

See merge request StarlockTeam/wx-starlock!37
This commit is contained in:
范鹏 2025-04-10 08:36:12 +00:00
commit e31bf024db
16 changed files with 963 additions and 112 deletions

View File

@ -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,

10
App.vue
View File

@ -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 @@
</script>
<style lang="scss">
@import 'uview-plus/index.scss';
@import 'uview-plus/index';
</style>

View File

@ -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
})
}

View File

@ -0,0 +1,7 @@
export const transportType = {
TRANSPORT_BLUETOOTH: 0,
TRANSPORT_OFFLINE: 10,
TRANSPORT_GATEWAY: 20,
TRANSPORT_WIFI: 30,
TRANSPORT_TENCENT_YUN: 40
}

View File

@ -31,6 +31,24 @@
"navigationBarTitleText": "微信授权",
"disableScroll": true
}
},
{
"path": "videoDetail",
"style": {
"navigationBarTitleText": "视频播放"
}
},
{
"path": "videoLog",
"style": {
"navigationBarTitleText": "云存"
}
},
{
"path": "videoEdit",
"style": {
"navigationBarTitleText": "视频编辑"
}
}
],
"plugins": {

View File

@ -9,7 +9,7 @@
placeholder-class="input-placeholder"
@input="updateName"
/>
<view class="button" @click="bindLock">确定</view>
<view class="button" @click="bindLockOperation">确定</view>
</view>
</template>
@ -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(),

View File

@ -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: '连接失败,请靠近设备并保持设备处于唤醒状态',

View File

@ -1,5 +1,5 @@
<template>
<view class="dialog">
<view class="dialog" v-if="lockId">
<image
class="top-background"
src="https://oss-lock.xhjcn.ltd/mp/background_main.jpg"
@ -19,6 +19,7 @@
import { useBasicStore } from '@/stores/basic'
import { useUserStore } from '@/stores/user'
import { getLockDetailRequest, getLockNetTokenRequest } from '@/api/lock'
import { passthrough } from '@/api/sdk'
const $bluetooth = useBluetoothStore()
const $basic = useBasicStore()
@ -32,29 +33,49 @@
const onlineToken = ref('0')
const lockId = ref(2712)
const lockId = ref()
const time = ref(0)
onMounted(async () => {
const { code, data, message } = await getLockDetailRequest({
lockId: lockId.value
const accountInfo = uni.getAccountInfoSync()
getApp().globalData.appid = accountInfo.miniProgram.appId
getApp().globalData.envVersion = accountInfo.miniProgram.envVersion
const result = await passthrough({
request_method: 'POST',
request_uri: '/api/v1/tencentYun/getLockIdBySn',
post_args: {
wxDeviceSn: getApp().globalData.sn
}
})
if (code === 0) {
lockInfo.value = data
$bluetooth.updateCurrentLockInfo({
...lockInfo.value,
name: lockInfo.value.lockName,
deviceId: lockInfo.value.lockName,
commKey: lockInfo.value.privateKey
if (result.code === 0) {
lockId.value = result.data.lockId
const { code, data, message } = await getLockDetailRequest({
lockId: lockId.value
})
if (code === 0) {
lockInfo.value = data
$bluetooth.updateCurrentLockInfo({
...lockInfo.value,
name: lockInfo.value.lockName,
deviceId: lockInfo.value.lockName,
commKey: lockInfo.value.privateKey
})
} else {
uni.showToast({
title: message,
icon: 'none'
})
}
await getServeTime()
} else {
uni.showToast({
title: message,
title: result.message,
icon: 'none'
})
}
await getServeTime()
})
const getServeTime = async () => {

View File

@ -202,7 +202,7 @@
</view>
<view
class="menu-main-view transform-scale-105"
@click="$basic.routeJump({ name: 'p2pPlayer' })"
@click="$basic.routeJump({ name: 'videoLog' })"
>
<image
class="menu-main-image"

219
pages/p2p/VideoList.vue Normal file
View File

@ -0,0 +1,219 @@
<template>
<view>
<view v-if="list.length === 0 && requestFinished">
<image
class="empty-list"
src="https://oss-lock.xhjcn.ltd/mp/background_empty_list.png"
mode="aspectFill"
></image>
<view class="empty-list-text">暂无数据</view>
</view>
<view v-else>
<view v-for="(item, index) in list" :key="index" class="mt-4">
<view>{{ item.date }}</view>
<view class="mt-2 flex flex-wrap gap-[19rpx]">
<view v-for="video in item.recordList" :key="video.recordId" @click="handleVideo(video)">
<image :src="video.imagesUrl" class="w-224 h-224 rounded-xl relative" mode="aspectFill">
<view v-if="type === 'select'" class="absolute inset-0 bg-black bg-opacity-30">
<image
v-if="selectList.includes(video)"
class="w-40 h-40 top-16 right-16 absolute"
src="https://oss-lock.xhjcn.ltd/mp/icon_select.png"
></image>
<image
v-else
class="w-40 h-40 top-16 right-16 absolute"
src="https://oss-lock.xhjcn.ltd/mp/icon_not_select.png"
></image>
</view>
<view
v-else
class="absolute inset-0 bg-black bg-opacity-30 flex items-center justify-center"
>
<up-icon name="play-right-fill" color="#ffffff" size="40"></up-icon>
</view>
</image>
<view class="text-xs">{{ timeFormat(video.operateDate, 'yyyy-mm-dd hh:MM') }}</view>
</view>
</view>
</view>
</view>
</view>
</template>
<script setup>
import { timeFormat } from 'uview-plus'
import { onMounted, ref } from 'vue'
import { useBasicStore } from '@/stores/basic'
import { useBluetoothStore } from '@/stores/bluetooth'
import { getVideoList } from '@/api/sdk'
const $basic = useBasicStore()
const $bluetooth = useBluetoothStore()
const props = defineProps({
type: {
type: String,
default: 'list'
}
})
const emit = defineEmits(['change'])
const requestFinished = ref(false)
const list = ref([])
const selectList = ref([])
onMounted(async () => {
await getList()
requestFinished.value = true
})
const getList = async () => {
const res = await getVideoList({
lockId: $bluetooth.currentLockInfo.lockId
})
if (res.code === 0) {
// list.value = res.data
list.value = [
{
date: '2025-04-08',
recordList: [
{
recordId: 1,
imagesUrl:
'https://q0.itc.cn/q_70/images03/20250331/84b2646fc92d4ea0b12f1b134652c807.jpeg',
videoUrl:
'https://sf1-cdn-tos.huoshanstatic.com/obj/media-fe/xgplayer_doc_video/mp4/xgplayer-demo-360p.mp4',
operateDate: '1745423939000'
}
]
},
{
date: '2025-04-07',
recordList: [
{
recordId: 2,
imagesUrl:
'https://q0.itc.cn/q_70/images03/20250331/84b2646fc92d4ea0b12f1b134652c807.jpeg',
videoUrl: 'http://vjs.zencdn.net/v/oceans.mp4',
operateDate: '1745423939000'
},
{
recordId: 3,
imagesUrl:
'https://q0.itc.cn/q_70/images03/20250331/84b2646fc92d4ea0b12f1b134652c807.jpeg',
videoUrl: 'http://www.w3school.com.cn/example/html5/mov_bbb.mp4',
operateDate: '1745423939000'
}
]
},
{
date: '2025-04-06',
recordList: [
{
recordId: 4,
imagesUrl:
'https://q0.itc.cn/q_70/images03/20250331/84b2646fc92d4ea0b12f1b134652c807.jpeg',
videoUrl: 'https://www.w3schools.com/html/movie.mp4',
operateDate: '1745423939000'
},
{
recordId: 5,
imagesUrl:
'https://q0.itc.cn/q_70/images03/20250331/84b2646fc92d4ea0b12f1b134652c807.jpeg',
videoUrl: 'https://media.w3.org/2010/05/sintel/trailer.mp4',
operateDate: '1745423939000'
},
{
recordId: 6,
imagesUrl:
'https://q0.itc.cn/q_70/images03/20250331/84b2646fc92d4ea0b12f1b134652c807.jpeg',
videoUrl:
'https://stream7.iqilu.com/10339/upload_transcode/202002/09/20200209105011F0zPoYzHry.mp4',
operateDate: '1745423939000'
}
]
},
{
date: '2025-04-05',
recordList: [
{
recordId: 7,
imagesUrl:
'https://q0.itc.cn/q_70/images03/20250331/84b2646fc92d4ea0b12f1b134652c807.jpeg',
videoUrl: 'http://vjs.zencdn.net/v/oceans.mp4',
operateDate: '1745423939000'
}
]
}
]
} else {
uni.showToast({
title: res.message,
icon: 'none'
})
}
}
const handleVideo = item => {
if (props.type === 'select') {
const isExist = selectList.value.find(data => data.recordId === item.recordId)
if (isExist) {
selectList.value = selectList.value.filter(data => data.recordId !== item.recordId)
} else {
selectList.value.push(item)
}
emit('change', selectList.value)
} else {
$basic.routeJump({
type: props.type === 'list' ? 'navigateTo' : 'redirectTo',
name: 'videoDetail',
params: {
video: JSON.stringify(item)
}
})
}
}
const selectAll = isSelectAll => {
if (props.type === 'select') {
if (isSelectAll) {
list.value.forEach(item => {
item.recordList.forEach(video => {
selectList.value.push(video)
})
})
} else {
selectList.value = []
}
emit('change', selectList.value)
}
}
const refresh = () => {
getList()
}
defineExpose({
refresh,
selectAll
})
</script>
<style lang="scss" scoped>
.empty-list {
width: 150rpx;
height: 150rpx;
margin: 300rpx auto 20rpx 50%;
transform: translateX(-50%);
}
.empty-list-text {
font-size: 32rpx;
color: #999999;
text-align: center;
}
</style>

View File

@ -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'

38
pages/p2p/videoDetail.vue Normal file
View File

@ -0,0 +1,38 @@
<template>
<view>
<view>
<view class="relative" v-if="video?.videoUrl">
<video
:src="video.videoUrl"
play-btn-position="center"
class="w-full h-650"
object-fit="contain"
:poster="video.imagesUrl"
:enable-play-gesture="true"
></video>
<view
class="absolute top-3 left-3 text-white bg-black bg-opacity-50 px-2 py-1 rounded z-10"
>
{{ timeFormat(video.operateDate, 'yyyy-mm-dd hh:MM') }}
</view>
</view>
</view>
<view class="mx-2.5 pb-10">
<VideoList type="detail" />
</view>
</view>
</template>
<script setup>
import { onLoad } from '@dcloudio/uni-app'
import { ref } from 'vue'
import { timeFormat } from 'uview-plus'
import VideoList from './VideoList.vue'
const video = ref(null)
onLoad(options => {
video.value = JSON.parse(options.video)
console.log(video.value)
})
</script>

145
pages/p2p/videoEdit.vue Normal file
View File

@ -0,0 +1,145 @@
<template>
<view>
<view class="flex justify-between items-center px-2.5 py-2">
<view>已选{{ selectList.length }}</view>
<view @click="selectAll">{{ isSelectAll ? '取消全选' : '全选' }}</view>
</view>
<view class="mx-2.5 pb-25">
<VideoList ref="videoListRef" type="select" @change="handleChange" />
</view>
<view class="fixed bottom-0 flex justify-center w-full w-300 mx-auto bg-white">
<view class="flex justify-between w-200 mr-4 h-160">
<view @click="handleDownload">
<view class="flex flex-col items-center">
<image
src="https://oss-lock.xhjcn.ltd/mp/icon_video_download.png"
class="w-50 h-50"
></image>
<view class="mt-2">下载</view>
</view>
</view>
<view @click="handleDelete">
<view class="flex flex-col items-center">
<image
src="https://oss-lock.xhjcn.ltd/mp/icon_video_delete.png"
class="w-50 h-50"
></image>
<view class="mt-2">删除</view>
</view>
</view>
</view>
</view>
</view>
</template>
<script setup>
import { getCurrentInstance, ref } from 'vue'
import VideoList from './VideoList.vue'
import { deleteVideo } from '@/api/sdk'
const instance = getCurrentInstance().proxy
const eventChannel = instance.getOpenerEventChannel()
const videoListRef = ref(null)
const isSelectAll = ref(false)
const selectList = ref([])
const pending = ref(false)
const handleChange = list => {
selectList.value = list
}
const selectAll = () => {
isSelectAll.value = !isSelectAll.value
videoListRef.value.selectAll(isSelectAll.value)
}
const handleDownload = () => {
console.log('下载')
if (selectList.value.length === 0) {
uni.showToast({
title: '请选择要下载的视频',
icon: 'none'
})
return
}
if (selectList.value.length > 1) {
uni.showToast({
title: '视频暂不支持批量下载',
icon: 'none'
})
return
}
uni.showLoading({
title: '下载中'
})
pending.value = true
const url = selectList.value[0].videoUrl
uni.downloadFile({
url,
success: res => {
uni.saveVideoToPhotosAlbum({
filePath: res.tempFilePath,
success: () => {
uni.hideLoading()
pending.value = false
uni.showToast({
title: '下载成功',
icon: 'none'
})
},
fail: () => {
uni.hideLoading()
pending.value = false
uni.showToast({
title: '下载失败',
icon: 'none'
})
}
})
},
fail: () => {
uni.hideLoading()
pending.value = false
uni.showToast({
title: '下载失败',
icon: 'none'
})
}
})
}
const handleDelete = async () => {
if (selectList.value.length === 0) {
uni.showToast({
title: '请选择要删除的视频',
icon: 'none'
})
return
}
uni.showLoading({
title: '删除中'
})
pending.value = true
const idList = selectList.value.map(item => item.recordId)
const { code, message } = await deleteVideo(idList)
uni.hideLoading()
pending.value = false
if (code === 0) {
videoListRef.value.refresh()
eventChannel.emit('refresh')
uni.showToast({
title: '删除成功',
icon: 'success'
})
} else {
uni.showToast({
title: message,
icon: 'none'
})
}
}
</script>

51
pages/p2p/videoLog.vue Normal file
View File

@ -0,0 +1,51 @@
<template>
<view>
<view class="bg-#f5f4f8 flex items-center mx-2.5 my-4 p-4 rounded-xl shadow-sm">
<view>
<view>3天滚动储存</view>
<view class="text-#999999 mt-2 text-sm">
{{ appName }}已为本设备免费提供3天滚动视频储存服务
</view>
</view>
<view class="flex-none whitespace-nowrap mx-1.5">去升级</view>
<up-icon name="arrow-right" />
</view>
<view class="mx-2.5 pb-10">
<view class="flex items-center justify-between">
<view>全部视频</view>
<image
src="https://oss-lock.xhjcn.ltd/mp/icon_edit.png"
@click="handleEdit"
class="w-48 h-48"
/>
</view>
<VideoList ref="videoListRef" />
</view>
</view>
</template>
<script setup>
import { onMounted, ref } from 'vue'
import env from '@/config/env'
import VideoList from './VideoList.vue'
import { useBasicStore } from '@/stores/basic'
const $basic = useBasicStore()
const appName = ref('')
const videoListRef = ref(null)
onMounted(async () => {
appName.value = await env[await getApp().globalData.getEnvConfig()].appName
})
const handleEdit = () => {
$basic.routeJump({
name: 'videoEdit',
events: {
refresh: () => {
videoListRef.value.refresh()
}
}
})
}
</script>

View File

@ -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
}
]

View File

@ -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)
}
}
})