ztxkutils 2.8.4 → 2.8.7
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/dist/authority-5bc06c1a.js +366 -0
- package/dist/authority.js +1 -1
- package/dist/fileOperation.js +5 -5
- package/dist/hooks/useHistory.d.ts +14 -0
- package/dist/index.js +2 -2
- package/dist/print.d.ts +7 -1
- package/dist/print.js +63 -24
- package/dist/request-09b081d4.js +2750 -0
- package/dist/request.js +2 -2
- package/dist/stompClient.js +1 -1
- package/dist/useHistory.js +94 -0
- package/package.json +4 -2
@@ -0,0 +1,366 @@
|
|
1
|
+
/**
|
2
|
+
* base64.ts
|
3
|
+
*
|
4
|
+
* Licensed under the BSD 3-Clause License.
|
5
|
+
* http://opensource.org/licenses/BSD-3-Clause
|
6
|
+
*
|
7
|
+
* References:
|
8
|
+
* http://en.wikipedia.org/wiki/Base64
|
9
|
+
*
|
10
|
+
* @author Dan Kogai (https://github.com/dankogai)
|
11
|
+
*/
|
12
|
+
const _hasatob = typeof atob === 'function';
|
13
|
+
const _hasbtoa = typeof btoa === 'function';
|
14
|
+
const _hasBuffer = typeof Buffer === 'function';
|
15
|
+
const _TD = typeof TextDecoder === 'function' ? new TextDecoder() : undefined;
|
16
|
+
const _TE = typeof TextEncoder === 'function' ? new TextEncoder() : undefined;
|
17
|
+
const b64ch = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
18
|
+
const b64chs = [...b64ch];
|
19
|
+
const b64tab = ((a) => {
|
20
|
+
let tab = {};
|
21
|
+
a.forEach((c, i) => tab[c] = i);
|
22
|
+
return tab;
|
23
|
+
})(b64chs);
|
24
|
+
const b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
|
25
|
+
const _fromCC = String.fromCharCode.bind(String);
|
26
|
+
const _U8Afrom = typeof Uint8Array.from === 'function'
|
27
|
+
? Uint8Array.from.bind(Uint8Array)
|
28
|
+
: (it, fn = (x) => x) => new Uint8Array(Array.prototype.slice.call(it, 0).map(fn));
|
29
|
+
const _mkUriSafe = (src) => src
|
30
|
+
.replace(/[+\/]/g, (m0) => m0 == '+' ? '-' : '_')
|
31
|
+
.replace(/=+$/m, '');
|
32
|
+
const _tidyB64 = (s) => s.replace(/[^A-Za-z0-9\+\/]/g, '');
|
33
|
+
/**
|
34
|
+
* polyfill version of `btoa`
|
35
|
+
*/
|
36
|
+
const btoaPolyfill = (bin) => {
|
37
|
+
// console.log('polyfilled');
|
38
|
+
let u32, c0, c1, c2, asc = '';
|
39
|
+
const pad = bin.length % 3;
|
40
|
+
for (let i = 0; i < bin.length;) {
|
41
|
+
if ((c0 = bin.charCodeAt(i++)) > 255 ||
|
42
|
+
(c1 = bin.charCodeAt(i++)) > 255 ||
|
43
|
+
(c2 = bin.charCodeAt(i++)) > 255)
|
44
|
+
throw new TypeError('invalid character found');
|
45
|
+
u32 = (c0 << 16) | (c1 << 8) | c2;
|
46
|
+
asc += b64chs[u32 >> 18 & 63]
|
47
|
+
+ b64chs[u32 >> 12 & 63]
|
48
|
+
+ b64chs[u32 >> 6 & 63]
|
49
|
+
+ b64chs[u32 & 63];
|
50
|
+
}
|
51
|
+
return pad ? asc.slice(0, pad - 3) + "===".substring(pad) : asc;
|
52
|
+
};
|
53
|
+
/**
|
54
|
+
* does what `window.btoa` of web browsers do.
|
55
|
+
* @param {String} bin binary string
|
56
|
+
* @returns {string} Base64-encoded string
|
57
|
+
*/
|
58
|
+
const _btoa = _hasbtoa ? (bin) => btoa(bin)
|
59
|
+
: _hasBuffer ? (bin) => Buffer.from(bin, 'binary').toString('base64')
|
60
|
+
: btoaPolyfill;
|
61
|
+
const _fromUint8Array = _hasBuffer
|
62
|
+
? (u8a) => Buffer.from(u8a).toString('base64')
|
63
|
+
: (u8a) => {
|
64
|
+
// cf. https://stackoverflow.com/questions/12710001/how-to-convert-uint8-array-to-base64-encoded-string/12713326#12713326
|
65
|
+
const maxargs = 0x1000;
|
66
|
+
let strs = [];
|
67
|
+
for (let i = 0, l = u8a.length; i < l; i += maxargs) {
|
68
|
+
strs.push(_fromCC.apply(null, u8a.subarray(i, i + maxargs)));
|
69
|
+
}
|
70
|
+
return _btoa(strs.join(''));
|
71
|
+
};
|
72
|
+
// This trick is found broken https://github.com/dankogai/js-base64/issues/130
|
73
|
+
// const utob = (src: string) => unescape(encodeURIComponent(src));
|
74
|
+
// reverting good old fationed regexp
|
75
|
+
const cb_utob = (c) => {
|
76
|
+
if (c.length < 2) {
|
77
|
+
var cc = c.charCodeAt(0);
|
78
|
+
return cc < 0x80 ? c
|
79
|
+
: cc < 0x800 ? (_fromCC(0xc0 | (cc >>> 6))
|
80
|
+
+ _fromCC(0x80 | (cc & 0x3f)))
|
81
|
+
: (_fromCC(0xe0 | ((cc >>> 12) & 0x0f))
|
82
|
+
+ _fromCC(0x80 | ((cc >>> 6) & 0x3f))
|
83
|
+
+ _fromCC(0x80 | (cc & 0x3f)));
|
84
|
+
}
|
85
|
+
else {
|
86
|
+
var cc = 0x10000
|
87
|
+
+ (c.charCodeAt(0) - 0xD800) * 0x400
|
88
|
+
+ (c.charCodeAt(1) - 0xDC00);
|
89
|
+
return (_fromCC(0xf0 | ((cc >>> 18) & 0x07))
|
90
|
+
+ _fromCC(0x80 | ((cc >>> 12) & 0x3f))
|
91
|
+
+ _fromCC(0x80 | ((cc >>> 6) & 0x3f))
|
92
|
+
+ _fromCC(0x80 | (cc & 0x3f)));
|
93
|
+
}
|
94
|
+
};
|
95
|
+
const re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
|
96
|
+
/**
|
97
|
+
* @deprecated should have been internal use only.
|
98
|
+
* @param {string} src UTF-8 string
|
99
|
+
* @returns {string} UTF-16 string
|
100
|
+
*/
|
101
|
+
const utob = (u) => u.replace(re_utob, cb_utob);
|
102
|
+
//
|
103
|
+
const _encode = _hasBuffer
|
104
|
+
? (s) => Buffer.from(s, 'utf8').toString('base64')
|
105
|
+
: _TE
|
106
|
+
? (s) => _fromUint8Array(_TE.encode(s))
|
107
|
+
: (s) => _btoa(utob(s));
|
108
|
+
/**
|
109
|
+
* converts a UTF-8-encoded string to a Base64 string.
|
110
|
+
* @param {boolean} [urlsafe] if `true` make the result URL-safe
|
111
|
+
* @returns {string} Base64 string
|
112
|
+
*/
|
113
|
+
const encode = (src, urlsafe = false) => urlsafe
|
114
|
+
? _mkUriSafe(_encode(src))
|
115
|
+
: _encode(src);
|
116
|
+
// This trick is found broken https://github.com/dankogai/js-base64/issues/130
|
117
|
+
// const btou = (src: string) => decodeURIComponent(escape(src));
|
118
|
+
// reverting good old fationed regexp
|
119
|
+
const re_btou = /[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g;
|
120
|
+
const cb_btou = (cccc) => {
|
121
|
+
switch (cccc.length) {
|
122
|
+
case 4:
|
123
|
+
var cp = ((0x07 & cccc.charCodeAt(0)) << 18)
|
124
|
+
| ((0x3f & cccc.charCodeAt(1)) << 12)
|
125
|
+
| ((0x3f & cccc.charCodeAt(2)) << 6)
|
126
|
+
| (0x3f & cccc.charCodeAt(3)), offset = cp - 0x10000;
|
127
|
+
return (_fromCC((offset >>> 10) + 0xD800)
|
128
|
+
+ _fromCC((offset & 0x3FF) + 0xDC00));
|
129
|
+
case 3:
|
130
|
+
return _fromCC(((0x0f & cccc.charCodeAt(0)) << 12)
|
131
|
+
| ((0x3f & cccc.charCodeAt(1)) << 6)
|
132
|
+
| (0x3f & cccc.charCodeAt(2)));
|
133
|
+
default:
|
134
|
+
return _fromCC(((0x1f & cccc.charCodeAt(0)) << 6)
|
135
|
+
| (0x3f & cccc.charCodeAt(1)));
|
136
|
+
}
|
137
|
+
};
|
138
|
+
/**
|
139
|
+
* @deprecated should have been internal use only.
|
140
|
+
* @param {string} src UTF-16 string
|
141
|
+
* @returns {string} UTF-8 string
|
142
|
+
*/
|
143
|
+
const btou = (b) => b.replace(re_btou, cb_btou);
|
144
|
+
/**
|
145
|
+
* polyfill version of `atob`
|
146
|
+
*/
|
147
|
+
const atobPolyfill = (asc) => {
|
148
|
+
// console.log('polyfilled');
|
149
|
+
asc = asc.replace(/\s+/g, '');
|
150
|
+
if (!b64re.test(asc))
|
151
|
+
throw new TypeError('malformed base64.');
|
152
|
+
asc += '=='.slice(2 - (asc.length & 3));
|
153
|
+
let u24, bin = '', r1, r2;
|
154
|
+
for (let i = 0; i < asc.length;) {
|
155
|
+
u24 = b64tab[asc.charAt(i++)] << 18
|
156
|
+
| b64tab[asc.charAt(i++)] << 12
|
157
|
+
| (r1 = b64tab[asc.charAt(i++)]) << 6
|
158
|
+
| (r2 = b64tab[asc.charAt(i++)]);
|
159
|
+
bin += r1 === 64 ? _fromCC(u24 >> 16 & 255)
|
160
|
+
: r2 === 64 ? _fromCC(u24 >> 16 & 255, u24 >> 8 & 255)
|
161
|
+
: _fromCC(u24 >> 16 & 255, u24 >> 8 & 255, u24 & 255);
|
162
|
+
}
|
163
|
+
return bin;
|
164
|
+
};
|
165
|
+
/**
|
166
|
+
* does what `window.atob` of web browsers do.
|
167
|
+
* @param {String} asc Base64-encoded string
|
168
|
+
* @returns {string} binary string
|
169
|
+
*/
|
170
|
+
const _atob = _hasatob ? (asc) => atob(_tidyB64(asc))
|
171
|
+
: _hasBuffer ? (asc) => Buffer.from(asc, 'base64').toString('binary')
|
172
|
+
: atobPolyfill;
|
173
|
+
//
|
174
|
+
const _toUint8Array = _hasBuffer
|
175
|
+
? (a) => _U8Afrom(Buffer.from(a, 'base64'))
|
176
|
+
: (a) => _U8Afrom(_atob(a), c => c.charCodeAt(0));
|
177
|
+
//
|
178
|
+
const _decode = _hasBuffer
|
179
|
+
? (a) => Buffer.from(a, 'base64').toString('utf8')
|
180
|
+
: _TD
|
181
|
+
? (a) => _TD.decode(_toUint8Array(a))
|
182
|
+
: (a) => btou(_atob(a));
|
183
|
+
const _unURI = (a) => _tidyB64(a.replace(/[-_]/g, (m0) => m0 == '-' ? '+' : '/'));
|
184
|
+
/**
|
185
|
+
* converts a Base64 string to a UTF-8 string.
|
186
|
+
* @param {String} src Base64 string. Both normal and URL-safe are supported
|
187
|
+
* @returns {string} UTF-8 string
|
188
|
+
*/
|
189
|
+
const decode = (src) => _decode(_unURI(src));
|
190
|
+
|
191
|
+
/**
|
192
|
+
* @description 权限相关操作
|
193
|
+
*/
|
194
|
+
// 获取token
|
195
|
+
var getToken = function () {
|
196
|
+
try {
|
197
|
+
if (window.localStorage.getItem('system-token')) {
|
198
|
+
return window.localStorage.getItem('system-token');
|
199
|
+
}
|
200
|
+
else {
|
201
|
+
return false;
|
202
|
+
}
|
203
|
+
}
|
204
|
+
catch (err) {
|
205
|
+
return false;
|
206
|
+
}
|
207
|
+
};
|
208
|
+
// 获取refreshToken
|
209
|
+
var getRefreshToken = function () {
|
210
|
+
try {
|
211
|
+
if (window.localStorage.getItem('system-refresh-token')) {
|
212
|
+
return window.localStorage.getItem('system-refresh-token');
|
213
|
+
}
|
214
|
+
else {
|
215
|
+
return false;
|
216
|
+
}
|
217
|
+
}
|
218
|
+
catch (err) {
|
219
|
+
return false;
|
220
|
+
}
|
221
|
+
};
|
222
|
+
// 获取是否第三方登录
|
223
|
+
var getOAuth2 = function () {
|
224
|
+
try {
|
225
|
+
if (window.localStorage.getItem('system-oauth2')) {
|
226
|
+
return window.localStorage.getItem('system-oauth2');
|
227
|
+
}
|
228
|
+
else {
|
229
|
+
return false;
|
230
|
+
}
|
231
|
+
}
|
232
|
+
catch (err) {
|
233
|
+
return false;
|
234
|
+
}
|
235
|
+
};
|
236
|
+
// 设置token
|
237
|
+
var setToken = function (token) {
|
238
|
+
try {
|
239
|
+
window.localStorage.setItem('system-token', token);
|
240
|
+
}
|
241
|
+
catch (err) {
|
242
|
+
return false;
|
243
|
+
}
|
244
|
+
};
|
245
|
+
var removeToken = function () {
|
246
|
+
try {
|
247
|
+
window.localStorage.removeItem('system-token');
|
248
|
+
}
|
249
|
+
catch (err) {
|
250
|
+
return false;
|
251
|
+
}
|
252
|
+
};
|
253
|
+
// 设置refreshToken
|
254
|
+
var setRefreshToken = function (token) {
|
255
|
+
try {
|
256
|
+
window.localStorage.setItem('system-refresh-token', token);
|
257
|
+
}
|
258
|
+
catch (err) {
|
259
|
+
return false;
|
260
|
+
}
|
261
|
+
};
|
262
|
+
var removeRefreshToken = function () {
|
263
|
+
try {
|
264
|
+
window.localStorage.removeItem('system-refresh-token');
|
265
|
+
}
|
266
|
+
catch (err) {
|
267
|
+
return false;
|
268
|
+
}
|
269
|
+
};
|
270
|
+
// 设置第三方登录
|
271
|
+
var setOAuth2 = function () {
|
272
|
+
try {
|
273
|
+
window.localStorage.setItem('system-oauth2', '1');
|
274
|
+
}
|
275
|
+
catch (err) {
|
276
|
+
return false;
|
277
|
+
}
|
278
|
+
};
|
279
|
+
var removeOAuth2 = function () {
|
280
|
+
try {
|
281
|
+
window.localStorage.removeItem('system-oauth2');
|
282
|
+
}
|
283
|
+
catch (err) {
|
284
|
+
return false;
|
285
|
+
}
|
286
|
+
};
|
287
|
+
// 对用户名密码进行加密/解密处理
|
288
|
+
var aesEncrypt = function (str) {
|
289
|
+
return encode(str);
|
290
|
+
};
|
291
|
+
var aesDecrypt = function (str) {
|
292
|
+
if (str) {
|
293
|
+
return decode(str);
|
294
|
+
}
|
295
|
+
else {
|
296
|
+
return str;
|
297
|
+
}
|
298
|
+
};
|
299
|
+
/**按钮权限级别 */
|
300
|
+
var BTN_AUTHS = {
|
301
|
+
add: 'add',
|
302
|
+
update: 'update',
|
303
|
+
check: 'check',
|
304
|
+
detail: 'detail',
|
305
|
+
unfreeze: 'unfreeze',
|
306
|
+
frozen: 'frozen',
|
307
|
+
cancelLation: 'cancelLation',
|
308
|
+
cancelSubmit: 'cancelSubmit',
|
309
|
+
submitApprove: 'submitApprove', // 提交审核
|
310
|
+
};
|
311
|
+
/**判断是否有当前按钮的权限 */
|
312
|
+
var isBtnAuth = function (userBtns, code) {
|
313
|
+
if (typeof code === 'boolean') {
|
314
|
+
return code;
|
315
|
+
}
|
316
|
+
if (!Array.isArray(userBtns)) {
|
317
|
+
return false;
|
318
|
+
}
|
319
|
+
return userBtns.some(function (userBtn) { return (userBtn === null || userBtn === void 0 ? void 0 : userBtn.code) === code; });
|
320
|
+
};
|
321
|
+
/**设置最后一次访问的路由 */
|
322
|
+
var setLastUrlPath = function (pathname) {
|
323
|
+
try {
|
324
|
+
window.localStorage.setItem('last-url-path', pathname);
|
325
|
+
}
|
326
|
+
catch (err) {
|
327
|
+
return false;
|
328
|
+
}
|
329
|
+
};
|
330
|
+
var getLastUrlPath = function () {
|
331
|
+
try {
|
332
|
+
if (window.localStorage.getItem('last-url-path')) {
|
333
|
+
return window.localStorage.getItem('last-url-path');
|
334
|
+
}
|
335
|
+
else {
|
336
|
+
return false;
|
337
|
+
}
|
338
|
+
}
|
339
|
+
catch (err) {
|
340
|
+
return false;
|
341
|
+
}
|
342
|
+
};
|
343
|
+
/**返回是否在乾坤下启动 */
|
344
|
+
var isQiankun = function () { return window.__POWERED_BY_QIANKUN__; };
|
345
|
+
|
346
|
+
var authority = /*#__PURE__*/Object.freeze({
|
347
|
+
__proto__: null,
|
348
|
+
getToken: getToken,
|
349
|
+
getRefreshToken: getRefreshToken,
|
350
|
+
getOAuth2: getOAuth2,
|
351
|
+
setToken: setToken,
|
352
|
+
removeToken: removeToken,
|
353
|
+
setRefreshToken: setRefreshToken,
|
354
|
+
removeRefreshToken: removeRefreshToken,
|
355
|
+
setOAuth2: setOAuth2,
|
356
|
+
removeOAuth2: removeOAuth2,
|
357
|
+
aesEncrypt: aesEncrypt,
|
358
|
+
aesDecrypt: aesDecrypt,
|
359
|
+
BTN_AUTHS: BTN_AUTHS,
|
360
|
+
isBtnAuth: isBtnAuth,
|
361
|
+
setLastUrlPath: setLastUrlPath,
|
362
|
+
getLastUrlPath: getLastUrlPath,
|
363
|
+
isQiankun: isQiankun
|
364
|
+
});
|
365
|
+
|
366
|
+
export { BTN_AUTHS as B, getRefreshToken as a, setRefreshToken as b, authority as c, getOAuth2 as d, removeRefreshToken as e, setOAuth2 as f, getToken as g, removeOAuth2 as h, isQiankun as i, aesEncrypt as j, aesDecrypt as k, isBtnAuth as l, setLastUrlPath as m, getLastUrlPath as n, removeToken as r, setToken as s };
|
package/dist/authority.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export { B as BTN_AUTHS,
|
1
|
+
export { B as BTN_AUTHS, k as aesDecrypt, j as aesEncrypt, n as getLastUrlPath, d as getOAuth2, a as getRefreshToken, g as getToken, l as isBtnAuth, i as isQiankun, h as removeOAuth2, e as removeRefreshToken, r as removeToken, m as setLastUrlPath, f as setOAuth2, b as setRefreshToken, s as setToken } from './authority-5bc06c1a.js';
|
package/dist/fileOperation.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { g as getToken } from './authority-
|
1
|
+
import { g as getToken } from './authority-5bc06c1a.js';
|
2
2
|
|
3
3
|
/**
|
4
4
|
* @author cyx
|
@@ -137,10 +137,10 @@ function previewFile(fileUrl, fileId, otherOption) {
|
|
137
137
|
? fileUrl.slice(0, fileUrl.length - 1)
|
138
138
|
: fileUrl;
|
139
139
|
if (titleName) {
|
140
|
-
window.open(_fileUrl + "/attchPreview?attachId=" + fileId + "&Zmdms-Auth=bearer " + token + "&titleName=" + encodeURIComponent(titleName));
|
140
|
+
window.open(_fileUrl + "/attchPreview?attachId=" + fileId + "&Zmdms-Auth=bearer " + token + "&titleName=" + encodeURIComponent(titleName) + "&officePreviewType=pdf");
|
141
141
|
}
|
142
142
|
else {
|
143
|
-
window.open(fileUrl + "/attchPreview?attachId=" + fileId + "&Zmdms-Auth=bearer " + token);
|
143
|
+
window.open(fileUrl + "/attchPreview?attachId=" + fileId + "&Zmdms-Auth=bearer " + token + "&officePreviewType=pdf");
|
144
144
|
}
|
145
145
|
}
|
146
146
|
/**
|
@@ -156,10 +156,10 @@ function createOriginalUrl(fileUrl, fileId, otherOption) {
|
|
156
156
|
? fileUrl.slice(0, fileUrl.length - 1)
|
157
157
|
: fileUrl;
|
158
158
|
if (titleName) {
|
159
|
-
return _fileUrl + "/attchPreview?attachId=" + fileId + "&Zmdms-Auth=bearer " + token + "&titleName=" + encodeURIComponent(titleName);
|
159
|
+
return _fileUrl + "/attchPreview?attachId=" + fileId + "&Zmdms-Auth=bearer " + token + "&titleName=" + encodeURIComponent(titleName) + "&officePreviewType=pdf";
|
160
160
|
}
|
161
161
|
else {
|
162
|
-
return _fileUrl + "/attchPreview?attachId=" + fileId + "&Zmdms-Auth=bearer " + token;
|
162
|
+
return _fileUrl + "/attchPreview?attachId=" + fileId + "&Zmdms-Auth=bearer " + token + "&officePreviewType=pdf";
|
163
163
|
}
|
164
164
|
}
|
165
165
|
/**
|
@@ -0,0 +1,14 @@
|
|
1
|
+
/**
|
2
|
+
* @author 陈亚雄
|
3
|
+
* @description 代理路由的push方法,可以用window.open的方式跳转页面
|
4
|
+
*/
|
5
|
+
export declare function useHistory(routeBasename?: string): any;
|
6
|
+
/**
|
7
|
+
* @author 陈亚雄
|
8
|
+
* @description 设置浏览器标题信息
|
9
|
+
*/
|
10
|
+
export declare function useDocumentTitle(title: string): void;
|
11
|
+
export declare function setFilterAuth(): void;
|
12
|
+
export declare function isFilterAuth(): boolean;
|
13
|
+
export declare function setSession(name: any, value: any): void;
|
14
|
+
export declare function getSession(name: any): any;
|
package/dist/index.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
export { c as authority } from './authority-
|
1
|
+
export { c as authority } from './authority-5bc06c1a.js';
|
2
2
|
export { d as dataModel } from './dataModel-1fbaff40.js';
|
3
3
|
export { t as tools } from './tools-4de9d743.js';
|
4
4
|
export { v as validate } from './validate-3e15dd74.js';
|
5
|
-
export { r as request } from './request-
|
5
|
+
export { r as request } from './request-09b081d4.js';
|
6
6
|
export { r as reqUrl } from './reqUrl-88fcc5c5.js';
|
7
7
|
import './tslib.es6-f9459658.js';
|
8
8
|
import 'dayjs';
|
package/dist/print.d.ts
CHANGED
@@ -39,7 +39,7 @@ export interface IPdfOption {
|
|
39
39
|
/** 上下边距 */
|
40
40
|
pageMarginY?: number;
|
41
41
|
}
|
42
|
-
export declare function htmlToPdfNoCanvas({ pageClassName, dom, isShowPage, fileBinary, pdfName, isDownload, pdfOption, }: {
|
42
|
+
export declare function htmlToPdfNoCanvas({ pageClassName, dom, isShowPage, fileBinary, pdfName, isDownload, pdfOption, isAddWater, waterBase64, imgWidth, imgHeight, }: {
|
43
43
|
pageClassName?: string;
|
44
44
|
dom: HTMLElement;
|
45
45
|
isShowPage?: boolean;
|
@@ -47,5 +47,11 @@ export declare function htmlToPdfNoCanvas({ pageClassName, dom, isShowPage, file
|
|
47
47
|
pdfName?: string;
|
48
48
|
isDownload?: boolean;
|
49
49
|
pdfOption?: IPdfOption;
|
50
|
+
/** 是否添加水印 */
|
51
|
+
isAddWater?: boolean;
|
52
|
+
/** 水印base 64字符串 */
|
53
|
+
waterBase64?: string;
|
54
|
+
imgWidth?: number;
|
55
|
+
imgHeight?: number;
|
50
56
|
}): Promise<unknown>;
|
51
57
|
export {};
|
package/dist/print.js
CHANGED
@@ -150,18 +150,18 @@ function htmlToPdf(_a) {
|
|
150
150
|
}
|
151
151
|
function htmlToPdfNoCanvas(_a) {
|
152
152
|
var _b, _c, _d;
|
153
|
-
var pageClassName = _a.pageClassName, dom = _a.dom, isShowPage = _a.isShowPage, fileBinary = _a.fileBinary, pdfName = _a.pdfName, isDownload = _a.isDownload, pdfOption = _a.pdfOption;
|
153
|
+
var pageClassName = _a.pageClassName, dom = _a.dom, isShowPage = _a.isShowPage, fileBinary = _a.fileBinary, pdfName = _a.pdfName, isDownload = _a.isDownload, pdfOption = _a.pdfOption, isAddWater = _a.isAddWater, waterBase64 = _a.waterBase64, imgWidth = _a.imgWidth, imgHeight = _a.imgHeight;
|
154
154
|
return __awaiter(this, void 0, void 0, function () {
|
155
155
|
var allDom, pageFormat, pageOrient, pageMarginX, pageMarginY, pdfOptions, allDomArray_1, pdfBase64_1, pdfs_1, pdf_1, pageWidth_1;
|
156
156
|
return __generator(this, function (_e) {
|
157
157
|
allDom = document.querySelectorAll(pageClassName ? pageClassName : '.html2canvas-container-page');
|
158
|
-
pageFormat = pdfOption.pageFormat ? pdfOption.pageFormat : 'a4';
|
159
|
-
pageOrient = pdfOption.pageOrient ? pdfOption.pageOrient : 'p';
|
160
|
-
pageMarginX = (_b = pdfOption.pageMarginX) !== null && _b !== void 0 ? _b : 10;
|
161
|
-
pageMarginY = (_c = pdfOption.pageMarginY) !== null && _c !== void 0 ? _c : 10;
|
158
|
+
pageFormat = (pdfOption === null || pdfOption === void 0 ? void 0 : pdfOption.pageFormat) ? pdfOption.pageFormat : 'a4';
|
159
|
+
pageOrient = (pdfOption === null || pdfOption === void 0 ? void 0 : pdfOption.pageOrient) ? pdfOption.pageOrient : 'p';
|
160
|
+
pageMarginX = (_b = pdfOption === null || pdfOption === void 0 ? void 0 : pdfOption.pageMarginX) !== null && _b !== void 0 ? _b : 10;
|
161
|
+
pageMarginY = (_c = pdfOption === null || pdfOption === void 0 ? void 0 : pdfOption.pageMarginY) !== null && _c !== void 0 ? _c : 10;
|
162
162
|
pdfOptions = {
|
163
163
|
// 是否压缩生成的PDF
|
164
|
-
compress: (_d = pdfOption.pageMarginY) !== null && _d !== void 0 ? _d : true,
|
164
|
+
compress: (_d = pdfOption === null || pdfOption === void 0 ? void 0 : pdfOption.pageMarginY) !== null && _d !== void 0 ? _d : true,
|
165
165
|
// 格式
|
166
166
|
format: pageFormat,
|
167
167
|
hotfixes: ['px_scaling'],
|
@@ -188,15 +188,8 @@ function htmlToPdfNoCanvas(_a) {
|
|
188
188
|
case 0:
|
189
189
|
pdf = new jsPDF(pdfOptions);
|
190
190
|
pageWidth = pdf.internal.pageSize.width - pageMarginX * 2;
|
191
|
-
|
192
|
-
|
193
|
-
}
|
194
|
-
catch (err) {
|
195
|
-
console.log(err);
|
196
|
-
}
|
197
|
-
pdf.addFileToVFS('microsoft-yahei.ttf', fileBinary === null || fileBinary === void 0 ? void 0 : fileBinary.data);
|
198
|
-
pdf.addFont('microsoft-yahei.ttf', 'microsoft-yahei', 'normal');
|
199
|
-
pdf.setFont('microsoft-yahei');
|
191
|
+
setPdfVersion(pdf);
|
192
|
+
supportJsPdfChinese(pdf, fileBinary);
|
200
193
|
return [4 /*yield*/, new Promise(function (resolve) {
|
201
194
|
new jsPDF(pdfOptions).html(item, {
|
202
195
|
autoPaging: 'text',
|
@@ -215,6 +208,13 @@ function htmlToPdfNoCanvas(_a) {
|
|
215
208
|
width: pageWidth,
|
216
209
|
windowWidth: pageWidth,
|
217
210
|
callback: function () {
|
211
|
+
for (var i = 1, j = res.internal.getNumberOfPages(); i <= j; i++) {
|
212
|
+
pdf.setPage(i);
|
213
|
+
// 添加水印
|
214
|
+
if (isAddWater) {
|
215
|
+
setPdfWater(pdf, waterBase64, imgWidth, imgHeight);
|
216
|
+
}
|
217
|
+
}
|
218
218
|
if (isDownload) {
|
219
219
|
pdf.save(pdfName + ".pdf");
|
220
220
|
}
|
@@ -256,15 +256,8 @@ function htmlToPdfNoCanvas(_a) {
|
|
256
256
|
else {
|
257
257
|
pdf_1 = new jsPDF(pdfOptions);
|
258
258
|
pageWidth_1 = pdf_1.internal.pageSize.width - pageMarginX * 2;
|
259
|
-
|
260
|
-
|
261
|
-
}
|
262
|
-
catch (err) {
|
263
|
-
console.log(err);
|
264
|
-
}
|
265
|
-
pdf_1.addFileToVFS('microsoft-yahei.ttf', fileBinary === null || fileBinary === void 0 ? void 0 : fileBinary.data);
|
266
|
-
pdf_1.addFont('microsoft-yahei.ttf', 'microsoft-yahei', 'normal');
|
267
|
-
pdf_1.setFont('microsoft-yahei');
|
259
|
+
setPdfVersion(pdf_1);
|
260
|
+
supportJsPdfChinese(pdf_1, fileBinary);
|
268
261
|
return [2 /*return*/, new Promise(function (resolve) {
|
269
262
|
new jsPDF(pdfOptions).html(dom, {
|
270
263
|
autoPaging: 'text',
|
@@ -283,6 +276,13 @@ function htmlToPdfNoCanvas(_a) {
|
|
283
276
|
width: pageWidth_1,
|
284
277
|
windowWidth: pageWidth_1,
|
285
278
|
callback: function () {
|
279
|
+
for (var i = 1, j = res.internal.getNumberOfPages(); i <= j; i++) {
|
280
|
+
pdf_1.setPage(i);
|
281
|
+
// 添加水印
|
282
|
+
if (isAddWater) {
|
283
|
+
setPdfWater(pdf_1, waterBase64, imgWidth, imgHeight);
|
284
|
+
}
|
285
|
+
}
|
286
286
|
if (isDownload) {
|
287
287
|
pdf_1.save(pdfName + ".pdf");
|
288
288
|
}
|
@@ -298,6 +298,45 @@ function htmlToPdfNoCanvas(_a) {
|
|
298
298
|
}
|
299
299
|
});
|
300
300
|
});
|
301
|
+
}
|
302
|
+
/**
|
303
|
+
* @author 陈亚雄
|
304
|
+
* @description 设置pdf版本号,契约锁需要1.7以上的pdf版本
|
305
|
+
* @param pdf pdf实例
|
306
|
+
*/
|
307
|
+
function setPdfVersion(pdf) {
|
308
|
+
try {
|
309
|
+
pdf.__private__.setPdfVersion('1.7');
|
310
|
+
}
|
311
|
+
catch (err) {
|
312
|
+
console.log(err);
|
313
|
+
}
|
314
|
+
}
|
315
|
+
/**
|
316
|
+
* @author 陈亚雄
|
317
|
+
* @description jspdf支持中文字符
|
318
|
+
* @param pdf pdf实例
|
319
|
+
* @param fileBinary 中文字符编码base64串
|
320
|
+
*/
|
321
|
+
function supportJsPdfChinese(pdf, fileBinary) {
|
322
|
+
pdf.addFileToVFS('microsoft-yahei.ttf', fileBinary === null || fileBinary === void 0 ? void 0 : fileBinary.data);
|
323
|
+
pdf.addFont('microsoft-yahei.ttf', 'microsoft-yahei', 'normal');
|
324
|
+
pdf.setFont('microsoft-yahei');
|
325
|
+
}
|
326
|
+
/**
|
327
|
+
* @author 陈亚雄
|
328
|
+
* @description 为pdf添加水印,每页添加6个水印
|
329
|
+
* @param pdf pdf实例
|
330
|
+
*/
|
331
|
+
function setPdfWater(pdf, waterBase64, imgWidth, imgHeight) {
|
332
|
+
if (waterBase64 && imgWidth && imgHeight) {
|
333
|
+
pdf.addImage(waterBase64, 'PNG', 20, 20, imgWidth, imgHeight, '1');
|
334
|
+
pdf.addImage(waterBase64, 'PNG', 20 + imgWidth, 20, imgWidth, imgHeight, '2');
|
335
|
+
pdf.addImage(waterBase64, 'PNG', 20, 20 + imgHeight, imgWidth, imgHeight, '3');
|
336
|
+
pdf.addImage(waterBase64, 'PNG', 20 + imgWidth, 20 + imgHeight, imgWidth, imgHeight, '4');
|
337
|
+
pdf.addImage(waterBase64, 'PNG', 20, 20 + imgHeight + imgHeight, imgWidth, imgHeight, '5');
|
338
|
+
pdf.addImage(waterBase64, 'PNG', 20 + imgWidth, 20 + imgHeight + imgHeight, imgWidth, imgHeight, '6');
|
339
|
+
}
|
301
340
|
}
|
302
341
|
|
303
342
|
export { addWaterHandle, htmlToPdf, htmlToPdfNoCanvas, printCurrentDom, removeWaterHandle };
|