feat: 初始化 OnceLove GraphRAG 项目基础架构

- 添加完整的项目结构,包括前端(Vue3 + Vite)、后端(Fastify)和基础设施配置
- 实现核心 GraphRAG 服务,集成 Neo4j 图数据库和 Qdrant 向量数据库
- 添加用户认证系统和管理员登录界面
- 提供 Docker 容器化部署方案和开发环境配置
- 包含项目文档、API 文档(Swagger)和测试脚本
This commit is contained in:
KOSHM-Pig
2026-03-23 00:00:13 +08:00
commit ec21df7aa6
50 changed files with 7459 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

View File

@@ -0,0 +1,18 @@
# Build stage
FROM node:22-alpine AS build-stage
WORKDIR /app
COPY package*.json ./
RUN npm config set registry https://registry.npmmirror.com && npm install --no-audit --no-fund
COPY . .
ARG VITE_API_BASE_URL
ENV VITE_API_BASE_URL=$VITE_API_BASE_URL
RUN npm run build
# Production stage
FROM nginx:alpine
COPY --from=build-stage /app/dist /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

View File

@@ -0,0 +1,5 @@
# Vue 3 + Vite
This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
Learn more about IDE Support for Vue in the [Vue Docs Scaling up Guide](https://vuejs.org/guide/scaling-up/tooling.html#ide-support).

View File

@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>frontend</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>

View File

@@ -0,0 +1,15 @@
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,21 @@
{
"name": "frontend",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"axios": "^1.13.6",
"d3": "^7.9.0",
"vue": "^3.5.30",
"vue-router": "^5.0.4"
},
"devDependencies": {
"@vitejs/plugin-vue": "^6.0.5",
"vite": "^8.0.1"
}
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 9.3 KiB

View File

@@ -0,0 +1,24 @@
<svg xmlns="http://www.w3.org/2000/svg">
<symbol id="bluesky-icon" viewBox="0 0 16 17">
<g clip-path="url(#bluesky-clip)"><path fill="#08060d" d="M7.75 7.735c-.693-1.348-2.58-3.86-4.334-5.097-1.68-1.187-2.32-.981-2.74-.79C.188 2.065.1 2.812.1 3.251s.241 3.602.398 4.13c.52 1.744 2.367 2.333 4.07 2.145-2.495.37-4.71 1.278-1.805 4.512 3.196 3.309 4.38-.71 4.987-2.746.608 2.036 1.307 5.91 4.93 2.746 2.72-2.746.747-4.143-1.747-4.512 1.702.189 3.55-.4 4.07-2.145.156-.528.397-3.691.397-4.13s-.088-1.186-.575-1.406c-.42-.19-1.06-.395-2.741.79-1.755 1.24-3.64 3.752-4.334 5.099"/></g>
<defs><clipPath id="bluesky-clip"><path fill="#fff" d="M.1.85h15.3v15.3H.1z"/></clipPath></defs>
</symbol>
<symbol id="discord-icon" viewBox="0 0 20 19">
<path fill="#08060d" d="M16.224 3.768a14.5 14.5 0 0 0-3.67-1.153c-.158.286-.343.67-.47.976a13.5 13.5 0 0 0-4.067 0c-.128-.306-.317-.69-.476-.976A14.4 14.4 0 0 0 3.868 3.77C1.546 7.28.916 10.703 1.231 14.077a14.7 14.7 0 0 0 4.5 2.306q.545-.748.965-1.587a9.5 9.5 0 0 1-1.518-.74q.191-.14.372-.293c2.927 1.369 6.107 1.369 8.999 0q.183.152.372.294-.723.437-1.52.74.418.838.963 1.588a14.6 14.6 0 0 0 4.504-2.308c.37-3.911-.63-7.302-2.644-10.309m-9.13 8.234c-.878 0-1.599-.82-1.599-1.82 0-.998.705-1.82 1.6-1.82.894 0 1.614.82 1.599 1.82.001 1-.705 1.82-1.6 1.82m5.91 0c-.878 0-1.599-.82-1.599-1.82 0-.998.705-1.82 1.6-1.82.893 0 1.614.82 1.599 1.82 0 1-.706 1.82-1.6 1.82"/>
</symbol>
<symbol id="documentation-icon" viewBox="0 0 21 20">
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="m15.5 13.333 1.533 1.322c.645.555.967.833.967 1.178s-.322.623-.967 1.179L15.5 18.333m-3.333-5-1.534 1.322c-.644.555-.966.833-.966 1.178s.322.623.966 1.179l1.534 1.321"/>
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M17.167 10.836v-4.32c0-1.41 0-2.117-.224-2.68-.359-.906-1.118-1.621-2.08-1.96-.599-.21-1.349-.21-2.848-.21-2.623 0-3.935 0-4.983.369-1.684.591-3.013 1.842-3.641 3.428C3 6.449 3 7.684 3 10.154v2.122c0 2.558 0 3.838.706 4.726q.306.383.713.671c.76.536 1.79.64 3.581.66"/>
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M3 10a2.78 2.78 0 0 1 2.778-2.778c.555 0 1.209.097 1.748-.047.48-.129.854-.503.982-.982.145-.54.048-1.194.048-1.749a2.78 2.78 0 0 1 2.777-2.777"/>
</symbol>
<symbol id="github-icon" viewBox="0 0 19 19">
<path fill="#08060d" fill-rule="evenodd" d="M9.356 1.85C5.05 1.85 1.57 5.356 1.57 9.694a7.84 7.84 0 0 0 5.324 7.44c.387.079.528-.168.528-.376 0-.182-.013-.805-.013-1.454-2.165.467-2.616-.935-2.616-.935-.349-.91-.864-1.143-.864-1.143-.71-.48.051-.48.051-.48.787.051 1.2.805 1.2.805.695 1.194 1.817.857 2.268.649.064-.507.27-.857.49-1.052-1.728-.182-3.545-.857-3.545-3.87 0-.857.31-1.558.8-2.104-.078-.195-.349-1 .077-2.078 0 0 .657-.208 2.14.805a7.5 7.5 0 0 1 1.946-.26c.657 0 1.328.092 1.946.26 1.483-1.013 2.14-.805 2.14-.805.426 1.078.155 1.883.078 2.078.502.546.799 1.247.799 2.104 0 3.013-1.818 3.675-3.558 3.87.284.247.528.714.528 1.454 0 1.052-.012 1.896-.012 2.156 0 .208.142.455.528.377a7.84 7.84 0 0 0 5.324-7.441c.013-4.338-3.48-7.844-7.773-7.844" clip-rule="evenodd"/>
</symbol>
<symbol id="social-icon" viewBox="0 0 20 20">
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M12.5 6.667a4.167 4.167 0 1 0-8.334 0 4.167 4.167 0 0 0 8.334 0"/>
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M2.5 16.667a5.833 5.833 0 0 1 8.75-5.053m3.837.474.513 1.035c.07.144.257.282.414.309l.93.155c.596.1.736.536.307.965l-.723.73a.64.64 0 0 0-.152.531l.207.903c.164.715-.213.991-.84.618l-.872-.52a.63.63 0 0 0-.577 0l-.872.52c-.624.373-1.003.094-.84-.618l.207-.903a.64.64 0 0 0-.152-.532l-.723-.729c-.426-.43-.289-.864.306-.964l.93-.156a.64.64 0 0 0 .412-.31l.513-1.034c.28-.562.735-.562 1.012 0"/>
</symbol>
<symbol id="x-icon" viewBox="0 0 19 19">
<path fill="#08060d" fill-rule="evenodd" d="M1.893 1.98c.052.072 1.245 1.769 2.653 3.77l2.892 4.114c.183.261.333.48.333.486s-.068.089-.152.183l-.522.593-.765.867-3.597 4.087c-.375.426-.734.834-.798.905a1 1 0 0 0-.118.148c0 .01.236.017.664.017h.663l.729-.83c.4-.457.796-.906.879-.999a692 692 0 0 0 1.794-2.038c.034-.037.301-.34.594-.675l.551-.624.345-.392a7 7 0 0 1 .34-.374c.006 0 .93 1.306 2.052 2.903l2.084 2.965.045.063h2.275c1.87 0 2.273-.003 2.266-.021-.008-.02-1.098-1.572-3.894-5.547-2.013-2.862-2.28-3.246-2.273-3.266.008-.019.282-.332 2.085-2.38l2-2.274 1.567-1.782c.022-.028-.016-.03-.65-.03h-.674l-.3.342a871 871 0 0 1-1.782 2.025c-.067.075-.405.458-.75.852a100 100 0 0 1-.803.91c-.148.172-.299.344-.99 1.127-.304.343-.32.358-.345.327-.015-.019-.904-1.282-1.976-2.808L6.365 1.85H1.8zm1.782.91 8.078 11.294c.772 1.08 1.413 1.973 1.425 1.984.016.017.241.02 1.05.017l1.03-.004-2.694-3.766L7.796 5.75 5.722 2.852l-1.039-.004-1.039-.004z" clip-rule="evenodd"/>
</symbol>
</svg>

After

Width:  |  Height:  |  Size: 4.9 KiB

View File

@@ -0,0 +1,43 @@
<template>
<router-view />
</template>
<script setup>
</script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
#app {
font-family: 'JetBrains Mono', 'Space Grotesk', 'Noto Sans SC', monospace;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
color: #000000;
background-color: #ffffff;
}
::-webkit-scrollbar {
width: 8px;
height: 8px;
}
::-webkit-scrollbar-track {
background: #f1f1f1;
}
::-webkit-scrollbar-thumb {
background: #000000;
}
::-webkit-scrollbar-thumb:hover {
background: #333333;
}
button {
font-family: inherit;
}
</style>

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 8.5 KiB

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="37.07" height="36" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 198"><path fill="#41B883" d="M204.8 0H256L128 220.8L0 0h97.92L128 51.2L157.44 0h47.36Z"></path><path fill="#41B883" d="m0 0l128 220.8L256 0h-51.2L128 132.48L50.56 0H0Z"></path><path fill="#35495E" d="M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z"></path></svg>

