123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <template>
- <view id="barcode"></view>
- </template>
- <script>
- export default {
- data() {
- return {
- // #ifdef APP-PLUS
- barcode: [
- plus.barcode.CODE39,
- plus.barcode.CODE93,
- plus.barcode.CODE128,
- ], //码类型
- // #endif
- };
- },
- created() {
- var statusBarHeight = uni.getSystemInfoSync().statusBarHeight; //状态栏
- var height = statusBarHeight + 44 + 104 + 'px';
- var pages = getCurrentPages();
- var page = pages[pages.length - 1];
- // #ifdef APP-PLUS
- var currentWebview = page.$getAppWebview();
- this.barcode = plus.barcode.create('barcode', this.barcode, {
- top: '7px',
- left: '10%',
- width: '80%',
- height: '35%', //180px
- position: 'static',
- background:'#ffffff',
- frameColor:'#00A0EA',
- scanbarColor:'#00A0EA'
-
-
- });
- this.barcode.onmarked = this.onmarked;
- currentWebview.append(this.barcode);
- const res = uni.getSystemInfoSync();
- if (res.platform == 'android') { //安卓机
- this.barcode.start();
- }
-
- this.barcode.setStyle({
-
- });
- // #endif
- },
- onUnload() {
- clearTimeout(this.t);
- },
- methods: {
- onmarked(type, result) {
- // console.log(type +':'+ result);
- this.$emit('getCode', result);
- this.t = setTimeout(() => {
- this.barcode.start();
- }, 1000)
- }
- }
- }
- </script>
- <style lang="less">
- </style>
|