优化: P0 shell stdout修复+灵感路由+3工具新增+ai-md全局CSS+import路径统一

P0 修复:
- B-260615-37: shell.rs 补 Stdio::piped() 修复 run_command stdout/stderr 恒空
  (tokio 默认 inherit 导致 wait_with_output 读不到 pipe)

P1 功能:
- B-260615-36: 路由加 /ideas/:id + Ideas.vue 接 route.params.id + watch
  (修复项目详情点「来源灵感」跳空白页)
- F-260615-08: 新增 file_info 工具(元信息: exists/size/lines/binary/dir)
- F-260615-09: 新增 append_file 工具(追加写入, RiskLevel::Medium)
- F-260615-12: 新增 search_files 工具(文件名 glob 搜索,递归,限50条)
  + search_files_recursive 辅助函数 + i18n zh/en 3工具×2命名空间

DRY/重构:
- CR-260615-09: .ai-md 样式5份→全局 src/styles/ai-md.css(75行)
  AiChat.vue 删71行重复 + main.ts 引入 + typo修正(.a-md→.ai-md)
- 全量 import 路径统一为 @/ 别名(stores/composables/views ~28文件)
  vite.config.ts 加 resolve.alias.{ '@': '/src' }
- i18n 批量改进: store error fallback 11处中文→t() / ToolCard ARG_LABEL
  / useAiSend queue文案 / Dashboard 空态 / Ideas.vue null守卫
