wx-starlock/pages/setting/uploadLockData.vue

157 lines
4.5 KiB
Vue
Raw Permalink Normal View History

<template>
<view>
<view class="mx-4 pt-5 text-base">
<view class="text-sm">
<view> 本操作将上传锁内数据到服务器过程可能需要几分钟请耐心等待</view>
</view>
<view
@click="asyncData"
2025-07-29 11:07:43 +08:00
class="w-full bg-#4777ee text-white line-height-80rpx h-80 rounded-40rpx text-center mt-4 text-lg font-bold"
>
开始
</view>
</view>
</view>
</template>
<script setup>
import { ref } from 'vue'
import { useBluetoothStore } from '@/stores/bluetooth'
import { useUserStore } from '@/stores/user'
2025-02-27 11:29:53 +08:00
import { getLockSettingRequest, lockDataUploadRequest } from '@/api/setting'
import { useBasicStore } from '@/stores/basic'
const $bluetooth = useBluetoothStore()
const $user = useUserStore()
const $basic = useBasicStore()
const progress = ref(0)
const page = ref(0)
const list = ref([])
const pending = ref(false)
const typeList = ['password', 'card', 'fingerprint', 'face', 'palmVein', 'remote', 'setting']
const asyncData = async (flag = false) => {
if (pending.value && !flag) return
const netWork = await $basic.getNetworkType()
if (!netWork) {
return
}
pending.value = true
uni.showLoading({
title: `上传中${progress.value}/7`
})
const { code, data } = await $bluetooth.getLockDataList({
type: typeList[progress.value],
page: page.value,
lockId: $bluetooth.currentLockInfo.lockName.toString(),
uid: $user.userInfo.uid.toString(),
countReq: 10
})
if (code === 0) {
if (typeList[progress.value] === 'setting') {
const { code: resultCode } = await lockDataUploadRequest({
lockId: $bluetooth.currentLockInfo.lockId,
uploadType: 1,
records: data.list
})
$bluetooth.closeBluetoothConnection()
if (resultCode === 0) {
2025-02-27 11:29:53 +08:00
const { code, data } = await getLockSettingRequest({
lockId: $bluetooth.currentLockInfo.lockId
})
pending.value = false
2025-02-27 11:29:53 +08:00
if (code === 0) {
if (data.lockSettingInfo.catEyeConfig[0]) {
data.lockSettingInfo.catEyeConfig[0].catEyeModeConfig.recordTime = Number(
data.lockSettingInfo.catEyeConfig[0].catEyeModeConfig.recordTime
)
data.lockSettingInfo.catEyeConfig[0].catEyeModeConfig.detectionDistance = Number(
data.lockSettingInfo.catEyeConfig[0].catEyeModeConfig.detectionDistance
)
}
2025-02-27 11:29:53 +08:00
$bluetooth.updateCurrentLockSetting(data)
}
uni.hideLoading()
uni.showToast({
title: '上传成功',
icon: 'none'
})
} else {
pending.value = false
uni.hideLoading()
uni.showToast({
title: '上传失败,请重试',
icon: 'none'
})
}
progress.value = 0
page.value = 0
list.value = []
return
}
list.value = list.value.concat(data.list)
if (list.value.length === 0) {
page.value = 0
list.value = []
progress.value++
return await asyncData(true)
}
if (data.size === 10) {
page.value++
} else {
const { code: resultCode } = await lockDataUploadRequest({
lockId: $bluetooth.currentLockInfo.lockId,
uploadType: 2,
recordType: progress.value + 2,
records: list.value
})
if (resultCode !== 0) {
pending.value = false
$bluetooth.closeBluetoothConnection()
uni.hideLoading()
uni.showToast({
title: '上传失败,请重试',
icon: 'none'
})
progress.value = 0
page.value = 0
list.value = []
return
}
2025-02-27 11:29:53 +08:00
page.value = 0
list.value = []
progress.value++
}
await asyncData(true)
2025-03-07 10:06:47 +08:00
} else if (code === -21) {
pending.value = false
$bluetooth.closeBluetoothConnection()
uni.hideLoading()
progress.value = 0
page.value = 0
list.value = []
} else {
pending.value = false
$bluetooth.closeBluetoothConnection()
uni.hideLoading()
uni.showToast({
2025-03-07 10:06:47 +08:00
title: '上传失败,请保持在锁附近',
icon: 'none'
})
progress.value = 0
page.value = 0
list.value = []
}
}
</script>
<style lang="scss">
page {
background-color: $uni-bg-color-grey;
}
</style>