Files
paper-doc/frontend/src/views/HomeView.vue
T
govin 199e328b48 refactor: call a heading a title, and its use a placement
`template_field_library` and `template_field` were one word apart and meant
opposite kinds of thing — a catalogue of rows versus one row — and neither name
said what a row actually is. Every row of the library is a **heading**: a piece
of text like 「1. Introduction」 with a level and typography, which is what the
reader sees at the top of a paragraph; and every row of the join table is that
heading *placed* in a template, `sort` included.

    template_field_library  -> template_title
    template_field          -> template_title_placement
    field_id (the column)   -> title_id
    TemplateFieldLibrary    -> TemplateTitle
    TemplateField           -> TemplateTitlePlacement

The join table keeps its own name rather than becoming `_link`, because it is
not a bare link: it carries `sort`, the only place display order is stored, and
it deliberately allows the same title twice in one template. `_link` would
describe two foreign keys and hide the column the ordering rule rests on.

Carried through every level, because a half-renamed layer is how the confusing
pair got there in the first place: HTTP paths (`/template-field-library` ->
`/template-titles`), the template payload (`fields`/`field_id` ->
`placements`/`title_id`, and `field_count` -> `placement_count`), the Pydantic
schemas, the CRUD modules, the seed script, the frontend API module and types,
and `docs/OVERVIEW.md`, which now states the naming rules outright.

Two deliberate exceptions:

* `paper_template_filed_sort` is untouched — it is a column of the paper module
  and is spelled as the feature was specified.
* The MCP tools keep their agent-facing names (`field_list`, `field_ids`, and
  the `fields`/`field_id` keys in their responses). Agents already call them by
  those names; the storage names they read underneath have changed.

The migration renames in place (data preserved: 4 templates, 45 titles, 63
placements) and is written to tolerate a database where part of it already ran,
which is not hypothetical — the first attempt renamed the tables and then failed
on the column, because Alembic's MySQL dialect wants an explicit type for
`alter_column` and will not rename a column without one. TiDB carries the
foreign key along with both the renamed table and the renamed column, rehearsed
against the cluster first, and it stays enforced.

Verified: seed re-runs clean, the paper smoke test's 45 checks and the MCP
smoke test's 47 pass, `vue-tsc` and the build are clean, and the UI was driven
in a headless browser through the template list, its preview drawer, the title
library page, the template form (which now posts `placements` with `title_id`)
and the paper document with no console errors.
2026-09-22 16:55:02 +08:00

