wx-starlock/pages/main/lockDetail.vue

664 lines
18 KiB
Vue
Raw Normal View History

2024-08-22 16:37:15 +08:00
<template>
<view>
2025-03-03 09:01:28 +08:00
<scroll-view
v-if="deviceInfo"
scroll-y="true"
:style="{ height: deviceInfo.screenHeight - deviceInfo.safeArea.top + 'px' }"
@refresherrefresh="refresher"
:refresher-enabled="true"
:refresher-triggered="refresherTriggered"
>
<view class="days" v-if="$bluetooth.currentLockInfo.days"
>钥匙将在{{ $bluetooth.currentLockInfo.days }}天后失效</view
>
<view class="lock-name">{{ $bluetooth.currentLockInfo.lockAlias }}</view>
<view class="top">
<image
class="top-background"
src="https://oss-lock.xhjcn.ltd/mp/background_main.jpg"
2025-03-03 09:01:28 +08:00
mode="aspectFill"
></image>
<view style="width: 100%; height: 50rpx">
<view class="power" @click="powerTip">
<image
class="power-icon"
:src="$lock.getPowerIcon($bluetooth.currentLockInfo.electricQuantity)"
mode="aspectFill"
></image>
<view class="power-text">{{ $bluetooth.currentLockInfo.electricQuantity }}%</view>
<image
class="power-tips"
src="https://oss-lock.xhjcn.ltd/mp/icon_tips.png"
mode="aspectFill"
></image>
2025-03-03 09:01:28 +08:00
</view>
</view>
<view class="switch" @click="openDoorOperate('open')" @longpress="openDoorOperate('close')">
<SwitchLoading :size="220" ref="sLoading"></SwitchLoading>
</view>
<view class="switch-text">点击开锁长按闭锁</view>
<view class="bottom">
<view class="bottom-side">
<image
class="bottom-icon"
src="https://oss-lock.xhjcn.ltd/mp/icon_role.png"
mode="aspectFill"
></image>
2025-03-03 09:01:28 +08:00
<view>{{
$lock.getRole(
$bluetooth.currentLockInfo.userType,
$bluetooth.currentLockInfo.keyRight
)
}}</view>
</view>
<view class="bottom-side">
<image
class="bottom-icon"
:src="
$bluetooth.currentLockInfo.appUnlockOnline
? 'https://oss-lock.xhjcn.ltd/mp/icon_cloud_active.png'
: 'https://oss-lock.xhjcn.ltd/mp/icon_cloud.png'
2025-03-03 09:01:28 +08:00
"
mode="aspectFill"
style="width: 40rpx; height: 40rpx"
></image>
<view
:style="{
color: $bluetooth.currentLockInfo.appUnlockOnline ? '#63b8af' : '#a3a3a3'
}"
>手机需联网</view
>
</view>
</view>
</view>
2025-03-03 09:01:28 +08:00
<view class="menu">
<view class="menu-title">
<image class="menu-image" src="https://oss-lock.xhjcn.ltd/mp/icon_menu.png"></image>
2025-03-03 09:01:28 +08:00
<view>功能</view>
</view>
2025-03-03 09:01:28 +08:00
<view class="menu-main">
<view
v-if="$bluetooth.currentLockInfo.keyRight === 1"
class="menu-main-view"
@click="$basic.routeJump({ name: 'keyList' })"
>
<image
class="menu-main-image transform-scale-90"
src="https://oss-lock.xhjcn.ltd/mp/icon_key.png"
2025-03-03 09:01:28 +08:00
></image>
<view>电子钥匙</view>
</view>
<view
v-if="
$bluetooth.currentLockInfo.lockFeature.password &&
$bluetooth.currentLockInfo.keyRight === 1
"
class="menu-main-view"
@click="$basic.routeJump({ name: 'passwordList' })"
>
<image
class="menu-main-image"
src="https://oss-lock.xhjcn.ltd/mp/icon_password_green.png"
></image>
2025-03-03 09:01:28 +08:00
<view>密码</view>
</view>
<view
v-if="
$bluetooth.currentLockInfo.lockFeature.icCard &&
$bluetooth.currentLockInfo.keyRight === 1
"
class="menu-main-view"
@click="$basic.routeJump({ name: 'cardList' })"
>
<image
class="menu-main-image transform-scale-110"
src="https://oss-lock.xhjcn.ltd/mp/icon_card.png"
2025-03-03 09:01:28 +08:00
></image>
<view></view>
</view>
<view
v-if="
$bluetooth.currentLockInfo.lockFeature.fingerprint &&
$bluetooth.currentLockInfo.keyRight === 1
2025-02-06 11:37:41 +08:00
"
2025-03-03 09:01:28 +08:00
class="menu-main-view"
@click="$basic.routeJump({ name: 'fingerprintList' })"
>
<image
class="menu-main-image"
src="https://oss-lock.xhjcn.ltd/mp/icon_fingerprint.png"
></image>
2025-03-03 09:01:28 +08:00
<view>指纹</view>
</view>
2025-02-06 11:37:41 +08:00
<view
2025-03-03 09:01:28 +08:00
v-if="
$bluetooth.currentLockInfo.lockFeature.bluetoothRemoteControl &&
$bluetooth.currentLockInfo.keyRight === 1
"
class="menu-main-view transform-scale-110"
@click="$basic.routeJump({ name: 'remoteList' })"
2025-02-06 11:37:41 +08:00
>
<image
class="menu-main-image"
src="https://oss-lock.xhjcn.ltd/mp/icon_remote.png"
></image>
2025-03-03 09:01:28 +08:00
<view>遥控</view>
</view>
<view
v-if="
$bluetooth.currentLockInfo.lockFeature.d3Face &&
$bluetooth.currentLockInfo.keyRight === 1
"
class="menu-main-view"
@click="$basic.routeJump({ name: 'faceList' })"
>
<image
class="menu-main-image"
src="https://oss-lock.xhjcn.ltd/mp/icon_face.png"
></image>
2025-03-03 09:01:28 +08:00
<view>人脸</view>
</view>
<view
v-if="
$bluetooth.currentLockInfo.lockFeature.palmVein &&
$bluetooth.currentLockInfo.keyRight === 1
"
class="menu-main-view"
@click="$basic.routeJump({ name: 'palmVeinList' })"
>
<image
class="menu-main-image"
src="https://oss-lock.xhjcn.ltd/mp/icon_palm_vein.png"
></image>
2025-03-03 09:01:28 +08:00
<view>掌静脉</view>
</view>
<view
v-if="$bluetooth.currentLockInfo.userType === 110301"
class="menu-main-view"
@click="$basic.routeJump({ name: 'adminList' })"
>
<image
class="menu-main-image transform-scale-140"
src="https://oss-lock.xhjcn.ltd/mp/icon_admin_black.png"
2025-03-03 09:01:28 +08:00
></image>
<view>授权管理员</view>
</view>
<view
class="menu-main-view transform-scale-105"
@click="$basic.routeJump({ name: 'recordList' })"
>
<image
class="menu-main-image"
src="https://oss-lock.xhjcn.ltd/mp/icon_record.png"
></image>
2025-03-03 09:01:28 +08:00
<view>操作记录</view>
</view>
<view
v-if="$bluetooth.currentLockInfo.keyRight === 1"
class="menu-main-view"
@click="$basic.routeJump({ name: 'messageReminder' })"
>
<image
class="menu-main-image transform-scale-110"
src="https://oss-lock.xhjcn.ltd/mp/icon_remind.png"
2025-03-03 09:01:28 +08:00
></image>
<view>消息提醒</view>
</view>
</view>
</view>
2025-03-03 09:01:28 +08:00
<view class="setting" @click="$basic.routeJump({ name: 'setting' })">
<image class="setting-image" src="https://oss-lock.xhjcn.ltd/mp/icon_setting.png"></image>
2025-03-03 09:01:28 +08:00
<view class="setting-text">设置</view>
<image
class="setting-arrow"
mode="aspectFill"
src="https://oss-lock.xhjcn.ltd/mp/icon_arrow.png"
></image>
</view>
2025-03-03 09:01:28 +08:00
</scroll-view>
2025-02-06 11:37:41 +08:00
<up-popup
:show="show"
@close="closePopup"
mode="center"
:closeOnClickOverlay="true"
bgColor="transparent"
>
2024-09-05 15:46:49 +08:00
<view class="popup" @click="closePopup">
2025-02-06 11:37:41 +08:00
<image
class="popup-background"
:src="
2025-03-03 09:01:28 +08:00
typeValue === 'close'
? 'https://oss-lock.xhjcn.ltd/mp/background_close_door.png'
: 'https://oss-lock.xhjcn.ltd/mp/background_open_door.png'
2025-02-06 11:37:41 +08:00
"
mode="aspectFill"
/>
2024-09-05 15:46:49 +08:00
<view>
2025-03-03 09:01:28 +08:00
<view class="popup-name">{{ $bluetooth.currentLockInfo.lockAlias }}</view>
2024-09-05 15:46:49 +08:00
<view class="popup-time">{{ timeFormat('', 'mm/dd h:M') }}</view>
</view>
</view>
</up-popup>
2024-08-22 16:37:15 +08:00
</view>
</template>
2025-03-03 09:01:28 +08:00
<script setup>
2025-02-06 11:37:41 +08:00
import { timeFormat } from 'uview-plus'
2025-03-03 09:01:28 +08:00
import { onMounted, ref } from 'vue'
2025-02-06 11:37:41 +08:00
import { useBluetoothStore } from '@/stores/bluetooth'
import { useBasicStore } from '@/stores/basic'
import SwitchLoading from '@/components/SwitchLoading/SwitchLoading.vue'
import { useLockStore } from '@/stores/lock'
import { useUserStore } from '@/stores/user'
2025-03-03 09:01:28 +08:00
import { getLockDetailRequest, getLockNetTokenRequest } from '@/api/lock'
2025-02-06 11:37:41 +08:00
import { deleteKeyRequest } from '@/api/key'
2025-03-03 09:01:28 +08:00
const $bluetooth = useBluetoothStore()
const $basic = useBasicStore()
const $lock = useLockStore()
const $user = useUserStore()
const sLoading = ref(null)
const time = ref(0)
const onlineToken = ref('0')
const pending = ref(false)
const show = ref(false)
const typeValue = ref('')
const refresherTriggered = ref(false)
const deviceInfo = ref(null)
onMounted(async () => {
deviceInfo.value = await $basic.getDeviceInfo()
await getServeTime()
})
const openDoorOperate = async type => {
const timestamp = new Date().getTime()
if (
$bluetooth.currentLockInfo.faceAuthentication === 1 &&
$bluetooth.currentLockInfo.nextFaceValidateTime <= new Date().getTime() + time.value * 1000 &&
$bluetooth.currentLockInfo.nextFaceValidateTime !== 0
) {
uni.showModal({
title: '提示',
content: '开门前需进行实名认证小程序暂不支持请使用APP认证开门',
showCancel: false
})
return
}
if (pending.value) {
return
}
if ($bluetooth.currentLockInfo.appUnlockOnline && type !== 'close') {
const netWork = await $basic.getNetworkType()
if (!netWork) {
return
2025-02-06 11:37:41 +08:00
}
2025-03-03 09:01:28 +08:00
}
uni.vibrateLong()
pending.value = true
sLoading.value.open()
if (type === 'close') {
uni.showToast({
title: `正在尝试闭锁……`,
icon: 'none'
})
}
if ($bluetooth.currentLockInfo.appUnlockOnline && type !== 'close') {
const result = await getNetToken()
if (!result) {
sLoading.value.close()
pending.value = false
return
}
}
let openMode
if (type === 'close') {
openMode = $bluetooth.currentLockInfo.appUnlockOnline ? 33 : 32
} else {
openMode = $bluetooth.currentLockInfo.appUnlockOnline ? 1 : 0
}
const { code } = await $bluetooth.openDoor({
name: $bluetooth.currentLockInfo.name,
uid: $user.userInfo.uid.toString(),
openMode,
openTime: parseInt(new Date().getTime() / 1000, 10) + time.value,
onlineToken: onlineToken.value
})
$bluetooth
.syncRecord({
keyId: $bluetooth.currentLockInfo.keyId.toString(),
uid: $user.userInfo.uid.toString()
})
.then(() => {
$bluetooth.closeBluetoothConnection()
})
if (type === 'open') {
uni.reportEvent('open_door', {
result: code,
duration: new Date().getTime() - timestamp
})
} else if (type === 'close') {
uni.reportEvent('close_door', {
result: code,
duration: new Date().getTime() - timestamp
})
}
if (code === 0) {
show.value = true
typeValue.value = type
setTimeout(() => {
show.value = false
}, 3000)
if ($bluetooth.currentLockInfo.keyType === 3) {
const { code: deleteKeyCode } = await deleteKeyRequest({
keyId: $bluetooth.keyId
2025-02-11 15:45:53 +08:00
})
2025-03-03 09:01:28 +08:00
if (deleteKeyCode === 0) {
$lock.updateLockSearch({
...$lock.lockSearch,
pageNo: 1
2024-09-03 10:54:41 +08:00
})
2025-03-03 09:01:28 +08:00
$lock.getLockList($lock.lockSearch)
$basic.backAndToast('单次钥匙已在被使用后删除', 1)
2025-02-06 11:37:41 +08:00
}
}
2025-03-03 09:01:28 +08:00
} else if (code === 7) {
uni.showToast({
title: `钥匙过期`,
icon: 'none'
})
} else if (code === 13) {
uni.showToast({
title: `钥匙当前不可用`,
icon: 'none'
})
} else if (code === -1) {
uni.showToast({
title: `${type === 'close' ? '关' : '开'}锁失败,请保证在锁附近`,
icon: 'none'
})
}
sLoading.value.close()
pending.value = false
}
const closePopup = () => {
show.value = false
}
const powerTip = () => {
const time = timeFormat($bluetooth.currentLockInfo.electricQuantityDate, 'yyyy-mm-dd h:M')
uni.showModal({
title: '锁电量更新时间',
content: time,
showCancel: false
})
}
const getNetToken = async () => {
const { code, data, message } = await getLockNetTokenRequest({
lockId: $bluetooth.currentLockInfo.lockId
})
if (code === 0) {
onlineToken.value = data.token
return true
}
uni.showToast({
title: message,
icon: 'none'
})
return false
}
const getServeTime = async () => {
const { code, data } = await $bluetooth.updateServerTimestamp()
if (code === 0) {
time.value = parseInt((data.date - new Date().getTime()) / 1000, 10)
}
}
const refresher = async () => {
refresherTriggered.value = true
const { code, data, message } = await getLockDetailRequest({
lockId: $bluetooth.currentLockInfo.lockId
})
if (code === 0) {
$bluetooth.updateCurrentLockInfo({ ...$bluetooth.currentLockInfo, ...data })
uni.showToast({
title: '刷新成功',
icon: 'none'
})
} else {
uni.showToast({
title: message,
icon: 'none'
})
}
2025-03-03 09:01:28 +08:00
refresherTriggered.value = false
2024-08-26 20:04:22 +08:00
}
2024-08-22 16:37:15 +08:00
</script>
<style lang="scss" scoped>
2025-02-06 11:37:41 +08:00
.popup {
position: relative;
2025-03-28 10:00:27 +08:00
display: flex;
flex-wrap: wrap;
2024-09-05 15:46:49 +08:00
width: 400rpx;
height: 389rpx;
2025-02-06 11:37:41 +08:00
text-align: center;
2024-09-05 15:46:49 +08:00
2025-02-06 11:37:41 +08:00
.popup-background {
2025-03-28 10:00:27 +08:00
position: absolute;
2025-02-06 11:37:41 +08:00
z-index: -1;
width: 400rpx;
height: 389rpx;
}
2024-09-05 15:46:49 +08:00
2025-02-06 11:37:41 +08:00
.popup-name {
z-index: 9;
2025-03-28 10:00:27 +08:00
display: -webkit-box;
2025-02-06 11:37:41 +08:00
width: 340rpx;
max-height: 80rpx;
2025-03-28 10:00:27 +08:00
margin-top: 180rpx;
margin-left: 30rpx;
2025-02-06 11:37:41 +08:00
overflow: hidden;
text-overflow: ellipsis;
2025-03-28 10:00:27 +08:00
-webkit-line-clamp: 2;
line-height: 40rpx;
color: #676b6d;
word-break: break-all;
2025-02-06 11:37:41 +08:00
white-space: normal;
2025-03-28 10:00:27 +08:00
-webkit-box-orient: vertical;
2025-02-06 11:37:41 +08:00
}
2024-09-05 15:46:49 +08:00
2025-02-06 11:37:41 +08:00
.popup-time {
width: 400rpx;
2025-03-28 10:00:27 +08:00
margin-top: 10rpx;
2025-02-06 11:37:41 +08:00
}
}
2025-02-06 11:37:41 +08:00
.days {
2025-03-28 10:00:27 +08:00
width: 750rpx;
height: 60rpx;
font-size: 32rpx;
2025-02-06 11:37:41 +08:00
line-height: 60rpx;
color: #bc9839;
text-align: center;
2025-03-28 10:00:27 +08:00
background: #faecc9;
2025-02-06 11:37:41 +08:00
}
2024-09-03 18:07:47 +08:00
2025-02-06 11:37:41 +08:00
.lock-name {
padding: 32rpx 32rpx 0 32rpx;
2025-03-28 10:00:27 +08:00
font-size: 32rpx;
2025-02-06 11:37:41 +08:00
font-weight: bold;
2025-03-28 10:00:27 +08:00
text-align: center;
2025-02-06 11:37:41 +08:00
word-break: break-all;
}
2025-02-06 11:37:41 +08:00
.top {
2025-03-28 10:00:27 +08:00
position: relative;
width: 686rpx;
height: 464rpx;
2025-03-28 10:00:27 +08:00
margin-top: 32rpx;
margin-left: 32rpx;
border-radius: 32rpx;
2025-02-06 11:37:41 +08:00
.top-background {
position: absolute;
2025-03-28 10:00:27 +08:00
z-index: -1;
2025-02-06 11:37:41 +08:00
width: 686rpx;
height: 464rpx;
border-radius: 32rpx;
}
2025-02-06 11:37:41 +08:00
.switch {
display: flex;
align-items: center;
2025-03-28 10:00:27 +08:00
justify-content: center;
2025-02-06 11:37:41 +08:00
width: 250rpx;
height: 250rpx;
2025-03-28 10:00:27 +08:00
margin-top: 20rpx;
margin-left: 218rpx;
2025-02-06 11:37:41 +08:00
background: #ffffff;
border-radius: 50%;
box-shadow: 0 8rpx 36rpx 0 rgba(0, 0, 0, 0.12);
}
2025-02-06 11:37:41 +08:00
.power {
float: right;
//width: 100%;
display: flex;
align-items: center;
justify-content: flex-end;
2025-03-28 10:00:27 +08:00
height: 50rpx;
padding-top: 18rpx;
2025-02-06 11:37:41 +08:00
.power-icon {
width: 50rpx;
height: 30rpx;
2025-03-28 10:00:27 +08:00
margin-right: 10rpx;
2025-02-06 11:37:41 +08:00
}
2025-02-06 11:37:41 +08:00
.power-text {
2025-03-28 10:00:27 +08:00
margin-right: 10rpx;
2025-02-06 11:37:41 +08:00
font-size: 32rpx;
font-weight: bold;
line-height: 50rpx;
}
2025-02-06 11:37:41 +08:00
.power-tips {
width: 40rpx;
height: 40rpx;
2025-03-28 10:00:27 +08:00
margin-right: 32rpx;
2025-02-06 11:37:41 +08:00
}
}
2025-02-06 11:37:41 +08:00
.switch-text {
margin-top: 10rpx;
text-align: center;
}
}
2025-02-06 11:37:41 +08:00
.bottom {
position: absolute;
bottom: 0;
display: flex;
align-items: center;
2025-03-28 10:00:27 +08:00
justify-content: space-around;
width: 686rpx;
2025-02-06 11:37:41 +08:00
height: 48rpx;
font-size: 32rpx;
2025-03-28 10:00:27 +08:00
line-height: 48rpx;
2025-02-06 11:37:41 +08:00
color: #63b8af;
2025-03-28 10:00:27 +08:00
background-color: rgba(0, 0, 0, 0.1);
2025-02-06 11:37:41 +08:00
border-radius: 0 0 32rpx 32rpx;
2024-08-22 16:37:15 +08:00
2025-02-06 11:37:41 +08:00
.bottom-side {
display: flex;
align-items: center;
}
.bottom-icon {
width: 32rpx;
height: 32rpx;
margin-right: 10rpx;
}
}
2025-02-06 11:37:41 +08:00
.menu {
2025-03-28 10:00:27 +08:00
width: 686rpx;
2025-02-06 11:37:41 +08:00
margin-top: 32rpx;
margin-left: 32rpx;
2025-03-28 10:00:27 +08:00
font-size: 40rpx;
2025-02-06 11:37:41 +08:00
background-color: #ffffff;
border-radius: 32rpx;
box-shadow: 0 8rpx 36rpx 0 rgba(0, 0, 0, 0.12);
2025-02-06 11:37:41 +08:00
.menu-title {
display: flex;
align-items: center;
2025-03-28 10:00:27 +08:00
padding: 24rpx 32rpx;
2025-02-06 11:37:41 +08:00
}
2025-02-06 11:37:41 +08:00
.menu-image {
width: 40rpx;
height: 40rpx;
2025-03-28 10:00:27 +08:00
margin-right: 40rpx;
}
2025-02-06 11:37:41 +08:00
.menu-main {
display: flex;
2025-03-28 10:00:27 +08:00
flex-wrap: wrap;
2025-02-06 11:37:41 +08:00
align-items: center;
2025-03-28 10:00:27 +08:00
padding-top: 32rpx;
margin-left: 43rpx;
2025-02-07 16:28:45 +08:00
font-size: 28rpx;
2025-02-06 11:37:41 +08:00
text-align: center;
2025-02-06 11:37:41 +08:00
.menu-main-view {
width: 150rpx;
2025-02-07 16:28:45 +08:00
margin-bottom: 48rpx;
2025-02-06 11:37:41 +08:00
.menu-main-image {
2025-02-22 10:21:26 +08:00
width: 40rpx;
height: 40rpx;
2025-03-28 10:00:27 +08:00
margin-bottom: 10rpx;
2025-02-06 11:37:41 +08:00
}
}
}
}
2025-02-06 11:37:41 +08:00
.setting {
display: flex;
align-items: center;
width: 686rpx;
2025-03-28 10:00:27 +08:00
padding: 24rpx 0;
margin-top: 32rpx;
margin-left: 32rpx;
font-size: 40rpx;
2025-02-06 11:37:41 +08:00
background-color: #ffffff;
border-radius: 32rpx;
box-shadow: 0 8rpx 36rpx 0 rgba(0, 0, 0, 0.12);
.setting-text {
margin-left: 32rpx;
}
.setting-arrow {
width: 48rpx;
height: 48rpx;
2025-03-28 10:00:27 +08:00
margin-right: 32rpx;
2025-02-06 11:37:41 +08:00
margin-left: auto;
}
.setting-image {
2025-02-22 10:45:33 +08:00
width: 40rpx;
height: 40rpx;
2025-03-28 10:00:27 +08:00
margin-left: 32rpx;
2025-02-06 11:37:41 +08:00
}
}
2024-08-22 16:37:15 +08:00
</style>