小程序实现人脸识别功能

调用api   wx.startFacialRecognitionVerify

第一步:

      // 修改方法
      expertUpdate() {

       let _this = this
       wx.startFacialRecognitionVerify({
          name: _this.registerForm.realName, //身份证名称
          idCardNumber: _this.registerForm.idCard, //身份证号码
          checkAliveType: 1, //屏幕闪烁(人脸核验的交互方式,默认0,读数字)
          success(res) {
            
         console.log(res)  //认证结果
         if(res.errCode == 0){
          //识别成功  这个时候可以调后端的接口 (带着返的res.verifyResult)
          _this.verifyUser(res.verifyResult)
        }else{
        	tipInfo("识别失败")
        }
          },
          complete(res) {
          console.log(res)
          },
          fail(e) {
            console.log("err", err)//失败处理方法
           wx.showToast('请保持光线充足,面部正对手机,且无遮挡')
          }
   
        })
}


第二步:调方法 校验后端的接口

 // 人脸识别  根据上一个方法把verify_result传过来  //后端的校验接口


      verifyUser(verify_result) {
        //看后端实际要求 要传身份证号码不
        let obj = {
          uuid: this.infoForm.idCard,
          verify_result: verify_result
        }

      //后端接口=>verifyUser
        verifyUser(obj).then(res => {
          if (res.code == '0') {
            this.$refs.uForm.validate().then(res => {
              let obj = {
                pkid: uni.getStorageSync('expert_info').pkid,
                memberId: uni.getStorageSync('expert_info').memberId,
                avatar: this.fileList1[0].url,
                realName: this.infoForm.realName,
                orgName: this.infoForm.orgName,
                idCard: this.infoForm.idCard,
                province: this.infoForm.province,
                city: this.infoForm.city,
                district: this.infoForm.district,
                phone: this.infoForm.phone,
                professorLevel: this.infoForm.professorLevel,
                adept: this.infoForm.adept,
                intro: this.infoForm.intro,
                smsCode: this.infoForm.smsCode,
                annex: this.fileList2,
              }
             //修改方法
              expertUpdate(obj).then(res => {
                console.log(res, '修改成功了吗');
                if (res.code == '0') {
                  uni.$u.toast('修改成功', 5000)
                  uni.navigateBack()
                  //修改成功后 是返回上一步  还是跳转其他页面 根据实际情况
                } else {
                  uni.$u.toast(res.msg, 5000)
                }
              })
              console.log(res);
      
            }).catch(error => {
              console.log(error);
              uni.$u.toast('请先按要求填写', 5000)
            })
          }
        })
      
      },

