收藏
回答

wx.scancode 回调到的result 无法使用if判断?

getscancode:function(){

  var that=this

db.collection("Ringscancode").where({admincompany:that.data.usercompany}).get({

  success:function(res){

    if(res.data.length>0){

      console.log("Ringscancodedata",res.data)

      var code=res.data[0].code

      wx.scanCode({

        onlyFromCamera: true,

        success (re) {

          let getcode=re.result

          console.log('getcode',re.result)

          console.log("code",code )

          if( getcode==code ){

            db.collection("usersRing").where({ today: util.formatDate(new Date()), _openid: that.data.openid  }).get({

              success: function (res) {

                console.log("查询有无打卡数据", res)

                 if(res.data.length==0){

                   db.collection("usersRing").add({

                     data: {

                       usernickName: that.data.usernickName,

                       usercompany: that.data.usercompany,

                       username: that.data.username,

                       today: util.formatDate(new Date()),

                       MRinguptime: new Date(0),

                       MRingdowntime: new Date(0),

                       ARinguptime: new Date(0),

                       ARingdowntime: new Date(0),

                       ERinguptime: new Date(0),

                       ERingdowntime: new Date(0),

                       URinguptime: new Date(0),

                       URingdowntime: new Date(0)

                     },

                     success: res =>{

                       wx.navigateTo({

                         url: '../userpage1-1/userpage1-1',

                       },console.log("创建数据成功", res)

                     },

                     fail: err => {

                       wx.showToast({

                         title: '程序出错',

                         icon: '',

                       })

                     }

                   })

                 }

                 else {

                   console.log("直接跳转")

                   wx.navigateTo({

                     url: '../userpage1-1/userpage1-1',         

                   })  

                 }            

              }

            })

          }else{

            wx.showToast({

              title: '无效二维码',

              icon:"none"

            })

          }

  

        }

      })

    }else{

      console.log("Ringscancodedata",res.data)

   wx.showToast({

     title: '管理员未开启此功能',

     icon:"none",

   })

    }

  },

})

},

code 和 getcode打印出来的是一样的,就是执行函数后不执行if(code==getcode)后的语句 打印code==getcode是false

最后一次编辑于  2020-05-04
回答关注问题邀请回答
收藏

2 个回答

  • Mr.Zhao
    Mr.Zhao
    2020-05-04

    大佬,其中一个有空格吧,没事好好学学js

    2020-05-04
    有用 1
    回复 11
    • Lgh_13150849294
      Lgh_13150849294
      2020-05-04
      我先制作一个二维码,将二维码的内容保存到数据库,二维码保存到本地,然后扫码判断result和get到的数据库的二维码内容是否相同,相同则执行下面的内容,可是计算机判断他俩不同
      2020-05-04
      回复
    • Mr.Zhao
      Mr.Zhao
      2020-05-04回复Lgh_13150849294
      光说不练,假把式
      2020-05-04
      回复
    • Lgh_13150849294
      Lgh_13150849294
      2020-05-04
      我在问题中添加了打印截图,实在搞不懂,//我是新手。。。。
      2020-05-04
      回复
    • Mr.Zhao
      Mr.Zhao
      2020-05-04回复Lgh_13150849294
      输出字符串的长度,会不会?
      2020-05-04
      回复
    • Lgh_13150849294
      Lgh_13150849294
      2020-05-04
      咋样去掉空格呢,大哥,我不是大佬
      2020-05-04
      回复
    查看更多(6)
  • Lgh_13150849294
    Lgh_13150849294
    2020-05-04

    单独打印code和getcode是一样的,但是打印code == getcode是false

    2020-05-04
    有用
    回复
登录 后发表内容
问题标签