react_hsbc_teller 2.0.0 → 2.0.2-4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/hsbc.js +1 -1
- package/package.json +1 -1
- package/packages/api/api.js +137 -2
- package/packages/assets/img/icon_asr.png +0 -0
- package/packages/assets/img/icon_env.png +0 -0
- package/packages/assets/img/icon_fail.jpg +0 -0
- package/packages/assets/img/icon_paper.png +0 -0
- package/packages/assets/img/icon_success.jpg +0 -0
- package/packages/assets/mp3/networkweak.mp3 +0 -0
- package/packages/assets/mp3/pip_close.mp3 +0 -0
- package/packages/assets/mp3/record_error.mp3 +0 -0
- package/packages/demo/demo.js +39 -15
- package/packages/demo/pdf.js +16 -1
- package/packages/pages/foot/foot.jsx +23 -1
- package/packages/pages/foot/foot.less +1 -0
- package/packages/pages/video/video.jsx +1729 -641
- package/packages/pages/video/video.less +42 -2
- package/packages/utils/utils.js +114 -0
- package/packages/common/JKL.js +0 -61
- package/packages/common/XML.js +0 -271
- package/packages/common/websocket.js +0 -267
- package/packages/utils/cell.js +0 -64
|
@@ -276,6 +276,7 @@
|
|
|
276
276
|
font-size: 22px;
|
|
277
277
|
color: #222222;
|
|
278
278
|
font-weight: 600;
|
|
279
|
+
transform: translateX(-100px);
|
|
279
280
|
ul{
|
|
280
281
|
li{
|
|
281
282
|
list-style: none;
|
|
@@ -328,6 +329,27 @@
|
|
|
328
329
|
padding: 6px 13px;
|
|
329
330
|
}
|
|
330
331
|
}
|
|
332
|
+
.envClass {
|
|
333
|
+
margin-bottom: 0;
|
|
334
|
+
padding-left: 1.25rem;
|
|
335
|
+
}
|
|
336
|
+
.ant-collapse > .ant-collapse-item > .ant-collapse-header{
|
|
337
|
+
font-weight: bold;
|
|
338
|
+
}
|
|
339
|
+
.ant-collapse > .ant-collapse-item.panel-error > .ant-collapse-header{
|
|
340
|
+
color: #DA0110;
|
|
341
|
+
}
|
|
342
|
+
.ant-collapse-ghost > .ant-collapse-item > .ant-collapse-content > .ant-collapse-content-box{
|
|
343
|
+
padding-top: 0 !important;
|
|
344
|
+
}
|
|
345
|
+
.ant-collapse-header{
|
|
346
|
+
img{
|
|
347
|
+
width: 16px;
|
|
348
|
+
height: 16px;
|
|
349
|
+
margin-left: 10px;
|
|
350
|
+
margin-bottom: 1px;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
331
353
|
.voiceClass{
|
|
332
354
|
width: 25Px;
|
|
333
355
|
height: 25.3Px;
|
|
@@ -419,7 +441,7 @@
|
|
|
419
441
|
border-spacing: 20px!important;
|
|
420
442
|
}
|
|
421
443
|
.modelButtonFaceOkColorFile{
|
|
422
|
-
width: 170px!important;
|
|
444
|
+
min-width: 170px!important;
|
|
423
445
|
height: 40px!important;
|
|
424
446
|
font-size: 16px!important;
|
|
425
447
|
color: #5C5C5C!important;
|
|
@@ -622,4 +644,22 @@ display: inline-flex;
|
|
|
622
644
|
.imgDIV{
|
|
623
645
|
margin: 0 !important;
|
|
624
646
|
text-align:center;
|
|
625
|
-
}
|
|
647
|
+
}
|
|
648
|
+
.QRCode{
|
|
649
|
+
position: absolute;
|
|
650
|
+
right: -200px;
|
|
651
|
+
top: 30px;
|
|
652
|
+
display: flex;
|
|
653
|
+
flex-direction: column;
|
|
654
|
+
align-items: center;
|
|
655
|
+
.sessionDiv{
|
|
656
|
+
background: #DB0011;
|
|
657
|
+
border-radius: 20px;
|
|
658
|
+
padding: 0 15px;
|
|
659
|
+
text-align: center;
|
|
660
|
+
line-height: 40px;
|
|
661
|
+
height: 40px;
|
|
662
|
+
color: white;
|
|
663
|
+
margin-top: 20px;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
function compressImage(base64, callback) {
|
|
2
|
+
var targSize = 1024 * 1024 * 1.45 //1024KB
|
|
3
|
+
if (base64.length <= targSize) {
|
|
4
|
+
callback(base64);
|
|
5
|
+
// console.log("直接返回")
|
|
6
|
+
return
|
|
7
|
+
}
|
|
8
|
+
var newImage = new Image();
|
|
9
|
+
newImage.src = base64;
|
|
10
|
+
console.log('压缩前'+base64.length)
|
|
11
|
+
newImage.setAttribute("crossOrigin", 'Anonymous'); //url为外域时需要
|
|
12
|
+
newImage.onload = function () {
|
|
13
|
+
var quality = 0.95; //压缩系数0-1之间
|
|
14
|
+
var canvas = document.createElement("canvas");
|
|
15
|
+
var ctx = canvas.getContext("2d");
|
|
16
|
+
canvas.width = 720
|
|
17
|
+
canvas.height = 405
|
|
18
|
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
19
|
+
ctx.drawImage(newImage, 0, 0, canvas.width, canvas.height);
|
|
20
|
+
var base64 = canvas.toDataURL("image/png", quality); //压缩语句
|
|
21
|
+
// 如想确保图片压缩到自己想要的尺寸,如要求在5-10kb之间,请加以下语句,quality初始值根据情况自定
|
|
22
|
+
// console.log(base64.length + "循环1压缩" + (base64.length / 1024 > 512))
|
|
23
|
+
|
|
24
|
+
// while (base64.length > targSize) {
|
|
25
|
+
// quality -= 0.03;
|
|
26
|
+
// // console.log(base64.length + "循环压缩" + quality)
|
|
27
|
+
// base64 = canvas.toDataURL("image/png", quality);
|
|
28
|
+
// }
|
|
29
|
+
console.log('压缩后'+base64.length)
|
|
30
|
+
callback(base64); //必须通过回调函数返回,否则无法及时拿到该值
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function debounce(fn, delay = 500) {
|
|
34
|
+
// 是闭包中的
|
|
35
|
+
let timer
|
|
36
|
+
|
|
37
|
+
// input事件调用的函数,相当于obj调用函数 this指向Input
|
|
38
|
+
return function() {
|
|
39
|
+
// 这个if 判断不做也没关系,判断了(除第一次非空的情况)也就是执行从第二次开始,在延迟时间内多次触发才会走该判断
|
|
40
|
+
if(timer) {clearTimeout(timer)}
|
|
41
|
+
// 此时的箭头函数的this 和 arguments 都是从外部函数继承而来
|
|
42
|
+
// 如果用普通函数就要用词法作用域 var tshat = this var arg = arguments
|
|
43
|
+
timer = setTimeout(() =>{
|
|
44
|
+
// 使得传入的回调函数的this 指向Input这个元素对象
|
|
45
|
+
// arguments是该事件的详情,可以获得该函数被调用时的所有参数,是一个event 对象(所有Dom事件都会传event对象进入)
|
|
46
|
+
// 直接使用 fn() 问题也不大
|
|
47
|
+
fn.apply(this,arguments)
|
|
48
|
+
timer = null
|
|
49
|
+
},delay)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function isLight(src) {
|
|
53
|
+
let gray = new cv.Mat()
|
|
54
|
+
cv.cvtColor(src, gray, cv.COLOR_BGR2GRAY)
|
|
55
|
+
let sum = 0;
|
|
56
|
+
let avg = 0;
|
|
57
|
+
let scalar = new cv.Scalar()
|
|
58
|
+
let ls = new Array();
|
|
59
|
+
let size = gray.rows * gray.cols;
|
|
60
|
+
for (let i = 0; i < 256; i++)
|
|
61
|
+
ls[i] = 0;
|
|
62
|
+
|
|
63
|
+
for (let i = 0; i < gray.rows; i++)
|
|
64
|
+
{
|
|
65
|
+
for (let j = 0; j < gray.cols; j++)
|
|
66
|
+
{
|
|
67
|
+
scalar = gray.ucharPtr(i, j);
|
|
68
|
+
sum += (scalar[0] - 128);
|
|
69
|
+
let x = scalar[0];
|
|
70
|
+
ls[x]++;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
avg = sum / size;
|
|
74
|
+
let total = 0;
|
|
75
|
+
let mean = 0;
|
|
76
|
+
for (let i = 0; i < 256; i++)
|
|
77
|
+
{
|
|
78
|
+
total += Math.abs((i - 128) - avg) * ls[i];
|
|
79
|
+
}
|
|
80
|
+
mean = total / size;
|
|
81
|
+
let cast = Math.abs(avg / mean);
|
|
82
|
+
|
|
83
|
+
// 调用delete释放堆的内存
|
|
84
|
+
gray.delete();
|
|
85
|
+
|
|
86
|
+
console.log('亮度值:', cast)
|
|
87
|
+
//std::cout << "亮度异常值:" << cast << std::endl;
|
|
88
|
+
if (cast > 1)
|
|
89
|
+
{
|
|
90
|
+
if (avg > 0)
|
|
91
|
+
{
|
|
92
|
+
console.log('亮度异常 过亮:')
|
|
93
|
+
//std::cout << "亮度异常 过亮" << avg << std::endl;
|
|
94
|
+
return 1;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
console.log('亮度异常 过暗')
|
|
98
|
+
//std::cout << "亮度异常 过暗" << avg << std::endl;
|
|
99
|
+
return -1;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else
|
|
103
|
+
{
|
|
104
|
+
console.log('亮度正常')
|
|
105
|
+
//std::cout << "normal" << std::endl;
|
|
106
|
+
return 0;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
}
|
|
110
|
+
export {
|
|
111
|
+
compressImage,
|
|
112
|
+
debounce,
|
|
113
|
+
isLight
|
|
114
|
+
}
|
package/packages/common/JKL.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
const JKL = {};
|
|
2
|
-
|
|
3
|
-
JKL.Dumper = function () {
|
|
4
|
-
return this;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
// Dump the data into JSON format
|
|
8
|
-
|
|
9
|
-
JKL.Dumper.prototype.dump = function (data, offset) {
|
|
10
|
-
if (typeof (offset) === 'undefined') offset = '';
|
|
11
|
-
const nextoff = `${offset} `;
|
|
12
|
-
switch (typeof (data)) {
|
|
13
|
-
case 'string':
|
|
14
|
-
return `"${this.escapeString(data)}"`;
|
|
15
|
-
break;
|
|
16
|
-
case 'number':
|
|
17
|
-
return data;
|
|
18
|
-
break;
|
|
19
|
-
case 'boolean':
|
|
20
|
-
return data ? 'true' : 'false';
|
|
21
|
-
break;
|
|
22
|
-
case 'undefined':
|
|
23
|
-
return 'null';
|
|
24
|
-
break;
|
|
25
|
-
case 'object':
|
|
26
|
-
if (data == null) {
|
|
27
|
-
return 'null';
|
|
28
|
-
} if (data.constructor == Array) {
|
|
29
|
-
var array = [];
|
|
30
|
-
for (let i = 0; i < data.length; i++) {
|
|
31
|
-
array[i] = this.dump(data[i], nextoff);
|
|
32
|
-
}
|
|
33
|
-
return `[\n${nextoff}${array.join(`,\n${nextoff}`)}\n${offset}]`;
|
|
34
|
-
}
|
|
35
|
-
var array = [];
|
|
36
|
-
for (let key in data) {
|
|
37
|
-
const val = this.dump(data[key], nextoff);
|
|
38
|
-
// if ( key.match( /[^A-Za-z0-9_]/ )) {
|
|
39
|
-
key = `"${this.escapeString(key)}"`;
|
|
40
|
-
// }
|
|
41
|
-
array[array.length] = `${key}: ${val}`;
|
|
42
|
-
}
|
|
43
|
-
if (array.length == 1 && !array[0].match(/[\n\{\[]/)) {
|
|
44
|
-
return `{ ${array[0]} }`;
|
|
45
|
-
}
|
|
46
|
-
return `{\n${nextoff}${array.join(`,\n${nextoff}`)}\n${offset}}`;
|
|
47
|
-
|
|
48
|
-
break;
|
|
49
|
-
default:
|
|
50
|
-
return data;
|
|
51
|
-
// unsupported data type
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// escape '\' and '"'
|
|
57
|
-
|
|
58
|
-
JKL.Dumper.prototype.escapeString = function (str) {
|
|
59
|
-
return str.replace(/\\/g, '\\\\').replace(/\"/g, '\\"');
|
|
60
|
-
};
|
|
61
|
-
export default JKL;
|
package/packages/common/XML.js
DELETED
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-undef */
|
|
2
|
-
// ========================================================================
|
|
3
|
-
// XML.ObjTree -- XML source code from/to JavaScript object like E4X
|
|
4
|
-
// ========================================================================
|
|
5
|
-
|
|
6
|
-
import JKL from './JKL';
|
|
7
|
-
|
|
8
|
-
const XML = {};
|
|
9
|
-
|
|
10
|
-
XML.ObjTree = function () {
|
|
11
|
-
return this;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
// class variables
|
|
15
|
-
|
|
16
|
-
XML.ObjTree.VERSION = '0.23';
|
|
17
|
-
|
|
18
|
-
// object prototype
|
|
19
|
-
|
|
20
|
-
XML.ObjTree.prototype.xmlDecl = '<?xml version="1.0" encoding="UTF-8" ?>\n';
|
|
21
|
-
XML.ObjTree.prototype.attr_prefix = '-';
|
|
22
|
-
|
|
23
|
-
// method: parseXML( xmlsource )
|
|
24
|
-
|
|
25
|
-
XML.ObjTree.prototype.parseXML = function (xml) {
|
|
26
|
-
let xmldom;
|
|
27
|
-
let root;
|
|
28
|
-
if (window.DOMParser) {
|
|
29
|
-
xmldom = new DOMParser();
|
|
30
|
-
// xmldom.async = false; // DOMParser is always sync-mode
|
|
31
|
-
const dom = xmldom.parseFromString(xml, 'application/xml');
|
|
32
|
-
if (!dom) return;
|
|
33
|
-
root = dom.documentElement;
|
|
34
|
-
} else if (window.ActiveXObject) {
|
|
35
|
-
xmldom = new ActiveXObject('Microsoft.XMLDOM');
|
|
36
|
-
xmldom.async = false;
|
|
37
|
-
xmldom.loadXML(xml);
|
|
38
|
-
root = xmldom.documentElement;
|
|
39
|
-
}
|
|
40
|
-
if (!root) return;
|
|
41
|
-
return this.parseDOM(root);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
// method: parseHTTP( url, options, callback )
|
|
45
|
-
|
|
46
|
-
XML.ObjTree.prototype.parseHTTP = function (url, options, callback) {
|
|
47
|
-
const myopt = {};
|
|
48
|
-
for (const key in options) {
|
|
49
|
-
myopt[key] = options[key]; // copy object
|
|
50
|
-
}
|
|
51
|
-
if (!myopt.method) {
|
|
52
|
-
if (typeof (myopt.postBody) === 'undefined'
|
|
53
|
-
&& typeof (myopt.postbody) === 'undefined'
|
|
54
|
-
&& typeof (myopt.parameters) === 'undefined') {
|
|
55
|
-
myopt.method = 'get';
|
|
56
|
-
} else {
|
|
57
|
-
myopt.method = 'post';
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (callback) {
|
|
61
|
-
myopt.asynchronous = true; // async-mode
|
|
62
|
-
const __this = this;
|
|
63
|
-
const __func = callback;
|
|
64
|
-
const __save = myopt.onComplete;
|
|
65
|
-
myopt.onComplete = function (trans) {
|
|
66
|
-
let tree;
|
|
67
|
-
if (trans && trans.responseXML && trans.responseXML.documentElement) {
|
|
68
|
-
tree = __this.parseDOM(trans.responseXML.documentElement);
|
|
69
|
-
}
|
|
70
|
-
__func(tree, trans);
|
|
71
|
-
if (__save) __save(trans);
|
|
72
|
-
};
|
|
73
|
-
} else {
|
|
74
|
-
myopt.asynchronous = false; // sync-mode
|
|
75
|
-
}
|
|
76
|
-
let trans;
|
|
77
|
-
if (typeof (HTTP) !== 'undefined' && HTTP.Request) {
|
|
78
|
-
myopt.uri = url;
|
|
79
|
-
var req = new HTTP.Request(myopt); // JSAN
|
|
80
|
-
if (req) trans = req.transport;
|
|
81
|
-
} else if (typeof (Ajax) !== 'undefined' && Ajax.Request) {
|
|
82
|
-
var req = new Ajax.Request(url, myopt); // ptorotype.js
|
|
83
|
-
if (req) trans = req.transport;
|
|
84
|
-
}
|
|
85
|
-
if (callback) return trans;
|
|
86
|
-
if (trans && trans.responseXML && trans.responseXML.documentElement) {
|
|
87
|
-
return this.parseDOM(trans.responseXML.documentElement);
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
// method: parseDOM( documentroot )
|
|
92
|
-
|
|
93
|
-
XML.ObjTree.prototype.parseDOM = function (root) {
|
|
94
|
-
if (!root) return;
|
|
95
|
-
|
|
96
|
-
this.__force_array = {};
|
|
97
|
-
if (this.force_array) {
|
|
98
|
-
for (let i = 0; i < this.force_array.length; i++) {
|
|
99
|
-
this.__force_array[this.force_array[i]] = 1;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
let json = this.parseElement(root); // parse root node
|
|
104
|
-
if (this.__force_array[root.nodeName]) {
|
|
105
|
-
json = [json];
|
|
106
|
-
}
|
|
107
|
-
if (root.nodeType != 11) { // DOCUMENT_FRAGMENT_NODE
|
|
108
|
-
const tmp = {};
|
|
109
|
-
tmp[root.nodeName] = json; // root nodeName
|
|
110
|
-
json = tmp;
|
|
111
|
-
}
|
|
112
|
-
return json;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
// method: parseElement( element )
|
|
116
|
-
|
|
117
|
-
XML.ObjTree.prototype.parseElement = function (elem) {
|
|
118
|
-
// COMMENT_NODE
|
|
119
|
-
if (elem.nodeType == 7) {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// TEXT_NODE CDATA_SECTION_NODE
|
|
124
|
-
if (elem.nodeType == 3 || elem.nodeType == 4) {
|
|
125
|
-
const bool = elem.nodeValue.match(/[^\x00-\x20]/);
|
|
126
|
-
if (bool == null) return; // ignore white spaces
|
|
127
|
-
return elem.nodeValue;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
let retval;
|
|
131
|
-
const cnt = {};
|
|
132
|
-
|
|
133
|
-
// parse attributes
|
|
134
|
-
if (elem.attributes && elem.attributes.length) {
|
|
135
|
-
retval = {};
|
|
136
|
-
for (var i = 0; i < elem.attributes.length; i++) {
|
|
137
|
-
var key = elem.attributes[i].nodeName;
|
|
138
|
-
if (typeof (key) !== 'string') continue;
|
|
139
|
-
var val = elem.attributes[i].nodeValue;
|
|
140
|
-
if (!val) continue;
|
|
141
|
-
key = this.attr_prefix + key;
|
|
142
|
-
if (typeof (cnt[key]) === 'undefined') cnt[key] = 0;
|
|
143
|
-
cnt[key]++;
|
|
144
|
-
this.addNode(retval, key, cnt[key], val);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// parse child nodes (recursive)
|
|
149
|
-
if (elem.childNodes && elem.childNodes.length) {
|
|
150
|
-
let textonly = true;
|
|
151
|
-
if (retval) textonly = false; // some attributes exists
|
|
152
|
-
for (var i = 0; i < elem.childNodes.length && textonly; i++) {
|
|
153
|
-
const ntype = elem.childNodes[i].nodeType;
|
|
154
|
-
if (ntype == 3 || ntype == 4) continue;
|
|
155
|
-
textonly = false;
|
|
156
|
-
}
|
|
157
|
-
if (textonly) {
|
|
158
|
-
if (!retval) retval = '';
|
|
159
|
-
for (var i = 0; i < elem.childNodes.length; i++) {
|
|
160
|
-
retval += elem.childNodes[i].nodeValue;
|
|
161
|
-
}
|
|
162
|
-
} else {
|
|
163
|
-
if (!retval) retval = {};
|
|
164
|
-
for (var i = 0; i < elem.childNodes.length; i++) {
|
|
165
|
-
var key = elem.childNodes[i].nodeName;
|
|
166
|
-
if (typeof (key) !== 'string') continue;
|
|
167
|
-
var val = this.parseElement(elem.childNodes[i]);
|
|
168
|
-
if (!val) continue;
|
|
169
|
-
if (typeof (cnt[key]) === 'undefined') cnt[key] = 0;
|
|
170
|
-
cnt[key]++;
|
|
171
|
-
this.addNode(retval, key, cnt[key], val);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
return retval;
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
// method: addNode( hash, key, count, value )
|
|
179
|
-
|
|
180
|
-
XML.ObjTree.prototype.addNode = function (hash, key, cnts, val) {
|
|
181
|
-
if (this.__force_array[key]) {
|
|
182
|
-
if (cnts == 1) hash[key] = [];
|
|
183
|
-
hash[key][hash[key].length] = val; // push
|
|
184
|
-
} else if (cnts == 1) { // 1st sibling
|
|
185
|
-
hash[key] = val;
|
|
186
|
-
} else if (cnts == 2) { // 2nd sibling
|
|
187
|
-
hash[key] = [hash[key], val];
|
|
188
|
-
} else { // 3rd sibling and more
|
|
189
|
-
hash[key][hash[key].length] = val;
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
// method: writeXML( tree )
|
|
194
|
-
|
|
195
|
-
XML.ObjTree.prototype.writeXML = function (tree) {
|
|
196
|
-
const xml = this.hash_to_xml(null, tree);
|
|
197
|
-
return this.xmlDecl + xml;
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
// method: hash_to_xml( tagName, tree )
|
|
201
|
-
|
|
202
|
-
XML.ObjTree.prototype.hash_to_xml = function (name, tree) {
|
|
203
|
-
const elem = [];
|
|
204
|
-
const attr = [];
|
|
205
|
-
for (const key in tree) {
|
|
206
|
-
if (!tree.hasOwnProperty(key)) continue;
|
|
207
|
-
const val = tree[key];
|
|
208
|
-
if (key.charAt(0) != this.attr_prefix) {
|
|
209
|
-
if (typeof (val) === 'undefined' || val == null) {
|
|
210
|
-
elem[elem.length] = `<${key} />`;
|
|
211
|
-
} else if (typeof (val) === 'object' && val.constructor == Array) {
|
|
212
|
-
elem[elem.length] = this.array_to_xml(key, val);
|
|
213
|
-
} else if (typeof (val) === 'object') {
|
|
214
|
-
elem[elem.length] = this.hash_to_xml(key, val);
|
|
215
|
-
} else {
|
|
216
|
-
elem[elem.length] = this.scalar_to_xml(key, val);
|
|
217
|
-
}
|
|
218
|
-
} else {
|
|
219
|
-
attr[attr.length] = ` ${key.substring(1)}="${this.xml_escape(val)}"`;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
const jattr = attr.join('');
|
|
223
|
-
let jelem = elem.join('');
|
|
224
|
-
if (typeof (name) === 'undefined' || name == null) {
|
|
225
|
-
// no tag
|
|
226
|
-
} else if (elem.length > 0) {
|
|
227
|
-
if (jelem.match(/\n/)) {
|
|
228
|
-
jelem = `<${name}${jattr}>\n${jelem}</${name}>\n`;
|
|
229
|
-
} else {
|
|
230
|
-
jelem = `<${name}${jattr}>${jelem}</${name}>\n`;
|
|
231
|
-
}
|
|
232
|
-
} else {
|
|
233
|
-
jelem = `<${name}${jattr} />\n`;
|
|
234
|
-
}
|
|
235
|
-
return jelem;
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
// method: array_to_xml( tagName, array )
|
|
239
|
-
|
|
240
|
-
XML.ObjTree.prototype.array_to_xml = function (name, array) {
|
|
241
|
-
const out = [];
|
|
242
|
-
for (let i = 0; i < array.length; i++) {
|
|
243
|
-
const val = array[i];
|
|
244
|
-
if (typeof (val) === 'undefined' || val == null) {
|
|
245
|
-
out[out.length] = `<${name} />`;
|
|
246
|
-
} else if (typeof (val) === 'object' && val.constructor == Array) {
|
|
247
|
-
out[out.length] = this.array_to_xml(name, val);
|
|
248
|
-
} else if (typeof (val) === 'object') {
|
|
249
|
-
out[out.length] = this.hash_to_xml(name, val);
|
|
250
|
-
} else {
|
|
251
|
-
out[out.length] = this.scalar_to_xml(name, val);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
return out.join('');
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
// method: scalar_to_xml( tagName, text )
|
|
258
|
-
|
|
259
|
-
XML.ObjTree.prototype.scalar_to_xml = function (name, text) {
|
|
260
|
-
if (name == '#text') {
|
|
261
|
-
return this.xml_escape(text);
|
|
262
|
-
}
|
|
263
|
-
return `<${name}>${this.xml_escape(text)}</${name}>\n`;
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
// method: xml_escape( text )
|
|
267
|
-
|
|
268
|
-
XML.ObjTree.prototype.xml_escape = function (text) {
|
|
269
|
-
return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
270
|
-
};
|
|
271
|
-
export default XML;
|