scan.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <template>
  2. <view id="barcode"></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. // #endif
  15. };
  16. },
  17. created() {
  18. var statusBarHeight = uni.getSystemInfoSync().statusBarHeight; //状态栏
  19. var height = statusBarHeight + 44 + 144 + 'px';
  20. var pages = getCurrentPages();
  21. var page = pages[pages.length - 1];
  22. // #ifdef APP-PLUS
  23. var currentWebview = page.$getAppWebview();
  24. this.barcode = plus.barcode.create('barcode', this.barcode, {
  25. top: '12%',
  26. left: '10%',
  27. width: '80%',
  28. height: '31.5%', //180px
  29. position: 'static',
  30. background:'#ffffff',
  31. frameColor:'#00A0EA',
  32. scanbarColor:'#00A0EA'
  33. });
  34. this.barcode.onmarked = this.onmarked;
  35. currentWebview.append(this.barcode);
  36. const res = uni.getSystemInfoSync();
  37. if (res.platform == 'android') { //安卓机
  38. this.barcode.start();
  39. }
  40. this.barcode.setStyle({
  41. });
  42. // #endif
  43. },
  44. onUnload() {
  45. clearTimeout(this.t);
  46. },
  47. methods: {
  48. onmarked(type, result) {
  49. // console.log(type +':'+ result);
  50. this.$emit('getCode', result);
  51. this.t = setTimeout(() => {
  52. this.barcode.start();
  53. }, 1000)
  54. }
  55. }
  56. }
  57. </script>
  58. <style lang="less">
  59. </style>