cd frontend/vue-demo
yarn install
# 或
npm install
yarn dev
# 或
npm run dev
yarn build
# 或
npm run build
vue-demo/
├── src/
│ ├── api/ # API 接口定义
│ │ └── index.js # 所有 API 方法
│ ├── assets/ # 静态资源
│ ├── components/ # 公共组件
│ │ └── TaskCenter/ # 任务中心组件
│ ├── router/ # 路由配置
│ ├── stores/ # Pinia 状态管理
│ ├── views/ # 页面组件
│ │ ├── Login.vue # 登录页
│ │ ├── Register.vue # 注册页
│ │ └── Editor.vue # 编辑器页
│ ├── App.vue # 根组件
│ └── main.js # 入口文件
├── vite.config.js # Vite 配置
├── package.json # 项目配置
└── API_GUIDE.md # API 使用指南
编辑 vite.config.js 中的 API_SERVER 变量:
// 本地开发
const API_SERVER = 'http://localhost:18520'
// 远程服务器
const API_SERVER = 'http://服务器IP:18520'
Vite 已配置代理,自动转发以下请求:
/api/* → 后端 API/auth/* → 认证服务详见 API_GUIDE.md
import { templateApi, documentApi } from '@/api'
// 获取模板列表
const templates = await templateApi.list()
// 上传文档
const result = await parseApi.upload(file)
import { useTaskCenterStore } from '@/stores/taskCenter'
const taskStore = useTaskCenterStore()
// 添加任务
taskStore.addTask({
id: 'task-1',
type: 'parse',
status: 'running',
progress: 50
})
// 更新任务
taskStore.updateTask('task-1', { progress: 100, status: 'completed' })
import { useTemplateStore } from '@/stores/template'
const templateStore = useTemplateStore()
// 加载模板
await templateStore.loadTemplates()
// 选择模板
templateStore.selectTemplate(templateId)
<template>
<TaskCenterFab />
<TaskCenterPanel />
</template>
<script setup>
import { TaskCenterFab, TaskCenterPanel } from '@/components/TaskCenter'
</script>
const routes = [
{ path: '/login', component: Login },
{ path: '/register', component: Register },
{ path: '/editor/:documentId?', component: Editor }
]
创建 .env.local 文件:
# API 服务器地址
VITE_API_SERVER=http://localhost:18520
# 其他配置
VITE_APP_TITLE=灵越智报
在代码中使用:
const apiServer = import.meta.env.VITE_API_SERVER
打开浏览器开发者工具 → Network 标签
安装 Vue DevTools 浏览器扩展,查看组件状态和 Pinia store
在 src/api/index.js 中已配置响应拦截器,会自动打印错误:
api.interceptors.response.use(
response => { /* ... */ },
error => {
console.error('API Error:', error)
return Promise.reject(error)
}
)
已通过 Vite 代理解决,确保 vite.config.js 中的代理配置正确。
检查:
/api/v1/graph/*)使用 refreshToken 刷新:
const newToken = await authApi.refreshToken(refreshToken)
localStorage.setItem('accessToken', newToken)
curl http://localhost:18520/actuator/health
预期响应:
{"status":"UP"}
# 获取模板列表
curl http://localhost:18520/api/v1/templates
# 获取图谱模板列表
curl http://localhost:18520/api/v1/graph/templates
yarn build
生成的文件在 dist/ 目录
server {
listen 80;
server_name your-domain.com;
root /path/to/dist;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
location /api {
proxy_pass http://localhost:18520;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location /auth {
proxy_pass http://localhost:18520;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}