wx-starlock/pages/bindPalmVein/bindPalmVein.vue
2025-02-11 15:45:53 +08:00

107 lines
3.2 KiB
Vue

<template>
<view>
<view class="flex justify-center flex-col pt-20">
<image
src="/static/images/icon_add_palm_vein.png"
mode="aspectFill"
class="mx-[125rpx] w-500 h-500"
></image>
<view
class="text-base rounded-xl mt-15 bg-#5eb4ac mx-[32rpx] w-686 h-80 text-align-center line-height-[80rpx] text-white shadow-sm"
>{{ text }}</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 { addPalmVeinRequest } from '@/api/palmVein'
const instance = getCurrentInstance().proxy
const eventChannel = instance.getOpenerEventChannel()
const $bluetooth = useBluetoothStore()
const $basic = useBasicStore()
const $user = useUserStore()
const bindFlag = ref(false)
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 = '已连接到锁,请自然张开手掌,掌心对准摄像头'
} else {
$basic.backAndToast('操作失败,请重试')
}
uni.$on('registerPalmVeinConfirm', async data => {
if (data.status === 0) {
bindFlag.value = true
const { code, message } = await addPalmVeinRequest({
lockId: $bluetooth.currentLockInfo.lockId,
startDate: params.startDate,
endDate: params.endDate,
palmVeinName: params.palmVeinName,
palmVeinNumber: String(data.palmVeinNumber),
palmVeinUserNo: String(data.palmVeinNumber),
palmVeinType: params.palmVeinType,
addType: 1,
palmVeinRight: params.isAdmin,
isCoerced: params.isForce === 1 ? 2 : 1
})
if (code === 0) {
eventChannel.emit('refresherList', {})
$basic.backAndToast('绑卡成功', 2)
} else {
$basic.backAndToast(message)
}
} 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(async () => {
uni.$off('registerPalmVeinConfirm')
if (!bindFlag.value) {
await $bluetooth.registerAuthenticationCancel({
type: 'palmVein',
keyId: $bluetooth.keyId.toString(),
uid: $user.userInfo.uid.toString()
})
}
$bluetooth.closeBluetoothConnection()
})
</script>