index.vue 3.1 KB

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