国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

springboot vue 初步集成onlyoffice

這篇具有很好參考價值的文章主要介紹了springboot vue 初步集成onlyoffice。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。


前言

對接onlyoffice,實現(xiàn)文檔的預(yù)覽和在線編輯功能。

一、vue + ts

1. 安裝依賴

npm install --save @onlyoffice/文檔-editor-vue
# or
yarn add @onlyoffice/document-editor-vue

2. onlyoffice組件實現(xiàn)

<template>
  <DocumentEditor
      id="docEditor"
      :documentServerUrl="documentServerUrl"
      :config="config"
  />
</template>

<script lang="ts" setup>
import type {IConfig} from "@onlyoffice/document-editor-vue";
import {DocumentEditor} from "@onlyoffice/document-editor-vue";

defineProps<{
  documentServerUrl: string,
  config: IConfig
}>()

</script>

3. 使用組件

<template>
  <div class="container_div">
    <back-history :msg="fileName"/>
    <only-office :documentServerUrl="getGlobalConfig().onlyOffice.documentServerUrl" :config="config"/>
  </div>
</template>

<script setup lang="ts">
import onlyOffice from '../../components/onlyOffice.vue'
import {reactive, ref} from "vue"
import BackHistory from "@/components/BackHistory.vue"
import Guid from 'guid'
import {useRoute} from "vue-router"
import {getGlobalConfig} from "@/utils/globalConfig"

let route = useRoute()
let data = JSON.parse(decodeURIComponent(<string>route.query.params))

let fileId = data.id
let title = ref(data.fileName)
let fileName = ref(title.value.slice(0, title.value.lastIndexOf('.')))
let fileType = data.ext

//從配置文件讀取onlyoffice配置
const editorConfig = getGlobalConfig().onlyOffice.editorConfig
editorConfig.callbackUrl += fileId

function handleDocType(fileType) {
  let docType = '';
  let fileTypesDoc = [
    'doc', 'docm', 'docx', 'dot', 'dotm', 'dotx', 'epub', 'fodt', 'htm', 'html', 'mht', 'odt', 'ott', 'pdf', 'rtf', 'txt', 'djvu', 'xps'
  ];
  let fileTypesCsv = [
    'csv', 'fods', 'ods', 'ots', 'xls', 'xlsm', 'xlsx', 'xlt', 'xltm', 'xltx'
  ];
  let fileTypesPPt = [
    'fodp', 'odp', 'otp', 'pot', 'potm', 'potx', 'pps', 'ppsm', 'ppsx', 'ppt', 'pptm', 'pptx'
  ];
  if (fileTypesDoc.includes(fileType)) {
    docType = 'word'
  }
  if (fileTypesCsv.includes(fileType)) {
    docType = 'cell'
  }
  if (fileTypesPPt.includes(fileType)) {
    docType = 'slide'
  }
  return docType;
}

let config =
    {
      documentType: handleDocType(fileType),
      document: reactive<any>({
        fileType: fileType,
        key: Guid.raw(),
        title: title,
        url: data.url
      }),
      editorConfig: editorConfig,
      height: '850'
    }
</script>

4. 我的配置文件

{
  "onlyOffice": {
    "documentServerUrl": "onlyoffice 服務(wù)地址",
    "editorConfig": {
      "callbackUrl": "http://172.0.0.139:8095/api/gsdss/file/v1/onlyoffice/save?fileId=",
      "lang": "zh-CN"
    }
  }
}

二、springboot 回調(diào)代碼

1. 本地存儲

        /**
     * onlyOfficeCallBack
     */
    @ApiOperationSupport(order = 10)
    @PostMapping(value = "/v1/onlyoffice/save")
    public String onlyOfficeCallBack(String fileId, HttpServletRequest request, HttpServletResponse response) {
        return service.onlyOfficeCallBack(request, response, fileId);
    }


	@Override
    public String onlyOfficeCallBack(HttpServletRequest request, HttpServletResponse response, String fileId) {
        Scanner scanner;
        try {
            scanner = new Scanner(request.getInputStream()).useDelimiter("\\A");
            String body = scanner.hasNext() ? scanner.next() : "";
            OfficeFileResp jsonObj = JsonUtil.of(body, OfficeFileResp.class);
            
            if (jsonObj.getStatus() == 2) {
                String downloadUri = jsonObj.getUrl();
                URL url = new URL(downloadUri);
                HttpURLConnection connection = (java.net.HttpURLConnection) url.openConnection();
                InputStream stream = connection.getInputStream();
                //查詢附件信息,以獲取附件存儲路徑
                AttachmentPO po = findById(fileId);
                File savedFile = new File(po.getPath());
                try (FileOutputStream out = new FileOutputStream(savedFile)) {
                    int read;
                    final byte[] bytes = new byte[1024];
                    while ((read = stream.read(bytes)) != -1) {
                        out.write(bytes, 0, read);
                    }
                    out.flush();
                }
                connection.disconnect();
            }
            return "{\"error\":0}";
        } catch (IOException e) {
            throw new BusinessException("onlyOffice 保存回調(diào)失敗", e);
        }
    }

