199e328b48
`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.
97 lines
2.4 KiB
Vue
97 lines
2.4 KiB
Vue
<script setup lang="ts">
|
|
/**
|
|
* Read-only rendering of a template's outline.
|
|
*
|
|
* This is where the ordering contract becomes visible: the rows are painted in
|
|
* the order the API returned them, which is ascending `sort`, and each name is
|
|
* drawn at its own font size and colour. The `sort` value is shown alongside so
|
|
* the order can be checked against the numbers rather than taken on trust.
|
|
*/
|
|
import type { TemplateTitlePlacement } from '@/api/templates'
|
|
import { levelIndent, typographyStyle } from '@/utils/format'
|
|
|
|
withDefaults(
|
|
defineProps<{
|
|
placements: TemplateTitlePlacement[]
|
|
/** Show the sort value and typography under each heading. */
|
|
showMeta?: boolean
|
|
}>(),
|
|
{ showMeta: true },
|
|
)
|
|
</script>
|
|
|
|
<template>
|
|
<div class="outline">
|
|
<el-empty v-if="placements.length === 0" description="这个模板还没有选择任何字段" />
|
|
|
|
<ol v-else class="outline-list">
|
|
<li v-for="field in placements" :key="field.id" class="outline-row">
|
|
<span class="outline-sort">{{ field.sort }}</span>
|
|
<div class="outline-body">
|
|
<div class="outline-name" :style="{ paddingLeft: levelIndent(field.level) }">
|
|
<span :style="typographyStyle(field)">{{ field.name }}</span>
|
|
</div>
|
|
<div v-if="showMeta" class="outline-meta">
|
|
{{ field.level }} 级 · {{ field.font_size }}pt · {{ field.font_color }}
|
|
</div>
|
|
</div>
|
|
</li>
|
|
</ol>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.outline {
|
|
min-width: 0;
|
|
}
|
|
|
|
/* The list is styled as a bare stack: the visual numbering is already inside
|
|
each field's name, so a browser-generated marker would double it. */
|
|
.outline-list {
|
|
list-style: none;
|
|
margin: 0;
|
|
padding: 0;
|
|
}
|
|
|
|
.outline-row {
|
|
display: flex;
|
|
align-items: flex-start;
|
|
gap: 12px;
|
|
padding: 10px 12px;
|
|
border-bottom: 1px solid var(--el-border-color-lighter);
|
|
}
|
|
|
|
.outline-row:last-child {
|
|
border-bottom: none;
|
|
}
|
|
|
|
.outline-sort {
|
|
flex: 0 0 auto;
|
|
min-width: 32px;
|
|
padding: 1px 6px;
|
|
font-size: 12px;
|
|
font-variant-numeric: tabular-nums;
|
|
text-align: center;
|
|
color: var(--el-text-color-secondary);
|
|
background-color: var(--el-fill-color-light);
|
|
border-radius: 4px;
|
|
}
|
|
|
|
.outline-body {
|
|
min-width: 0;
|
|
flex: 1 1 auto;
|
|
}
|
|
|
|
.outline-name {
|
|
min-width: 0;
|
|
overflow-wrap: anywhere;
|
|
line-height: 1.5;
|
|
}
|
|
|
|
.outline-meta {
|
|
margin-top: 2px;
|
|
font-size: 12px;
|
|
color: var(--el-text-color-placeholder);
|
|
}
|
|
</style>
|