啊鑫
5 天以前 52c82b4f021814fc1cbe49b70871757a9001458a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<template>
    <view id="barcode"></view>
</template>
 
<script>
    export default {
        data() {
            return {
                // #ifdef APP-PLUS
                barcode: [
                    plus.barcode.QR,
                    plus.barcode.EAN13,
                    plus.barcode.EAN8,
                    plus.barcode.UPCA,
                    plus.barcode.UPCE,
                    plus.barcode.CODABAR,
                    plus.barcode.CODE39,
                    plus.barcode.CODE93,
                    plus.barcode.CODE128,
                    plus.barcode.ITF,
                ],//码类型
                // #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: '0',
                left: '0px',
                width: '100%',
                height: height,//这里可以设置扫码框的高度
                position: 'static'
            });
            this.barcode.onmarked = this.onmarked;
            currentWebview.append(this.barcode);
            const res = uni.getSystemInfoSync();
            if(res.platform == 'android'){//安卓机
                this.barcode.start();
            }
            // #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>