scan.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. if (!codeData.type) {
  65. if (codeData.type != 10) {
  66. uni.showToast({
  67. title: '请扫描设备二维码',
  68. icon: "none",
  69. mask: true,
  70. duration: 2000
  71. });
  72. } else {
  73. self.code = codeData.code;
  74. self.type = codeData.type;
  75. let joinHazardIds = [];
  76. if (this.form.hazardIds) {
  77. joinHazardIds = this.form.hazardIds.split(',')
  78. joinHazardIds.push(self.code)
  79. this.form.joinHazardIds = joinHazardIds
  80. } else {
  81. this.form.joinHazardIds = self.code
  82. }
  83. uni.navigateTo({
  84. url: '/pages_safetyExamine/views/examineManage/examineAddTow?form=' + encodeURIComponent(JSON
  85. .stringify(
  86. this.form)) + '&joinHazardIds=' + self.code
  87. });
  88. }
  89. } else {
  90. uni.showToast({
  91. title: '请扫描正确的二维码',
  92. icon: "none",
  93. mask: true,
  94. duration: 2000
  95. });
  96. }
  97. }
  98. }
  99. }
  100. </script>
  101. <style>
  102. .scanCode_box {
  103. width: 100%;
  104. height: 100%;
  105. display: flex;
  106. flex-direction: column;
  107. background-color: #000000;
  108. position: fixed;
  109. align-items: center;
  110. }
  111. .title {
  112. font-size: 34rpx;
  113. font-family: PingFang SC-Medium, PingFang SC;
  114. font-weight: 400;
  115. color: #FFFFFF;
  116. line-height: 48rpx;
  117. margin-top: 256rpx;
  118. text-align: center;
  119. }
  120. .camera {
  121. width: 433rpx;
  122. height: 434rpx;
  123. border-radius: 6rpx;
  124. margin: 30rpx;
  125. overflow: hidden;
  126. }
  127. .animation {
  128. position: absolute;
  129. top: 10rpx;
  130. left: 0rpx;
  131. width: 430rpx;
  132. height: 2rpx;
  133. background-color: #4CD964;
  134. border-radius: 50%;
  135. }
  136. .manual {
  137. width: 300rpx;
  138. height: 100rpx;
  139. background: #0183FA;
  140. border-radius: 60rpx 60rpx 60rpx 60rpx;
  141. font-size: 34rpx;
  142. font-family: PingFang SC-Medium, PingFang SC;
  143. font-weight: 400;
  144. color: #FFFFFF;
  145. line-height: 100rpx;
  146. text-align: center;
  147. position: fixed;
  148. bottom: 76rpx;
  149. left: 226rpx;
  150. }
  151. </style>