diff --git a/pages/home/home.vue b/pages/home/home.vue
index 1426b33..c6c0713 100644
--- a/pages/home/home.vue
+++ b/pages/home/home.vue
@@ -35,7 +35,8 @@
{{lock.lockAlias}}
- {{ getTimeLimit(lock.keyType) }}
+ {{
+ getTimeLimit(lock.keyType) }}
{{ timeFormat(lock.startDate, 'yyyy-mm-dd h:M') }}
{{ timeFormat(lock.endDate, 'yyyy-mm-dd h:M ') + getTimeLimit(lock.keyType) }}
diff --git a/pages/lockDetail/lockDetail.vue b/pages/lockDetail/lockDetail.vue
index 65c3c2d..61fff9f 100644
--- a/pages/lockDetail/lockDetail.vue
+++ b/pages/lockDetail/lockDetail.vue
@@ -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
}
diff --git a/pages/setting/setting.vue b/pages/setting/setting.vue
index dd5b8f6..550fc5f 100644
--- a/pages/setting/setting.vue
+++ b/pages/setting/setting.vue
@@ -152,7 +152,6 @@ export default {
})
that.getLockList(that.lockSearch)
that.backAndToast('删除成功', 2)
- uni.navigateBack()
} else {
uni.hideLoading()
uni.showToast({
diff --git a/stores/bluetooth.js b/stores/bluetooth.js
index 14bb798..d611fc5 100644
--- a/stores/bluetooth.js
+++ b/stores/bluetooth.js
@@ -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,