微信原生小程序上传与识别以及监听多个checkbox事件打开pdf

1.点击上传并识别

组件样式
      
        
      


view .van-field__control {
  text-align: right;
}
方法
  handleChooseImg(){
    wx.chooseImage({
      count: 1,
      sourceType: ['album'],
      success: (res) => {
        let temp_path = res.tempFilePaths[0];
        console.log(temp_path);
        const _this = this
        wx.uploadFile({
          filePath: temp_path, 文件路径 按后端接口参数修改
          name: 'file', 传过去的文件名
          url: 后端接口,
          success: (res) => {
            let data = JSON.parse(res.data)
            if (data.code === 200) {
              _this.getBankCardOcr(data.data.fullFilePath)
            } else {
              wx.showToast({
                title: '上传失败',
                icon: 'none',
                duration: 2000
              });
            }
            wx.hideLoading()
          },
          fail: () => {
            console.log("失败...");
          }
        })
      }
    })
  },

  OCR识别
    getBankCardOcr(imageUrl) {
      wx.showLoading()
      util.request(commonLoan.bankCardOcr, {
        imageUrl
      }, 'GET').then((res) => {
        wx.hideLoading()  
      }).catch(err => {})
    },
 2.一个方法监听多个checkbox打开pdf

场景:多个checkbox,我觉得要一个一个写bindchange事件太杂糅

微信原生小程序上传与识别以及监听多个checkbox事件打开pdf_第1张图片

 

样式代码

 
            
             阅读并同意签署《个人授权书》(适用于零售信贷线上业务个人征信授权)
change事件
  changeCheck2(e) {
    this.setData({
      ['check' + e.currentTarget.dataset.index]: e.detail
    })
    if (this.data.check1 && this.data.check2 && this.data.check3 && this.data.check4 && this.data.check5) {
      this.setData({
        checkAll: true
      })
    } else {
      this.setData({
        checkAll: false
      })
    }
  },

 

你可能感兴趣的:(前端,微信,小程序,前端)