Initial template: Vue 3 + FastAPI + SQLite full-stack with K8s deployment
Some checks failed
Deploy Production / test (push) Failing after 1s
Deploy Production / deploy (push) Has been skipped
Test / unit-test (push) Failing after 1s
Test / e2e-test (push) Has been skipped
Test / build-check (push) Failing after 1s

Extracted from oil project — business logic removed, auth/db/deploy infrastructure
generalized with APP_NAME placeholders.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-06 22:13:06 +00:00
commit d19183923c
32 changed files with 1350 additions and 0 deletions

41
frontend/src/App.vue Normal file
View File

@@ -0,0 +1,41 @@
<template>
<div class="app">
<header class="app-header">
<div class="header-inner">
<h1 class="header-title">App</h1>
<nav class="nav-tabs">
<router-link
v-for="tab in tabs"
:key="tab.to"
:to="tab.to"
class="nav-tab"
active-class="active"
>{{ tab.label }}</router-link>
</nav>
<div class="header-right">
<template v-if="auth.isLoggedIn">
<span class="user-name">{{ auth.user.display_name || auth.user.username }}</span>
<button class="btn-link" @click="auth.logout()">退出</button>
</template>
<template v-else>
<router-link to="/login" class="btn-link">登录</router-link>
</template>
</div>
</div>
</header>
<main class="app-main">
<router-view />
</main>
</div>
</template>
<script setup>
import { useAuthStore } from './stores/auth'
const auth = useAuthStore()
auth.initToken()
const tabs = [
{ to: '/', label: '首页' },
]
</script>

View File

@@ -0,0 +1,149 @@
/* ── Design tokens ─────────────────────────────────── */
:root {
--color-primary: #4a7c59;
--color-primary-dark: #3a6349;
--color-accent: #c9a84c;
--color-bg: #faf6f0;
--color-bg-card: #ffffff;
--color-text: #333333;
--color-text-muted: #888888;
--color-border: #e0d8cc;
--color-danger: #d32f2f;
--shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
--shadow-md: 0 2px 8px rgba(0, 0, 0, 0.12);
--radius: 8px;
--font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', sans-serif;
}
/* ── Reset ────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: var(--font-sans);
background: var(--color-bg);
color: var(--color-text);
line-height: 1.6;
}
/* ── Layout ───────────────────────────────────────── */
.app-header {
background: var(--color-primary);
color: white;
padding: 12px 20px;
}
.header-inner {
max-width: 1200px;
margin: 0 auto;
display: flex;
align-items: center;
gap: 20px;
}
.header-title {
font-size: 18px;
font-weight: 600;
white-space: nowrap;
}
.nav-tabs {
display: flex;
gap: 4px;
flex: 1;
}
.nav-tab {
padding: 6px 14px;
border-radius: var(--radius);
color: rgba(255, 255, 255, 0.8);
text-decoration: none;
font-size: 14px;
transition: background 0.2s;
}
.nav-tab:hover { background: rgba(255, 255, 255, 0.15); }
.nav-tab.active { background: rgba(255, 255, 255, 0.25); color: white; }
.header-right {
display: flex;
align-items: center;
gap: 10px;
font-size: 14px;
white-space: nowrap;
}
.app-main {
max-width: 1200px;
margin: 20px auto;
padding: 0 20px;
}
/* ── Components ───────────────────────────────────── */
.page { padding: 20px 0; }
.btn-primary {
background: var(--color-primary);
color: white;
border: none;
padding: 8px 20px;
border-radius: var(--radius);
cursor: pointer;
font-size: 14px;
}
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-link {
background: none;
border: none;
color: inherit;
cursor: pointer;
text-decoration: underline;
font-size: inherit;
}
.form-group {
margin-bottom: 14px;
}
.form-group label {
display: block;
font-size: 14px;
margin-bottom: 4px;
color: var(--color-text-muted);
}
.form-group input {
width: 100%;
padding: 8px 12px;
border: 1px solid var(--color-border);
border-radius: var(--radius);
font-size: 14px;
}
.error { color: var(--color-danger); font-size: 13px; }
.card {
background: var(--color-bg-card);
border-radius: var(--radius);
box-shadow: var(--shadow-sm);
padding: 16px;
}
.toast {
position: fixed;
top: 20px;
right: 20px;
background: #333;
color: white;
padding: 10px 20px;
border-radius: var(--radius);
z-index: 9999;
font-size: 14px;
}
/* ── Responsive ───────────────────────────────────── */
@media (max-width: 640px) {
.header-inner { flex-wrap: wrap; }
.nav-tabs { order: 3; width: 100%; overflow-x: auto; }
}

View File

