wx-starlock/pages/feature/bindFingerprint.vue

111 lines
3.6 KiB
Vue
Raw Permalink Normal View History

2025-02-09 14:38:52 +08:00
<template>
<view>
<view class="flex justify-center flex-col pt-10 text-align-center text-base">
<view>
{{ text }}
</view>
<view v-if="showProcess" class="mt-5 font-bold">({{ process }}/{{ maxProcess }})</view>
2025-02-09 14:38:52 +08:00
<image
:src="`https://oss-lock.xhjcn.ltd/mp/icon_fingerprint_${process}.png`"
2025-02-09 14:38:52 +08:00
mode="widthFix"
class="mx-[250rpx] w-250 mt-5"
></image>
<view class="mt-10">根据提示抬起手指后再进行下一次指纹采集</view>
</view>
</view>
</template>
<script setup>
import { ref, onUnmounted, getCurrentInstance } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { useBluetoothStore } from '@/stores/bluetooth'
import { useBasicStore } from '@/stores/basic'
import { useUserStore } from '@/stores/user'
import { addFingerprintRequest } from '@/api/fingerprint'
const instance = getCurrentInstance().proxy
const eventChannel = instance.getOpenerEventChannel()
const $bluetooth = useBluetoothStore()
const $basic = useBasicStore()
const $user = useUserStore()
const bindFlag = ref(false)
const showProcess = ref(false)
const process = ref(0)
const maxProcess = ref(0)
2025-02-09 14:38:52 +08:00
const text = ref('尝试连接设备…')
onLoad(async options => {
if (options.info) {
const params = JSON.parse(options.info)
uni.$on('registerFingerprintConfirm', async data => {
if (data.status === 0) {
bindFlag.value = true
const { code, message } = await addFingerprintRequest({
lockId: $bluetooth.currentLockInfo.lockId,
startDate: params.startDate,
endDate: params.endDate,
weekDay: params.weekDays,
startTime: params.startDate,
endTime: params.endDate,
2025-02-09 14:38:52 +08:00
fingerprintName: params.fingerprintName,
fingerprintNumber: String(data.fingerprintNumber),
2025-02-11 15:45:53 +08:00
fingerprintUserNo: String(data.fingerprintNumber),
2025-02-09 14:38:52 +08:00
fingerprintType: params.fingerprintType,
addType: 1,
fingerRight: params.isAdmin,
isCoerced: params.isForce === 1 ? 2 : 1
})
if (code === 0) {
eventChannel.emit('refresherList', {})
$basic.backAndToast('添加成功', 2)
} else {
$basic.backAndToast(message)
}
}
})
uni.$on('registerFingerprintProcess', data => {
if (data.status === 0) {
process.value = data.process
} else if (data.status === 0xff) {
$basic.backAndToast('添加失败,请重试')
} else if (data.status === 0xfe) {
2025-02-22 09:44:58 +08:00
$basic.backAndToast('管理员已满')
} else if (data.status === 0xfd) {
2025-02-22 09:44:58 +08:00
$basic.backAndToast('用户已满')
} else if (data.status === 0xfc) {
2025-02-22 09:44:58 +08:00
$basic.backAndToast('指纹已满')
} else if (data.status === 0xfb) {
uni.showToast({
title: '指纹已存在',
icon: 'none'
})
2025-02-09 14:38:52 +08:00
}
})
2025-02-22 09:44:58 +08:00
const { code, data } = await $bluetooth.registerAuthentication(params)
if (code === 0) {
text.value = '请将您的手指按下'
maxProcess.value = data.maxProcess
showProcess.value = true
} else if (code === -21) {
$basic.backAndToast('请先打开蓝牙')
}
2025-02-09 14:38:52 +08:00
}
})
onUnmounted(() => {
uni.$off('registerFingerprintConfirm')
2025-02-22 09:44:58 +08:00
uni.$off('registerFingerprintProcess')
2025-02-09 14:38:52 +08:00
if (!bindFlag.value) {
$bluetooth.registerAuthenticationCancel({
type: 'fingerprint',
keyId: $bluetooth.keyId.toString(),
uid: $user.userInfo.uid.toString()
})
}
})
</script>