scan.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <!-- 扫一扫 -->
  2. <template>
  3. <view>
  4. <view class="scanCode_box">
  5. <view class="title">请扫描设备二维码</view>
  6. <camera class='camera' mode="scanCode" @error="cameraError" @scancode='scancode' frame-size='large'>
  7. <cover-view class='animation' :animation="animation"></cover-view>
  8. </camera>
  9. <view @click="manualFun()" class="manual">手动选择设备</view>
  10. </view>
  11. </view>
  12. </template>
  13. <script>
  14. let animation = uni.createAnimation({});
  15. export default {
  16. data() {
  17. return {
  18. animation,
  19. form: {},
  20. }
  21. },
  22. onLoad(option) {
  23. if (option.form) {
  24. this.form = JSON.parse(decodeURIComponent(option.form));
  25. }
  26. },
  27. onShow() {
  28. this.donghua()
  29. },
  30. methods: {
  31. donghua() {
  32. let that = this;
  33. let scode = true
  34. setInterval(function() {
  35. if (scode) {
  36. animation.translateY(250).step({
  37. duration: 3000
  38. })
  39. scode = !scode;
  40. } else {
  41. animation.translateY(-10).step({
  42. duration: 3000
  43. })
  44. scode = !scode;
  45. }
  46. that.animation = animation.export()
  47. }.bind(this), 3000)
  48. },
  49. //手动选择设备
  50. manualFun() {
  51. uni.redirectTo({
  52. url: '/pages_safetyExamine/examineManage/examineAddContent?form=' + encodeURIComponent(JSON.stringify(this
  53. .form)) + '&pageType=3'
  54. });
  55. },
  56. scancode(e) {
  57. let self = this;
  58. let text = decodeURIComponent(e.detail.result)
  59. let list = text.split("?")[1].split("&");
  60. let codeData = {};
  61. list.forEach((item) => {
  62. codeData[item.split("=")[0]] = item.split("=")[1];
  63. })
  64. self.code = codeData.code;
  65. self.type = codeData.type;
  66. let joinHazardIds = [];
  67. if (this.form.hazardIds) {
  68. joinHazardIds = this.form.hazardIds.split(',')
  69. joinHazardIds.push(self.code)
  70. this.form.joinHazardIds = joinHazardIds
  71. } else {
  72. this.form.joinHazardIds = self.code
  73. }
  74. uni.navigateTo({
  75. url: '/pages_safetyExamine/views/examineManage/examineAddTow?form=' + encodeURIComponent(JSON.stringify(
  76. this.form)) + '&joinHazardIds=' + self.code
  77. });
  78. }
  79. }
  80. }
  81. </script>
  82. <style>
  83. .scanCode_box {
  84. width: 100%;
  85. height: 100%;
  86. display: flex;
  87. flex-direction: column;
  88. background-color: #000000;
  89. position: fixed;
  90. align-items: center;
  91. }
  92. .title {
  93. font-size: 34rpx;
  94. font-family: PingFang SC-Medium, PingFang SC;
  95. font-weight: 400;
  96. color: #FFFFFF;
  97. line-height: 48rpx;
  98. margin-top: 256rpx;
  99. text-align: center;
  100. }
  101. .camera {
  102. width: 433rpx;
  103. height: 434rpx;
  104. border-radius: 6rpx;
  105. margin: 30rpx;
  106. overflow: hidden;
  107. }
  108. .animation {
  109. position: absolute;
  110. top: 10rpx;
  111. left: 0rpx;
  112. width: 430rpx;
  113. height: 2rpx;
  114. background-color: #4CD964;
  115. border-radius: 50%;
  116. }
  117. .manual {
  118. width: 300rpx;
  119. height: 100rpx;
  120. background: #0183FA;
  121. border-radius: 60rpx 60rpx 60rpx 60rpx;
  122. font-size: 34rpx;
  123. font-family: PingFang SC-Medium, PingFang SC;
  124. font-weight: 400;
  125. color: #FFFFFF;
  126. line-height: 100rpx;
  127. text-align: center;
  128. position: fixed;
  129. bottom: 76rpx;
  130. left: 226rpx;
  131. }
  132. </style>