Files
DevFlow/docs/06-前端开发/View改造指南-2026-06-12.md
绝尘 19d64fc421 修复: DOC-14+§11 View 指南归档+对抗评估未实施横幅
View 改造指南归档(横幅指 DEVFLOW-3.Store对接为真相源 + 列过时点:Phase1 四问题已解决/页面命名 ProjectsView·WorkflowView 与实际不符);对抗评估文档加未实施横幅(纯启发式,三路 LLM+AI Prompt+Phase2+idea_evaluations 表为设计稿,grep idea_evaluations 零命中/migrations 无此表)。批5
2026-06-15 05:45:04 +08:00

104 lines
3.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# View 改造指南 — 硬编码到 Store 对接
> 创建: 2026-06-10 | 状态: **已归档2026-06-15**
> ⚠️ **本文档已归档,内容过时,请勿据本文档改造**。Store → IPC 对接的全部内容已收敛到真相源 [`DEVFLOW-3.Store对接实施-2026-06-12.md`](../04-功能迭代/DEVFLOW-3.Store对接实施-2026-06-12.md)。本文档过时点(详见 `docs/05-代码审查/文档全量核对报告-2026-06-15.md` §24
> 1. 「当前问题」四项(数据硬编码 / Store 未接入 / 事件处理空函数 / Arco 未使用Phase1 已**全部解决**,前端已通过 Store → IPC 对接真实数据。
> 2. 「涉及页面」表格的页面命名(`ProjectsView`/`TasksView`/`WorkflowView` 等)与实际不符:实际页面**无 `View` 后缀**,且**不存在 `WorkflowView`**(工作流引擎非独立页面)。
>
> 本文件保留仅为历史参考,后续以前述 `DEVFLOW-3` 文档为准。
---
## 概述
当前所有 Vue 页面使用硬编码数据 (`ref([...])`)Pinia Store 和 View 完全独立。本文档指导如何将 View 改造为通过 Store → IPC 获取真实数据。
## 当前问题
1. **数据硬编码** — 每个 View 用 `ref([...])` 定义假数据
2. **Store 未接入** — Pinia Store 有 state/getter 但无 action
3. **事件处理空函数** — 按钮点击绑定 `() => {}`
4. **Arco Design 未使用** — 仅 CSS 变量覆盖,未引入组件
## 改造步骤
### Step 1: Store 添加 Actions
```typescript
// stores/projectStore.ts
import { invoke } from '@tauri-apps/api/core'
export const useProjectStore = defineStore('project', () => {
const projects = ref<Project[]>([])
// 新增 action
async function fetchProjects() {
projects.value = await invoke<Project[]>('get_projects')
}
async function createProject(input: CreateProjectInput) {
const project = await invoke<Project>('create_project', { input })
projects.value.push(project)
}
return { projects, fetchProjects, createProject }
})
```
### Step 2: View 接入 Store
```typescript
// views/ProjectsView.vue — 改造前
const projects = ref([
{ id: '1', name: '项目A', ... }, // 硬编码
])
// views/ProjectsView.vue — 改造后
const store = useProjectStore()
const { projects } = storeToRefs(store)
onMounted(() => {
store.fetchProjects()
})
```
### Step 3: 事件绑定真实操作
```typescript
// 改造前
const handleCreate = () => {}
// 改造后
const handleCreate = async () => {
await store.createProject(form)
modalVisible.value = false
}
```
### Step 4: 加载与错误状态
```vue
<template>
<a-spin :loading="store.loading">
<!-- 内容 -->
</a-spin>
</template>
```
## 涉及页面
| 页面 | Store | 改造优先级 |
|------|-------|-----------|
| ProjectsView | projectStore | P0 |
| TasksView | taskStore | P0 |
| WorkflowView | workflowStore | P0 |
| IdeasView | ideaStore | P1 |
| DashboardView | 多个 Store | P2 |
## 相关文档
- [Tauri IPC 模式](../01-技术文档/Tauri-IPC模式-2026-06-12.md)
- [前后端类型对齐](../02-架构设计/前后端类型对齐-2026-06-12.md)
- [DEVFLOW-3 Store 对接实施](../04-功能迭代/DEVFLOW-3.Store对接实施-2026-06-12.md)