1
yhj
2025-03-31 9003044073373185511f1e2c901285a3287e7fa4
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title></title>
    <script src="../../../js/mui.min.js"></script>
    <script src="../../../js/api.js"></script>
    <link href="../../../css/mui.min.css" rel="stylesheet"/>
    <link rel="stylesheet" type="text/css" href="../../../css/iconfont.css" />
 <style type="text/css">
            #bcid {
                width: 100%;
                height: 100%;
                position: absolute;
                background: #000000;
            }
            html,
            body,
            div {
                height: 100%;
                width: 100%;
            }
            .fbt {
                color: #0E76E1;
                width: 50%;
                background-color: #ffffff;
                float: left;
                line-height: 44px;
                text-align: center;
            }
        </style>
    </head>
    <body>
        <header class="mui-bar mui-bar-nav" style="background-color: #ffffff;">
            <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
            <h1 class="mui-title" style="color: #0E76E1;">条码扫描</h1>
            <span class="title-right" id="usr"></span>
            <span class="title-right mui-icon mui-icon-camera" style="color:#ffffff;" id="cameraId"></span>
            <span class="mui-icon mui-icon-spinner-cycle mui-spin mui-pull-right" id="turnTheLight"></span>
        </header>
 
        <div id="bcid">
            <!--盛放扫描控件的div-->
        </div>
 
        <div class="mui-bar mui-bar-footer" style="padding: 0px;">
            <div class="fbt" οnclick="scanPicture();">从相册选择二维码</div>
            <div class="fbt mui-action-back">取  消</div>
        </div>
 
        <script type="text/javascript">
            scan = null; //扫描对象
            var urlId = '';var inputId="";
            var ws=null,wo=null;
            var scan=null,domready=false;
            mui.plusReady(function() {
                mui.init();
                document.getElementById("usr").innerHTML = setUsrCode()
                //urlId = plus.webview.currentWebview().urlId;
                inputId = plus.webview.currentWebview().inputId; //获取父页面传入的inputId
                premark = plus.webview.currentWebview().premark
                console.log(premark)
                startRecognize();
            });
 
            function startRecognize() {
                try {
                    var filter;
                    //自定义的扫描控件样式
                    var styles = {
                        top: '100px',
                        left: '0px',
                        width: '100%',
                        height: '500px',
                        position: 'static',
                    }
                    //扫描控件构造
                    scan = plus.barcode.create('bcid', filter, styles);
                    scan.onmarked = onmarked;
                    scan.onerror = onerror;
                    plus.webview.currentWebview().append(scan);
                    scan.start();
                    //打开关闭闪光灯处理
                    var flag = false;
                    document.getElementById("turnTheLight").addEventListener('tap', function() {
                        if (flag == false) {
                            scan.setFlash(true);
                            flag = true;
                        } else {
                            scan.setFlash(false);
                            flag = false;
                        }
                    });
                } catch (e) {
                    console.log(e)
                    alert("出现错误啦:\n" + e);
                }
            };
 
            function onerror(e) {
                alert(e);
            };
 
            function onmarked(type, result) {
                var text = '';
                switch (type) {
                    case plus.barcode.QR:
                        text = 'QR: ';
                        break;
                    case plus.barcode.EAN13:
                        text = 'EAN13: ';
                        break;
                    case plus.barcode.EAN8:
                        text = 'EAN8: ';
                        break;
                }
                //扫描成功之后的处理
                // alert(text + " : " + result);
                // playerYes()
                back(result);
                scan.start();
            };
            function back(result){
                // var main=plus.webview.getWebviewById(urlId);
                // mui.fire(main,'changeBar',{barcode:result});
                // mui.back();
                var view = plus.webview.currentWebview().opener(); //子页面调用父页面
                if(premark!=""){
                    result = premark+result
                }
                mui.fire(view,'changeBar',{ //通过mui.fire()方法可以触发目标窗口的自定义事件,mui.fire(目标窗口的webview,'自定义事件名',{参数列表});
                    barcode:result,
                    inputId:inputId
                });
                mui.back()
                }
 
            // 从相册中选择二维码图片 
            function scanPicture() {
                plus.gallery.pick(function(path) { //实现拍照或者相册选择图片上传
                    plus.barcode.scan(path, onmarked, function(error) {
                        plus.nativeUI.alert("无法识别此图片");
                    });
                }, function(err) {
                    plus.nativeUI.alert("Failed: " + err.message);
                });
            }
        </script>
    </body>
</html>