wx-starlock/pages/bindFingerprint/bindFingerprint.vue
2025-02-09 14:38:52 +08:00

92 lines
2.8 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<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 }}/5)</view>
<image
:src="`/static/images/icon_fingerprint_${process}.png`"
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 text = ref('尝试连接设备…')
onLoad(async options => {
if (options.info) {
const params = JSON.parse(options.info)
const { code } = await $bluetooth.registerAuthentication(params)
if (code === 0) {
text.value = '请将您的手指按下'
showProcess.value = true
} else {
$basic.backAndToast('操作失败,请重试')
}
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,
fingerprintName: params.fingerprintName,
fingerprintNumber: String(data.fingerprintNumber),
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
}
})
}
})
onUnmounted(() => {
uni.$off('registerFingerprintConfirm')
if (!bindFlag.value) {
$bluetooth.registerAuthenticationCancel({
type: 'fingerprint',
keyId: $bluetooth.keyId.toString(),
uid: $user.userInfo.uid.toString()
})
}
})
</script>