Skip to content
This repository was archived by the owner on Sep 25, 2023. It is now read-only.

Commit b0b050f

Browse files
authored
Merge pull request #1 from panzhengxu/main
参赛作品提交
2 parents bbf0903 + 72fb0a8 commit b0b050f

File tree

143 files changed

+84880
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+84880
-0
lines changed

“基于WPS JS的加载项——XToolPlugin”-潘正煦/README.md

Lines changed: 370 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
http://127.0.0.1:3889/.debugTemp/systemdemo.html
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var projInfo = {"name":"XToolPlugin","type":"wps"}
Lines changed: 283 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,283 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<meta http-equiv="X-UA-Compatible" content="IE=edge chrome=1">
4+
5+
<head>
6+
<meta charset="utf-8">
7+
<meta http-equiv="X-UA-Compatible" content="IE=8">
8+
<title>业务系统模拟页面</title>
9+
<script type="text/javascript" src="./wpsjsrpcsdk.js"></script>
10+
<script type="text/javascript" src="./project.js"></script>
11+
</head>
12+
13+
<body>
14+
<div class="divTitle">XXX业务系统-前端模拟页面</div>
15+
<div>
16+
<div class="partItem">单进程模式:</div>
17+
<div class="divItem">
18+
<li><a href="#" onclick="openOfficeFile('http://我是文件的服务端地址')">打开业务系统文件</a></li>
19+
</div>
20+
<div class="divItem">
21+
<li><a href="#" onclick="onDivClick('getDocumentName', false)">获取wps当前打开的文件的文件名</a></li>
22+
</div>
23+
<div class="divItem">
24+
<li><a href="#" onclick="onDivClick('newDocument', true)">新建一个文件</a></li>
25+
</div>
26+
<div class="divItem">请点击wps加载项“给业务系统发通知”按钮,体验加载项主动发送消息</div>
27+
<div class="divItem">消息内容:<span style="font-weight: bolder;color: red;" id="webnotifyspan"></span></div>
28+
</div>
29+
30+
<div id='tishi'>
31+
<p style="text-align: center;">正在打开文件</p>
32+
<p>
33+
<progress id="openFile" value="0" max="100">
34+
<p style="text-align: center;">当前进度<span id="openfilespan" style="color:crimson;">0</span>%</p>
35+
</progress>
36+
</p>
37+
</div>
38+
39+
<div>
40+
<div class="partItem">多进程模式:</div>
41+
<li><a href="#" onclick="openFileInSilentMode()">新建客户端:静默打开文件</a>
42+
</li>
43+
<div id="rootClients"></div>
44+
</div>
45+
46+
<div class="divNote">
47+
<hr>
48+
<p>
49+
更详细的与B/S业务系统集成的能力相关的示例,请参考:
50+
<span style="font-weight: bolder;color: slateblue;"><a
51+
href="https://code.aliyun.com/zouyingfeng/wps/blob/master/README.md" target="_blank">
52+
https://code.aliyun.com/zouyingfeng/wps/blob/master/README.md
53+
</a></span>
54+
</p>
55+
<p>
56+
和我们一起构建WPS开发者社区,可以来<a href="https://zhuanlan.zhihu.com/c_1256350603921915904"
57+
target="_blank">「WPS二次开发」</a>转转,留下您的评论。
58+
</p>
59+
</div>
60+
</body>
61+
<script>
62+
//实际的开发中,业务系统与wps加载项的交互代码如下:
63+
var WebNotifycount = 0;
64+
var callbackFunc = function (result) {
65+
if (result.status == 0) {
66+
//下面这行代码用来注册从wps加载项返回的消息的接收函数
67+
WpsInvoke.RegWebNotify(projInfo.type, projInfo.name, function (messageText) {
68+
var span = document.getElementById("webnotifyspan")
69+
span.innerHTML = "(次数:" + ++WebNotifycount + "):" + messageText;
70+
})
71+
alert(result.response)
72+
}
73+
else
74+
alert(result.message)
75+
}
76+
77+
function openOfficeFile(param) {
78+
var invokeParam = {
79+
flag: "openOfficeFile",
80+
filepath: param
81+
} //根据需求任意定义
82+
WpsInvoke.InvokeAsHttp(
83+
projInfo.type,
84+
projInfo.name, //wps加载项的名字,在实际项目中写上对应的名字
85+
"openOfficeFileFromSystemDemo", //要调用的在wps加载项中的函数名
86+
JSON.stringify(invokeParam), //调用的在wps加载项中的函数要传递的数据,是一个json对象,根据业务系统需求任意定义
87+
callbackFunc) //回调函数,wps加载项中InvokeFromSystemDemo这个函数的返回值作为这个函数的参数
88+
}
89+
90+
function onDivClick(param, showToFront) {
91+
var invokeParam = {
92+
按需求定义: "安需求给值",
93+
Index: param,
94+
AppType: projInfo.type,
95+
自定义: {
96+
xxx定义: "xxx值"
97+
}
98+
} //根据需求任意定义
99+
WpsInvoke.InvokeAsHttp(
100+
projInfo.type,
101+
projInfo.name, //wps加载项的名字,在实际项目中写上对应的名字
102+
"InvokeFromSystemDemo", //要调用的在wps加载项中的函数名
103+
JSON.stringify(invokeParam), //调用的在wps加载项中的函数要传递的数据,是一个json对象,根据业务系统需求任意定义
104+
callbackFunc, //回调函数,wps加载项中InvokeFromSystemDemo这个函数的返回值作为这个函数的参数
105+
showToFront) //设置wps是否显示到最前面来
106+
}
107+
108+
//WebNotifyUseTimeout()
109+
//EnableMultiUser();
110+
var clientCount = 0;
111+
var dialogProgress; //打开文件进度计数
112+
var interval; //window.setInterval对象
113+
function openFileInSilentMode() {
114+
var dlg = document.getElementById("tishi");
115+
dlg.style.display = 'block';
116+
dialogProgress = 0
117+
interval = setInterval(updateProgress, 100)
118+
document.body.style.pointerEvents = "none"
119+
120+
var houzui = ".xlsx";
121+
if (projInfo.type == "wps")
122+
houzui = ".docx"
123+
else if (projInfo.type == "wpp")
124+
houzui = ".pptx"
125+
var url = (location.protocol + "//" + location.host + location.pathname).slice(0, -15) + projInfo.type + "Demo" + houzui
126+
var wpsClient = new WpsClient(projInfo.type);
127+
var eleId = "clientId" + (++clientCount);
128+
var WebNotifycount = 0;
129+
wpsClient.onMessage = function (messageText) {
130+
++WebNotifycount;
131+
var spanDiv = document.getElementById("webnotifyCount" + eleId);
132+
spanDiv.innerText = "(次数:" + WebNotifycount + "):";
133+
var span = document.getElementById("webnotifyspan" + eleId);
134+
span.innerHTML = messageText;
135+
}
136+
//先静默启动客户端,在回调函数里面实现打开大文件
137+
wpsClient.StartWpsInSilentMode(projInfo.name, function () {
138+
var invokeParam = {
139+
按需求定义: "安需求给值",
140+
Index: 'OpenFile',
141+
AppType: projInfo.type,
142+
filepath: url, //要打开的文件路径
143+
自定义: {
144+
xxx定义: "xxx值"
145+
}
146+
} //根据需求任意定义
147+
wpsClient.InvokeAsHttp(
148+
projInfo.name, //wps加载项的名字,在实际项目中写上对应的名字
149+
"InvokeFromSystemDemo", //要调用的在wps加载项中的函数名
150+
JSON.stringify(invokeParam), //调用的在wps加载项中的函数要传递的数据,是一个json对象,根据业务系统需求任意定义
151+
openFileCallbackFunc, //回调函数,wps加载项中InvokeFromSystemDemo这个函数的返回值作为这个函数的参数
152+
false) //设置wps是否显示到最前面来
153+
});
154+
155+
//打开文件成功后的交互代码
156+
function openFileCallbackFunc(result) {
157+
clearInterval(interval);
158+
//console.log(JSON.stringify(result))
159+
if (result.status !== 0) {
160+
setProgress(0)
161+
var dlg = document.getElementById("tishi");
162+
dlg.style.display = 'none';
163+
document.body.style.pointerEvents = "auto"
164+
alert(result.message)
165+
return;
166+
}
167+
setProgress(100);
168+
wpsClient.ShowToFront(projInfo.name, function () {
169+
setProgress(0)
170+
var dlg = document.getElementById("tishi");
171+
dlg.style.display = 'none';
172+
document.body.style.pointerEvents = "auto"
173+
});
174+
175+
var rootElement = document.getElementById("rootClients");
176+
var ele = document.createElement("div");
177+
ele.className = "addonItem";
178+
ele.id = eleId;
179+
ele.client = wpsClient;
180+
ele.innerHTML =
181+
'<div class="clientItem">客户端' + clientCount + '\n' +
182+
'<div class="divItem"><li><a href="#" onclick="onClientGetFileName(' + "'" + ele.id + "'" + ',' + "'getDocumentName'" + ', false' + ')">获取wps当前打开的文件的文件名</a></li></div>\n' +
183+
'<div class="divItem"><li><a href="#" onclick="onClientGetFileName(' + "'" + ele.id + "'" + ',' + "'newDocument'" + ', true' + ')">新建一个文件</a></li></div>\n' +
184+
'<div class="divItem">加载项主动发送的消息内容<span id="webnotifyCount' + ele.id + '"></span><span style="font-weight: bolder;color: red;" id="webnotifyspan' + ele.id + '"></span></div>'
185+
'</div>';
186+
rootElement.appendChild(ele);
187+
}
188+
}
189+
190+
function onClientGetFileName(clientId, param, showToFront) {
191+
var invokeParam = {
192+
按需求定义: "安需求给值",
193+
Index: param,
194+
AppType: projInfo.type,
195+
自定义: {
196+
xxx定义: "xxx值"
197+
}
198+
} //根据需求任意定义
199+
var ele = document.getElementById(clientId);
200+
ele.client.InvokeAsHttp(
201+
projInfo.name, //wps加载项的名字,在实际项目中写上对应的名字
202+
"InvokeFromSystemDemo", //要调用的在wps加载项中的函数名
203+
JSON.stringify(invokeParam), //调用的在wps加载项中的函数要传递的数据,是一个json对象,根据业务系统需求任意定义
204+
clientCallbackFunc, //回调函数,wps加载项中InvokeFromSystemDemo这个函数的返回值作为这个函数的参数
205+
showToFront) //设置wps是否显示到最前面来
206+
207+
function clientCallbackFunc(result) {
208+
if (result.status !== 0){
209+
if (result.message == "Failed to send message to WPS.") {
210+
ele.client.IsClientRunning(function (status) {
211+
if (status.response == "Client is running.")
212+
alert("任务发送失败,WPS 正在执行其他任务,请前往WPS完成当前任务")
213+
else
214+
alert("WPS 客户端被关闭了!")
215+
})
216+
}
217+
else {
218+
alert(result.message)
219+
}
220+
}
221+
else {
222+
alert(result.response)
223+
}
224+
}
225+
}
226+
227+
function updateProgress() {
228+
setProgress(++dialogProgress);
229+
}
230+
function setProgress(newValue) {
231+
if (newValue < 90 || newValue == 100) {
232+
var progress = document.getElementById('openFile');
233+
progress.value = newValue;
234+
var span = document.getElementById("openfilespan")
235+
span.innerHTML = newValue;
236+
}
237+
}
238+
</script>
239+
<style>
240+
.divTitle {
241+
margin-top: 30px;
242+
margin-bottom: 20px;
243+
font-size: 40px;
244+
font-weight: bolder;
245+
text-align: center;
246+
}
247+
248+
.divItem {
249+
margin: 5px;
250+
}
251+
252+
.divNote {
253+
margin-top: 60px;
254+
}
255+
256+
#rootClients {
257+
padding-left: 20px;
258+
font-size: 15px;
259+
}
260+
261+
.clientItem {
262+
margin: 5px;
263+
}
264+
265+
.partItem {
266+
font-size: 20px;
267+
margin: 5px;
268+
padding-top: 20px;
269+
}
270+
271+
#tishi {
272+
position: absolute;
273+
left: 600px;
274+
min-height: 150px;
275+
border: 1px solid black;
276+
padding: 10px 12px;
277+
display: none;
278+
background: #fff;
279+
280+
}
281+
</style>
282+
283+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
F:\wps\hackathon\XToolPlugin
Binary file not shown.

0 commit comments

Comments
 (0)