Initial commit: ai4se-harness-suite
Import harness suite (skills, installers, overnight-runner, docs) as a fresh history for InspireChina. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
13
example-project/frontend/index.html
Normal file
13
example-project/frontend/index.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<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>咨询预约平台</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
2034
example-project/frontend/package-lock.json
generated
Normal file
2034
example-project/frontend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
25
example-project/frontend/package.json
Normal file
25
example-project/frontend/package.json
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "consultation-frontend",
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vue-tsc -b && vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^1.7.0",
|
||||
"element-plus": "^2.9.0",
|
||||
"pinia": "^2.2.0",
|
||||
"vue": "^3.5.13",
|
||||
"vue-router": "^4.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^25.9.3",
|
||||
"@vitejs/plugin-vue": "^5.0.5",
|
||||
"typescript": "~5.5.0",
|
||||
"vite": "^5.4.0",
|
||||
"vue-tsc": "^2.0.0"
|
||||
}
|
||||
}
|
||||
3
example-project/frontend/src/App.vue
Normal file
3
example-project/frontend/src/App.vue
Normal file
@@ -0,0 +1,3 @@
|
||||
<template>
|
||||
<router-view />
|
||||
</template>
|
||||
22
example-project/frontend/src/assets/main.css
Normal file
22
example-project/frontend/src/assets/main.css
Normal file
@@ -0,0 +1,22 @@
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
:root {
|
||||
--primary: #4F46E5; --primary-light: #818CF8; --primary-dark: #3730A3;
|
||||
--success: #10B981; --warning: #F59E0B; --danger: #EF4444;
|
||||
--gray-50: #F9FAFB; --gray-100: #F3F4F6; --gray-200: #E5E7EB;
|
||||
--gray-300: #D1D5DB; --gray-400: #9CA3AF; --gray-500: #6B7280;
|
||||
--gray-600: #4B5563; --gray-700: #374151; --gray-800: #1F2937; --gray-900: #111827;
|
||||
}
|
||||
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; color: var(--gray-900); background: var(--gray-50); line-height: 1.6; }
|
||||
a { color: var(--primary); text-decoration: none; }
|
||||
button { cursor: pointer; border: none; font-size: inherit; }
|
||||
.container { max-width: 1200px; margin: 0 auto; padding: 0 1rem; }
|
||||
.btn { display: inline-flex; align-items: center; justify-content: center; padding: 0.5rem 1rem; border-radius: 0.375rem; font-weight: 500; transition: all 0.2s; }
|
||||
.btn-primary { background: var(--primary); color: white; }
|
||||
.btn-primary:hover { background: var(--primary-dark); }
|
||||
.btn-secondary { background: var(--gray-200); color: var(--gray-700); }
|
||||
.btn-danger { background: var(--danger); color: white; }
|
||||
.card { background: white; border-radius: 0.5rem; box-shadow: 0 1px 3px rgba(0,0,0,0.1); padding: 1.5rem; }
|
||||
.input { width: 100%; padding: 0.5rem 0.75rem; border: 1px solid var(--gray-300); border-radius: 0.375rem; font-size: 0.875rem; }
|
||||
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,0.1); }
|
||||
.form-group { margin-bottom: 1rem; }
|
||||
.form-group label { display: block; margin-bottom: 0.25rem; font-weight: 500; font-size: 0.875rem; color: var(--gray-700); }
|
||||
@@ -0,0 +1,34 @@
|
||||
<template>
|
||||
<div class="admin-layout">
|
||||
<aside class="sidebar">
|
||||
<h2>管理后台</h2>
|
||||
<nav><router-link v-for="l in links" :key="l.path" :to="l.path" class="nav-link">{{ l.label }}</router-link></nav>
|
||||
<button class="btn btn-sm" style="margin-top:auto" @click="auth.logout()">退出</button>
|
||||
</aside>
|
||||
<main class="main"><router-view /></main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { useRouter } from 'vue-router'
|
||||
const auth = useAuthStore()
|
||||
const router = useRouter()
|
||||
if (!auth.isLoggedIn) router.push('/login')
|
||||
const links = [
|
||||
{ path: '/admin/dashboard', label: '仪表盘' },
|
||||
{ path: '/admin/users', label: '用户管理' },
|
||||
{ path: '/admin/consultants', label: '咨询师管理' },
|
||||
{ path: '/admin/appointments', label: '预约管理' },
|
||||
{ path: '/admin/branches', label: '网点管理' },
|
||||
]
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.admin-layout { display: flex; min-height: 100vh; }
|
||||
.sidebar { width: 220px; background: #1e293b; color: #fff; padding: 1.5rem; display: flex; flex-direction: column; }
|
||||
.sidebar h2 { font-size: 1.125rem; margin-bottom: 1.5rem; }
|
||||
.nav-link { display: block; padding: 0.5rem 0.75rem; color: #cbd5e1; text-decoration: none; border-radius: 0.25rem; margin-bottom: 0.25rem; }
|
||||
.nav-link:hover, .nav-link.router-link-active { background: #334155; color: #fff; }
|
||||
.main { flex: 1; padding: 2rem; background: #f8fafc; }
|
||||
</style>
|
||||
37
example-project/frontend/src/components/layout/AppHeader.vue
Normal file
37
example-project/frontend/src/components/layout/AppHeader.vue
Normal file
@@ -0,0 +1,37 @@
|
||||
<template>
|
||||
<div>
|
||||
<header class="header">
|
||||
<div class="container header-inner">
|
||||
<router-link to="/" class="logo">咨询预约平台</router-link>
|
||||
<nav class="nav">
|
||||
<router-link to="/">首页</router-link>
|
||||
<template v-if="auth.isLoggedIn">
|
||||
<router-link to="/user/dashboard">用户中心</router-link>
|
||||
<router-link v-if="auth.isAdmin" to="/admin/dashboard">管理后台</router-link>
|
||||
<span class="user-name">{{ auth.user?.name }}</span>
|
||||
<button class="btn btn-secondary" @click="auth.logout(); router.push('/')">退出</button>
|
||||
</template>
|
||||
<template v-else>
|
||||
<router-link to="/login">登录</router-link>
|
||||
<router-link to="/register" class="btn btn-primary">注册</router-link>
|
||||
</template>
|
||||
</nav>
|
||||
</div>
|
||||
</header>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { useRouter } from 'vue-router'
|
||||
const auth = useAuthStore()
|
||||
const router = useRouter()
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.header { background: white; border-bottom: 1px solid var(--gray-200); position: sticky; top: 0; z-index: 100; }
|
||||
.header-inner { display: flex; align-items: center; justify-content: space-between; height: 3.5rem; }
|
||||
.logo { font-size: 1.25rem; font-weight: 700; color: var(--primary); }
|
||||
.nav { display: flex; align-items: center; gap: 1rem; }
|
||||
.user-name { color: var(--gray-600); font-size: 0.875rem; }
|
||||
</style>
|
||||
@@ -0,0 +1,10 @@
|
||||
<template>
|
||||
<div>
|
||||
<AppHeader />
|
||||
<div class="container" style="padding-top:2rem;padding-bottom:2rem"><router-view /></div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import AppHeader from './AppHeader.vue'
|
||||
</script>
|
||||
6
example-project/frontend/src/env.d.ts
vendored
Normal file
6
example-project/frontend/src/env.d.ts
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
/// <reference types="vite/client" />
|
||||
declare module '*.vue' {
|
||||
import type { DefineComponent } from 'vue'
|
||||
const component: DefineComponent<{}, {}, any>
|
||||
export default component
|
||||
}
|
||||
13
example-project/frontend/src/main.ts
Normal file
13
example-project/frontend/src/main.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { createApp } from 'vue'
|
||||
import { createPinia } from 'pinia'
|
||||
import ElementPlus from 'element-plus'
|
||||
import 'element-plus/dist/index.css'
|
||||
import App from './App.vue'
|
||||
import router from './router'
|
||||
import './assets/main.css'
|
||||
|
||||
const app = createApp(App)
|
||||
app.use(createPinia())
|
||||
app.use(router)
|
||||
app.use(ElementPlus)
|
||||
app.mount('#app')
|
||||
35
example-project/frontend/src/router/index.ts
Normal file
35
example-project/frontend/src/router/index.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes: [
|
||||
{ path: '/', name: 'home', component: () => import('@/views/home/HomePage.vue') },
|
||||
{ path: '/login', name: 'login', component: () => import('@/views/auth/Login.vue') },
|
||||
{ path: '/register', name: 'register', component: () => import('@/views/auth/Register.vue') },
|
||||
{
|
||||
path: '/user',
|
||||
component: () => import('@/components/layout/UserLayout.vue'),
|
||||
children: [
|
||||
{ path: '', redirect: '/user/dashboard' },
|
||||
{ path: 'dashboard', component: () => import('@/views/user/Dashboard.vue') },
|
||||
{ path: 'appointments', component: () => import('@/views/user/MyAppointments.vue') },
|
||||
{ path: 'book', component: () => import('@/views/user/BookAppointment.vue') },
|
||||
{ path: 'profile', component: () => import('@/views/user/Profile.vue') },
|
||||
],
|
||||
},
|
||||
{
|
||||
path: '/admin',
|
||||
component: () => import('@/components/layout/AdminLayout.vue'),
|
||||
children: [
|
||||
{ path: '', redirect: '/admin/dashboard' },
|
||||
{ path: 'dashboard', component: () => import('@/views/admin/Dashboard.vue') },
|
||||
{ path: 'appointments', component: () => import('@/views/admin/Appointments.vue') },
|
||||
{ path: 'consultants', component: () => import('@/views/admin/Consultants.vue') },
|
||||
{ path: 'users', component: () => import('@/views/admin/Users.vue') },
|
||||
{ path: 'branches', component: () => import('@/views/admin/Branches.vue') },
|
||||
],
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
export default router
|
||||
35
example-project/frontend/src/stores/auth.ts
Normal file
35
example-project/frontend/src/stores/auth.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref, computed } from 'vue'
|
||||
import type { AuthResponse, User } from '@/types'
|
||||
import http from '@/utils/request'
|
||||
|
||||
export const useAuthStore = defineStore('auth', () => {
|
||||
const token = ref(localStorage.getItem('token') || '')
|
||||
const user = ref<User | null>(JSON.parse(localStorage.getItem('user') || 'null'))
|
||||
const isLoggedIn = computed(() => !!token.value)
|
||||
const isAdmin = computed(() => user.value?.role === 'ROLE_ADMIN')
|
||||
|
||||
function setAuth(t: string, u: User) {
|
||||
token.value = t; user.value = u
|
||||
localStorage.setItem('token', t); localStorage.setItem('user', JSON.stringify(u))
|
||||
}
|
||||
|
||||
async function login(email: string, password: string) {
|
||||
const r = await http.post<AuthResponse>('/auth/login', { email, password })
|
||||
setAuth(r.data.token, r.data.user)
|
||||
return r.data
|
||||
}
|
||||
|
||||
async function register(email: string, password: string, name: string, phone?: string) {
|
||||
const r = await http.post<AuthResponse>('/auth/register', { email, password, name, phone })
|
||||
setAuth(r.data.token, r.data.user)
|
||||
return r.data
|
||||
}
|
||||
|
||||
function logout() {
|
||||
token.value = ''; user.value = null
|
||||
localStorage.removeItem('token'); localStorage.removeItem('user')
|
||||
}
|
||||
|
||||
return { token, user, isLoggedIn, isAdmin, login, register, logout }
|
||||
})
|
||||
17
example-project/frontend/src/types/index.ts
Normal file
17
example-project/frontend/src/types/index.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
export interface User {
|
||||
id: string; email: string; name: string; phone: string; role: string; status: string
|
||||
}
|
||||
export interface AuthResponse { token: string; user: User }
|
||||
export interface Appointment {
|
||||
id: string; userId: string; consultantId: string; branchId: string;
|
||||
appointmentDate: string; startTime: string; endTime: string;
|
||||
durationMinutes: number; status: string; note: string; cancelReason: string
|
||||
}
|
||||
export interface Consultant {
|
||||
id: string; name: string; title: string; bio: string; specialties: string;
|
||||
avatar: string; branchId: string; status: string; sortOrder: number
|
||||
}
|
||||
export interface Branch {
|
||||
id: string; name: string; address: string; phone: string; status: string
|
||||
}
|
||||
export interface TimeSlot { startTime: string; endTime: string }
|
||||
9
example-project/frontend/src/utils/date.ts
Normal file
9
example-project/frontend/src/utils/date.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export function getWeekDates(): string[] {
|
||||
const dates: string[] = []
|
||||
const today = new Date()
|
||||
for (let i = 0; i < 7; i++) {
|
||||
const d = new Date(today); d.setDate(d.getDate() + i)
|
||||
dates.push(d.toISOString().split('T')[0])
|
||||
}
|
||||
return dates
|
||||
}
|
||||
23
example-project/frontend/src/utils/request.ts
Normal file
23
example-project/frontend/src/utils/request.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import axios from 'axios'
|
||||
|
||||
const http = axios.create({
|
||||
baseURL: '/api/v1',
|
||||
timeout: 15000,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
})
|
||||
|
||||
http.interceptors.request.use(cfg => {
|
||||
const token = localStorage.getItem('token')
|
||||
if (token) cfg.headers.Authorization = `Bearer ${token}`
|
||||
return cfg
|
||||
})
|
||||
|
||||
http.interceptors.response.use(
|
||||
r => r,
|
||||
e => {
|
||||
if (e.response?.status === 401) { localStorage.removeItem('token'); localStorage.removeItem('user'); window.location.href = '/login' }
|
||||
return Promise.reject(e)
|
||||
}
|
||||
)
|
||||
|
||||
export default http
|
||||
31
example-project/frontend/src/views/admin/Appointments.vue
Normal file
31
example-project/frontend/src/views/admin/Appointments.vue
Normal file
@@ -0,0 +1,31 @@
|
||||
<template>
|
||||
<div>
|
||||
<h1>预约管理</h1>
|
||||
<div v-if="loading">加载中...</div>
|
||||
<table v-else class="table"><thead><tr><th>ID</th><th>咨询师ID</th><th>日期</th><th>时间</th><th>状态</th><th>备注</th></tr></thead>
|
||||
<tbody><tr v-for="a in apps" :key="a.id"><td>{{ a.id.substring(0,8) }}...</td><td>{{ a.consultantId.substring(0,8) }}...</td>
|
||||
<td>{{ a.appointmentDate }}</td><td>{{ a.startTime }}-{{ a.endTime }}</td><td><span class="status" :class="a.status.toLowerCase()">{{ a.status }}</span></td><td>{{ a.note }}</td>
|
||||
</tr></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import http from '@/utils/request'
|
||||
import type { Appointment } from '@/types'
|
||||
|
||||
const apps = ref<Appointment[]>([]); const loading = ref(true)
|
||||
onMounted(async () => { try { const r = await http.get('/admin/appointments'); apps.value = r.data } finally { loading.value = false } })
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
h1 { margin-bottom: 1rem; }
|
||||
.table { width: 100%; border-collapse: collapse; }
|
||||
.table th, .table td { text-align: left; padding: 0.75rem; border-bottom: 1px solid var(--gray-200); }
|
||||
.status { display: inline-block; padding: 0.125rem 0.5rem; border-radius: 1rem; font-size: 0.75rem; font-weight: 500; }
|
||||
.pending { background: #FEF3C7; color: #92400E; }
|
||||
.confirmed { background: #DBEAFE; color: #1E40AF; }
|
||||
.completed { background: #D1FAE5; color: #065F46; }
|
||||
.cancelled { background: #FEE2E2; color: #991B1B; }
|
||||
</style>
|
||||
65
example-project/frontend/src/views/admin/Branches.vue
Normal file
65
example-project/frontend/src/views/admin/Branches.vue
Normal file
@@ -0,0 +1,65 @@
|
||||
<template>
|
||||
<div>
|
||||
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:1rem">
|
||||
<h1>网点管理</h1>
|
||||
<button class="btn btn-primary" @click="showForm = true; editing = null; form = {name:'',address:'',phone:''}">新增网点</button>
|
||||
</div>
|
||||
<div v-if="loading">加载中...</div>
|
||||
<table v-else class="table"><thead><tr><th>名称</th><th>地址</th><th>电话</th><th>状态</th><th>操作</th></tr></thead>
|
||||
<tbody><tr v-for="b in branches" :key="b.id"><td>{{ b.name }}</td><td>{{ b.address }}</td><td>{{ b.phone }}</td>
|
||||
<td :class="b.status === 'ACTIVE' ? 'active' : 'disabled'">{{ b.status }}</td>
|
||||
<td><button class="btn btn-sm btn-secondary" @click="edit(b)">编辑</button><button class="btn btn-sm btn-danger" style="margin-left:0.25rem" @click="doDelete(b.id)">删除</button></td>
|
||||
</tr></tbody>
|
||||
</table>
|
||||
<div v-if="showForm" class="modal"><div class="modal-content card">
|
||||
<h3>{{ editing ? '编辑网点' : '新增网点' }}</h3>
|
||||
<div class="form-group"><label>名称</label><input v-model="form.name" class="input" /></div>
|
||||
<div class="form-group"><label>地址</label><input v-model="form.address" class="input" /></div>
|
||||
<div class="form-group"><label>电话</label><input v-model="form.phone" class="input" /></div>
|
||||
<div style="display:flex;gap:0.5rem;margin-top:1rem">
|
||||
<button class="btn btn-primary" @click="save" :disabled="saving">{{ saving ? '保存中...' : '保存' }}</button>
|
||||
<button class="btn btn-secondary" @click="showForm = false">取消</button>
|
||||
</div>
|
||||
</div></div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import http from '@/utils/request'
|
||||
import type { Branch } from '@/types'
|
||||
|
||||
const branches = ref<Branch[]>([]); const loading = ref(true)
|
||||
const showForm = ref(false); const editing = ref<string | null>(null); const saving = ref(false)
|
||||
const form = ref({ name: '', address: '', phone: '' })
|
||||
|
||||
function edit(b: Branch) { editing.value = b.id; form.value = { name: b.name, address: b.address, phone: b.phone }; showForm.value = true }
|
||||
|
||||
async function save() {
|
||||
saving.value = true
|
||||
try {
|
||||
if (editing.value) { await http.put(`/admin/branches/${editing.value}`, form.value) }
|
||||
else { await http.post('/admin/branches', form.value) }
|
||||
showForm.value = false; await fetch()
|
||||
} catch (e: any) { alert(e.response?.data?.errorMessage || '操作失败') }
|
||||
finally { saving.value = false }
|
||||
}
|
||||
|
||||
async function doDelete(id: string) {
|
||||
if (!confirm('确定删除?')) return; await http.delete(`/admin/branches/${id}`); await fetch()
|
||||
}
|
||||
|
||||
async function fetch() { loading.value = true; try { const r = await http.get('/admin/branches'); branches.value = r.data } finally { loading.value = false } }
|
||||
onMounted(fetch)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
h1 { margin: 0; }
|
||||
.table { width: 100%; border-collapse: collapse; }
|
||||
.table th, .table td { text-align: left; padding: 0.75rem; border-bottom: 1px solid var(--gray-200); }
|
||||
.active { color: #16a34a; font-weight: 500; }
|
||||
.disabled { color: #dc2626; font-weight: 500; }
|
||||
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 100; }
|
||||
.modal-content { width: 100%; max-width: 480px; }
|
||||
.btn-sm { padding: 0.25rem 0.75rem; font-size: 0.8125rem; }
|
||||
</style>
|
||||
29
example-project/frontend/src/views/admin/Consultants.vue
Normal file
29
example-project/frontend/src/views/admin/Consultants.vue
Normal file
@@ -0,0 +1,29 @@
|
||||
<template>
|
||||
<div>
|
||||
<h1>咨询师管理</h1>
|
||||
<div v-if="loading">加载中...</div>
|
||||
<table v-else class="table"><thead><tr><th>姓名</th><th>职称</th><th>专长</th><th>网点ID</th><th>状态</th><th>排序</th></tr></thead>
|
||||
<tbody><tr v-for="c in consultants" :key="c.id"><td>{{ c.name }}</td><td>{{ c.title }}</td>
|
||||
<td>{{ c.specialties }}</td><td>{{ c.branchId ? c.branchId.substring(0,8)+'...' : '-' }}</td>
|
||||
<td :class="c.status === 'ACTIVE' ? 'active' : 'disabled'">{{ c.status }}</td><td>{{ c.sortOrder }}</td>
|
||||
</tr></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import http from '@/utils/request'
|
||||
import type { Consultant } from '@/types'
|
||||
|
||||
const consultants = ref<Consultant[]>([]); const loading = ref(true)
|
||||
onMounted(async () => { try { const r = await http.get('/admin/consultants'); consultants.value = r.data } finally { loading.value = false } })
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
h1 { margin-bottom: 1rem; }
|
||||
.table { width: 100%; border-collapse: collapse; }
|
||||
.table th, .table td { text-align: left; padding: 0.75rem; border-bottom: 1px solid var(--gray-200); }
|
||||
.active { color: #16a34a; font-weight: 500; }
|
||||
.disabled { color: #dc2626; font-weight: 500; }
|
||||
</style>
|
||||
28
example-project/frontend/src/views/admin/Dashboard.vue
Normal file
28
example-project/frontend/src/views/admin/Dashboard.vue
Normal file
@@ -0,0 +1,28 @@
|
||||
<template>
|
||||
<div>
|
||||
<h1>管理仪表盘</h1>
|
||||
<div class="stats-grid">
|
||||
<div class="card stat-card"><h3>{{ stats.totalUsers }}</h3><p>用户数</p></div>
|
||||
<div class="card stat-card"><h3>{{ stats.totalConsultants }}</h3><p>咨询师</p></div>
|
||||
<div class="card stat-card"><h3>{{ stats.totalAppointments }}</h3><p>总预约</p></div>
|
||||
<div class="card stat-card"><h3>{{ stats.pendingAppointments }}</h3><p>待确认</p></div>
|
||||
<div class="card stat-card"><h3>{{ stats.totalBranches }}</h3><p>网点</p></div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import http from '@/utils/request'
|
||||
|
||||
const stats = ref<any>({})
|
||||
onMounted(async () => { const r = await http.get('/admin/dashboard'); stats.value = r.data })
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
h1 { margin-bottom: 1.5rem; }
|
||||
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1rem; }
|
||||
.stat-card { text-align: center; }
|
||||
.stat-card h3 { font-size: 2rem; color: var(--primary); }
|
||||
.stat-card p { color: var(--gray-500); }
|
||||
</style>
|
||||
32
example-project/frontend/src/views/admin/Users.vue
Normal file
32
example-project/frontend/src/views/admin/Users.vue
Normal file
@@ -0,0 +1,32 @@
|
||||
<template>
|
||||
<div>
|
||||
<h1>用户管理</h1>
|
||||
<div v-if="loading">加载中...</div>
|
||||
<table v-else class="table"><thead><tr><th>邮箱</th><th>姓名</th><th>手机</th><th>角色</th><th>状态</th><th>操作</th></tr></thead>
|
||||
<tbody><tr v-for="u in users" :key="u.id"><td>{{ u.email }}</td><td>{{ u.name }}</td><td>{{ u.phone }}</td>
|
||||
<td>{{ u.role }}</td><td :class="u.status === 'ACTIVE' ? 'active' : 'disabled'">{{ u.status }}</td>
|
||||
<td><button class="btn btn-sm" :class="u.status === 'ACTIVE' ? 'btn-danger' : 'btn-primary'" @click="toggle(u.id)">{{ u.status === 'ACTIVE' ? '禁用' : '启用' }}</button></td>
|
||||
</tr></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import http from '@/utils/request'
|
||||
import type { User } from '@/types'
|
||||
|
||||
const users = ref<User[]>([]); const loading = ref(true)
|
||||
async function toggle(id: string) { await http.put(`/admin/users/${id}/toggle-status`); await fetch() }
|
||||
async function fetch() { loading.value = true; try { const r = await http.get('/admin/users'); users.value = r.data } finally { loading.value = false } }
|
||||
onMounted(fetch)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
h1 { margin-bottom: 1rem; }
|
||||
.table { width: 100%; border-collapse: collapse; }
|
||||
.table th, .table td { text-align: left; padding: 0.75rem; border-bottom: 1px solid var(--gray-200); }
|
||||
.active { color: #16a34a; font-weight: 500; }
|
||||
.disabled { color: #dc2626; font-weight: 500; }
|
||||
.btn-sm { padding: 0.25rem 0.75rem; font-size: 0.8125rem; }
|
||||
</style>
|
||||
46
example-project/frontend/src/views/auth/Login.vue
Normal file
46
example-project/frontend/src/views/auth/Login.vue
Normal file
@@ -0,0 +1,46 @@
|
||||
<template>
|
||||
<div class="auth-page">
|
||||
<div class="card auth-card">
|
||||
<h2>登录</h2>
|
||||
<form @submit.prevent="handleLogin">
|
||||
<div class="form-group"><label>邮箱</label><input v-model="email" type="email" class="input" required placeholder="请输入邮箱" /></div>
|
||||
<div class="form-group"><label>密码</label><input v-model="password" type="password" class="input" required placeholder="请输入密码" /></div>
|
||||
<p v-if="error" class="error">{{ error }}</p>
|
||||
<button type="submit" class="btn btn-primary" style="width:100%" :disabled="loading">{{ loading ? '登录中...' : '登录' }}</button>
|
||||
</form>
|
||||
<p class="switch">还没有账号?<router-link to="/register">立即注册</router-link></p>
|
||||
<router-link to="/" class="back-link">← 返回首页</router-link>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
const auth = useAuthStore()
|
||||
const router = useRouter()
|
||||
const email = ref('')
|
||||
const password = ref('')
|
||||
const error = ref('')
|
||||
const loading = ref(false)
|
||||
|
||||
async function handleLogin() {
|
||||
error.value = ''; loading.value = true
|
||||
try {
|
||||
await auth.login(email.value, password.value)
|
||||
router.push(auth.isAdmin ? '/admin/dashboard' : '/user/dashboard')
|
||||
} catch (e: any) { error.value = e.response?.data?.errorMessage || '登录失败' }
|
||||
finally { loading.value = false }
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.auth-page { display: flex; justify-content: center; align-items: center; min-height: 100vh; background: var(--gray-50); }
|
||||
.auth-card { width: 100%; max-width: 400px; }
|
||||
.auth-card h2 { text-align: center; margin-bottom: 1.5rem; }
|
||||
.error { color: var(--danger); font-size: 0.875rem; margin-bottom: 0.5rem; }
|
||||
.switch { text-align: center; margin-top: 1rem; font-size: 0.875rem; color: var(--gray-500); }
|
||||
.back-link { display: block; text-align: center; margin-top: 0.5rem; font-size: 0.875rem; }
|
||||
</style>
|
||||
44
example-project/frontend/src/views/auth/Register.vue
Normal file
44
example-project/frontend/src/views/auth/Register.vue
Normal file
@@ -0,0 +1,44 @@
|
||||
<template>
|
||||
<div class="auth-page">
|
||||
<div class="card auth-card">
|
||||
<h2>注册</h2>
|
||||
<form @submit.prevent="handleRegister">
|
||||
<div class="form-group"><label>姓名</label><input v-model="name" class="input" required placeholder="请输入姓名" /></div>
|
||||
<div class="form-group"><label>邮箱</label><input v-model="email" type="email" class="input" required placeholder="请输入邮箱" /></div>
|
||||
<div class="form-group"><label>手机号</label><input v-model="phone" class="input" placeholder="选填" /></div>
|
||||
<div class="form-group"><label>密码(至少8位)</label><input v-model="password" type="password" class="input" required minlength="8" placeholder="请输入密码" /></div>
|
||||
<p v-if="error" class="error">{{ error }}</p>
|
||||
<button type="submit" class="btn btn-primary" style="width:100%" :disabled="loading">{{ loading ? '注册中...' : '注册' }}</button>
|
||||
</form>
|
||||
<p class="switch">已有账号?<router-link to="/login">立即登录</router-link></p>
|
||||
<router-link to="/" class="back-link">← 返回首页</router-link>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
const auth = useAuthStore()
|
||||
const router = useRouter()
|
||||
const name = ref(''); const email = ref(''); const phone = ref(''); const password = ref('')
|
||||
const error = ref(''); const loading = ref(false)
|
||||
|
||||
async function handleRegister() {
|
||||
error.value = ''; loading.value = true
|
||||
try { await auth.register(email.value, password.value, name.value, phone.value); router.push('/user/dashboard') }
|
||||
catch (e: any) { error.value = e.response?.data?.errorMessage || '注册失败' }
|
||||
finally { loading.value = false }
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.auth-page { display: flex; justify-content: center; align-items: center; min-height: 100vh; background: var(--gray-50); }
|
||||
.auth-card { width: 100%; max-width: 400px; }
|
||||
.auth-card h2 { text-align: center; margin-bottom: 1.5rem; }
|
||||
.error { color: var(--danger); font-size: 0.875rem; }
|
||||
.switch { text-align: center; margin-top: 1rem; font-size: 0.875rem; color: var(--gray-500); }
|
||||
.back-link { display: block; text-align: center; margin-top: 0.5rem; font-size: 0.875rem; }
|
||||
</style>
|
||||
39
example-project/frontend/src/views/home/HomePage.vue
Normal file
39
example-project/frontend/src/views/home/HomePage.vue
Normal file
@@ -0,0 +1,39 @@
|
||||
<template>
|
||||
<div>
|
||||
<AppHeader />
|
||||
<section class="hero">
|
||||
<div class="container hero-content">
|
||||
<h1>{{ info.title }}</h1>
|
||||
<p>{{ info.description }}</p>
|
||||
<div class="hero-actions">
|
||||
<router-link v-if="!auth.isLoggedIn" to="/register" class="btn btn-primary btn-lg">免费注册</router-link>
|
||||
<router-link to="/user/book" class="btn btn-secondary btn-lg">立即预约</router-link>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<footer class="footer"><div class="container"><p>© 2026 咨询预约平台</p></div></footer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import AppHeader from '@/components/layout/AppHeader.vue'
|
||||
import http from '@/utils/request'
|
||||
|
||||
const auth = useAuthStore()
|
||||
const info = ref({ title: '', description: '' })
|
||||
onMounted(async () => {
|
||||
try { const r = await http.get('/home/info'); info.value = r.data } catch {}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.hero { background: linear-gradient(135deg, var(--primary), var(--primary-light)); color: white; padding: 4rem 0; }
|
||||
.hero-content { text-align: center; }
|
||||
.hero h1 { font-size: 2.5rem; margin-bottom: 1rem; }
|
||||
.hero p { font-size: 1.125rem; opacity: 0.9; max-width: 600px; margin: 0 auto 2rem; }
|
||||
.hero-actions { display: flex; gap: 1rem; justify-content: center; }
|
||||
.btn-lg { padding: 0.75rem 2rem; font-size: 1rem; }
|
||||
.footer { background: var(--gray-800); color: var(--gray-400); padding: 2rem 0; text-align: center; }
|
||||
</style>
|
||||
96
example-project/frontend/src/views/user/BookAppointment.vue
Normal file
96
example-project/frontend/src/views/user/BookAppointment.vue
Normal file
@@ -0,0 +1,96 @@
|
||||
<template>
|
||||
<div>
|
||||
<h1>预约咨询</h1>
|
||||
<div class="booking-steps">
|
||||
<div class="card step">
|
||||
<h3>1. 选择咨询师</h3>
|
||||
<div class="consultant-list">
|
||||
<div v-for="c in consultants" :key="c.id" class="consultant-option"
|
||||
:class="{ selected: selectedConsultant === c.id }" @click="pickConsultant(c.id)">
|
||||
<strong>{{ c.name }}</strong> <p>{{ c.title }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="selectedConsultant" class="card step">
|
||||
<h3>2. 选择日期</h3>
|
||||
<div class="date-list">
|
||||
<button v-for="d in dates" :key="d" class="btn"
|
||||
:class="selectedDate === d ? 'btn-primary' : 'btn-secondary'" @click="pickDate(d)">{{ d }}</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="selectedDate && slots.length" class="card step">
|
||||
<h3>3. 选择时间</h3>
|
||||
<div class="slot-list">
|
||||
<button v-for="s in slots" :key="s.startTime" class="btn"
|
||||
:class="selectedSlot === s.startTime ? 'btn-primary' : 'btn-secondary'"
|
||||
@click="selectedSlot = s.startTime">{{ s.startTime }}-{{ s.endTime }}</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="selectedSlot" class="card step">
|
||||
<h3>4. 备注</h3>
|
||||
<textarea v-model="note" class="input" rows="3" placeholder="描述您的问题..."></textarea>
|
||||
<button class="btn btn-primary" style="margin-top:1rem" @click="submit" :disabled="submitting">
|
||||
{{ submitting ? '提交中...' : '确认预约' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, watch } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import http from '@/utils/request'
|
||||
import { getWeekDates } from '@/utils/date'
|
||||
import type { Consultant, TimeSlot } from '@/types'
|
||||
|
||||
const router = useRouter()
|
||||
const auth = useAuthStore()
|
||||
if (!auth.isLoggedIn) router.push('/login')
|
||||
|
||||
const consultants = ref<Consultant[]>([])
|
||||
const selectedConsultant = ref('')
|
||||
const selectedDate = ref('')
|
||||
const selectedSlot = ref('')
|
||||
const note = ref('')
|
||||
const slots = ref<TimeSlot[]>([])
|
||||
const dates = getWeekDates()
|
||||
const submitting = ref(false)
|
||||
|
||||
onMounted(async () => { const r = await http.get('/consultants'); consultants.value = r.data })
|
||||
|
||||
watch(selectedConsultant, () => { selectedDate.value = ''; selectedSlot.value = ''; slots.value = [] })
|
||||
watch(selectedDate, async (d) => {
|
||||
if (!d) return; selectedSlot.value = ''
|
||||
const r = await http.get(`/consultants/${selectedConsultant.value}/slots`, { params: { date: d } }); slots.value = r.data
|
||||
})
|
||||
|
||||
function pickConsultant(id: string) { selectedConsultant.value = id }
|
||||
function pickDate(d: string) { selectedDate.value = d }
|
||||
|
||||
async function submit() {
|
||||
submitting.value = true
|
||||
try {
|
||||
await http.post('/appointments', {
|
||||
consultantId: selectedConsultant.value, date: selectedDate.value,
|
||||
startTime: selectedSlot.value,
|
||||
endTime: `${String(Number(selectedSlot.value.split(':')[0]) + 1).padStart(2, '0')}:00`,
|
||||
note: note.value,
|
||||
})
|
||||
router.push('/user/appointments')
|
||||
} catch (e: any) { alert(e.response?.data?.errorMessage || '预约失败') }
|
||||
finally { submitting.value = false }
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
h1 { margin-bottom: 1.5rem; }
|
||||
.booking-steps { display: flex; flex-direction: column; gap: 1rem; max-width: 600px; }
|
||||
.step h3 { margin-bottom: 0.75rem; }
|
||||
.consultant-list { display: flex; flex-direction: column; gap: 0.5rem; }
|
||||
.consultant-option { padding: 0.75rem; border: 1px solid var(--gray-200); border-radius: 0.375rem; cursor: pointer; }
|
||||
.consultant-option:hover { border-color: var(--primary); }
|
||||
.consultant-option.selected { border-color: var(--primary); background: rgba(79,70,229,0.05); }
|
||||
.date-list, .slot-list { display: flex; flex-wrap: wrap; gap: 0.5rem; }
|
||||
</style>
|
||||
41
example-project/frontend/src/views/user/Dashboard.vue
Normal file
41
example-project/frontend/src/views/user/Dashboard.vue
Normal file
@@ -0,0 +1,41 @@
|
||||
<template>
|
||||
<div>
|
||||
<h1>用户中心</h1>
|
||||
<div class="stats-grid">
|
||||
<div class="card stat-card"><h3>{{ total }}</h3><p>总预约</p></div>
|
||||
<div class="card stat-card"><h3>{{ pending }}</h3><p>待确认</p></div>
|
||||
<div class="card stat-card"><h3>{{ completed }}</h3><p>已完成</p></div>
|
||||
</div>
|
||||
<div class="actions" style="margin-top:1rem">
|
||||
<router-link to="/user/book" class="btn btn-primary">预约咨询</router-link>
|
||||
<router-link to="/user/appointments" class="btn btn-secondary" style="margin-left:0.5rem">我的预约</router-link>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, computed } from 'vue'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { useRouter } from 'vue-router'
|
||||
import http from '@/utils/request'
|
||||
import type { Appointment } from '@/types'
|
||||
|
||||
const router = useRouter()
|
||||
const auth = useAuthStore()
|
||||
if (!auth.isLoggedIn) router.push('/login')
|
||||
|
||||
const appointments = ref<Appointment[]>([])
|
||||
const total = computed(() => appointments.value.length)
|
||||
const pending = computed(() => appointments.value.filter(a => a.status === 'PENDING').length)
|
||||
const completed = computed(() => appointments.value.filter(a => a.status === 'COMPLETED').length)
|
||||
|
||||
onMounted(async () => { const r = await http.get('/appointments'); appointments.value = r.data })
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
h1 { margin-bottom: 1.5rem; }
|
||||
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
|
||||
.stat-card { text-align: center; }
|
||||
.stat-card h3 { font-size: 2rem; color: var(--primary); }
|
||||
.stat-card p { color: var(--gray-500); font-size: 0.875rem; }
|
||||
</style>
|
||||
69
example-project/frontend/src/views/user/MyAppointments.vue
Normal file
69
example-project/frontend/src/views/user/MyAppointments.vue
Normal file
@@ -0,0 +1,69 @@
|
||||
<template>
|
||||
<div>
|
||||
<h1>我的预约</h1>
|
||||
<div v-if="loading">加载中...</div>
|
||||
<div v-else-if="appointments.length === 0" class="empty"><p>暂无预约记录</p><router-link to="/user/book" class="btn btn-primary">预约咨询</router-link></div>
|
||||
<div v-else class="appointment-list">
|
||||
<div v-for="a in appointments" :key="a.id" class="card appointment-card">
|
||||
<div>
|
||||
<span class="status" :class="a.status.toLowerCase()">{{ label(a.status) }}</span>
|
||||
<p class="date">{{ a.appointmentDate }} {{ a.startTime }}-{{ a.endTime }}</p>
|
||||
<p class="meta">咨询师ID: {{ a.consultantId.substring(0,8) }}... | 时长: {{ a.durationMinutes }}分钟</p>
|
||||
<p v-if="a.note" class="note">备注: {{ a.note }}</p>
|
||||
<p v-if="a.cancelReason" class="cancel">取消原因: {{ a.cancelReason }}</p>
|
||||
</div>
|
||||
<button v-if="a.status === 'PENDING' || a.status === 'CONFIRMED'" class="btn btn-danger btn-sm" @click="doCancel(a.id)">取消</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { useRouter } from 'vue-router'
|
||||
import http from '@/utils/request'
|
||||
import type { Appointment } from '@/types'
|
||||
|
||||
const router = useRouter()
|
||||
const auth = useAuthStore()
|
||||
if (!auth.isLoggedIn) router.push('/login')
|
||||
|
||||
const appointments = ref<Appointment[]>([])
|
||||
const loading = ref(true)
|
||||
|
||||
function label(s: string) {
|
||||
const m: Record<string, string> = { PENDING: '待确认', CONFIRMED: '已确认', COMPLETED: '已完成', CANCELLED: '已取消' }
|
||||
return m[s] || s
|
||||
}
|
||||
|
||||
async function doCancel(id: string) {
|
||||
if (!confirm('确定取消?')) return
|
||||
await http.put(`/appointments/${id}/cancel`, { reason: '用户取消' })
|
||||
await fetch()
|
||||
}
|
||||
|
||||
async function fetch() {
|
||||
loading.value = true
|
||||
try { const r = await http.get('/appointments'); appointments.value = r.data } finally { loading.value = false }
|
||||
}
|
||||
|
||||
onMounted(fetch)
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
h1 { margin-bottom: 1.5rem; }
|
||||
.empty { text-align: center; padding: 3rem; color: var(--gray-500); }
|
||||
.appointment-list { display: flex; flex-direction: column; gap: 1rem; }
|
||||
.appointment-card { display: flex; justify-content: space-between; align-items: flex-start; }
|
||||
.status { display: inline-block; padding: 0.125rem 0.5rem; border-radius: 1rem; font-size: 0.75rem; font-weight: 500; margin-bottom: 0.5rem; }
|
||||
.pending { background: #FEF3C7; color: #92400E; }
|
||||
.confirmed { background: #DBEAFE; color: #1E40AF; }
|
||||
.completed { background: #D1FAE5; color: #065F46; }
|
||||
.cancelled { background: #FEE2E2; color: #991B1B; }
|
||||
.date { font-weight: 600; }
|
||||
.meta { font-size: 0.875rem; color: var(--gray-500); }
|
||||
.note { font-size: 0.875rem; color: var(--gray-600); }
|
||||
.cancel { font-size: 0.875rem; color: var(--danger); }
|
||||
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8125rem; }
|
||||
</style>
|
||||
56
example-project/frontend/src/views/user/Profile.vue
Normal file
56
example-project/frontend/src/views/user/Profile.vue
Normal file
@@ -0,0 +1,56 @@
|
||||
<template>
|
||||
<div>
|
||||
<h1>个人信息</h1>
|
||||
<div class="card" style="max-width:500px">
|
||||
<div class="form-group"><label>邮箱</label><input :value="auth.user?.email" class="input" disabled /></div>
|
||||
<div class="form-group"><label>姓名</label><input v-model="name" class="input" /></div>
|
||||
<div class="form-group"><label>手机号</label><input v-model="phone" class="input" /></div>
|
||||
<p v-if="err" class="error">{{ err }}</p>
|
||||
<button class="btn btn-primary" @click="save" :disabled="saving">{{ saving ? '保存中...' : '保存' }}</button>
|
||||
</div>
|
||||
<h2 style="margin-top:2rem">修改密码</h2>
|
||||
<div class="card" style="max-width:500px">
|
||||
<div class="form-group"><label>原密码</label><input v-model="oldPw" type="password" class="input" /></div>
|
||||
<div class="form-group"><label>新密码</label><input v-model="newPw" type="password" class="input" minlength="8" /></div>
|
||||
<p v-if="pwErr" class="error">{{ pwErr }}</p>
|
||||
<button class="btn btn-primary" @click="changePw" :disabled="changing">{{ changing ? '修改中...' : '修改密码' }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { useRouter } from 'vue-router'
|
||||
import http from '@/utils/request'
|
||||
|
||||
const router = useRouter()
|
||||
const auth = useAuthStore()
|
||||
if (!auth.isLoggedIn) router.push('/login')
|
||||
|
||||
const name = ref(auth.user?.name || '')
|
||||
const phone = ref(auth.user?.phone || '')
|
||||
const err = ref(''); const saving = ref(false)
|
||||
const oldPw = ref(''); const newPw = ref(''); const pwErr = ref(''); const changing = ref(false)
|
||||
|
||||
async function save() {
|
||||
saving.value = true; err.value = ''
|
||||
try { const r = await http.put('/users/me', { name: name.value, phone: phone.value }); auth.user = r.data; localStorage.setItem('user', JSON.stringify(r.data)); alert('保存成功') }
|
||||
catch (e: any) { err.value = e.response?.data?.errorMessage || '保存失败' }
|
||||
finally { saving.value = false }
|
||||
}
|
||||
|
||||
async function changePw() {
|
||||
if (newPw.value.length < 8) { pwErr.value = '密码至少8位'; return }
|
||||
changing.value = true; pwErr.value = ''
|
||||
try { await http.put('/users/me/password', { oldPassword: oldPw.value, newPassword: newPw.value }); alert('密码修改成功'); oldPw.value = ''; newPw.value = '' }
|
||||
catch (e: any) { pwErr.value = e.response?.data?.errorMessage || '修改失败' }
|
||||
finally { changing.value = false }
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
h1 { margin-bottom: 1.5rem; } h2 { margin-bottom: 1rem; }
|
||||
.card { margin-bottom: 1rem; }
|
||||
.error { color: var(--danger); font-size: 0.875rem; margin-bottom: 0.5rem; }
|
||||
</style>
|
||||
18
example-project/frontend/tsconfig.app.json
Normal file
18
example-project/frontend/tsconfig.app.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"target": "ES2020",
|
||||
"module": "ESNext",
|
||||
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
||||
"skipLibCheck": true,
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"isolatedModules": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
"jsx": "preserve",
|
||||
"strict": true,
|
||||
"paths": { "@/*": ["./src/*"] }
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.vue"]
|
||||
}
|
||||
7
example-project/frontend/tsconfig.json
Normal file
7
example-project/frontend/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "./tsconfig.app.json" },
|
||||
{ "path": "./tsconfig.node.json" }
|
||||
]
|
||||
}
|
||||
12
example-project/frontend/tsconfig.node.json
Normal file
12
example-project/frontend/tsconfig.node.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"skipLibCheck": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"noEmit": true,
|
||||
"types": ["node"]
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
||||
9
example-project/frontend/vite.config.ts
Normal file
9
example-project/frontend/vite.config.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import { resolve } from 'path'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
resolve: { alias: { '@': resolve(__dirname, 'src') } },
|
||||
server: { port: 5173, proxy: { '/api': { target: 'http://localhost:8080', changeOrigin: true } } },
|
||||
})
|
||||
Reference in New Issue
Block a user