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.

func_docEvents.js 3.4KB

7 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //切换窗口时触发的事件
  2. function OnWindowActivate() {
  3. console.log("OnWindowActivate" + "=======================");
  4. showOATab(); // 根据文件是否为OA文件来显示OA菜单再进行刷新按钮
  5. setTimeout(activeTab, 2000); // 激活页面必须要页签显示出来,所以做1秒延迟
  6. return;
  7. }
  8. function OnPresentationBeforeClose(doc) {
  9. console.log('OnPresentationClose');
  10. var l_fullName = doc.FullName;
  11. var l_bIsOADoc = false;
  12. l_bIsOADoc = CheckIfDocIsOADoc(doc); //判断是否OA文档要关闭
  13. if (l_bIsOADoc == false) { // 非OA文档不做处理
  14. return;
  15. }
  16. if (doc.Saved == false) { //如果OA文档关闭前,有未保存的数据
  17. if (wps.confirm("系统文件有改动,是否提交后关闭?" + "\n" + "确认后请按上传按钮执行上传操作。取消则继续关闭文档。")) {
  18. wps.ApiEvent.Cancel = true;
  19. return;
  20. }
  21. }
  22. wps.ApiEvent.RemoveApiEventListener("PresentationBeforeClose", OnPresentationBeforeClose);
  23. doc.Close();
  24. wps.ApiEvent.AddApiEventListener("PresentationBeforeClose", OnPresentationBeforeClose);
  25. pSetNoneOADocFlag(l_fullName);
  26. closeWppIfNoDocument(); // 判断文件个数是否为0,若为0则关闭组件
  27. wps.FileSystem.Remove(l_fullName);
  28. }
  29. /**
  30. * 作用:判断当前文档是否从OA来的文档,如果非OA文档(就是本地新建或打开的文档,则设置EnumOAFlag 标识)
  31. * 作用:设置非OA文档的标识状态
  32. * @param {*} doc
  33. * 返回值:无
  34. */
  35. function pSetNoneOADocFlag(fullName) {
  36. var l_param = wps.PluginStorage.getItem(fullName); //定义JSON文档参数
  37. var l_objParams = new Object();
  38. if (l_param) {
  39. l_objParams = JSON.parse(l_param);
  40. }
  41. l_objParams.isOA = EnumOAFlag.DocFromNoOA; // 新增非OA打开文档属性
  42. wps.PluginStorage.setItem(fullName, JSON.stringify(l_objParams)); // 存入内存中
  43. }
  44. /**
  45. * 权限点集合
  46. */
  47. var ksoRightsInfo = {
  48. ksoNoneRight: 0x0000,
  49. ksoModifyRight: 0x0001,
  50. ksoCopyRight: 0x0002,
  51. ksoPrintRight: 0x0004,
  52. ksoSaveRight: 0x0008,
  53. ksoBackupRight: 0x0010,
  54. ksoVbaRight: 0x0020,
  55. ksoSaveAsRight: 0x0040,
  56. ksoFullRight: -1
  57. }
  58. var gRightsInfo = ksoRightsInfo.ksoFullRight;
  59. /**
  60. * 设置文档的权限
  61. *
  62. * @param {*} rightsInfo
  63. * 所有权限: ksoRightsInfo.ksoFullRight
  64. * 备份权限: ksoRightsInfo.ksoFullRight & ~ksoRightsInfo.ksoBackupRight
  65. * 另存权限: ksoRightsInfo.ksoFullRight & ~ksoRightsInfo.ksoSaveAsRight
  66. * 类似保护模式: ksoRightsInfo.ksoFullRight & ~ksoRightsInfo.ksoBackupRight & ~ksoRightsInfo.ksoSaveAsRight & ~ksoRightsInfo.ksoSaveRight & ~ksoRightsInfo.ksoPrintRight & ~ksoRightsInfo.ksoCopyRight
  67. */
  68. function setDocumentRights(rightsInfo) {
  69. gRightsInfo = rightsInfo;
  70. var l_doc = wps.WppApplication().ActivePresentation;
  71. if (l_doc) {
  72. l_doc.InvalidateRightsInfo();
  73. wps.ribbonUI.Invalidate();
  74. }
  75. }
  76. /**
  77. * 设置权限的事件实现
  78. *
  79. * @param {*} doc
  80. */
  81. function OnDocumentRightsInfo(doc) {
  82. var curRightsInfo = wps.ApiEvent.RightsInfo;
  83. wps.ApiEvent.RightsInfo = gRightsInfo;
  84. }
  85. /**
  86. * 针对权限的功能可用状态判断
  87. *
  88. * @returns
  89. */
  90. function OnSetSaveAsRightsEnable() {
  91. if (gRightsInfo & ksoRightsInfo.ksoSaveAsRight)
  92. return true;
  93. else
  94. return false;
  95. }