电子钥匙添加授权与冻结功能

This commit is contained in:
范鹏 2025-02-17 17:46:58 +08:00
parent b8cfcc33a4
commit 3149b92f15
4 changed files with 323 additions and 7 deletions

View File

@ -82,3 +82,39 @@ export function getKeyRequest(data) {
data
})
}
// 冻结电子钥匙
export function freezeKeyRequest(data) {
return request({
url: '/key/freeze',
method: 'POST',
data
})
}
// 解冻电子钥匙
export function unfreezeKeyRequest(data) {
return request({
url: '/key/unfreeze',
method: 'POST',
data
})
}
// 设置授权管理员
export function authorizeKeyRequest(data) {
return request({
url: '/key/authorize',
method: 'POST',
data
})
}
// 取消授权管理员
export function unauthorizeKeyRequest(data) {
return request({
url: '/key/unauthorize',
method: 'POST',
data
})
}

View File

@ -4,12 +4,20 @@
<view class="bg-#f3f3f3 rounded-2xl">
<view class="py-4 text-center font-bold text-lg">{{ title }}</view>
<view class="px-4">
<input
class="bg-white border-none outline-none rounded-md h-80 w-450 text-base px-4"
placeholder-class="text-base line-height-[80rpx]"
:focus="show"
<up-input
:customStyle="{
padding: '0 28rpx',
outline: 'none',
width: '450rpx',
height: '80rpx',
backgroundColor: '#FFFFFF',
border: 0
}"
placeholder-class="!text-base !line-height-[80rpx]"
:placeholder="placeholder"
:value="text"
:cursorSpacing="130"
border="none"
:modelValue="text"
:maxlength="maxlength"
:type="type"
@change="change"
@ -72,5 +80,3 @@
close
})
</script>
<style scoped lang="scss"></style>

View File

