完成电子钥匙和授权管理员的修改功能

This commit is contained in:
范鹏 2025-02-14 13:58:15 +08:00
parent 8cdb4dd0c5
commit 7cd011cc9d
5 changed files with 640 additions and 286 deletions

View File

@ -55,3 +55,30 @@ export function getUserNoListRequest(data) {
data data
}) })
} }
// 修改电子钥匙名称
export function updateKeyNameRequest(data) {
return request({
url: '/key/modifyKeyNameForAdmin',
method: 'POST',
data
})
}
// 修改电子钥匙有效期
export function updateKeyDateRequest(data) {
return request({
url: '/key/updateKeyDate',
method: 'POST',
data
})
}
// 获取电子钥匙详情
export function getKeyRequest(data) {
return request({
url: '/key/detail',
method: 'POST',
data
})
}

View File

@ -1,17 +1,27 @@
<template> <template>
<view> <view>
<view v-if="info"> <view v-if="info">
<view class="item"> <view class="item" @click="() => $refs.modalInput.open()">
<view class="item-title">姓名</view> <view class="item-title">姓名</view>
<view class="item-content">{{ info.keyName }}</view> <view class="flex items-center">
<view class="item-content mr-2">{{ info.keyName }}</view>
<up-icon name="arrow-right"></up-icon>
</view> </view>
<view class="item" style="margin-top: 2rpx"> </view>
<view class="item" style="margin-top: 2rpx" @click="updateTime">
<view class="item-title">有效期</view> <view class="item-title">有效期</view>
<view v-if="info.keyType === 1">永久</view> <view class="flex items-center">
<view v-else> <view v-if="info.keyType === 1" class="mr-2">永久</view>
<view v-else-if="info.keyType === 2" class="mr-2 w-400 text-right">
<view class="item-content">{{ timeFormat(info.startDate, 'yyyy-mm-dd h:M') }}</view> <view class="item-content">{{ timeFormat(info.startDate, 'yyyy-mm-dd h:M') }}</view>
<view class="item-content">{{ timeFormat(info.endDate, 'yyyy-mm-dd h:M') }}</view> <view class="item-content">{{ timeFormat(info.endDate, 'yyyy-mm-dd h:M') }}</view>
</view> </view>
<view v-else class="mr-2">
<view class="item-content">{{ timeFormat(info.startDate, 'yyyy-mm-dd') }}</view>
<view class="item-content">{{ timeFormat(info.endDate, 'yyyy-mm-dd') }}</view>
</view>
<up-icon name="arrow-right"></up-icon>
</view>
</view> </view>
<view class="item" style="margin-top: 20rpx"> <view class="item" style="margin-top: 20rpx">
<view class="item-title">接受者</view> <view class="item-title">接受者</view>
@ -25,11 +35,29 @@
<view class="item-title">发送时间</view> <view class="item-title">发送时间</view>
<view class="item-content">{{ timeFormat(info.sendDate, 'yyyy-mm-dd h:M') }}</view> <view class="item-content">{{ timeFormat(info.sendDate, 'yyyy-mm-dd h:M') }}</view>
</view> </view>
<view class="item !py-2" style="margin-top: 20rpx">
<view class="item-title">仅管理自己创建的用户</view>
<switch
:checked="info.isOnlyManageSelf"
class="transform-scale-90"
@click="changeManageSelf"
:disabled="true"
color="#002ce5"
/>
</view>
<view class="item" style="margin-top: 20rpx" @click="toRecordList"> <view class="item" style="margin-top: 20rpx" @click="toRecordList">
<view class="item-title">操作记录</view> <view class="item-title">操作记录</view>
<up-icon name="arrow-right"></up-icon> <up-icon name="arrow-right"></up-icon>
</view> </view>
<view class="button" @click="showModal = true">删除</view> <view class="button" @click="showModal = true">删除</view>
<ModalInput
ref="modalInput"
title="请输入姓名"
:autoClose="false"
placeholder="请输入姓名"
:value="info.keyName"
@confirm="changeName"
/>
</view> </view>
<up-modal <up-modal
:show="showModal" :show="showModal"
@ -53,19 +81,62 @@
import { getCurrentInstance, ref } from 'vue' import { getCurrentInstance, ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app' import { onLoad } from '@dcloudio/uni-app'
import { timeFormat } from 'uview-plus' import { timeFormat } from 'uview-plus'
import { deleteKeyRequest } from '@/api/key' import {
deleteKeyRequest,
getKeyRequest,
updateKeyDateRequest,
updateKeyNameRequest
} from '@/api/key'
import { useBasicStore } from '@/stores/basic' import { useBasicStore } from '@/stores/basic'
import { useBluetoothStore } from '@/stores/bluetooth'
const instance = getCurrentInstance().proxy const instance = getCurrentInstance().proxy
const eventChannel = instance.getOpenerEventChannel() const eventChannel = instance.getOpenerEventChannel()
const $basic = useBasicStore() const $basic = useBasicStore()
const $bluetooth = useBluetoothStore()
const info = ref(null) const info = ref(null)
const showModal = ref(false) const showModal = ref(false)
const checked = ref(false) const checked = ref(false)
const modalInput = ref(null)
const pending = ref(false)
const changeName = async name => {
if (!name) {
uni.showToast({
title: '请输入姓名',
icon: 'none'
})
return
}
if (pending.value) return
pending.value = true
const { code, message } = await updateKeyNameRequest({
lockId: $bluetooth.currentLockInfo.lockId,
keyId: info.value.keyId,
keyNameForAdmin: name
})
pending.value = false
if (code === 0) {
modalInput.value.close()
eventChannel.emit('refresherList', {})
info.value.keyName = name
uni.showToast({
title: '更新成功',
icon: 'none'
})
} else {
uni.showToast({
title: message,
icon: 'none'
})
}
}
onLoad(options => { onLoad(options => {
if (options.info) { if (options.info) {
info.value = JSON.parse(options.info) info.value = JSON.parse(options.info)
@ -73,6 +144,56 @@
} }
}) })
const changeManageSelf = async () => {
if (pending.value) return
pending.value = true
uni.showLoading({
title: '更新中'
})
const { code, message } = await updateKeyDateRequest({
lockId: $bluetooth.currentLockInfo.lockId,
keyId: info.value.keyId,
keyType: info.value.keyType,
startDate: info.value.startDate,
endDate: info.value.endDate,
isOnlyManageSelf: info.value.isOnlyManageSelf === 1 ? 0 : 1
})
pending.value = false
uni.hideLoading()
if (code === 0) {
info.value.isOnlyManageSelf = info.value.isOnlyManageSelf === 1 ? 0 : 1
eventChannel.emit('refresherList', {})
uni.showToast({
title: '更新成功',
icon: 'none'
})
} else {
uni.showToast({
title: message,
icon: 'none'
})
}
}
const updateTime = () => {
$basic.routeJump({
name: 'temporaryDate',
params: {
info: JSON.stringify({ ...info.value, type: 'key' })
},
events: {
refresh() {
eventChannel.emit('refresherList', {})
getKeyRequest({
keyId: info.value.keyId
}).then(res => {
info.value = res.data
})
}
}
})
}
const toRecordList = async () => { const toRecordList = async () => {
$basic.routeJump({ $basic.routeJump({
name: 'typeRecordList', name: 'typeRecordList',

View File

@ -145,6 +145,7 @@
import { updateRemoteRequest } from '@/api/remote' import { updateRemoteRequest } from '@/api/remote'
import { updatePalmVeinRequest } from '@/api/palmVein' import { updatePalmVeinRequest } from '@/api/palmVein'
import { updateFaceRequest } from '@/api/face' import { updateFaceRequest } from '@/api/face'
import { updateKeyDateRequest } from '@/api/key'
const instance = getCurrentInstance().proxy const instance = getCurrentInstance().proxy
const eventChannel = instance.getOpenerEventChannel() const eventChannel = instance.getOpenerEventChannel()
@ -265,7 +266,33 @@
uni.showLoading({ uni.showLoading({
title: '更新中' title: '更新中'
}) })
if (info.value.type === 'key') {
const data = await updateKeyDateRequest({
lockId: $bluetooth.currentLockInfo.lockId,
keyId: info.value.keyId,
keyType: 4,
weekDays: weekDays.value.sort(),
startDate: updateTime(startDate.value, startTimeText.value),
endDate: updateTime(endDate.value, endTimeText.value),
startTime: updateTime(startDate.value, startTimeText.value),
endTime: updateTime(endDate.value, endTimeText.value)
})
uni.hideLoading()
pending.value = false
if (data.code === 0) {
eventChannel.emit('refresh', {})
$basic.backAndToast('更新成功')
uni.showToast({
title: '更新成功',
icon: 'none'
})
} else {
uni.showToast({
title: data.message,
icon: 'none'
})
}
} else {
const { code } = await $bluetooth.registerAuthentication({ const { code } = await $bluetooth.registerAuthentication({
type: info.value.type, type: info.value.type,
operate: 1, operate: 1,
@ -370,6 +397,7 @@
} }
} }
} }
}
const updateTime = (datetime, timeStr) => { const updateTime = (datetime, timeStr) => {
const date = new Date(datetime) const date = new Date(datetime)

View File

@ -1,49 +1,89 @@
<template> <template>
<view> <view>
<view class="item"> <view class="item" @click="() => $refs.modalInput.open()">
<view class="item-title" style="width: 350rpx">姓名</view> <view class="item-title" style="width: 350rpx">姓名</view>
<view class="item-content">{{ currentKeyInfo.keyName }}</view> <view class="flex items-center">
<view class="item-content mr-2">{{ $lock.currentKeyInfo.keyName }}</view>
<up-icon name="arrow-right"></up-icon>
</view> </view>
<view class="item" style="margin-top: 2rpx"> </view>
<view class="item" style="margin-top: 2rpx" @click="updateTime">
<view class="item-title">有效期</view> <view class="item-title">有效期</view>
<view v-if="currentKeyInfo.keyType === 1">永久</view> <view class="flex items-center">
<view v-else-if="currentKeyInfo.keyType === 3">单次</view> <view v-if="$lock.currentKeyInfo.keyType === 1" class="mr-2">永久</view>
<view v-else-if="currentKeyInfo.keyType === 4"> <view v-else-if="$lock.currentKeyInfo.keyType === 3">单次</view>
<view class="item-content">{{ timeFormat(currentKeyInfo.startDate, 'yyyy-mm-dd') }}</view> <view v-else-if="$lock.currentKeyInfo.keyType === 4" class="mr-2">
<view class="item-content">{{ timeFormat(currentKeyInfo.endDate, 'yyyy-mm-dd') }}</view>
</view>
<view v-else>
<view class="item-content">{{ <view class="item-content">{{
timeFormat(currentKeyInfo.startDate, 'yyyy-mm-dd h:M') timeFormat($lock.currentKeyInfo.startDate, 'yyyy-mm-dd')
}}</view> }}</view>
<view class="item-content">{{ timeFormat(currentKeyInfo.endDate, 'yyyy-mm-dd h:M') }}</view> <view class="item-content">{{
timeFormat($lock.currentKeyInfo.endDate, 'yyyy-mm-dd')
}}</view>
</view>
<view v-else class="mr-2">
<view class="item-content">{{
timeFormat($lock.currentKeyInfo.startDate, 'yyyy-mm-dd h:M')
}}</view>
<view class="item-content">{{
timeFormat($lock.currentKeyInfo.endDate, 'yyyy-mm-dd h:M')
}}</view>
</view>
<up-icon v-if="$lock.currentKeyInfo.keyType !== 3" name="arrow-right"></up-icon>
</view> </view>
</view> </view>
<view v-if="currentKeyInfo.keyType === 4" class="item" style="margin-top: 2rpx"> <view
v-if="$lock.currentKeyInfo.keyType === 4"
class="item"
style="margin-top: 2rpx"
@click="updateTime"
>
<view class="item-title">有效日</view> <view class="item-title">有效日</view>
<view class="item-content">{{ <view class="flex items-center">
convertWeekDaysToChineseString(currentKeyInfo.weekDays) <view class="item-content mr-2">{{
$lock.convertWeekDaysToChineseString($lock.currentKeyInfo.weekDays)
}}</view> }}</view>
<up-icon name="arrow-right"></up-icon>
</view> </view>
<view class="item" v-if="currentKeyInfo.keyType === 4" style="margin-top: 2rpx"> </view>
<view
class="item"
v-if="$lock.currentKeyInfo.keyType === 4"
style="margin-top: 2rpx"
@click="updateTime"
>
<view class="item-title">有效时间</view> <view class="item-title">有效时间</view>
<view class="item-content"> <view class="flex items-center">
{{ timeFormat(currentKeyInfo.startDate, 'h:M') }}{{ <view class="item-content mr-2">
timeFormat(currentKeyInfo.endDate, 'h:M') {{ timeFormat($lock.currentKeyInfo.startDate, 'h:M') }}{{
}} timeFormat($lock.currentKeyInfo.endDate, 'h:M')
}}</view
>
<up-icon name="arrow-right"></up-icon>
</view> </view>
</view> </view>
<view class="item" style="margin-top: 20rpx"> <view class="item" style="margin-top: 20rpx">
<view class="item-title">接收者</view> <view class="item-title">接收者</view>
<view class="item-content">{{ currentKeyInfo.username }}</view> <view class="item-content">{{ $lock.currentKeyInfo.username }}</view>
</view> </view>
<view class="item" style="margin-top: 2rpx"> <view class="item" style="margin-top: 2rpx">
<view class="item-title">发送人</view> <view class="item-title">发送人</view>
<view class="item-content">{{ currentKeyInfo.senderUsername }}</view> <view class="item-content">{{ $lock.currentKeyInfo.senderUsername }}</view>
</view> </view>
<view class="item" style="margin-top: 2rpx"> <view class="item" style="margin-top: 2rpx">
<view class="item-title">发送时间</view> <view class="item-title">发送时间</view>
<view class="item-content">{{ timeFormat(currentKeyInfo.sendDate, 'yyyy-mm-dd h:M') }}</view> <view class="item-content">{{
timeFormat($lock.currentKeyInfo.sendDate, 'yyyy-mm-dd h:M')
}}</view>
</view>
<view class="item !py-2" style="margin-top: 20rpx" v-if="$lock.currentKeyInfo.keyRight === 1">
<view class="item-title">仅管理自己创建的用户</view>
<switch
:checked="$lock.currentKeyInfo.isOnlyManageSelf"
class="transform-scale-90"
@click="changeManageSelf"
:disabled="true"
color="#002ce5"
/>
</view> </view>
<view class="item" style="margin-top: 20rpx" @click="toRecordList"> <view class="item" style="margin-top: 20rpx" @click="toRecordList">
<view class="item-title">操作记录</view> <view class="item-title">操作记录</view>
@ -65,70 +105,184 @@
</view> </view>
</view> </view>
</up-modal> </up-modal>
<ModalInput
ref="modalInput"
title="请输入姓名"
:autoClose="false"
placeholder="请输入姓名"
:value="$lock.currentKeyInfo.keyName"
@confirm="changeName"
/>
</view> </view>
</template> </template>
<script> <script setup>
import { mapActions, mapState } from 'pinia'
import { timeFormat } from 'uview-plus' import { timeFormat } from 'uview-plus'
import { ref } from 'vue'
import { useLockStore } from '@/stores/lock' import { useLockStore } from '@/stores/lock'
import { deleteKeyRequest } from '@/api/key' import {
deleteKeyRequest,
getKeyRequest,
updateKeyDateRequest,
updateKeyNameRequest
} from '@/api/key'
import { useBasicStore } from '@/stores/basic' import { useBasicStore } from '@/stores/basic'
import { useBluetoothStore } from '@/stores/bluetooth'
export default { const $lock = useLockStore()
data() { const $basic = useBasicStore()
return { const $bluetooth = useBluetoothStore()
showModal: false,
checked: false const showModal = ref(false)
const checked = ref(false)
const modalInput = ref(null)
const pending = ref(false)
const changeManageSelf = async () => {
if (pending.value) return
pending.value = true
uni.showLoading({
title: '更新中'
})
const { code, message } = await updateKeyDateRequest({
lockId: $bluetooth.currentLockInfo.lockId,
keyId: $lock.currentKeyInfo.keyId,
keyType: $lock.currentKeyInfo.keyType,
startDate: $lock.currentKeyInfo.startDate,
endDate: $lock.currentKeyInfo.endDate,
isOnlyManageSelf: $lock.currentKeyInfo.isOnlyManageSelf === 1 ? 0 : 1
})
pending.value = false
uni.hideLoading()
if (code === 0) {
$lock.updateCurrentKeyInfo({
...$lock.currentKeyInfo,
isOnlyManageSelf: $lock.currentKeyInfo.isOnlyManageSelf === 1 ? 0 : 1
})
$lock.updateKeySearch({
...$lock.keySearch,
pageNo: 1
})
$lock.getKeyList($lock.keySearch)
uni.showToast({
title: '更新成功',
icon: 'none'
})
} else {
uni.showToast({
title: message,
icon: 'none'
})
} }
}, }
computed: {
...mapState(useLockStore, ['currentKeyInfo', 'keySearch']) const updateTime = () => {
}, if ($lock.currentKeyInfo.keyType === 3) return
methods: { $basic.routeJump({
timeFormat, name:
...mapActions(useLockStore, [ $lock.currentKeyInfo.keyType === 1 || $lock.currentKeyInfo.keyType === 2
'updateKeySearch', ? 'temporaryDate'
'getKeyList', : 'cycleDate',
'convertWeekDaysToChineseString'
]),
...mapActions(useBasicStore, ['backAndToast', 'routeJump']),
async toRecordList() {
this.routeJump({
name: 'typeRecordList',
params: { params: {
name: this.currentKeyInfo.keyName, info: JSON.stringify({ ...$lock.currentKeyInfo, type: 'key' })
key: 'keyId', },
id: this.currentKeyInfo.keyId events: {
refresh() {
$lock.updateKeySearch({
...$lock.keySearch,
pageNo: 1
})
$lock.getKeyList($lock.keySearch)
getKeyRequest({
lockId: $bluetooth.currentLockInfo.lockId,
keyId: $lock.currentKeyInfo.keyId
}).then(res => {
$lock.updateCurrentKeyInfo(res.data)
})
}
} }
}) })
}, }
cancelModal() {
this.showModal = false const changeName = async name => {
this.checked = false if (!name) {
}, uni.showToast({
changeRadio() { title: '请输入姓名',
this.checked = !this.checked icon: 'none'
}, })
async confirmModal() { return
}
if (pending.value) return
pending.value = true
const { code, message } = await updateKeyNameRequest({
lockId: $bluetooth.currentLockInfo.lockId,
keyId: $lock.currentKeyInfo.keyId,
keyNameForAdmin: name
})
pending.value = false
if (code === 0) {
modalInput.value.close()
$lock.updateKeySearch({
...$lock.keySearch,
pageNo: 1
})
$lock.getKeyList($lock.keySearch)
$lock.updateCurrentKeyInfo({
...$lock.currentKeyInfo,
keyName: name
})
uni.showToast({
title: '更新成功',
icon: 'none'
})
} else {
uni.showToast({
title: message,
icon: 'none'
})
}
}
const toRecordList = () => {
$basic.routeJump({
name: 'typeRecordList',
params: {
name: $lock.currentKeyInfo.keyName,
key: 'keyId',
id: $lock.currentKeyInfo.keyId
}
})
}
const cancelModal = () => {
showModal.value = false
checked.value = false
}
const changeRadio = () => {
checked.value = !checked.value
}
const confirmModal = async () => {
uni.showLoading({ uni.showLoading({
title: '删除中', title: '删除中',
mask: true mask: true
}) })
const that = this
const { code } = await deleteKeyRequest({ const { code } = await deleteKeyRequest({
keyId: that.currentKeyInfo.keyId, keyId: $lock.currentKeyInfo.keyId,
includeUnderlings: that.checked ? 1 : 0 includeUnderlings: checked.value ? 1 : 0
}) })
that.showModal = false showModal.value = false
if (code === 0) { if (code === 0) {
that.updateKeySearch({ $lock.updateKeySearch({
...that.keySearch, ...$lock.keySearch,
pageNo: 1 pageNo: 1
}) })
that.getKeyList(that.keySearch) $lock.getKeyList($lock.keySearch)
uni.hideLoading() uni.hideLoading()
that.backAndToast('删除成功') $basic.backAndToast('删除成功')
} else { } else {
uni.hideLoading() uni.hideLoading()
uni.showToast({ uni.showToast({
@ -136,11 +290,11 @@
icon: 'none' icon: 'none'
}) })
} }
}, }
async deleteKey() {
const that = this const deleteKey = async () => {
if (that.currentKeyInfo.keyRight === 1) { if ($lock.currentKeyInfo.keyRight === 1) {
that.showModal = true showModal.value = true
return return
} }
uni.showModal({ uni.showModal({
@ -153,16 +307,16 @@
mask: true mask: true
}) })
const { code: requestCode, message } = await deleteKeyRequest({ const { code: requestCode, message } = await deleteKeyRequest({
keyId: that.currentKeyInfo.keyId keyId: $lock.currentKeyInfo.keyId
}) })
if (requestCode === 0) { if (requestCode === 0) {
uni.hideLoading() uni.hideLoading()
that.updateKeySearch({ $lock.updateKeySearch({
...that.keySearch, ...$lock.keySearch,
pageNo: 1 pageNo: 1
}) })
await that.getKeyList(that.keySearch) await $lock.getKeyList($lock.keySearch)
that.backAndToast('删除成功') $lock.backAndToast('删除成功')
} else { } else {
uni.hideLoading() uni.hideLoading()
uni.showToast({ uni.showToast({
@ -174,8 +328,6 @@
} }
}) })
} }
}
}
</script> </script>
<style lang="scss"> <style lang="scss">

View File

@ -78,6 +78,7 @@
import { updateRemoteRequest } from '@/api/remote' import { updateRemoteRequest } from '@/api/remote'
import { updateFaceRequest } from '@/api/face' import { updateFaceRequest } from '@/api/face'
import { updatePalmVeinRequest } from '@/api/palmVein' import { updatePalmVeinRequest } from '@/api/palmVein'
import { updateKeyDateRequest } from '@/api/key'
const instance = getCurrentInstance().proxy const instance = getCurrentInstance().proxy
const eventChannel = instance.getOpenerEventChannel() const eventChannel = instance.getOpenerEventChannel()
@ -108,12 +109,12 @@
const data = JSON.parse(options.info) const data = JSON.parse(options.info)
if (data.startDate) { if (data.startDate) {
startDate.value = data.startDate startDate.value = data.startDate
endDate.value = data.endDate endDate.value = data.endDate === 0 ? data.startDate + 24 * 60 * 60 * 1000 : data.endDate
info.value = data info.value = data
defaultStartDate.value = data.startDate defaultStartDate.value = data.startDate
defaultEndDate.value = data.endDate defaultEndDate.value =
data.endDate === 0 ? data.startDate + 24 * 60 * 60 * 1000 : data.endDate
} }
console.log(info.value)
} }
}) })
@ -139,6 +140,30 @@
title: '更新中' title: '更新中'
}) })
if (info.value.type === 'key') {
const data = await updateKeyDateRequest({
lockId: $bluetooth.currentLockInfo.lockId,
keyId: info.value.keyId,
keyType: 2,
startDate: startDate.value,
endDate: endDate.value
})
uni.hideLoading()
pending.value = false
if (data.code === 0) {
eventChannel.emit('refresh', {})
$basic.backAndToast('更新成功')
uni.showToast({
title: '更新成功',
icon: 'none'
})
} else {
uni.showToast({
title: data.message,
icon: 'none'
})
}
} else {
const { code } = await $bluetooth.registerAuthentication({ const { code } = await $bluetooth.registerAuthentication({
type: info.value.type, type: info.value.type,
operate: 1, operate: 1,
@ -225,6 +250,7 @@
}) })
} }
} }
}
const confirmDate = (type, date) => { const confirmDate = (type, date) => {
if (type === 'start') { if (type === 'start') {