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.

importTemplate.html 5.2KB

пре 5 месеци
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>导入模板</title>
  5. <meta charset="UTF-8">
  6. <script type="text/javascript" src='js/main.js'></script>
  7. <script type="text/javascript" src="otherslib/lib/vue.min.js"></script>
  8. <style type="text/css">
  9. * {
  10. box-sizing: border-box;
  11. }
  12. /*清除浮动*/
  13. .clear:after {
  14. content: "";
  15. display: block;
  16. clear: both;
  17. }
  18. html,
  19. body,
  20. #template {
  21. margin: 0;
  22. padding: 0;
  23. width: 100%;
  24. height: 100%;
  25. }
  26. .row {
  27. width: 100%;
  28. border-top: 2px solid #e7e7e7;
  29. }
  30. .row>div {
  31. height: 100%;
  32. }
  33. #file_select {
  34. width: 100%;
  35. padding-left: 5%;
  36. }
  37. .def_control {
  38. height: 55%;
  39. width: 100%;
  40. font-size: 18px;
  41. }
  42. .btn_box {
  43. width: 16%;
  44. float: right;
  45. line-height: 4.5em;
  46. margin-right: 3%;
  47. }
  48. </style>
  49. </head>
  50. <body>
  51. <div id="template">
  52. <div class="row" style="height:50%;padding-top: 3%;">
  53. <div id="file_select">
  54. <span>文件名:</span>
  55. <select class="def_control" style="width: 80%;" v-model="templateItem">
  56. <option value="-1">请选择模板</option>
  57. <option v-for="(item,key) in templates" :value="item.tempId" :key="key">{{item.tempName}}</option>
  58. </select>
  59. </div>
  60. </div>
  61. <div class="row" style="height: 50%;">
  62. <div class="btn_box">
  63. <button class="def_control" type="button" @click="cancel()">取消</button>
  64. </div>
  65. <div class="btn_box">
  66. <button class="def_control" type="button" @click="OnImportTemplate()">导入</button>
  67. </div>
  68. </div>
  69. </div>
  70. </body>
  71. </html>
  72. <script>
  73. /**
  74. * 导入公文模板,并替换当前文档全部内容
  75. * @param templateURL 模板路径
  76. */
  77. function importTemlateFile(templateURL) {
  78. var wpsApp = wps.WpsApplication();
  79. var activeDoc = wpsApp.ActiveDocument;
  80. if (!activeDoc) {
  81. alert("文档不存在");
  82. return;
  83. }
  84. var selection = wpsApp.ActiveWindow.Selection;
  85. selection.WholeStory(); //选取全文
  86. selection.Delete(); // 删除选中内容
  87. selection.InsertFile(templateURL);
  88. if (activeDoc.Revisions.Count > 0) { // 文档或区域中的修订
  89. activeDoc.AcceptAllRevisions(); // 接受对指定文档的所有修订
  90. }
  91. }
  92. // 获取选中项,拼接模板Url进行导入模板
  93. function OnImportTemplate() {
  94. var templateId = vm.templateItem;
  95. console.log(vm);
  96. if (templateId == -1) {
  97. alert('请选中模板!!');
  98. return;
  99. }
  100. // var p_Doc = wps.WpsApplication().ActiveDocument;
  101. // var templatePath = GetDocParamsValue(p_Doc, "templatePath");
  102. // if (templatePath == "") { templatePath = OA_DOOR.templateBaseURL; }
  103. // var templateURL = templatePath + templateId;
  104. var templateURL = getHtmlURL("template/模板.docx");
  105. importTemlateFile(templateURL);
  106. window.opener = null;
  107. window.open('', '_self', '');
  108. window.close();
  109. wps.OAAssist.ShellExecute("ksowebstartupwps://");
  110. }
  111. function cancel() { // 取消按钮
  112. window.close();
  113. wps.OAAssist.ShellExecute("ksowebstartupwps://"); // 将WPS程序置前
  114. }
  115. var vm = new Vue({
  116. el: "#template",
  117. data: {
  118. templateItem: -1,
  119. templates: {}
  120. },
  121. methods: {
  122. getAllTemplate: function () {
  123. var _this = this
  124. //通过接口拉取模板列表
  125. // var p_Doc = wps.WpsApplication().ActiveDocument;
  126. // var templateDataUrl = GetDocParamsValue(p_Doc, "templateDataUrl");
  127. // if (templateDataUrl == "") { templateDataUrl = OA_DOOR.templateDataUrl; }
  128. // $.ajax({
  129. // url: templateDataUrl,
  130. // async: false,
  131. // method: "post",
  132. // dataType: 'json',
  133. // success: function (res) {
  134. // _this.templates = res;
  135. // console.log("模板列表数据:" + JSON.stringify(res));
  136. // },
  137. // error: function (res) {
  138. // alert("获取响应失败");
  139. // _this.templates = {}
  140. // }
  141. // });
  142. //本地静态列表
  143. this.templates=[{
  144. tempName:'模板',
  145. tempId:1
  146. }]
  147. }
  148. },
  149. mounted: function () {
  150. this.getAllTemplate();
  151. }
  152. });
  153. </script>