From 9786030f0b39d11f60abe0d759c6e311a41f3633 Mon Sep 17 00:00:00 2001 From: prr <3099672575@qq.com> Date: Sat, 23 Nov 2024 18:22:49 +0800 Subject: [PATCH] =?UTF-8?q?=20fix=EF=BC=9AAI=E5=86=99=E4=BD=9C=E9=83=A8?= =?UTF-8?q?=E5=88=86bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/word/index.html | 6 ++- packages/word/src/assets/images/loader.svg | 1 + .../src/editor/core/command/CommandAdapt.ts | 2 +- .../src/editor/dataset/constant/AIResult.ts | 5 --- packages/word/src/main.ts | 36 +++++++++++----- .../word/src/plugins/floatingToolbar/index.ts | 41 +++++++++++-------- packages/word/src/style.css | 20 +++++++++ 7 files changed, 75 insertions(+), 36 deletions(-) create mode 100644 packages/word/src/assets/images/loader.svg delete mode 100644 packages/word/src/editor/dataset/constant/AIResult.ts diff --git a/packages/word/index.html b/packages/word/index.html index 38dbf8b..9129105 100644 --- a/packages/word/index.html +++ b/packages/word/index.html @@ -374,10 +374,12 @@
- + +
- + +
diff --git a/packages/word/src/assets/images/loader.svg b/packages/word/src/assets/images/loader.svg new file mode 100644 index 0000000..11a5877 --- /dev/null +++ b/packages/word/src/assets/images/loader.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/word/src/editor/core/command/CommandAdapt.ts b/packages/word/src/editor/core/command/CommandAdapt.ts index 102f3bd..c1b3154 100644 --- a/packages/word/src/editor/core/command/CommandAdapt.ts +++ b/packages/word/src/editor/core/command/CommandAdapt.ts @@ -1209,7 +1209,7 @@ export class CommandAdapt { const isReadonly = this.draw.isReadonly() if (isReadonly) return - if(aiArticle && aiArticle == true) { + if(aiArticle == true) { if (!payload) return } else { // console.log('zero:', new RegExp(`${ZERO}`, 'g').test(payload)) diff --git a/packages/word/src/editor/dataset/constant/AIResult.ts b/packages/word/src/editor/dataset/constant/AIResult.ts deleted file mode 100644 index 5680c4e..0000000 --- a/packages/word/src/editor/dataset/constant/AIResult.ts +++ /dev/null @@ -1,5 +0,0 @@ -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 e7141fc..32cbfd9 100644 --- a/packages/word/src/main.ts +++ b/packages/word/src/main.ts @@ -27,10 +27,9 @@ import { Signature } from './components/signature/Signature' import { debounce, nextTick, scrollIntoView } from './utils' import barcode1DPlugin from "./plugins/barcode1d" import barcode2dPlugin from "./plugins/barcode2d" -import floatingToolbarPlugin from "./plugins/floatingToolbar" +import { floatingToolbarPlugin, changeAiTextarea} 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) @@ -1148,6 +1147,8 @@ window.onload = function () { const createArticleBtn = document.querySelector('#createArticle')! const outlineTextarea = document.querySelector('#outlineText')! const articleTextarea = document.querySelector('#articleText')! + const articleLoader = document.querySelector('#articleLoader')! + const outlineLoader = document.querySelector('#outlineLoader')! aiEditDom.title = `ai写作` aiEditDom.onclick = function () { // instance.command.executeAiEdit('') @@ -1191,15 +1192,16 @@ window.onload = function () { }, '*' ) - outlineTextarea.value = AiResult.aiOutline - console.log('结果:', AiResult); - + // outlineTextarea.value = AiResult.aiOutline aiOutlineDom?.classList.add('hide') aiContentDom?.classList.remove('hide') aiMenuBox.classList.add('add-height') + outlineLoader.classList.remove('hide') } // 视图切换 function switchView(view: string) { + outlineTextarea.value == '' ? outlineLoader.classList.remove('hide') : '' + articleTextarea.value == '' ? articleLoader.classList.remove('hide') : '' switch (view) { case 'outline': watchOutline.classList.add('active-ai') @@ -1208,6 +1210,8 @@ window.onload = function () { aiInertBtn?.classList.add('hide') outlineViewDom.classList.remove('hide') articleViewDom.classList.add('hide') + // outlineLoader.classList.remove('hide') + // articleLoader.classList.add('hide') break case 'article': watchArticle.classList.add('active-ai') @@ -1216,6 +1220,8 @@ window.onload = function () { aiInertBtn?.classList.remove('hide') outlineViewDom.classList.add('hide') articleViewDom.classList.remove('hide') + // articleLoader.classList.remove('hide') + // outlineLoader.classList.add('hide') break default: break @@ -1239,7 +1245,17 @@ window.onload = function () { }, '*' ) - articleTextarea.value = AiResult.aiArticle + // articleTextarea.value = AiResult.aiArticle + } + // 替换textarea内容 + function changeAiArticleTextarea (data: string , type: string) { + if (type == 'outline') { + outlineTextarea.value = data + outlineLoader.classList.add('hide') + } else { + articleTextarea.value = data + articleLoader.classList.add('hide') + } } //插入文章 aiInertBtn.onclick = function () { @@ -2161,13 +2177,13 @@ window.onload = function () { }); } else if (eventData.type == 'aiReciver') { - console.log('接收到来自伏组件数据:', eventData.data); + console.log('接收到来自伏组件数据:', eventData); if (eventData.action == 'creation_leader') { - AiResult.aiOutline = eventData.data + changeAiArticleTextarea(eventData.data, 'outline') } else if (eventData.action == 'creation_builder') { - AiResult.aiArticle = eventData.data + changeAiArticleTextarea(eventData.data, 'article') } else { - AiResult.aiContent = eventData.data + changeAiTextarea(eventData.data) } } diff --git a/packages/word/src/plugins/floatingToolbar/index.ts b/packages/word/src/plugins/floatingToolbar/index.ts index ffb5706..45026d4 100644 --- a/packages/word/src/plugins/floatingToolbar/index.ts +++ b/packages/word/src/plugins/floatingToolbar/index.ts @@ -6,7 +6,6 @@ import { ToolbarType } from './enum' import { IToolbarRegister } from './interface' import { PLUGIN_PREFIX } from './constant' import { Svgs } from './icons/Svgs' -import { AiResult } from '../../editor/dataset/constant/AIResult' function createPickerToolbar( container: HTMLDivElement, toolbarType: ToolbarType, @@ -103,9 +102,9 @@ function createAIToolbar(
-
+
${Svgs.refresh} -
+