oo.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <!--onlyoffice 编辑器-->
  2. <template>
  3. <div id='vabOnlyOffice'></div>
  4. </template>
  5. <script>
  6. export default {
  7. name: 'VabOnlyOffice',
  8. props: {
  9. option: {
  10. type: Object,
  11. default: () => {
  12. return {}
  13. },
  14. },
  15. },
  16. data() {
  17. return {
  18. doctype: '',
  19. docEditor: null,
  20. }
  21. },
  22. beforeDestroy() {
  23. if (this.docEditor !== null) {
  24. this.docEditor.destroyEditor();
  25. this.docEditor = null;
  26. }
  27. },
  28. watch: {
  29. option: {
  30. handler: function(n) {
  31. this.setEditor(n)
  32. this.doctype = this.getFileType(n.fileType)
  33. },
  34. deep: true,
  35. },
  36. },
  37. mounted() {
  38. if (this.option.url) {
  39. this.setEditor(this.option)
  40. }
  41. },
  42. methods: {
  43. async setEditor(option) {
  44. if (this.docEditor !== null) {
  45. this.docEditor.destroyEditor();
  46. this.docEditor = null;
  47. }
  48. this.doctype =this.getFileType(option.fileType);
  49. let config = {
  50. document: {
  51. //后缀
  52. fileType: option.fileType,
  53. key: option.key || '',
  54. title: option.title,
  55. permissions: {
  56. edit: option.isEdit, //是否可以编辑: 只能查看,传false
  57. print: option.isPrint, //是否可以打印
  58. download: option.isEdit, //是否可以下载
  59. // "fillForms": true,//是否可以填写表格,如果将mode参数设置为edit,则填写表单仅对文档编辑器可用。 默认值与edit或review参数的值一致。
  60. // "review": true //跟踪变化
  61. },
  62. url: option.url,
  63. },
  64. documentType: this.doctype,
  65. editorConfig: {
  66. callbackUrl: option.editUrl, //"编辑word后保存时回调的地址,这个api需要自己写了,将编辑后的文件通过这个api保存到自己想要的位置
  67. lang: option.lang, //语言设置
  68. //定制
  69. customization: {
  70. autosave: false, //是否自动保存
  71. chat: false,
  72. comments: false,
  73. help: false,
  74. // "hideRightMenu": false,//定义在第一次加载时是显示还是隐藏右侧菜单。 默认值为false
  75. //是否显示插件
  76. plugins: false,
  77. },
  78. user: {
  79. id: option.user.id,
  80. name: option.user.name
  81. },
  82. mode: option.model ? option.model : 'edit',
  83. // 定义共享编辑模式(快速fast/严格strict), change为控制是否允许修改
  84. coEditing: {
  85. mode: 'fast',
  86. change: false
  87. }
  88. },
  89. width: '100%',
  90. height: document.body.clientHeight-110,
  91. token: option.token || ''
  92. }
  93. // eslint-disable-next-line no-undef,no-unused-vars
  94. this.docEditor = new DocsAPI.DocEditor('vabOnlyOffice', config)
  95. },
  96. getFileType(fileType) {
  97. let docType = ''
  98. let fileTypesDoc = [
  99. 'doc', 'docm', 'docx', 'dot', 'dotm', 'dotx', 'epub', 'fodt', 'htm', 'html', 'mht', 'odt', 'ott', 'pdf',
  100. 'rtf', 'txt', 'djvu', 'xps',
  101. ]
  102. let fileTypesCsv = [
  103. 'csv', 'fods', 'ods', 'ots', 'xls', 'xlsm', 'xlsx', 'xlt', 'xltm', 'xltx',
  104. ]
  105. let fileTypesPPt = [
  106. 'fodp', 'odp', 'otp', 'pot', 'potm', 'potx', 'pps', 'ppsm', 'ppsx', 'ppt', 'pptm', 'pptx',
  107. ]
  108. if (fileTypesDoc.includes(fileType)) {
  109. docType = 'word'
  110. }
  111. if (fileTypesCsv.includes(fileType)) {
  112. docType = 'cell'
  113. }
  114. if (fileTypesPPt.includes(fileType)) {
  115. docType = 'slide'
  116. }
  117. return docType
  118. }
  119. },
  120. }
  121. </script>