App-Android(使用App+htnl5框架,解决消息推送兼容SignalR问题)
loulijun2021
2022-09-21 32383daed1b498577da8c37145e66e2a93e28b2d
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="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
        <meta name="HandheldFriendly" content="true"/>
        <meta name="MobileOptimized" content="320"/>
        <title>Hello H5+</title>
        <script type="text/javascript" src="../js/common.js"></script>
        <script type="text/javascript">
var img = null;
var blist = [];
function scaned(t, r, f){
    var d = new Date();
    var h=d.getHours(),m=d.getMinutes(),s=d.getSeconds(),ms=d.getMilliseconds();
    if(h < 10){ h='0'+h; }
    if(m < 10){ m='0'+m; }
    if(s < 10){ s='0'+s; }
    if(ms < 10){ ms='00'+ms; }
    else if(ms < 100){ ms='0'+ms; }
    var ts = '['+h+':'+m+':'+s+'.'+ms+']';
    var li=null,hl = document.getElementById('history');
    if(blist.length > 0){
        li = document.createElement('li');
        li.className = 'ditem';
        hl.insertBefore(li, hl.childNodes[0]);
    } else{
        li = document.getElementById('nohistory');
    }
    li.id = blist.length;
    var html = '['+h+':'+m+':'+s+'.'+ms+']'+'  '+t+'码<div class="hdata">';
    html += r;
    html += '</div>';
    li.innerHTML = html;
    li.setAttribute('onclick', 'selected(id)');
    blist[blist.length] = {type:t,result:r,file:f};
    update(t, r, f);
}
function selected(id){
    var h = blist[id];
    update( h.type, h.result, h.file );
    if(h.result.indexOf('http://')==0  || h.result.indexOf('https://')==0){
        plus.nativeUI.confirm(h.result, function(i){
            if(i.index == 0){
                plus.runtime.openURL(h.result);
            }
        }, '', ['打开', '取消']);
    } else{
        plus.nativeUI.alert(h.result);
    }
}
function update(t, r, f){
    outSet('扫描成功:');
    outLine(t);
    outLine(r);
    outLine('\n图片地址:'+f);
    if(!f || f=='null'){
        img.src = '../img/barcode.png';    
    } else{
        plus.io.resolveLocalFileSystemURL(f, function(entry){
            img.src=entry.toLocalURL();
        });
        //img.src = 'http://localhost:13131/'+f;
    }
}
function onempty(){
    if(window.plus){
        plus.nativeUI.alert('无扫描记录');
    } else {
        alert('无扫描记录');
    }
}
function cleanHistroy(){
    if(blist.length > 0){
        var hl = document.getElementById('history');
        hl.innerHTML = '<li id="nohistory" class="ditem" onclick="onempty();">无历史记录    </li>';
    }
    plus.io.resolveLocalFileSystemURL('_doc/barcode/', function(entry){
        entry.removeRecursively(function(){
            // Success
        }, function(e){
            //alert( "failed"+e.message );
        });
    });
}
// 打开二维码扫描界面 
function openBarcode(){
    createWithoutTitle('barcode_scan.html', {
        titleNView:{
            type: 'float',
            backgroundColor: 'rgba(215,75,40,0.3)',
            titleText: '扫一扫',
            titleColor: '#FFFFFF',
            autoBackButton: true,
            buttons: [{
                fontSrc: '_www/helloh5.ttf',
                text: '\ue302',
                fontSize: '18px',
                onclick: 'javascript:scanPicture()'
            }]
        }
    });
}
// 打开自定义扫描界面 
function openBarcodeCustom(){
    createWithoutTitle('barcode_custom.html', {
        titleNView:{
            type: 'float',
            backgroundColor: 'rgba(215,75,40,0.3)',
            titleText: '扫一扫',
            titleColor: '#FFFFFF',
            autoBackButton: true,
            buttons: [{
                fontSrc: '_www/helloh5.ttf',
                text: '\ue401',
                fontSize: '18px',
                onclick: 'javascript:switchFlash()'
            }]
        }
    });
}
        </script>
        <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8"/>
        <style type="text/css" media="screen">
.hdata {
    color: #e1673e;    
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
        </style>
    </head>
    <body onload="img=document.getElementById('bimg')">
        <br/>
        <img style="width:40%" id="bimg" src="../img/barcode.png"/>
        <br/>
        <div class="button" onclick="openBarcode()">扫一扫</div>
        <div class="button" onclick="openBarcodeCustom()">扫一扫(自定义)</div>
        <br/>
        <ul id="history" class="dlist" style="text-align:left;">
            <li id="nohistory" class="ditem" onclick="onempty()">无历史记录    </li>
        </ul>
        <br/>
        <div class="button button-waring" onclick="cleanHistroy()">清空历史记录</div>
        <div id="outpos"/>
        <div id="output">
Barcode提供二维码扫描识别功能,支持调用摄像头即时扫描二维码,也可直接输入图片进行扫描识别。
        </div>
    </body>
</html>