isite 2022.9.15 → 2022.9.16
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/ui-print/site_files/js/index.js +186 -189
- package/package.json +1 -1
|
@@ -1,208 +1,205 @@
|
|
|
1
1
|
site.print = site.printHTML = function (options) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
options = options || {};
|
|
3
|
+
let content = '';
|
|
4
|
+
|
|
5
|
+
if (typeof options === 'string') {
|
|
6
|
+
options = {
|
|
7
|
+
selector: options,
|
|
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[href]').forEach((l) => {
|
|
16
|
+
content += '<link rel="stylesheet" href="' + site.handle_url(l.href) + '" type="text/css" >';
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
window.document.querySelectorAll('style').forEach((s) => {
|
|
20
|
+
content += s.outerHTML;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
if (options.links) {
|
|
24
|
+
options.links.forEach((link) => {
|
|
25
|
+
content += '<link rel="stylesheet" href="' + link + '" type="text/css" >';
|
|
26
|
+
});
|
|
9
27
|
}
|
|
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
|
-
});
|
|
19
|
-
|
|
20
|
-
window.document.querySelectorAll('style').forEach((s) => {
|
|
21
|
-
content += s.outerHTML;
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
if (options.links) {
|
|
25
|
-
options.links.forEach((link) => {
|
|
26
|
-
content += '<link rel="stylesheet" href="' + link + '" type="text/css" >';
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
});
|
|
29
|
+
if (options.preappends) {
|
|
30
|
+
options.preappends.forEach((el) => {
|
|
31
|
+
el = window.document.querySelector(el);
|
|
32
|
+
if (el) {
|
|
33
|
+
content += el.outerHTML;
|
|
37
34
|
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
38
|
+
document.querySelectorAll(options.selector).forEach((el) => {
|
|
39
|
+
let el2 = el.cloneNode(true);
|
|
40
|
+
el2.querySelectorAll('input').forEach((input) => {
|
|
41
|
+
input.setAttribute('value', input.value);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
el2.querySelectorAll('textarea').forEach((textarea) => {
|
|
45
|
+
textarea.innerText = textarea.value;
|
|
46
|
+
});
|
|
47
|
+
el2.style.display = 'block';
|
|
48
|
+
content += el2.outerHTML;
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
if (options.appends) {
|
|
52
|
+
options.appends.forEach((el) => {
|
|
53
|
+
el = window.document.querySelector(el);
|
|
54
|
+
if (el) {
|
|
55
|
+
content += el.outerHTML;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
} else {
|
|
60
|
+
options.type = 'content';
|
|
61
|
+
content = options.content;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (!options.ip) {
|
|
65
|
+
options.ip = '127.0.0.1';
|
|
66
|
+
}
|
|
67
|
+
if (!options.port) {
|
|
68
|
+
options.port = '60080';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
site.postData(
|
|
72
|
+
{ url: '/api/print', data: { content: content, type: options.type } },
|
|
73
|
+
(response) => {
|
|
74
|
+
if (response.done) {
|
|
75
|
+
if (options.printer) {
|
|
76
|
+
fetch(response.url, {
|
|
77
|
+
mode: 'cors',
|
|
78
|
+
method: 'get',
|
|
79
|
+
})
|
|
80
|
+
.then((res) => res.text())
|
|
81
|
+
.then((html) => {
|
|
82
|
+
options.html = html;
|
|
83
|
+
options.type = 'html';
|
|
84
|
+
site.postData(
|
|
85
|
+
{
|
|
86
|
+
url: `http://${options.ip}:${options.port}/print`,
|
|
87
|
+
data: options,
|
|
88
|
+
},
|
|
89
|
+
(res) => {
|
|
90
|
+
console.log(res);
|
|
91
|
+
},
|
|
92
|
+
(err) => {
|
|
93
|
+
console.log(err);
|
|
59
94
|
}
|
|
95
|
+
);
|
|
96
|
+
})
|
|
97
|
+
.catch((err) => {
|
|
98
|
+
console.error(err);
|
|
60
99
|
});
|
|
100
|
+
} else {
|
|
101
|
+
window.open(response.url);
|
|
61
102
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (!options.ip) {
|
|
68
|
-
options.ip = '127.0.0.1';
|
|
69
|
-
}
|
|
70
|
-
if (!options.port) {
|
|
71
|
-
options.port = '60080';
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
(error) => {
|
|
106
|
+
console.log(error);
|
|
72
107
|
}
|
|
108
|
+
);
|
|
73
109
|
|
|
74
|
-
|
|
75
|
-
{ url: '/api/print', data: { content: content, type: options.type } },
|
|
76
|
-
(response) => {
|
|
77
|
-
if (response.done) {
|
|
78
|
-
if (options.printer) {
|
|
79
|
-
fetch(response.url, {
|
|
80
|
-
mode: 'cors',
|
|
81
|
-
method: 'get',
|
|
82
|
-
})
|
|
83
|
-
.then((res) => res.text())
|
|
84
|
-
.then((html) => {
|
|
85
|
-
options.html = html;
|
|
86
|
-
options.type = 'html';
|
|
87
|
-
site.postData(
|
|
88
|
-
{
|
|
89
|
-
url: `http://${options.ip}:${options.port}/print`,
|
|
90
|
-
data: options,
|
|
91
|
-
},
|
|
92
|
-
(res) => {
|
|
93
|
-
console.log(res);
|
|
94
|
-
},
|
|
95
|
-
(err) => {
|
|
96
|
-
console.log(err);
|
|
97
|
-
},
|
|
98
|
-
);
|
|
99
|
-
})
|
|
100
|
-
.catch((err) => {
|
|
101
|
-
console.error(err);
|
|
102
|
-
});
|
|
103
|
-
} else {
|
|
104
|
-
window.open(response.url);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
(error) => {
|
|
109
|
-
console.log(error);
|
|
110
|
-
},
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
return !0;
|
|
110
|
+
return !0;
|
|
114
111
|
};
|
|
115
112
|
|
|
116
113
|
site.printAsImageBusy = false;
|
|
117
114
|
|
|
118
115
|
site.printAsImage = function (options, callback) {
|
|
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
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
116
|
+
if (site.printAsImageBusy) {
|
|
117
|
+
setTimeout(() => {
|
|
118
|
+
site.printAsImage(options, callback);
|
|
119
|
+
}, 1000);
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
site.printAsImageBusy = true;
|
|
124
|
+
options = options || {};
|
|
125
|
+
|
|
126
|
+
if (typeof options === 'string') {
|
|
127
|
+
options = {
|
|
128
|
+
selector: options,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
if (!options.selector) {
|
|
132
|
+
console.error('No Selector sets ...');
|
|
133
|
+
site.printAsImageBusy = false;
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
if (!options.ip) {
|
|
137
|
+
options.ip = '127.0.0.1';
|
|
138
|
+
}
|
|
139
|
+
if (!options.port) {
|
|
140
|
+
options.port = '60080';
|
|
141
|
+
}
|
|
142
|
+
if (!options.type) {
|
|
143
|
+
options.type = 'image';
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
let node = typeof options.selector === 'string' ? document.querySelector(options.selector) : options.selector;
|
|
147
|
+
if (!node) {
|
|
148
|
+
console.error('No Node Selector ');
|
|
149
|
+
site.printAsImageBusy = false;
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
domtoimage
|
|
154
|
+
.toPng(node, { quality: 1, bgcolor: '#ffffff' })
|
|
155
|
+
.then(function (dataUrl) {
|
|
156
|
+
var img = new Image();
|
|
157
|
+
img.src = dataUrl;
|
|
158
|
+
if (callback) {
|
|
159
|
+
callback(img);
|
|
160
|
+
}
|
|
161
|
+
options.content = dataUrl;
|
|
162
|
+
site.printDataUrl(options);
|
|
163
|
+
site.printAsImageBusy = false;
|
|
164
|
+
})
|
|
165
|
+
.catch(function (error) {
|
|
166
|
+
console.error(error);
|
|
167
|
+
site.printAsImageBusy = false;
|
|
168
|
+
});
|
|
172
169
|
};
|
|
173
170
|
|
|
174
171
|
site.printDataUrl = function (options) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
172
|
+
site.postData(
|
|
173
|
+
{ url: '/api/print', data: options },
|
|
174
|
+
(response) => {
|
|
175
|
+
if (response.done) {
|
|
176
|
+
if (options.printer) {
|
|
177
|
+
fetch(response.url, {
|
|
178
|
+
mode: 'cors',
|
|
179
|
+
method: 'get',
|
|
180
|
+
})
|
|
181
|
+
.then((res) => res.text())
|
|
182
|
+
.then((html) => {
|
|
183
|
+
options.html = html;
|
|
184
|
+
options.type = 'html';
|
|
185
|
+
site.postData(
|
|
186
|
+
{
|
|
187
|
+
url: `http://${options.ip}:${options.port}/print`,
|
|
188
|
+
data: options,
|
|
189
|
+
},
|
|
190
|
+
(res) => {}
|
|
191
|
+
);
|
|
192
|
+
})
|
|
193
|
+
.catch((err) => {
|
|
194
|
+
console.error(err);
|
|
195
|
+
});
|
|
196
|
+
} else {
|
|
197
|
+
window.open(response.url);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
(error) => {
|
|
202
|
+
console.log(error);
|
|
203
|
+
}
|
|
204
|
+
);
|
|
208
205
|
};
|