scan.vue 3.0 KB

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