Skip to content

Commit 380acb7

Browse files
committed
fix:fix review
1 parent 567a3b8 commit 380acb7

5 files changed

Lines changed: 73 additions & 40 deletions

File tree

packages/canvas/DesignCanvas/src/api/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export type AIHelperState = 'hidden' | 'chat' | 'loading' | 'confirm' | 'complet
66

77
export interface NodeAIStatus {
88
state: AIHelperState
9+
collapsed?: boolean // 面板是否收起(收起时保留原状态,重新打开可恢复)
910
aiContext?: any
1011
lastAIAction?: string
1112
aiHistory?: Array<{

packages/canvas/container/src/components/AILoadingDialog.vue

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,6 @@ export default {
8484
display: flex;
8585
gap: 12px;
8686
align-items: center;
87-
.refresh-icon {
88-
cursor: pointer;
89-
color: #000;
90-
font-size: 18px;
91-
}
9287
.actions-btn {
9388
min-width: 40px;
9489
height: 28px;

packages/canvas/container/src/components/CanvasAIChat.vue

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,9 @@ export default {
3636
content.value = ''
3737
}
3838
39-
const handleClose = () => {
40-
emit('close')
41-
}
42-
4339
return {
4440
content,
45-
handleSubmit,
46-
handleClose
41+
handleSubmit
4742
}
4843
}
4944
}

packages/canvas/container/src/components/CanvasAction.vue

Lines changed: 59 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -93,25 +93,36 @@
9393
</div>
9494
<!-- AI助手按钮(默认状态:隐藏) -->
9595
<div title="AI助手" class="ai-helper">
96-
<svg-icon name="add-group" @click.stop="openAIHelper"></svg-icon>
97-
<CanvasAIChat
98-
v-if="shouldShowAIChat"
99-
class="ai-component"
100-
@complete="handleAIChatComplete"
101-
@close="closeAIHelper"
102-
></CanvasAIChat>
103-
<AILoadingDialog
104-
v-if="shouldShowAILoading"
105-
class="ai-component"
106-
@cancel="handleAILoadingCancel"
107-
></AILoadingDialog>
108-
<AIConfirmDialog
109-
v-if="shouldShowAIConfirm"
110-
class="ai-component"
111-
@confirm="handleAIConfirm"
112-
@cancel="handleAICancel"
113-
@refresh="handleAIRefresh"
114-
></AIConfirmDialog>
96+
<TinyPopover
97+
v-model="showAIPopover"
98+
placement="bottom-start"
99+
width="360"
100+
popper-class="ai-popper"
101+
trigger="manual"
102+
:visible-arrow="false"
103+
>
104+
<CanvasAIChat
105+
v-if="shouldShowAIChat"
106+
class="ai-component"
107+
@complete="handleAIChatComplete"
108+
@close="closeAIHelper"
109+
></CanvasAIChat>
110+
<AILoadingDialog
111+
v-if="shouldShowAILoading"
112+
class="ai-component"
113+
@cancel="handleAILoadingCancel"
114+
></AILoadingDialog>
115+
<AIConfirmDialog
116+
v-if="shouldShowAIConfirm"
117+
class="ai-component"
118+
@confirm="handleAIConfirm"
119+
@cancel="handleAICancel"
120+
@refresh="handleAIRefresh"
121+
></AIConfirmDialog>
122+
<template #reference>
123+
<svg-icon name="add-group" @click.stop="openAIHelper"></svg-icon>
124+
</template>
125+
</TinyPopover>
115126
</div>
116127
</div>
117128
</div>
@@ -367,6 +378,15 @@ export default {
367378
return shouldShowNodeAILoading(currentSchema.id)
368379
})
369380
381+
const showAIPopover = computed(() => {
382+
const currentSchema = getCurrent().schema
383+
if (!currentSchema?.id) {
384+
return false
385+
}
386+
const status = getNodeAIStatus(currentSchema?.id)
387+
return status?.state !== 'hidden' && !status?.collapsed
388+
})
389+
370390
// 切换AI助手显示/隐藏
371391
const openAIHelper = () => {
372392
const currentSchema = getCurrent().schema
@@ -377,23 +397,32 @@ export default {
377397
378398
const currentStatus = getNodeAIStatus(currentSchema.id)
379399
380-
if (currentStatus && currentStatus.state !== 'hidden') {
381-
// 如果AI助手当前不是隐藏状态,则关闭它
382-
closeNodeAIHelper(currentSchema.id)
400+
if (currentStatus && currentStatus.collapsed) {
401+
// 面板已收起,重新展开恢复原状态
402+
updateNodeAIStatus(currentSchema.id, { collapsed: false })
403+
} else if (currentStatus && currentStatus.state !== 'hidden') {
404+
// 面板当前可见,收起面板但保留业务状态
405+
updateNodeAIStatus(currentSchema.id, { collapsed: true })
383406
} else {
384-
// 如果AI助手当前是隐藏状态,则打开它
407+
// hidden状态,进入chat
385408
openNodeAIChat(currentSchema.id)
386409
}
387410
}
388411
389-
// 关闭AI助手(由其他组件调用,如AI聊天界面
412+
// 关闭AI助手(由其他组件调用,如AI聊天界面的关闭按钮
390413
const closeAIHelper = () => {
391414
const currentSchema = getCurrent().schema
392415
if (!currentSchema?.id) {
393416
return
394417
}
395418
396-
closeNodeAIHelper(currentSchema.id)
419+
const currentStatus = getNodeAIStatus(currentSchema.id)
420+
// loading/confirm状态下只收起面板,保留状态以便重新打开恢复
421+
if (currentStatus && (currentStatus.state === 'loading' || currentStatus.state === 'confirm')) {
422+
updateNodeAIStatus(currentSchema.id, { collapsed: true })
423+
} else {
424+
closeNodeAIHelper(currentSchema.id)
425+
}
397426
}
398427
399428
const optionRef = ref(null)
@@ -902,6 +931,7 @@ export default {
902931
showQuickAction,
903932
showPopover,
904933
showToParent,
934+
showAIPopover,
905935
activeSetting,
906936
isModal,
907937
onMousedown,
@@ -1234,4 +1264,8 @@ export default {
12341264
transform: translateY(10px);
12351265
}
12361266
}
1267+
.ai-popper.ai-popper.tiny-popper.tiny-popover {
1268+
padding: 0;
1269+
border-radius: 40px;
1270+
}
12371271
</style>

packages/canvas/container/src/composables/useAIChat.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ const addNodeAIActionHistory = (nodeId: string, action: string, content: any) =>
8181
const openNodeAIChat = (nodeId: string, initialContent: string = '') => {
8282
updateNodeAIStatus(nodeId, {
8383
state: 'chat',
84+
collapsed: false,
8485
chatContent: initialContent,
8586
lastAIAction: 'open_chat'
8687
})
@@ -111,8 +112,10 @@ const confirmNodeAIAction = (nodeId: string) => {
111112
return
112113
}
113114

115+
// 采纳后直接回到hidden,completed无对应UI,避免需要点击两次才能重新打开
114116
updateNodeAIStatus(nodeId, {
115-
state: 'completed',
117+
state: 'hidden',
118+
collapsed: false,
116119
originalNodeData: deepClone(currentStatus.aiModifiedNodeData),
117120
aiModifiedNodeData: undefined,
118121
lastAIAction: 'confirm'
@@ -144,6 +147,7 @@ const cancelNodeAIAction = (nodeId: string) => {
144147

145148
updateNodeAIStatus(nodeId, {
146149
state: newState,
150+
collapsed: false,
147151
aiModifiedNodeData: undefined,
148152
lastAIAction: 'cancel'
149153
})
@@ -270,19 +274,20 @@ const hasAnyPendingAIModification = (): boolean => {
270274
// 获取当前节点是否应该显示AI聊天界面
271275
const shouldShowNodeAIChat = (nodeId: string): boolean => {
272276
const status = getNodeAIStatus(nodeId)
273-
return status?.state === 'chat'
277+
return status?.state === 'chat' && !status?.collapsed
274278
}
275279

276280
// 获取当前节点是否应该显示确认弹窗
277281
const shouldShowNodeAIConfirm = (nodeId: string): boolean => {
278282
const status = getNodeAIStatus(nodeId)
279-
return status?.state === 'confirm'
283+
return status?.state === 'confirm' && !status?.collapsed
280284
}
281285

282286
// 开始AI加载状态
283287
const startNodeAILoading = (nodeId: string, loadingMessage: string = 'AI处理中...') => {
284288
updateNodeAIStatus(nodeId, {
285289
state: 'loading',
290+
collapsed: false,
286291
lastAIAction: 'start_loading',
287292
aiContext: {
288293
loadingMessage,
@@ -300,6 +305,7 @@ const startNodeAILoading = (nodeId: string, loadingMessage: string = 'AI处理
300305
const completeNodeAILoading = (nodeId: string) => {
301306
updateNodeAIStatus(nodeId, {
302307
state: 'confirm',
308+
collapsed: false,
303309
lastAIAction: 'complete_loading'
304310
})
305311

@@ -320,6 +326,7 @@ const cancelNodeAILoading = (nodeId: string) => {
320326

321327
updateNodeAIStatus(nodeId, {
322328
state: newState,
329+
collapsed: false,
323330
aiContext: undefined,
324331
lastAIAction: 'cancel_loading'
325332
})
@@ -334,7 +341,7 @@ const cancelNodeAILoading = (nodeId: string) => {
334341
// 获取当前节点是否应该显示AI加载状态
335342
const shouldShowNodeAILoading = (nodeId: string): boolean => {
336343
const status = getNodeAIStatus(nodeId)
337-
return status?.state === 'loading'
344+
return status?.state === 'loading' && !status?.collapsed
338345
}
339346

340347
/**
@@ -645,6 +652,7 @@ const applyAIPatches = (nodeId: string, chatResponse: any, chatContent?: string)
645652

646653
updateNodeAIStatus(nodeId, {
647654
state: 'confirm',
655+
collapsed: false,
648656
chatContent,
649657
aiModifiedNodeData: modifiedNodeData
650658
})

0 commit comments

Comments
 (0)