-
Notifications
You must be signed in to change notification settings - Fork 310
Expand file tree
/
Copy pathproxy.html
More file actions
74 lines (72 loc) · 2.71 KB
/
proxy.html
File metadata and controls
74 lines (72 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!DOCTYPE html>
<html>
<head>
<title>通用设计器隐藏渲染</title>
<meta charset="utf-8" />
<meta rd="putatgml" />
<style>
html,
body {
margin: 0
}
</style>
</head>
<body>
<script src="dist/viewer.js?v=202603290806"></script>
<script type="module">
let { searchParams } = new URL(location.href);
let id = searchParams.get('pId');//从地址栏获取pId并返回回去,供父页面识别
let action = searchParams.get('action');
let { origin } = location;
let processed;
window.addEventListener('message', async e => {
if (processed) return;
let stage, hasException;
try {
stage = JSON.parse(e.data);
} catch {
stage = e.data;
hasException = true;
}
if (hasException || !stage) {
Promise.reject(JSON.stringify(stage));
parent.postMessage({ pId: id }, origin);
return;
}
let { page } = stage;
if (page.viewer == 'iot'||page.viewer=='board') {
alert('IoT和看板不支持打印和虚拟渲染');
parent.postMessage({ pId: id }, origin);
} else {
processed = true;
let latent = action != 'print';
await viewer.install({
version:'202603290806',
use: page.viewer,
latent,
request({url}){//请求发起前对参数等相关数据进行二次修改,便于适配现有接口。如没特殊需求,不要配置该方法
//console.log('request',request,url);
if (url.startsWith('//unpkg.') ||
url.startsWith('//at.') ||
url.startsWith('//cdn.') ||
url.startsWith('//cdnjs.')) {
return { //公共cdn不能发送任何凭证。如果自建资源服务器,则可以根据需要调整
options:{},
};
}
}
});
if (latent) {
let renderData = await viewer.getHTML({ stage });
parent.postMessage({ pId: id, renderData }, origin);
} else {
await viewer.print({ stage });
parent.postMessage({ pId: id }, origin);
}
}
});
//通知父页面当前页面就绪
parent.postMessage({ pId: id, action: 'ready' }, origin);
</script>
</body>
</html>