赞
踩
wps加载项目有两种部署模式,publish模式和jsplugins.xml模式,可以参考实际情况自己选择部署模式。
1. 原理
通过访问 publish自动安装是通过接口在客户本地的jsaddons目录下生成publish.xml文件,WPS启动时,会去读取该文件,找到相应的加载项。
2. 具体实现
(1)通过 wpsjs publish生成publish.html 部署文件。publish.html中curList的url为http://部署加载项的服务器地址:端口/xxx/,填写127.0.0.1则访问的是本项目该目录下的加载项。
- function LoadPublishAddons() {
- var addonList = document.getElementById("addonList");
- var curList = [{"name":"xxx","addonType":"wps","online":"true","url":"http://ip:port/wps加载项index.html路径"}];
- // var curList = [{"name":"xxx","version":"1.0","addonType":"wps","online":"false","url":"http://ip:port/wps加载项.7z"}];
- curList.forEach(function (element) {
- var param = JSON.stringify(element).replace("\"", "\'");
- UpdateElement(element, 'enable')
- });
- }
注意:publish.html 中的 curList 值为 [{"name":"xxx","addonType":"wps","online":"true","url":"http://ip:port/wps加载项index.html路径"}] 访问的是在线加载项文件,curList 值为 [{"name":"xxx","version":"1.0","addonType":"wps","online":"false","url":"http://ip:port/wps加载项.7z"}] 访问时自动下载加载项文件,可以离线使用。
(2)把 publish.html 放到项目中,保证可以被访问到,同时把开发的加载项文件 或 加载项文件压缩包放到项目中。
- @Controller
- @RequestMapping("/publish")
- public class PublishController {
- @GetMapping()
- public String template() {
- return "/publish";
- }
- }
(3)访问http://127.0.0.1:端口/xxx/publish,选择wps加载项
(4)查看本地目录C:\Users\Administrator\AppData\Roaming\kingsoft\wps\jsaddons是否生成publish.xml文件(publish模式)。如果存在jsplugins.xml文件(jsplugins模式)需要删除,两者不同时生效。同时使用两种模式时,需要保证两种模式中的加载项名称不会重复。
(5)查看http://ip:port/xxx/ribbon.xml能否访问(加载项文件)
(6)查看http://ip:port/xxx/index.html是否报错(加载项文件)
(7)做完以上步骤后,打开wps后会自动出现wps加载项
1. 原理
两种部署方式,实现的效果一样。
2. 具体实现
可以参考文档附件
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。