sur-onlyoffice 1.0.8 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- import { defineComponent as S, ref as p, onMounted as v, onBeforeUnmount as L, createElementBlock as P, openBlock as Y, createCommentVNode as R, createElementVNode as B } from "vue";
2
- const _ = { class: "onlyoffice-box" }, W = "asc.{91EAC419-EF8B-440C-A960-B451C7DF3A37}", M = /* @__PURE__ */ S({
1
+ import { defineComponent as v, ref as i, onMounted as D, onBeforeUnmount as C, createElementBlock as I, openBlock as w, createCommentVNode as F, createElementVNode as A } from "vue";
2
+ const N = { class: "onlyoffice-box" }, U = "asc.{91EAC419-EF8B-440C-A960-B451C7DF3A37}", h = /* @__PURE__ */ v({
3
3
  __name: "onlyoffice",
4
4
  props: {
5
5
  config: {
@@ -17,52 +17,43 @@ const _ = { class: "onlyoffice-box" }, W = "asc.{91EAC419-EF8B-440C-A960-B451C7D
17
17
  }
18
18
  }
19
19
  },
20
- setup(b) {
21
- let i = null;
22
- const d = p(!1), c = b;
23
- console.log(c, "props");
24
- const s = c?.documentServerUrl || "https://test.xuandou.vip:126", r = s + "/web-apps/apps/api/documents/api.js", $ = s + "/8.3.1-10ca0f5dd35a63800b6a3956f350bf95/sdkjs-plugins/example_extended_comments/config.json";
25
- function I() {
20
+ setup(m) {
21
+ let l = null;
22
+ const p = i(!1), t = m;
23
+ console.log(t, "props", t?.documentServerUrl), t?.documentServerUrl || console.error("[ONLYOFFICE] documentServerUrl 不能为空");
24
+ const a = t?.documentServerUrl || "";
25
+ console.log(a, "DOCUMENT_SERVER");
26
+ const c = i(""), y = a + "/8.3.1-10ca0f5dd35a63800b6a3956f350bf95/sdkjs-plugins/example_extended_comments/config.json";
27
+ function E() {
26
28
  return new Promise((o, e) => {
27
29
  if (window.DocsAPI) return o();
28
30
  const n = document.createElement("script");
29
- n.src = r, n.onload = () => o(), n.onerror = () => e(new Error("加载 DocsAPI 失败:" + r)), document.head.appendChild(n);
31
+ if (!c.value)
32
+ return console.error("[ONLYOFFICE] documentServerUrl 不能为空"), e(new Error("[ONLYOFFICE] documentServerUrl 不能为空"));
33
+ console.log("DOCS_API", c.value), n.src = c.value, n.onload = () => o(), n.onerror = () => e(new Error("加载 DocsAPI 失败:" + c.value)), document.head.appendChild(n);
30
34
  });
31
35
  }
32
- const f = [];
33
- let a = null;
34
- function g() {
35
- a === null && (a = window.setInterval(() => {
36
- if (!(!i || typeof i.serviceCommand != "function") && d.value) {
37
- for (; f.length; ) {
38
- const { cmd: o, payload: e } = f.shift();
39
- try {
40
- console.log("[ONLYOFFICE] 发送排队指令:", o, e), i.serviceCommand(o, e);
41
- } catch (n) {
42
- console.error("[ONLYOFFICE] 队列指令发送失败:", o, n);
43
- }
44
- }
45
- a !== null && (clearInterval(a), a = null);
46
- }
47
- }, 300));
36
+ function d(o, e) {
37
+ const n = { ...o };
38
+ for (const r in e)
39
+ e.hasOwnProperty(r) && (n.hasOwnProperty(r) && typeof n[r] == "object" && n[r] !== null && !Array.isArray(n[r]) && typeof e[r] == "object" && e[r] !== null && !Array.isArray(e[r]) ? n[r] = d(n[r], e[r]) : n[r] = e[r]);
40
+ return n;
48
41
  }
49
- const m = {
42
+ let s = {
50
43
  document: {
51
44
  fileType: "docx",
52
45
  title: "Demo.docx",
53
- url: "https://qiniu2.xuandou.vip/new.docx",
54
- key: "test-key",
55
- permissions: { edit: !0 }
46
+ url: "https://badges-1302420147.cos.ap-shanghai.myqcloud.com/test1.docx",
47
+ key: ""
48
+ // permissions: { edit: true }
56
49
  },
57
50
  documentType: "word",
58
51
  editorConfig: {
59
52
  lang: "zh-CN",
60
- mode: "edit",
61
- user: { id: "u1", name: "Tester" },
62
53
  plugins: {
63
- //!
64
- autostart: [W],
65
- pluginsData: [{ url: $ + "?v=2.0." + Date.now() }]
54
+ //!!!!!
55
+ autostart: [U],
56
+ pluginsData: [{ url: y + "?v=2.0." + Date.now() }]
66
57
  // 强刷缓存
67
58
  }
68
59
  },
@@ -73,271 +64,39 @@ const _ = { class: "onlyoffice-box" }, W = "asc.{91EAC419-EF8B-440C-A960-B451C7D
73
64
  console.log("[ONLYOFFICE] 插件资源已加载,但不代表已初始化");
74
65
  },
75
66
  onDocumentReady: () => {
76
- console.log("[ONLYOFFICE] 文档已就绪"), y(), g(), console.log("window.Asc.plugin1", window?.Asc?.plugin), setTimeout(() => {
77
- console.log("window.Asc.plugin2", window), console.log("window.Asc.plugin3-editor", i.serviceCommand), i.serviceCommand("event_onAddComment", { id: 111 });
78
- }, 2e3);
67
+ console.log("[ONLYOFFICE] 文档已就绪");
79
68
  },
80
69
  onInfo: (o) => {
81
- const e = o?.data;
82
- console.log("[ONLYOFFICE] Info 事件:", o.data), o && (e?.command === "openPlugin" && (console.log("[ONLYOFFICE] openPlugin"), i.frame?.contentWindow?.Common?.Gateway?.sendInfo(e)), o.data.command === "pluginInitialized" && (d.value = !0, console.log("[ONLYOFFICE] 插件初始化完成"), g()), o.data.command === "pluginAck" && console.log("[ONLYOFFICE] 插件确认收到:", o.data), o.data.command === "pluginError" && console.error("[ONLYOFFICE] 插件错误:", o.data), o.data.command === "linkClicked" && (console.log("[ONLYOFFICE] 链接被点击,数据:", o.data.data), C(o.data.data)), o.data.command === "wordArtInserted" && (console.log("[ONLYOFFICE] WordArt 插入成功:", o.data.data), D(o.data.data)), o.data.command === "wordArtError" && (console.error("[ONLYOFFICE] WordArt 插入失败:", o.data.data), E(o.data.data)), o.data.command === "tableClicked" && (console.log("[ONLYOFFICE] 表格被点击,数据:", o.data.data), O(o.data.data)), o.data.command === "selectionAnalyzed" && (console.log("[ONLYOFFICE] 选中内容分析结果:", o.data.data), F(o.data.data)), o.data.command === "selectionBound" && (console.log("[ONLYOFFICE] 选中内容绑定完成:", o.data.data), T(o.data.data)), o.data.command === "bindingClicked" && (console.log("[ONLYOFFICE] 绑定控件被点击:", o.data.data), N(o.data.data)), o.data.command === "elementClicked" && (console.log("[ONLYOFFICE] 元素被点击:", o.data.data), w(o.data.data)), o.data.command === "preciseTableCellClicked" && (console.log("[ONLYOFFICE] 精确表格单元格被点击:", o.data.data), k(o.data.data)), o.data.command === "chartClicked" && (console.log("[ONLYOFFICE] 图表被点击:", o.data.data), A(o.data.data)));
83
70
  }
84
71
  }
72
+ }, u = i(!1);
73
+ const g = (o) => {
74
+ o.data.eventType === "customEventReplay" && console.info(o, "DDD11"), o.data.eventType === "customEventCommon" && console.info(o, "DDD22");
85
75
  };
86
- async function h() {
87
- await I();
88
- const o = window.DocsAPI;
89
- i?.destroyEditor && i.destroyEditor(), d.value = !1, c.config && (m = c.config), i = new o.DocEditor("editor", m);
90
- }
91
- function y() {
92
- try {
93
- i.executeCommand && i.executeCommand("focus"), console.log("autoOpenPluginSidePanel", i), i.serviceCommand && i.serviceCommand("sidePanel", {
94
- action: "toggle",
95
- state: !1
96
- });
97
- } catch (o) {
98
- console.error("auto-open plugin failed:", o);
76
+ async function O() {
77
+ if (t.documentServerUrl)
78
+ c.value = t.documentServerUrl + "/web-apps/apps/api/documents/api.js";
79
+ else {
80
+ console.error("[ONLYOFFICE] documentServerUrl 不能为空");
81
+ return;
99
82
  }
83
+ await E().then(() => {
84
+ console.log("[ONLYOFFICE] 加载 DocsAPI 成功");
85
+ }).catch((e) => {
86
+ console.error("[ONLYOFFICE] 加载 DocsAPI 失败:", e);
87
+ });
88
+ const o = window.DocsAPI;
89
+ l?.destroyEditor && l.destroyEditor(), p.value = !1, t.config && (s = d(s, t.config)), console.log("cfg", s), l = new o.DocEditor("editor", s);
100
90
  }
101
- function C(o) {
102
- console.log("处理链接点击事件,收到数据:", o), o && typeof o == "object" && (`${o.controlId || "unknown"}${o.controlTitle || "无标题"}${o.tag || "无Tag"}${JSON.stringify(o.data, null, 2)}${JSON.stringify(o, null, 2)}`, o.data && o.data.name && console.log("检测到用户名:", o.data.name));
103
- }
104
- function D(o) {
105
- if (console.log("WordArt 插入成功,数据:", o), o && o.success) {
106
- const e = `WordArt 插入成功!
107
-
108
- 文本: ${o.parameters?.text || "未知"}
109
- 字体大小: ${o.parameters?.fontSize || "未知"}
110
- 字体: ${o.parameters?.fontFamily || "未知"}
111
- 变换效果: ${o.parameters?.transform || "未知"}
112
-
113
- ${o.message || ""}`;
114
- confirm(e + `
115
-
116
- 点击"确定"可继续插入更多WordArt`) && console.log("用户选择继续操作WordArt");
117
- }
118
- }
119
- function E(o) {
120
- console.error("WordArt 插入失败,错误:", o), o?.error;
121
- }
122
- function O(o) {
123
- if (console.log("处理表格点击事件,收到数据:", o), o && o.success && o.data) {
124
- const e = o.data;
125
- let n = `表格被点击!
126
-
127
- `;
128
- e.clickType === "table" ? (n += `点击类型: 表格内容
129
- `, n += `表格索引: ${e.tableIndex >= 0 ? e.tableIndex : "未知"}
130
- `, n += `行索引: ${e.rowIndex >= 0 ? e.rowIndex : "未知"}
131
- `, n += `单元格索引: ${e.cellIndex >= 0 ? e.cellIndex : "未知"}
132
- `, n += `单元格文本: "${e.cellText || "空"}"
133
- `, n += `点击时间: ${e.timestamp}
134
- `, e.tableData && (n += `
135
- 表格数据结构:
136
- `, n += `- 行数: ${e.tableData.rows}
137
- `, n += `- 列数: ${e.tableData.columns}
138
- `, e.tableData.content && e.tableData.content.length > 0 && (n += `
139
- 表格内容预览:
140
- `, e.tableData.content.slice(0, 3).forEach((t, l) => {
141
- n += `第${l + 1}行: [${t.join(", ")}]
142
- `;
143
- }), e.tableData.content.length > 3 && (n += `... 还有 ${e.tableData.content.length - 3} 行
144
- `)))) : (n += `点击类型: 非表格区域
145
- `, n += `点击时间: ${e.timestamp}
146
- `), e.clickType === "table" && e.tableData && console.log("检测到表格点击,可以执行相关操作:", {
147
- tableIndex: e.tableIndex,
148
- tableData: e.tableData
149
- });
150
- } else
151
- console.log("表格点击检测失败:", o?.error || "未知错误");
152
- }
153
- function F(o) {
154
- if (console.log("处理选中内容分析结果,收到数据:", o), o && o.success && o.data) {
155
- const e = o.data;
156
- let n = `选中内容分析结果!
157
-
158
- `;
159
- n += `选择类型: ${e.selectionType}
160
- `, n += `是否可绑定: ${e.bindable ? "是" : "否"}
161
- `, n += `选中内容: "${e.content.substring(0, 50)}${e.content.length > 50 ? "..." : ""}"
162
-
163
- `, e.suggestedBindings && e.suggestedBindings.length > 0 && (n += `建议的绑定方式:
164
- `, e.suggestedBindings.slice(0, 3).forEach((t, l) => {
165
- n += `${l + 1}. ${t.description} (${t.category})
166
- `;
167
- }), e.suggestedBindings.length > 3 && (n += `... 还有 ${e.suggestedBindings.length - 3} 种绑定方式
168
- `)), n += `
169
- 分析时间: ${e.timestamp}`, e.bindable && console.log("内容可以绑定,建议绑定方式:", e.suggestedBindings);
170
- } else
171
- console.log("选中内容分析失败:", o?.error || "未知错误");
172
- }
173
- function T(o) {
174
- if (console.log("处理选中内容绑定完成,收到数据:", o), o && o.success) {
175
- const e = o.data;
176
- let n = `数据绑定完成!
177
-
178
- `;
179
- n += `绑定方法: ${e.method}
180
- `, n += `绑定类型: ${e.binding?.type || "未知"}
181
- `, e.binding && (e.binding.fieldName && (n += `字段名称: ${e.binding.fieldName}
182
- `), e.binding.dataType && (n += `数据类型: ${e.binding.dataType}
183
- `), e.binding.originalValue && (n += `原始值: "${e.binding.originalValue}"
184
- `)), n += `
185
- ${e.message}`, console.log("数据绑定成功,绑定信息:", e.binding);
186
- } else
187
- console.log("数据绑定失败:", o?.error || "未知错误");
188
- }
189
- function w(o) {
190
- if (console.log("🎯 处理通用元素点击事件,收到数据:", o), o && o.success && o.data) {
191
- const e = o.data;
192
- let n = `🎯 元素点击检测结果!
193
-
194
- `;
195
- n += `点击类型: ${e.clickType}
196
- `, n += `检测时间: ${e.timestamp}
197
-
198
- `, e.clickType === "table" ? (n += `📊 表格信息:
199
- `, n += `- 表格索引: ${e.elementInfo.tableIndex}
200
- `, n += `- 总行数: ${e.elementInfo.totalRows}
201
- `, n += `- 总列数: ${e.elementInfo.totalColumns}
202
- `, e.elementInfo.clickedCell && (n += `- 点击位置: 第${e.elementInfo.clickedCell.row}行第${e.elementInfo.clickedCell.column}列
203
- `, n += `- 单元格内容: "${e.elementInfo.clickedCellInfo?.content || "空"}"
204
- `), e.elementInfo.sampleContent && e.elementInfo.sampleContent.length > 0 && (n += `
205
- 📋 表格内容预览:
206
- `, e.elementInfo.sampleContent.slice(0, 2).forEach((t, l) => {
207
- n += `第${l + 1}行: [${t.slice(0, 3).join(", ")}${t.length > 3 ? "..." : ""}]
208
- `;
209
- }))) : e.clickType === "paragraph" ? (n += `📝 段落信息:
210
- `, n += `- 段落索引: ${e.elementInfo.paragraphIndex}
211
- `, n += `- 对齐方式: ${e.elementInfo.alignment}
212
- `, n += `- 文本长度: ${e.elementInfo.metadata?.fullTextLength || 0}字符
213
- `, n += `- 文本预览: "${e.elementInfo.text}"
214
- `) : e.clickType === "shape" ? (n += `🔷 图形信息:
215
- `, n += `- 图形索引: ${e.elementInfo.shapeIndex}
216
- `, n += `- 图形类型: ${e.elementInfo.shapeType}
217
- `, n += `- 包含内容: ${e.elementInfo.hasContent ? "是" : "否"}
218
- `) : e.clickType === "document" && (n += `📄 文档区域:
219
- `, n += `- 有选区: ${e.elementInfo.hasSelection ? "是" : "否"}
220
- `, n += `- 扫描元素: ${e.elementInfo.metadata?.totalElementsScanned || 0}个
221
- `), e.fullScanResults && (n += `
222
- 🔍 文档扫描统计:
223
- `, n += `- 表格: ${e.fullScanResults.tablesFound}个
224
- `, n += `- 段落: ${e.fullScanResults.paragraphsFound}个
225
- `, n += `- 图形: ${e.fullScanResults.shapesFound}个
226
- `), console.log("🎯 元素类型:", e.clickType, "详细信息:", e.elementInfo);
227
- } else
228
- console.log("❌ 通用元素检测失败:", o?.error || "未知错误");
229
- }
230
- function k(o) {
231
- if (console.log("📊 处理精确表格单元格点击事件,收到数据:", o), o && o.success && o.data) {
232
- const e = o.data;
233
- let n = `📊 精确表格单元格点击!
234
-
235
- `;
236
- n += `🎯 单元格位置:
237
- `, n += `- 行: 第${e.cellPosition.row}行
238
- `, n += `- 列: 第${e.cellPosition.column}列
239
- `, n += `- 单元格内容: "${e.cellContent}"
240
-
241
- `, n += `📋 表格信息:
242
- `, n += `- 总行数: ${e.tableInfo.totalRows}
243
- `, n += `- 总列数: ${e.tableInfo.totalColumns}
244
- `, n += `- 检测方法: ${e.detectionMethod}
245
- `, n += `- 检测时间: ${e.timestamp}
246
- `, console.log("📊 精确单元格信息:", {
247
- row: e.cellPosition.row,
248
- column: e.cellPosition.column,
249
- content: e.cellContent,
250
- tableInfo: e.tableInfo
251
- }), e.cellPosition.row === 1 ? console.log("🎯 点击了表头行,可以执行排序等操作") : console.log("🎯 点击了数据行,可以执行编辑等操作");
252
- } else
253
- console.log("❌ 精确表格单元格检测失败:", o?.error || "未知错误");
254
- }
255
- function A(o) {
256
- if (console.log("📈 处理图表点击事件,收到数据:", o), o && o.success && o.data) {
257
- const e = o.data;
258
- let n = `📈 图表点击检测结果!
259
-
260
- `;
261
- if (n += `点击类型: ${e.clickType}
262
- `, n += `检测时间: ${e.timestamp}
263
-
264
- `, e.chartInfo) {
265
- if (n += `📊 图表信息:
266
- `, n += `- 图表索引: ${e.chartInfo.chartIndex}
267
- `, n += `- 图表类型: ${e.chartInfo.chartType}
268
- `, e.chartInfo.detailedChartType) {
269
- const t = e.chartInfo.detailedChartType;
270
- n += `- 图表分类: ${t.category}
271
- `, n += `- 具体类型: ${t.specificType}
272
- `, n += `- 类型描述: ${t.description}
273
- `, n += `- 识别置信度: ${(t.confidence * 100).toFixed(1)}%
274
- `, t.properties && Object.keys(t.properties).length > 0 && (n += `- 属性信息: ${JSON.stringify(t.properties)}
275
- `);
276
- }
277
- n += `- 有绑定数据: ${e.chartInfo.hasBindingData ? "是" : "否"}
278
- `, n += `- 绑定方法: ${e.chartInfo.bindingMethod || "无"}
279
-
280
- `;
281
- }
282
- if (e.boundData) {
283
- if (n += `💾 绑定的数据:
284
- `, e.boundData.title && (n += `- 标题: ${e.boundData.title}
285
- `), e.boundData.type && (n += `- 类型: ${e.boundData.type}
286
- `), e.boundData.dataSource && (n += `- 数据源: ${e.boundData.dataSource}
287
- `), e.boundData.period && (n += `- 时间周期: ${e.boundData.period}
288
- `), e.boundData.metrics) {
289
- n += `
290
- 📈 关键指标:
291
- `;
292
- const t = e.boundData.metrics;
293
- t.totalSales && (n += `- 总销售额: ¥${t.totalSales.toLocaleString()}
294
- `), t.growthRate && (n += `- 增长率: ${t.growthRate}%
295
- `), t.topProduct && (n += `- 热门产品: ${t.topProduct}
296
- `), t.targetAchievement && (n += `- 目标达成: ${t.targetAchievement}%
297
- `);
298
- }
299
- e.boundData.series && e.boundData.series.length > 0 && (n += `
300
- 📊 数据系列:
301
- `, e.boundData.series.slice(0, 2).forEach((t) => {
302
- n += `- ${t.name}: [${t.data.slice(0, 3).join(", ")}${t.data.length > 3 ? "..." : ""}]
303
- `;
304
- }));
305
- }
306
- e.bindingMetadata && (n += `
307
- 🔗 绑定信息:
308
- `, n += `- 绑定ID: ${e.bindingMetadata.bindingId}
309
- `, n += `- 绑定时间: ${e.bindingMetadata.boundAt}
310
- `, n += `- 绑定方法: ${e.bindingMetadata.bindingMethod}
311
- `), e.detectionSummary && (n += `
312
- 🔍 检测摘要:
313
- `, n += `- 文档中图表总数: ${e.detectionSummary.totalChartsFound}
314
- `, n += `- 有数据的图表: ${e.detectionSummary.chartsWithData}
315
- `, n += `- 有选区: ${e.detectionSummary.hasSelection ? "是" : "否"}
316
- `), console.log("📈 图表绑定数据:", e.boundData), e.boundData && (e.boundData.type === "line-chart" ? console.log("📈 这是线图,可以显示趋势分析") : e.boundData.type === "bar-chart" && console.log("📊 这是柱状图,可以显示比较分析"), e.boundData.dataSource === "ERP系统" && console.log("🔄 可以触发ERP系统数据刷新"));
317
- } else o && o.success === !1 && console.log("❌ 图表检测失败或无图表:", o.error || "未知错误");
318
- }
319
- function N(o) {
320
- if (console.log("处理绑定控件点击事件,收到数据:", o), o && o.success && o.data) {
321
- const e = o.data;
322
- let n = "绑定控件被点击!\\n\\n";
323
- n += `点击类型: ${e.clickType}\\n`, n += `绑定类型: ${e.bindingType}\\n`, n += `控件索引: ${e.controlIndex}\\n`, n += `控件别名: ${e.controlAlias || "无"}\\n`, n += `控件内容: "${e.controlContent || "空"}"\\n`, n += `点击时间: ${e.timestamp}\\n`, e.bindingData && (n += "\\n绑定数据详情:\\n", e.bindingType === "data-binding" ? (n += `- 字段名称: ${e.bindingData.fieldName}\\n`, n += `- 数据类型: ${e.bindingData.dataType}\\n`, n += `- 原始值: "${e.bindingData.originalValue}"\\n`, n += `- 绑定时间: ${e.bindingData.boundAt}\\n`) : e.bindingType === "template-variable" ? (n += `- 变量名: ${e.bindingData.variableName}\\n`, n += `- 原始值: "${e.bindingData.originalValue}"\\n`, n += `- 绑定时间: ${e.bindingData.boundAt}\\n`) : e.bindingType === "table-data-binding" ? (n += `- 表格名称: ${e.bindingData.tableName}\\n`, n += `- 绑定模式: ${e.bindingData.bindingMode}\\n`, n += `- 绑定时间: ${e.bindingData.boundAt}\\n`) : e.bindingType === "paragraph-template" ? (n += `- 模板名称: ${e.bindingData.templateName}\\n`, n += `- 原始内容: "${e.bindingData.originalContent?.substring(0, 50)}${e.bindingData.originalContent?.length > 50 ? "..." : ""}"\\n`, n += `- 绑定时间: ${e.bindingData.boundAt}\\n`) : e.bindingType === "custom-binding" && (n += `- 自定义类型: ${e.bindingData.customType}\\n`, n += `- 字段名称: ${e.bindingData.fieldName}\\n`, n += `- 原始值: "${e.bindingData.originalValue}"\\n`, n += `- 绑定时间: ${e.bindingData.boundAt}\\n`)), console.log("检测到绑定控件点击,可以执行相关操作:", {
324
- bindingType: e.bindingType,
325
- bindingData: e.bindingData
326
- }), e.bindingType === "data-binding" ? console.log("数据字段绑定被点击,可以打开数据编辑界面") : e.bindingType === "template-variable" ? console.log("模板变量绑定被点击,可以打开变量设置界面") : e.bindingType === "table-data-binding" && console.log("表格数据源绑定被点击,可以打开数据源配置界面");
327
- } else
328
- console.log("绑定控件点击检测失败或无绑定控件:", o?.error || "未知错误"), o?.data?.clickType === "non-binding" && console.log("当前点击位置不是绑定控件");
329
- }
330
- let u = p(!1);
331
- const x = (o) => {
332
- o.data.eventType === "customEventReplay" && console.info(o, "DDD11"), o.data.eventType === "customEventCommon" && console.info(o, "DDD22");
333
- };
334
- return v(async () => {
335
- await h(), u.value ? console.warn("⚠️ 消息监听器已存在,跳过重复注册") : (window.addEventListener("message", x), u.value = !0, console.log("✅ 消息监听器已注册"));
336
- }), L(() => {
337
- i?.destroyEditor && i.destroyEditor(), a !== null && clearInterval(a);
338
- }), (o, e) => (Y(), P("div", _, [
339
- R("", !0),
340
- e[1] || (e[1] = B("div", {
91
+ D(async () => {
92
+ await O(), u.value ? console.warn("⚠️ 消息监听器已存在,跳过重复注册") : (window.addEventListener("message", g), u.value = !0, console.log("✅ 消息监听器已注册"));
93
+ }), C(() => {
94
+ l?.destroyEditor && l.destroyEditor(), f !== null && clearInterval(f);
95
+ });
96
+ let f = null;
97
+ return (o, e) => (w(), I("div", N, [
98
+ F("", !0),
99
+ e[1] || (e[1] = A("div", {
341
100
  id: "editor",
342
101
  style: { flex: "1" }
343
102
  }, null, -1))
@@ -345,5 +104,5 @@ ${e.message}`, console.log("数据绑定成功,绑定信息:", e.binding);
345
104
  }
346
105
  });
347
106
  export {
348
- M as onlyoffice
107
+ h as onlyoffice
349
108
  };
@@ -1,129 +1 @@
1
- (function(a,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],l):(a=typeof globalThis<"u"?globalThis:a||self,l(a.OnlyofficeUI={},a.Vue))})(this,(function(a,l){"use strict";const $={class:"onlyoffice-box"},I="asc.{91EAC419-EF8B-440C-A960-B451C7DF3A37}",h=l.defineComponent({__name:"onlyoffice",props:{config:{type:Object,default:()=>{}},documentServerUrl:{type:String,default:""},onLoadComponentError:{type:Object,default:()=>{}}},setup(y){let i=null;const r=l.ref(!1),s=y;console.log(s,"props");const f=s?.documentServerUrl||"https://test.xuandou.vip:126",g=f+"/web-apps/apps/api/documents/api.js",C=f+"/8.3.1-10ca0f5dd35a63800b6a3956f350bf95/sdkjs-plugins/example_extended_comments/config.json";function D(){return new Promise((o,e)=>{if(window.DocsAPI)return o();const n=document.createElement("script");n.src=g,n.onload=()=>o(),n.onerror=()=>e(new Error("加载 DocsAPI 失败:"+g)),document.head.appendChild(n)})}const u=[];let c=null;function m(){c===null&&(c=window.setInterval(()=>{if(!(!i||typeof i.serviceCommand!="function")&&r.value){for(;u.length;){const{cmd:o,payload:e}=u.shift();try{console.log("[ONLYOFFICE] 发送排队指令:",o,e),i.serviceCommand(o,e)}catch(n){console.error("[ONLYOFFICE] 队列指令发送失败:",o,n)}}c!==null&&(clearInterval(c),c=null)}},300))}const p={document:{fileType:"docx",title:"Demo.docx",url:"https://qiniu2.xuandou.vip/new.docx",key:"test-key",permissions:{edit:!0}},documentType:"word",editorConfig:{lang:"zh-CN",mode:"edit",user:{id:"u1",name:"Tester"},plugins:{autostart:[I],pluginsData:[{url:C+"?v=2.0."+Date.now()}]}},width:"100%",height:"100%",events:{onPluginsReady:()=>{console.log("[ONLYOFFICE] 插件资源已加载,但不代表已初始化")},onDocumentReady:()=>{console.log("[ONLYOFFICE] 文档已就绪"),T(),m(),console.log("window.Asc.plugin1",window?.Asc?.plugin),setTimeout(()=>{console.log("window.Asc.plugin2",window),console.log("window.Asc.plugin3-editor",i.serviceCommand),i.serviceCommand("event_onAddComment",{id:111})},2e3)},onInfo:o=>{const e=o?.data;console.log("[ONLYOFFICE] Info 事件:",o.data),o&&(e?.command==="openPlugin"&&(console.log("[ONLYOFFICE] openPlugin"),i.frame?.contentWindow?.Common?.Gateway?.sendInfo(e)),o.data.command==="pluginInitialized"&&(r.value=!0,console.log("[ONLYOFFICE] 插件初始化完成"),m()),o.data.command==="pluginAck"&&console.log("[ONLYOFFICE] 插件确认收到:",o.data),o.data.command==="pluginError"&&console.error("[ONLYOFFICE] 插件错误:",o.data),o.data.command==="linkClicked"&&(console.log("[ONLYOFFICE] 链接被点击,数据:",o.data.data),E(o.data.data)),o.data.command==="wordArtInserted"&&(console.log("[ONLYOFFICE] WordArt 插入成功:",o.data.data),F(o.data.data)),o.data.command==="wordArtError"&&(console.error("[ONLYOFFICE] WordArt 插入失败:",o.data.data),w(o.data.data)),o.data.command==="tableClicked"&&(console.log("[ONLYOFFICE] 表格被点击,数据:",o.data.data),k(o.data.data)),o.data.command==="selectionAnalyzed"&&(console.log("[ONLYOFFICE] 选中内容分析结果:",o.data.data),A(o.data.data)),o.data.command==="selectionBound"&&(console.log("[ONLYOFFICE] 选中内容绑定完成:",o.data.data),N(o.data.data)),o.data.command==="bindingClicked"&&(console.log("[ONLYOFFICE] 绑定控件被点击:",o.data.data),P(o.data.data)),o.data.command==="elementClicked"&&(console.log("[ONLYOFFICE] 元素被点击:",o.data.data),x(o.data.data)),o.data.command==="preciseTableCellClicked"&&(console.log("[ONLYOFFICE] 精确表格单元格被点击:",o.data.data),S(o.data.data)),o.data.command==="chartClicked"&&(console.log("[ONLYOFFICE] 图表被点击:",o.data.data),L(o.data.data)))}}};async function O(){await D();const o=window.DocsAPI;i?.destroyEditor&&i.destroyEditor(),r.value=!1,s.config&&(p=s.config),i=new o.DocEditor("editor",p)}function T(){try{i.executeCommand&&i.executeCommand("focus"),console.log("autoOpenPluginSidePanel",i),i.serviceCommand&&i.serviceCommand("sidePanel",{action:"toggle",state:!1})}catch(o){console.error("auto-open plugin failed:",o)}}function E(o){console.log("处理链接点击事件,收到数据:",o),o&&typeof o=="object"&&(`${o.controlId||"unknown"}${o.controlTitle||"无标题"}${o.tag||"无Tag"}${JSON.stringify(o.data,null,2)}${JSON.stringify(o,null,2)}`,o.data&&o.data.name&&console.log("检测到用户名:",o.data.name))}function F(o){if(console.log("WordArt 插入成功,数据:",o),o&&o.success){const e=`WordArt 插入成功!
2
-
3
- 文本: ${o.parameters?.text||"未知"}
4
- 字体大小: ${o.parameters?.fontSize||"未知"}
5
- 字体: ${o.parameters?.fontFamily||"未知"}
6
- 变换效果: ${o.parameters?.transform||"未知"}
7
-
8
- ${o.message||""}`;confirm(e+`
9
-
10
- 点击"确定"可继续插入更多WordArt`)&&console.log("用户选择继续操作WordArt")}}function w(o){console.error("WordArt 插入失败,错误:",o),o?.error}function k(o){if(console.log("处理表格点击事件,收到数据:",o),o&&o.success&&o.data){const e=o.data;let n=`表格被点击!
11
-
12
- `;e.clickType==="table"?(n+=`点击类型: 表格内容
13
- `,n+=`表格索引: ${e.tableIndex>=0?e.tableIndex:"未知"}
14
- `,n+=`行索引: ${e.rowIndex>=0?e.rowIndex:"未知"}
15
- `,n+=`单元格索引: ${e.cellIndex>=0?e.cellIndex:"未知"}
16
- `,n+=`单元格文本: "${e.cellText||"空"}"
17
- `,n+=`点击时间: ${e.timestamp}
18
- `,e.tableData&&(n+=`
19
- 表格数据结构:
20
- `,n+=`- 行数: ${e.tableData.rows}
21
- `,n+=`- 列数: ${e.tableData.columns}
22
- `,e.tableData.content&&e.tableData.content.length>0&&(n+=`
23
- 表格内容预览:
24
- `,e.tableData.content.slice(0,3).forEach((t,d)=>{n+=`第${d+1}行: [${t.join(", ")}]
25
- `}),e.tableData.content.length>3&&(n+=`... 还有 ${e.tableData.content.length-3} 行
26
- `)))):(n+=`点击类型: 非表格区域
27
- `,n+=`点击时间: ${e.timestamp}
28
- `),e.clickType==="table"&&e.tableData&&console.log("检测到表格点击,可以执行相关操作:",{tableIndex:e.tableIndex,tableData:e.tableData})}else console.log("表格点击检测失败:",o?.error||"未知错误")}function A(o){if(console.log("处理选中内容分析结果,收到数据:",o),o&&o.success&&o.data){const e=o.data;let n=`选中内容分析结果!
29
-
30
- `;n+=`选择类型: ${e.selectionType}
31
- `,n+=`是否可绑定: ${e.bindable?"是":"否"}
32
- `,n+=`选中内容: "${e.content.substring(0,50)}${e.content.length>50?"...":""}"
33
-
34
- `,e.suggestedBindings&&e.suggestedBindings.length>0&&(n+=`建议的绑定方式:
35
- `,e.suggestedBindings.slice(0,3).forEach((t,d)=>{n+=`${d+1}. ${t.description} (${t.category})
36
- `}),e.suggestedBindings.length>3&&(n+=`... 还有 ${e.suggestedBindings.length-3} 种绑定方式
37
- `)),n+=`
38
- 分析时间: ${e.timestamp}`,e.bindable&&console.log("内容可以绑定,建议绑定方式:",e.suggestedBindings)}else console.log("选中内容分析失败:",o?.error||"未知错误")}function N(o){if(console.log("处理选中内容绑定完成,收到数据:",o),o&&o.success){const e=o.data;let n=`数据绑定完成!
39
-
40
- `;n+=`绑定方法: ${e.method}
41
- `,n+=`绑定类型: ${e.binding?.type||"未知"}
42
- `,e.binding&&(e.binding.fieldName&&(n+=`字段名称: ${e.binding.fieldName}
43
- `),e.binding.dataType&&(n+=`数据类型: ${e.binding.dataType}
44
- `),e.binding.originalValue&&(n+=`原始值: "${e.binding.originalValue}"
45
- `)),n+=`
46
- ${e.message}`,console.log("数据绑定成功,绑定信息:",e.binding)}else console.log("数据绑定失败:",o?.error||"未知错误")}function x(o){if(console.log("🎯 处理通用元素点击事件,收到数据:",o),o&&o.success&&o.data){const e=o.data;let n=`🎯 元素点击检测结果!
47
-
48
- `;n+=`点击类型: ${e.clickType}
49
- `,n+=`检测时间: ${e.timestamp}
50
-
51
- `,e.clickType==="table"?(n+=`📊 表格信息:
52
- `,n+=`- 表格索引: ${e.elementInfo.tableIndex}
53
- `,n+=`- 总行数: ${e.elementInfo.totalRows}
54
- `,n+=`- 总列数: ${e.elementInfo.totalColumns}
55
- `,e.elementInfo.clickedCell&&(n+=`- 点击位置: 第${e.elementInfo.clickedCell.row}行第${e.elementInfo.clickedCell.column}列
56
- `,n+=`- 单元格内容: "${e.elementInfo.clickedCellInfo?.content||"空"}"
57
- `),e.elementInfo.sampleContent&&e.elementInfo.sampleContent.length>0&&(n+=`
58
- 📋 表格内容预览:
59
- `,e.elementInfo.sampleContent.slice(0,2).forEach((t,d)=>{n+=`第${d+1}行: [${t.slice(0,3).join(", ")}${t.length>3?"...":""}]
60
- `}))):e.clickType==="paragraph"?(n+=`📝 段落信息:
61
- `,n+=`- 段落索引: ${e.elementInfo.paragraphIndex}
62
- `,n+=`- 对齐方式: ${e.elementInfo.alignment}
63
- `,n+=`- 文本长度: ${e.elementInfo.metadata?.fullTextLength||0}字符
64
- `,n+=`- 文本预览: "${e.elementInfo.text}"
65
- `):e.clickType==="shape"?(n+=`🔷 图形信息:
66
- `,n+=`- 图形索引: ${e.elementInfo.shapeIndex}
67
- `,n+=`- 图形类型: ${e.elementInfo.shapeType}
68
- `,n+=`- 包含内容: ${e.elementInfo.hasContent?"是":"否"}
69
- `):e.clickType==="document"&&(n+=`📄 文档区域:
70
- `,n+=`- 有选区: ${e.elementInfo.hasSelection?"是":"否"}
71
- `,n+=`- 扫描元素: ${e.elementInfo.metadata?.totalElementsScanned||0}个
72
- `),e.fullScanResults&&(n+=`
73
- 🔍 文档扫描统计:
74
- `,n+=`- 表格: ${e.fullScanResults.tablesFound}个
75
- `,n+=`- 段落: ${e.fullScanResults.paragraphsFound}个
76
- `,n+=`- 图形: ${e.fullScanResults.shapesFound}个
77
- `),console.log("🎯 元素类型:",e.clickType,"详细信息:",e.elementInfo)}else console.log("❌ 通用元素检测失败:",o?.error||"未知错误")}function S(o){if(console.log("📊 处理精确表格单元格点击事件,收到数据:",o),o&&o.success&&o.data){const e=o.data;let n=`📊 精确表格单元格点击!
78
-
79
- `;n+=`🎯 单元格位置:
80
- `,n+=`- 行: 第${e.cellPosition.row}行
81
- `,n+=`- 列: 第${e.cellPosition.column}列
82
- `,n+=`- 单元格内容: "${e.cellContent}"
83
-
84
- `,n+=`📋 表格信息:
85
- `,n+=`- 总行数: ${e.tableInfo.totalRows}
86
- `,n+=`- 总列数: ${e.tableInfo.totalColumns}
87
- `,n+=`- 检测方法: ${e.detectionMethod}
88
- `,n+=`- 检测时间: ${e.timestamp}
89
- `,console.log("📊 精确单元格信息:",{row:e.cellPosition.row,column:e.cellPosition.column,content:e.cellContent,tableInfo:e.tableInfo}),e.cellPosition.row===1?console.log("🎯 点击了表头行,可以执行排序等操作"):console.log("🎯 点击了数据行,可以执行编辑等操作")}else console.log("❌ 精确表格单元格检测失败:",o?.error||"未知错误")}function L(o){if(console.log("📈 处理图表点击事件,收到数据:",o),o&&o.success&&o.data){const e=o.data;let n=`📈 图表点击检测结果!
90
-
91
- `;if(n+=`点击类型: ${e.clickType}
92
- `,n+=`检测时间: ${e.timestamp}
93
-
94
- `,e.chartInfo){if(n+=`📊 图表信息:
95
- `,n+=`- 图表索引: ${e.chartInfo.chartIndex}
96
- `,n+=`- 图表类型: ${e.chartInfo.chartType}
97
- `,e.chartInfo.detailedChartType){const t=e.chartInfo.detailedChartType;n+=`- 图表分类: ${t.category}
98
- `,n+=`- 具体类型: ${t.specificType}
99
- `,n+=`- 类型描述: ${t.description}
100
- `,n+=`- 识别置信度: ${(t.confidence*100).toFixed(1)}%
101
- `,t.properties&&Object.keys(t.properties).length>0&&(n+=`- 属性信息: ${JSON.stringify(t.properties)}
102
- `)}n+=`- 有绑定数据: ${e.chartInfo.hasBindingData?"是":"否"}
103
- `,n+=`- 绑定方法: ${e.chartInfo.bindingMethod||"无"}
104
-
105
- `}if(e.boundData){if(n+=`💾 绑定的数据:
106
- `,e.boundData.title&&(n+=`- 标题: ${e.boundData.title}
107
- `),e.boundData.type&&(n+=`- 类型: ${e.boundData.type}
108
- `),e.boundData.dataSource&&(n+=`- 数据源: ${e.boundData.dataSource}
109
- `),e.boundData.period&&(n+=`- 时间周期: ${e.boundData.period}
110
- `),e.boundData.metrics){n+=`
111
- 📈 关键指标:
112
- `;const t=e.boundData.metrics;t.totalSales&&(n+=`- 总销售额: ¥${t.totalSales.toLocaleString()}
113
- `),t.growthRate&&(n+=`- 增长率: ${t.growthRate}%
114
- `),t.topProduct&&(n+=`- 热门产品: ${t.topProduct}
115
- `),t.targetAchievement&&(n+=`- 目标达成: ${t.targetAchievement}%
116
- `)}e.boundData.series&&e.boundData.series.length>0&&(n+=`
117
- 📊 数据系列:
118
- `,e.boundData.series.slice(0,2).forEach(t=>{n+=`- ${t.name}: [${t.data.slice(0,3).join(", ")}${t.data.length>3?"...":""}]
119
- `}))}e.bindingMetadata&&(n+=`
120
- 🔗 绑定信息:
121
- `,n+=`- 绑定ID: ${e.bindingMetadata.bindingId}
122
- `,n+=`- 绑定时间: ${e.bindingMetadata.boundAt}
123
- `,n+=`- 绑定方法: ${e.bindingMetadata.bindingMethod}
124
- `),e.detectionSummary&&(n+=`
125
- 🔍 检测摘要:
126
- `,n+=`- 文档中图表总数: ${e.detectionSummary.totalChartsFound}
127
- `,n+=`- 有数据的图表: ${e.detectionSummary.chartsWithData}
128
- `,n+=`- 有选区: ${e.detectionSummary.hasSelection?"是":"否"}
129
- `),console.log("📈 图表绑定数据:",e.boundData),e.boundData&&(e.boundData.type==="line-chart"?console.log("📈 这是线图,可以显示趋势分析"):e.boundData.type==="bar-chart"&&console.log("📊 这是柱状图,可以显示比较分析"),e.boundData.dataSource==="ERP系统"&&console.log("🔄 可以触发ERP系统数据刷新"))}else o&&o.success===!1&&console.log("❌ 图表检测失败或无图表:",o.error||"未知错误")}function P(o){if(console.log("处理绑定控件点击事件,收到数据:",o),o&&o.success&&o.data){const e=o.data;let n="绑定控件被点击!\\n\\n";n+=`点击类型: ${e.clickType}\\n`,n+=`绑定类型: ${e.bindingType}\\n`,n+=`控件索引: ${e.controlIndex}\\n`,n+=`控件别名: ${e.controlAlias||"无"}\\n`,n+=`控件内容: "${e.controlContent||"空"}"\\n`,n+=`点击时间: ${e.timestamp}\\n`,e.bindingData&&(n+="\\n绑定数据详情:\\n",e.bindingType==="data-binding"?(n+=`- 字段名称: ${e.bindingData.fieldName}\\n`,n+=`- 数据类型: ${e.bindingData.dataType}\\n`,n+=`- 原始值: "${e.bindingData.originalValue}"\\n`,n+=`- 绑定时间: ${e.bindingData.boundAt}\\n`):e.bindingType==="template-variable"?(n+=`- 变量名: ${e.bindingData.variableName}\\n`,n+=`- 原始值: "${e.bindingData.originalValue}"\\n`,n+=`- 绑定时间: ${e.bindingData.boundAt}\\n`):e.bindingType==="table-data-binding"?(n+=`- 表格名称: ${e.bindingData.tableName}\\n`,n+=`- 绑定模式: ${e.bindingData.bindingMode}\\n`,n+=`- 绑定时间: ${e.bindingData.boundAt}\\n`):e.bindingType==="paragraph-template"?(n+=`- 模板名称: ${e.bindingData.templateName}\\n`,n+=`- 原始内容: "${e.bindingData.originalContent?.substring(0,50)}${e.bindingData.originalContent?.length>50?"...":""}"\\n`,n+=`- 绑定时间: ${e.bindingData.boundAt}\\n`):e.bindingType==="custom-binding"&&(n+=`- 自定义类型: ${e.bindingData.customType}\\n`,n+=`- 字段名称: ${e.bindingData.fieldName}\\n`,n+=`- 原始值: "${e.bindingData.originalValue}"\\n`,n+=`- 绑定时间: ${e.bindingData.boundAt}\\n`)),console.log("检测到绑定控件点击,可以执行相关操作:",{bindingType:e.bindingType,bindingData:e.bindingData}),e.bindingType==="data-binding"?console.log("数据字段绑定被点击,可以打开数据编辑界面"):e.bindingType==="template-variable"?console.log("模板变量绑定被点击,可以打开变量设置界面"):e.bindingType==="table-data-binding"&&console.log("表格数据源绑定被点击,可以打开数据源配置界面")}else console.log("绑定控件点击检测失败或无绑定控件:",o?.error||"未知错误"),o?.data?.clickType==="non-binding"&&console.log("当前点击位置不是绑定控件")}let b=l.ref(!1);const v=o=>{o.data.eventType==="customEventReplay"&&console.info(o,"DDD11"),o.data.eventType==="customEventCommon"&&console.info(o,"DDD22")};return l.onMounted(async()=>{await O(),b.value?console.warn("⚠️ 消息监听器已存在,跳过重复注册"):(window.addEventListener("message",v),b.value=!0,console.log("✅ 消息监听器已注册"))}),l.onBeforeUnmount(()=>{i?.destroyEditor&&i.destroyEditor(),c!==null&&clearInterval(c)}),(o,e)=>(l.openBlock(),l.createElementBlock("div",$,[l.createCommentVNode("",!0),e[1]||(e[1]=l.createElementVNode("div",{id:"editor",style:{flex:"1"}},null,-1))]))}});a.onlyoffice=h,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(c,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],o):(c=typeof globalThis<"u"?globalThis:c||self,o(c.OnlyofficeUI={},c.Vue))})(this,(function(c,o){"use strict";const p={class:"onlyoffice-box"},y="asc.{91EAC419-EF8B-440C-A960-B451C7DF3A37}",g=o.defineComponent({__name:"onlyoffice",props:{config:{type:Object,default:()=>{}},documentServerUrl:{type:String,default:""},onLoadComponentError:{type:Object,default:()=>{}}},setup(E){let s=null;const O=o.ref(!1),l=E;console.log(l,"props",l?.documentServerUrl),l?.documentServerUrl||console.error("[ONLYOFFICE] documentServerUrl 不能为空");const a=l?.documentServerUrl||"";console.log(a,"DOCUMENT_SERVER");const i=o.ref(""),D=a+"/8.3.1-10ca0f5dd35a63800b6a3956f350bf95/sdkjs-plugins/example_extended_comments/config.json";function C(){return new Promise((n,e)=>{if(window.DocsAPI)return n();const r=document.createElement("script");if(!i.value)return console.error("[ONLYOFFICE] documentServerUrl 不能为空"),e(new Error("[ONLYOFFICE] documentServerUrl 不能为空"));console.log("DOCS_API",i.value),r.src=i.value,r.onload=()=>n(),r.onerror=()=>e(new Error("加载 DocsAPI 失败:"+i.value)),document.head.appendChild(r)})}function f(n,e){const r={...n};for(const t in e)e.hasOwnProperty(t)&&(r.hasOwnProperty(t)&&typeof r[t]=="object"&&r[t]!==null&&!Array.isArray(r[t])&&typeof e[t]=="object"&&e[t]!==null&&!Array.isArray(e[t])?r[t]=f(r[t],e[t]):r[t]=e[t]);return r}let d={document:{fileType:"docx",title:"Demo.docx",url:"https://badges-1302420147.cos.ap-shanghai.myqcloud.com/test1.docx",key:""},documentType:"word",editorConfig:{lang:"zh-CN",plugins:{autostart:[y],pluginsData:[{url:D+"?v=2.0."+Date.now()}]}},width:"100%",height:"100%",events:{onPluginsReady:()=>{console.log("[ONLYOFFICE] 插件资源已加载,但不代表已初始化")},onDocumentReady:()=>{console.log("[ONLYOFFICE] 文档已就绪")},onInfo:n=>{}}},u=o.ref(!1);const I=n=>{n.data.eventType==="customEventReplay"&&console.info(n,"DDD11"),n.data.eventType==="customEventCommon"&&console.info(n,"DDD22")};async function w(){if(l.documentServerUrl)i.value=l.documentServerUrl+"/web-apps/apps/api/documents/api.js";else{console.error("[ONLYOFFICE] documentServerUrl 不能为空");return}await C().then(()=>{console.log("[ONLYOFFICE] 加载 DocsAPI 成功")}).catch(e=>{console.error("[ONLYOFFICE] 加载 DocsAPI 失败:",e)});const n=window.DocsAPI;s?.destroyEditor&&s.destroyEditor(),O.value=!1,l.config&&(d=f(d,l.config)),console.log("cfg",d),s=new n.DocEditor("editor",d)}o.onMounted(async()=>{await w(),u.value?console.warn("⚠️ 消息监听器已存在,跳过重复注册"):(window.addEventListener("message",I),u.value=!0,console.log(" 消息监听器已注册"))}),o.onBeforeUnmount(()=>{s?.destroyEditor&&s.destroyEditor(),m!==null&&clearInterval(m)});let m=null;return(n,e)=>(o.openBlock(),o.createElementBlock("div",p,[o.createCommentVNode("",!0),e[1]||(e[1]=o.createElementVNode("div",{id:"editor",style:{flex:"1"}},null,-1))]))}});c.onlyoffice=g,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sur-onlyoffice",
3
- "version": "1.0.8",
3
+ "version": "1.10.0",
4
4
  "description": "文档",
5
5
  "main": "dist/onlyoffice.umd.js",
6
6
  "module": "dist/onlyoffice.es.js",
package/src/App.vue ADDED
@@ -0,0 +1,45 @@
1
+ <template>
2
+ <div class="onlyoffice-test" style="height:100%; " >
3
+ <!-- <onlyoffice :config="config" :documentServerUrl="'https://test.xuandou.vip:126'" /> -->
4
+ <onlyoffice :config="config" documentServerUrl="https://test.xuandou.vip:126" />
5
+ </div>
6
+ </template>
7
+
8
+ <script lang="ts" setup>
9
+ import { ref } from 'vue'
10
+ import onlyoffice from './package/onlyoffice.vue'
11
+
12
+ const config = ref({
13
+ document: {
14
+ fileType: 'docx',
15
+ title: 'Demo.docx',
16
+ // url: 'https://badges-1302420147.cos.ap-shanghai.myqcloud.com/test1.docx',
17
+ url: 'https://qiniu2.xuandou.vip/%E5%AD%A6%E9%BE%84%E6%AE%B5%E9%A2%86%E5%9F%9F%E6%96%87%E4%BB%B6/%E7%A7%91%E5%AD%A6.docx',
18
+ key: '',
19
+ },
20
+ // documentType: 'word',
21
+ // editorConfig: {
22
+ // lang: 'zh-CN',
23
+ // callbackUrl: 'https://test.xuandou.vip:126' + '/admin-api/onlyoffice/callback',
24
+ // customization: {
25
+ // chat: false,
26
+ // features: {
27
+ // spellcheck: false,
28
+ // },
29
+ // },
30
+ // user: { id: 1, name: '123' },
31
+ // },
32
+ // events: {
33
+ // onDocumentStateChange: () => {
34
+ // console.log('onDocumentStateChange');
35
+ // },
36
+ // onAppReady: () => {
37
+ // console.log('onAppReady');
38
+ // },
39
+ // onError: (error: any) => {
40
+ // console.log('onError', error);
41
+ // },
42
+ // },
43
+ });
44
+
45
+ </script>
package/src/index.ts CHANGED
@@ -8,9 +8,11 @@
8
8
 
9
9
  // 测试
10
10
  // import { createApp } from 'vue'
11
- // import App from './package/onlyoffice.vue'
11
+ // import App from './App.vue'
12
12
  // createApp(App).mount('#app')
13
13
 
14
+
15
+
14
16
  import onlyoffice from "./package/onlyoffice.vue";
15
17
  export { onlyoffice };
16
18
 
@@ -105,15 +105,18 @@ const props = defineProps({
105
105
  },
106
106
  })
107
107
 
108
- console.log(props,'props')
108
+ console.log(props,'props',props?.documentServerUrl)
109
+
110
+ if(!props?.documentServerUrl){
111
+ console.error('[ONLYOFFICE] documentServerUrl 不能为空')
112
+ }
109
113
 
110
114
  // === 按你的环境修改 ===
111
- const DOCUMENT_SERVER = props?.documentServerUrl || 'https://test.xuandou.vip:126'
112
- // const DOCUMENT_SERVER = 'https://prev.xuandou.vip:126'
113
- //const DOCUMENT_SERVER = 'http://222.187.11.98:8918'
115
+ const DOCUMENT_SERVER = props?.documentServerUrl || ''
116
+ console.log(DOCUMENT_SERVER,'DOCUMENT_SERVER') //'https://prev.xuandou.vip:126'
117
+ const DOCS_API = ref('')
114
118
 
115
119
 
116
- const DOCS_API = DOCUMENT_SERVER + '/web-apps/apps/api/documents/api.js'
117
120
  // https://badges-1302420147.cos.ap-shanghai.myqcloud.com/test1.docx
118
121
  // 插件 GUID(需与插件 config.json 一致)
119
122
  //9.0.4-9ade76efaf7465c8db6be392804370a8
@@ -133,98 +136,73 @@ const DOCS_API = DOCUMENT_SERVER + '/web-apps/apps/api/documents/api.js'
133
136
  const PLUGIN_GUID = 'asc.{91EAC419-EF8B-440C-A960-B451C7DF3A37}'
134
137
  const PLUGIN_CONF = DOCUMENT_SERVER + '/8.3.1-10ca0f5dd35a63800b6a3956f350bf95/sdkjs-plugins/example_extended_comments/config.json'
135
138
 
136
-
137
139
  //! 444
138
140
  // const PLUGIN_GUID = 'asc.{89643394-0F74-4297-9E0B-541A67F1E98C}'
139
141
  // const PLUGIN_CONF = DOCUMENT_SERVER + '/8.3.1-10ca0f5dd35a63800b6a3956f350bf95/sdkjs-plugins/example_add_comment_in_cell/config.json'
140
142
 
141
-
142
-
143
143
  //! 333 preview
144
144
  // const PLUGIN_GUID = 'asc.{91EAC419-EF8B-440C-A960-B451C7DF3A37}'
145
145
  // const PLUGIN_CONF = DOCUMENT_SERVER + '/8.3.3-903fa321b0e16c3ec855c98c81f29d78/sdkjs-plugins/example_extended_comments/config.json'
146
146
 
147
147
 
148
-
149
- // ---- 动态加载 api.js ----
148
+ //!----step2 动态加载 api.js ----
150
149
  function loadDocsApi(): Promise<void> {
151
150
  return new Promise((resolve, reject) => {
152
151
  if ((window as any).DocsAPI) return resolve()
153
152
  const script = document.createElement('script')
154
- script.src = DOCS_API
153
+ if (!DOCS_API.value) {
154
+ console.error('[ONLYOFFICE] documentServerUrl 不能为空')
155
+ return reject(new Error('[ONLYOFFICE] documentServerUrl 不能为空'))
156
+ }
157
+ console.log('DOCS_API',DOCS_API.value)
158
+ script.src = DOCS_API.value
155
159
  script.onload = () => resolve()
156
- script.onerror = () => reject(new Error('加载 DocsAPI 失败:' + DOCS_API))
160
+ script.onerror = () => reject(new Error('加载 DocsAPI 失败:' + DOCS_API.value))
157
161
  document.head.appendChild(script)
158
162
  })
159
163
  }
160
164
 
161
- // ---- 命令发送:带队列 + 重试,确保等插件就绪 ----
162
- type Cmd = { cmd: string; payload: any }
163
- const queue: Cmd[] = []
164
- let flushTimer: number | null = null
165
165
 
166
- function serviceCommandSafe(cmd: string, payload: any) {
167
- // 未加载好编辑器
168
- if (!editor || typeof editor.serviceCommand !== 'function') {
169
- console.warn('[ONLYOFFICE] editor/serviceCommand 未就绪,先入队:', cmd, payload)
170
- queue.push({ cmd, payload })
171
- return
172
- }
173
- // 插件未就绪:排队等待
174
- if (!pluginReady.value) {
175
- console.log('[ONLYOFFICE] 插件未就绪,先入队:', cmd, payload)
176
- queue.push({ cmd, payload })
177
- scheduleFlush()
178
- return
179
- }
180
- try {
181
- if (typeof editor.executeCommand === 'function') {
182
- editor.executeCommand('focus');
183
- }
184
- // 让浏览器完成一次光标同步,然后再发命令
185
- setTimeout(() => editor.serviceCommand(cmd, payload), 0);
186
- } catch (e) {
187
- console.error('[ONLYOFFICE] serviceCommand 调用失败:', e)
188
- }
189
- }
190
166
 
191
- function scheduleFlush() {
192
- if (flushTimer !== null) return
193
- flushTimer = window.setInterval(() => {
194
- if (!editor || typeof editor.serviceCommand !== 'function') return
195
- if (!pluginReady.value) return
196
- // 开始出队
197
- while (queue.length) {
198
- const { cmd, payload } = queue.shift()!
199
- try {
200
- console.log('[ONLYOFFICE] 发送排队指令:', cmd, payload)
201
- editor.serviceCommand(cmd, payload)
202
- } catch (e) {
203
- console.error('[ONLYOFFICE] 队列指令发送失败:', cmd, e)
167
+ function deepMerge(original, updates) {
168
+ const result = { ...original };
169
+
170
+ for (const key in updates) {
171
+ if (updates.hasOwnProperty(key)) {
172
+ // 如果原对象有该属性且都是对象类型,则递归合并
173
+ if (
174
+ result.hasOwnProperty(key) &&
175
+ typeof result[key] === 'object' &&
176
+ result[key] !== null &&
177
+ !Array.isArray(result[key]) &&
178
+ typeof updates[key] === 'object' &&
179
+ updates[key] !== null &&
180
+ !Array.isArray(updates[key])
181
+ ) {
182
+ result[key] = deepMerge(result[key], updates[key]);
183
+ } else {
184
+ // 否则直接替换(包括数组和基本类型)
185
+ result[key] = updates[key];
204
186
  }
205
187
  }
206
- if (flushTimer !== null) {
207
- clearInterval(flushTimer)
208
- flushTimer = null
209
- }
210
- }, 300)
188
+ }
189
+
190
+ return result;
211
191
  }
212
192
 
213
- const cfg = {
193
+ let cfg = {
214
194
  document: {
215
195
  fileType: 'docx',
216
196
  title: 'Demo.docx',
217
- url: 'https://qiniu2.xuandou.vip/new.docx',
218
- key: 'test-key',
219
- permissions: { edit: true }
197
+ url: 'https://badges-1302420147.cos.ap-shanghai.myqcloud.com/test1.docx',
198
+ key: '',
199
+ // permissions: { edit: true }
220
200
  },
221
201
  documentType: 'word',
222
202
  editorConfig: {
223
203
  lang: 'zh-CN',
224
- mode: 'edit',
225
- user: { id: 'u1', name: 'Tester' },
226
204
  plugins: {
227
- //!
205
+ //!!!!!
228
206
  autostart: [PLUGIN_GUID],
229
207
  pluginsData: [{ url: PLUGIN_CONF + '?v=2.0.' + Date.now() }] // 强刷缓存
230
208
  },
@@ -238,22 +216,17 @@ const cfg = {
238
216
  onDocumentReady: () => {
239
217
  console.log('[ONLYOFFICE] 文档已就绪')
240
218
  // 有些插件会很快 ready,这里安排一次队列尝试
241
- autoOpenPluginSidePanel();
242
- scheduleFlush();
243
-
244
- console.log('window.Asc.plugin1',window?.Asc?.plugin)
245
-
246
- setTimeout(()=>{
247
- console.log('window.Asc.plugin2',window)
248
- console.log('window.Asc.plugin3-editor',editor.serviceCommand)
249
-
250
- editor.serviceCommand('event_onAddComment', {id:111})
251
-
252
-
253
- },2000)
219
+ // autoOpenPluginSidePanel();
220
+ // scheduleFlush();
221
+ // setTimeout(()=>{
222
+ // console.log('window.Asc.plugin2',window)
223
+ // console.log('window.Asc.plugin3-editor',editor.serviceCommand)
224
+ // editor.serviceCommand('event_onAddComment', {id:111})
225
+ // },1000)
254
226
  },
255
227
  onInfo: (e: any) => {
256
- const msg = e?.data;
228
+ return
229
+ const msg = e?.data;
257
230
  console.log('[ONLYOFFICE] Info 事件:', e.data)
258
231
  if (!e) return
259
232
  if (msg?.command === 'openPlugin') {
@@ -319,24 +292,127 @@ const cfg = {
319
292
  }
320
293
  }
321
294
 
322
- // ---- 创建编辑器 ----
295
+
296
+ //! 使用标志确保监听器只注册一次
297
+ let messageListenerRegistered = ref(false);
298
+ const messageHandler = (event) => {
299
+ // 您的业务逻辑...
300
+ if (event.data.eventType === 'customEventReplay') {
301
+ console.info(event,'DDD11')
302
+ }
303
+
304
+ if (event.data.eventType === 'customEventCommon') {
305
+ console.info(event,'DDD22')
306
+ }
307
+ };
308
+
309
+
310
+ //! ---- step1 创建编辑器 ----
323
311
  async function createEditor() {
324
- await loadDocsApi()
312
+
313
+ if (!props.documentServerUrl) {
314
+ console.error('[ONLYOFFICE] documentServerUrl 不能为空')
315
+ return
316
+ }else{
317
+ DOCS_API.value = props.documentServerUrl + '/web-apps/apps/api/documents/api.js'
318
+ }
319
+
320
+ await loadDocsApi().then(() => {
321
+ console.log('[ONLYOFFICE] 加载 DocsAPI 成功')
322
+ }).catch((e) => {
323
+ console.error('[ONLYOFFICE] 加载 DocsAPI 失败:', e)
324
+ return
325
+ })
326
+
325
327
  // @ts-ignore
326
328
  const DocsAPI = (window as any).DocsAPI
327
329
 
328
330
  if (editor?.destroyEditor) editor.destroyEditor()
329
331
  pluginReady.value = false
330
332
 
331
-
332
333
  if(props.config){
333
- cfg = props.config
334
+ cfg = deepMerge(cfg, props.config);
334
335
  }
335
-
336
+ console.log('cfg',cfg)
336
337
  editor = new DocsAPI.DocEditor('editor', cfg)
337
338
 
338
339
  }
339
340
 
341
+ onMounted(async() =>{
342
+
343
+ await createEditor()
344
+
345
+ if (!messageListenerRegistered.value) {
346
+ window.addEventListener('message', messageHandler);
347
+ messageListenerRegistered.value = true;
348
+ console.log('✅ 消息监听器已注册');
349
+ } else {
350
+ console.warn('⚠️ 消息监听器已存在,跳过重复注册');
351
+ }
352
+
353
+ })
354
+
355
+ onBeforeUnmount(() => {
356
+ if (editor?.destroyEditor) editor.destroyEditor()
357
+ if (flushTimer !== null) clearInterval(flushTimer)
358
+ })
359
+
360
+ //! END!!!!!!!!!!!!!!END
361
+
362
+ // ---- 命令发送:带队列 + 重试,确保等插件就绪 ----
363
+ type Cmd = { cmd: string; payload: any }
364
+ const queue: Cmd[] = []
365
+ let flushTimer: number | null = null
366
+
367
+ function serviceCommandSafe(cmd: string, payload: any) {
368
+ // 未加载好编辑器
369
+ if (!editor || typeof editor.serviceCommand !== 'function') {
370
+ console.warn('[ONLYOFFICE] editor/serviceCommand 未就绪,先入队:', cmd, payload)
371
+ queue.push({ cmd, payload })
372
+ return
373
+ }
374
+ // 插件未就绪:排队等待
375
+ if (!pluginReady.value) {
376
+ console.log('[ONLYOFFICE] 插件未就绪,先入队:', cmd, payload)
377
+ queue.push({ cmd, payload })
378
+ scheduleFlush()
379
+ return
380
+ }
381
+ try {
382
+ if (typeof editor.executeCommand === 'function') {
383
+ editor.executeCommand('focus');
384
+ }
385
+ // 让浏览器完成一次光标同步,然后再发命令
386
+ setTimeout(() => editor.serviceCommand(cmd, payload), 0);
387
+ } catch (e) {
388
+ console.error('[ONLYOFFICE] serviceCommand 调用失败:', e)
389
+ }
390
+ }
391
+
392
+ function scheduleFlush() {
393
+ if (flushTimer !== null) return
394
+ flushTimer = window.setInterval(() => {
395
+ if (!editor || typeof editor.serviceCommand !== 'function') return
396
+ if (!pluginReady.value) return
397
+ // 开始出队
398
+ while (queue.length) {
399
+ const { cmd, payload } = queue.shift()!
400
+ try {
401
+ console.log('[ONLYOFFICE] 发送排队指令:', cmd, payload)
402
+ editor.serviceCommand(cmd, payload)
403
+ } catch (e) {
404
+ console.error('[ONLYOFFICE] 队列指令发送失败:', cmd, e)
405
+ }
406
+ }
407
+ if (flushTimer !== null) {
408
+ clearInterval(flushTimer)
409
+ flushTimer = null
410
+ }
411
+ }, 300)
412
+ }
413
+
414
+
415
+
340
416
  function autoOpenPluginSidePanel() {
341
417
  try {
342
418
  editor.executeCommand && editor.executeCommand('focus');
@@ -1144,39 +1220,10 @@ function handleBindingClicked(data: any) {
1144
1220
 
1145
1221
 
1146
1222
 
1147
- // 使用标志确保监听器只注册一次
1148
- let messageListenerRegistered = ref(false);
1149
- const messageHandler = (event) => {
1150
- // 您的业务逻辑...
1151
- if (event.data.eventType === 'customEventReplay') {
1152
- console.info(event,'DDD11')
1153
- }
1154
1223
 
1155
- if (event.data.eventType === 'customEventCommon') {
1156
- console.info(event,'DDD22')
1157
- }
1158
- };
1159
1224
 
1160
1225
 
1161
- onMounted(async() =>{
1162
-
1163
- await createEditor()
1164
1226
 
1165
- if (!messageListenerRegistered.value) {
1166
- window.addEventListener('message', messageHandler);
1167
- messageListenerRegistered.value = true;
1168
- console.log('✅ 消息监听器已注册');
1169
- } else {
1170
- console.warn('⚠️ 消息监听器已存在,跳过重复注册');
1171
- }
1172
-
1173
- })
1174
-
1175
-
1176
- onBeforeUnmount(() => {
1177
- if (editor?.destroyEditor) editor.destroyEditor()
1178
- if (flushTimer !== null) clearInterval(flushTimer)
1179
- })
1180
1227
  </script>
1181
1228
 
1182
1229
  <style>