wx-starlock/pages/bindFingerprint/bindFingerprint.vue

118 lines
3.6 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 }}/{{ maxProcess }})</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 maxProcess = ref(0)
const text = ref('尝试连接设备…')
onLoad(async options => {
if (options.info) {
const params = JSON.parse(options.info)
const { code, data } = await $bluetooth.registerAuthentication(params)
if (code === 0) {
text.value = '请将您的手指按下'
maxProcess.value = data.maxProcess
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,
weekDay: params.weekDays,
fingerprintName: params.fingerprintName,
fingerprintNumber: String(data.fingerprintNumber),
fingerprintUserNo: 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
} else if (data.status === 0xff) {
$basic.backAndToast('添加失败,请重试')
} else if (data.status === 0xfe) {
uni.showToast({
title: '管理员已满',
icon: 'none'
})
} else if (data.status === 0xfd) {
uni.showToast({
title: '用户已满',
icon: 'none'
})
} else if (data.status === 0xfc) {
uni.showToast({
title: '指纹已满',
icon: 'none'
})
} else if (data.status === 0xfb) {
uni.showToast({
title: '指纹已存在',
icon: 'none'
})
}
})
}
})
onUnmounted(() => {
uni.$off('registerFingerprintConfirm')
if (!bindFlag.value) {
$bluetooth.registerAuthenticationCancel({
type: 'fingerprint',
keyId: $bluetooth.keyId.toString(),
uid: $user.userInfo.uid.toString()
})
}
})
</script>