function scanQRCode(wx) {
  // 只允许从相机扫码
  wx.scanCode({
    onlyFromCamera: true,
    success(res) {
      console.log(res)
      if (res.scanType == "WX_CODE" && res.path) {
        // console.log("res.path", res.path)
        // res.path  pages/index/index?scene=guard;1758617522619420679
        let searchParams = res.path.split('?');
        let params = searchParams[1]
        console.log("searchParams", searchParams, "params", params)
        if (params && params.startsWith('scene=guard')) {
          wx.navigateTo({
            url: "/pages/scan/entrance?" + params
          })
          return
        }
      }
      wx.showToast({
        title: "您扫描的不是门禁码",
        icon: 'error',
        duration: 2000
      })
    }
  })
}

module.exports = scanQRCode;