After

Width:  |  Height:  |  Size: 496 B

View File

@@ -0,0 +1,93 @@
<script setup>
import { ref } from 'vue'
import viteLogo from '../assets/vite.svg'
import heroImg from '../assets/hero.png'
import vueLogo from '../assets/vue.svg'
const count = ref(0)
</script>
<template>
<section id="center">
<div class="hero">
<img :src="heroImg" class="base" width="170" height="179" alt="" />
<img :src="vueLogo" class="framework" alt="Vue logo" />
<img :src="viteLogo" class="vite" alt="Vite logo" />
</div>
<div>
<h1>Get started</h1>
<p>Edit <code>src/App.vue</code> and save to test <code>HMR</code></p>
</div>
<button class="counter" @click="count++">Count is {{ count }}</button>
</section>
<div class="ticks"></div>
<section id="next-steps">
<div id="docs">
<svg class="icon" role="presentation" aria-hidden="true">
<use href="/icons.svg#documentation-icon"></use>
</svg>
<h2>Documentation</h2>
<p>Your questions, answered</p>
<ul>
<li>
<a href="https://vite.dev/" target="_blank">
<img class="logo" :src="viteLogo" alt="" />
Explore Vite
</a>
</li>
<li>
<a href="https://vuejs.org/" target="_blank">
<img class="button-icon" :src="vueLogo" alt="" />
Learn more
</a>
</li>
</ul>
</div>
<div id="social">
<svg class="icon" role="presentation" aria-hidden="true">
<use href="/icons.svg#social-icon"></use>
</svg>
<h2>Connect with us</h2>
<p>Join the Vite community</p>
<ul>
<li>
<a href="https://github.com/vitejs/vite" target="_blank">
<svg class="button-icon" role="presentation" aria-hidden="true">
<use href="/icons.svg#github-icon"></use>
</svg>
GitHub
</a>
</li>
<li>
<a href="https://chat.vite.dev/" target="_blank">
<svg class="button-icon" role="presentation" aria-hidden="true">
<use href="/icons.svg#discord-icon"></use>
</svg>
Discord
</a>
</li>
<li>
<a href="https://x.com/vite_js" target="_blank">
<svg class="button-icon" role="presentation" aria-hidden="true">
<use href="/icons.svg#x-icon"></use>
</svg>
X.com
</a>
</li>
<li>
<a href="https://bsky.app/profile/vite.dev" target="_blank">
<svg class="button-icon" role="presentation" aria-hidden="true">
<use href="/icons.svg#bluesky-icon"></use>
</svg>
Bluesky
</a>
</li>
</ul>
</div>
</section>
<div class="ticks"></div>
<section id="spacer"></section>
</template>

View File

@@ -0,0 +1,9 @@
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
const app = createApp(App)
app.use(router)
app.mount('#app')

View File

