Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

7 месяцев назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <html>
  2. <meta charset="utf-8">
  3. <title>套用红头</title>
  4. </head>
  5. <body onload="getAllTemplelists()">
  6. <script type="text/javascript" src='js/main.js'></script>
  7. <div id="search">
  8. <span>关键词:</span>
  9. <input id="content" type="text" style="width:245px">
  10. <button type="button" onClick="search()">查询</button>
  11. <br />
  12. <br />
  13. </div>
  14. <select id="templates" size=5 style='width:360px'>
  15. <!--这里ajax动态拉取。-->
  16. </select>
  17. <br />
  18. <br />
  19. <button type="button" onClick="selectTemplate()">套红头</button>
  20. </body>
  21. </html>
  22. <script>
  23. function selectTemplate() {
  24. var wpsApp = wps.WpsApplication();
  25. var obj = document.getElementById("templates");
  26. var index = obj.selectedIndex;
  27. if (index == -1) { //添加未选中数据时的异常处理
  28. alert("请先选择红头文件后再进行套红头!");
  29. return;
  30. }
  31. var redId = obj.options[index].getAttribute("value");
  32. var activeDoc = wpsApp.ActiveDocument;
  33. var base = wps.PluginStorage.getItem("getRedHeadPath") || OA_DOOR.getRedHeadPath;
  34. if (base == undefined) { //未配置则模拟服务端返回
  35. SetDocParamsValue(activeDoc, "insertFileUrl", getDemoTemplatePath());
  36. SetDocParamsValue(activeDoc, "bkInsertFile", "Content");
  37. InsertRedHeadDoc(activeDoc);
  38. window.opener = null;
  39. window.open('', '_self', '');
  40. window.close();
  41. return
  42. }
  43. var path = base + redId;
  44. SetDocParamsValue(activeDoc, "insertFileUrl", path);
  45. InsertRedHeadDoc(activeDoc);
  46. window.opener = null;
  47. window.open('', '_self', '');
  48. window.close();
  49. }
  50. //判断是否是word文档
  51. function isWord(suffix) {
  52. var suffixArray = ["doc", "dot", "wps", "wpt", "docx", "docm", "dotm"];
  53. for (var f1 in suffixArray) {
  54. if (suffixArray[f1].indexOf(suffix) > -1) {
  55. return true;
  56. }
  57. }
  58. return false;
  59. }
  60. function getAllTemplelists() {
  61. var xmlhttp = new XMLHttpRequest();
  62. xmlhttp.onreadystatechange = function () {
  63. //当接受到响应时回调该方法
  64. if (xmlhttp.readyState == 4 && (xmlhttp.status == 200 || xmlhttp.status == 0)) {
  65. var text = xmlhttp.responseText; //使用接口返回内容,响应内容
  66. var resultJson = JSON.parse(text) //将json字符串转换成对象
  67. for (var i = 0; i < resultJson.length; i++) {
  68. var element = resultJson[i]
  69. var myOption = document.createElement("option"); //动态创建option标签
  70. var suffix = element.tempName.split('.')[1];
  71. if (isWord(suffix)) {
  72. myOption.value = element.tempId; //红头文档id
  73. myOption.text = element.tempName; //红头文档名称
  74. templates.add(myOption);
  75. }
  76. }
  77. }
  78. }
  79. var redHeadsPath = wps.PluginStorage.getItem("redHeadsPath") || OA_DOOR.redHeadsPath
  80. if (redHeadsPath == undefined) { //未配置则模拟服务端返回
  81. var strData =
  82. '[{"tempId":23,"tempName":"广东省xx局.docx"},{"tempId":24,"tempName":"广东省xx局 - 副本.docx"},{"tempId":25,"tempName":"红头.docx"}]'
  83. resultJson = JSON.parse(strData);
  84. for (var i = 0; i < resultJson.length; i++) {
  85. var element = resultJson[i]
  86. var myOption = document.createElement("option"); //动态创建option标签
  87. var suffix = element.tempName.split('.')[1];
  88. if (isWord(suffix)) {
  89. myOption.value = element.tempId; //红头文档id
  90. myOption.text = element.tempName; //红头文档名称
  91. templates.add(myOption);
  92. }
  93. }
  94. document.getElementById("search").style.display = "none";
  95. return
  96. }
  97. xmlhttp.open("POST", redHeadsPath, true); //以POST方式请求该接口
  98. xmlhttp.setRequestHeader("Content-type",
  99. "application/x-www-form-urlencoded;charset=UTF-16LE"); //添加Content-type
  100. xmlhttp.send(); //发送请求参数间用&分割
  101. if (!wps.PluginStorage.getItem("searchRedHeadPath")) {
  102. document.getElementById("search").style.display = "none";
  103. }
  104. }
  105. function search() {
  106. var xmlhttp = new XMLHttpRequest();
  107. xmlhttp.onreadystatechange = function () {
  108. //当接受到响应时回调该方法
  109. if (xmlhttp.readyState == 4 && (xmlhttp.status == 200 || xmlhttp.status == 0)) {
  110. var text = xmlhttp.responseText; //使用接口返回内容,响应内容
  111. var resultJson = JSON.parse(text) //将json字符串转换成对象
  112. templates.options.length = 0;
  113. for (var i = 0; i < resultJson.length; i++) {
  114. var element = resultJson[i]
  115. var myOption = document.createElement("option"); //动态创建option标签
  116. myOption.value = element.tempId; //红头文档id
  117. myOption.text = element.tempName; //红头文档名称
  118. templates.add(myOption);
  119. }
  120. }
  121. }
  122. var searchPath = wps.PluginStorage.getItem("searchRedHeadPath") || OA_DOOR.redHeadsPath
  123. var totalPath = searchPath + "?content=" + document.getElementById("content").value;
  124. xmlhttp.open("get", totalPath, true); //以POST方式请求该接口
  125. xmlhttp.setRequestHeader("Content-type",
  126. "application/x-www-form-urlencoded;charset=UTF-16LE"); //添加Content-type
  127. xmlhttp.send(); //发送请求参数间用&分割
  128. }
  129. </script>