注释:完整方法  这个是实现小程序个人信息完善,加了一个判断,如果 输入框没有值则需要走人脸识别验证方法  如果有值 只是修改其他项 就不需要验证  修改完成之后 名字和身份证号码直接禁用

 // 修改方法
      expertUpdate() {
        if (this.fileList1.length == 0) {
          uni.$u.toast('请上传头像')
          return false
        }
        // 判断 realName 是否为空
        if (!this.infoForm.realName) {
          uni.$u.toast('请填写姓名');
          return false;
        }
        // 验证 realName 是否为中文
        const chineseRegex = /^[\u4e00-\u9fa5]+$/;
        if (!chineseRegex.test(this.infoForm.realName)) {
          uni.$u.toast('姓名必须为中文');
          return false;
        }
        // 判断 idCard 是否为空
        if (!this.infoForm.idCard) {
          uni.$u.toast('请填写身份证号码');
          return false;
        }
        // 验证 idCard 是否符合身份证标准
        const idCardRegex = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
        if (!idCardRegex.test(this.infoForm.idCard)) {
          uni.$u.toast('身份证号格式不正确');
          return false;
        }
        if (this.fileList2.length == 0) {
          uni.$u.toast('请上传附件')
          return false
        }
        if (this.infoForm.intro.length > 200) {
          uni.$u.toast('简介字数不能超过200字!')
          return false
        }
        if (!this.flag) {
          let _this = this
          wx.startFacialRecognitionVerify({
            name: _this.infoForm.realName,
            idCardNumber: _this.infoForm.idCard,
            checkAliveType: 1,
            success(res) {
              console.log(res)
              _this.verifyUser(res.verifyResult)
              // console.log(res)
              // uni.navigateBack()
            },
            complete(res) {
              console.log(res)
            },
            fail(e) {
              // console.log(res)
              // console.log(_this.infoForm.realName)
              // console.log(_this.infoForm.idCard)
              console.log(e, 'fail')
            }
          })
        } else {
          this.$refs.uForm.validate().then(res => {
            let obj = {
              pkid: uni.getStorageSync('expert_info').pkid,
              memberId: uni.getStorageSync('expert_info').memberId,
              avatar: this.fileList1[0].url,
              realName: this.infoForm.realName,
              orgName: this.infoForm.orgName,
              idCard: this.infoForm.idCard,
              province: this.infoForm.province,
              city: this.infoForm.city,
              district: this.infoForm.district,
              phone: this.infoForm.phone,
              professorLevel: this.infoForm.professorLevel,
              adept: this.infoForm.adept,
              intro: this.infoForm.intro,
              smsCode: this.infoForm.smsCode,
              annex: this.fileList2,
            }
            expertUpdate(obj).then(res => {
              console.log(res, '修改成功了吗');
              if (res.code == '0') {
                uni.$u.toast('修改成功', 5000)
                uni.navigateBack()
                // this.getExpertInfo()
              } else {
                uni.$u.toast(res.msg, 5000)
              }
            })
            console.log(res);

          }).catch(error => {
            console.log(error);
            uni.$u.toast('请先按要求填写', 5000)
          })
        }
      },
      
      // 人脸识别
      verifyUser(verify_result) {
        let obj = {
          uuid: this.infoForm.idCard,
          verify_result: verify_result
        }
        verifyUser(obj).then(res => {
          if (res.code == '0') {
            this.$refs.uForm.validate().then(res => {
              let obj = {
                pkid: uni.getStorageSync('expert_info').pkid,
                memberId: uni.getStorageSync('expert_info').memberId,
                avatar: this.fileList1[0].url,
                realName: this.infoForm.realName,
                orgName: this.infoForm.orgName,
                idCard: this.infoForm.idCard,
                province: this.infoForm.province,
                city: this.infoForm.city,
                district: this.infoForm.district,
                phone: this.infoForm.phone,
                professorLevel: this.infoForm.professorLevel,
                adept: this.infoForm.adept,
                intro: this.infoForm.intro,
                smsCode: this.infoForm.smsCode,
                annex: this.fileList2,
              }
              expertUpdate(obj).then(res => {
                console.log(res, '修改成功了吗');
                if (res.code == '0') {
                  uni.$u.toast('修改成功', 5000)
                  uni.navigateBack()
                  // this.getExpertInfo()
                } else {
                  uni.$u.toast(res.msg, 5000)
                }
              })
              console.log(res);
      
            }).catch(error => {
              console.log(error);
              uni.$u.toast('请先按要求填写', 5000)
            })
          }
        })
      
      },
      

