支持单次和循环电子钥匙的使用与展示

This commit is contained in:
范鹏 2024-09-02 16:09:52 +08:00
parent b18c77bb2c
commit a77d39e19a
4 changed files with 53 additions and 17 deletions

View File

@ -35,7 +35,8 @@
</view>
<view class="lock-name">{{lock.lockAlias}}</view>
<view class="lock-time">
<view v-if="lock.keyType === 1" style="font-size: 32rpx">{{ getTimeLimit(lock.keyType) }}</view>
<view v-if="lock.keyType === 1 || lock.keyType === 3" style="font-size: 32rpx">{{
getTimeLimit(lock.keyType) }}</view>
<view v-else>
<view>{{ timeFormat(lock.startDate, 'yyyy-mm-dd h:M') }}</view>
<view>{{ timeFormat(lock.endDate, 'yyyy-mm-dd h:M ') + getTimeLimit(lock.keyType) }}</view>

View File

@ -61,6 +61,7 @@ import { useLockStore } from '@/stores/lock'
import { useUserStore } from '@/stores/user'
import { getLockNetTokenRequest } from '@/api/lock'
import { timeFormat } from 'uview-plus'
import { deleteKeyRequest } from '@/api/key'
export default {
data () {
@ -71,8 +72,9 @@ export default {
}
},
computed: {
...mapState(useBluetoothStore, ['currentLockInfo']),
...mapState(useUserStore, ['userInfo'])
...mapState(useBluetoothStore, ['currentLockInfo', 'keyId']),
...mapState(useUserStore, ['userInfo']),
...mapState(useLockStore, ['lockSearch']),
},
components: {
SwitchLoading
@ -84,9 +86,9 @@ export default {
this.getServeTime()
},
methods: {
...mapActions(useLockStore, ['getRole']),
...mapActions(useLockStore, ['getRole', 'updateLockSearch', 'getLockList']),
...mapActions(useBluetoothStore, ['openDoor', 'updateServerTimestamp']),
...mapActions(useBasicStore, ['routeJump']),
...mapActions(useBasicStore, ['routeJump', 'backAndToast']),
powerTip() {
const that = this
const time = timeFormat(that.currentLockInfo.electricQuantityDate, 'yyyy-mm-dd h:M')
@ -151,12 +153,30 @@ export default {
title: `${type === 'close' ? '关' : '开'}锁成功`,
icon: 'none'
})
} else if(code === 13) {
uni.showToast({
title: `只能在循环时间内操作门锁`,
icon: 'none'
})
} else {
uni.showToast({
title: `${type === 'close' ? '关' : '开'}锁失败,请保证在锁附近`,
icon: 'none'
})
}
if(this.currentLockInfo.keyType === 3) {
const { code: deleteKeyCode } = await deleteKeyRequest({
keyId: this.keyId
})
if(deleteKeyCode === 0) {
this.updateLockSearch({
...this.lockSearch,
pageNo: 1
})
this.getLockList(this.lockSearch)
this.backAndToast('单次钥匙已在被使用后删除', 1)
}
}
this.$refs.loading.close()
this.pending = false
}

View File

@ -152,7 +152,6 @@ export default {
})
that.getLockList(that.lockSearch)
that.backAndToast('删除成功', 2)
uni.navigateBack()
} else {
uni.hideLoading()
uni.showToast({

View File

@ -711,6 +711,21 @@ export const useBluetoothStore = defineStore('ble', {
}
})
},
// 周数组转换
convertWeekdaysToNumber(weekDay) {
let weekStr = '00000000'
for (const day of weekDay) {
const index = day % 7 // 将周日的索引转换为0
weekStr = weekStr.substring(0, index) + '1' + weekStr.substring(index + 1)
}
// 倒序 weekStr
weekStr = weekStr.split('').reverse().join('')
const weekRound = parseInt(weekStr, 2)
return weekRound
},
// 查找设备并连接
async searchAndConnectDevice() {
const that = this
@ -771,26 +786,27 @@ export const useBluetoothStore = defineStore('ble', {
const timestamp = parseInt(new Date().getTime() / 1000)
const password = (Math.floor(Math.random() * 900000) + 100000).toString()
console.log('用户未添加,开始添加用户')
const { code: addUserCode } = await this.addLockUser({
const addUserParams = {
name: this.currentLockInfo.name,
keyId: this.keyId,
authUid: this.currentLockInfo.senderUserId.toString(),
uid: this.currentLockInfo.uid.toString(),
openMode: 1,
keyType: 0,
startDate: this.currentLockInfo.startDate === 0 ? timestamp : this.currentLockInfo.startDate,
expireDate: this.currentLockInfo.endDate === 0 ? 0xffffffff : this.currentLockInfo.endDate,
startDate: this.currentLockInfo.startDate === 0 ? timestamp : parseInt(this.currentLockInfo.startDate / 1000),
expireDate: this.currentLockInfo.endDate === 0 ? 0xffffffff : parseInt(this.currentLockInfo.endDate / 1000),
useCountLimit: this.currentLockInfo.keyType === 3 ? 1 : 0xffff,
isRound: 0,
weekRound: 0,
startHour: 0,
startMin: 0,
endHour: 0,
endMin: 0,
isRound: this.currentLockInfo.keyType === 4 ? 1 : 0,
weekRound: this.currentLockInfo.keyType === 4 ? this.convertWeekdaysToNumber(this.currentLockInfo.weekDays) : 0,
startHour: this.currentLockInfo.keyType === 4 ? new Date(this.currentLockInfo.startDate).getHours() : 0,
startMin: this.currentLockInfo.keyType === 4 ? new Date(this.currentLockInfo.startDate).getMinutes() : 0,
endHour: this.currentLockInfo.keyType === 4 ? new Date(this.currentLockInfo.endDate).getHours() : 0,
endMin: this.currentLockInfo.keyType === 4 ? new Date(this.currentLockInfo.endDate).getMinutes() : 0,
role: 0,
password
})
console.log('添加用户蓝牙结果', addUserCode)
}
const { code: addUserCode } = await this.addLockUser(addUserParams)
console.log('添加用户蓝牙结果', addUserCode, addUserParams)
if(addUserCode === 0) {
const { code } = await updateLockUserNoRequest({
keyId: this.keyId,