index.vue 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <!--onlyoffice 编辑器-->
  2. <template>
  3. <div>
  4. <div id="editorDiv" ref="editor" class="nav" />
  5. </div>
  6. </template>
  7. <script>
  8. import { handleDocType } from '@/business/platform/file/attachment/editFile/editor/editor.js'
  9. import { getToken } from '@/utils/auth'
  10. export default {
  11. name: 'editor',
  12. data() {
  13. return {
  14. doctype: '',
  15. newId: '',
  16. timer: '',
  17. configKey: '',
  18. option: {},
  19. hasRole: localStorage.getItem('hasHighRole') === '1'
  20. }
  21. },
  22. watch: {
  23. option: {
  24. handler: function (n, o) {
  25. this.setEditor(n)
  26. this.doctype = handleDocType(n.fileType)
  27. },
  28. deep: true
  29. }
  30. },
  31. mounted() {
  32. this.option = this.$route.query
  33. /* 调用初始化方法 ,渲染wps*/
  34. if (this.option.url) {
  35. this.setEditor(this.option)
  36. }
  37. },
  38. methods: {
  39. setEditor(option) {
  40. this.doctype = handleDocType(option.fileType)
  41. const url = option.url + '&access_token=' + getToken()
  42. console.log('url:' + url)
  43. const config = {
  44. document: {
  45. fileType: option.fileType,
  46. key: option.key,
  47. title: option.title,
  48. permissions: {
  49. comment: true,
  50. copy: true,
  51. download: this.hasRole,
  52. modifyContentControl: true,
  53. modifyFilter: true,
  54. print: this.hasRole,
  55. edit: true,
  56. fillForms: true,
  57. review: true
  58. },
  59. url: url
  60. },
  61. documentType: this.doctype,
  62. editorConfig: {
  63. callbackUrl: option.editUrl,
  64. lang: 'zh',
  65. canHistoryRestore: true,
  66. canUseHistory: true,
  67. customization: {
  68. commentAuthorOnly: false,
  69. comments: true,
  70. compactHeader: false,
  71. compactToolbar: true,
  72. plugins: true,
  73. feedback: {
  74. // 隐藏反馈按钮
  75. visible: false
  76. },
  77. // true 表示强制文件保存请求添加到回调处理程序
  78. forcesave: true,
  79. // 取消强制保存,进行手动保存
  80. atuosave: false
  81. },
  82. user: {
  83. id: this.$store.getters.userId,
  84. name: this.$store.getters.name
  85. },
  86. mode: option.mode
  87. },
  88. width: '100%',
  89. height: document.body.clientHeight + 'px'
  90. }
  91. const docEditor = new DocsAPI.DocEditor('editorDiv', config)
  92. this.configKey = config.document.key
  93. }
  94. }
  95. }
  96. </script>