241 lines
6.0 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
/**
* Welcome page.
*
* Shown before either section is opened, so it does two jobs: greet, and offer
* the two ways in. The counts underneath come from the same endpoints the
* section pages use, which makes this page double as a connectivity check —
* if the numbers are there, the API and TiDB are up.
*/
import { onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import { Files, Notebook, Setting } from '@element-plus/icons-vue'
import { listPapers } from '@/api/papers'
import { listTemplateTitle } from '@/api/templateTitles'
import { listTemplates } from '@/api/templates'
import AppLogo from '@/components/AppLogo.vue'
const router = useRouter()
const paperCount = ref<number | null>(null)
const templateCount = ref<number | null>(null)
const titleCount = ref<number | null>(null)
/** `null` renders as an em dash: unknown, not zero. */
function display(value: number | null): string {
return value === null ? '—' : String(value)
}
onMounted(async () => {
// `page_size: 1` because only `total` is used. A failure leaves the count as
// an em dash rather than blocking the page.
const [papers, templates, titles] = await Promise.allSettled([
listPapers({ page: 1, page_size: 1 }),
listTemplates({ page: 1, page_size: 1 }),
listTemplateTitle({ page: 1, page_size: 1 }),
])
if (papers.status === 'fulfilled') paperCount.value = papers.value.total
if (templates.status === 'fulfilled') templateCount.value = templates.value.total
if (titles.status === 'fulfilled') titleCount.value = titles.value.total
})
</script>
<template>
<div class="page welcome">
<section class="hero">
<span class="hero-mark"><AppLogo :size="40" /></span>
<h1 class="hero-title">欢迎访问</h1>
<p class="hero-subtitle">先配置好论文模板,写作时只需对着结构填内容。</p>
</section>
<section class="entries">
<button type="button" class="entry" @click="router.push('/papers')">
<el-icon class="entry-icon"><Notebook /></el-icon>
<span class="entry-title">论文</span>
<span class="entry-desc">按模板逐段撰写与管理论文</span>
<el-tag size="small" type="success" effect="plain">
{{ display(paperCount) }} 篇
</el-tag>
</button>
<button type="button" class="entry" @click="router.push('/templates')">
<el-icon class="entry-icon"><Files /></el-icon>
<span class="entry-title">模板</span>
<span class="entry-desc">维护模板列表与可复用的段落字段</span>
<el-tag size="small" type="success" effect="plain">
{{ display(templateCount) }} 个模板
</el-tag>
</button>
</section>
<el-card shadow="never" class="stats">
<div class="stat">
<el-icon class="stat-icon"><Notebook /></el-icon>
<div>
<div class="stat-value">{{ display(paperCount) }}</div>
<div class="stat-label">论文</div>
</div>
</div>
<el-divider direction="vertical" class="stat-divider" />
<div class="stat">
<el-icon class="stat-icon"><Setting /></el-icon>
<div>
<div class="stat-value">{{ display(titleCount) }}</div>
<div class="stat-label">字段库</div>
</div>
</div>
<el-divider direction="vertical" class="stat-divider" />
<div class="stat">
<el-icon class="stat-icon"><Files /></el-icon>
<div>
<div class="stat-value">{{ display(templateCount) }}</div>
<div class="stat-label">模板</div>
</div>
</div>
<div class="stat-hint">
字段可以自由组合进模板,显示顺序完全由每个字段的 sort 决定;论文按模板的段落逐句填写,
换模板不会丢内容。
</div>
</el-card>
</div>
</template>
<style scoped>
.welcome {
gap: 24px;
padding-top: 24px;
}
.hero {
display: flex;
flex-direction: column;
align-items: center;
gap: 12px;
text-align: center;
}
.hero-mark {
display: grid;
place-items: center;
width: 76px;
height: 76px;
border-radius: 22px;
color: #fff;
background-image: linear-gradient(135deg, var(--el-color-primary), #7c5cff);
box-shadow: 0 10px 24px rgb(64 158 255 / 28%);
}
.hero-title {
margin: 4px 0 0;
font-size: 30px;
font-weight: 650;
letter-spacing: 0.02em;
}
.hero-subtitle {
margin: 0;
color: var(--el-text-color-secondary);
font-size: 14px;
}
.entries {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
gap: 16px;
max-width: 720px;
width: 100%;
margin: 0 auto;
}
/* A button, not a div: these navigate, so they belong in the tab order and
respond to Enter and Space for free. */
.entry {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 8px;
padding: 20px;
font: inherit;
text-align: left;
cursor: pointer;
background-color: var(--el-bg-color);
border: 1px solid var(--el-border-color);
border-radius: 12px;
transition:
border-color 0.2s ease,
box-shadow 0.2s ease,
transform 0.2s ease;
}
.entry:hover,
.entry:focus-visible {
border-color: var(--el-color-primary);
box-shadow: 0 6px 18px rgb(0 0 0 / 8%);
transform: translateY(-2px);
outline: none;
}
.entry-icon {
font-size: 24px;
color: var(--el-color-primary);
}
.entry-title {
font-size: 18px;
font-weight: 600;
}
.entry-desc {
color: var(--el-text-color-secondary);
font-size: 13px;
}
.stats {
max-width: 720px;
width: 100%;
margin: 0 auto;
}
.stats :deep(.el-card__body) {
display: flex;
align-items: center;
gap: 24px;
width: 100%;
flex-wrap: wrap;
}
.stat {
display: flex;
align-items: center;
gap: 12px;
}
.stat-icon {
font-size: 20px;
color: var(--el-color-primary);
}
.stat-value {
font-size: 22px;
font-weight: 650;
line-height: 1.1;
}
.stat-label {
color: var(--el-text-color-secondary);
font-size: 12px;
}
.stat-divider {
height: 32px;
}
.stat-hint {
flex: 1 1 220px;
color: var(--el-text-color-secondary);
font-size: 12px;
line-height: 1.6;
}
</style>