wx-starlock/pages/uploadLockData/uploadLockData.vue

119 lines
3.2 KiB
Vue
Raw Normal View History

<template>
<view>
<view class="mx-4 pt-5 text-base">
<view class="text-sm">
<view> 本操作将上传锁内数据到服务器过程可能需要几分钟请耐心等待 </view>
</view>
<view
@click="asyncData"
class="w-full bg-#63b8af 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'
const $bluetooth = useBluetoothStore()
const $user = useUserStore()
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
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
})
uni.hideLoading()
pending.value = false
$bluetooth.closeBluetoothConnection()
if (resultCode === 0) {
2025-02-27 11:29:53 +08:00
const { code, data } = await getLockSettingRequest({
lockId: $bluetooth.currentLockInfo.lockId
})
if (code === 0) {
$bluetooth.updateCurrentLockSetting(data)
}
uni.showToast({
title: '上传成功',
icon: 'none'
})
} else {
uni.showToast({
title: '上传失败,请重试',
icon: 'none'
})
}
return
}
list.value = list.value.concat(data.list)
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'
})
return
}
2025-02-27 11:29:53 +08:00
page.value = 0
list.value = []
progress.value++
}
await asyncData(true)
} else {
pending.value = false
$bluetooth.closeBluetoothConnection()
uni.hideLoading()
uni.showToast({
title: '上传失败,请重试',
icon: 'none'
})
}
}
</script>
<style lang="scss">
page {
background-color: $uni-bg-color-grey;
}
</style>