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

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
})
}
// 修改电子钥匙名称
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,16 +1,26 @@
<template>
<view>
<view v-if="info">
<view class="item">
<view class="item" @click="() => $refs.modalInput.open()">
<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 class="item" style="margin-top: 2rpx" @click="updateTime">
<view class="item-title">有效期</view>
<view v-if="info.keyType === 1">永久</view>
<view v-else>
<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="flex items-center">
<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.endDate, 'yyyy-mm-dd h:M') }}</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 class="item" style="margin-top: 20rpx">
@ -25,11 +35,29 @@
<view class="item-title">发送时间</view>
<view class="item-content">{{ timeFormat(info.sendDate, 'yyyy-mm-dd h:M') }}</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-title">操作记录</view>
<up-icon name="arrow-right"></up-icon>
</view>
<view class="button" @click="showModal = true">删除</view>
<ModalInput
ref="modalInput"
title="请输入姓名"
:autoClose="false"
placeholder="请输入姓名"
:value="info.keyName"
@confirm="changeName"
/>
</view>
<up-modal
:show="showModal"
@ -53,19 +81,62 @@
import { getCurrentInstance, ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { timeFormat } from 'uview-plus'
import { deleteKeyRequest } from '@/api/key'
import {
deleteKeyRequest,
getKeyRequest,
updateKeyDateRequest,
updateKeyNameRequest
} from '@/api/key'
import { useBasicStore } from '@/stores/basic'
import { useBluetoothStore } from '@/stores/bluetooth'
const instance = getCurrentInstance().proxy
const eventChannel = instance.getOpenerEventChannel()
const $basic = useBasicStore()
const $bluetooth = useBluetoothStore()
const info = ref(null)
const showModal = 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 => {
if (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 () => {
$basic.routeJump({
name: 'typeRecordList',

View File

@ -145,6 +145,7 @@
import { updateRemoteRequest } from '@/api/remote'
import { updatePalmVeinRequest } from '@/api/palmVein'
import { updateFaceRequest } from '@/api/face'
import { updateKeyDateRequest } from '@/api/key'
const instance = getCurrentInstance().proxy
const eventChannel = instance.getOpenerEventChannel()
@ -265,88 +266,19 @@
uni.showLoading({
title: '更新中'
})
const { code } = await $bluetooth.registerAuthentication({
type: info.value.type,
operate: 1,
isAdmin: info.value.type,
isForce: info.value.isForce,
isRound: 1,
weekDays: weekDays.value.sort(),
no: info.value[`${info.value.type}Number`],
userCountLimit: 0xffff,
keyId: $bluetooth.keyId.toString(),
uid: $user.userInfo.uid.toString(),
startDate: updateTime(startDate.value, startTimeText.value),
endDate: updateTime(endDate.value, endTimeText.value),
startTime: startTimeText.value,
endTime: endTimeText.value
})
if (code === 0) {
let data
if (info.value.type === 'card') {
data = await updateCardRequest({
lockId: $bluetooth.currentLockInfo.lockId,
cardId: info.value.cardId,
cardType: 4,
weekDay: 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),
changeType: 1
})
} else if (info.value.type === 'fingerprint') {
data = await updateFingerprintRequest({
lockId: $bluetooth.currentLockInfo.lockId,
fingerprintId: info.value.fingerprintId,
fingerprintType: 4,
weekDay: 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),
changeType: 1
})
} else if (info.value.type === 'remote') {
data = await updateRemoteRequest({
lockId: $bluetooth.currentLockInfo.lockId,
remoteId: info.value.remoteId,
remoteType: 4,
weekDay: 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),
changeType: 1
})
} else if (info.value.type === 'face') {
data = await updateFaceRequest({
lockId: $bluetooth.currentLockInfo.lockId,
faceId: info.value.faceId,
faceType: 4,
weekDay: 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),
changeType: 1
})
} else if (info.value.type === 'palmVein') {
data = await updatePalmVeinRequest({
lockId: $bluetooth.currentLockInfo.lockId,
palmVeinId: info.value.palmVeinId,
palmVeinType: 4,
weekDay: 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),
changeType: 1
})
}
pending.value = false
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('更新成功')
@ -361,12 +293,108 @@
})
}
} else {
pending.value = false
uni.hideLoading()
uni.showToast({
title: '操作失败,请重试',
icon: 'none'
const { code } = await $bluetooth.registerAuthentication({
type: info.value.type,
operate: 1,
isAdmin: info.value.type,
isForce: info.value.isForce,
isRound: 1,
weekDays: weekDays.value.sort(),
no: info.value[`${info.value.type}Number`],
userCountLimit: 0xffff,
keyId: $bluetooth.keyId.toString(),
uid: $user.userInfo.uid.toString(),
startDate: updateTime(startDate.value, startTimeText.value),
endDate: updateTime(endDate.value, endTimeText.value),
startTime: startTimeText.value,
endTime: endTimeText.value
})
if (code === 0) {
let data
if (info.value.type === 'card') {
data = await updateCardRequest({
lockId: $bluetooth.currentLockInfo.lockId,
cardId: info.value.cardId,
cardType: 4,
weekDay: 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),
changeType: 1
})
} else if (info.value.type === 'fingerprint') {
data = await updateFingerprintRequest({
lockId: $bluetooth.currentLockInfo.lockId,
fingerprintId: info.value.fingerprintId,
fingerprintType: 4,
weekDay: 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),
changeType: 1
})
} else if (info.value.type === 'remote') {
data = await updateRemoteRequest({
lockId: $bluetooth.currentLockInfo.lockId,
remoteId: info.value.remoteId,
remoteType: 4,
weekDay: 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),
changeType: 1
})
} else if (info.value.type === 'face') {
data = await updateFaceRequest({
lockId: $bluetooth.currentLockInfo.lockId,
faceId: info.value.faceId,
faceType: 4,
weekDay: 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),
changeType: 1
})
} else if (info.value.type === 'palmVein') {
data = await updatePalmVeinRequest({
lockId: $bluetooth.currentLockInfo.lockId,
palmVeinId: info.value.palmVeinId,
palmVeinType: 4,
weekDay: 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),
changeType: 1
})
}
pending.value = false
uni.hideLoading()
if (data.code === 0) {
eventChannel.emit('refresh', {})
$basic.backAndToast('更新成功')
uni.showToast({
title: '更新成功',
icon: 'none'
})
} else {
uni.showToast({
title: data.message,
icon: 'none'
})
}
} else {
pending.value = false
uni.hideLoading()
uni.showToast({
title: '操作失败,请重试',
icon: 'none'
})
}
}
}
}