三、效果展示

springboot vue 初步集成onlyoffice,【Java技術(shù)】,【前端】,spring boot,vue.js,后端,onlyoffice
修改離開當(dāng)前頁面后會自動觸發(fā)保存,大約5秒后下載文件,文件已經(jīng)是最新。

踩坑總結(jié)

問題1

The document could not be saved. Please check connection settings or
contact your administratorWhen you click the ‘Ok’ button, you will be
prompted to download the document.
(這份文件無法保存。請檢查連接設(shè)置或聯(lián)系您的管理員當(dāng)你點擊“OK“按鈕,系統(tǒng)將提示您下載文檔。)

回調(diào)接口不通導(dǎo)致,callbackUrl必須是onlyoffice所在服務(wù)器可訪問的接口地址,可以進(jìn)入docker鏡像內(nèi)部查看onlyoffice日志就會有所發(fā)現(xiàn)。

docker exec -it 【鏡像id】/bin/bash

tail -f /var/log/onlyoffice/documentserver/docservice/out.log-20230805

Error: connect ECONNREFUSED 127.0.0.1:8194
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1107:14)
[2023-08-07T00:57:50.813] [ERROR] nodeJS - postData error: docId = fc5d1b8f6211403fa8788661007ccd42;url = https://localhost:8194/api/gsdss/file/v1/onlyoffice/save;data = {“key”:“fc5d1b8f6211403fa8788661007ccd42”,“status”:1,“users”:[“uid-1691118844328”],“actions”:[{“type”:1,“userid”:“uid-1691118844328”}]}

問題2

文件版本已更改(The file version has been changed)

document.key 每次編輯和保存文檔時,都必須重新生成,目前采用的guid,但是沒有捕獲編輯后保存的事件去改變,而是每次加載都用新的key

有價值的參考:

  1. https://www.onlyoffice.org.cn/guide/parameters.html
  2. https://blog.csdn.net/qq_43548590/article/details/129948103
  3. https://www.jianshu.com/p/2d4f977ffeac
  4. https://api.onlyoffice.com/editors/config/
  5. https://devpress.csdn.net/viewdesign/64084b4b986c660f3cf917ba.html

springboot vue 初步集成onlyoffice,【Java技術(shù)】,【前端】,spring boot,vue.js,后端,onlyoffice文章來源地址http://www.zghlxwxcb.cn/news/detail-636622.html

