解决思路:
1、监听出现警告的事件:已经实现
<script setup>
import {message} from "ant-design-vue";
const onError = (event) => {
console.log("ONLYOFFICE Document Editor reports an error: code " + event.data.errorCode + ", description " + event.data.errorDescription);
};
const onWarning = (event) => {
console.log("ONLYOFFICE Document Editor reports a warning: code " + event.data.warningCode + ", description " + event.data.warningDescription);
console.log("event=", event)
return true
}
const onLoadDocumentClick = () => {
message.success("load document")
// isDocument.value = true
new DocsAPI.DocEditor("doc", {
"events": {
"onError": onError,
"onWarning": onWarning,
},
"document": {
"fileType": "docx",
"key": `Khirz6zTPdfd7`,
"title": "Example Document Title.docx",
"url": "http://192.168.234.138:18888/dist/test.docx"
},
"editorConfig": {
"callbackUrl": "http://192.168.234.138:18888/callback",
"lang": "zh-CN",
"user": {
"id": "1",
"name": "zdp"
},
"customization": {
"forcesave": true,
},
"coEditing": {
"mode": "fast",
"change": true
},
},
"documentType": "word",
height: '500px',
width: '100%',
token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkb2N1bWVudCI6eyJmaWxlVHlwZSI6ImRvY3giLCJrZXkiOiJLaGlyejZ6VFBkZmQ3IiwidGl0bGUiOiJFeGFtcGxlIERvY3VtZW50IFRpdGxlLmRvY3giLCJ1cmwiOiJodHRwOi8vMTkyLjE2OC4yMzQuMTM4OjE4ODg4L2Rpc3QvdGVzdC5kb2N4In0sImVkaXRvckNvbmZpZyI6eyJjYWxsYmFja1VybCI6Imh0dHA6Ly8xOTIuMTY4LjIzNC4xMzg6MTg4ODgvY2FsbGJhY2siLCJsYW5nIjoiemgtQ04iLCJ1c2VyIjp7ImlkIjoiMSIsIm5hbWUiOiJ6ZHAifSwiY3VzdG9taXphdGlvbiI6eyJmb3JjZXNhdmUiOnRydWV9LCJjb0VkaXRpbmciOnsibW9kZSI6ImZhc3QiLCJjaGFuZ2UiOnRydWV9fSwiZG9jdW1lbnRUeXBlIjoid29yZCIsImhlaWdodCI6IjUwMHB4Iiwid2lkdGgiOiIxMDAlIn0.vnSYKU22-IsBmuoSn5Po-Ukz1RrnM-G3ch3-JuJd1xg",
});
}
</script>
<template>
<div class="bg-indigo-50 p-8 min-h-screen">
<div class="bg-amber-200 p-8">
<a-button type="primary" @click="onLoadDocumentClick">Load Document</a-button>
</div>
<div class="bg-amber-400 p-8 min-h-96">
<div id="doc">doc</div>
</div>
</div>
</template>
2、检查如何在警告的回调函数中,返回某个值,或者阻止事件的继续传播,以解决出现警告弹窗的问题。目前主要解决方案是查阅官方源码:
https://github.com/ONLYOFFICE/sdkjs/blob/master/common/errorCodes.js