@lingxiteam/ebe-utils 0.0.38 → 0.0.39
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.
|
@@ -78,11 +78,14 @@ const historyFunc =
|
|
|
78
78
|
if (urlParamsStr) {
|
|
79
79
|
Object.assign(tmpQuery, Qs.parse(urlParamsStr));
|
|
80
80
|
}
|
|
81
|
-
history[type](
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
history[type](
|
|
82
|
+
{
|
|
83
|
+
pathname: mPathName,
|
|
84
|
+
search: Qs.stringify(tmpQuery),
|
|
85
|
+
state,
|
|
86
|
+
},
|
|
84
87
|
state,
|
|
85
|
-
|
|
88
|
+
);
|
|
86
89
|
}
|
|
87
90
|
};
|
|
88
91
|
const createUrl = (isPortal: boolean, params: HistoryReplaceProps) => {
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 打印工具类
|
|
3
|
+
* 针对 react 简单改造与优化 https://github.com/crabbly/Print.js html 模式下为非 iframe 模式打印,保证样式不丢失
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
function isHtmlElement(printable: any) {
|
|
7
|
+
// Check if element is instance of HTMLElement or has nodeType === 1 (for elements in iframe)
|
|
8
|
+
return (
|
|
9
|
+
typeof printable === 'object' &&
|
|
10
|
+
(printable instanceof HTMLElement || printable.nodeType === 1)
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const print = (options: { printable: any; type: string }) => {
|
|
15
|
+
let { printable } = options;
|
|
16
|
+
if (!printable) {
|
|
17
|
+
printable = 'root';
|
|
18
|
+
}
|
|
19
|
+
let printElement = (
|
|
20
|
+
isHtmlElement(printable)
|
|
21
|
+
? printable
|
|
22
|
+
: document.getElementsByClassName(printable)?.[0]
|
|
23
|
+
) as HTMLElement; // Check if the element exists
|
|
24
|
+
if (!printElement) {
|
|
25
|
+
window.console.error(
|
|
26
|
+
'Invalid HTML element id: '.concat(printable as string),
|
|
27
|
+
);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 原节点,避免cloneNode后canvas图像丢失
|
|
32
|
+
const originPrintElement = printElement;
|
|
33
|
+
|
|
34
|
+
printElement = printElement.cloneNode(true) as HTMLElement;
|
|
35
|
+
|
|
36
|
+
const copyCanvas = printElement.querySelectorAll('canvas');
|
|
37
|
+
const originCanvas = originPrintElement.querySelectorAll('canvas');
|
|
38
|
+
|
|
39
|
+
const getRealSize = (size: string) =>
|
|
40
|
+
Number((size || '0px').replace('px', ''));
|
|
41
|
+
|
|
42
|
+
for (let i = 0; i < copyCanvas.length; i += 1) {
|
|
43
|
+
const originCvs = originCanvas[i] as any;
|
|
44
|
+
const copyCvs = copyCanvas[i];
|
|
45
|
+
|
|
46
|
+
// canvas替换成img并插入节点
|
|
47
|
+
const imageUrl = originCvs.toDataURL();
|
|
48
|
+
const img = document.createElement('img');
|
|
49
|
+
img.src = imageUrl;
|
|
50
|
+
img.setAttribute('style', 'width: 100%');
|
|
51
|
+
|
|
52
|
+
const copyCvsParent = copyCvs.parentElement as HTMLElement;
|
|
53
|
+
// 图表最顶层父节点
|
|
54
|
+
const topCopyCvsParent = copyCvsParent.parentElement as HTMLElement;
|
|
55
|
+
if (topCopyCvsParent) {
|
|
56
|
+
topCopyCvsParent.insertBefore(img, copyCvsParent.nextElementSibling);
|
|
57
|
+
// 将px转换为百分比 避免打印被截取
|
|
58
|
+
if (topCopyCvsParent.style.width?.includes('px')) {
|
|
59
|
+
topCopyCvsParent.style.width = `${
|
|
60
|
+
(getRealSize(topCopyCvsParent.style.width) /
|
|
61
|
+
originPrintElement.clientWidth) *
|
|
62
|
+
100
|
|
63
|
+
}%`;
|
|
64
|
+
}
|
|
65
|
+
topCopyCvsParent.style.height = 'fit-content';
|
|
66
|
+
topCopyCvsParent.removeChild(copyCvsParent);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const styles = document.querySelectorAll('style');
|
|
71
|
+
const link = document.querySelectorAll('link');
|
|
72
|
+
const tempWin = window.open(
|
|
73
|
+
'',
|
|
74
|
+
'',
|
|
75
|
+
'top=-10,left=-10,toolbar=no,menubar=no,location=no,status=no',
|
|
76
|
+
); // 重新打开一个窗口,
|
|
77
|
+
try {
|
|
78
|
+
window.top?.moveTo(-10, -10);
|
|
79
|
+
window.top?.resizeTo(window.screen.availWidth, window.screen.availHeight);
|
|
80
|
+
} catch {
|
|
81
|
+
//
|
|
82
|
+
}
|
|
83
|
+
tempWin?.document.open('text/html');
|
|
84
|
+
for (let i = 0; i < styles.length; i += 1) {
|
|
85
|
+
tempWin?.document.write(styles[i].outerHTML);
|
|
86
|
+
}
|
|
87
|
+
for (let i = 0; i < link.length; i += 1) {
|
|
88
|
+
tempWin?.document.write(link[i].outerHTML);
|
|
89
|
+
}
|
|
90
|
+
const tableBody = printElement.querySelector(
|
|
91
|
+
'.pcfactory-table-body',
|
|
92
|
+
) as HTMLElement;
|
|
93
|
+
// 获取当前打印的表格节点,保存maxHeight,打印完成再设置回去
|
|
94
|
+
// let _maxHeight = '';
|
|
95
|
+
if (tableBody) {
|
|
96
|
+
// _maxHeight = tableBody.style.maxHeight;
|
|
97
|
+
tableBody.style.maxHeight = 'inherit';
|
|
98
|
+
}
|
|
99
|
+
tempWin?.document.write(printElement.outerHTML);
|
|
100
|
+
|
|
101
|
+
// 兼容表格行打印宽度
|
|
102
|
+
const tableHeaderColGroup = tempWin?.document.querySelector(
|
|
103
|
+
'.pcfactory-table-header table colgroup',
|
|
104
|
+
);
|
|
105
|
+
const tableBodyColGroup = tempWin?.document.querySelector(
|
|
106
|
+
'.pcfactory-table-body table colgroup',
|
|
107
|
+
);
|
|
108
|
+
const bodyTable = tempWin?.document.querySelector(
|
|
109
|
+
'.pcfactory-table-body table',
|
|
110
|
+
);
|
|
111
|
+
if (tableHeaderColGroup && tableBodyColGroup) {
|
|
112
|
+
const cloneTableHeaderColGroup = tableHeaderColGroup.cloneNode(true);
|
|
113
|
+
tableBodyColGroup.remove();
|
|
114
|
+
bodyTable?.appendChild(cloneTableHeaderColGroup);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const script = document.createElement('script');
|
|
118
|
+
script.type = 'text/javascript';
|
|
119
|
+
// 立即执行函数
|
|
120
|
+
script.innerHTML = `
|
|
121
|
+
(function() {
|
|
122
|
+
const linkTags = (document.querySelectorAll('link[rel="stylesheet"]'));
|
|
123
|
+
var number=linkTags.length
|
|
124
|
+
for (let i = 0; i < linkTags.length; i += 1) {
|
|
125
|
+
const mylink = linkTags[i];
|
|
126
|
+
mylink.onload = () => {
|
|
127
|
+
number--;
|
|
128
|
+
if(number==0){
|
|
129
|
+
window.focus();
|
|
130
|
+
window.print();
|
|
131
|
+
window.setTimeout(() => {
|
|
132
|
+
window.close();
|
|
133
|
+
}, 200); // 关闭窗口
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
)();
|
|
139
|
+
`;
|
|
140
|
+
tempWin?.document.head.appendChild(script);
|
|
141
|
+
tempWin?.document.close();
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export { print };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingxiteam/ebe-utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.39",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@babel/types": "^7.12.12",
|
|
20
20
|
"cac": "^6.7.14",
|
|
21
21
|
"fs-extra": "9.x",
|
|
22
|
-
"@lingxiteam/ebe": "0.0.
|
|
22
|
+
"@lingxiteam/ebe": "0.0.39"
|
|
23
23
|
},
|
|
24
24
|
"publishConfig": {
|
|
25
25
|
"access": "public"
|