scanner.html
5.27 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
<title>添加设备</title>
<link rel="stylesheet" type="text/css" href="../../css/api.css" />
<link rel="stylesheet" type="text/css" href="../../css/aui.css" />
<link rel="stylesheet" type="text/css" href="../../css/style.css" />
</head>
<body class="scanner-view">
</body>
</html>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript" src="../../script/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="../../script/ctrl.js"></script>
<script type="text/javascript">
apiready = function() {
var isEmpty = api.pageParam.isEmpty;
var FNScanner = api.require('FNScanner');
api.addEventListener({
name:'pause'
}, function(ret, err){
FNScanner.onPause();
});
api.addEventListener({
name:'resume'
}, function(ret, err){
FNScanner.onResume();
});
openFNScanner()
setTimeout(function(){
FNScanner.closeView();
api.closeWin();
},3*60*1000);
}
function openFNScanner() {
var FNScanner = api.require('FNScanner');
FNScanner.openView({
autorotation: true,
rect:{
x: 0, //(可选项)数字类型;模块左上角的 x 坐标(相对于所属的 Window 或 Frame);默认:0
y: 0, //(可选项)数字类型;模块左上角的 y 坐标(相对于所属的 Window 或 Frame);默认:0
w: 'auto', //(可选项)数字类型;模块的宽度;支持设置'auto';默认:所属的 Window 或 Frame 的宽度
h: 'auto' //(可选项)数字类型;模块的高度;支持设置'auto';默认:所属的 Window 或 Frame 的高度
},
sound: "../../res/5383.wav"
},async function(ret, err) {
if (ret) {
if (ret.eventType == 'cancel') {
if (isEmpty) {
api.alert({
title: '添加设备',
msg: '暂无设备,请先添加设备',
}, function(ret, err){
if( ret ){
openCanner(isEmpty);
}
});
}
} else if (ret.eventType == 'success') {
var checkExist = true;
var result = await check_device_bind(ret.content, api.getPrefs({sync: true,key: 'userID'}), api.getPrefs({sync: true,key: 'userToken'}))
// console.log(JSON.stringify(ret.content));
// console.log(JSON.stringify(api.getPrefs({sync: true,key: 'userID'})));
if (result.code != 0) {
addAlert(result.msg)
return;
}
if (result.data.device.bind) {
checkExist = true //已绑定
}else {
checkExist = false //可绑定
}
if (!checkExist) {
api.sendEvent({
name: 'confirm_add_device',
extra: {type: result.data.device.type, imei: ret.content}
});
// api.openWin({
// slidBackEnabled:false,
// name: 'perfectInfo_win',
// url: './perfectInfo_win.html',
// pageParam: {
// "code": ret.content,
// "isEmpty": isEmpty
// }
// });
}else if (checkExist) {
api.alert({
title: '请重新扫描设备二维码',
msg: '当前设备已添加!',
}, function(ret, err) {
// openCanner(isEmpty);
});
}else {
api.alert({
title: '请扫描正确的设备二维码',
msg: '当前设备二维码不正确',
}, function(ret, err) {
// openCanner(isEmpty);
});
}
}else{
api.openFrame({
name: 'scannerView',
url: 'scannerView.html',
rect: {
x:0,
y:0,
w:'auto',
h: api.winHeight,
bounces: false,
bgColor: 'rgba(0,0,0,0)'
},
});
}
} else {
//alert(JSON.stringify(err));
}
});
}
</script>