diff --git a/pages/home/home.vue b/pages/home/home.vue index 1426b33..a46fb54 100644 --- a/pages/home/home.vue +++ b/pages/home/home.vue @@ -30,12 +30,13 @@ {{lock.electricQuantity}}% - {{getRole(lock.userType)}} + {{getRole(lock.userType, lock.keyRight)}} {{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/keyDetail/keyDetail.vue b/pages/keyDetail/keyDetail.vue index aa9aa4a..c6f1a61 100644 --- a/pages/keyDetail/keyDetail.vue +++ b/pages/keyDetail/keyDetail.vue @@ -2,16 +2,31 @@ 名称 - {{ currentKeyInfo.nickname }} + {{ currentKeyInfo.keyName }} 有效期 永久 + 单次 + + {{ timeFormat(currentKeyInfo.startDate, 'yyyy-mm-dd') }} + {{ timeFormat(currentKeyInfo.endDate, 'yyyy-mm-dd') }} + {{ timeFormat(currentKeyInfo.startDate, 'yyyy-mm-dd h:M') }} {{ timeFormat(currentKeyInfo.endDate, 'yyyy-mm-dd h:M') }} + + 有效日 + {{ convertWeekDaysToChineseString(currentKeyInfo.weekDays) }} + + + 有效时间 + + {{ timeFormat(currentKeyInfo.startDate, 'h:M') }}-{{ timeFormat(currentKeyInfo.endDate, 'h:M') }} + + 接收者 {{ currentKeyInfo.username }} @@ -78,8 +93,23 @@ export default { } } }) + }, + convertWeekDaysToChineseString(weekDays) { + const dayMap = { + 1: '一', + 2: '二', + 3: '三', + 4: '四', + 5: '五', + 6: '六', + 7: '日' + } + + const chineseWeekDays = weekDays.map(day => dayMap[day]) + + return chineseWeekDays.join(',') } - }, + } } diff --git a/pages/keyList/keyList.vue b/pages/keyList/keyList.vue index 303b8ce..fd41edf 100644 --- a/pages/keyList/keyList.vue +++ b/pages/keyList/keyList.vue @@ -280,7 +280,7 @@ page { } .key-right-bottom { - font-size: 26rpx; + font-size: 24rpx; color: #999999; } } diff --git a/pages/lockDetail/lockDetail.vue b/pages/lockDetail/lockDetail.vue index 65c3c2d..4f5d080 100644 --- a/pages/lockDetail/lockDetail.vue +++ b/pages/lockDetail/lockDetail.vue @@ -16,7 +16,7 @@ - {{ getRole(currentLockInfo.userType) }} + {{ getRole(currentLockInfo.userType, currentLockInfo.keyRight) }} + 功能 - 电子钥匙 - 密码 @@ -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/passwordDetail/passwordDetail.vue b/pages/passwordDetail/passwordDetail.vue index abfd8bc..85f6f69 100644 --- a/pages/passwordDetail/passwordDetail.vue +++ b/pages/passwordDetail/passwordDetail.vue @@ -11,10 +11,13 @@ 有效期 永久 - + {{ timeFormat(currentPasswordInfo.startDate, 'yyyy-mm-dd h:M') }} {{ timeFormat(currentPasswordInfo.endDate, 'yyyy-mm-dd h:M') }} + + {{ currentPasswordInfo.timeText }} + 发送人 diff --git a/pages/passwordList/passwordList.vue b/pages/passwordList/passwordList.vue index da16990..afa40b0 100644 --- a/pages/passwordList/passwordList.vue +++ b/pages/passwordList/passwordList.vue @@ -303,11 +303,11 @@ page { .password-right-top { font-size: 32rpx; font-weight: bold; - padding-bottom: 6rpx; + padding-bottom: 10rpx; } .password-right-bottom { - font-size: 26rpx; + font-size: 24rpx; color: #999999; } } 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, diff --git a/stores/lock.js b/stores/lock.js index 8071158..1cb2120 100644 --- a/stores/lock.js +++ b/stores/lock.js @@ -66,9 +66,11 @@ export const useLockStore = defineStore('lock', { updateCurrentPasswordInfo(info) { this.currentPasswordInfo = info }, - getRole(userType) { + getRole(userType, keyRight) { if(userType === 110301) { return '超级管理员' + } else if(keyRight === 1) { + return '授权管理员' } else { return '普通用户' } @@ -118,10 +120,41 @@ export const useLockStore = defineStore('lock', { if(code === 0) { this.passwordTotal = data.total for(let i = 0; i < data.list.length; i++) { - if(data.list[i].keyboardPwdType === 2) { - data.list[i].timeText = `${timeFormat(new Date(data.list[i].created_at), 'yyyy-mm-dd h:M')} 永久` + if(data.list[i].keyboardPwdType === 1) { + data.list[i].timeText = `${timeFormat(new Date(data.list[i].startDate), 'yyyy-mm-dd h:M')} 单次` + } else if(data.list[i].keyboardPwdType === 2) { + data.list[i].timeText = `${timeFormat(new Date(data.list[i].startDate), 'yyyy-mm-dd h:M')} 永久` } else if(data.list[i].keyboardPwdType === 3) { data.list[i].timeText = `${data.list[i].validTimeStr} 限时` + } else if(data.list[i].keyboardPwdType === 4) { + data.list[i].timeText = `${timeFormat(new Date(data.list[i].startDate), 'yyyy-mm-dd h:M')} 清空码` + } else { + let text = '' + if(data.list[i].keyboardPwdType === 5) { + text = '周末' + } else if(data.list[i].keyboardPwdType === 6) { + text = '每日' + } else if(data.list[i].keyboardPwdType === 7) { + text = '工作日' + } else if(data.list[i].keyboardPwdType === 8) { + text = '周一' + } else if(data.list[i].keyboardPwdType === 9) { + text = '周二' + } else if(data.list[i].keyboardPwdType === 10) { + text = '周三' + } else if(data.list[i].keyboardPwdType === 11) { + text = '周四' + } else if(data.list[i].keyboardPwdType === 12) { + text = '周五' + } else if(data.list[i].keyboardPwdType === 13) { + text = '周六' + } else if(data.list[i].keyboardPwdType === 14) { + text = '周日' + } + data.list[i].timeText = `${text} ${data.list[i].hoursStart}:00-${data.list[i].hoursEnd}:00 循环` + } + if(data.list[i].isCustom === 1) { + data.list[i].timeText += ' 自定义' } } if(params.pageNo === 1) { @@ -143,10 +176,15 @@ export const useLockStore = defineStore('lock', { if(code === 0) { this.keyTotal = data.total for(let i = 0; i < data.list.length; i++) { - if(data.list[i].keyType === 2) { + console.log(data.list[i].keyType) + if(data.list[i].keyType === 1) { + data.list[i].timeText = `${timeFormat(new Date(data.list[i].sendDate), 'yyyy-mm-dd h:M')} 永久` + } else if(data.list[i].keyType === 2) { data.list[i].timeText = `${timeFormat(new Date(data.list[i].startDate), 'yyyy-mm-dd h:M')} - ${timeFormat(new Date(data.list[i].endDate), 'yyyy-mm-dd h:M')} 限时` + } else if(data.list[i].keyType === 3) { + data.list[i].timeText = `${timeFormat(new Date(data.list[i].sendDate), 'yyyy-mm-dd h:M')} 单次` } else { - data.list[i].timeText = `${timeFormat(new Date(data.list[i].startDate), 'yyyy-mm-dd h:M')} 永久` + data.list[i].timeText = `循环` } } if(params.pageNo === 1) {