scan.vue 1.4 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: '50%', //180px
  30. position: 'static',
  31. background: '#ffffff',
  32. frameColor: '#00A0EA',
  33. scanbarColor: '#00A0EA'
  34. });
  35. this.barcode.onmarked = this.onmarked;
  36. currentWebview.append(this.barcode);
  37. const res = uni.getSystemInfoSync();
  38. if (res.platform == 'android') { //安卓机
  39. this.barcode.start();
  40. }
  41. this.barcode.setStyle({
  42. });
  43. // #endif
  44. },
  45. onUnload() {
  46. clearTimeout(this.t);
  47. },
  48. methods: {
  49. onmarked(type, result) {
  50. // console.log(type +':'+ result);
  51. this.$emit('getCode', result);
  52. this.t = setTimeout(() => {
  53. this.barcode.start();
  54. }, 1000)
  55. }
  56. }
  57. }
  58. </script>
  59. <style lang="less">
  60. </style>