@ -49,7 +49,49 @@
<view class="item-title">操作记录</view>
<up-icon name="arrow-right"></up-icon>
</view>
<view class="m-4 flex items-center justify-between text-base">
<view :class="[info.keyStatus === 110405 ? 'text-#63b8af' : 'text-red']" @click="freeze">{{
info.keyStatus === 110405 ? '解冻' : '冻结'
}}</view>
<view :class="[info.keyRight === 1 ? 'text-red' : 'text-#63b8af']" @click="authorize">{{
info.keyRight === 1 ? '取消授权管理员' : '授权管理员'
}}</view>
</view>
<view class="button" @click="showModal = true">删除</view>
<up-modal
:show="showModalFreeze"
title="提示"
:showCancelButton="true"
width="600rpx"
@cancel="cancelModalFreeze"
@confirm="confirmModalFreeze"
>
<view v-if="info.keyRight === 1" class="slot-content" @click="changeRadioFreeze">
<view style="display: flex; align-items: center">
<radio :checked="checkedFreeze"></radio>
<view>同时{{ info.keyStatus === 110405 ? '解冻' : '冻结' }}其发送的钥匙</view>
</view>
</view>
<view v-else class="slot-content">
<view>{{ info.keyStatus === 110405 ? '取消冻结' : '冻结' }}会在用户APP连网后生效</view>
</view>
</up-modal>
<up-modal
:show="showModalAuthorize"
title="提示"
:showCancelButton="true"
width="600rpx"
@cancel="cancelModalAuthorize"
@confirm="confirmModalAuthorize"
>
<view class="slot-content">
<view>{{
info.keyRight === 1
? '取消授权会在用户APP连网后生效'
: '授权用户拥有管理员的大部分权限,比如发送要是、发送密码'
}}</view>
</view>
</up-modal>
<ModalInput
ref="modalInput"
title="请输入姓名"
@ -82,8 +124,12 @@
import { onLoad } from '@dcloudio/uni-app'
import { timeFormat } from 'uview-plus'
import {
authorizeKeyRequest,
deleteKeyRequest,
freezeKeyRequest,
getKeyRequest,
unauthorizeKeyRequest,
unfreezeKeyRequest,
updateKeyDateRequest,
updateKeyNameRequest
} from '@/api/key'
@ -99,7 +145,10 @@
const info = ref(null)
const showModal = ref(false)
const showModalFreeze = ref(false)
const showModalAuthorize = ref(false)
const checked = ref(false)
const checkedFreeze = ref(false)
const modalInput = ref(null)
@ -137,6 +186,83 @@
}
}
const freeze = async () => {
showModalFreeze.value = true
}
const authorize = async () => {
showModalAuthorize.value = true
}
const cancelModalFreeze = () => {
showModalFreeze.value = false
checkedFreeze.value = false
}
const cancelModalAuthorize = () => {
showModalAuthorize.value = false
}
const changeRadioFreeze = () => {
checkedFreeze.value = !checkedFreeze.value
}
const confirmModalFreeze = async () => {
uni.showLoading({
title: '更新中',
mask: true
})
const { code, message } =
info.value.keyStatus === 110405
? await unfreezeKeyRequest({
keyId: info.value.keyId,
includeUnderlings: checkedFreeze.value ? 1 : 0
})
: await freezeKeyRequest({
keyId: info.value.keyId,
includeUnderlings: checkedFreeze.value ? 1 : 0
})
if (code === 0) {
showModalFreeze.value = false
eventChannel.emit('refresherList', {})
uni.hideLoading()
$basic.backAndToast(info.value.keyStatus === 110405 ? '解冻成功' : '冻结成功')
} else {
uni.hideLoading()
uni.showToast({
title: message,
icon: 'none'
})
}
}
const confirmModalAuthorize = async () => {
uni.showLoading({
title: '更新中',
mask: true
})
const { code, message } =
info.value.keyRight === 1
? await unauthorizeKeyRequest({
keyId: info.value.keyId
})
: await authorizeKeyRequest({
keyId: info.value.keyId
})
if (code === 0) {
showModalAuthorize.value = false
eventChannel.emit('refresherList', {})
uni.hideLoading()
$basic.backAndToast(info.value.keyRight === 1 ? '取消授权成功' : '授权成功')
} else {
uni.hideLoading()
uni.showToast({
title: message,
icon: 'none'
})
}
}
onLoad(options => {
if (options.info) {
info.value = JSON.parse(options.info)

View File

@ -89,6 +89,18 @@
<view class="item-title">操作记录</view>
<up-icon name="arrow-right"></up-icon>
</view>
<view class="m-4 flex items-center justify-between text-base">
<view
:class="[$lock.currentKeyInfo.keyStatus === 110405 ? 'text-#63b8af' : 'text-red']"
@click="freeze"
>{{ $lock.currentKeyInfo.keyStatus === 110405 ? '解冻' : '冻结' }}</view
>
<view
:class="[$lock.currentKeyInfo.keyRight === 1 ? 'text-red' : 'text-#63b8af']"
@click="authorize"
>{{ $lock.currentKeyInfo.keyRight === 1 ? '取消授权管理员' : '授权管理员' }}</view
>
</view>
<view class="button" @click="deleteKey">删除</view>
<up-modal
:show="showModal"
@ -105,6 +117,50 @@
</view>
</view>
</up-modal>
<up-modal
:show="showModalFreeze"
title="提示"
:showCancelButton="true"
width="600rpx"
@cancel="cancelModalFreeze"
@confirm="confirmModalFreeze"
>
<view
v-if="$lock.currentKeyInfo.keyRight === 1"
class="slot-content"
@click="changeRadioFreeze"
>
<view style="display: flex; align-items: center">
<radio :checked="checkedFreeze"></radio>
<view
>同时{{ $lock.currentKeyInfo.keyStatus === 110405 ? '解冻' : '冻结' }}其发送的钥匙</view
>
</view>
</view>
<view v-else class="slot-content">
<view
>{{
$lock.currentKeyInfo.keyStatus === 110405 ? '取消冻结' : '冻结'
}}会在用户APP连网后生效</view
>
</view>
</up-modal>
<up-modal
:show="showModalAuthorize"
title="提示"
:showCancelButton="true"
width="600rpx"
@cancel="cancelModalAuthorize"
@confirm="confirmModalAuthorize"
>
<view class="slot-content">
<view>{{
$lock.currentKeyInfo.keyRight === 1
? '取消授权会在用户APP连网后生效'
: '授权用户拥有管理员的大部分权限,比如发送要是、发送密码'
}}</view>
</view>
</up-modal>
<ModalInput
ref="modalInput"
title="请输入姓名"
@ -121,8 +177,12 @@
import { ref } from 'vue'
import { useLockStore } from '@/stores/lock'
import {
authorizeKeyRequest,
deleteKeyRequest,
freezeKeyRequest,
getKeyRequest,
unauthorizeKeyRequest,
unfreezeKeyRequest,
updateKeyDateRequest,
updateKeyNameRequest
} from '@/api/key'
@ -134,12 +194,23 @@
const $bluetooth = useBluetoothStore()
const showModal = ref(false)
const showModalFreeze = ref(false)
const showModalAuthorize = ref(false)
const checked = ref(false)
const checkedFreeze = ref(false)
const modalInput = ref(null)
const pending = ref(false)
const freeze = async () => {
showModalFreeze.value = true
}
const authorize = async () => {
showModalAuthorize.value = true
}
const changeManageSelf = async () => {
if (pending.value) return
pending.value = true
@ -264,10 +335,23 @@
checked.value = false
}
const cancelModalFreeze = () => {
showModalFreeze.value = false
checkedFreeze.value = false
}
const cancelModalAuthorize = () => {
showModalAuthorize.value = false
}
const changeRadio = () => {
checked.value = !checked.value
}
const changeRadioFreeze = () => {
checkedFreeze.value = !checkedFreeze.value
}
const confirmModal = async () => {
uni.showLoading({
title: '删除中',
@ -295,6 +379,70 @@
}
}
const confirmModalFreeze = async () => {
uni.showLoading({
title: '更新中',
mask: true
})
const { code, message } =
$lock.currentKeyInfo.keyStatus === 110405
? await unfreezeKeyRequest({
keyId: $lock.currentKeyInfo.keyId,
includeUnderlings: checkedFreeze.value ? 1 : 0
})
: await freezeKeyRequest({
keyId: $lock.currentKeyInfo.keyId,
includeUnderlings: checkedFreeze.value ? 1 : 0
})
if (code === 0) {
showModalFreeze.value = false
$lock.updateKeySearch({
...$lock.keySearch,
pageNo: 1
})
$lock.getKeyList($lock.keySearch)
uni.hideLoading()
$basic.backAndToast($lock.currentKeyInfo.keyStatus === 110405 ? '解冻成功' : '冻结成功')
} else {
uni.hideLoading()
uni.showToast({
title: message,
icon: 'none'
})
}
}
const confirmModalAuthorize = async () => {
uni.showLoading({
title: '更新中',
mask: true
})
const { code, message } =
$lock.currentKeyInfo.keyRight === 1
? await unauthorizeKeyRequest({
keyId: $lock.currentKeyInfo.keyId
})
: await authorizeKeyRequest({
keyId: $lock.currentKeyInfo.keyId
})
if (code === 0) {
showModalAuthorize.value = false
$lock.updateKeySearch({
...$lock.keySearch,
pageNo: 1
})
$lock.getKeyList($lock.keySearch)
uni.hideLoading()
$basic.backAndToast($lock.currentKeyInfo.keyRight === 1 ? '取消授权成功' : '授权成功')
} else {
uni.hideLoading()
uni.showToast({
title: message,
icon: 'none'
})
}
}
const deleteKey = async () => {
if ($lock.currentKeyInfo.keyRight === 1) {
showModal.value = true