<think>嗯,用户想了解Excel中的VLOOKUP函数的用法和参数含义。首先,我需要回忆一下VLOOKUP的基本结构。VLOOKUP是垂直查找函数,用于在表格的首列查找指定的值,然后返回该行中指定列的数据。它的四个参数分别是查找值、表格范围、列索引号和匹配模式。 接下来,我得确认每个参数的具体作用。第一个参数是lookup_value,也就是用户要查找的值,比如产品ID或者姓名。第二个参数是table_array,即查找的范围,这里要注意的是,查找值必须位于这个范围的第一列,否则函数无法正确工作。第三个参数是col_index_num,也就是用户想要返回的数据在表格范围中的第几列,这个列数是从表格范围的第一列开始算起的,不是整个工作表的列。第四个参数是range_lookup,决定是精确匹配还是近似匹配,通常用FALSE或0来指定精确匹配,避免错误。 然后,用户可能需要一个具体的例子来理解如何使用。比如,假设有一个产品价格表,用户想根据产品ID查找对应的价格。这时候,VLOOKUP就可以在ID列查找,然后返回价格列的数据。同时,要提醒用户注意表格范围最好使用绝对引用,比如$A$2:$C$100,这样在拖动公式时范围不会变化。 可能遇到的问题也需要考虑。比如,如果查找值不在表格的第一列,或者列索引号超过了表格的列数,函数会返回错误。此外,数据格式不一致也可能导致问题,比如查找值是数字,而表格中是文本格式的数字,这时候需要统一格式。还有,当出现#N/A错误时,可能是查找值不存在,或者匹配模式设置不正确,需要检查参数是否正确。 用户可能还会问到如何避免常见的错误,比如部分数据匹配出错的情况。这时候需要检查是否有多余的空格,或者数据格式不一致,或者表格范围没有锁定导致拖动时偏移。此外,XLOOKUP作为VLOOKUP的升级版,可能在某些情况下更方便,比如可以向左查找或者返回多列数据,这也是可以提及的内容。 最后,整理步骤,从基础语法到参数说明,再到具体案例,逐步引导用户理解如何使用VLOOKUP函数。同时,提供常见错误和解决方法,帮助用户在实际应用中避免问题。如果有必要,还可以比较VLOOKUP和其他查找函数的区别,比如HLOOKUP或XLOOKUP,但根据用户的问题,主要集中在VLOOKUP本身即可。</think>### Excel VLOOKUP函数详解 #### 一、基础语法与参数说明 VLOOKUP函数的语法为: $$=VLOOKUP(lookup\_value, table\_array, col\_index\_num, [range\_lookup])$$ 包含4个参数: 1. **lookup_value**(必填):要查找的值(如单元格引用或具体值) 2. **table_array**(必填):包含数据的表格范围(必须包含查找列和返回列) 3. **col_index_num**(必填):返回值所在列的序号(从table_array第一列开始计数) 4. **range_lookup**(可选):匹配类型 - `TRUE`/`1`:近似匹配(默认值,需数据升序排列) - `FALSE`/`0`:精确匹配(常用选项) [^1][^2] #### 二、使用步骤演示(工资表查询案例) 假设需要根据员工编号查询工资: 1. 建立查询单元格(如`B12`) 2. 输入公式: ```excel =VLOOKUP(A12, $A$2:$D$100, 4, 0) ``` - `A12`:待查询的员工编号 - `$A$2:$D$100`:锁定数据区域(绝对引用) - `4`:返回第4列(工资列) - `0`:精确匹配 [^2][^3] #### 三、常见错误与解决方法 | 错误现象 | 原因 | 解决方案 | |---------|------|---------| | #N/A | 查找值不存在 | 检查数据源或改用`IFERROR`容错 | | #REF! | 列序号超出范围 | 确认col_index_num ≤ 表格列数 | | 部分匹配失败 | 数据格式不一致 | 统一数值/文本格式 | | 结果错位 | 表格未锁定 | 使用`$`符号固定区域引用 | [^3][^4] #### 四、进阶技巧 1. **多条件查询**: 使用辅助列合并多个条件字段 ```excel =VLOOKUP(A2&B2, $D$2:$F$100, 3, 0) ``` 2. **通配符匹配**: `"*"`匹配任意字符,`"?"`匹配单个字符 ```excel =VLOOKUP("张*", $A$2:$C$100, 3, 0) ``` 3. **跨表查询**: 引用其他工作表数据 ```excel =VLOOKUP(A2, Sheet2!$A$2:$D$100, 4, 0) ``` [^1][^4]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值