verify.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <view class="container">
  3. <view class="text-box">
  4. <text v-if="scanResult == ''" class="scanResult">待扫码</text>
  5. <text v-else class="scanResult">扫码结果:{{ scanResult }}</text>
  6. </view>
  7. <view class="btn-box">
  8. <button class="btn-scan" type="primary" @click="handleScan()">扫一扫</button>
  9. </view>
  10. </view>
  11. </template>
  12. <script>
  13. import {
  14. AssVerificationRequest
  15. } from "@/grpc/app_api_pb.js"
  16. import Base64 from 'base-64'
  17. export default {
  18. data() {
  19. return {
  20. userId: 0,
  21. uoId: 0,
  22. scanResult: ''
  23. }
  24. },
  25. onLoad() {},
  26. methods: {
  27. handleScan() {
  28. let that = this
  29. this.scanResult = ''
  30. // 允许从相机和相册扫码
  31. uni.scanCode({
  32. success: function(res) {
  33. // console.log('条码类型:' + res.scanType)
  34. // console.log('条码内容:' + res.result)
  35. let result = Base64.decode(res.result)
  36. console.log(result)
  37. result = JSON.parse(result)
  38. // console.log('条码内容 Base64.decode:' + JSON.stringify(result))
  39. that.userId = result.userId
  40. that.uoId = result.uoId
  41. // console.log('userId:' + that.userId)
  42. // console.log('uoId:' + that.uoId)
  43. that.verification()
  44. }
  45. })
  46. },
  47. // 核销
  48. verification() {
  49. // 创建请求参数并赋值
  50. var request = new AssVerificationRequest()
  51. request.setUserid(this.userId)
  52. request.setUoid(this.uoId)
  53. // 调用客户端相应的grpc方法,发送grpc请求,并接受后台发送回来的返回值
  54. this.$client.assVerification(request, {}, (err, response) => {
  55. if (err) {
  56. console.log(`[assVerification] err: code = ${err.code}` +
  57. `, message = "${err.message}"`)
  58. uni.showToast({
  59. title: `${err.message} (err:${err.code})`,
  60. icon: 'none',
  61. duration: 2000
  62. })
  63. this.scanResult = `${err.message} (err:${err.code})`
  64. } else {
  65. // console.log(response)
  66. uni.showToast({
  67. title: `核销成功`,
  68. icon: 'success',
  69. duration: 2000
  70. })
  71. this.scanResult = '核销成功'
  72. }
  73. });
  74. }
  75. }
  76. }
  77. </script>
  78. <style scoped lang="scss">
  79. .container {
  80. padding: 15px;
  81. box-sizing: border-box;
  82. .text-box {
  83. display: flex;
  84. justify-content: center;
  85. align-items: center;
  86. height: 200rpx;
  87. .scanResult {}
  88. }
  89. .btn-box {
  90. display: flex;
  91. justify-content: space-between;
  92. align-items: center;
  93. margin-top: 20px;
  94. .btn-scan {
  95. width: 90%;
  96. }
  97. }
  98. }
  99. </style>