feat(frontend): S0 Vue3 脚手架 + auth + Layout shell(4入口,模拟/实盘灰显)
- Vite+TS+ElementPlus+ECharts+Pinia+Router+Axios - auth store + JWT axios 拦截器 + 路由守卫 - 登录页 + Layout(侧栏 4 入口,回测/投研 active,模拟/实盘 disabled) - 占位页(backtest/factor,S1/S2 填充) - vitest auth store 3 tests passed + build 通过(dist 生成)
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
<script setup lang="ts">
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
|
||||
const router = useRouter()
|
||||
const auth = useAuthStore()
|
||||
|
||||
function navigate(path: string): void {
|
||||
router.push(path)
|
||||
}
|
||||
|
||||
function onLogout(): void {
|
||||
auth.logout()
|
||||
router.push('/login')
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<el-container class="layout">
|
||||
<el-aside width="200px" class="sidebar">
|
||||
<div class="logo">三国量化</div>
|
||||
<el-menu :default-active="$route.path" @select="navigate">
|
||||
<el-menu-item index="/backtest/new">
|
||||
<span>📊 回测</span>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="/factor/new">
|
||||
<span>🔬 投研</span>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="sim" disabled>
|
||||
<span>🧪 模拟 <em class="muted">(C 期)</em></span>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="live" disabled>
|
||||
<span>💰 实盘 <em class="muted">(D 期 · 国金 QMT)</em></span>
|
||||
</el-menu-item>
|
||||
</el-menu>
|
||||
</el-aside>
|
||||
<el-container>
|
||||
<el-header class="header">
|
||||
<span class="sys-name">投研 + 回测 控制台</span>
|
||||
<div class="user-area">
|
||||
<span>{{ auth.username }}</span>
|
||||
<el-button link type="primary" @click="onLogout">登出</el-button>
|
||||
</div>
|
||||
</el-header>
|
||||
<el-main>
|
||||
<router-view />
|
||||
</el-main>
|
||||
</el-container>
|
||||
</el-container>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.layout {
|
||||
height: 100vh;
|
||||
}
|
||||
.sidebar {
|
||||
background: #001529;
|
||||
color: #fff;
|
||||
}
|
||||
.logo {
|
||||
height: 60px;
|
||||
line-height: 60px;
|
||||
text-align: center;
|
||||
font-size: 18px;
|
||||
color: #fff;
|
||||
background: #002140;
|
||||
}
|
||||
.header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
background: #fff;
|
||||
border-bottom: 1px solid #eee;
|
||||
}
|
||||
.sys-name {
|
||||
font-weight: 600;
|
||||
}
|
||||
.user-area {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
.muted {
|
||||
color: #999;
|
||||
font-style: normal;
|
||||
font-size: 12px;
|
||||
}
|
||||
:deep(.el-menu) {
|
||||
background: transparent;
|
||||
border-right: none;
|
||||
}
|
||||
:deep(.el-menu-item) {
|
||||
color: #ccc;
|
||||
}
|
||||
:deep(.el-menu-item.is-active) {
|
||||
color: #fff;
|
||||
background: #1890ff;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,69 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { apiClient } from '@/api/client'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
|
||||
const router = useRouter()
|
||||
const auth = useAuthStore()
|
||||
|
||||
const loading = ref(false)
|
||||
const form = reactive({ username: 'admin', password: '' })
|
||||
|
||||
async function onSubmit(): Promise<void> {
|
||||
if (!form.username || !form.password) {
|
||||
ElMessage.warning('请输入用户名和密码')
|
||||
return
|
||||
}
|
||||
loading.value = true
|
||||
try {
|
||||
const { data } = await apiClient.post<{ token: string }>('/auth/login', {
|
||||
username: form.username,
|
||||
password: form.password,
|
||||
})
|
||||
auth.setToken(data.token, form.username)
|
||||
router.push('/')
|
||||
} catch {
|
||||
ElMessage.error('登录失败:用户名或密码错误')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="login-wrap">
|
||||
<el-card class="login-card">
|
||||
<template #header>
|
||||
<h2 class="login-title">三国量化研究台</h2>
|
||||
</template>
|
||||
<el-form label-position="top" @submit.prevent="onSubmit">
|
||||
<el-form-item label="用户名">
|
||||
<el-input v-model="form.username" placeholder="admin" />
|
||||
</el-form-item>
|
||||
<el-form-item label="密码">
|
||||
<el-input v-model="form.password" type="password" show-password placeholder="请输入密码" @keyup.enter="onSubmit" />
|
||||
</el-form-item>
|
||||
<el-button type="primary" :loading="loading" style="width: 100%" @click="onSubmit">登录</el-button>
|
||||
</el-form>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.login-wrap {
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #f0f2f5;
|
||||
}
|
||||
.login-card {
|
||||
width: 360px;
|
||||
}
|
||||
.login-title {
|
||||
margin: 0;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,4 @@
|
||||
<script setup lang="ts"></script>
|
||||
<template>
|
||||
<el-empty description="回测 - 新建(S1 切片实现)" />
|
||||
</template>
|
||||
@@ -0,0 +1,4 @@
|
||||
<script setup lang="ts"></script>
|
||||
<template>
|
||||
<el-empty description="回测 - 进度(S1 切片实现)" />
|
||||
</template>
|
||||
@@ -0,0 +1,4 @@
|
||||
<script setup lang="ts"></script>
|
||||
<template>
|
||||
<el-empty description="回测 - 结果(S1 切片实现)" />
|
||||
</template>
|
||||
@@ -0,0 +1,4 @@
|
||||
<script setup lang="ts"></script>
|
||||
<template>
|
||||
<el-empty description="投研 - 新建因子分析(S2 切片实现)" />
|
||||
</template>
|
||||
@@ -0,0 +1,4 @@
|
||||
<script setup lang="ts"></script>
|
||||
<template>
|
||||
<el-empty description="投研 - 结果(S2 切片实现)" />
|
||||
</template>
|
||||
Reference in New Issue
Block a user