WpsOffice2.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
  2. MWF.xApplication.process.Xform.WpsOffice2 = MWF.APPWpsOffice2 = new Class({
  3. Extends: MWF.APP$Module,
  4. isActive: false,
  5. options:{
  6. "version": "v1.1.8",
  7. "moduleEvents": ["beforeOpen",
  8. "afterOpen",
  9. "afterSave"
  10. ]
  11. },
  12. initialize: function(node, json, form, options){
  13. this.node = $(node);
  14. this.node.store("module", this);
  15. this.json = json;
  16. this.form = form;
  17. this.documentId = "";
  18. this.mode = "write";
  19. },
  20. _loadUserInterface: function(){
  21. this.node.empty();
  22. this.node.setStyles({
  23. "min-height": "700px"
  24. });
  25. },
  26. _afterLoaded: function(){
  27. if(!layout.serviceAddressList["x_wpsfile2_assemble_control"]){
  28. this.node.set("html","<h3><font color=red>请先安装wps私有化应用</font></h3>");
  29. return false;
  30. }
  31. this.action = o2.Actions.load("x_wpsfile2_assemble_control");
  32. if (!this.json.isNotLoadNow){
  33. this.data = this.getData();
  34. if(this.data.documentId === ""){
  35. this.createDocument(function (){
  36. this.loadDocument();
  37. }.bind(this));
  38. }else {
  39. this.documentId = this.data.documentId;
  40. this.loadDocument();
  41. }
  42. }
  43. },
  44. createDocument : function (callback){
  45. var json = {};
  46. if(this.json.template !== ""){
  47. json.templateId = this.json.template;
  48. this.json.officeType = "word";
  49. }
  50. if(this.json.fileName !== ""){
  51. json.fileName = this.json.fileName;
  52. }
  53. json.category = "process";
  54. json.docId = this.form.businessData.work.job;
  55. this.action.CustomAction.createFileBlank(this.json.officeType,json, function( json ){
  56. this.documentId = json.data.docId;
  57. this.setData();
  58. if (callback) callback();
  59. }.bind(this),null, false);
  60. },
  61. loadDocument: function () {
  62. this.getEditor(function () {
  63. this.loadApi(function (){
  64. this.loadEditor();
  65. }.bind(this));
  66. }.bind(this));
  67. },
  68. loadApi : function (callback){
  69. o2.load(["../o2_lib/wps/polyfill.min.js","../o2_lib/wps/web-office-sdk.umd.js"], {"sequence": true}, function () {
  70. if (callback) callback();
  71. }.bind(this));
  72. },
  73. getEditor: function (callback) {
  74. if (this.isReadonly()){
  75. this.mode = "read";
  76. }else{
  77. if (this.json.readScript && this.json.readScript.code){
  78. var flag = this.form.Macro.exec(this.json.readScript.code, this);
  79. if (flag){
  80. this.mode = "read";
  81. }
  82. }
  83. }
  84. this.fireEvent("beforeOpen");
  85. console.log("wps:" + this.mode);
  86. this.action.CustomAction.getFileUrl(this.documentId,{"permission":this.mode} ,function( json ){
  87. this.wpsUrl = json.data.wpsUrl;
  88. this.wpsToken = json.data.token;
  89. if(this.json.officeType === "other"){
  90. if(this.wpsUrl.indexOf("/w/")>-1){
  91. this.json.officeType = "word";
  92. }
  93. if(this.wpsUrl.indexOf("/p/")>-1){
  94. this.json.officeType = "ppt";
  95. }
  96. if(this.wpsUrl.indexOf("/s/")>-1){
  97. this.json.officeType = "excel";
  98. }
  99. }
  100. if (callback) callback();
  101. }.bind(this),null,false);
  102. },
  103. loadEditor : function (){
  104. this.wpsOffice = WebOfficeSDK.config({
  105. url : this.wpsUrl,
  106. mount: this.node,
  107. mode : this.json.showMode,
  108. cooperUserAttribute: {
  109. isCooperUsersAvatarVisible: this.json.isCooperUsersAvatarVisible //是否显示协作用户头像
  110. },
  111. // 通用选项,所有类型文档适用
  112. commonOptions: {
  113. isShowTopArea: this.json.isShowTopArea, // 隐藏顶部区域(头部和工具栏)
  114. isShowHeader: this.json.isShowHeader, // 隐藏头部区域
  115. isBrowserViewFullscreen : this.json.isBrowserViewFullscreen,//是否在浏览器区域全屏
  116. isIframeViewFullscreen : this.json.isIframeViewFullscreen//是否在iframe区域内全屏
  117. },
  118. wordOptions : {
  119. isShowDocMap : this.json.isShowDocMap,//是否开启目录功能,默认开启
  120. isBestScale : this.json.isBestScale,//打开文档时,默认以最佳比例显示(适用于pc)
  121. isShowBottomStatusBar : this.json.isShowBottomStatusBar,//pc-是否展示底部状态栏
  122. "mobile.isOpenIntoEdit" : this.json.isOpenIntoEdit//mobile-要有编辑权限,移动端打开时是否进入编辑
  123. },
  124. commandBars: [
  125. {
  126. cmbId: "HeaderLeft",
  127. attributes: {
  128. visible: this.json.HeaderLeft,
  129. enable: this.json.HeaderLeft
  130. }
  131. },
  132. {
  133. cmbId: "HeaderRight",
  134. attributes: {
  135. visible: this.json.HeaderRight,
  136. enable: this.json.HeaderRight
  137. }
  138. },
  139. {
  140. cmbId: "FloatQuickHelp",
  141. attributes: {
  142. visible: this.json.FloatQuickHelp,
  143. enable: this.json.FloatQuickHelp
  144. }
  145. },
  146. {
  147. cmbId: "HistoryVersion",
  148. attributes: {
  149. visible: this.json.HistoryVersion,
  150. enable: this.json.HistoryVersion
  151. }
  152. },
  153. {
  154. cmbId: "HistoryRecord",
  155. attributes: {
  156. visible: this.json.HistoryRecord,
  157. enable: this.json.HistoryRecord
  158. }
  159. },
  160. {
  161. cmbId: "HistoryVersionDivider",
  162. attributes: {
  163. visible: this.json.HistoryVersionDivider,
  164. enable: this.json.HistoryVersionDivider
  165. }
  166. },
  167. {
  168. cmbId: "Logo",
  169. attributes: {
  170. visible: this.json.Logo,
  171. enable: this.json.Logo
  172. }
  173. },
  174. {
  175. cmbId: "Cooperation",
  176. attributes: {
  177. visible: this.json.Cooperation,
  178. enable: this.json.Cooperation
  179. }
  180. },
  181. {
  182. cmbId: "More",
  183. attributes: {
  184. visible: this.json.More,
  185. enable: this.json.More
  186. }
  187. },
  188. {
  189. cmbId: "SendButton",
  190. attributes: {
  191. visible: this.json.SendButton,
  192. enable: this.json.SendButton
  193. }
  194. },
  195. {
  196. cmbId: "CooperHistoryMenuItem",
  197. attributes: {
  198. visible: this.json.CooperHistoryMenuItem,
  199. enable: this.json.CooperHistoryMenuItem
  200. }
  201. },
  202. {
  203. cmbId: "TabPrintPreview",
  204. attributes: {
  205. visible: this.json.TabPrintPreview,
  206. enable: this.json.TabPrintPreview
  207. }
  208. },
  209. {
  210. cmbId: "MenuPrintPreview",
  211. attributes: {
  212. visible: this.json.MenuPrintPreview,
  213. enable: this.json.MenuPrintPreview
  214. }
  215. },
  216. {
  217. cmbId: "ReviewTrackChanges",
  218. attributes: {
  219. visible: this.json.ReviewTrackChanges,
  220. enable: this.json.ReviewTrackChanges
  221. }
  222. },
  223. {
  224. cmbId: "TrackChanges",
  225. attributes: {
  226. visible: this.json.TrackChanges,
  227. enable: this.json.TrackChanges
  228. }
  229. },
  230. {
  231. cmbId: "ContextMenuConvene",
  232. attributes: {
  233. visible: this.json.ContextMenuConvene,
  234. enable: this.json.ContextMenuConvene
  235. }
  236. },
  237. {
  238. cmbId: "WriterHoverToolbars",
  239. attributes: {
  240. visible: this.json.WriterHoverToolbars,
  241. enable: this.json.WriterHoverToolbars
  242. }
  243. },
  244. {
  245. cmbId: "ReadSetting",
  246. attributes: {
  247. visible: this.json.ReadSetting,
  248. enable: this.json.ReadSetting
  249. }
  250. }
  251. ]
  252. });
  253. var token = this.wpsToken;
  254. // 设置token
  255. // this.wpsOffice.setToken({
  256. // token: token,
  257. // timeout: 10000 // token超时时间, 可配合refreshToken配置函数使用,当超时前将调用refreshToken
  258. // })
  259. // 打开文档结果
  260. this.wpsOffice.on('fileOpen', function(result) {
  261. this.fireEvent("afterOpen");
  262. }.bind(this));
  263. this.wpsOffice.on('fileStatus', function(result) {
  264. if(result.status === 7){
  265. this.fireEvent("afterSave");
  266. }
  267. }.bind(this));
  268. this.wpsOffice.on('fullscreenChange', function(result) {
  269. console.log(JSON.stringify(result))
  270. });
  271. this.wpsOffice.on('previewLimit', function(result) {
  272. console.log(JSON.stringify(result))
  273. });
  274. this.wpsOffice.on('tabSwitch', function(result) {
  275. console.log(JSON.stringify(result))
  276. });
  277. this.wpsOffice.on('error', function(result) {
  278. console.log(JSON.stringify(result))
  279. });
  280. //是否显示评论
  281. if(this.json.isShowComment){
  282. this.showComments();
  283. }else {
  284. this.hideComments();
  285. }
  286. },
  287. hide: function(){
  288. this.node.hide();
  289. },
  290. show: function(){
  291. this.node.show();
  292. },
  293. isEmpty : function(){
  294. var data = this.getData();
  295. if(data.documentId === ""){
  296. return true;
  297. }else {
  298. return false;
  299. }
  300. },
  301. getData: function(){
  302. var data = {
  303. "documentId" : ""
  304. };
  305. if(this.form.businessData.data[this.json.id]){
  306. data.documentId = this.form.businessData.data[this.json.id].documentId;
  307. }
  308. return data;
  309. },
  310. setData: function(){
  311. var data = {
  312. "documentId" : this.documentId
  313. };
  314. this._setBusinessData(data);
  315. },
  316. save: function(callback){
  317. var promise = this.wpsOffice.save();
  318. promise.then(function(){
  319. console.log("save success");
  320. if(callback) callback();
  321. });
  322. },
  323. getTotalPage : function (callback){
  324. var p1 = this.wpsOffice.ready();
  325. p1.then(function (){
  326. const app = this.wpsOffice.WordApplication()
  327. var p2 = app.ActiveDocument.Range.Information(app.Enum.WdInformation.wdNumberOfPagesInDocument);
  328. p2.then(function(totalPages){
  329. if(totalPages.End){
  330. if(callback) callback(totalPages.PagesCount);
  331. }else {
  332. promise();
  333. }
  334. }.bind(this));
  335. }.bind(this));
  336. },
  337. getCurrentPage: function (callback){
  338. var p1 = this.wpsOffice.ready();
  339. p1.then(function(){
  340. const app = this.wpsOffice.WordApplication();
  341. var p2 = app.ActiveDocument.Selection.Information(app.Enum.WdInformation.wdActiveEndPageNumber);
  342. p2.then(function(currentPage){
  343. if(callback) callback(currentPage);
  344. });
  345. }.bind(this));
  346. },
  347. gotoPage : function (page){
  348. var p1 = this.wpsOffice.ready();
  349. p1.then(function(){
  350. const app = this.wpsOffice.WordApplication();
  351. var p2 = app.ActiveDocument.Selection.GoTo({
  352. What: app.Enum.WdGoToItem.wdGoToPage,
  353. Which: app.Enum.WdGoToDirection.wdGoToAbsolute,
  354. Count: page
  355. });
  356. p2.then(function(){
  357. })
  358. }.bind(this));
  359. },
  360. getAllBookmark : function (callback){
  361. var p1 = this.wpsOffice.ready();
  362. p1.then(function(){
  363. const app = this.wpsOffice.WordApplication();
  364. var p2 = app.ActiveDocument.Bookmarks.Json();
  365. p2.then(function(bookMarks){
  366. if(callback) callback(bookMarks);
  367. });
  368. }.bind(this));
  369. },
  370. getBookmarkText : function (name,callback) {
  371. var p1 = this.wpsOffice.ready();
  372. p1.then(function(){
  373. const app = this.wpsOffice.WordApplication();
  374. var p2 = app.ActiveDocument.GetBookmarkText(name);
  375. p2.then(function(text){
  376. if(callback) callback(text);
  377. });
  378. }.bind(this));
  379. },
  380. gotoBookmark : function (name){
  381. var p1 = this.wpsOffice.ready();
  382. p1.then(function(){
  383. const app = this.wpsOffice.WordApplication();
  384. var p2 = app.ActiveDocument.Selection.GoTo({
  385. What: app.Enum.WdGoToItem.wdGoToBookmark,
  386. Which: app.Enum.WdGoToDirection.wdGoToAbsolute,
  387. Name: name
  388. })
  389. p2.then(function(){
  390. });
  391. }.bind(this));
  392. },
  393. setBookmarkText : function (name,value,callback){
  394. var p1 = this.wpsOffice.ready();
  395. p1.then(function(){
  396. const app = this.wpsOffice.WordApplication();
  397. var p2 = app.ActiveDocument.ReplaceBookmark([{name: name, type: 'text', value: value} ])
  398. p2.then(function(isReplaceSuccess){
  399. if(callback) callback(isReplaceSuccess);
  400. });
  401. }.bind(this));
  402. },
  403. replaceText : function (key,value,options){
  404. var p1 = this.wpsOffice.ready();
  405. p1.then(function(){
  406. const app = this.wpsOffice.WordApplication();
  407. var p2 = app.ActiveDocument.ReplaceText([{key: key, value: value}])
  408. p2.then(function(isReplaceSuccess){
  409. if(callback) callback(isReplaceSuccess);
  410. });
  411. }.bind(this));
  412. },
  413. startRevisions : function (){
  414. //开启修订模式
  415. this.wpsOffice.ready().then(function(){
  416. const app = this.wpsOffice.Application;
  417. // 将当前文档的编辑状态切换成修订模式
  418. app.ActiveDocument.TrackRevisions = true;
  419. }.bind(this));
  420. },
  421. stopRevisions : function (){
  422. //关闭修订模式
  423. this.wpsOffice.ready().then(function(){
  424. const app = this.wpsOffice.Application;
  425. // 将当前文档的编辑状态切换成修订模式
  426. app.ActiveDocument.TrackRevisions = false;
  427. }.bind(this));
  428. },
  429. acceptAllRevisions : function (callback){
  430. //接受所有修订
  431. this.wpsOffice.ready().then(function(){
  432. const app = this.wpsOffice.Application;
  433. // 获取修订对象
  434. app.ActiveDocument.Revisions.then(function(revisions){
  435. // 接受对指定文档的所有修订
  436. revisions.AcceptAll().then(function(){
  437. if(callback) callback();
  438. });
  439. }.bind(this));
  440. }.bind(this));
  441. },
  442. rejectAllRevisions : function (callback){
  443. //拒绝所有修订
  444. this.wpsOffice.ready().then(function(){
  445. const app = this.wpsOffice.Application;
  446. // 获取修订对象
  447. app.ActiveDocument.Revisions.then(function(revisions){
  448. // 拒绝所有修订
  449. revisions.RejectAll().then(function(){
  450. if(callback) callback();
  451. });
  452. }.bind(this));
  453. }.bind(this));
  454. },
  455. showRevisions : function (){
  456. //显示痕迹
  457. this.wpsOffice.ready().then(function(){
  458. const app = this.wpsOffice.Application;
  459. // 获取节对象
  460. app.ActiveDocument.ActiveWindow.View.then(function(View){
  461. // 设置修订状态为最终状态
  462. View.RevisionsView = 0;
  463. // 设置修订状态为 显示标记的最终状态
  464. View.ShowRevisionsAndComments = true;
  465. });
  466. }.bind(this));
  467. },
  468. hideRevisions : function (){
  469. //隐藏
  470. this.wpsOffice.ready().then(function(){
  471. const app = this.wpsOffice.Application;
  472. // 获取节对象
  473. app.ActiveDocument.ActiveWindow.View.then(function(View){
  474. // 设置修订状态为最终状态
  475. View.RevisionsView = 0;
  476. // 设置修订状态为 显示标记的最终状态
  477. View.ShowRevisionsAndComments = false;
  478. });
  479. }.bind(this));
  480. },
  481. addControlButton : function(text,callback){
  482. this.wpsOffice.ready().then(function(){
  483. const app = this.wpsOffice.Application;
  484. app.CommandBars('StartTab').Controls.then(function(controls){
  485. controls.Add(1).then(function(controlButton){
  486. controlButton.Caption = text;
  487. controlButton.OnAction = callback
  488. });
  489. });
  490. }.bind(this));
  491. },
  492. print : function (){
  493. //隐藏
  494. this.wpsOffice.ready().then(function(){
  495. const app = this.wpsOffice.Application;
  496. // 页面定制对象:更多菜单
  497. app.CommandBars('TabPrintPreview').then(function(printMenu){
  498. printMenu.Execute();
  499. });
  500. }.bind(this));
  501. },
  502. exportPDF : function (){
  503. var p1 = this.wpsOffice.ready();
  504. p1.then(function(){
  505. const app = this.wpsOffice.WordApplication();
  506. var p2;
  507. switch (this.json.officeType){
  508. case "word":
  509. p2 = app.ActiveDocument.ExportAsFixedFormat();
  510. break;
  511. case "excel":
  512. p2 = app.ActiveWorkbook.ExportAsFixedFormat()
  513. break;
  514. case "ppt":
  515. p2 = app.ActivePresentation.ExportAsFixedFormat()
  516. }
  517. p2.then(function (pdfUrl){
  518. window.open(pdfUrl.url);
  519. });
  520. }.bind(this));
  521. },
  522. getContentControlsCount : function (callback){
  523. //获取内容控件
  524. var p1 = this.wpsOffice.ready();
  525. p1.then(function(){
  526. const app = this.wpsOffice.WordApplication();
  527. var p2 = app.ActiveDocument.ContentControls.Count;
  528. p2.then(function (count){
  529. if(callback) callback(count);
  530. });
  531. }.bind(this));
  532. },
  533. getContentControl : function (pos,callback){
  534. var p1 = this.wpsOffice.ready();
  535. p1.then(function(){
  536. const app = this.wpsOffice.WordApplication();
  537. var p2 = app.ActiveDocument.ContentControls.Item(pos);
  538. p2.then(function (contentControl){
  539. var p3 = contentControl.Title;
  540. var p4 = contentControl.Tag;
  541. var p5 = contentControl.PlaceholderText;
  542. var content = {};
  543. p3.then(function (contentTitle){
  544. content.contentTitle = contentTitle;
  545. p4.then(function (contentTag){
  546. content.contentTag = contentTag;
  547. p5.then(function (contentPlaceholderText){
  548. content.contentPlaceholderText = contentPlaceholderText;
  549. if(callback) callback(content);
  550. });
  551. });
  552. });
  553. });
  554. }.bind(this));
  555. },
  556. setContentControl : function (pos,contentTitle,contentTag,contentPlaceholderText,callback){
  557. var p1 = this.wpsOffice.ready();
  558. p1.then(function(){
  559. const app = this.wpsOffice.WordApplication();
  560. var p2 = app.ActiveDocument.ContentControls.Item(pos);
  561. p2.then(function (contentControl){
  562. contentControl.Title = contentTitle
  563. contentControl.Tag = contentTag
  564. contentControl.SetPlaceholderText({Text: contentPlaceholderText})
  565. if(callback) callback();
  566. });
  567. }.bind(this));
  568. },
  569. getOperatorsInfo : function (callback){
  570. //获取文档权限信息
  571. var p1 = this.wpsOffice.ready();
  572. p1.then(function(){
  573. const app = this.wpsOffice.WordApplication();
  574. var p2 ;
  575. switch (this.json.officeType){
  576. case "word":
  577. p2 = app.ActiveDocument.GetOperatorsInfo();
  578. break;
  579. case "excel":
  580. p2 = app.ActiveWorkbook.GetOperatorsInfo();
  581. break;
  582. case "ppt":
  583. p2 = app.ActivePresentation.GetOperatorsInfo();
  584. }
  585. p2.then(function (operatorsInfo){
  586. if(callback) callback(operatorsInfo);
  587. });
  588. }.bind(this));
  589. },
  590. getZoom : function (callback){
  591. //获取文档缩放
  592. var p1 = this.wpsOffice.ready();
  593. p1.then(function(){
  594. const app = this.wpsOffice.WordApplication();
  595. var p2 ;
  596. switch (this.json.officeType){
  597. case "word":
  598. p2 = app.ActiveDocument.ActiveWindow.View.Zoom.Percentage
  599. break;
  600. case "excel":
  601. p2 = app.ActiveWorkbook.ActiveSheetView.Zoom
  602. break;
  603. case "ppt":
  604. p2 = app.ActivePresentation.View.Zoom
  605. }
  606. p2.then(function (zoom){
  607. if(callback) callback(zoom);
  608. });
  609. }.bind(this));
  610. },
  611. setZoom : function (zoom,callback){
  612. //缩放属性值在50%到 300%之间。
  613. var p1 = this.wpsOffice.ready();
  614. p1.then(function(){
  615. const app = this.wpsOffice.Application;
  616. switch (this.json.officeType){
  617. case "word":
  618. app.ActiveDocument.ActiveWindow.View.Zoom.Percentage = zoom;
  619. break;
  620. case "excel":
  621. app.ActiveWorkbook.ActiveSheetView.Zoom = zoom;
  622. break;
  623. case "ppt":
  624. app.ActivePresentation.View.Zoom = zoom;
  625. }
  626. if(callback) callback();
  627. }.bind(this));
  628. },
  629. destroy : function (){
  630. this.wpsOffice.destroy();
  631. },
  632. reload : function (){
  633. this.destroy();
  634. this.loadDocument();
  635. },
  636. hasComments : function (callback){
  637. //是否有评论
  638. this.wpsOffice.ready().then(function(){
  639. const app = this.wpsOffice.Application;
  640. var hasComments;
  641. switch (this.json.officeType){
  642. case "word":
  643. hasComments = app.ActiveDocument.HasComments();
  644. break;
  645. case "excel":
  646. hasComments = app.ActiveWorkbook.HasComments();
  647. break;
  648. case "ppt":
  649. hasComments = app.ActivePresentation.HasComments();
  650. }
  651. Promise.resolve(hasComments).then(function(comments){
  652. if(callback) callback(comments);
  653. });
  654. }.bind(this));
  655. },
  656. showComments : function (){
  657. this.wpsOffice.ready().then(function(){
  658. const app = this.wpsOffice.Application;
  659. // 控制评论显示与否
  660. app.ActiveDocument.ActiveWindow.View.ShowComments = true;
  661. }.bind(this));
  662. },
  663. hideComments : function (callback){
  664. this.wpsOffice.ready().then(function(){
  665. const app = this.wpsOffice.Application;
  666. // 控制评论显示与否
  667. app.ActiveDocument.ActiveWindow.View.ShowComments = false;
  668. }.bind(this));
  669. },
  670. getComments : function (callback){
  671. var p1 = this.wpsOffice.ready();
  672. p1.then(function (){
  673. const app = this.wpsOffice.Application;
  674. var p2 = app.ActiveDocument.GetComments({ Offset: 0, Limit: 2000 });
  675. p2.then(function (operatorsInfo){
  676. if(callback) callback(operatorsInfo);
  677. })
  678. }.bind(this));
  679. },
  680. showPageMode : function (callback){
  681. //页面模式
  682. var p1 = this.wpsOffice.ready();
  683. p1.then(function (){
  684. const app = this.wpsOffice.Application;
  685. var p2 = app.ActiveDocument.SwitchTypoMode(false);
  686. p2.then()
  687. }.bind(this));
  688. },
  689. showUnionPageMode : function (callback){
  690. //连页模式
  691. var p1 = this.wpsOffice.ready();
  692. p1.then(function (){
  693. const app = this.wpsOffice.Application;
  694. var p2 = app.ActiveDocument.SwitchTypoMode(true);
  695. p2.then()
  696. }.bind(this));
  697. },
  698. showFileName : function (callback){
  699. //显示连页模式下的文件名
  700. this.showUnionPageMode(function (){
  701. var p1 = this.wpsOffice.ready();
  702. p1.then(function (){
  703. const app = this.wpsOffice.Application;
  704. var p2 = app.ActiveDocument.SwitchFileName(true);
  705. p2.then()
  706. }.bind(this));
  707. }.bind(this))
  708. },
  709. hideFileName : function (callback){
  710. //显示连页模式下的文件名
  711. var p1 = this.wpsOffice.ready();
  712. p1.then(function (){
  713. const app = this.wpsOffice.Application;
  714. var p2 = app.ActiveDocument.SwitchFileName(false);
  715. p2.then()
  716. }.bind(this));
  717. },
  718. showDocumentMap : function (callback){
  719. // debugger
  720. //连页模式
  721. // var promise = async () =>{
  722. // await this.wpsOffice.ready();
  723. // const app = this.wpsOffice.Application;
  724. // app.ActiveDocument.ActiveWindow.DocumentMap = true
  725. // if(callback) callback();
  726. // }
  727. // promise();
  728. var promise = new Promise(function(resolve, reject){
  729. this.wpsOffice.ready();
  730. resolve();
  731. }.bind(this));
  732. promise.then(function(){
  733. const app = this.wpsOffice.Application;
  734. app.ActiveDocument.ActiveWindow.DocumentMap = true;
  735. if(callback) callback();
  736. }.bind(this));
  737. },
  738. hideDocumentMap : function (callback){
  739. //连页模式
  740. var promise = new Promise(function(resolve, reject){
  741. this.wpsOffice.ready();
  742. resolve();
  743. }.bind(this));
  744. promise.then(function(){
  745. const app = this.wpsOffice.Application;
  746. app.ActiveDocument.ActiveWindow.DocumentMap = false;
  747. if(callback) callback();
  748. }.bind(this));
  749. },
  750. });