@@ -0,0 +1,35 @@
import { createRouter, createWebHistory } from 'vue-router'
const routes = [
{
path: '/login',
name: 'Login',
component: () => import('../views/Login.vue')
},
{
path: '/',
name: 'Dashboard',
component: () => import('../views/Dashboard.vue'),
meta: { requiresAuth: true }
}
]
const router = createRouter({
history: createWebHistory(),
routes
})
router.beforeEach((to, from, next) => {
if (to.meta.requiresAuth) {
const authStatus = localStorage.getItem('auth_token')
if (authStatus) {
next()
} else {
next('/login')
}
} else {
next()
}
})
export default router

View File

@@ -0,0 +1,296 @@
:root {
--text: #6b6375;
--text-h: #08060d;
--bg: #fff;
--border: #e5e4e7;
--code-bg: #f4f3ec;
--accent: #aa3bff;
--accent-bg: rgba(170, 59, 255, 0.1);
--accent-border: rgba(170, 59, 255, 0.5);
--social-bg: rgba(244, 243, 236, 0.5);
--shadow:
rgba(0, 0, 0, 0.1) 0 10px 15px -3px, rgba(0, 0, 0, 0.05) 0 4px 6px -2px;
--sans: system-ui, 'Segoe UI', Roboto, sans-serif;
--heading: system-ui, 'Segoe UI', Roboto, sans-serif;
--mono: ui-monospace, Consolas, monospace;
font: 18px/145% var(--sans);
letter-spacing: 0.18px;
color-scheme: light dark;
color: var(--text);
background: var(--bg);
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
@media (max-width: 1024px) {
font-size: 16px;
}
}
@media (prefers-color-scheme: dark) {
:root {
--text: #9ca3af;
--text-h: #f3f4f6;
--bg: #16171d;
--border: #2e303a;
--code-bg: #1f2028;
--accent: #c084fc;
--accent-bg: rgba(192, 132, 252, 0.15);
--accent-border: rgba(192, 132, 252, 0.5);
--social-bg: rgba(47, 48, 58, 0.5);
--shadow:
rgba(0, 0, 0, 0.4) 0 10px 15px -3px, rgba(0, 0, 0, 0.25) 0 4px 6px -2px;
}
#social .button-icon {
filter: invert(1) brightness(2);
}
}
body {
margin: 0;
}
h1,
h2 {
font-family: var(--heading);
font-weight: 500;
color: var(--text-h);
}
h1 {
font-size: 56px;
letter-spacing: -1.68px;
margin: 32px 0;
@media (max-width: 1024px) {
font-size: 36px;
margin: 20px 0;
}
}
h2 {
font-size: 24px;
line-height: 118%;
letter-spacing: -0.24px;
margin: 0 0 8px;
@media (max-width: 1024px) {
font-size: 20px;
}
}
p {
margin: 0;
}
code,
.counter {
font-family: var(--mono);
display: inline-flex;
border-radius: 4px;
color: var(--text-h);
}
code {
font-size: 15px;
line-height: 135%;
padding: 4px 8px;
background: var(--code-bg);
}
.counter {
font-size: 16px;
padding: 5px 10px;
border-radius: 5px;
color: var(--accent);
background: var(--accent-bg);
border: 2px solid transparent;
transition: border-color 0.3s;
margin-bottom: 24px;
&:hover {
border-color: var(--accent-border);
}
&:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
}
.hero {
position: relative;
.base,
.framework,
.vite {
inset-inline: 0;
margin: 0 auto;
}
.base {
width: 170px;
position: relative;
z-index: 0;
}
.framework,
.vite {
position: absolute;
}
.framework {
z-index: 1;
top: 34px;
height: 28px;
transform: perspective(2000px) rotateZ(300deg) rotateX(44deg) rotateY(39deg)
scale(1.4);
}
.vite {
z-index: 0;
top: 107px;
height: 26px;
width: auto;
transform: perspective(2000px) rotateZ(300deg) rotateX(40deg) rotateY(39deg)
scale(0.8);
}
}
#app {
width: 1126px;
max-width: 100%;
margin: 0 auto;
text-align: center;
border-inline: 1px solid var(--border);
min-height: 100svh;
display: flex;
flex-direction: column;
box-sizing: border-box;
}
#center {
display: flex;
flex-direction: column;
gap: 25px;
place-content: center;
place-items: center;
flex-grow: 1;
@media (max-width: 1024px) {
padding: 32px 20px 24px;
gap: 18px;
}
}
#next-steps {
display: flex;
border-top: 1px solid var(--border);
text-align: left;
& > div {
flex: 1 1 0;
padding: 32px;
@media (max-width: 1024px) {
padding: 24px 20px;
}
}
.icon {
margin-bottom: 16px;
width: 22px;
height: 22px;
}
@media (max-width: 1024px) {
flex-direction: column;
text-align: center;
}
}
#docs {
border-right: 1px solid var(--border);
@media (max-width: 1024px) {
border-right: none;
border-bottom: 1px solid var(--border);
}
}
#next-steps ul {
list-style: none;
padding: 0;
display: flex;
gap: 8px;
margin: 32px 0 0;
.logo {
height: 18px;
}
a {
color: var(--text-h);
font-size: 16px;
border-radius: 6px;
background: var(--social-bg);
display: flex;
padding: 6px 12px;
align-items: center;
gap: 8px;
text-decoration: none;
transition: box-shadow 0.3s;
&:hover {
box-shadow: var(--shadow);
}
.button-icon {
height: 18px;
width: 18px;
}
}
@media (max-width: 1024px) {
margin-top: 20px;
flex-wrap: wrap;
justify-content: center;
li {
flex: 1 1 calc(50% - 8px);
}
a {
width: 100%;
justify-content: center;
box-sizing: border-box;
}
}
}
#spacer {
height: 88px;
border-top: 1px solid var(--border);
@media (max-width: 1024px) {
height: 48px;
}
}
.ticks {
position: relative;
width: 100%;
&::before,
&::after {
content: '';
position: absolute;
top: -4.5px;
border: 5px solid transparent;
}
&::before {
left: 0;
border-left-color: var(--border);
}
&::after {
right: 0;
border-right-color: var(--border);
}
}

View File