@@ -0,0 +1,51 @@
const API_BASE = '' // same origin, uses vite proxy in dev
export function getToken() {
return localStorage.getItem('auth_token') || ''
}
export function setToken(token) {
if (token) localStorage.setItem('auth_token', token)
else localStorage.removeItem('auth_token')
}
function buildHeaders(extra = {}) {
const headers = { 'Content-Type': 'application/json', ...extra }
const token = getToken()
if (token) headers['Authorization'] = 'Bearer ' + token
return headers
}
async function request(path, opts = {}) {
const headers = buildHeaders(opts.headers)
const res = await fetch(API_BASE + path, { ...opts, headers })
return res
}
async function requestJSON(path, opts = {}) {
const res = await request(path, opts)
if (!res.ok) {
let msg = `${res.status}`
try {
const body = await res.json()
msg = body.detail || body.message || msg
} catch {}
const err = new Error(msg)
err.status = res.status
throw err
}
return res.json()
}
function apiFn(path, opts = {}) {
return request(path, opts)
}
apiFn.raw = request
apiFn.get = (path) => requestJSON(path)
apiFn.post = (path, body) => requestJSON(path, { method: 'POST', body: JSON.stringify(body) })
apiFn.put = (path, body) => requestJSON(path, { method: 'PUT', body: JSON.stringify(body) })
apiFn.del = (path) => requestJSON(path, { method: 'DELETE' })
apiFn.delete = (path) => requestJSON(path, { method: 'DELETE' })
export const api = apiFn

10
frontend/src/main.js Normal file
View File

@@ -0,0 +1,10 @@
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import router from './router'
import './assets/styles.css'
const app = createApp(App)
app.use(createPinia())
app.use(router)
app.mount('#app')

View File

@@ -0,0 +1,21 @@
import { createRouter, createWebHistory } from 'vue-router'
const routes = [
{
path: '/',
name: 'Home',
component: () => import('../views/Home.vue'),
},
{
path: '/login',
name: 'Login',
component: () => import('../views/Login.vue'),
},
]
const router = createRouter({
history: createWebHistory(),
routes,
})
export default router

View File

@@ -0,0 +1,80 @@
import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import { api, setToken } from '../composables/useApi'
const DEFAULT_USER = {
id: null,
role: 'viewer',
username: 'anonymous',
display_name: '匿名',
}
export const useAuthStore = defineStore('auth', () => {
const token = ref(localStorage.getItem('auth_token') || '')
const user = ref({ ...DEFAULT_USER })
const isLoggedIn = computed(() => user.value.id !== null)
const isAdmin = computed(() => user.value.role === 'admin')
const canEdit = computed(() =>
['editor', 'admin'].includes(user.value.role)
)
async function initToken() {
const params = new URLSearchParams(window.location.search)
const urlToken = params.get('token')
if (urlToken) {
token.value = urlToken
setToken(urlToken)
const url = new URL(window.location)
url.searchParams.delete('token')
window.history.replaceState({}, '', url)
}
if (token.value) {
await loadMe()
}
}
async function loadMe() {
try {
const data = await api.get('/api/me')
user.value = {
id: data.id,
role: data.role,
username: data.username,
display_name: data.display_name,
}
} catch {
logout()
}
}
async function login(username, password) {
const data = await api.post('/api/login', { username, password })
token.value = data.token
setToken(data.token)
await loadMe()
}
async function register(username, password, displayName) {
const data = await api.post('/api/register', {
username,
password,
display_name: displayName,
})
token.value = data.token
setToken(data.token)
await loadMe()
}
function logout() {
token.value = ''
setToken(null)
user.value = { ...DEFAULT_USER }
}
return {
token, user,
isLoggedIn, isAdmin, canEdit,
initToken, loadMe, login, register, logout,
}
})

View File

@@ -0,0 +1,6 @@
<template>
<div class="page">
<h2>Welcome</h2>
<p>App is running.</p>
</div>
</template>

View File

@@ -0,0 +1,39 @@
<template>
<div class="page login-page">
<h2>登录</h2>
<form @submit.prevent="handleLogin">
<div class="form-group">
<label>用户名</label>
<input v-model="username" required />
</div>
<div class="form-group">
<label>密码</label>
<input v-model="password" type="password" required />
</div>
<p v-if="error" class="error">{{ error }}</p>
<button type="submit" class="btn-primary">登录</button>
</form>
</div>
</template>
<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { useAuthStore } from '../stores/auth'
const auth = useAuthStore()
const router = useRouter()
const username = ref('')
const password = ref('')
const error = ref('')
async function handleLogin() {
error.value = ''
try {
await auth.login(username.value, password.value)
router.push('/')
} catch (e) {
error.value = e.message
}
}
</script>