index.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { connect } from 'herculex';
  2. import request from "../../../../core/utils/request";
  3. Component(connect({
  4. mapStateToProps: {}
  5. })({
  6. data: {
  7. icon: 'https://intranetproxy.alipay.com/skylark/lark/0/2021/png/336036/1617850771006-06992055-9adf-4dce-af7f-08f5066feb99.png',
  8. tips: '扫码核验的目的\n方便商家核验用户身份的真实性'
  9. },
  10. props: {},
  11. didMount() {},
  12. methods: {
  13. async handleScan() {
  14. my.scan({
  15. success: res => {
  16. // console.log(res);
  17. if (!res || !res.qrCode) {
  18. return my.alert({
  19. title: '识别失败',
  20. content: '未识别到二维码参数',
  21. buttonText: '我知道了'
  22. });
  23. }
  24. this.recognizeQrCode(res.qrCode);
  25. },
  26. fail: error => {
  27. if (error.code === 11) {
  28. my.alert({
  29. title: '识别失败',
  30. content: '调用扫码失败',
  31. buttonText: '我知道了'
  32. });
  33. }
  34. }
  35. });
  36. },
  37. async recognizeQrCode(qrCode) {
  38. const params = {
  39. url: '/api/v1/proxy/soldier/recognizeCertQrCode',
  40. method: 'post',
  41. data: {
  42. qrCode
  43. },
  44. isShowError: true,
  45. isShowLoadig: true
  46. };
  47. const [err, res = {}] = await request(params);
  48. if (err || res.result !== 'suc') {
  49. const msg = res.recognizeRemark || '扫码识别失败';
  50. return my.alert({
  51. title: '识别失败',
  52. content: msg,
  53. buttonText: '我知道了'
  54. });
  55. }
  56. my.redirectTo({
  57. url: `/antbuilder/industry/soldier/pages/scan-result/index?query=${JSON.stringify(res)}`
  58. });
  59. }
  60. }
  61. }));