wx-starlock/pages/main/lockDetail.vue

1097 lines
30 KiB
Vue
Raw Permalink 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"
2025-10-27 09:58:13 +08:00
:style="{
height: deviceInfo.windowHeight - deviceInfo.safeArea.top + 'px'
}"
2025-03-03 09:01:28 +08:00
@refresherrefresh="refresher"
:refresher-enabled="true"
:refresher-triggered="refresherTriggered"
>
2025-10-27 09:58:13 +08:00
<view class="select-lock-row">
2025-03-03 09:01:28 +08:00
<image
2025-10-27 09:58:13 +08:00
src="https://cos-lock.skychip.top/mp/icon_add_round.png"
2025-03-03 09:01:28 +08:00
mode="aspectFill"
2025-10-27 09:58:13 +08:00
style="width: 48rpx; height: 48rpx"
@click="toSearchDevice"
2025-03-03 09:01:28 +08:00
></image>
2025-10-27 09:58:13 +08:00
<!-- 普通 picker -->
<picker :range="pickerOptions" @change="onPickerChange">
<view class="lock-name">
<text>
{{ $bluetooth.currentLockInfo.lockAlias }}
</text>
<image
2025-10-27 09:58:13 +08:00
class="icon-down"
src="https://cos-lock.skychip.top/mp/icon_down.png"
mode="aspectFill"
2025-10-27 09:58:13 +08:00
>
</image>
2025-03-03 09:01:28 +08:00
</view>
2025-10-27 09:58:13 +08:00
</picker>
<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://cos-lock.skychip.top/mp/icon_tips.png"
mode="aspectFill"
>
</image>
2025-03-03 09:01:28 +08:00
</view>
2025-10-27 09:58:13 +08:00
</view>
<view
class="open-lock-btn"
@click="openDoorOperate('open')"
@longpress="openDoorOperate('close')"
>
<image
class="open-lock-btn-image-1"
ref="sLoading"
src="https://cos-lock.skychip.top/mp/icon_main_openLockBtn_center.png"
></image>
<image
class="open-lock-btn-image-2"
:class="{ rotate: isRotating }"
src="https://cos-lock.skychip.top/mp/icon_main_openLockBtn_circle.png"
></image>
</view>
<view class="days" v-if="$bluetooth.currentLockInfo.days"
>钥匙将在{{ $bluetooth.currentLockInfo.days }}天后失效
</view>
<view class="switch-text">点击开锁长按闭锁</view>
<view class="other-text">
<view class="bottom-side">
<image
class="bottom-icon"
style="width: 32rpx; height: 32rpx"
src="https://cos-lock.skychip.top/mp/icon_role.png"
mode="aspectFill"
></image>
<view>{{
$lock.getRole($bluetooth.currentLockInfo.userType, $bluetooth.currentLockInfo.keyRight)
}}</view>
2025-03-03 09:01:28 +08:00
</view>
2025-10-27 09:58:13 +08:00
<view class="bottom-side">
<image
class="bottom-icon"
:src="
$bluetooth.currentLockInfo.appUnlockOnline
? 'https://cos-lock.skychip.top/mp/icon_cloud_active.png'
: 'https://cos-lock.skychip.top/mp/icon_cloud.png'
"
mode="aspectFill"
style="width: 40rpx; height: 40rpx"
></image>
<view
:style="{
color: $bluetooth.currentLockInfo.appUnlockOnline ? '#4777ee' : '#a3a3a3'
}"
>手机需联网</view
>
</view>
</view>
2025-03-03 09:01:28 +08:00
<view class="menu">
<view class="menu-main">
<view
2025-07-07 10:00:44 +08:00
v-if="
$bluetooth.currentLockInfo.keyRight === 1 &&
$bluetooth.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
"
2025-03-03 09:01:28 +08:00
class="menu-main-view"
@click="$basic.routeJump({ name: 'keyList' })"
>
<image
2025-10-27 09:58:13 +08:00
class="menu-main-image"
src="https://cos-lock.skychip.top/mp/icon_main_electronicKey.png"
2025-03-03 09:01:28 +08:00
></image>
<view>电子钥匙</view>
</view>
<view
v-if="
$bluetooth.currentLockInfo.lockFeature.password &&
2025-07-07 10:00:44 +08:00
$bluetooth.currentLockInfo.keyRight === 1 &&
$bluetooth.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
2025-03-03 09:01:28 +08:00
"
class="menu-main-view"
@click="$basic.routeJump({ name: 'passwordList' })"
>
<image
class="menu-main-image"
2025-10-27 09:58:13 +08:00
src="https://cos-lock.skychip.top/mp/icon_main_password.png"
>
</image>
2025-03-03 09:01:28 +08:00
<view>密码</view>
</view>
<view
v-if="
$bluetooth.currentLockInfo.lockFeature.icCard &&
2025-07-07 10:00:44 +08:00
$bluetooth.currentLockInfo.keyRight === 1 &&
$bluetooth.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
2025-03-03 09:01:28 +08:00
"
class="menu-main-view"
@click="$basic.routeJump({ name: 'cardList' })"
>
<image
class="menu-main-image transform-scale-110"
2025-10-27 09:58:13 +08:00
src="https://cos-lock.skychip.top/mp/icon_main_icCard.png"
2025-03-03 09:01:28 +08:00
></image>
<view></view>
</view>
<view
v-if="
$bluetooth.currentLockInfo.lockFeature.fingerprint &&
2025-07-07 10:00:44 +08:00
$bluetooth.currentLockInfo.keyRight === 1 &&
$bluetooth.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
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"
2025-10-27 09:58:13 +08:00
src="https://cos-lock.skychip.top/mp/icon_main_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 &&
2025-07-07 10:00:44 +08:00
$bluetooth.currentLockInfo.keyRight === 1 &&
$bluetooth.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
2025-03-03 09:01:28 +08:00
"
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"
2025-10-27 09:58:13 +08:00
src="https://cos-lock.skychip.top/mp/icon_main_remoteControl.png"
></image>
2025-03-03 09:01:28 +08:00
<view>遥控</view>
</view>
<view
v-if="
$bluetooth.currentLockInfo.lockFeature.d3Face &&
2025-07-07 10:00:44 +08:00
$bluetooth.currentLockInfo.keyRight === 1 &&
$bluetooth.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
2025-03-03 09:01:28 +08:00
"
class="menu-main-view"
@click="$basic.routeJump({ name: 'faceList' })"
>
<image
class="menu-main-image"
2025-07-29 11:07:43 +08:00
src="https://cos-lock.skychip.top/mp/icon_face.png"
></image>
2025-03-03 09:01:28 +08:00
<view>人脸</view>
</view>
<view
v-if="
$bluetooth.currentLockInfo.lockFeature.palmVein &&
2025-07-07 10:00:44 +08:00
$bluetooth.currentLockInfo.keyRight === 1 &&
$bluetooth.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
2025-03-03 09:01:28 +08:00
"
class="menu-main-view"
@click="$basic.routeJump({ name: 'palmVeinList' })"
>
<image
class="menu-main-image"
2025-10-27 09:58:13 +08:00
src="https://cos-lock.skychip.top/mp/icon_palm.png"
></image>
2025-03-03 09:01:28 +08:00
<view>掌静脉</view>
</view>
<view
v-if="$bluetooth.currentLockInfo.transportType === transportType.TRANSPORT_TENCENT_YUN"
class="menu-main-view"
2025-06-16 16:07:14 +08:00
@click="jumpToPlayer"
>
2025-04-06 15:19:55 +08:00
<image
class="menu-main-image transform-scale-140"
2025-10-27 09:58:13 +08:00
src="https://oss-lock.xhjcn.ltd/mp/icon_catEyes.png"
2025-04-06 15:19:55 +08:00
></image>
<view>监控</view>
</view>
2025-03-03 09:01:28 +08:00
<view
2025-07-07 10:00:44 +08:00
v-if="
$bluetooth.currentLockInfo.userType === 110301 &&
$bluetooth.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN
"
2025-03-03 09:01:28 +08:00
class="menu-main-view"
@click="$basic.routeJump({ name: 'adminList' })"
>
<image
class="menu-main-image transform-scale-140"
2025-10-27 09:58:13 +08:00
src="https://cos-lock.skychip.top/mp/icon_main_authorizedAdmin.png"
2025-03-03 09:01:28 +08:00
></image>
<view>授权管理员</view>
</view>
<view
v-if="$bluetooth.currentLockInfo.transportType !== transportType.TRANSPORT_TENCENT_YUN"
2025-03-03 09:01:28 +08:00
class="menu-main-view transform-scale-105"
@click="$basic.routeJump({ name: 'recordList' })"
>
<image
class="menu-main-image"
2025-10-27 09:58:13 +08:00
src="https://cos-lock.skychip.top/mp/icon_main_operatingRecord.png"
></image>
2025-03-03 09:01:28 +08:00
<view>操作记录</view>
</view>
2025-04-06 15:19:55 +08:00
<view
v-if="$bluetooth.currentLockInfo.transportType === transportType.TRANSPORT_TENCENT_YUN"
2025-04-06 15:19:55 +08:00
class="menu-main-view transform-scale-105"
2025-04-09 18:04:26 +08:00
@click="$basic.routeJump({ name: 'videoLog' })"
2025-04-06 15:19:55 +08:00
>
<image
class="menu-main-image"
2025-10-27 09:58:13 +08:00
src="https://cos-lock.skychip.top/mp/icon_main_operatingRecord.png"
2025-04-06 15:19:55 +08:00
></image>
2025-05-29 14:21:39 +08:00
<view>门锁记录</view>
2025-04-06 15:19:55 +08:00
</view>
2025-10-27 09:58:13 +08:00
<view class="menu-main-view" @click="$basic.routeJump({ name: 'setting' })">
2025-03-03 09:01:28 +08:00
<image
class="menu-main-image transform-scale-110"
2025-10-27 09:58:13 +08:00
src="https://cos-lock.skychip.top/mp/icon_main_set.png"
2025-04-06 18:17:50 +08:00
></image>
2025-10-27 09:58:13 +08:00
<view>设置</view>
2025-04-06 18:17:50 +08:00
</view>
</view>
</view>
2025-03-03 09:01:28 +08:00
</scroll-view>
2025-10-27 09:58:13 +08:00
<view v-else class="not-devices-box">
<image class="menu-main-image" src="https://cos-lock.skychip.top/mp/icon_noData.png"></image>
<text>暂无智能锁</text>
<image
src="https://cos-lock.skychip.top/mp/icon_add_round.png"
mode="aspectFill"
class="button-add-big"
@click="toSearchDevice"
></image>
</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-10-27 09:58:13 +08:00
import { onMounted, onUnmounted, 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-07-07 10:00:44 +08:00
import { getLockDetailRequest, getLockNetTokenRequest, deleteLockRequest } from '@/api/lock'
2025-02-06 11:37:41 +08:00
import { deleteKeyRequest } from '@/api/key'
import { transportType } from '@/constant/transportType'
2025-10-27 09:58:13 +08:00
import { loginRequest } from '@/api/user'
import { setStorage, getStorage } from '@/utils/storage'
import { onLoad, onShow } from '@dcloudio/uni-app' // 注意:这里需要正确导入 UniApp 的生命周期钩子!
// #ifdef APP-PLUS
import { requestPermission } from '@/uni_modules/xhj-record'
// #endif
2025-03-03 09:01:28 +08:00
const $bluetooth = useBluetoothStore()
const $basic = useBasicStore()
const $lock = useLockStore()
const $user = useUserStore()
2025-10-27 09:58:13 +08:00
// const sLoading = ref(null)
2025-03-03 09:01:28 +08:00
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)
2025-10-27 09:58:13 +08:00
// 控制是否应用旋转动画
const isRotating = ref(false)
// 选择器数据源(比如一个字符串数组)
const pickerOptions = ref([])
// 当前选中项的索引picker 内部使用)
const selectedIndex = ref(0)
// 选中后展示的文本
const selectedText = ref(pickerOptions.value[0])
2025-03-03 09:01:28 +08:00
onMounted(async () => {
2025-10-27 09:58:13 +08:00
try {
// #ifdef MP-WEIXIN
const accountInfo = uni.getAccountInfoSync()
getApp().globalData.appid = accountInfo.miniProgram.appId
getApp().globalData.envVersion = accountInfo.miniProgram.envVersion
// #endif
uni.showLoading({
title: '加载中',
mask: true
})
const token = getStorage('token')
const list = getStorage('lockList')
const userInfo = getStorage('userInfo')
if (token) {
await Promise.all([$lock.getLockList($lock.lockSearch), $user.getUserInfo()]).then(res => {
pending.value = false
uni.hideLoading()
if (res[0].code === -1 && res[1] === -1 && list && userInfo) {
uni.showToast({
title: '网络访问失败,请检查网络是否正常',
icon: 'none'
})
$lock.updateLockList(list)
$user.updateUserInfo(userInfo)
$user.updateLoginStatus(true)
}
})
} else {
// 封装 uni.login() 为 Promise
await new Promise((resolve, reject) => {
uni.login({
provider: 'weixin',
success: async loginRes => {
try {
const { code, data } = await loginRequest({
js_code: loginRes.code
})
if (code === 0) {
await setStorage('openid', data.openid)
if (data.accessToken) {
setStorage('token', data.accessToken)
const list = getStorage('lockList')
const userInfo = getStorage('userInfo')
if (!list && !userInfo) {
await $lock.getLockList($lock.lockSearch)
await $user.getUserInfo()
await $user.updateLoginStatus(true)
}
} else {
$user.updateLoginStatus(false)
}
resolve() // 登录成功resolve Promise
} else {
throw new Error('登录请求失败')
}
} catch (err) {
console.error('登录过程出错:', err)
reject(err) // 登录过程出错reject Promise
}
},
fail: err => {
console.error('微信登录失败:', err)
reject(err) // 微信登录失败reject Promise
}
})
})
}
// 取第一个锁的信息作为首页的展示
const lock = list.flatMap(item => item.lockList)
console.log('lock', lock)
if (lock) {
const defaultShowLockIndex = 0
const data = {
...lock[defaultShowLockIndex],
name: lock[defaultShowLockIndex].bluetooth.bluetoothDeviceName,
deviceId: lock[defaultShowLockIndex].bluetooth.bluetoothDeviceId,
commKey: lock[defaultShowLockIndex].bluetooth.privateKey,
signKey: lock[defaultShowLockIndex].bluetooth.signKey,
publicKey: lock[defaultShowLockIndex].bluetooth.publicKey
}
await $bluetooth.updateKeyId(lock[defaultShowLockIndex].keyId.toString())
await $bluetooth.updateCurrentLockInfo(data)
pickerOptions.value = lock.map(item => item.lockAlias)
}
if (Object.keys($bluetooth.currentLockInfo).length !== 0) {
if (!($bluetooth.bluetoothStatus === 0 || $bluetooth.bluetoothStatus === -1)) {
$bluetooth.getBluetoothStatus()
return
}
let result = true
if (!$bluetooth.isInitBluetooth) {
result = await $bluetooth.initAndListenBluetooth()
}
if (!result) {
$bluetooth.checkSetting()
}
}
// 确保登录完成后再执行后续操作
deviceInfo.value = await $basic.getDeviceInfo()
await getServeTime()
} catch (err) {
console.error('初始化过程出错:', err)
uni.showToast({
title: '登录失败,请重试',
icon: 'none'
})
} finally {
uni.hideLoading() // 无论成功失败,最后都隐藏 loading
}
2025-03-03 09:01:28 +08:00
})
const jumpToPlayer = async () => {
2025-07-04 18:53:21 +08:00
// #ifdef APP-PLUS
// 检查权限
const result = await requestPermission()
if (result.code !== 0) {
uni.showToast({
title: '请在设置中打开应用的麦克风权限',
icon: 'none'
})
return
}
// #endif
2025-10-27 09:58:13 +08:00
$basic.routeJump({
name: 'p2pPlayer'
})
2025-06-16 16:07:14 +08:00
}
2025-03-03 09:01:28 +08:00
const openDoorOperate = async type => {
2025-10-27 09:58:13 +08:00
if (!($bluetooth.bluetoothStatus === 0 || $bluetooth.bluetoothStatus === -1)) {
$bluetooth.getBluetoothStatus()
return
}
let result = true
if (!$bluetooth.isInitBluetooth) {
result = await $bluetooth.initAndListenBluetooth()
}
if (!result) {
$bluetooth.checkSetting()
}
isRotating.value = true
2025-03-03 09:01:28 +08:00
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
})
2025-10-27 09:58:13 +08:00
isRotating.value = false
2025-03-03 09:01:28 +08:00
return
}
if (pending.value) {
2025-10-27 09:58:13 +08:00
isRotating.value = false
2025-03-03 09:01:28 +08:00
return
}
if ($bluetooth.currentLockInfo.appUnlockOnline && type !== 'close') {
const netWork = await $basic.getNetworkType()
if (!netWork) {
2025-10-27 09:58:13 +08:00
isRotating.value = false
2025-03-03 09:01:28 +08:00
return
2025-02-06 11:37:41 +08:00
}
2025-03-03 09:01:28 +08:00
}
uni.vibrateLong()
pending.value = true
2025-10-27 09:58:13 +08:00
2025-03-03 09:01:28 +08:00
if (type === 'close') {
uni.showToast({
title: `正在尝试闭锁……`,
icon: 'none'
})
}
// if ($bluetooth.currentLockInfo.appUnlockOnline && type !== 'close') {
if ($bluetooth.currentLockInfo.appUnlockOnline) {
2025-03-03 09:01:28 +08:00
const result = await getNetToken()
2025-10-27 09:58:13 +08:00
2025-03-03 09:01:28 +08:00
if (!result) {
2025-10-27 09:58:13 +08:00
// sLoading.value.close()
2025-03-03 09:01:28 +08:00
pending.value = false
2025-10-27 09:58:13 +08:00
isRotating.value = false
2025-03-03 09:01:28 +08:00
return
}
}
let openMode
if (type === 'close') {
openMode = $bluetooth.currentLockInfo.appUnlockOnline ? 33 : 32
} else {
openMode = $bluetooth.currentLockInfo.appUnlockOnline ? 1 : 0
}
2025-10-27 09:58:13 +08:00
2025-03-03 09:01:28 +08:00
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
})
if (type === 'open') {
2025-06-06 15:20:34 +08:00
// #ifdef MP-WEIXIN
2025-03-03 09:01:28 +08:00
uni.reportEvent('open_door', {
result: code,
duration: new Date().getTime() - timestamp
})
2025-06-06 15:20:34 +08:00
// #endif
2025-03-03 09:01:28 +08:00
} else if (type === 'close') {
2025-06-06 15:20:34 +08:00
// #ifdef MP-WEIXIN
2025-03-03 09:01:28 +08:00
uni.reportEvent('close_door', {
result: code,
duration: new Date().getTime() - timestamp
})
2025-06-06 15:20:34 +08:00
// #endif
2025-03-03 09:01:28 +08:00
}
if (code === 0) {
await $bluetooth
2025-05-28 15:15:14 +08:00
.syncRecord({
keyId: $bluetooth.currentLockInfo.keyId.toString(),
uid: $user.userInfo.uid.toString()
})
.then(() => {
$bluetooth.closeBluetoothConnection()
})
2025-03-03 09:01:28 +08:00
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'
})
}
2025-10-27 09:58:13 +08:00
2025-03-03 09:01:28 +08:00
pending.value = false
2025-10-27 09:58:13 +08:00
isRotating.value = false
2025-03-03 09:01:28 +08:00
}
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) {
2025-10-27 09:58:13 +08:00
$bluetooth.updateCurrentLockInfo({
...$bluetooth.currentLockInfo,
...data
})
2025-03-03 09:01:28 +08:00
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
}
2025-07-07 10:00:44 +08:00
2025-10-27 09:58:13 +08:00
const toSearchDevice = async () => {
$basic.routeJump({
name: 'addLockGuid'
})
}
2025-07-07 10:00:44 +08:00
const deleteLock = async () => {
const netWork = await $basic.getNetworkType()
if (!netWork) {
return
}
const message = '删除锁后,所有信息都会一起删除,确定删除锁吗?'
uni.showModal({
title: '提示',
content: message,
async success(res) {
if (res.confirm) {
uni.showLoading({
title: '删除中'
})
const { code: resetDeviceCode } = await $bluetooth.resetDevice({
name: $bluetooth.currentLockInfo.name,
authUid: $user.userInfo.uid.toString(),
keyId: $bluetooth.keyId.toString()
})
if (resetDeviceCode === 0 || resetDeviceCode === -2) {
const { code, message } = await deleteLockRequest({
lockId: $bluetooth.currentLockInfo.lockId
})
if (code === 0) {
uni.hideLoading()
$lock.updateLockSearch({
...$lock.lockSearch,
pageNo: 1
})
$lock.getLockList($lock.lockSearch)
$basic.backAndToast('删除成功', 1)
} else {
uni.hideLoading()
uni.showToast({
title: message,
icon: 'none'
})
}
} else if (resetDeviceCode === -1) {
uni.hideLoading()
uni.showToast({
title: '删除失败,请保持在锁附近',
icon: 'none'
})
}
}
}
})
}
2025-10-27 09:58:13 +08:00
// picker 数据变化时触发
const onPickerChange = async e => {
const list = getStorage('lockList')
// 取第一个锁的信息作为首页的展示
const lock = list.flatMap(item => item.lockList)
if (lock) {
const defaultShowLockIndex = e.detail.value
const data = {
...lock[defaultShowLockIndex],
name: lock[defaultShowLockIndex].bluetooth.bluetoothDeviceName,
deviceId: lock[defaultShowLockIndex].bluetooth.bluetoothDeviceId,
commKey: lock[defaultShowLockIndex].bluetooth.privateKey,
signKey: lock[defaultShowLockIndex].bluetooth.signKey,
publicKey: lock[defaultShowLockIndex].bluetooth.publicKey
}
await $bluetooth.updateKeyId(lock[defaultShowLockIndex].keyId.toString())
await $bluetooth.updateCurrentLockInfo(data)
pickerOptions.value = lock.map(item => item.lockAlias)
}
}
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
.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;
2025-02-06 11:37:41 +08:00
.power-icon {
width: 50rpx;
height: 30rpx;
}
2025-02-06 11:37:41 +08:00
.power-text {
font-size: 32rpx;
}
2025-02-06 11:37:41 +08:00
.power-tips {
width: 40rpx;
height: 40rpx;
}
}
}
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-07-29 11:07:43 +08:00
color: #4777ee;
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-10-27 09:58:13 +08:00
width: 48rpx;
height: 48rpx;
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
}
}
2025-10-27 09:58:13 +08:00
.not-devices-box {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
color: gray;
font-size: 24rpx;
width: 100%;
height: 100vh;
gap: 20rpx;
position: relative;
image {
width: 320rpx;
height: 240rpx;
}
.add-new-lock {
background-color: #4777ee;
color: white;
}
.button-add-big {
position: absolute;
width: 88rpx;
height: 88rpx;
right: 55rpx;
bottom: 55rpx;
}
}
.select-lock-row {
display: flex;
align-items: center;
justify-content: space-between;
border-radius: 15rpx;
padding: 8rpx 24rpx;
.lock-name {
display: flex;
align-items: center;
justify-content: center;
gap: 18rpx;
border-radius: 50rpx;
margin-top: 24rpx;
margin-bottom: 32rpx;
font-size: 32rpx;
background-color: #4777ee;
color: white;
padding: 12rpx 32rpx;
.icon-down {
width: 32rpx;
height: 32rpx;
}
}
.power {
display: flex;
align-items: center;
gap: 12rpx;
.power-icon {
width: 50rpx;
height: 30rpx;
}
.power-text {
font-size: 32rpx;
}
.power-tips {
width: 40rpx;
height: 40rpx;
}
}
}
.open-lock-btn {
display: flex;
justify-content: center;
position: relative;
height: 480rpx;
margin-top: 18rpx;
margin-bottom: 18rpx;
.open-lock-btn-image-1 {
width: 480rpx;
height: 480rpx;
position: absolute;
}
.open-lock-btn-image-2 {
width: 480rpx;
height: 480rpx;
position: absolute;
transition: transform 0.6s ease-in-out;
}
}
/* 旋转动画 class */
.rotate {
animation: rotate 2s linear infinite; /* 无限旋转动画 */
}
@keyframes rotate {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
.switch-text {
margin-top: 35rpx;
font-size: 32rpx;
color: #414141;
text-align: center;
}
.other-text {
display: flex;
align-items: center;
justify-content: center;
gap: 15rpx;
margin-top: 35rpx;
.bottom-side {
display: flex;
align-items: center;
font-size: 32rpx;
gap: 10rpx;
}
.bottom-icon {
width: 48rpx;
height: 48rpx;
}
}
2024-08-22 16:37:15 +08:00
</style>