From b871888a4ee32d15adfd52fdfabc44c7c674db0e Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期四, 17 九月 2026 16:36:45 +0800
Subject: [PATCH] 新疆——新聚lims 1.标准维护预览附件问题
---
src/components/Onlyoffice/onlyoffice.vue | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 51 insertions(+), 7 deletions(-)
diff --git a/src/components/Onlyoffice/onlyoffice.vue b/src/components/Onlyoffice/onlyoffice.vue
index a903641..1c1e261 100644
--- a/src/components/Onlyoffice/onlyoffice.vue
+++ b/src/components/Onlyoffice/onlyoffice.vue
@@ -4,6 +4,37 @@
</template>
<script>
+// OnlyOffice 鏂囨。鏈嶅姟鍦板潃锛屾寜鐜閰嶇疆锛涜剼鏈湪鐪熸闇�瑕侀瑙堟椂鎵嶅姞杞�
+const OFFICE_API_BASE = process.env.VUE_APP_ONLYOFFICE_API || "http://192.168.21.53:9001";
+
+// 澶氫釜椤甸潰鍏辩敤缂栬緫鍣紝api.js 鍙姞杞戒竴娆�
+let docsApiPromise = null;
+function loadDocsApi() {
+ if (window.DocsAPI) {
+ return Promise.resolve(window.DocsAPI);
+ }
+ if (!docsApiPromise) {
+ docsApiPromise = new Promise((resolve, reject) => {
+ const script = document.createElement("script");
+ script.src = OFFICE_API_BASE.replace(/\/$/, "") + "/web-apps/apps/api/documents/api.js";
+ script.onload = () => {
+ if (window.DocsAPI) {
+ resolve(window.DocsAPI);
+ } else {
+ reject(new Error("api.js 鍔犺浇瀹屾垚浣嗘湭娉ㄥ唽 DocsAPI"));
+ }
+ };
+ script.onerror = () => reject(new Error("OnlyOffice 鏂囨。鏈嶅姟鑴氭湰鍔犺浇澶辫触锛�" + script.src));
+ document.head.appendChild(script);
+ });
+ // 鍔犺浇澶辫触鍚庡厑璁镐笅娆¢噸璇�
+ docsApiPromise.catch(() => {
+ docsApiPromise = null;
+ });
+ }
+ return docsApiPromise;
+}
+
export default {
name: "VabOnlyOffice",
props: ['options'],
@@ -50,10 +81,7 @@
}
},
beforeDestroy() {
- if (this.docEditor !== null) {
- this.docEditor.destroyEditor();
- this.docEditor = null;
- }
+ this.destroyEditor();
},
watch: {
option: {
@@ -70,10 +98,17 @@
}
},
methods: {
- async setEditor(option) {
+ destroyEditor() {
if (this.docEditor !== null) {
this.docEditor.destroyEditor();
this.docEditor = null;
+ }
+ },
+ async setEditor(option) {
+ this.destroyEditor();
+ // 娌℃湁鏂囨。鍦板潃灏变笉鍒濆鍖栫紪杈戝櫒锛岄伩鍏嶈闂皻鏈姞杞界殑 DocsAPI
+ if (!option || !option.url) {
+ return;
}
this.doctype = this.getFileType(option.fileType);
let config = {
@@ -116,8 +151,17 @@
token: option.token || ""
};
- // eslint-disable-next-line no-undef,no-unused-vars
- this.docEditor = new DocsAPI.DocEditor("vabOnlyOffice", config);
+ try {
+ await loadDocsApi();
+ } catch (error) {
+ console.error(error);
+ this.$message.error("鏂囨。鏈嶅姟鏆傛椂涓嶅彲鐢紝鏃犳硶棰勮");
+ return;
+ }
+ if (this._isDestroyed) {
+ return;
+ }
+ this.docEditor = new window.DocsAPI.DocEditor("vabOnlyOffice", config);
},
getFileType(fileType) {
let docType = "";
--
Gitblit v1.9.3