到了這里,關(guān)于springboot vue 初步集成onlyoffice的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • onlyoffice的介紹搭建、集成過程。Windows、Linux

    onlyoffice的介紹搭建、集成過程。Windows、Linux

    項目中用到的技術(shù),做個筆記哈~ 在本地服務(wù)器上安裝ONLYOFFICE Docs Community Edition Community Edition允許您在本地服務(wù)器上安裝ONLYOFFICE文檔,并將在線編輯器與ONLYOFFICE協(xié)作平臺或其他流行系統(tǒng)集成。 ONLYOFFICE Docs是一個在線辦公套件,包括文本、電子表格和演示文稿的查看器和編輯

    2024年01月19日
    瀏覽(51)
  • Nextcloud 集成 onlyoffice 配置 apache 反向 SSL 反向代理填坑

    onlyoffice nextcloud Apache? 反向代理 nginx Error while downloading the document file to be converted 一臺服務(wù)器設(shè)備安裝了很多 docker 服務(wù),包括 nextcloud 和 onlyoffice 和 apache。nextcloud、onlyoffice 服務(wù)默認(rèn)使用 10001 和 10002 端口映射到兩個服務(wù)的 80 端口。直接訪問是通過 80 端口訪問的,沒有 SSL 加

    2024年01月21日
    瀏覽(15)
  • kafka:java集成 kafka(springboot集成、客戶端集成)

    kafka:java集成 kafka(springboot集成、客戶端集成)

    摘要 對于java的kafka集成,一般選用springboot集成kafka,但可能由于對接方kafka老舊、kafka不安全等問題導(dǎo)致kafak版本與spring版本不兼容,這個時候就得自己根據(jù)kafka客戶端api集成了。 一、springboot集成kafka 具體官方文檔地址:https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/

    2023年04月22日
    瀏覽(94)
  • SpringBoot2+Vue2實戰(zhàn)(十四)springboot集成redis實現(xiàn)緩存

    添加redis緩存之后就不會一直刷新數(shù)據(jù)庫,減少數(shù)據(jù)庫壓力 pom.xml依賴 也可以自定義key,要用 \\\' \\\' 括起來 fileController 數(shù)據(jù)庫執(zhí)行刪除之后,第一次緩存也刪除,后面就不會請求數(shù)據(jù)庫 pom.xml application.yml EchartController 操作完數(shù)據(jù)庫更新緩存操作:(增刪改時使用) 第一種方法:

    2024年02月13日
    瀏覽(14)
  • springboot項目引入onlyoffice多人協(xié)同編輯文檔

    采用docker安裝很方便,例如我服務(wù)器ip為? ? 172.12.2.333 安裝后訪問? ?http://172.12.2.333:8888 訪問成功即可 參考Spring-Boot-onlyOffice: springboot集成onlyOffice的實現(xiàn)。在參考網(wǎng)絡(luò)上的資料結(jié)合自身實際情況總結(jié),讓集成oo方便快捷。 封裝了oo服務(wù)的API和統(tǒng)一了配置。 ?1.上面下載下來后,

    2024年01月20日
    瀏覽(21)
  • 科大訊飛語音合成Java springboot集成

    科大訊飛語音合成 文本轉(zhuǎn)語音 一、引入依賴: 二、下載響應(yīng)的sdk,我這里是下載的java win版本的sdk SDK下載 - 科大訊飛api接口 - 訊飛開放平臺 三、具體代碼: 從下載的依賴?yán)锩嬲业綄?yīng)文件,給代碼里面替換成你的絕對路徑,運行即可 備注:這個地方需要你自己的賬號下載

    2024年02月15日
    瀏覽(18)
  • SpringBoot和Vue2集成WebSocket,實現(xiàn)聊天室功能

    springboot集成websocket實現(xiàn)聊天室的功能。如有不足之處,還望大家斧正。

    2024年01月23日
    瀏覽(27)
  • WebView2 的初步集成與試用

    WebView2 的初步集成與試用

    目錄 一、環(huán)境概況 二、安裝 三、集成測試 ?參考資料 ? ? ? ? 由于以前公司自己集成了一個瀏覽器供客戶使用,而原來的瀏覽器使用的是IWebBrowser2的技術(shù),而IWebBrowser2技術(shù)支持的IE框架只能到ie11,但由于現(xiàn)在新的js框架橫行,而且加上windows放棄了IE瀏覽器,而有的客戶項目

    2024年02月05日
    瀏覽(24)
  • Java21 + SpringBoot3集成WebSocket

    Java21 + SpringBoot3集成WebSocket

    近日心血來潮想做一個開源項目,目標(biāo)是做一款可以適配多端、功能完備的模板工程,包含后臺管理系統(tǒng)和前臺系統(tǒng),開發(fā)者基于此項目進(jìn)行裁剪和擴展來完成自己的功能開發(fā)。 本項目為前后端分離開發(fā),后端基于 Java21 和 SpringBoot3 開發(fā),前端提供了vue、angular、react、uniap

    2024年01月23日
    瀏覽(62)
  • 【Java系列】SpringBoot 集成MongoDB 詳細(xì)介紹

    【Java系列】SpringBoot 集成MongoDB 詳細(xì)介紹

    目錄 寫在前面 一、步驟介紹 步驟 1: 添加 MongoDB 依賴 步驟 2: 配置 MongoDB 連接信息 步驟 3: 創(chuàng)建實體類 步驟 4: 創(chuàng)建 Repository 接口 步驟 5: 使用 Repository 進(jìn)行操作 二、特殊處理 在Spring Boot中集成MongoDB的過程相對簡單,以下是一個基本的步驟指南。確保項目已經(jīng)使用了Spring Boo

    2024年02月04日
    瀏覽(22)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包