wx-starlock/pages/passwordDetail/passwordDetail.vue
2025-02-06 11:37:41 +08:00

166 lines
5.1 KiB
Vue

<template>
<view>
<view class="item">
<view class="item-title">密码</view>
<view class="item-content">{{ currentPasswordInfo.keyboardPwd }}</view>
</view>
<view class="item" style="margin-top: 2rpx">
<view class="item-title">姓名</view>
<view class="item-content">{{ currentPasswordInfo.keyboardPwdName }}</view>
</view>
<view class="item" style="margin-top: 2rpx">
<view class="item-title">有效期</view>
<view v-if="currentPasswordInfo.keyboardPwdType === 2">永久</view>
<view v-else-if="currentPasswordInfo.keyboardPwdType <= 4">
<view class="item-content">{{
timeFormat(currentPasswordInfo.startDate, 'yyyy-mm-dd h:M')
}}</view>
<view class="item-content">{{
timeFormat(currentPasswordInfo.endDate, 'yyyy-mm-dd h:M')
}}</view>
</view>
<view v-else>
{{ currentPasswordInfo.timeText.slice(0, -3) }}
</view>
</view>
<view class="item" style="margin-top: 20rpx">
<view class="item-title">发送人</view>
<view class="item-content">{{ currentPasswordInfo.senderUsername }}</view>
</view>
<view class="item" style="margin-top: 2rpx">
<view class="item-title">发送时间</view>
<view class="item-content">{{
timeFormat(currentPasswordInfo.sendDate, 'yyyy-mm-dd h:M')
}}</view>
</view>
<view class="button" @click="deletePassword">删除</view>
</view>
</template>
<script>
import { mapActions, mapState } from 'pinia'
import { timeFormat } from 'uview-plus'
import { useLockStore } from '@/stores/lock'
import { deletePsaawordRequest } from '@/api/keyboardPwd'
import { useBluetoothStore } from '@/stores/bluetooth'
import { useUserStore } from '@/stores/user'
import { useBasicStore } from '@/stores/basic'
export default {
data() {
return {}
},
computed: {
...mapState(useLockStore, ['currentPasswordInfo', 'passwordSearch']),
...mapState(useBluetoothStore, ['currentLockInfo', 'keyId']),
...mapState(useUserStore, ['userInfo'])
},
methods: {
timeFormat,
...mapActions(useBluetoothStore, ['setLockPassword', 'closeBluetoothConnection']),
...mapActions(useLockStore, ['updatePasswordSearch', 'getPasswordList']),
...mapActions(useBasicStore, ['backAndToast', 'getNetworkType']),
async deletePassword() {
const netWork = await this.getNetworkType()
if (!netWork) {
return
}
const that = this
uni.showModal({
title: '提示',
content: '确定要删除该密码',
async success(res) {
if (res.confirm) {
uni.showLoading({
title: '删除中',
mask: true
})
const timestamp = parseInt(new Date().getTime() / 1000, 10)
const { code } = await that.setLockPassword({
keyId: that.keyId.toString(),
uid: that.userInfo.uid.toString(),
pwdNo: that.currentPasswordInfo.pwdUserNo,
operate: 3,
isAdmin: that.currentPasswordInfo.pwdRight,
pwd: that.currentPasswordInfo.keyboardPwd,
userCountLimit: 0xffff,
startTime: timestamp,
endTime: timestamp
})
that.closeBluetoothConnection()
if (code === 0) {
const { code: requestCode, message } = await deletePsaawordRequest({
lockId: that.currentLockInfo.lockId,
keyboardPwdId: that.currentPasswordInfo.keyboardPwdId,
deleteType: 1
})
if (requestCode === 0) {
uni.hideLoading()
that.updatePasswordSearch({
...that.passwordSearch,
pageNo: 1
})
that.getPasswordList(that.passwordSearch)
that.backAndToast('删除成功')
} else {
uni.hideLoading()
uni.showToast({
title: message,
icon: 'none'
})
}
} else if (code === -1) {
uni.hideLoading()
uni.showToast({
title: '删除失败,请保持在锁附近',
icon: 'none'
})
}
}
}
})
}
}
}
</script>
<style lang="scss">
page {
background-color: $uni-bg-color-grey;
}
</style>
<style lang="scss" scoped>
.item-title {
width: 350rpx;
}
.item {
padding: 24rpx 32rpx;
background-color: #ffffff;
display: flex;
align-items: center;
justify-content: space-between;
font-size: 32rpx;
font-weight: 500;
}
.tips {
padding: 24rpx 32rpx;
font-size: 24rpx;
color: #999999;
}
.button {
margin: 32rpx;
width: 686rpx;
height: 88rpx;
background-color: #df282d;
color: white;
text-align: center;
line-height: 88rpx;
border-radius: 44rpx;
font-weight: bold;
}
</style>