From 407a52a3b60301dfd0396fdc3e40112dddad928b Mon Sep 17 00:00:00 2001 From: prr <3099672575@qq.com> Date: Sat, 23 Nov 2024 15:49:12 +0800 Subject: [PATCH] =?UTF-8?q?add=EF=BC=9AAI=E5=86=99=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/window/IframeFile.vue | 4 ++- packages/word/index.html | 18 +--------- .../word/src/editor/core/command/Command.ts | 2 -- .../src/editor/core/command/CommandAdapt.ts | 8 ++--- .../src/editor/dataset/constant/AIResult.ts | 5 +++ packages/word/src/main.ts | 33 +++++++++++-------- .../word/src/plugins/floatingToolbar/index.ts | 11 +++---- 7 files changed, 36 insertions(+), 45 deletions(-) create mode 100644 packages/word/src/editor/dataset/constant/AIResult.ts diff --git a/frontend/src/components/window/IframeFile.vue b/frontend/src/components/window/IframeFile.vue index 77f813a..882de40 100644 --- a/frontend/src/components/window/IframeFile.vue +++ b/frontend/src/components/window/IframeFile.vue @@ -188,7 +188,7 @@ const eventHandler = async (e: MessageEvent) => { } else if (eventData.type == 'aiCreater') { - console.log(eventData) + // console.log(eventData) let postData:any = {} if(eventData.data){ postData.content = eventData.data @@ -199,12 +199,14 @@ const eventHandler = async (e: MessageEvent) => { if(eventData.category){ postData.category = eventData.category } + // 模拟AI返回数据 const res = await askAi(postData, eventData.action); storeRef.value?.contentWindow?.postMessage( { type: 'aiReciver', data: res, + action: eventData.action }, "*" ); diff --git a/packages/word/index.html b/packages/word/index.html index fedcb7c..38dbf8b 100644 --- a/packages/word/index.html +++ b/packages/word/index.html @@ -377,23 +377,7 @@
diff --git a/packages/word/src/editor/core/command/Command.ts b/packages/word/src/editor/core/command/Command.ts index c2a85e9..8d5b714 100644 --- a/packages/word/src/editor/core/command/Command.ts +++ b/packages/word/src/editor/core/command/Command.ts @@ -28,7 +28,6 @@ export class Command { public executeStrikeout: CommandAdapt['strikeout'] public executeSuperscript: CommandAdapt['superscript'] public executeSubscript: CommandAdapt['subscript'] - public excuteAiResult: CommandAdapt['aiResult'] public executeAiEdit: CommandAdapt['aiEdit'] public executeAiArticle: CommandAdapt['aiArticle'] public executeColor: CommandAdapt['color'] @@ -155,7 +154,6 @@ export class Command { this.executeStrikeout = adapt.strikeout.bind(adapt) this.executeSuperscript = adapt.superscript.bind(adapt) this.executeSubscript = adapt.subscript.bind(adapt) - this.excuteAiResult = adapt.aiResult.bind(adapt) this.executeAiEdit = adapt.aiEdit.bind(adapt) this.executeAiArticle = adapt.aiArticle.bind(adapt) this.executeColor = adapt.color.bind(adapt) diff --git a/packages/word/src/editor/core/command/CommandAdapt.ts b/packages/word/src/editor/core/command/CommandAdapt.ts index 34008c3..102f3bd 100644 --- a/packages/word/src/editor/core/command/CommandAdapt.ts +++ b/packages/word/src/editor/core/command/CommandAdapt.ts @@ -635,10 +635,6 @@ export class CommandAdapt { }) this.draw.render({ isSetCursor: false }) } - public aiResult(result?: string) { - result ? (this.aiContent = result) : '' - return this.aiContent - } public aiArticle(payload: string) { this.selectAll() const isDisabled = this.draw.isReadonly() || this.draw.isDisabled() @@ -678,8 +674,6 @@ export class CommandAdapt { selection.forEach(el => { content += el.value }) - // const eventBus = this.draw.getEventBus() - this.search(content) if (operate && content) { window.parent.postMessage( @@ -1218,6 +1212,8 @@ export class CommandAdapt { if(aiArticle && aiArticle == true) { if (!payload) return } else { + // console.log('zero:', new RegExp(`${ZERO}`, 'g').test(payload)) + if (!payload || new RegExp(`${ZERO}`, 'g').test(payload)) return } // if (!payload || (isZero && aiArticle)) return diff --git a/packages/word/src/editor/dataset/constant/AIResult.ts b/packages/word/src/editor/dataset/constant/AIResult.ts new file mode 100644 index 0000000..5680c4e --- /dev/null +++ b/packages/word/src/editor/dataset/constant/AIResult.ts @@ -0,0 +1,5 @@ +export const AiResult = { + aiContent: '', + aiArticle: '', + aiOutline: '' +} \ No newline at end of file diff --git a/packages/word/src/main.ts b/packages/word/src/main.ts index e08dd60..e7141fc 100644 --- a/packages/word/src/main.ts +++ b/packages/word/src/main.ts @@ -30,6 +30,7 @@ import barcode2dPlugin from "./plugins/barcode2d" import floatingToolbarPlugin from "./plugins/floatingToolbar" import excelPlugin from "./plugins/excel" import docxPlugin from './plugins/docx' +import { AiResult } from './editor/dataset/constant/AIResult' window.onload = function () { const isApple = typeof navigator !== 'undefined' && /Mac OS X/.test(navigator.userAgent) @@ -1149,8 +1150,7 @@ window.onload = function () { const articleTextarea = document.querySelector