You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

demo.js 8.0KB

5 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. var isServerOk = false
  2. var isSetupOk = false
  3. var pluginsMode=0;//0表示jsplugins.xml模式,1表示publish模式,2表示 多进程加动态传递jsplugins.xml模式
  4. //publish自动安装开始
  5. /*
  6. * 将自己的加载项地址配置到这里来
  7. * 需要保证加载项的name和业务业务系统中传递加载项name相对应
  8. * url必须以/ 结尾,且url+ribbon.xml和url+index.html在清除浏览器缓存的情况下能直接访问,不会被重定向
  9. * addonType:对应组件类型,wps文字,wpp演示,et表格
  10. */
  11. //复制开始
  12. // var curList = [{"name":"EtOAAssist","addonType":"et","online":"false","url":"http://127.0.0.1/jsplugindir/EtOAAssist.7z","version":"1.0.0"}]; //离线模式参考
  13. var curList=[
  14. {"name":"WpsOAAssist","addonType":"wps","online":"true","url":"http://127.0.0.1:3888/plugin/wps/"},
  15. {"name":"EtOAAssist","addonType":"et","online":"true","url":"http://127.0.0.1:3888/plugin/et/"},
  16. {"name":"WppOAAssist","addonType":"wpp","online":"true","url":"http://127.0.0.1:3888/plugin/wpp/"}
  17. ]//在线模式配置参考
  18. var localList=[];
  19. var publishIndex=0;
  20. var publishUnIndex=0;
  21. /*获取用户本地全部加载项的接口是必须要的,这个接口做了判断,
  22. ** 如果58890端口未启动,会先去启动这个端口
  23. */
  24. //加载项安装函数
  25. function installWpsAddin(callBack){
  26. WpsAddonMgr.getAllConfig(function(e){
  27. if(!e.response||e.response.indexOf("null")>=0){//本地没有加载项,直接安装
  28. if(curList.length>0){
  29. installWpsAddinOne(callBack);
  30. }
  31. }else{//本地有加载项,先卸载原有加载项,然后再安装
  32. localList=JSON.parse(e.response)
  33. // if(e.response)
  34. unInstallWpsAddinOne(callBack)
  35. }
  36. })
  37. }
  38. //安装单个加载项
  39. function installWpsAddinOne(callBack){
  40. WpsAddonMgr.enable(curList[publishIndex],function(e){
  41. if(e.status){
  42. console.log(e.msg)
  43. }else{
  44. console.log("安装成功")
  45. }
  46. publishIndex++;
  47. if(publishIndex<curList.length){
  48. installWpsAddinOne();
  49. }else{
  50. callBack&&callBack()
  51. }
  52. })
  53. }
  54. //卸载单个加载项
  55. function unInstallWpsAddinOne(callBack){
  56. WpsAddonMgr.disable(localList[publishUnIndex],function(e){
  57. if(e.status){
  58. console.log(e.msg)
  59. }else{
  60. console.log("卸载成功")
  61. }
  62. publishUnIndex++;
  63. if(publishUnIndex<localList.length){
  64. unInstallWpsAddinOne(callBack);
  65. }else{
  66. if(curList.length>0){
  67. installWpsAddinOne(callBack);
  68. }
  69. }
  70. })
  71. }
  72. //publish自动安装结束
  73. function envTest() {
  74. //1.服务端检测
  75. var xhr = getHttpObj()
  76. xhr.onload = function(e) {
  77. isServerOk = true
  78. //2.安装包检测
  79. var xhr1 = getHttpObj()
  80. xhr1.onload = function(e) {
  81. if (xhr1.responseText.indexOf('异常') > -1 || xhr1.responseText.indexOf('未安装') > -1 || xhr1.responseText.indexOf('失败') > -1) {
  82. window.location.href = "./demo.html"
  83. return;
  84. }
  85. isSetupOk = true
  86. window.location.href.indexOf("file://") > -1 ? window.location.href = "http://127.0.0.1:3888/index.html" : ''
  87. }
  88. xhr1.onerror = function(e) {
  89. isServerOk = false
  90. window.location.href = "./demo.html"
  91. }
  92. xhr1.open('get', 'http://127.0.0.1:3888/WpsSetupTest?pluginsMode='+pluginsMode, true)
  93. xhr1.send()
  94. }
  95. xhr.onerror = function(e) {
  96. isServerOk = false
  97. window.location.href = "./demo.html"
  98. }
  99. xhr.open('get', 'http://127.0.0.1:3888/FileList', true)
  100. xhr.send();
  101. }
  102. // 切换到相应 tab. 0: wps 1: wpp 2: et
  103. function SwitchTab(crtTabIndex) {
  104. var iframe_wps = document.getElementById("iframe_wps");
  105. var iframe_wpp = document.getElementById("iframe_wpp");
  106. var iframe_et = document.getElementById("iframe_et");
  107. if (iframe_wps && iframe_wpp && iframe_et) {
  108. switch (crtTabIndex) {
  109. case 0:
  110. iframe_wpp.setAttribute("height", "0px");
  111. iframe_et.setAttribute("height", "0px");
  112. iframe_wps.setAttribute("height", "100%");
  113. break;
  114. case 1:
  115. iframe_wps.setAttribute("height", "0px");
  116. iframe_wpp.setAttribute("height", "0px");
  117. iframe_et.setAttribute("height", "100%");
  118. break;
  119. case 2:
  120. iframe_wps.setAttribute("height", "0px");
  121. iframe_et.setAttribute("height", "0px");
  122. iframe_wpp.setAttribute("height", "100%");
  123. break;
  124. default:
  125. iframe_wps.setAttribute("height", "0px");
  126. iframe_wpp.setAttribute("height", "0px");
  127. iframe_et.setAttribute("height", "0px");
  128. break;
  129. }
  130. }
  131. }
  132. function appChange() {
  133. var obj = document.getElementById("app");
  134. SwitchTab(obj.selectedIndex);
  135. }
  136. window.onload = function() {
  137. var app = document.getElementById("app");
  138. var opts = app.getElementsByTagName("option"); //得到数组option
  139. opts[0].selected = true;
  140. var indexFrame = document.getElementById("indexFrame");
  141. indexFrame.innerHTML="<iframe src='./resource/wps.html?pluginsMode="+pluginsMode+"' id='iframe_wps' frameborder='0' width='100%' height='0%'></iframe><iframe src='./resource/wpp.html?pluginsMode="+pluginsMode+"' id='iframe_wpp' frameborder='0' width='100%' height='0%'></iframe><iframe src='./resource/et.html?pluginsMode="+pluginsMode+"' id='iframe_et' frameborder='0' width='100%' height='0%'></iframe>"
  142. // 默认切换到 wps
  143. SwitchTab(0);
  144. //demo三种模式进行切换
  145. envTest() //自动配置oem.ini
  146. if(pluginsMode==1){
  147. installWpsAddin() //自动安装集成
  148. }else{
  149. //卸载掉publish模式
  150. curList=[]
  151. installWpsAddin()
  152. }
  153. }
  154. function IEVersion() {
  155. var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
  156. var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器
  157. var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器
  158. var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
  159. if (isIE) {
  160. var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
  161. reIE.test(userAgent);
  162. var fIEVersion = parseFloat(RegExp["$1"]);
  163. if (fIEVersion == 7) {
  164. return 7;
  165. } else if (fIEVersion == 8) {
  166. return 8;
  167. } else if (fIEVersion == 9) {
  168. return 9;
  169. } else if (fIEVersion == 10) {
  170. return 10;
  171. } else {
  172. return 6; //IE版本<=7
  173. }
  174. } else if (isEdge) {
  175. return 20; //edge
  176. } else if (isIE11) {
  177. return 11; //IE11
  178. } else {
  179. return 30; //不是ie浏览器
  180. }
  181. }
  182. function getHttpObj() {
  183. var httpobj = null;
  184. if (IEVersion() < 10) {
  185. try {
  186. httpobj = new XDomainRequest();
  187. } catch (e1) {
  188. httpobj = new createXHR();
  189. }
  190. } else {
  191. httpobj = new createXHR();
  192. }
  193. return httpobj;
  194. }
  195. //兼容IE低版本的创建xmlhttprequest对象的方法
  196. function createXHR() {
  197. if (typeof XMLHttpRequest != 'undefined') { //兼容高版本浏览器
  198. return new XMLHttpRequest();
  199. } else if (typeof ActiveXObject != 'undefined') { //IE6 采用 ActiveXObject, 兼容IE6
  200. var versions = [ //由于MSXML库有3个版本,因此都要考虑
  201. 'MSXML2.XMLHttp.6.0',
  202. 'MSXML2.XMLHttp.3.0',
  203. 'MSXML2.XMLHttp'
  204. ];
  205. for (var i = 0; i < versions.length; i++) {
  206. try {
  207. return new ActiveXObject(versions[i]);
  208. } catch (e) {
  209. //跳过
  210. }
  211. }
  212. } else {
  213. throw new Error('您的浏览器不支持XHR对象');
  214. }
  215. }