sweepPage.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <div class="sweep" v-if="show">
  3. <QrcodeStream
  4. class="ku-scanner"
  5. ref="QrcodeStreamRef"
  6. v-if="show"
  7. :constraints="{ facingMode: { ideal: 'environment' } }"
  8. :camera="camera"
  9. :torch="torchActive"
  10. :zoom="1"
  11. :key="cameraKey"
  12. @decode="onDecode"
  13. @init="onInit"
  14. >
  15. <div class="ku-scanner-content">
  16. <div class="ku-scanner-tooltip">
  17. 将二维码/条码放入框内,即自动扫描
  18. </div>
  19. <div class="ku-scanner-section">
  20. <div class="ku-scanner-section-animation-line"></div>
  21. <div class="ku-scanner-section-angle"></div>
  22. </div>
  23. </div>
  24. </QrcodeStream>
  25. <span class="closeBtn" @click="close">
  26. <svg
  27. t="1733477770331"
  28. class="icon"
  29. viewBox="0 0 1024 1024"
  30. version="1.1"
  31. xmlns="http://www.w3.org/2000/svg"
  32. p-id="4265"
  33. width="64"
  34. height="64"
  35. >
  36. <path
  37. d="M623.807 528.693a113.756 113.756 0 0 0-0.139-33.126l252.787-252.692c26.245-26.236 26.245-68.772 0-95.006-26.248-26.236-68.798-26.236-95.043 0L528.281 400.902c-5.296-0.762-10.708-1.164-16.216-1.164s-10.92 0.402-16.216 1.164l-253.13-253.031c-26.245-26.236-68.796-26.236-95.043 0-26.245 26.234-26.245 68.77 0 95.006l252.789 252.692a113.726 113.726 0 0 0-0.14 33.124L147.676 781.247c-26.245 26.236-26.245 68.77 0 95.006 26.248 26.236 68.798 26.236 95.043 0L494.85 624.218c5.613 0.859 11.362 1.305 17.215 1.305s11.602-0.446 17.215-1.305l252.13 252.035c26.245 26.236 68.796 26.236 95.043 0 26.245-26.236 26.245-68.77 0-95.006L623.807 528.693z"
  38. fill="#000000"
  39. p-id="4266"
  40. ></path>
  41. <path
  42. d="M512.063 444.326c37.407 0 67.73 30.327 67.73 67.736 0 37.41-30.323 67.735-67.73 67.735-37.405 0-67.728-30.325-67.728-67.735 0.001-37.408 30.323-67.736 67.728-67.736z"
  43. fill="#000000"
  44. p-id="4267"
  45. ></path>
  46. </svg>
  47. </span>
  48. </div>
  49. </template>
  50. <script>
  51. import { QrcodeStream } from 'vue-qrcode-reader'
  52. export default {
  53. components: {
  54. QrcodeStream
  55. },
  56. data() {
  57. return {
  58. show: false,
  59. camera: 'auto', //front auto environment
  60. torchActive: false,
  61. flag: 0,
  62. paused: true,
  63. cameraKey: 'qgt'
  64. // constraints:{
  65. // width:300,
  66. // height:300
  67. // }
  68. }
  69. },
  70. methods: {
  71. open() {
  72. this.cameraKey = new Date().getTime()
  73. this.show = true
  74. // setTimeout(()=>{
  75. // this.$emit('success', "功能测试2503261429")
  76. // },1000)
  77. },
  78. stopCamera() {
  79. const video = document.querySelector('video')
  80. if (video && video.srcObject) {
  81. const stream = video.srcObject
  82. const tracks = stream.getTracks()
  83. tracks.forEach(track => track.stop())
  84. video.srcObject = null
  85. }
  86. },
  87. close() {
  88. this.stopCamera()
  89. this.show = false
  90. },
  91. onDecode(result) {
  92. this.$emit('success', result)
  93. // this.$toast(result)
  94. },
  95. async onInit(promise) {
  96. try {
  97. const { capabilities } = await promise
  98. const TORCH_IS_SUPPORTED = !!capabilities.torch
  99. console.log('TORCH_IS_SUPPORTED', TORCH_IS_SUPPORTED)
  100. await promise
  101. } catch (error) {
  102. this.$emit('error', error)
  103. this.close()
  104. }
  105. }
  106. }
  107. }
  108. </script>
  109. <style lang="scss" scoped>
  110. .sweep {
  111. width: 100vw;
  112. height: 100vh;
  113. z-index: 9990;
  114. background-color: #000;
  115. position: fixed;
  116. top: 0;
  117. left: 0;
  118. }
  119. .closeBtn {
  120. width: 40px;
  121. height: 40px;
  122. position: absolute;
  123. top: 20px;
  124. border-radius: 50%;
  125. background-color: #ffffff80;
  126. right: 20px;
  127. z-index: 9992;
  128. box-sizing: border-box;
  129. padding: 10px;
  130. svg {
  131. width: 100%;
  132. height: 100%;
  133. }
  134. }
  135. .ku-scanner {
  136. width: 100%;
  137. height: 100%;
  138. position: absolute;
  139. right: 0;
  140. top: 0;
  141. z-index: 9991;
  142. display: flex;
  143. justify-content: center;
  144. align-items: center;
  145. .ku-scanner-content {
  146. background-size: 3rem 3rem;
  147. background-position: -1rem -1rem;
  148. width: 100%;
  149. height: 100%;
  150. position: relative;
  151. background-color: rgba(18, 18, 18, 0);
  152. margin: auto;
  153. // 提示信息
  154. .ku-scanner-tooltip {
  155. width: 100%;
  156. height: 35px;
  157. line-height: 35px;
  158. font-size: 14px;
  159. text-align: center; /* color: #f9f9f9; */
  160. margin: 0 auto;
  161. position: absolute;
  162. top: 0;
  163. left: 0;
  164. color: #ffffff;
  165. }
  166. .ku-scanner-section {
  167. width: 213px;
  168. height: 213px;
  169. position: absolute;
  170. left: 50%;
  171. top: 50%;
  172. transform: translate(-50%, -50%);
  173. overflow: hidden;
  174. border: 0.1rem solid rgba(86, 247, 118, 0.301);
  175. // // 装饰角
  176. // &:after {
  177. // content: '';
  178. // display: block;
  179. // position: absolute;
  180. // width: 12px;
  181. // height: 12px;
  182. // border: 0.2rem solid transparent;
  183. // top: 0;
  184. // border-top-color: #2ffc58;
  185. // right: 0;
  186. // border-right-color: #2ffc58;
  187. // }
  188. // &:before {
  189. // content: '';
  190. // display: block;
  191. // position: absolute;
  192. // width: 12px;
  193. // height: 12px;
  194. // border: 0.2rem solid transparent;
  195. // top: 0;
  196. // border-top-color: #2ffc58;
  197. // left: 0;
  198. // border-left-color: #2ffc58;
  199. // }
  200. // // 装饰角
  201. // .ku-scanner-section-angle {
  202. // &:after {
  203. // content: '';
  204. // display: block;
  205. // position: absolute;
  206. // width: 12px;
  207. // height: 12px;
  208. // border: 0.2rem solid transparent;
  209. // bottom: 0;
  210. // border-bottom-color: #2ffc58;
  211. // right: 0;
  212. // border-right-color: #2ffc58;
  213. // }
  214. // &:before {
  215. // content: '';
  216. // display: block;
  217. // position: absolute;
  218. // width: 12px;
  219. // height: 12px;
  220. // border: 0.2rem solid transparent;
  221. // bottom: 0;
  222. // border-bottom-color: #2ffc58;
  223. // left: 0;
  224. // border-left-color: #2ffc58;
  225. // }
  226. // }
  227. // 扫描活动线
  228. .ku-scanner-section-animation-line {
  229. height: calc(100% - 2px);
  230. width: 100%;
  231. background: linear-gradient(180deg, rgba(0, 255, 51, 0) 43%, #2ffc58 211%);
  232. border-bottom: 3px solid #2ffc58;
  233. transform: translateY(-100%);
  234. animation: radar-beam 2s infinite alternate;
  235. animation-timing-function: cubic-bezier(0.53, 0, 0.43, 0.99);
  236. animation-delay: 1.4s;
  237. }
  238. }
  239. }
  240. }
  241. // 扫描活动线--上下 动画
  242. @keyframes radar-beam {
  243. 0% {
  244. transform: translateY(-100%);
  245. }
  246. 100% {
  247. transform: translateY(0);
  248. }
  249. }
  250. </style>