View File

@ -1,49 +1,89 @@
<template>
<view>
<view class="item">
<view class="item" @click="() => $refs.modalInput.open()">
<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 class="item" style="margin-top: 2rpx" @click="updateTime">
<view class="item-title">有效期</view>
<view v-if="currentKeyInfo.keyType === 1">永久</view>
<view v-else-if="currentKeyInfo.keyType === 3">单次</view>
<view v-else-if="currentKeyInfo.keyType === 4">
<view class="item-content">{{ timeFormat(currentKeyInfo.startDate, 'yyyy-mm-dd') }}</view>
<view class="item-content">{{ timeFormat(currentKeyInfo.endDate, 'yyyy-mm-dd') }}</view>
</view>
<view v-else>
<view class="item-content">{{
timeFormat(currentKeyInfo.startDate, 'yyyy-mm-dd h:M')
}}</view>
<view class="item-content">{{ timeFormat(currentKeyInfo.endDate, 'yyyy-mm-dd h:M') }}</view>
<view class="flex items-center">
<view v-if="$lock.currentKeyInfo.keyType === 1" class="mr-2">永久</view>
<view v-else-if="$lock.currentKeyInfo.keyType === 3">单次</view>
<view v-else-if="$lock.currentKeyInfo.keyType === 4" class="mr-2">
<view class="item-content">{{
timeFormat($lock.currentKeyInfo.startDate, 'yyyy-mm-dd')
}}</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 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-content">{{
convertWeekDaysToChineseString(currentKeyInfo.weekDays)
}}</view>
<view class="flex items-center">
<view class="item-content mr-2">{{
$lock.convertWeekDaysToChineseString($lock.currentKeyInfo.weekDays)
}}</view>
<up-icon name="arrow-right"></up-icon>
</view>
</view>
<view class="item" v-if="currentKeyInfo.keyType === 4" style="margin-top: 2rpx">
<view
class="item"
v-if="$lock.currentKeyInfo.keyType === 4"
style="margin-top: 2rpx"
@click="updateTime"
>
<view class="item-title">有效时间</view>
<view class="item-content">
{{ timeFormat(currentKeyInfo.startDate, 'h:M') }}{{
timeFormat(currentKeyInfo.endDate, 'h:M')
}}
<view class="flex items-center">
<view class="item-content mr-2">
{{ timeFormat($lock.currentKeyInfo.startDate, 'h:M') }}{{
timeFormat($lock.currentKeyInfo.endDate, 'h:M')
}}</view
>
<up-icon name="arrow-right"></up-icon>
</view>
</view>
<view class="item" style="margin-top: 20rpx">
<view class="item-title">接收者</view>
<view class="item-content">{{ currentKeyInfo.username }}</view>
<view class="item-content">{{ $lock.currentKeyInfo.username }}</view>
</view>
<view class="item" style="margin-top: 2rpx">
<view class="item-title">发送人</view>
<view class="item-content">{{ currentKeyInfo.senderUsername }}</view>
<view class="item-content">{{ $lock.currentKeyInfo.senderUsername }}</view>
</view>
<view class="item" style="margin-top: 2rpx">
<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 class="item" style="margin-top: 20rpx" @click="toRecordList">
<view class="item-title">操作记录</view>
@ -65,116 +105,228 @@
</view>
</view>
</up-modal>
<ModalInput
ref="modalInput"
title="请输入姓名"
:autoClose="false"
placeholder="请输入姓名"
:value="$lock.currentKeyInfo.keyName"
@confirm="changeName"
/>
</view>
</template>
<script>
import { mapActions, mapState } from 'pinia'
<script setup>
import { timeFormat } from 'uview-plus'
import { ref } from 'vue'
import { useLockStore } from '@/stores/lock'
import { deleteKeyRequest } from '@/api/key'
import {
deleteKeyRequest,
getKeyRequest,
updateKeyDateRequest,
updateKeyNameRequest
} from '@/api/key'
import { useBasicStore } from '@/stores/basic'
import { useBluetoothStore } from '@/stores/bluetooth'
export default {
data() {
return {
showModal: false,
checked: false
}
},
computed: {
...mapState(useLockStore, ['currentKeyInfo', 'keySearch'])
},
methods: {
timeFormat,
...mapActions(useLockStore, [
'updateKeySearch',
'getKeyList',
'convertWeekDaysToChineseString'
]),
...mapActions(useBasicStore, ['backAndToast', 'routeJump']),
async toRecordList() {
this.routeJump({
name: 'typeRecordList',
params: {
name: this.currentKeyInfo.keyName,
key: 'keyId',
id: this.currentKeyInfo.keyId
}
})
const $lock = useLockStore()
const $basic = useBasicStore()
const $bluetooth = useBluetoothStore()
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'
})
}
}
const updateTime = () => {
if ($lock.currentKeyInfo.keyType === 3) return
$basic.routeJump({
name:
$lock.currentKeyInfo.keyType === 1 || $lock.currentKeyInfo.keyType === 2
? 'temporaryDate'
: 'cycleDate',
params: {
info: JSON.stringify({ ...$lock.currentKeyInfo, type: 'key' })
},
cancelModal() {
this.showModal = false
this.checked = false
},
changeRadio() {
this.checked = !this.checked
},
async confirmModal() {
uni.showLoading({
title: '删除中',
mask: true
})
const that = this
const { code } = await deleteKeyRequest({
keyId: that.currentKeyInfo.keyId,
includeUnderlings: that.checked ? 1 : 0
})
that.showModal = false
if (code === 0) {
that.updateKeySearch({
...that.keySearch,
events: {
refresh() {
$lock.updateKeySearch({
...$lock.keySearch,
pageNo: 1
})
that.getKeyList(that.keySearch)
uni.hideLoading()
that.backAndToast('删除成功')
} else {
uni.hideLoading()
uni.showToast({
title: 'message',
icon: 'none'
$lock.getKeyList($lock.keySearch)
getKeyRequest({
lockId: $bluetooth.currentLockInfo.lockId,
keyId: $lock.currentKeyInfo.keyId
}).then(res => {
$lock.updateCurrentKeyInfo(res.data)
})
}
},
async deleteKey() {
const that = this
if (that.currentKeyInfo.keyRight === 1) {
that.showModal = true
return
}
uni.showModal({
title: '提示',
content: '确定要删除该钥匙',
async success(res) {
if (res.confirm) {
uni.showLoading({
title: '删除中',
mask: true
})
const { code: requestCode, message } = await deleteKeyRequest({
keyId: that.currentKeyInfo.keyId
})
if (requestCode === 0) {
uni.hideLoading()
that.updateKeySearch({
...that.keySearch,
pageNo: 1
})
await that.getKeyList(that.keySearch)
that.backAndToast('删除成功')
} else {
uni.hideLoading()
uni.showToast({
title: message,
icon: 'none'
})
}
}
}
})
}
})
}
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: $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({
title: '删除中',
mask: true
})
const { code } = await deleteKeyRequest({
keyId: $lock.currentKeyInfo.keyId,
includeUnderlings: checked.value ? 1 : 0
})
showModal.value = false
if (code === 0) {
$lock.updateKeySearch({
...$lock.keySearch,
pageNo: 1
})
$lock.getKeyList($lock.keySearch)
uni.hideLoading()
$basic.backAndToast('删除成功')
} else {
uni.hideLoading()
uni.showToast({
title: 'message',
icon: 'none'
})
}
}
const deleteKey = async () => {
if ($lock.currentKeyInfo.keyRight === 1) {
showModal.value = true
return
}
uni.showModal({
title: '提示',
content: '确定要删除该钥匙',
async success(res) {
if (res.confirm) {
uni.showLoading({
title: '删除中',
mask: true
})
const { code: requestCode, message } = await deleteKeyRequest({
keyId: $lock.currentKeyInfo.keyId
})
if (requestCode === 0) {
uni.hideLoading()
$lock.updateKeySearch({
...$lock.keySearch,
pageNo: 1
})
await $lock.getKeyList($lock.keySearch)
$lock.backAndToast('删除成功')
} else {
uni.hideLoading()
uni.showToast({
title: message,
icon: 'none'
})
}
}
}
})
}
</script>

View File

@ -78,6 +78,7 @@
import { updateRemoteRequest } from '@/api/remote'
import { updateFaceRequest } from '@/api/face'
import { updatePalmVeinRequest } from '@/api/palmVein'
import { updateKeyDateRequest } from '@/api/key'
const instance = getCurrentInstance().proxy
const eventChannel = instance.getOpenerEventChannel()
@ -108,12 +109,12 @@
const data = JSON.parse(options.info)
if (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
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,68 +140,14 @@
title: '更新中'
})
const { code } = await $bluetooth.registerAuthentication({
type: info.value.type,
operate: 1,
isAdmin: info.value.type,
isForce: info.value.isForce,
isRound: 0,
weekDays: [],
no: info.value[`${info.value.type}Number`],
userCountLimit: 0xffff,
keyId: $bluetooth.keyId.toString(),
uid: $user.userInfo.uid.toString(),
startDate: startDate.value,
endDate: endDate.value
})
if (code === 0) {
let data
if (info.value.type === 'card') {
data = await updateCardRequest({
lockId: $bluetooth.currentLockInfo.lockId,
cardId: info.value.cardId,
cardType: 2,
startDate: startDate.value,
endDate: endDate.value,
changeType: 1
})
} else if (info.value.type === 'fingerprint') {
data = await updateFingerprintRequest({
lockId: $bluetooth.currentLockInfo.lockId,
fingerprintId: info.value.fingerprintId,
fingerprintType: 2,
startDate: startDate.value,
endDate: endDate.value,
changeType: 1
})
} else if (info.value.type === 'remote') {
data = await updateRemoteRequest({
lockId: $bluetooth.currentLockInfo.lockId,
remoteId: info.value.remoteId,
remoteType: 2,
startDate: startDate.value,
endDate: endDate.value,
changeType: 1
})
} else if (info.value.type === 'face') {
data = await updateFaceRequest({
lockId: $bluetooth.currentLockInfo.lockId,
faceId: info.value.faceId,
faceType: 2,
startDate: startDate.value,
endDate: endDate.value,
changeType: 1
})
} else if (info.value.type === 'palmVein') {
data = await updatePalmVeinRequest({
lockId: $bluetooth.currentLockInfo.lockId,
palmVeinId: info.value.palmVeinId,
palmVeinType: 2,
startDate: startDate.value,
endDate: endDate.value,
changeType: 1
})
}
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) {
@ -217,12 +164,91 @@
})
}
} else {
pending.value = false
uni.hideLoading()
uni.showToast({
title: '操作失败,请重试',
icon: 'none'
const { code } = await $bluetooth.registerAuthentication({
type: info.value.type,
operate: 1,
isAdmin: info.value.type,
isForce: info.value.isForce,
isRound: 0,
weekDays: [],
no: info.value[`${info.value.type}Number`],
userCountLimit: 0xffff,
keyId: $bluetooth.keyId.toString(),
uid: $user.userInfo.uid.toString(),
startDate: startDate.value,
endDate: endDate.value
})
if (code === 0) {
let data
if (info.value.type === 'card') {
data = await updateCardRequest({
lockId: $bluetooth.currentLockInfo.lockId,
cardId: info.value.cardId,
cardType: 2,
startDate: startDate.value,
endDate: endDate.value,
changeType: 1
})
} else if (info.value.type === 'fingerprint') {
data = await updateFingerprintRequest({
lockId: $bluetooth.currentLockInfo.lockId,
fingerprintId: info.value.fingerprintId,
fingerprintType: 2,
startDate: startDate.value,
endDate: endDate.value,
changeType: 1
})
} else if (info.value.type === 'remote') {
data = await updateRemoteRequest({
lockId: $bluetooth.currentLockInfo.lockId,
remoteId: info.value.remoteId,
remoteType: 2,
startDate: startDate.value,
endDate: endDate.value,
changeType: 1
})
} else if (info.value.type === 'face') {
data = await updateFaceRequest({
lockId: $bluetooth.currentLockInfo.lockId,
faceId: info.value.faceId,
faceType: 2,
startDate: startDate.value,
endDate: endDate.value,
changeType: 1
})
} else if (info.value.type === 'palmVein') {
data = await updatePalmVeinRequest({
lockId: $bluetooth.currentLockInfo.lockId,
palmVeinId: info.value.palmVeinId,
palmVeinType: 2,
startDate: startDate.value,
endDate: endDate.value,
changeType: 1
})
}
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 {
pending.value = false
uni.hideLoading()
uni.showToast({
title: '操作失败,请重试',
icon: 'none'
})
}
}
}