@@ -0,0 +1,768 @@
<template>
<div class="dashboard">
<aside class="sidebar">
<div class="sidebar-header">
<div class="logo-mark">
<svg width="32" height="32" viewBox="0 0 48 48" fill="none">
<circle cx="24" cy="24" r="20" stroke="#6366f1" stroke-width="2.5"/>
<circle cx="24" cy="24" r="6" fill="#6366f1"/>
<line x1="24" y1="4" x2="24" y2="18" stroke="#6366f1" stroke-width="2.5"/>
<line x1="24" y1="30" x2="24" y2="44" stroke="#6366f1" stroke-width="2.5"/>
<line x1="4" y1="24" x2="18" y2="24" stroke="#6366f1" stroke-width="2.5"/>
<line x1="30" y1="24" x2="44" y2="24" stroke="#6366f1" stroke-width="2.5"/>
</svg>
</div>
<div class="logo-text">
<span class="logo-name">GraphRAG</span>
<span class="logo-sub">管理平台</span>
</div>
</div>
<nav class="sidebar-nav">
<button
v-for="item in navItems"
:key="item.id"
class="nav-btn"
:class="{ active: activeTab === item.id }"
@click="activeTab = item.id"
>
<span class="nav-icon" v-html="item.icon"></span>
<span>{{ item.label }}</span>
</button>
</nav>
<div class="sidebar-footer">
<div class="user-card">
<div class="user-avatar">A</div>
<div class="user-info">
<span class="user-role">管理员</span>
<span class="user-name">Admin</span>
</div>
</div>
<button class="logout-btn" @click="handleLogout">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/>
<polyline points="16 17 21 12 16 7"/>
<line x1="21" y1="12" x2="9" y2="12"/>
</svg>
退出登录
</button>
</div>
</aside>
<main class="main-panel">
<header class="top-header">
<div class="header-left">
<h1 class="page-title">{{ currentNav.label }}</h1>
<p class="page-desc">{{ currentNav.desc }}</p>
</div>
<div class="header-actions">
<button class="btn-ghost" @click="refreshData">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="23 4 23 10 17 10"/>
<path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"/>
</svg>
刷新
</button>
</div>
</header>
<div class="content-area">
<div v-if="activeTab === 'graph'" class="graph-view">
<div class="graph-toolbar">
<div class="toolbar-left">
<span class="data-badge">实时数据</span>
<span class="node-count">{{ graphStats.nodes }} 节点 · {{ graphStats.edges }} 关系</span>
</div>
<div class="toolbar-right">
<button class="btn-outline" @click="zoomIn">+ 放大</button>
<button class="btn-outline" @click="zoomOut">- 缩小</button>
<button class="btn-primary" @click="fitView">适应画布</button>
</div>
</div>
<div class="graph-canvas" ref="graphCanvas">
<div v-if="graphLoading" class="graph-loading">
<div class="spinner"></div>
<p>加载图谱数据...</p>
</div>
<svg v-show="!graphLoading" ref="svgEl" class="graph-svg"></svg>
</div>
</div>
<div v-if="activeTab === 'ingest'" class="ingest-view">
<div class="panel-grid">
<div class="panel-card">
<div class="panel-header">
<h3>文本导入</h3>
<span class="panel-tag">Ingest</span>
</div>
<div class="panel-body">
<textarea
v-model="ingestText"
class="text-area"
placeholder="在此输入文本内容,系统将自动完成分句、向量化并写入 Neo4j 与 Qdrant..."
rows="8"
></textarea>
<div class="panel-actions">
<button class="btn-primary" @click="handleIngest" :disabled="!ingestText || ingestLoading">
{{ ingestLoading ? '导入中...' : '开始导入' }}
</button>
</div>
</div>
</div>
<div class="panel-card">
<div class="panel-header">
<h3>导入记录</h3>
<span class="panel-tag info">Recent</span>
</div>
<div class="panel-body">
<div class="log-list">
<div v-for="(log, i) in ingestLogs" :key="i" class="log-item" :class="log.type">
<span class="log-time">{{ log.time }}</span>
<span class="log-msg">{{ log.msg }}</span>
</div>
<p v-if="!ingestLogs.length" class="log-empty">暂无导入记录</p>
</div>
</div>
</div>
</div>
</div>
<div v-if="activeTab === 'query'" class="query-view">
<div class="panel-grid">
<div class="panel-card wide">
<div class="panel-header">
<h3>时序检索</h3>
<span class="panel-tag">Query</span>
</div>
<div class="panel-body">
<div class="query-input-row">
<input
v-model="queryText"
class="query-input"
placeholder="输入查询内容,例如:张三和张四的关系是什么?"
@keyup.enter="handleQuery"
/>
<button class="btn-primary" @click="handleQuery" :disabled="!queryText || queryLoading">
{{ queryLoading ? '检索中...' : '检索' }}
</button>
</div>
<div v-if="queryResult" class="query-result">
<div class="result-section">
<h4>检索结果</h4>
<p class="result-text">{{ queryResult.answer }}</p>
</div>
<div v-if="queryResult.chunks?.length" class="result-section">
<h4>相关片段</h4>
<div class="chunk-list">
<div v-for="(chunk, i) in queryResult.chunks" :key="i" class="chunk-item">
<p>{{ chunk.text || chunk.content }}</p>
<span v-if="chunk.score" class="chunk-score">相关度: {{ (chunk.score * 100).toFixed(1) }}%</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div v-if="activeTab === 'api'" class="api-view">
<div class="panel-grid">
<div class="panel-card wide">
<div class="panel-header">
<h3>接口调试</h3>
<span class="panel-tag">API Tester</span>
</div>
<div class="panel-body">
<div class="api-row">
<select v-model="apiMethod" class="method-select">
<option value="GET">GET</option>
<option value="POST">POST</option>
<option value="PUT">PUT</option>
<option value="DELETE">DELETE</option>
</select>
<input v-model="apiUrl" class="api-url-input" placeholder="/graph/stats" @keyup.enter="sendApiRequest" />
<button class="btn-primary" @click="sendApiRequest" :disabled="apiLoading">
{{ apiLoading ? '发送中...' : '发送' }}
</button>
</div>
<div class="api-endpoints">
<span class="endpoint-label">快速调用</span>
<button v-for="ep in quickEndpoints" :key="ep.path" class="endpoint-chip" @click="fillApi(ep)">
<span class="chip-method" :class="ep.method.toLowerCase()">{{ ep.method }}</span>
{{ ep.path }}
</button>
</div>
<div v-if="apiMethod === 'POST' || apiMethod === 'PUT'" class="api-body-section">
<h4 class="body-label">请求体 (JSON)</h4>
<textarea v-model="apiBody" class="text-area code-area" placeholder='{"key": "value"}' rows="8"></textarea>
</div>
<div class="api-response-section">
<div class="response-header">
<h4>响应结果</h4>
<span v-if="apiStatus" class="status-badge" :class="apiStatus >= 200 && apiStatus < 300 ? 'success' : 'error'">
{{ apiStatus }}
</span>
</div>
<pre class="response-pre">{{ apiResponse || '等待发送请求...' }}</pre>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
</div>
</template>
<script setup>
import { ref, computed, onMounted, onUnmounted } from 'vue'
import { useRouter } from 'vue-router'
import * as d3 from 'd3'
const router = useRouter()
const activeTab = ref('graph')
const graphLoading = ref(false)
const ingestLoading = ref(false)
const queryLoading = ref(false)
const ingestText = ref('')
const queryText = ref('')
const queryResult = ref(null)
const ingestLogs = ref([])
const graphStats = ref({ nodes: 0, edges: 0 })
const graphCanvas = ref(null)
const svgEl = ref(null)
const apiMethod = ref('GET')
const apiUrl = ref('')
const apiBody = ref('')
const apiResponse = ref('')
const apiStatus = ref(null)
const apiLoading = ref(false)
const quickEndpoints = [
{ method: 'GET', path: '/health', body: '' },
{ method: 'GET', path: '/ready', body: '' },
{ method: 'POST', path: '/bootstrap', body: '{}' },
{ method: 'GET', path: '/graph/stats', body: '' },
{ method: 'POST', path: '/ingest', body: '{"persons":[{"id":"p1","name":"张三"}],"events":[{"id":"e1","summary":"测试事件","occurred_at":"2024-01-01T00:00:00Z","participants":["p1"],"topics":["t1"]}],"chunks":[{"id":"c1","text":"这是测试内容","payload":{"event_id":"e1"}}]}' },
{ method: 'POST', path: '/query/timeline', body: '{"a_id":"p1","b_id":"p2"}' },
{ method: 'POST', path: '/query/graphrag', body: '{"query_text":"张三的事件","top_k":5}' },
{ method: 'POST', path: '/auth/verify', body: '{"password":"your-password"}' }
]
const fillApi = (ep) => {
apiMethod.value = ep.method
apiUrl.value = ep.path
apiBody.value = ep.body
}
const sendApiRequest = async () => {
if (!apiUrl.value) return
apiLoading.value = true
apiResponse.value = ''
apiStatus.value = null
try {
let targetUrl = apiUrl.value
if (!targetUrl.startsWith('http://') && !targetUrl.startsWith('https://')) {
const apiBase = import.meta.env.VITE_API_BASE_URL || 'http://localhost:3000'
targetUrl = `${apiBase}${apiUrl.value}`
}
const opts = { method: apiMethod.value, headers: { 'Content-Type': 'application/json' } }
if ((apiMethod.value === 'POST' || apiMethod.value === 'PUT') && apiBody.value) {
opts.body = apiBody.value
}
const res = await fetch(targetUrl, opts)
apiStatus.value = res.status
const text = await res.text()
try { apiResponse.value = JSON.stringify(JSON.parse(text), null, 2) }
catch { apiResponse.value = text }
} catch (err) {
apiStatus.value = 0
apiResponse.value = '请求失败: ' + err.message
} finally {
apiLoading.value = false
}
}
const navItems = [
{ id: 'graph', label: '知识图谱', desc: '可视化关系网络与时序事件', icon: '◉' },
{ id: 'ingest', label: '数据导入', desc: '导入文本并自动完成向量化', icon: '↓' },
{ id: 'query', label: '时序检索', desc: '基于 GraphRAG 的智能问答', icon: '⌕' },
{ id: 'api', label: 'API 测试', desc: '在线调试后端接口', icon: '⚡' }
]
const currentNav = computed(() => navItems.find(n => n.id === activeTab.value) || navItems[0])
const handleLogout = () => {
localStorage.removeItem('auth_token')
router.push('/login')
}
const refreshData = () => {
if (activeTab.value === 'graph') renderGraph()
}
const zoomIn = () => {
if (!svgEl.value) return
d3.select(svgEl.value).transition().call(d3.zoom().scaleBy, 1.3)
}
const zoomOut = () => {
if (!svgEl.value) return
d3.select(svgEl.value).transition().call(d3.zoom().scaleBy, 0.7)
}
const fitView = () => {
if (!svgEl.value) return
d3.select(svgEl.value).transition().call(d3.zoom().transform, d3.zoomIdentity)
}
const fetchGraphData = async () => {
const apiBase = import.meta.env.VITE_API_BASE_URL || 'http://localhost:3000'
try {
const res = await fetch(`${apiBase}/graph/stats`, { method: 'GET' })
if (res.ok) return await res.json()
} catch {}
return null
}
const renderGraph = async () => {
if (!graphCanvas.value || !svgEl.value) return
graphLoading.value = true
const width = graphCanvas.value.clientWidth
const height = graphCanvas.value.clientHeight
d3.select(svgEl.value).selectAll('*').remove()
const svg = d3.select(svgEl.value)
.attr('width', width)
.attr('height', height)
const data = await fetchGraphData()
const nodes = Array.isArray(data?.nodes) ? data.nodes : []
const links = Array.isArray(data?.links) ? data.links : []
graphStats.value = { nodes: nodes.length, edges: links.length }
if (!nodes.length) {
svg.append('text')
.attr('x', width / 2)
.attr('y', height / 2)
.attr('text-anchor', 'middle')
.attr('font-size', 14)
.attr('fill', '#9ca3af')
.text('暂无节点数据')
graphLoading.value = false
return
}
const colorMap = { person: '#6366f1', event: '#10b981', topic: '#f59e0b' }
const color = d => colorMap[d.type] || '#6366f1'
const g = svg.append('g')
svg.call(d3.zoom().scaleExtent([0.2, 3]).on('zoom', (event) => {
g.attr('transform', event.transform)
}))
const simulation = d3.forceSimulation(nodes)
.force('link', d3.forceLink(links).id(d => d.id).distance(140))
.force('charge', d3.forceManyBody().strength(-350))
.force('center', d3.forceCenter(width / 2, height / 2))
.force('collision', d3.forceCollide().radius(40))
const link = g.append('g')
.selectAll('line')
.data(links)
.join('line')
.attr('stroke', '#e5e7eb')
.attr('stroke-width', 1.5)
const nodeGroup = g.append('g')
.selectAll('g')
.data(nodes)
.join('g')
.call(d3.drag()
.on('start', (event, d) => { if (!event.active) simulation.alphaTarget(0.3).restart(); d.fx = d.x; d.fy = d.y })
.on('drag', (event, d) => { d.fx = event.x; d.fy = event.y })
.on('end', (event, d) => { if (!event.active) simulation.alphaTarget(0); d.fx = null; d.fy = null })
)
nodeGroup.append('circle')
.attr('r', 24)
.attr('fill', d => color(d))
.attr('stroke', '#fff')
.attr('stroke-width', 2)
nodeGroup.append('text')
.attr('dy', 36)
.attr('text-anchor', 'middle')
.attr('font-size', 12)
.attr('fill', '#6b7280')
.text(d => d.name)
simulation.on('tick', () => {
link
.attr('x1', d => d.source.x)
.attr('y1', d => d.source.y)
.attr('x2', d => d.target.x)
.attr('y2', d => d.target.y)
nodeGroup.attr('transform', d => `translate(${d.x},${d.y})`)
})
graphLoading.value = false
}
const handleIngest = async () => {
if (!ingestText.value) return
ingestLoading.value = true
const apiBase = import.meta.env.VITE_API_BASE_URL || 'http://localhost:3000'
const now = new Date().toLocaleTimeString()
try {
const res = await fetch(`${apiBase}/ingest`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text: ingestText.value })
})
const data = await res.json()
ingestLogs.value.unshift({ time: now, msg: `导入成功: ${data.chunks?.length || 0} 个 chunk`, type: 'success' })
ingestText.value = ''
} catch (e) {
ingestLogs.value.unshift({ time: now, msg: `导入失败: ${e.message}`, type: 'error' })
} finally {
ingestLoading.value = false
}
}
const handleQuery = async () => {
if (!queryText.value) return
queryLoading.value = true
const apiBase = import.meta.env.VITE_API_BASE_URL || 'http://localhost:3000'
try {
const res = await fetch(`${apiBase}/query/graphrag`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query: queryText.value })
})
queryResult.value = await res.json()
} catch (e) {
queryResult.value = { answer: `检索失败: ${e.message}`, chunks: [] }
} finally {
queryLoading.value = false
}
}
let resizeObserver
let graphRendered = false
onMounted(() => {
renderGraph()
graphRendered = true
if (graphCanvas.value) {
resizeObserver = new ResizeObserver(() => {
if (graphRendered) renderGraph()
})
resizeObserver.observe(graphCanvas.value)
}
})
onUnmounted(() => {
resizeObserver?.disconnect()
})
</script>
<style scoped>
* { margin: 0; padding: 0; box-sizing: border-box; }
.dashboard {
display: flex;
height: 100vh;
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
background: #f7f8fa;
color: #1f2937;
}
.sidebar {
width: 240px;
background: #fff;
border-right: 1px solid #e5e7eb;
display: flex;
flex-direction: column;
flex-shrink: 0;
}
.sidebar-header {
display: flex;
align-items: center;
gap: 12px;
padding: 24px 20px;
border-bottom: 1px solid #e5e7eb;
}
.logo-mark { flex-shrink: 0; }
.logo-text { display: flex; flex-direction: column; }
.logo-name { font-size: 1rem; font-weight: 700; color: #0f0f0f; }
.logo-sub { font-size: 0.75rem; color: #9ca3af; }
.sidebar-nav {
flex: 1;
padding: 16px 12px;
display: flex;
flex-direction: column;
gap: 4px;
}
.nav-btn {
display: flex;
align-items: center;
gap: 12px;
padding: 10px 12px;
border: none;
background: transparent;
border-radius: 8px;
cursor: pointer;
font-size: 0.9rem;
color: #6b7280;
transition: all 0.15s ease;
text-align: left;
width: 100%;
}
.nav-btn:hover { background: #f3f4f6; color: #1f2937; }
.nav-btn.active { background: #eef2ff; color: #6366f1; font-weight: 600; }
.nav-icon { font-size: 1.1rem; width: 20px; text-align: center; }
.sidebar-footer {
padding: 16px 12px;
border-top: 1px solid #e5e7eb;
}
.user-card {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
}
.user-avatar {
width: 32px; height: 32px;
background: #6366f1;
border-radius: 50%;
display: flex; align-items: center; justify-content: center;
color: white; font-size: 0.85rem; font-weight: 600;
}
.user-info { display: flex; flex-direction: column; }
.user-role { font-size: 0.7rem; color: #9ca3af; }
.user-name { font-size: 0.85rem; font-weight: 600; color: #1f2937; }
.logout-btn {
display: flex; align-items: center; gap: 8px;
width: 100%; padding: 8px 12px;
background: transparent; border: 1px solid #e5e7eb;
border-radius: 8px; cursor: pointer;
font-size: 0.85rem; color: #6b7280;
transition: all 0.15s;
}
.logout-btn:hover { background: #fee2e2; color: #ef4444; border-color: #fca5a5; }
.main-panel {
flex: 1;
display: flex;
flex-direction: column;
overflow: hidden;
}
.top-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 24px 32px;
background: #fff;
border-bottom: 1px solid #e5e7eb;
flex-shrink: 0;
}
.page-title { font-size: 1.25rem; font-weight: 700; color: #0f0f0f; }
.page-desc { font-size: 0.85rem; color: #9ca3af; margin-top: 2px; }
.btn-ghost {
display: flex; align-items: center; gap: 6px;
padding: 8px 16px;
background: transparent; border: 1px solid #e5e7eb;
border-radius: 8px; cursor: pointer;
font-size: 0.85rem; color: #6b7280;
transition: all 0.15s;
}
.btn-ghost:hover { background: #f3f4f6; color: #1f2937; }
.content-area { flex: 1; overflow: hidden; padding: 24px 32px; }
.graph-view { height: 100%; display: flex; flex-direction: column; gap: 16px; }
.graph-toolbar {
display: flex; align-items: center; justify-content: space-between;
background: #fff; padding: 12px 16px;
border-radius: 10px; border: 1px solid #e5e7eb;
flex-shrink: 0;
}
.toolbar-left { display: flex; align-items: center; gap: 16px; }
.data-badge {
background: #dcfce7; color: #16a34a;
font-size: 0.75rem; font-weight: 600;
padding: 3px 10px; border-radius: 20px;
}
.node-count { font-size: 0.85rem; color: #6b7280; }
.toolbar-right { display: flex; gap: 8px; }
.btn-outline {
padding: 6px 14px;
background: transparent; border: 1px solid #e5e7eb;
border-radius: 6px; cursor: pointer;
font-size: 0.8rem; color: #6b7280;
transition: all 0.15s;
}
.btn-outline:hover { background: #f3f4f6; color: #1f2937; }
.btn-primary {
padding: 6px 16px;
background: #6366f1; color: white;
border: none; border-radius: 6px;
cursor: pointer; font-size: 0.8rem; font-weight: 600;
transition: all 0.15s;
}
.btn-primary:hover:not(:disabled) { background: #4f46e5; }
.btn-primary:disabled { background: #d1d5db; cursor: not-allowed; }
.graph-canvas {
flex: 1;
background: #fff;
border-radius: 10px;
border: 1px solid #e5e7eb;
position: relative;
overflow: hidden;
}
.graph-loading {
position: absolute; inset: 0;
display: flex; flex-direction: column;
align-items: center; justify-content: center; gap: 12px;
background: rgba(255,255,255,0.9);
}
.spinner {
width: 32px; height: 32px;
border: 3px solid #e5e7eb;
border-top-color: #6366f1;
border-radius: 50%;
animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.graph-loading p { font-size: 0.9rem; color: #6b7280; }
.graph-svg { width: 100%; height: 100%; }
.panel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; height: 100%; }
.panel-grid .wide { grid-column: 1 / -1; }
.panel-card {
background: #fff;
border: 1px solid #e5e7eb;
border-radius: 10px;
display: flex;
flex-direction: column;
overflow: hidden;
}
.panel-header {
display: flex; align-items: center; justify-content: space-between;
padding: 16px 20px;
border-bottom: 1px solid #e5e7eb;
}
.panel-header h3 { font-size: 0.95rem; font-weight: 700; }
.panel-tag {
font-size: 0.7rem; font-weight: 600;
padding: 2px 8px; border-radius: 20px;
background: #e0e7ff; color: #6366f1;
}
.panel-tag.info { background: #dbeafe; color: #2563eb; }
.panel-body { flex: 1; padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.text-area {
width: 100%; padding: 12px;
border: 1px solid #e5e7eb; border-radius: 8px;
font-size: 0.9rem; resize: none; outline: none;
font-family: inherit;
transition: border-color 0.15s;
}
.text-area:focus { border-color: #6366f1; }
.panel-actions { display: flex; justify-content: flex-end; }
.log-list { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; max-height: 300px; }
.log-item {
display: flex; align-items: flex-start; gap: 10px;
padding: 8px 10px; border-radius: 6px;
font-size: 0.8rem;
}
.log-item.success { background: #dcfce7; color: #16a34a; }
.log-item.error { background: #fee2e2; color: #ef4444; }
.log-time { color: #9ca3af; flex-shrink: 0; }
.log-msg { flex: 1; }
.log-empty { color: #9ca3af; font-size: 0.85rem; text-align: center; padding: 20px; }
.query-input-row { display: flex; gap: 12px; }
.query-input {
flex: 1; padding: 10px 14px;
border: 1px solid #e5e7eb; border-radius: 8px;
font-size: 0.9rem; outline: none;
transition: border-color 0.15s;
}
.query-input:focus { border-color: #6366f1; }
.query-result { display: flex; flex-direction: column; gap: 16px; margin-top: 8px; }
.result-section { display: flex; flex-direction: column; gap: 8px; }
.result-section h4 { font-size: 0.85rem; font-weight: 600; color: #6b7280; }
.result-text { font-size: 0.95rem; color: #1f2937; line-height: 1.6; }
.chunk-list { display: flex; flex-direction: column; gap: 8px; }
.chunk-item {
padding: 10px 12px;
background: #f9fafb; border: 1px solid #e5e7eb;
border-radius: 6px; font-size: 0.85rem;
}
.chunk-score { color: #6366f1; font-size: 0.75rem; margin-top: 4px; display: block; }
.api-row { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.method-select { padding: 8px 12px; border: 1px solid #e5e7eb; border-radius: 6px; font-size: 0.85rem; background: #fff; min-width: 90px; }
.api-url-input { flex: 1; padding: 8px 12px; border: 1px solid #e5e7eb; border-radius: 6px; font-size: 0.85rem; }
.api-endpoints { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 12px; }
.endpoint-label { font-size: 0.8rem; color: #6b7280; }
.endpoint-chip { display: flex; align-items: center; gap: 4px; padding: 4px 10px; border: 1px solid #e5e7eb; border-radius: 16px; background: #fff; cursor: pointer; font-size: 0.78rem; transition: all 0.2s; }
.endpoint-chip:hover { border-color: #6366f1; background: #eef2ff; }
.chip-method { font-weight: 700; font-size: 0.7rem; padding: 1px 4px; border-radius: 3px; }
.chip-method.get { color: #10b981; } .chip-method.post { color: #6366f1; } .chip-method.put { color: #f59e0b; } .chip-method.delete { color: #ef4444; }
.api-body-section { margin-bottom: 12px; }
.body-label { font-size: 0.82rem; color: #6b7280; margin-bottom: 6px; font-weight: 500; }
.code-area { font-family: 'Fira Code', monospace; font-size: 0.82rem; }
.api-response-section { background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 6px; padding: 12px; }
.response-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.response-header h4 { font-size: 0.85rem; font-weight: 600; }
.status-badge { font-size: 0.75rem; padding: 2px 8px; border-radius: 10px; font-weight: 600; }
.status-badge.success { background: #d1fae5; color: #065f46; } .status-badge.error { background: #fee2e2; color: #991b1b; }
.response-pre { font-family: 'Fira Code', monospace; font-size: 0.8rem; white-space: pre-wrap; word-break: break-all; max-height: 300px; overflow-y: auto; color: #374151; }
</style>

View File

@@ -0,0 +1,363 @@
<template>
<div class="login-page">
<div class="login-left">
<div class="brand-content">
<div class="brand-logo">
<svg width="48" height="48" viewBox="0 0 48 48" fill="none">
<circle cx="24" cy="24" r="20" stroke="#fff" stroke-width="2"/>
<circle cx="24" cy="24" r="8" fill="#fff"/>
<line x1="24" y1="4" x2="24" y2="16" stroke="#fff" stroke-width="2"/>
<line x1="24" y1="32" x2="24" y2="44" stroke="#fff" stroke-width="2"/>
<line x1="4" y1="24" x2="16" y2="24" stroke="#fff" stroke-width="2"/>
<line x1="32" y1="24" x2="44" y2="24" stroke="#fff" stroke-width="2"/>
</svg>
</div>
<h1>OnceLove GraphRAG</h1>
<p class="brand-desc">智能知识图谱与时序检索管理平台</p>
<div class="feature-list">
<div class="feature-item">
<span class="feature-icon"></span>
<span>Neo4j 关系图谱</span>
</div>
<div class="feature-item">
<span class="feature-icon"></span>
<span>Qdrant 向量检索</span>
</div>
<div class="feature-item">
<span class="feature-icon"></span>
<span>时序事件分析</span>
</div>
</div>
</div>
<div class="bg-decoration">
<div class="circle c1"></div>
<div class="circle c2"></div>
<div class="circle c3"></div>
</div>
</div>
<div class="login-right">
<div class="login-card">
<div class="card-header">
<h2>管理员登录</h2>
<p>请输入访问密钥以继续</p>
</div>
<form @submit.prevent="handleLogin" class="login-form">
<div class="form-item">
<label>访问密钥</label>
<div class="input-wrapper" :class="{ error: error, focus: isFocused }">
<svg class="input-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<rect x="3" y="11" width="18" height="11" rx="2" ry="2"/>
<path d="M7 11V7a5 5 0 0 1 10 0v4"/>
</svg>
<input
type="password"
v-model="password"
@focus="isFocused = true"
@blur="isFocused = false"
placeholder="请输入密钥"
:disabled="loading"
autocomplete="current-password"
/>
</div>
</div>
<p v-if="error" class="error-text">
<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor">
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"/>
</svg>
{{ error }}
</p>
<button type="submit" class="login-btn" :class="{ loading }" :disabled="loading || !password">
<span v-if="!loading">进入控制台</span>
<span v-else class="loading-dots">
<span></span><span></span><span></span>
</span>
</button>
</form>
<div class="card-footer">
<p>OnceLove GraphRAG © 2024</p>
</div>
</div>
</div>
</div>
</template>
<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
const router = useRouter()
const password = ref('')
const error = ref('')
const loading = ref(false)
const isFocused = ref(false)
const handleLogin = async () => {
if (!password.value) {
error.value = '请输入密钥'
return
}
loading.value = true
error.value = ''
try {
const apiBase = import.meta.env.VITE_API_BASE_URL || 'http://localhost:3000'
const res = await fetch(`${apiBase}/auth/verify`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ password: password.value })
})
const data = await res.json().catch(() => ({}))
if (!res.ok || !data?.ok) {
error.value = data?.message || '密钥错误'
return
}
localStorage.setItem('auth_token', 'ok')
router.push('/')
} catch (e) {
error.value = '登录请求失败,请检查 API 地址或网络'
} finally {
loading.value = false
}
}
</script>
<style scoped>
.login-page {
display: flex;
min-height: 100vh;
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.login-left {
flex: 1;
background: linear-gradient(135deg, #0f0f0f 0%, #1a1a2e 100%);
color: white;
padding: 60px;
position: relative;
overflow: hidden;
display: flex;
align-items: center;
}
.brand-content {
position: relative;
z-index: 2;
}
.brand-logo {
margin-bottom: 32px;
}
.brand-content h1 {
font-size: 2.5rem;
font-weight: 700;
margin-bottom: 12px;
letter-spacing: -0.02em;
}
.brand-desc {
font-size: 1.1rem;
color: rgba(255,255,255,0.6);
margin-bottom: 48px;
}
.feature-list {
display: flex;
flex-direction: column;
gap: 16px;
}
.feature-item {
display: flex;
align-items: center;
gap: 12px;
font-size: 1rem;
color: rgba(255,255,255,0.85);
}
.feature-icon {
color: #6366f1;
font-size: 1.2rem;
}
.bg-decoration {
position: absolute;
inset: 0;
z-index: 1;
}
.circle {
position: absolute;
border-radius: 50%;
background: linear-gradient(135deg, rgba(99,102,241,0.3) 0%, rgba(99,102,241,0) 100%);
}
.c1 { width: 400px; height: 400px; top: -100px; right: -100px; }
.c2 { width: 300px; height: 300px; bottom: -50px; left: -50px; }
.c3 { width: 200px; height: 200px; bottom: 20%; right: 10%; opacity: 0.5; }
.login-right {
width: 520px;
display: flex;
align-items: center;
justify-content: center;
padding: 60px;
background: #fafafa;
}
.login-card {
width: 100%;
max-width: 380px;
}
.card-header {
margin-bottom: 40px;
}
.card-header h2 {
font-size: 1.75rem;
font-weight: 700;
color: #0f0f0f;
margin-bottom: 8px;
}
.card-header p {
color: #666;
font-size: 0.95rem;
}
.login-form {
display: flex;
flex-direction: column;
gap: 24px;
}
.form-item label {
display: block;
font-size: 0.875rem;
font-weight: 500;
color: #374151;
margin-bottom: 8px;
}
.input-wrapper {
display: flex;
align-items: center;
background: white;
border: 1.5px solid #e5e7eb;
border-radius: 10px;
padding: 0 16px;
transition: all 0.2s ease;
}
.input-wrapper.focus {
border-color: #6366f1;
box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}
.input-wrapper.error {
border-color: #ef4444;
}
.input-icon {
color: #9ca3af;
flex-shrink: 0;
}
.input-wrapper input {
flex: 1;
border: none;
outline: none;
padding: 14px 12px;
font-size: 1rem;
background: transparent;
color: #0f0f0f;
}
.input-wrapper input::placeholder {
color: #9ca3af;
}
.input-wrapper input:disabled {
opacity: 0.6;
}
.error-text {
display: flex;
align-items: center;
gap: 6px;
color: #ef4444;
font-size: 0.875rem;
margin-top: -8px;
}
.login-btn {
width: 100%;
padding: 14px 24px;
background: #0f0f0f;
color: white;
border: none;
border-radius: 10px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.2s ease;
margin-top: 8px;
}
.login-btn:hover:not(:disabled) {
background: #1a1a1a;
transform: translateY(-1px);
}
.login-btn:disabled {
background: #d1d5db;
cursor: not-allowed;
transform: none;
}
.login-btn.loading {
pointer-events: none;
}
.loading-dots {
display: flex;
justify-content: center;
gap: 4px;
}
.loading-dots span {
width: 6px;
height: 6px;
background: white;
border-radius: 50%;
animation: bounce 1.4s infinite ease-in-out;
}
.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce {
0%, 80%, 100% { transform: scale(0); }
40% { transform: scale(1); }
}
.card-footer {
margin-top: 48px;
text-align: center;
}
.card-footer p {
font-size: 0.8rem;
color: #9ca3af;
}
@media (max-width: 900px) {
.login-left { display: none; }
.login-right { width: 100%; }
}
</style>

View File

@@ -0,0 +1,7 @@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// https://vite.dev/config/
export default defineConfig({
plugins: [vue()],
})