优化: 前端DRY收敛与命名对齐
审批等待格式化与阈值沉 utils/time 正典 相对时间阶梯三套收敛 formatRelative 参数化 灵感状态表沉 constants,透传通道退役 aggText/clearOwn 等命名对齐,IPC 参数名统一 conversation_id
This commit is contained in:
@@ -55,7 +55,7 @@
|
||||
<!-- H1 修复:审批挂起时长提示(对齐 ToolCard: >2min 橙色 / >5min 红色脉冲)。
|
||||
后端 APPROVAL_TIMEOUT_MS 5min 静默拒绝,浮窗原本无计时,用户误以为还有时间。
|
||||
基于审批到达时间(popup 首次见到该 tc.id 的时刻)计时,与 ToolCard 同款语义同款样式。 -->
|
||||
<div v-if="waitSecsFor(tc.id) > 0" class="popup-item-wait" :class="'is-' + waitLevelFor(tc.id)">
|
||||
<div v-if="waitSecsFor(tc.id) > 0" class="popup-item-wait" :class="'is-' + waitLevelOf(waitSecsFor(tc.id))">
|
||||
{{ $t('aiTool.waitTime', { time: formatWaitTime(waitSecsFor(tc.id)) }) }}
|
||||
</div>
|
||||
<!-- path 类:目录提示 -->
|
||||
@@ -153,6 +153,7 @@ import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow'
|
||||
import { toolDisplayName } from '@/composables/ai/useToolCardHeader'
|
||||
import { dispatchApprovalIPC } from '@/composables/ai/useToolApproval'
|
||||
import { ApprovalPopupEvents } from '@/composables/ai/useApprovalPopup'
|
||||
import { formatWaitTime, waitLevelOf } from '@/utils/time'
|
||||
import ConfirmDialog from '@/components/ConfirmDialog.vue'
|
||||
import { useToast } from '@/composables/useToast'
|
||||
import type { AiToolCallInfo } from '@/api/types'
|
||||
@@ -189,30 +190,18 @@ function answerConfirm(ok: boolean) {
|
||||
// ── H1:审批挂起时长计时(对齐 ToolCard useToolApproval 的 waitSecs/waitLevel)──
|
||||
// 浮窗独立于主窗口,不直接复用 useToolApproval(那个绑定单 tc + 完整状态机 emit/防抖,
|
||||
// 浮窗已用 processingId/runApproval 自管)。这里基于「到达时间」(popup 首次见到 tc.id 的时刻)
|
||||
// 每秒刷新。语义/样式/阈值与 ToolCard 同款:120s long / 300s urgent。
|
||||
// 每秒刷新。格式化(formatWaitTime)与分级阈值(waitLevelOf,120s long / 300s urgent)
|
||||
// 收敛至 @/utils/time,与 ToolCard 同源。
|
||||
/** tc.id → 到达时刻(ms)。审批首次出现在 approvals 即记时;移除即清。 */
|
||||
const arrivalTimes = reactive(new Map<string, number>())
|
||||
/** tc.id → 已等待秒数(每秒 tick 更新)。 */
|
||||
const waitSecsMap = reactive(new Map<string, number>())
|
||||
let _waitTimer: ReturnType<typeof setInterval> | null = null
|
||||
|
||||
/** 格式化秒为 MM:SS(与 useToolApproval.formatWaitTime 同款) */
|
||||
function formatWaitTime(secs: number): string {
|
||||
const m = Math.floor(secs / 60)
|
||||
const s = secs % 60
|
||||
return `${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}`
|
||||
}
|
||||
/** 取某条审批已等待秒数(无记录返回 0) */
|
||||
function waitSecsFor(id: string): number {
|
||||
return waitSecsMap.get(id) ?? 0
|
||||
}
|
||||
/** 取等待级别(对齐 ToolCard: 300s urgent / 120s long / 其余 normal) */
|
||||
function waitLevelFor(id: string): 'normal' | 'long' | 'urgent' {
|
||||
const s = waitSecsFor(id)
|
||||
if (s >= 300) return 'urgent'
|
||||
if (s >= 120) return 'long'
|
||||
return 'normal'
|
||||
}
|
||||
/** 每秒刷新所有挂起审批的 waitSecs(单 timer 驱动多 tc,避免每条一个 interval) */
|
||||
function _tickWaitSecs() {
|
||||
const now = Date.now()
|
||||
|
||||
Reference in New Issue
Block a user