isite 2022.2.5 → 2022.3.3
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/apps/client-side/app.js +7 -0
- package/apps/client-side/site_files/js/site.js +35 -1
- package/apps/ui-print/app.js +34 -32
- package/apps/ui-print/site_files/html/content.html +22 -0
- package/apps/ui-print/site_files/html/index.html +0 -5
- package/apps/ui-print/site_files/js/index.js +57 -53
- package/package.json +1 -1
package/apps/client-side/app.js
CHANGED
|
@@ -191,4 +191,11 @@ module.exports = function (site) {
|
|
|
191
191
|
site.get({ name: '/api/file/:category/:name', public: true }, (req, res) => {
|
|
192
192
|
res.download(site.dir + '/../../uploads/' + req.params.category + '/files/' + req.params.name);
|
|
193
193
|
});
|
|
194
|
+
|
|
195
|
+
site.onPOST('/x-api/convert', (req, res) => {
|
|
196
|
+
res.json({
|
|
197
|
+
done: true,
|
|
198
|
+
value: Buffer.from(req.data.text, 'utf8').toString('hex'),
|
|
199
|
+
});
|
|
200
|
+
});
|
|
194
201
|
};
|
|
@@ -1103,12 +1103,46 @@
|
|
|
1103
1103
|
}
|
|
1104
1104
|
};
|
|
1105
1105
|
|
|
1106
|
+
site.hex = function (txt) {
|
|
1107
|
+
if (typeof txt == 'string') {
|
|
1108
|
+
const encoder = new TextEncoder();
|
|
1109
|
+
return Array.from(encoder.encode(txt))
|
|
1110
|
+
.map((b) => b.toString(16).padStart(2, '0'))
|
|
1111
|
+
.join('');
|
|
1112
|
+
} else if (typeof txt == 'number') {
|
|
1113
|
+
let value = txt.toString(16);
|
|
1114
|
+
if (value.length == 1) {
|
|
1115
|
+
value = '0' + value;
|
|
1116
|
+
}
|
|
1117
|
+
return value;
|
|
1118
|
+
}
|
|
1119
|
+
};
|
|
1120
|
+
site.zakat = function (obj) {
|
|
1121
|
+
let value = '';
|
|
1122
|
+
if (obj.name) {
|
|
1123
|
+
value += '01' + site.hex(obj.name.length) + site.hex(obj.name);
|
|
1124
|
+
}
|
|
1125
|
+
if (obj.vat_number) {
|
|
1126
|
+
value += '02' + site.hex(obj.vat_number.length) + site.hex(obj.vat_number);
|
|
1127
|
+
}
|
|
1128
|
+
if (obj.time) {
|
|
1129
|
+
value += '03' + site.hex(obj.time.length) + site.hex(obj.time);
|
|
1130
|
+
}
|
|
1131
|
+
if (obj.total) {
|
|
1132
|
+
value += '04' + site.hex(obj.total.length) + site.hex(obj.total);
|
|
1133
|
+
}
|
|
1134
|
+
if (obj.vat_total) {
|
|
1135
|
+
value += '05' + site.hex(obj.vat_total.length) + site.hex(obj.vat_total);
|
|
1136
|
+
}
|
|
1137
|
+
return site.toBase64(value);
|
|
1138
|
+
};
|
|
1139
|
+
|
|
1106
1140
|
site.barcode = function (options) {
|
|
1107
1141
|
if (!options || !options.selector || !options.text) {
|
|
1108
1142
|
console.error('qrcode need {selector , text}');
|
|
1109
1143
|
return;
|
|
1110
1144
|
}
|
|
1111
|
-
return JsBarcode(options.selector, options.selector);
|
|
1145
|
+
return JsBarcode(options.selector, options.selector, options.options);
|
|
1112
1146
|
};
|
|
1113
1147
|
site.qrcode = function (options) {
|
|
1114
1148
|
if (!options || !options.selector || !options.text) {
|
package/apps/ui-print/app.js
CHANGED
|
@@ -1,40 +1,42 @@
|
|
|
1
1
|
module.exports = function (site) {
|
|
2
|
-
|
|
2
|
+
site.printList = [];
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
site.post('/api/print', (req, res) => {
|
|
5
|
+
let id = new Date().getTime();
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
site.printList.push({
|
|
8
|
+
id: id,
|
|
9
|
+
content: req.data.content,
|
|
10
|
+
type: req.data.type ?? 'html',
|
|
11
|
+
});
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
res.json({
|
|
14
|
+
done: !0,
|
|
15
|
+
url: '/view/print/' + id,
|
|
16
|
+
});
|
|
16
17
|
});
|
|
17
|
-
});
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
site.get('/view/print/:id', (req, res) => {
|
|
20
|
+
let content = '';
|
|
21
|
+
let type = 'html';
|
|
22
|
+
site.printList.forEach((item) => {
|
|
23
|
+
if (item.id.toString() == req.params.id) {
|
|
24
|
+
content = item.content;
|
|
25
|
+
type = item.type ?? 'html';
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
let html = '';
|
|
30
|
+
if (type == 'image') {
|
|
31
|
+
html = site.readFileSync(__dirname + '/site_files/html/image.html');
|
|
32
|
+
} else if (type == 'svg') {
|
|
33
|
+
html = site.readFileSync(__dirname + '/site_files/html/svg.html');
|
|
34
|
+
} else if (type == 'content') {
|
|
35
|
+
html = site.readFileSync(__dirname + '/site_files/html/content.html');
|
|
36
|
+
} else {
|
|
37
|
+
html = site.readFileSync(__dirname + '/site_files/html/index.html');
|
|
38
|
+
}
|
|
39
|
+
html = html.replace('##data.content##', content);
|
|
40
|
+
res.htmlContent(html);
|
|
41
|
+
});
|
|
40
42
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
|
7
|
+
<title>content Print</title>
|
|
8
|
+
</head>
|
|
9
|
+
|
|
10
|
+
<body>
|
|
11
|
+
##data.content##
|
|
12
|
+
|
|
13
|
+
<script>
|
|
14
|
+
document.querySelectorAll('.not-print').forEach((el) => {
|
|
15
|
+
el.remove();
|
|
16
|
+
});
|
|
17
|
+
window.addEventListener('load', () => {
|
|
18
|
+
window.print({});
|
|
19
|
+
});
|
|
20
|
+
</script>
|
|
21
|
+
</body>
|
|
22
|
+
</html>
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
<body class="print-mode">
|
|
11
11
|
##data.content##
|
|
12
12
|
|
|
13
|
-
<style></style>
|
|
14
13
|
<script>
|
|
15
14
|
document.querySelectorAll('.not-print').forEach((el) => {
|
|
16
15
|
el.remove();
|
|
@@ -18,10 +17,6 @@
|
|
|
18
17
|
window.addEventListener('load', () => {
|
|
19
18
|
window.print({});
|
|
20
19
|
});
|
|
21
|
-
/*
|
|
22
|
-
Repeat table headers in every page if table too large
|
|
23
|
-
use thead & tbody
|
|
24
|
-
*/
|
|
25
20
|
</script>
|
|
26
21
|
</body>
|
|
27
22
|
</html>
|
|
@@ -1,74 +1,78 @@
|
|
|
1
1
|
site.print = site.printHTML = function (options) {
|
|
2
2
|
options = options || {};
|
|
3
|
+
let content = '';
|
|
3
4
|
|
|
4
5
|
if (typeof options === 'string') {
|
|
5
6
|
options = {
|
|
6
7
|
selector: options,
|
|
7
8
|
};
|
|
8
9
|
}
|
|
10
|
+
if (!options.content) {
|
|
11
|
+
if (!options.selector) {
|
|
12
|
+
console.error('No Selector sets ...');
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
window.document.querySelectorAll('link[rel=stylesheet]').forEach((l) => {
|
|
16
|
+
l.href = site.handle_url(l.href);
|
|
17
|
+
content += l.outerHTML;
|
|
18
|
+
});
|
|
9
19
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
if (!options.ip) {
|
|
15
|
-
options.ip = '127.0.0.1';
|
|
16
|
-
}
|
|
17
|
-
if (!options.port) {
|
|
18
|
-
options.port = '60080';
|
|
19
|
-
}
|
|
20
|
+
window.document.querySelectorAll('style').forEach((s) => {
|
|
21
|
+
content += s.outerHTML;
|
|
22
|
+
});
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
if (options.links) {
|
|
25
|
+
options.links.forEach((link) => {
|
|
26
|
+
content += '<link rel="stylesheet" href="' + link + '" type="text/css" >';
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (options.preappends) {
|
|
31
|
+
options.preappends.forEach((el) => {
|
|
32
|
+
el = window.document.querySelector(el);
|
|
33
|
+
if (el) {
|
|
34
|
+
content += el.outerHTML;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
document.querySelectorAll(options.selector + ' input').forEach((el) => {
|
|
40
|
+
el.setAttribute('value', el.value);
|
|
34
41
|
});
|
|
35
|
-
}
|
|
36
42
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
el = window.document.querySelector(el);
|
|
40
|
-
if (el) {
|
|
41
|
-
content += el.outerHTML;
|
|
42
|
-
}
|
|
43
|
+
document.querySelectorAll(options.selector + ' textarea').forEach((el) => {
|
|
44
|
+
el.innerText = el.value;
|
|
43
45
|
});
|
|
44
|
-
}
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
el.innerText = el.value;
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
document.querySelectorAll(options.selector).forEach((el) => {
|
|
55
|
-
let display = el.style.display;
|
|
56
|
-
el.style.display = 'block';
|
|
57
|
-
content += el.outerHTML;
|
|
58
|
-
el.style.display = display;
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
if (options.appends) {
|
|
62
|
-
options.appends.forEach((el) => {
|
|
63
|
-
el = window.document.querySelector(el);
|
|
64
|
-
if (el) {
|
|
65
|
-
content += el.outerHTML;
|
|
66
|
-
}
|
|
47
|
+
document.querySelectorAll(options.selector).forEach((el) => {
|
|
48
|
+
let display = el.style.display;
|
|
49
|
+
el.style.display = 'block';
|
|
50
|
+
content += el.outerHTML;
|
|
51
|
+
el.style.display = display;
|
|
67
52
|
});
|
|
53
|
+
|
|
54
|
+
if (options.appends) {
|
|
55
|
+
options.appends.forEach((el) => {
|
|
56
|
+
el = window.document.querySelector(el);
|
|
57
|
+
if (el) {
|
|
58
|
+
content += el.outerHTML;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
options.type = 'content';
|
|
64
|
+
content = options.content;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (!options.ip) {
|
|
68
|
+
options.ip = '127.0.0.1';
|
|
69
|
+
}
|
|
70
|
+
if (!options.port) {
|
|
71
|
+
options.port = '60080';
|
|
68
72
|
}
|
|
69
73
|
|
|
70
74
|
site.postData(
|
|
71
|
-
{ url: '/api/print', data: { content: content } },
|
|
75
|
+
{ url: '/api/print', data: { content: content, type: options.type } },
|
|
72
76
|
(response) => {
|
|
73
77
|
if (response.done) {
|
|
74
78
|
if (options.printer) {
|