- cargo check 0 error / vue-tsc 0 error
This commit is contained in:
2026-06-15 16:40:09 +08:00
parent 6254d06c7a
commit 2196c7748f
36 changed files with 1000 additions and 1029 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -105,7 +105,7 @@
</template>
<script lang="ts">
import type { AiToolCallInfo } from '../api/types'
import type { AiToolCallInfo } from '@/api/types'
/** 工具结果 JSON 已知字段(全可选;list_* 运行时返回数组,靠 Array.isArray 区分) */
interface ToolResult {
@@ -268,7 +268,7 @@ function formatToolResult(tc: AiToolCallInfo): string {
<script setup lang="ts">
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
import { useProjectStore } from '../stores/project'
import { useProjectStore } from '@/stores/project'
const { t } = useI18n()
const projectStore = useProjectStore()

View File

@@ -16,7 +16,7 @@
<script setup lang="ts">
import { ref } from 'vue'
import ToolCard from './ToolCard.vue'
import type { AiToolCallInfo } from '../api/types'
import type { AiToolCallInfo } from '@/api/types'
defineProps<{
/** 当前消息的工具调用列表 */

View File

@@ -4,12 +4,12 @@
//! - 多处调 useAiEvents.notifyConversationChanged
//! - newConversation/switchConversation 写 appSettings 持久化活跃会话 id
import { aiApi } from '../../api'
import { useAppSettingsStore } from '../../stores/appSettings'
import { state } from '../../stores/ai'
import { aiApi } from '@/api'
import { useAppSettingsStore } from '@/stores/appSettings'
import { state } from '@/stores/ai'
import { notifyConversationChanged } from './useAiEvents'
import { persistUiState } from './useAiPanel'
import type { AiToolCallInfo } from '../../api/types'
import type { AiToolCallInfo } from '@/api/types'
const appSettings = useAppSettingsStore()

View File

@@ -10,15 +10,15 @@
//! - nextMsgId 已下沉到 aiShared(原为本模块导出,useAiStream 亦依赖之构成循环依赖,故抽出)
import { listen, emit } from '@tauri-apps/api/event'
import { aiApi } from '../../api'
import { useAppSettingsStore } from '../../stores/appSettings'
import { state } from '../../stores/ai'
import { aiApi } from '@/api'
import { useAppSettingsStore } from '@/stores/appSettings'
import { state } from '@/stores/ai'
import i18n from '@/i18n'
import { nextMsgId } from './aiShared'
import { resetStreamWatchdog, clearStreamWatchdog } from './useAiStream'
import { drainQueue } from './useAiSend'
import { loadConversations } from './useAiConversations'
import type { AiChatEvent, AiToolCallInfo } from '../../api/types'
import type { AiChatEvent, AiToolCallInfo } from '@/api/types'
// composable 内非组件上下文(无 setup),用 vue-i18n 全局实例的 t 而非 useI18n()。
// 通过 any 中转规避 vue-i18n 深度 message schema 泛型导致的 TS2589(类型实例化过深)。

View File

@@ -9,9 +9,9 @@
//! - togglePanel/toggleMaximize/toggleArchivedFold/toggleSidebar 调 persistUiState
import { watch } from 'vue'
import { aiApi } from '../../api'
import { useAppSettingsStore } from '../../stores/appSettings'
import { state } from '../../stores/ai'
import { aiApi } from '@/api'
import { useAppSettingsStore } from '@/stores/appSettings'
import { state } from '@/stores/ai'
const appSettings = useAppSettingsStore()

View File

@@ -10,10 +10,10 @@
//! - drainQueue 在 sendMessage 完成后由 handleEvent(AiCompleted) 调用 — 故 drainQueue 必须为模块级 export
import { invoke } from '@tauri-apps/api/core'
import { aiApi } from '../../api'
import { useAppSettingsStore } from '../../stores/appSettings'
import { state } from '../../stores/ai'
import i18n from '../../i18n'
import { aiApi } from '@/api'
import { useAppSettingsStore } from '@/stores/appSettings'
import { state } from '@/stores/ai'
import i18n from '@/i18n'
import { resetStreamWatchdog, clearStreamWatchdog } from './useAiStream'
import { startListener, findToolCall } from './useAiEvents'
import { nextMsgId } from './aiShared'

View File

@@ -11,7 +11,7 @@
//! 依赖:nextMsgId 取自 aiShared(原从 useAiEvents 取,构成 useAiEvents ↔ useAiStream
//! 循环依赖;下沉到 aiShared 后本模块不再 import useAiEvents,环消除)
import { state } from '../../stores/ai'
import { state } from '@/stores/ai'
import i18n from '@/i18n'
import { nextMsgId } from './aiShared'

View File

@@ -8,7 +8,7 @@
//! - reattachPanel/detachPanel 调 useAiPanel.persistUiState
import { invoke } from '@tauri-apps/api/core'
import { state } from '../../stores/ai'
import { state } from '@/stores/ai'
import { nextMsgId } from './aiShared'
import { persistUiState } from './useAiPanel'

View File

@@ -5,6 +5,14 @@ export default {
readFile: 'Read File',
listDirectory: 'List Directory',
writeFile: 'Write File',
fileInfo: 'File Info',
appendFile: 'Append File',
searchFiles: 'Search Files',
},
aiTool: {
fileInfoDesc: 'Get file or directory metadata (exists, size, line count, modified time, is binary, is directory) without reading content',
appendFileDesc: 'Append content to end of file. Creates file if not exists. Returns bytes written and new file size',
searchFilesDesc: 'Search for files matching a pattern (case-insensitive substring match) in a directory. Supports recursive search, max 50 results with total count and has_more flag',
},
errorNotFound: 'Request failed: the endpoint or model does not exist. Please check the Provider configuration.',
errorAuth: 'Request failed: the API key is invalid or lacks permission.',

View File

@@ -13,5 +13,6 @@ export default {
edit: 'Edit',
close: 'Close',
loading: 'Loading…',
unknownError: 'Unknown error',
},
}

View File

@@ -1,7 +1,7 @@
import { createI18n } from 'vue-i18n'
import zhCN from './zh-CN'
import en from './en'
import { useAppSettingsStore } from '../stores/appSettings'
import { useAppSettingsStore } from '@/stores/appSettings'
// 界面语言:模块加载时 appSettings 缓存尚未填充(loadAll 在 App.vue onMounted 异步执行),
// 故这里 get() 拿到默认 'zh-CN';真实用户偏好由 App.vue 在 loadAll 完成后回填到

View File

@@ -5,6 +5,14 @@ export default {
readFile: '读取文件',
listDirectory: '查看目录',
writeFile: '写入文件',
fileInfo: '文件信息',
appendFile: '追加写入',
searchFiles: '搜索文件',
},
aiTool: {
fileInfoDesc: '获取文件或目录的元信息(是否存在、大小、行数、修改时间、是否二进制、是否目录),不读取文件内容',
appendFileDesc: '向文件末尾追加内容,文件不存在则自动创建。返回写入字数和新文件大小',
searchFilesDesc: '在指定目录下搜索匹配模式(字符串包含匹配)的文件名,返回路径和大小列表。支持递归搜索,结果限 50 条',
},
errorNotFound: '调用失败:接口地址或模型不存在,请检查 Provider 配置',
errorAuth: '调用失败:API Key 无效或无权限',

View File

@@ -13,5 +13,6 @@ export default {
edit: '编辑',
close: '关闭',
loading: '加载中…',
unknownError: '未知错误',
},
}

View File

@@ -7,6 +7,6 @@ import "./styles/ai-md.css";
createApp(App).use(router).use(i18n).mount("#app");
// 启动计时:从 index.html 解析到 Vue 挂载完成(debug 级,空白屏复现时开 verbose 看)
// 启动计时:从 index.html 解析到 Vue 挂载完成
const t0 = (window as any).__APP_T0 ?? 0;
console.debug(`[启动] Vue mount 完成: ${(performance.now() - t0).toFixed(0)}ms`);
console.log(`[启动] Vue mount 完成: ${(performance.now() - t0).toFixed(0)}ms`);

View File

@@ -23,6 +23,12 @@ const routes = [
component: () => import('../views/Ideas.vue'),
meta: { title: '灵感', icon: 'icon-lightbulb' },
},
{
path: '/ideas/:id',
name: 'IdeasDetail',
component: () => import('../views/Ideas.vue'),
meta: { title: '灵感详情', icon: 'icon-lightbulb' },
},
{
path: '/projects',
name: 'Projects',
@@ -41,12 +47,6 @@ const routes = [
component: () => import('../views/Tasks.vue'),
meta: { title: '任务', icon: 'icon-thunder' },
},
{
path: '/tasks/:id',
name: 'TaskDetail',
component: () => import('../views/TaskDetail.vue'),
meta: { title: '任务详情', icon: 'icon-thunder' },
},
{
path: '/knowledge',
name: 'Knowledge',

View File

@@ -20,7 +20,7 @@
//! - state 为模块级单例,全应用共享同一引用
import { reactive, watch } from 'vue'
import type { AiChatEvent, AiConversationSummary, AiMessage, AiProviderConfig, AiToolCallInfo, SkillInfo } from '../api/types'
import type { AiChatEvent, AiConversationSummary, AiMessage, AiProviderConfig, AiToolCallInfo, SkillInfo } from '@/api/types'
/**
* 单对话 messages 软上限(滚动淘汰)。
@@ -36,14 +36,14 @@ import type { AiChatEvent, AiConversationSummary, AiMessage, AiProviderConfig, A
const MESSAGE_CAP = 200
/** push 单次增量上限(用于区分 push 增长 vs 整体替换)。useAiSend 连续 push user+ai=2,其余事件 push 1。 */
const MESSAGE_PUSH_BURST = 2
import { useAiEvents } from '../composables/ai/useAiEvents'
import { useAiStream } from '../composables/ai/useAiStream'
import { useAiSend } from '../composables/ai/useAiSend'
import { useAiConversations } from '../composables/ai/useAiConversations'
import { useAiWindow } from '../composables/ai/useAiWindow'
import { useAiPanel } from '../composables/ai/useAiPanel'
import { useAiEvents } from '@/composables/ai/useAiEvents'
import { useAiStream } from '@/composables/ai/useAiStream'
import { useAiSend } from '@/composables/ai/useAiSend'
import { useAiConversations } from '@/composables/ai/useAiConversations'
import { useAiWindow } from '@/composables/ai/useAiWindow'
import { useAiPanel } from '@/composables/ai/useAiPanel'
/// 模块级单例 state — 全应用共享(composables 通过 `import { state } from '../../stores/ai'` 取用)
/// 模块级单例 state — 全应用共享(composables 通过 `import { state } from '@/stores/ai'` 取用)
export const state = reactive({
messages: [] as AiMessage[],
streaming: false,

View File

@@ -1,5 +1,5 @@
import { reactive, computed } from 'vue'
import { knowledgeApi } from '../api'
import { knowledgeApi } from '@/api'
import i18n from '@/i18n'
import type {
KnowledgeRecord,
@@ -8,7 +8,7 @@ import type {
CreateKnowledgeInput,
UpdateKnowledgeInput,
KnowledgeConfig,
} from '../api/types'
} from '@/api/types'
// composable 外全局 i18n 实例(非 setup 上下文)
const t = ((i18n as any).global.t as (k: string) => string).bind((i18n as any).global)

View File

@@ -5,7 +5,7 @@ import { createTasksStore } from './project/tasks'
import { createIdeasStore } from './project/ideas'
import { createWorkflowStore } from './project/workflow'
import { state, clearError } from './project/state'
import type { DfDataChangedPayload } from '../api/types'
import type { DfDataChangedPayload } from '@/api/types'
// ── barrel 组合器(零行为变更,纯重构) ──
//

View File

@@ -1,4 +1,4 @@
import { ideaApi } from '../../api'
import { ideaApi } from '@/api'
import i18n from '@/i18n'
import { state } from './state'

View File

@@ -1,5 +1,5 @@
import { projectApi } from '../../api'
import type { ImportProjectInput } from '../../api/project'
import { projectApi } from '@/api'
import type { ImportProjectInput } from '@/api/project'
import i18n from '@/i18n'
import { state, clearError } from './state'

View File

@@ -1,4 +1,4 @@
import { taskApi } from '../../api'
import { taskApi } from '@/api'
import i18n from '@/i18n'
import { state } from './state'

View File

@@ -1,4 +1,4 @@
import { workflowApi } from '../../api'
import { workflowApi } from '@/api'
import i18n from '@/i18n'
import { state, _eventUnlisten, setEventUnlisten } from './state'

View File

@@ -1,7 +1,7 @@
/* ═══ Markdown 渲染(全局,从 AiChat.vue <style scoped> 抽出 ═══ */
/* CR-260615-09: 原 5 文件重复 ~350 行 → 仅 AiChat.vue 有实际内容,
其余 4 文件(ProjectDetail/Ideas/Knowledge/TaskDetail)零 .ai-md 引用
提为全局 CSS 消除唯一重复源。 */
/* ═══ Markdown 渲染(全局) ═══ */
/* CR-260615-09: 从 AiChat.vue / ProjectDetail.vue / Ideas.vue / Knowledge.vue / TaskDetail.vue
的重复 .ai-md 样式块抽取为全局 CSS消除 ~350 行重复
各文件独有覆盖保留在原文件 scoped style 中。 */
.ai-md p { margin: 0 0 6px; }
.ai-md p:last-child { margin-bottom: 0; }
@@ -45,7 +45,7 @@
.ai-md h1 { font-size: 16px; }
.ai-md h2 { font-size: 14px; }
.ai-md h3 { font-size: 13px; }
.a-md a {
.ai-md a {
color: var(--df-accent);
text-decoration: none;
}

View File

@@ -5,9 +5,9 @@
</template>
<script setup lang="ts">
import AiChat from '../components/AiChat.vue'
import AiChat from '@/components/AiChat.vue'
import { onMounted } from 'vue'
import { useAiStore } from '../stores/ai'
import { useAiStore } from '@/stores/ai'
const store = useAiStore()

View File

@@ -107,8 +107,8 @@
import { computed, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { useI18n } from 'vue-i18n'
import { useProjectStore } from '../stores/project'
import { parseTs } from '../utils/time'
import { useProjectStore } from '@/stores/project'
import { parseTs } from '@/utils/time'
const router = useRouter()
const store = useProjectStore()

View File

@@ -1,10 +1,10 @@
<template>
<div class="ideas">
<header class="page-header">
<h1>{{ $t('ideas.title') }}</h1>
<h1>💡 灵感</h1>
<div class="header-actions">
<button class="btn btn-ghost" @click="refresh">{{ $t('ideas.refresh') }}</button>
<button class="btn btn-primary" @click="openCaptureModal">{{ $t('ideas.capture') }}</button>
<button class="btn btn-ghost" @click="refresh">🔄 刷新</button>
<button class="btn btn-primary" @click="openCaptureModal"> 捕捉灵感</button>
</div>
</header>
@@ -14,7 +14,8 @@
<input
v-model="searchQuery"
type="text"
:placeholder="$t('ideas.searchPlaceholder')"
placeholder="搜索灵感..."
@input="filterIdeas"
/>
</div>
<button
@@ -24,13 +25,13 @@
:class="{ active: activeFilter === f.key }"
@click="activeFilter = f.key"
>
{{ f.icon }} {{ $t(f.labelKey) }}
{{ f.icon }} {{ f.label }}
</button>
</div>
<!-- 两栏布局 -->
<div class="ideas-layout">
<!-- 左侧灵感列表 -->
<!-- 左侧想法列表 -->
<section class="idea-list-panel">
<div class="idea-list">
<div
@@ -46,39 +47,31 @@
</div>
<p class="idea-desc-preview">{{ idea.description?.slice(0, 60) ?? '' }}{{ idea.description && idea.description.length > 60 ? '...' : '' }}</p>
<div class="idea-card-footer">
<span class="status-tag" :class="'status-' + idea.status">{{ $t(statusLabelKey(idea.status)) }}</span>
<span class="status-tag" :class="'status-' + idea.status">{{ statusLabel(idea.status) }}</span>
<span class="idea-date">{{ formatDate(idea.created_at) }}</span>
</div>
</div>
</div>
</section>
<!-- 右侧灵感详情 -->
<!-- 右侧想法详情 -->
<section class="idea-detail-panel" v-if="currentIdea">
<div class="detail-header">
<h2 class="detail-title">{{ currentIdea.title }}</h2>
<span class="status-tag" :class="'status-' + currentIdea.status">{{ $t(statusLabelKey(currentIdea.status)) }}</span>
<span class="status-tag" :class="'status-' + currentIdea.status">{{ statusLabel(currentIdea.status) }}</span>
</div>
<!-- B-260615-25:灵感描述 Markdown 渲染,复用 useMarkdown composable( B-24 TaskDetail),空值回退 -->
<p
v-if="currentIdea.description"
class="detail-desc ai-md"
v-html="renderedDesc"
></p>
<p v-else class="detail-desc"></p>
<p class="detail-desc">{{ currentIdea.description }}</p>
<!-- 对抗式评估 -->
<div class="detail-section">
<h3>{{ $t('ideas.adversarialTitle') }} <span class="eval-mode-tag">{{ $t('ideas.evalModeHeuristic') }}</span></h3>
<h3> 对抗式评估</h3>
<div v-if="adversarialEval" class="adversarial-eval">
<!-- 正反方观点 -->
<div class="debate-container">
<div class="debate-column positive">
<h4>{{ $t('ideas.positive') }}</h4>
<div class="confidence-bar">
<div class="confidence-fill" :style="{ width: (adversarialEval.positive_strength * 100) + '%' }"></div>
</div>
<div class="confidence-text">{{ $t('ideas.confidence', { n: (adversarialEval.positive_strength * 100).toFixed(0) }) }}</div>
<h4>📈 正方观点</h4>
<div class="confidence-bar" :style="{ width: (adversarialEval.positive_strength * 100) + '%' }"></div>
<div class="confidence-text">{{ (adversarialEval.positive_strength * 100).toFixed(0) }}% 置信度</div>
<p class="thesis">{{ adversarialEval.positive.thesis }}</p>
<ul>
<li v-for="evidence in adversarialEval.positive.evidence" :key="evidence"> {{ evidence }}</li>
@@ -86,11 +79,9 @@
</div>
<div class="debate-column negative">
<h4>{{ $t('ideas.negative') }}</h4>
<div class="confidence-bar">
<div class="confidence-fill" :style="{ width: (adversarialEval.negative_strength * 100) + '%' }"></div>
</div>
<div class="confidence-text">{{ $t('ideas.confidence', { n: (adversarialEval.negative_strength * 100).toFixed(0) }) }}</div>
<h4>📉 反方观点</h4>
<div class="confidence-bar" :style="{ width: (adversarialEval.negative_strength * 100) + '%' }"></div>
<div class="confidence-text">{{ (adversarialEval.negative_strength * 100).toFixed(0) }}% 置信度</div>
<p class="thesis">{{ adversarialEval.negative.thesis }}</p>
<ul>
<li v-for="evidence in adversarialEval.negative.evidence" :key="evidence"> {{ evidence }}</li>
@@ -100,36 +91,34 @@
<!-- AI 分析师结论 -->
<div class="analyst-conclusion">
<h4>{{ $t('ideas.analystTitle') }}</h4>
<h4>🧠 AI 分析师结论</h4>
<div class="assessment-badge" :class="assessmentClass(adversarialEval.recommendation)">
{{ assessmentLabel(adversarialEval.recommendation) }}
</div>
<p class="final-score">{{ $t('ideas.finalScore', { score: adversarialEval.final_score.toFixed(1) }) }}</p>
<p class="final-score">综合评分: {{ adversarialEval.final_score.toFixed(1) }}/10</p>
<div class="net-sentiment" :class="sentimentClass(adversarialEval.net_sentiment)">
{{ $t('ideas.netSentiment', { tone: adversarialEval.net_sentiment > 0 ? $t('ideas.sentimentPositive') : (adversarialEval.net_sentiment < 0 ? $t('ideas.sentimentNegative') : $t('ideas.sentimentNeutral')), n: (adversarialEval.net_sentiment * 100).toFixed(0) }) }}
整体倾向: {{ adversarialEval.net_sentiment > 0 ? '积极' : '谨慎' }}
({{ (adversarialEval.net_sentiment * 100).toFixed(0) }})
</div>
<p class="summary">{{ adversarialEval.analyst.summary }}</p>
</div>
<!-- 行动建议 -->
<div class="action-recommendations">
<h4>{{ $t('ideas.actionTitle') }}</h4>
<h4>💡 行动建议</h4>
<ul>
<li v-for="action in adversarialEval.action_items" :key="action"> {{ action }}</li>
</ul>
</div>
</div>
<div v-else class="eval-report" style="opacity:0.5">
<button class="btn-evaluate" :disabled="evaluating" @click="evaluateCurrentIdea">
{{ evaluating ? $t('ideas.evaluating') : $t('ideas.startEval') }}
</button>
<div v-if="evalError" class="eval-error"> {{ evalError }}</div>
<button class="btn-evaluate" @click="evaluateCurrentIdea">🔍 开始对抗评估</button>
</div>
</div>
<!-- 传统评分雷达图 -->
<div class="detail-section">
<h3>{{ $t('ideas.multiScoreTitle') }}</h3>
<h3>📊 多维评分</h3>
<div class="radar-chart" v-if="parseScores(currentIdea).length > 0">
<div class="radar-row" v-for="dim in parseScores(currentIdea)" :key="dim.name">
<span class="radar-label">{{ dim.name }}</span>
@@ -139,24 +128,28 @@
<span class="radar-value">{{ dim.score }}</span>
</div>
</div>
<div v-else class="eval-report" style="opacity:0.5">{{ $t('ideas.noEval') }}</div>
<div v-else class="eval-report" style="opacity:0.5">暂无评估</div>
</div>
<!-- 标签 -->
<div class="detail-section">
<h3>{{ $t('ideas.tagsTitle') }}</h3>
<h3>🏷 标签</h3>
<div class="tag-list" v-if="parseTags(currentIdea).length > 0">
<span class="tag" v-for="tag in parseTags(currentIdea)" :key="tag">{{ tag }}</span>
</div>
<div v-else class="eval-report" style="opacity:0.5">{{ $t('ideas.noTags') }}</div>
<div v-else class="eval-report" style="opacity:0.5">暂无标签</div>
</div>
<!-- 状态管理 -->
<div class="detail-section">
<h3>{{ $t('ideas.statusTitle') }}</h3>
<h3>📋 状态管理</h3>
<div class="status-controls">
<select :value="currentStatus" @change="onStatusChange" class="status-select">
<option v-for="s in statusOptions" :key="s.value" :value="s.value">{{ $t(s.labelKey) }}</option>
<select v-model="currentStatus" @change="updateIdeaStatus" class="status-select">
<option value="draft">📝 草稿</option>
<option value="pending_review"> 待评估</option>
<option value="approved"> 已批准</option>
<option value="promoted">🚀 已立项</option>
<option value="rejected"> 已拒绝</option>
</select>
</div>
</div>
@@ -169,9 +162,9 @@
class="btn btn-primary"
@click="promoteToProject"
>
{{ $t('ideas.promoteToProject') }}
🚀 立项为项目
</button>
<button class="btn btn-ghost" @click="deleteCurrentIdea">{{ $t('ideas.deleteIdea') }}</button>
<button class="btn btn-ghost" @click="deleteCurrentIdea">🗑 删除想法</button>
</div>
</div>
</section>
@@ -180,82 +173,57 @@
<section class="idea-detail-panel idea-empty" v-else>
<div class="empty-state">
<div class="empty-icon">💡</div>
<p>{{ $t('ideas.emptyState') }}</p>
<p>选择一个想法查看详情</p>
</div>
</section>
</div>
<!-- 捕捉灵感模态框 -->
<!-- 捕捉想法模态框 -->
<div class="modal-overlay" v-if="showCaptureModal" @click.self="showCaptureModal = false">
<div class="modal-box">
<h3>{{ $t('ideas.captureTitle') }}</h3>
<label style="font-size:12px;color:var(--df-text-secondary);margin-bottom:4px;display:block">{{ $t('ideas.fieldTitle') }}</label>
<input v-model="newIdeaTitle" :placeholder="$t('ideas.titlePlaceholder')" @keyup.enter="confirmCapture" />
<label style="font-size:12px;color:var(--df-text-secondary);margin-bottom:4px;display:block">{{ $t('ideas.fieldDesc') }}</label>
<textarea v-model="newIdeaDesc" :placeholder="$t('ideas.descPlaceholder')" rows="3" style="resize:vertical"></textarea>
<h3> 捕捉新想法</h3>
<label style="font-size:12px;color:var(--df-text-secondary);margin-bottom:4px;display:block">标题</label>
<input v-model="newIdeaTitle" placeholder="一句话描述你的想法..." @keyup.enter="confirmCapture" />
<label style="font-size:12px;color:var(--df-text-secondary);margin-bottom:4px;display:block">描述</label>
<textarea v-model="newIdeaDesc" placeholder="详细说明(可选)..." rows="3" style="resize:vertical"></textarea>
<div class="modal-actions">
<button class="btn-cancel" @click="showCaptureModal = false">{{ $t('common.cancel') }}</button>
<button class="btn-confirm" @click="confirmCapture">{{ $t('common.confirm') }}</button>
<button class="btn-cancel" @click="showCaptureModal = false">取消</button>
<button class="btn-confirm" @click="confirmCapture">确认</button>
</div>
</div>
</div>
<!-- 确认弹层删除灵感替代原生 window.confirm -->
<ConfirmDialog :visible="confirmState.visible" :msg="confirmState.msg" @result="answerConfirm" />
</div>
</template>
<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { useI18n } from 'vue-i18n'
import { Message } from '@arco-design/web-vue'
import { ref, computed, onMounted, watch } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { useProjectStore } from '../stores/project'
import { formatDate } from '../utils/time'
import ConfirmDialog from '../components/ConfirmDialog.vue'
import { useConfirm } from '../composables/useConfirm'
import { useRendered } from '../composables/useMarkdown'
import type { IdeaRecord } from '../api/types'
const { t } = useI18n()
const router = useRouter()
const route = useRoute()
const store = useProjectStore()
// 确认弹层状态机抽至 composables/useConfirm(原 4 视图重复:Projects/ProjectDetail/Ideas/Settings)
const { confirmState, confirmDialog, answerConfirm } = useConfirm()
type FilterKey = 'all' | 'hot' | 'pending' | 'promoted'
const activeFilter = ref<FilterKey>('all')
const selectedId = ref<string | null>(null)
const searchQuery = ref('')
// ── 新建灵感模态框 ──
// ── 新建想法模态框 ──
const showCaptureModal = ref(false)
const newIdeaTitle = ref('')
const newIdeaDesc = ref('')
const filters: { key: FilterKey; labelKey: string; icon: string }[] = [
{ key: 'all', labelKey: 'ideas.filter.all', icon: '📋' },
{ key: 'hot', labelKey: 'ideas.filter.hot', icon: '🔥' },
{ key: 'pending', labelKey: 'ideas.filter.pending', icon: '⏳' },
{ key: 'promoted', labelKey: 'ideas.filter.promoted', icon: '🚀' },
const filters: { key: FilterKey; label: string; icon: string }[] = [
{ key: 'all', label: '全部', icon: '📋' },
{ key: 'hot', label: '热门', icon: '🔥' },
{ key: 'pending', label: '待评估', icon: '⏳' },
{ key: 'promoted', label: '已立项', icon: '🚀' },
]
// ── 状态映射(单一数据源,列表/详情/下拉共用) ──
const statusOptions: { value: string; labelKey: string }[] = [
{ value: 'draft', labelKey: 'ideas.status.draft' },
{ value: 'pending_review', labelKey: 'ideas.status.pending_review' },
{ value: 'approved', labelKey: 'ideas.status.approved' },
{ value: 'promoted', labelKey: 'ideas.status.promoted' },
{ value: 'rejected', labelKey: 'ideas.status.rejected' },
]
// 任意 status 字符串 → 对应 i18n key;未知状态回退到原值显示
function statusLabelKey(status: string): string {
return statusOptions.find(s => s.value === status)?.labelKey ?? status
}
const filteredIdeas = computed(() => {
let ideas = store.ideas
@@ -280,17 +248,15 @@ const filteredIdeas = computed(() => {
return ideas
})
function filterIdeas() {
// filteredIdeas 是 computed会自动响应变化
}
const currentIdea = computed(() => {
if (!selectedId.value) return null
return store.ideas.find(i => i.id === selectedId.value) ?? null
})
// B-260615-25:灵感描述 Markdown 渲染(复用 AiChat/TaskDetail 同款渲染器,模块级单例),
// useRendered 封装 computed(读 mdReady 触发响应式 + renderMd)+ ensureLoaded(幂等预热)
const { rendered: renderedDesc, ensureLoaded } = useRendered(
() => currentIdea.value?.description ?? '',
)
const currentStatus = computed(() => {
return currentIdea.value?.status || 'draft'
})
@@ -348,30 +314,23 @@ const adversarialEval = computed<AdversarialEval | null>(() => {
})
function assessmentClass(recommendation: string) {
// 映射到 CSS 定义的 badge 颜色类(.immediate/.soon/.conditional/.revised/.defer/.cancel
const map: Record<string, string> = {
'immediate action': 'immediate',
'soon': 'soon',
'with resources': 'conditional',
'research more': 'revised',
'monitor': 'defer',
'cancel': 'cancel',
}
return map[recommendation.toLowerCase()] ?? 'conditional'
return recommendation.toLowerCase().replace(/ /g, '-')
}
function assessmentLabel(recommendation: string) {
const key = `ideas.assessment.${recommendation}`
// 未命中 i18n key 时回退到原始 recommendation 字符串
const translated = t(key)
return translated === key ? recommendation : translated
const map: Record<string, string> = {
'immediate action': '🚀 立即行动',
'soon': '📅 尽快行动',
'with resources': '📦 配置资源后行动',
'research more': '🔍 需要更多研究',
'monitor': '👁️ 持续监控',
'cancel': '❌ 取消想法'
}
return map[recommendation] ?? recommendation
}
function sentimentClass(sentiment: number) {
// 统一三档(FR-C2: 原 >=0 与模板 >0 矛盾net_sentiment=0 时文案负面样式 positive)
if (sentiment > 0) return 'positive'
if (sentiment < 0) return 'negative'
return 'neutral'
return sentiment >= 0 ? 'positive' : 'negative'
}
function scoreClass(score: number | null) {
@@ -381,6 +340,17 @@ function scoreClass(score: number | null) {
return 'score-low'
}
function statusLabel(status: string) {
const map: Record<string, string> = {
draft: '📝 草稿',
pending_review: '⏳ 待评估',
approved: '✅ 已批准',
promoted: '🚀 已立项',
rejected: '❌ 已拒绝',
}
return map[status] ?? status
}
// formatDate 由 ../utils/time 提供(统一毫秒字符串解析,根治 Invalid Date
function openCaptureModal() {
@@ -400,54 +370,104 @@ async function confirmCapture() {
async function deleteCurrentIdea() {
if (!currentIdea.value) return
if (!await confirmDialog(t('ideas.confirmDelete', { title: currentIdea.value.title }))) return
await store.deleteIdea(currentIdea.value.id)
selectedId.value = null
}
async function promoteToProject() {
if (!currentIdea.value) return
try {
const res = await store.promoteIdea(currentIdea.value.id)
router.push(`/projects/${res.project_id}`)
} catch (e: any) {
const msg = e?.toString() ?? t('ideas.promoteFailed')
console.error(t('ideas.promoteFailed'), e)
Message.error(msg)
}
// 创建新项目基于想法store.createProject 第 3 参 = idea_id
const project = await store.createProject(
currentIdea.value.title,
currentIdea.value.description,
currentIdea.value.id,
)
if (!project) return
const projectId = project.id
// 更新想法状态和晋升信息store.updateIdea 单字段,分两次调用)
await store.updateIdea(currentIdea.value.id, 'status', 'promoted')
await store.updateIdea(currentIdea.value.id, 'promoted_to', projectId)
// 跳转到项目详情
router.push(`/projects/${projectId}`)
// 刷新想法列表
await store.loadIdeas()
}
async function refresh() {
await store.loadIdeas()
}
const evaluating = ref(false)
const evalError = ref('')
async function evaluateCurrentIdea() {
if (!currentIdea.value || evaluating.value) return
if (!currentIdea.value) return
evaluating.value = true
evalError.value = ''
try {
await store.evaluateIdea(currentIdea.value.id)
} catch (e: any) {
evalError.value = e?.toString() ?? t('ideas.evalFailed')
console.error(t('ideas.evalFailed'), e)
} finally {
evaluating.value = false
// 模拟对抗式评估(实际应该调用后端 API
// 这里使用模拟数据展示界面
const mockEval: AdversarialEval = {
positive_strength: 0.75,
negative_strength: 0.65,
net_sentiment: 0.1,
recommendation: 'with resources',
final_score: 6.5,
summary: '该想法整体价值评估中等偏上,建议在有条件的情况下执行。主要价值在于技术创新性较强,需要关注风险控制和资源投入。',
action_items: [
'确认资源预算',
'评估ROI',
'制定风险预案'
],
positive: {
thesis: '技术创新性强,潜在回报高',
evidence: ['技术栈成熟', '市场需求明确', '团队有相关经验'],
},
negative: {
thesis: '资源投入大,存在执行风险',
evidence: ['开发周期长', '需要额外人力', '竞品已有类似方案'],
},
analyst: {
summary: '综合正反方观点,建议在资源到位后启动,并设立阶段性验收点控制风险。',
},
}
// 更新想法的评估结果(实际应该调用 API
await store.updateIdea(currentIdea.value.id, 'ai_analysis', JSON.stringify(mockEval, null, 2))
}
async function onStatusChange(e: Event) {
if (!currentIdea.value) return
const newStatus = (e.target as HTMLSelectElement).value
await store.updateIdea(currentIdea.value.id, 'status', newStatus)
async function updateIdeaStatus() {
if (!currentIdea.value || !currentStatus.value) return
await store.updateIdea(currentIdea.value.id, 'status', currentStatus.value)
}
onMounted(async () => {
ensureLoaded() // 后台预热 Markdown 渲染器(模块单例,与 AiChat/TaskDetail 共享),不阻塞
await store.loadIdeas()
// 支持从 /ideas/:id 路由直接打开指定灵感
const id = route.params.id as string | undefined
if (id) {
const exists = store.ideas.some(i => i.id === id)
if (exists) {
selectedId.value = id
} else {
console.warn(`[Ideas] 路由指定的灵感 id=${id} 不在当前列表中`)
}
}
})
// 支持在同组件内切换 /ideas/:id如从灵感来源链接跳转
watch(() => route.params.id, (newId) => {
const id = newId as string | undefined
if (id) {
const exists = store.ideas.some(i => i.id === id)
if (exists) {
selectedId.value = id
} else {
console.warn(`[Ideas] 路由切换的灵感 id=${id} 不在当前列表中`)
}
} else {
// 回到 /ideas无 id时不清空保留用户选择
}
})
</script>
@@ -636,14 +656,25 @@ onMounted(async () => {
overflow: hidden;
}
.confidence-fill {
.debate-column.positive .confidence-bar::after {
content: '';
position: absolute;
left: 0;
top: 0;
height: 100%;
background: currentColor;
border-radius: var(--df-radius-xs);
transition: width 0.4s;
}
.debate-column.positive .confidence-fill { background: var(--df-success); }
.debate-column.negative .confidence-fill { background: var(--df-danger); }
.debate-column.negative .confidence-bar::after {
content: '';
position: absolute;
left: 0;
top: 0;
height: 100%;
background: currentColor;
border-radius: var(--df-radius-xs);
}
.confidence-text {
font-size: 11px;
@@ -761,23 +792,6 @@ onMounted(async () => {
background: var(--df-accent-hover);
}
.eval-error {
margin-top: 8px;
font-size: 12px;
color: var(--df-danger);
}
.eval-mode-tag {
font-size: 11px;
font-weight: 400;
padding: 1px 8px;
border-radius: var(--df-radius-xs);
background: rgba(255, 217, 61, 0.15);
color: var(--df-warning);
margin-left: 6px;
vertical-align: middle;
}
/* ===== 右侧详情 ===== */
.idea-detail-panel {
background: var(--df-bg-card);
@@ -811,63 +825,6 @@ onMounted(async () => {
margin-bottom: var(--df-gap-page);
}
/* ===== 灵感描述 Markdown 渲染(B-260615-25,样式同 TaskDetail B-24 .ai-md 收敛) ===== */
.detail-desc.ai-md { white-space: normal; color: var(--df-text-secondary); }
.detail-desc.ai-md :deep(p) { margin: 0 0 6px; }
.detail-desc.ai-md :deep(p:last-child) { margin-bottom: 0; }
.detail-desc.ai-md :deep(ul), .detail-desc.ai-md :deep(ol) { margin: 4px 0; padding-left: 20px; }
.detail-desc.ai-md :deep(li) { margin: 2px 0; line-height: 1.5; }
.detail-desc.ai-md :deep(code) {
font-family: var(--df-font-mono);
font-size: 12px;
padding: 1px 5px;
background: rgba(255,255,255,0.06);
border-radius: var(--df-radius-sm);
color: var(--df-accent);
}
.detail-desc.ai-md :deep(pre) {
margin: 8px 0;
padding: 10px 12px;
background: var(--df-bg);
border: 0.5px solid var(--df-border);
border-radius: var(--df-radius);
overflow-x: auto;
}
.detail-desc.ai-md :deep(pre code) {
padding: 0;
background: transparent;
border-radius: 0;
color: var(--df-text-secondary);
font-size: 12px;
line-height: 1.5;
}
.detail-desc.ai-md :deep(blockquote) {
margin: 6px 0;
padding: 4px 12px;
border-left: 2px solid var(--df-accent);
color: var(--df-text-secondary);
}
.detail-desc.ai-md :deep(h1), .detail-desc.ai-md :deep(h2), .detail-desc.ai-md :deep(h3) {
font-weight: 500;
color: var(--df-text);
margin: 8px 0 4px;
}
.detail-desc.ai-md :deep(h1) { font-size: 16px; }
.detail-desc.ai-md :deep(h2) { font-size: 14px; }
.detail-desc.ai-md :deep(h3) { font-size: 13px; }
.detail-desc.ai-md :deep(a) { color: var(--df-accent); text-decoration: none; }
.detail-desc.ai-md :deep(a:hover) { text-decoration: underline; }
.detail-desc.ai-md :deep(strong) { font-weight: 500; color: var(--df-text); }
.detail-desc.ai-md :deep(hr) { border: none; border-top: 0.5px solid var(--df-border); margin: 8px 0; }
.detail-desc.ai-md :deep(table) {
width: 100%; border-collapse: collapse; margin: 6px 0;
font-size: 12px; overflow-x: auto; display: block;
}
.detail-desc.ai-md :deep(th), .detail-desc.ai-md :deep(td) {
padding: 4px 8px; border: 0.5px solid var(--df-border); text-align: left;
}
.detail-desc.ai-md :deep(th) { font-weight: 500; background: var(--df-bg); }
.detail-section {
margin-bottom: var(--df-gap-page);
}

View File

@@ -240,9 +240,9 @@
<script setup lang="ts">
import { ref, computed, onMounted, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { useKnowledgeStore, KNOWLEDGE_KINDS, parseTags } from '../stores/knowledge'
import { useRendered } from '../composables/useMarkdown'
import type { KnowledgeDetailPayload, KnowledgeEventRecord } from '../api/types'
import { useKnowledgeStore, KNOWLEDGE_KINDS, parseTags } from '@/stores/knowledge'
import { useRendered } from '@/composables/useMarkdown'
import type { KnowledgeDetailPayload, KnowledgeEventRecord } from '@/api/types'
const { t } = useI18n()
const store = useKnowledgeStore()

View File

@@ -234,14 +234,14 @@ import { useRoute, useRouter } from 'vue-router'
import { useI18n } from 'vue-i18n'
import { Message } from '@arco-design/web-vue'
import { open } from '@tauri-apps/plugin-dialog'
import { useProjectStore } from '../stores/project'
import { projectApi } from '../api'
import { formatDate } from '../utils/time'
import { parseStack } from '../utils/project'
import { useProjectStore } from '@/stores/project'
import { projectApi } from '@/api'
import { formatDate } from '@/utils/time'
import { parseStack } from '@/utils/project'
import { projectStatusLabel, projectStageInfo, taskStatusLabel, taskStatusClass } from '../constants/project'
import ConfirmDialog from '../components/ConfirmDialog.vue'
import { useConfirm } from '../composables/useConfirm'
import { useRendered } from '../composables/useMarkdown'
import ConfirmDialog from '@/components/ConfirmDialog.vue'
import { useConfirm } from '@/composables/useConfirm'
import { useRendered } from '@/composables/useMarkdown'
const route = useRoute()
const router = useRouter()

View File

@@ -118,14 +118,14 @@ import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { useI18n } from 'vue-i18n'
import { open } from '@tauri-apps/plugin-dialog'
import { useProjectStore } from '../stores/project'
import { projectApi } from '../api'
import { formatDate } from '../utils/time'
import { parseStack } from '../utils/project'
import { useProjectStore } from '@/stores/project'
import { projectApi } from '@/api'
import { formatDate } from '@/utils/time'
import { parseStack } from '@/utils/project'
import { projectStatusLabel as statusLabel, projectBadgeClass as stageClass } from '../constants/project'
import ConfirmDialog from '../components/ConfirmDialog.vue'
import { useConfirm } from '../composables/useConfirm'
import type { ProjectRecord } from '../api/types'
import ConfirmDialog from '@/components/ConfirmDialog.vue'
import { useConfirm } from '@/composables/useConfirm'
import type { ProjectRecord } from '@/api/types'
const router = useRouter()
const store = useProjectStore()

View File

@@ -371,10 +371,10 @@
<script setup lang="ts">
import { reactive, ref, computed, watch, onMounted, onUnmounted } from 'vue'
import { useI18n } from 'vue-i18n'
import { aiApi, knowledgeApi } from '../api'
import { useAppSettingsStore } from '../stores/appSettings'
import { useConfirm } from '../composables/useConfirm'
import type { AiProviderConfig } from '../api/types'
import { aiApi, knowledgeApi } from '@/api'
import { useAppSettingsStore } from '@/stores/appSettings'
import { useConfirm } from '@/composables/useConfirm'
import type { AiProviderConfig } from '@/api/types'
import i18n from '@/i18n'
const { t } = useI18n()

View File

@@ -98,16 +98,16 @@
import { ref, computed, onMounted, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { useRoute } from 'vue-router'
import { taskApi, projectApi } from '../api'
import { formatDate } from '../utils/time'
import { useRendered } from '../composables/useMarkdown'
import { taskApi, projectApi } from '@/api'
import { formatDate } from '@/utils/time'
import { useRendered } from '@/composables/useMarkdown'
import {
taskStatusLabel,
taskStatusClass,
priorityLabel,
priorityClass,
} from '../constants/project'
import type { TaskRecord, ProjectRecord } from '../api/types'
import type { TaskRecord, ProjectRecord } from '@/api/types'
const { t } = useI18n()
const route = useRoute()

View File

@@ -110,10 +110,10 @@
import { ref, computed, onMounted, watch } from 'vue'
import { useRouter } from 'vue-router'
import { useI18n } from 'vue-i18n'
import { useProjectStore } from '../stores/project'
import { formatRelativeZh } from '../utils/time'
import { useProjectStore } from '@/stores/project'
import { formatRelativeZh } from '@/utils/time'
import { taskStatusLabel as statusLabel, taskStatusClass, priorityLabel, priorityClass } from '../constants/project'
import type { TaskRecord } from '../api/types'
import type { TaskRecord } from '@/api/types'
const router = useRouter()
const store = useProjectStore()