scan.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <view id="barcode" style="background-color: #18B566;width: 100%;height: 100%"></view>
  3. </template>
  4. <script>
  5. export default {
  6. data() {
  7. return {
  8. // #ifdef APP-PLUS
  9. barcode: [
  10. plus.barcode.CODE39,
  11. plus.barcode.CODE93,
  12. plus.barcode.CODE128,
  13. ], //码类型
  14. bug:'',
  15. // #endif
  16. };
  17. },
  18. created() {
  19. var statusBarHeight = uni.getSystemInfoSync().statusBarHeight; //状态栏
  20. var height = statusBarHeight + 44 + 144 + 'px';
  21. var pages = getCurrentPages();
  22. var page = pages[pages.length - 1];
  23. // #ifdef APP-PLUS
  24. var currentWebview = page.$getAppWebview();
  25. this.barcode = plus.barcode.create('barcode', this.barcode, {
  26. top: '0',
  27. left: '0',
  28. width: '100%',
  29. height: '420', //180px
  30. position: 'static',
  31. background: '#ffffff',
  32. frameColor: '#00A0EA',
  33. scanbarColor: '#00A0EA'
  34. });
  35. this.barcode.onmarked = this.onmarked;
  36. // this.barcode.start({vibrate: false}); //振动
  37. this.barcode.start({sound: "none"}); //提示音
  38. currentWebview.append(this.barcode);
  39. const res = uni.getSystemInfoSync();
  40. if (res.platform == 'android') { //安卓机
  41. this.barcode.start();
  42. }
  43. this.barcode.setStyle({
  44. background: '#ffffff',
  45. frameColor: '#00A0EA',
  46. scanbarColor: '#00A0EA'
  47. });
  48. // #endif
  49. },
  50. methods: {
  51. onmarked(type, result) {
  52. this.$emit('getCode', result);
  53. this.t = setTimeout(() => {
  54. this.barcode.start();
  55. }, 2000)
  56. }
  57. }
  58. }
  59. </script>
  60. <style lang="less">
  61. </style>