From 5fd2505a3358fd3887af58aaa37cf85cd83d403e Mon Sep 17 00:00:00 2001 From: kuaifan Date: Tue, 23 Sep 2025 14:41:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=20AI=20=E7=94=9F?= =?UTF-8?q?=E6=88=90=E4=BA=A4=E4=BA=92=E4=BD=93=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除不必要的 loading 状态,简化用户交互 - 在项目和任务生成中添加取消功能,提升用户体验 - 更新相关组件以支持取消操作,确保生成过程的灵活性 --- resources/assets/js/pages/manage.vue | 29 ++++++++++--------- .../manage/components/ChatInput/index.vue | 23 +++++++++++---- .../js/pages/manage/components/TaskAdd.vue | 16 ++++++++++ 3 files changed, 49 insertions(+), 19 deletions(-) diff --git a/resources/assets/js/pages/manage.vue b/resources/assets/js/pages/manage.vue index 4ce7ce44d..cf815c37d 100644 --- a/resources/assets/js/pages/manage.vue +++ b/resources/assets/js/pages/manage.vue @@ -250,7 +250,6 @@
@@ -464,7 +463,6 @@ export default { columns: '', flow: 'open', }, - projectAiLoading: false, addRule: { name: [ { required: true, message: this.$L('请填写项目名称!'), trigger: 'change' }, @@ -999,7 +997,6 @@ export default { onAddShow() { this.$store.dispatch("getColumnTemplate").catch(() => {}) - this.projectAiLoading = false; this.addShow = true; this.$nextTick(() => { this.$refs.projectName.focus(); @@ -1007,9 +1004,7 @@ export default { }, onProjectAI() { - if (this.projectAiLoading) { - return; - } + let canceled = false; $A.modalInput({ title: 'AI 生成', placeholder: '请简要描述项目目标、范围或关键里程碑,AI 将生成名称和任务列表', @@ -1019,12 +1014,18 @@ export default { autosize: {minRows: 2, maxRows: 6}, maxlength: 500, }, + onCancel: () => { + canceled = true; + }, onOk: (value) => { if (!value) { return '请输入项目需求'; } return new Promise((resolve, reject) => { - this.projectAiLoading = true; + if (canceled) { + reject(); + return; + } const parseColumns = (cols) => { if (Array.isArray(cols)) { return cols; @@ -1042,10 +1043,6 @@ export default { columns: parseColumns(item.columns) })); - const finish = () => { - this.projectAiLoading = false; - }; - this.$store.dispatch("call", { url: 'project/ai/generate', data: { @@ -1056,6 +1053,10 @@ export default { }, timeout: 45 * 1000, }).then(({data}) => { + if (canceled) { + resolve(); + return; + } const columns = Array.isArray(data.columns) ? data.columns : parseColumns(data.columns); this.$set(this.addData, 'name', data.name || ''); this.$set(this.addData, 'columns', columns.length > 0 ? columns.join(',') : ''); @@ -1064,10 +1065,12 @@ export default { this.$refs.projectName.focus(); } }); - finish(); resolve(); }).catch(({msg}) => { - finish(); + if (canceled) { + resolve(); + return; + } reject(msg); }); }); diff --git a/resources/assets/js/pages/manage/components/ChatInput/index.vue b/resources/assets/js/pages/manage/components/ChatInput/index.vue index ea60b5a72..5ef25d0cc 100755 --- a/resources/assets/js/pages/manage/components/ChatInput/index.vue +++ b/resources/assets/js/pages/manage/components/ChatInput/index.vue @@ -433,8 +433,6 @@ export default { showMore: false, showEmoji: false, - chatAiLoading: false, - emojiQuickShow: false, emojiQuickKey: '', emojiQuickItems: [], @@ -1823,13 +1821,14 @@ export default { }, onMessageAI() { - if (this.disabled || this.chatAiLoading) { + if (this.disabled) { return; } if (!this.dialogId) { $A.messageWarning(this.$L('当前未选择会话')); return; } + let canceled = false; $A.modalInput({ title: 'AI 生成', placeholder: '请简要描述消息的主题、语气或要点,AI 将生成完整消息', @@ -1839,12 +1838,18 @@ export default { autosize: {minRows: 2, maxRows: 6}, maxlength: 500, }, + onCancel: () => { + canceled = true; + }, onOk: (value) => { if (!value) { return '请输入消息需求'; } return new Promise((resolve, reject) => { - this.chatAiLoading = true; + if (canceled) { + reject(); + return; + } this.$store.dispatch('call', { url: 'dialog/msg/ai_generate', data: { @@ -1856,6 +1861,10 @@ export default { timeout: 45 * 1000, }).then(({data}) => { const html = data && (data.html || data.text) ? (data.html || data.text) : ''; + if (canceled) { + resolve(); + return; + } if (!html) { reject(this.$L('AI 未生成内容')); return; @@ -1864,9 +1873,11 @@ export default { this.$nextTick(() => this.focus()); resolve(); }).catch(({msg}) => { + if (canceled) { + resolve(); + return; + } reject(msg); - }).finally(() => { - this.chatAiLoading = false; }); }); } diff --git a/resources/assets/js/pages/manage/components/TaskAdd.vue b/resources/assets/js/pages/manage/components/TaskAdd.vue index b64663006..dd7f9756e 100644 --- a/resources/assets/js/pages/manage/components/TaskAdd.vue +++ b/resources/assets/js/pages/manage/components/TaskAdd.vue @@ -625,6 +625,7 @@ export default { }, onAI() { + let canceled = false; $A.modalInput({ title: 'AI 生成', placeholder: '请简要描述任务目标、背景或预期交付,AI 将生成标题、详细说明和子任务', @@ -634,11 +635,18 @@ export default { autosize: { minRows: 2, maxRows: 6 }, maxlength: 500, }, + onCancel: () => { + canceled = true; + }, onOk: (value) => { if (!value) { return `请输入任务描述` } return new Promise((resolve, reject) => { + if (canceled) { + reject(); + return; + } // 获取当前任务模板信息 const currentTemplate = this.templateActiveID ? this.taskTemplateList.find(item => item.id === this.templateActiveID) : null; @@ -660,6 +668,10 @@ export default { }, timeout: 60 * 1000, }).then(({data}) => { + if (canceled) { + resolve(); + return; + } this.addData.name = data.title; this.$refs.editorTaskRef.setContent(data.content, {format: 'raw'}); if (Array.isArray(data.subtasks) && data.subtasks.length > 0) { @@ -695,6 +707,10 @@ export default { } resolve(); }).catch(({msg}) => { + if (canceled) { + resolve(); + return; + } reject(msg); }); })