• docker 安装 onlyoffice


    1.文档地址

    Installing ONLYOFFICE Docs for Docker on a local server - ONLYOFFICE

    2.安装onlyoffice

    docker run -i -t -d -p 9000:8000 --restart=always -e JWT_ENABLED=false onlyoffice/documentserver

    如果发现镜像无法下载,可以尝试更换镜像源

    1. {
    2. "registry-mirrors": [
    3. "https://do.nark.eu.org",
    4. "https://dc.j8.work",
    5. "https://docker.m.daocloud.io",
    6. "https://dockerproxy.com",
    7. "https://docker.mirrors.ustc.edu.cn",
    8. "https://docker.nju.edu.cn"
    9. ]
    10. }

     参考从Docker Hub 拉取镜像一直失败超时?这些解决方案帮你解决烦恼_docker拉取镜像超时-CSDN博客

    3.启动成功后,访问服务,查看服务是否启动成功

     访问时,localhost和127.0.0.1都可以试试,可能有些不能访问

    访问 http://localhost:9000/welcome/

    访问 http://localhost:9000/web-apps/apps/api/documents/api.js

    说明启动成功

    4.集成到vue 

    <script type='text/javascript' src='http://localhost:9000/web-apps/apps/api/documents/api.js'></script>

    1. //onlyoffice测试
    2. {
    3. path: "/onlyoffice",
    4. name: "onlyoffice",
    5. component: () => import("@/views/onlyoffice/test.vue"),
    6. },

    test.vue 文件内容

    1. <template>
    2. <div id="app">
    3. <div class="qualityManual-container">
    4. <div>
    5. <button style="width: 120px" type="primary" @click="getFile">
    6. 测试预览office文档
    7. </button>
    8. <button style="width: 120px" type="primary" @click="close">关闭</button>
    9. </div>
    10. <div v-if="show" class="qualityManual-container-office">
    11. <vab-only-office :option="option" />
    12. </div>
    13. </div>
    14. </div>
    15. </template>
    16. <script>
    17. import vabOnlyOffice from "./VabOnlyOffice.vue";
    18. export default {
    19. name: "App",
    20. components: {
    21. vabOnlyOffice,
    22. },
    23. data() {
    24. return {
    25. //参考vabOnlyOffice组件参数配置
    26. option: {
    27. url:
    28. "http://192.168.0.104:8003/system/api/file/attachment/2024-07-13/1812066832136409088.docx",
    29. isEdit: "",
    30. fileType: "",
    31. title: "",
    32. lang: "",
    33. isPrint: "",
    34. user: { id: null, name: "" },
    35. },
    36. show: false,
    37. };
    38. },
    39. methods: {
    40. getFile() {
    41. this.show = true;
    42. // getAction('/file/selectById', { id: this.id }).then(res => {
    43. this.option.isEdit = false;
    44. this.option.lang = "zh-CN";
    45. this.option.url =
    46. "http://192.168.0.104:8003/system/api/file/attachment/2024-07-13/1812066832136409088.docx";
    47. this.option.title = "123";
    48. this.option.fileType = "docx";
    49. this.option.isPrint = false;
    50. this.option.user = { id: 12, name: "张三" };
    51. // })
    52. },
    53. close() {
    54. this.show = false;
    55. },
    56. },
    57. };
    58. </script>
    59. <style>
    60. html,
    61. body {
    62. height: 100%;
    63. }
    64. #app {
    65. font-family: Avenir, Helvetica, Arial, sans-serif;
    66. -webkit-font-smoothing: antialiased;
    67. -moz-osx-font-smoothing: grayscale;
    68. text-align: center;
    69. color: #2c3e50;
    70. height: 100%;
    71. }
    72. .qualityManual-container {
    73. padding: 0 !important;
    74. height: 100%;
    75. }
    76. .qualityManual-container-office {
    77. /* mobile
    78. width: 0px;*/
    79. /* desktop */
    80. width: 100%;
    81. height: calc(100% - 55px);
    82. }
    83. </style>

    VabOnlyOffice.vue 文件内容

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

    打开页面

    预览文档 时 如果出现 下载失败 按下面解决方法

    编辑docker中/etc/onlyoffice/documentserver/default.json​下的内容

    搜索并修改以下字段为true

    可以使用docker容器内的nano default.json 命令编辑文件,然后重启容器

    1. "request-filtering-agent" : {
    2. "allowPrivateIPAddress": true,
    3. "allowMetaIPAddress": true
    4. },

    参考文档 OnlyOffice 打开文档时提示下载失败_onlyoffice 下载失败-CSDN博客

    desktop 效果

    mobile效果

    如果需要在线编辑和保存,可参考以下文章

    SpringBoot中整合ONLYOFFICE在线编辑_springboot 集成 onlyoffice-CSDN博客

  • 相关阅读:
    HiQPdf Library for .NET - HTML to PDF Crack
    抖音开放平台第三方代小程序开发,一整套流程
    LeetCode使用JavaScript破解两数之和
    为什么客户端和服务器不支持SSL协议
    Electron中加载百度地图api调用其中方法报错:Uncaught ReferenceError: md5 is not defined
    Vue3详解
    AcWing 1282. 搜索关键词【AC自动机】
    【无标题】初识TCP,实验加抓包带你理解为什么需要三次握手、四次挥手
    十、rem适配方案
    【编程题】【Scratch三级】2021.06 计算成绩总和
  • 原文地址:https://blog.csdn.net/qq_31683775/article/details/140443361