473 lines
12 KiB
Vue
Raw Permalink Normal View History

2024-08-26 20:04:22 +08:00
<template>
<view>
2025-02-06 11:37:41 +08:00
<scroll-view
v-if="deviceInfo"
scroll-y="true"
:style="{ height: deviceInfo.windowHeight - deviceInfo.safeArea.top + 'px' }"
2025-02-06 11:37:41 +08:00
lower-threshold="100"
@refresherrefresh="refresherList"
:refresher-enabled="true"
@scrolltolower="nextPage"
:refresher-triggered="refresherTriggered"
>
<view class="search">
2025-02-06 11:37:41 +08:00
<up-search
shape="square"
2025-04-02 18:40:56 +08:00
searchIconSize="48rpx"
2025-02-06 11:37:41 +08:00
:inputStyle="{ fontSize: '32rpx' }"
2025-04-02 18:40:56 +08:00
height="80rpx"
2025-02-06 11:37:41 +08:00
placeholder="搜索"
:clearabled="false"
@change="changeSearch"
v-model="keySearch.searchStr"
bgColor="#ffffff"
:showAction="false"
maxlength="50"
></up-search>
</view>
<view style="padding: 32rpx 0 calc(env(safe-area-inset-bottom) + 250rpx) 0">
<view v-if="keyList.length === 0 && requestFinished">
2025-02-06 11:37:41 +08:00
<image
class="empty-list"
src="https://oss-lock.xhjcn.ltd/mp/background_empty_list.png"
2025-02-06 11:37:41 +08:00
mode="aspectFill"
></image>
<view class="empty-list-text">暂无数据</view>
</view>
<view v-else>
<up-swipe-action>
2025-02-06 11:37:41 +08:00
<up-swipe-action-item
ref="swipeItem"
:options="options"
v-for="key in keyList"
:key="key.keyboardPwdId"
:threshold="50"
@click="deleteKey(key)"
>
<view class="key" @click="toKeyDetail(key)">
2025-02-06 11:37:41 +08:00
<image
class="key-left"
:src="
key.headUrl === '' ? 'https://oss-lock.xhjcn.ltd/mp/icon_user.png' : key.headUrl
"
2025-02-06 11:37:41 +08:00
mode="aspectFill"
></image>
<view class="key-right">
2025-02-06 11:37:41 +08:00
<view style="display: flex">
<view class="key-right-top">{{ key.keyName }}</view>
2025-02-06 11:37:41 +08:00
<image
class="key-admin"
mode="aspectFill"
v-if="key.remoteEnable === 1"
src="https://oss-lock.xhjcn.ltd/mp/icon_remote_unlock.png"
2025-02-06 11:37:41 +08:00
></image>
<image
class="key-admin"
mode="aspectFill"
v-if="key.keyRight === 1"
src="https://oss-lock.xhjcn.ltd/mp/icon_admin.png"
2025-02-06 11:37:41 +08:00
></image>
<view
class="key-status"
2025-07-29 11:07:43 +08:00
:style="{ color: key.keyStatus === 110401 ? '#4777ee' : '#df282d' }"
2025-02-06 11:37:41 +08:00
>
{{ getKeyStatus(key.keyStatus) }}
</view>
</view>
<view class="key-right-bottom">{{ key.timeText }}</view>
</view>
</view>
<view class="line"></view>
</up-swipe-action-item>
</up-swipe-action>
</view>
</view>
</scroll-view>
<view class="button">
<view class="button-reset" @click="resetKey">重置钥匙</view>
<view class="button-create" @click="toCreateKey">发送钥匙</view>
</view>
2025-02-06 11:37:41 +08:00
<up-modal
:show="showModal"
title="是否删除授权管理员钥匙?"
:showCancelButton="true"
width="600rpx"
@cancel="cancelModal"
@confirm="confirmModal"
>
2024-09-04 10:36:33 +08:00
<view class="slot-content" @click="changeRadio">
2025-02-06 11:37:41 +08:00
<view style="display: flex; align-items: center">
2024-09-04 10:36:33 +08:00
<radio :checked="checked"></radio>
<view>同时删除其发送的所有钥匙钥匙删除后不能恢复</view>
</view>
</view>
</up-modal>
2024-08-26 20:04:22 +08:00
</view>
</template>
<script>
2025-02-06 11:37:41 +08:00
import { mapActions, mapState } from 'pinia'
import { useBasicStore } from '@/stores/basic'
import { useBluetoothStore } from '@/stores/bluetooth'
import { useLockStore } from '@/stores/lock'
import { useUserStore } from '@/stores/user'
import { deleteKeyRequest, resetKeyRequest } from '@/api/key'
2025-02-06 11:37:41 +08:00
export default {
data() {
return {
showModal: false,
checked: false,
deviceInfo: null,
refresherTriggered: false,
requestFinished: false,
options: [
{
text: '删除',
style: {
backgroundColor: '#f56c6c'
}
}
],
deleteKeyId: ''
}
2024-09-04 10:36:33 +08:00
},
2025-02-06 11:37:41 +08:00
computed: {
...mapState(useUserStore, ['userInfo']),
...mapState(useBluetoothStore, ['currentLockInfo', 'keyId']),
...mapState(useLockStore, ['keyTotal', 'keyList', 'keySearch'])
},
async onLoad() {
2024-09-04 10:36:33 +08:00
uni.showLoading({
2025-02-06 11:37:41 +08:00
title: '加载中',
2024-09-04 10:36:33 +08:00
mask: true
})
2025-02-06 11:37:41 +08:00
this.deviceInfo = await this.getDeviceInfo()
this.updateKeySearch({
...this.keySearch,
lockId: this.currentLockInfo.lockId
2024-09-04 10:36:33 +08:00
})
2025-02-06 11:37:41 +08:00
const { code, message } = await this.getKeyList(this.keySearch)
uni.hideLoading()
this.requestFinished = true
if (code !== 0) {
2024-09-04 10:36:33 +08:00
uni.showToast({
2025-02-06 11:37:41 +08:00
title: message,
2024-09-04 10:36:33 +08:00
icon: 'none'
})
}
},
2025-02-06 11:37:41 +08:00
onUnload() {
this.clearList('key')
2024-09-04 10:36:33 +08:00
},
2025-02-06 11:37:41 +08:00
methods: {
...mapActions(useBasicStore, ['routeJump', 'getDeviceInfo']),
...mapActions(useLockStore, [
'getKeyList',
'updateCurrentKeyInfo',
'updateKeySearch',
'getKeyStatus',
'clearList'
]),
changeRadio() {
this.checked = !this.checked
},
async confirmModal() {
uni.showLoading({
title: '删除中',
mask: true
})
const that = this
const { code, message } = await deleteKeyRequest({
2025-02-06 11:37:41 +08:00
keyId: that.deleteKeyId,
includeUnderlings: that.checked ? 1 : 0
})
that.showModal = false
if (code === 0) {
that.updateKeySearch({
...that.keySearch,
pageNo: 1
})
that.getKeyList(that.keySearch)
uni.hideLoading()
uni.showToast({
title: '删除成功',
icon: 'none'
})
} else {
uni.hideLoading()
uni.showToast({
title: message,
2025-02-06 11:37:41 +08:00
icon: 'none'
})
}
},
cancelModal() {
this.showModal = false
this.checked = false
},
toKeyDetail(key) {
this.updateCurrentKeyInfo(key)
this.routeJump({
name: 'keyDetail'
})
},
async deleteKey(data) {
const key = data
const that = this
let index = this.keyList.findIndex(item => item.keyId === key.keyId)
that.$refs.swipeItem[index].closeHandler()
if (data.keyRight === 1) {
this.deleteKeyId = key.keyId
this.showModal = true
return
}
uni.showModal({
title: '提示',
content: '确定要删除该钥匙',
async success(res) {
if (res.confirm) {
uni.showLoading({
title: '删除中',
mask: true
})
2025-02-06 11:37:41 +08:00
const { code: requestCode, message } = await deleteKeyRequest({
keyId: key.keyId
})
2025-02-06 11:37:41 +08:00
if (requestCode === 0) {
uni.hideLoading()
uni.showToast({
title: '删除成功',
icon: 'none'
})
that.updateKeySearch({
...that.keySearch,
pageNo: 1
})
await that.getKeyList(that.keySearch)
} else {
uni.hideLoading()
uni.showToast({
title: message,
icon: 'none'
})
}
}
}
})
2025-02-06 11:37:41 +08:00
},
async resetKey() {
const that = this
if (that.keyList.length === 0) {
uni.showToast({
title: '暂无钥匙,无需重置',
icon: 'none'
})
return
}
uni.showModal({
title: '提示',
content: '确定要重置钥匙,该锁的所有钥匙都将被删除',
async success(res) {
if (res.confirm) {
const { code: requestCode, message } = await resetKeyRequest({
lockId: that.currentLockInfo.lockId
})
2025-02-06 11:37:41 +08:00
console.log('重置钥匙返回', requestCode, message)
if (requestCode === 0) {
uni.showToast({
title: '重置钥匙成功',
icon: 'none'
})
that.updateKeySearch({
...that.keySearch,
pageNo: 1
})
await that.getKeyList(that.keySearch)
} else {
uni.showToast({
title: message,
icon: 'none'
})
}
}
}
})
2025-02-06 11:37:41 +08:00
},
toCreateKey() {
this.routeJump({
name: 'createKey'
})
2025-02-06 11:37:41 +08:00
},
async refresherList() {
this.refresherTriggered = true
this.updateKeySearch({
...this.keySearch,
2025-02-06 11:37:41 +08:00
pageNo: 1
})
2025-02-06 11:37:41 +08:00
const { code, message } = await this.getKeyList(this.keySearch)
if (code === 0) {
uni.showToast({
title: '刷新成功',
icon: 'none'
})
} else {
uni.showToast({
title: message,
icon: 'none'
})
}
this.refresherTriggered = false
},
async nextPage() {
if (this.keyTotal <= this.keySearch.pageNo * this.keySearch.pageSize) {
return
}
const pageNo = this.keySearch.pageNo + 1
const params = {
...this.keySearch,
pageNo
}
const { code, message } = await this.getKeyList(params)
if (code === 0) {
this.updateKeySearch({
...this.keySearch,
pageNo
})
} else {
uni.showToast({
title: message,
icon: 'none'
})
}
},
async changeSearch(data) {
this.updateKeySearch({
...this.keySearch,
searchStr: data
})
2025-02-06 11:37:41 +08:00
const { code, message } = await this.getKeyList(this.keySearch)
if (code !== 0) {
uni.showToast({
title: message,
icon: 'none'
})
}
}
2025-02-06 11:37:41 +08:00
}
}
2024-08-26 20:04:22 +08:00
</script>
<style lang="scss">
2025-02-06 11:37:41 +08:00
page {
background-color: $uni-bg-color-grey;
}
</style>
<style lang="scss" scoped>
2025-02-06 11:37:41 +08:00
.search {
width: 686rpx !important;
2025-04-02 18:40:56 +08:00
margin-top: 32rpx;
2025-02-06 11:37:41 +08:00
margin-left: 32rpx;
}
2025-02-06 11:37:41 +08:00
.button {
position: fixed;
bottom: calc(env(safe-area-inset-bottom) + 48rpx);
2025-04-02 18:40:56 +08:00
display: flex;
align-items: center;
2025-02-06 11:37:41 +08:00
font-weight: bold;
2024-08-26 20:04:22 +08:00
2025-02-06 11:37:41 +08:00
.button-reset {
width: 300rpx;
height: 88rpx;
2025-04-02 18:40:56 +08:00
margin-left: 50rpx;
line-height: 88rpx;
2025-02-06 11:37:41 +08:00
color: white;
text-align: center;
2025-04-02 18:40:56 +08:00
background-color: #df282d;
2025-02-06 11:37:41 +08:00
border-radius: 44rpx;
}
2025-02-06 11:37:41 +08:00
.button-create {
width: 300rpx;
height: 88rpx;
2025-04-02 18:40:56 +08:00
margin-left: 50rpx;
line-height: 88rpx;
2025-02-06 11:37:41 +08:00
color: white;
text-align: center;
2025-07-29 11:07:43 +08:00
background-color: #4777ee;
2025-02-06 11:37:41 +08:00
border-radius: 44rpx;
}
}
2025-02-06 11:37:41 +08:00
.key {
display: flex;
align-items: center;
width: 750rpx;
2025-04-02 18:40:56 +08:00
height: 120rpx;
background-color: #ffffff;
2025-02-06 11:37:41 +08:00
.key-left {
width: 80rpx;
height: 80rpx;
2025-04-02 18:40:56 +08:00
margin-left: 32rpx;
2025-02-06 11:37:41 +08:00
border-radius: 50%;
}
2025-02-06 11:37:41 +08:00
.key-right {
width: 574rpx;
2025-04-02 18:40:56 +08:00
margin-right: 32rpx;
margin-left: 32rpx;
2025-02-06 11:37:41 +08:00
.key-right-top {
max-width: 400rpx;
padding-bottom: 6rpx;
overflow: hidden;
text-overflow: ellipsis;
2025-04-02 18:40:56 +08:00
font-size: 32rpx;
font-weight: bold;
white-space: nowrap;
2025-02-06 11:37:41 +08:00
}
.key-admin {
width: 25rpx;
height: 25rpx;
2025-04-02 18:40:56 +08:00
margin-top: 8rpx;
margin-left: 10rpx;
2025-02-06 11:37:41 +08:00
}
.key-right-bottom {
font-size: 24rpx;
color: #999999;
}
2024-09-04 10:36:33 +08:00
}
2025-02-06 11:37:41 +08:00
.key-status {
margin-top: 4rpx;
margin-left: auto;
font-size: 26rpx;
color: #63b8af;
}
}
2025-02-06 11:37:41 +08:00
.line {
width: 100%;
height: 2rpx;
background: #ebebeb;
}
2025-02-06 11:37:41 +08:00
.empty-list {
width: 150rpx;
height: 150rpx;
margin: 300rpx auto 20rpx 50%;
transform: translateX(-50%);
}
2025-02-06 11:37:41 +08:00
.empty-list-text {
font-size: 32rpx;
color: #999999;
2025-04-02 18:40:56 +08:00
text-align: center;
2025-02-06 11:37:41 +08:00
}
2024-08-26 20:04:22 +08:00
</style>