<template>
<view>
<view class="uni-list">
<view v-show="isFingerPrint" class="uni-list-cell uni-list-cell-pd">
<view class="uni-list-cell-db">指纹登录工资条</view>
<switch :checked="fingerPrintChecked" @change="switchChange($event,1)" />
</view>
<view v-show="isFacial" class="uni-list-cell uni-list-cell-pd">
<view class="uni-list-cell-db">面容登录工资条</view>
<switch :checked="facialChecked" @change="switchChange($event,2)"/>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
isFingerPrint:false,
isFacial:false,
fingerPrintChecked:false,
facialChecked:false,
wageSafeInfo:[]
}
},
onLoad(){
let that = this
that.getWageSafeInfo()
},
methods: {
switchChange: function (e,type) {
let that = this
let value = e.target.value
let isChangeFingerPrintChecked = type == 1
let supportMode = isChangeFingerPrintChecked ? 'fingerPrint' : 'facial'
isChangeFingerPrintChecked ? that.fingerPrintChecked = value : that.facialChecked = value
if (!value && !that.fingerPrintChecked && !that.facialChecked) {
that.setWageSafe(0)
}
let checked = isChangeFingerPrintChecked ? that.facialChecked : that.fingerPrintChecked
if (checked && value) {
uni.showToast({
title: '需取消'+(isChangeFingerPrintChecked ? '面容' : '指纹')+'登录',
icon: 'error',
duration: 1000,
success() {
isChangeFingerPrintChecked ? that.fingerPrintChecked = false : that.facialChecked = false
}
});
} else if(value) {
uni.showModal({
title: '提示',
content: '确定使用'+(isChangeFingerPrintChecked ? '指纹' : '面容')+'登录工资条?',
success: function (res) {
if (res.confirm) {
// 获取设备内是否录入如指纹等生物信息
uni.checkIsSoterEnrolledInDevice({
checkAuthMode: supportMode,
success(res2) {
if(res2.isEnrolled){
// 开始 SOTER 生物认证
uni.startSoterAuthentication({
requestAuthModes: [supportMode],
challenge: new Date().getTime().toString(),
success() {
that.setWageSafe(type)
},
fail() {
uni.showToast({
title: '设置失败!',
icon: 'error',
duration: 1000,
success() {
isChangeFingerPrintChecked ? that.fingerPrintChecked = false : that.facialChecked = false
}
});
}
})
} else {
uni.showToast({
title: '请先录入'+(isChangeFingerPrintChecked ? '指纹' : '面容'),
icon: 'error',
duration: 1000,
success() {
isChangeFingerPrintChecked ? that.fingerPrintChecked = false : that.facialChecked = false
}
});
}
},
fail() {
uni.showToast({
title: '设置失败!',
icon: 'error',
duration: 1000,
success() {
isChangeFingerPrintChecked ? that.fingerPrintChecked = false : that.facialChecked = false
}
});
}
})
} else if (res.cancel) {
isChangeFingerPrintChecked ? that.fingerPrintChecked = false : that.facialChecked = false
}
}
})
}
},
setWageSafe(unlockMode){
let that = this
let postJson = {
functionCode:'gztOne',
unlockMode: unlockMode
}
that.$http.put('/functionSafe/changeUnlockMode', {}, {
params: postJson,
})
.then(res => {
uni.hideLoading()
if (res.code === that.$globalConfig.successCode) {
//接口返回值
// "code": 0,
// "message": "设置成功!",
// "data": null
if (unlockMode != 0) {
// 修改成功
uni.showToast({
title: '设置成功!',
icon: 'success',
duration: 1000
})
}
} else {
unlockMode == 1 ? that.fingerPrintChecked = false : that.facialChecked = false
}
})
.catch(err=>{
unlockMode == 1 ? that.fingerPrintChecked = false : that.facialChecked = false
})
},
checkIsSupportSoterAuthentication(unlockMode){
let that = this
// 检查设备支持的生物识别类型
uni.checkIsSupportSoterAuthentication({
success(res) {
let supportMode = res.supportMode
if (supportMode.length == 0) {
uni.showModal({
title: '提示',
content: '设备不支持!',
showCancel:false,
success: function (res) {
if (res.confirm) {
uni.navigateBack({})
}
}
})
} else {
for (let item of supportMode) {
if (item == 'fingerPrint') {
that.isFingerPrint = true
if (unlockMode == 1) {
that.fingerPrintChecked = true
}
} else if(item == 'facial') {
that.isFacial = true
if(unlockMode == 2) {
that.facialChecked = true
}
}
}
}
}
})
},
getWageSafeInfo(){
let that = this;
that.$http.get('/functionSafe/getOneByFunctionCode', {
params: {
functionCode:'gztOne'
},
header: {
launchUrl: '/' + [...getCurrentPages()].reverse()[0].route
}
})
.then(res=>{
uni.hideLoading()
if(res.code == that.$globalConfig.successCode){
//接口返回值
// "id": "2c9180847a7a865c017a84f967d90010",
// "userId": "2c9180847337e654017369d77c8e055c",
// "functionCode": "gztOne",
// "password": "9834cb3f3d889d6c",
// "unlockMode": 0
if (res.data !== null) {
that.wageSafeInfo = res.data
let unlockMode = that.wageSafeInfo.unlockMode
that.checkIsSupportSoterAuthentication(unlockMode)
} else {
// uni.showModal({
// title: '提示',
// content: '请先设置文字密码!',
// showCancel: false,
// success: function (res) {
// if (res.confirm) {
// uni.redirectTo({
// url: '/pages/work/wage/wage-login'
// })
// }
// }
// });
}
}
})
.catch(err=>{
uni.hideLoading()
})
}
}
}
</script>
<style>
page {
height: 100%;
background-color: #F1F5F8;
}
</style>
uni-生物识别模块代码(指纹,面容)
猜你喜欢
转载自blog.csdn.net/qq_35181466/article/details/120313632
今日推荐
周排行