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.
This commit is contained in:
@@ -102,8 +102,8 @@ export interface Sentence {
|
||||
/** One paragraph of a paper: its heading and the sentences under it. */
|
||||
export interface PaperParagraph {
|
||||
paper_template_filed_sort: number
|
||||
template_field_id: number | null
|
||||
field_id: number | null
|
||||
placement_id: number | null
|
||||
title_id: number | null
|
||||
/** `null` when the template has no placement here — rendered as 未设定. */
|
||||
name: string | null
|
||||
level: number
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import http from './client'
|
||||
import type { BatchDeleteResult, PageQuery, PageResult } from './types'
|
||||
|
||||
/** Mirrors `app.schemas.template_field_library.TemplateFieldLibraryRead`. */
|
||||
export interface TemplateFieldLibrary {
|
||||
/** Mirrors `app.schemas.template_title.TemplateTitleRead`. */
|
||||
export interface TemplateTitle {
|
||||
id: number
|
||||
/** Display name, numbering included — e.g. `1. Introduction`. */
|
||||
name: string
|
||||
@@ -17,23 +17,23 @@ export interface TemplateFieldLibrary {
|
||||
}
|
||||
|
||||
/** Body for creating or updating a library field. */
|
||||
export interface TemplateFieldLibraryPayload {
|
||||
export interface TemplateTitlePayload {
|
||||
name: string
|
||||
level: number
|
||||
font_size: number
|
||||
font_color: string
|
||||
}
|
||||
|
||||
export interface TemplateFieldLibraryQuery extends PageQuery {
|
||||
export interface TemplateTitleQuery extends PageQuery {
|
||||
level?: number | null
|
||||
}
|
||||
|
||||
/** The API caps `page_size` at 500; 200 keeps responses modest while looping. */
|
||||
const LIBRARY_PAGE_SIZE = 200
|
||||
|
||||
export async function listTemplateFieldLibrary(
|
||||
query: TemplateFieldLibraryQuery = {},
|
||||
): Promise<PageResult<TemplateFieldLibrary>> {
|
||||
export async function listTemplateTitle(
|
||||
query: TemplateTitleQuery = {},
|
||||
): Promise<PageResult<TemplateTitle>> {
|
||||
// Drop empty filters so the URL stays clean and the backend sees "no filter"
|
||||
// rather than `keyword=`.
|
||||
const params: Record<string, unknown> = {}
|
||||
@@ -42,8 +42,8 @@ export async function listTemplateFieldLibrary(
|
||||
if (query.page) params.page = query.page
|
||||
if (query.page_size) params.page_size = query.page_size
|
||||
|
||||
const { data } = await http.get<PageResult<TemplateFieldLibrary>>(
|
||||
'/template-field-library',
|
||||
const { data } = await http.get<PageResult<TemplateTitle>>(
|
||||
'/template-titles',
|
||||
{ params },
|
||||
)
|
||||
return data
|
||||
@@ -55,12 +55,12 @@ export async function listTemplateFieldLibrary(
|
||||
* The template form needs every field, not one page, so that a field placed
|
||||
* deep in the library can still be shown by name in an existing selection.
|
||||
*/
|
||||
export async function fetchAllTemplateFieldLibrary(keyword?: string): Promise<TemplateFieldLibrary[]> {
|
||||
const all: TemplateFieldLibrary[] = []
|
||||
export async function fetchAllTemplateTitle(keyword?: string): Promise<TemplateTitle[]> {
|
||||
const all: TemplateTitle[] = []
|
||||
let page = 1
|
||||
|
||||
for (;;) {
|
||||
const result = await listTemplateFieldLibrary({
|
||||
const result = await listTemplateTitle({
|
||||
keyword,
|
||||
page,
|
||||
page_size: LIBRARY_PAGE_SIZE,
|
||||
@@ -73,29 +73,29 @@ export async function fetchAllTemplateFieldLibrary(keyword?: string): Promise<Te
|
||||
}
|
||||
}
|
||||
|
||||
export async function createTemplateFieldLibrary(
|
||||
payload: TemplateFieldLibraryPayload,
|
||||
): Promise<TemplateFieldLibrary> {
|
||||
const { data } = await http.post<TemplateFieldLibrary>('/template-field-library', payload)
|
||||
export async function createTemplateTitle(
|
||||
payload: TemplateTitlePayload,
|
||||
): Promise<TemplateTitle> {
|
||||
const { data } = await http.post<TemplateTitle>('/template-titles', payload)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function updateTemplateFieldLibrary(
|
||||
export async function updateTemplateTitle(
|
||||
id: number,
|
||||
payload: Partial<TemplateFieldLibraryPayload>,
|
||||
): Promise<TemplateFieldLibrary> {
|
||||
const { data } = await http.patch<TemplateFieldLibrary>(`/template-field-library/${id}`, payload)
|
||||
payload: Partial<TemplateTitlePayload>,
|
||||
): Promise<TemplateTitle> {
|
||||
const { data } = await http.patch<TemplateTitle>(`/template-titles/${id}`, payload)
|
||||
return data
|
||||
}
|
||||
|
||||
export async function deleteTemplateFieldLibrary(id: number): Promise<void> {
|
||||
await http.delete(`/template-field-library/${id}`)
|
||||
export async function deleteTemplateTitle(id: number): Promise<void> {
|
||||
await http.delete(`/template-titles/${id}`)
|
||||
}
|
||||
|
||||
export async function batchDeleteTemplateFieldLibrary(
|
||||
export async function batchDeleteTemplateTitle(
|
||||
ids: number[],
|
||||
): Promise<BatchDeleteResult> {
|
||||
const { data } = await http.post<BatchDeleteResult>('/template-field-library/batch-delete', {
|
||||
const { data } = await http.post<BatchDeleteResult>('/template-titles/batch-delete', {
|
||||
ids,
|
||||
})
|
||||
return data
|
||||
@@ -1,10 +1,11 @@
|
||||
import http from './client'
|
||||
import type { BatchDeleteResult, PageQuery, PageResult } from './types'
|
||||
|
||||
/** One placement of a library field inside a template, with its typography. */
|
||||
export interface TemplateField {
|
||||
/** One placement of a library title inside a template, with its typography. */
|
||||
export interface TemplateTitlePlacement {
|
||||
id: number
|
||||
field_id: number
|
||||
/** The library entry this placement puts here. */
|
||||
title_id: number
|
||||
/** Display position. The only thing that decides render order. */
|
||||
sort: number
|
||||
name: string
|
||||
@@ -18,7 +19,8 @@ export interface TemplateListItem {
|
||||
id: number
|
||||
name: string
|
||||
abstract: string | null
|
||||
field_count: number
|
||||
/** How many placements the template defines. */
|
||||
placement_count: number
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
@@ -28,21 +30,22 @@ export interface TemplateDetail {
|
||||
id: number
|
||||
name: string
|
||||
abstract: string | null
|
||||
fields: TemplateField[]
|
||||
/** The outline, already ordered by `sort`. */
|
||||
placements: TemplateTitlePlacement[]
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
/** One entry of the selection sent on create/update. */
|
||||
export interface TemplateFieldInput {
|
||||
field_id: number
|
||||
export interface TemplateTitlePlacementInput {
|
||||
title_id: number
|
||||
sort: number
|
||||
}
|
||||
|
||||
export interface TemplatePayload {
|
||||
name: string
|
||||
abstract: string | null
|
||||
fields: TemplateFieldInput[]
|
||||
placements: TemplateTitlePlacementInput[]
|
||||
}
|
||||
|
||||
export async function listTemplates(
|
||||
|
||||
@@ -11,18 +11,18 @@ import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
|
||||
|
||||
import { errorMessage } from '@/api/client'
|
||||
import {
|
||||
createTemplateFieldLibrary,
|
||||
updateTemplateFieldLibrary,
|
||||
type TemplateFieldLibrary,
|
||||
type TemplateFieldLibraryPayload,
|
||||
} from '@/api/templateFieldLibrary'
|
||||
createTemplateTitle,
|
||||
updateTemplateTitle,
|
||||
type TemplateTitle,
|
||||
type TemplateTitlePayload,
|
||||
} from '@/api/templateTitles'
|
||||
import { normalizeHexColor, typographyStyle } from '@/utils/format'
|
||||
|
||||
const props = defineProps<{
|
||||
/** Visibility, used with `v-model`. */
|
||||
modelValue: boolean
|
||||
/** The field being edited, or `null` to create a new one. */
|
||||
field: TemplateFieldLibrary | null
|
||||
field: TemplateTitle | null
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -39,7 +39,7 @@ const visible = computed({
|
||||
const formRef = ref<FormInstance>()
|
||||
const saving = ref(false)
|
||||
|
||||
const form = reactive<TemplateFieldLibraryPayload>({
|
||||
const form = reactive<TemplateTitlePayload>({
|
||||
name: '',
|
||||
level: 1,
|
||||
// 小四, the conventional body size for a Chinese thesis.
|
||||
@@ -47,7 +47,7 @@ const form = reactive<TemplateFieldLibraryPayload>({
|
||||
font_color: '#000000',
|
||||
})
|
||||
|
||||
const rules: FormRules<TemplateFieldLibraryPayload> = {
|
||||
const rules: FormRules<TemplateTitlePayload> = {
|
||||
name: [
|
||||
{ required: true, message: '请填写字段名称', trigger: 'blur' },
|
||||
{ max: 255, message: '字段名称最多 255 个字符', trigger: 'blur' },
|
||||
@@ -118,10 +118,10 @@ async function submit(): Promise<void> {
|
||||
saving.value = true
|
||||
try {
|
||||
if (props.field) {
|
||||
await updateTemplateFieldLibrary(props.field.id, { ...form })
|
||||
await updateTemplateTitle(props.field.id, { ...form })
|
||||
ElMessage.success('字段已更新,使用它的模板会同步生效')
|
||||
} else {
|
||||
await createTemplateFieldLibrary({ ...form })
|
||||
await createTemplateTitle({ ...form })
|
||||
ElMessage.success('字段已创建')
|
||||
}
|
||||
emit('saved')
|
||||
|
||||
@@ -173,7 +173,7 @@ async function submit(): Promise<void> {
|
||||
:label="template.name"
|
||||
>
|
||||
<span>{{ template.name }}</span>
|
||||
<span class="option-hint">{{ template.field_count }} 段</span>
|
||||
<span class="option-hint">{{ template.placement_count }} 段</span>
|
||||
</el-option>
|
||||
</el-select>
|
||||
<div v-if="templates.length === 0" class="field-hint">
|
||||
|
||||
@@ -107,7 +107,10 @@ async function loadCandidate(templateId: number | null): Promise<void> {
|
||||
previewing.value = true
|
||||
try {
|
||||
const detail = await getTemplate(templateId)
|
||||
candidate.value = detail.fields.map((field) => ({ sort: field.sort, name: field.name }))
|
||||
candidate.value = detail.placements.map((placement) => ({
|
||||
sort: placement.sort,
|
||||
name: placement.name,
|
||||
}))
|
||||
} catch (error) {
|
||||
ElMessage.error(errorMessage(error))
|
||||
candidate.value = []
|
||||
@@ -170,7 +173,7 @@ async function submit(): Promise<void> {
|
||||
:disabled="template.id === paper.template_id"
|
||||
>
|
||||
<span>{{ template.name }}</span>
|
||||
<span class="option-hint">{{ template.field_count }} 段</span>
|
||||
<span class="option-hint">{{ template.placement_count }} 段</span>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</div>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* The picker is the heart of the feature, and it is deliberately *not* a tree.
|
||||
* Fields come from one flat library and are chosen freely: any subset, any
|
||||
* order, and the same field more than once. What the reader finally sees is
|
||||
* order, and the same title more than once. What the reader finally sees is
|
||||
* decided by `sort` alone, so the right-hand list is always rendered sorted by
|
||||
* `sort` — reordering the numbers reorders the outline immediately, and the
|
||||
* order the user clicked in is never stored.
|
||||
@@ -28,12 +28,12 @@ import {
|
||||
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus'
|
||||
|
||||
import { errorMessage } from '@/api/client'
|
||||
import { fetchAllTemplateFieldLibrary, type TemplateFieldLibrary } from '@/api/templateFieldLibrary'
|
||||
import { fetchAllTemplateTitle, type TemplateTitle } from '@/api/templateTitles'
|
||||
import {
|
||||
createTemplate,
|
||||
getTemplate,
|
||||
updateTemplate,
|
||||
type TemplateFieldInput,
|
||||
type TemplateTitlePlacementInput,
|
||||
type TemplateListItem,
|
||||
} from '@/api/templates'
|
||||
import { levelIndent, typographyStyle } from '@/utils/format'
|
||||
@@ -51,11 +51,11 @@ const emit = defineEmits<{
|
||||
saved: []
|
||||
}>()
|
||||
|
||||
/** One chosen field, at one position. The same field may appear many times. */
|
||||
/** One chosen title, at one position. The same title may appear many times. */
|
||||
interface Placement {
|
||||
/** Local identity for `v-for` / `row-key`; not sent to the server. */
|
||||
key: number
|
||||
field_id: number
|
||||
title_id: number
|
||||
sort: number
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ const formRef = ref<FormInstance>()
|
||||
const loading = ref(false)
|
||||
const saving = ref(false)
|
||||
|
||||
const library = ref<TemplateFieldLibrary[]>([])
|
||||
const library = ref<TemplateTitle[]>([])
|
||||
const libraryKeyword = ref('')
|
||||
const selected = ref<Placement[]>([])
|
||||
|
||||
@@ -81,12 +81,12 @@ const rules: FormRules = { name: [{ required: true, message: '请填写模板名
|
||||
/** Keys only ever count up, so a reopened dialog cannot collide with itself. */
|
||||
let nextKey = 1
|
||||
|
||||
const fieldMap = computed(() => new Map(library.value.map((field) => [field.id, field])))
|
||||
const titleMap = computed(() => new Map(library.value.map((title) => [title.id, title])))
|
||||
|
||||
const filteredLibrary = computed(() => {
|
||||
const keyword = libraryKeyword.value.trim().toLowerCase()
|
||||
if (!keyword) return library.value
|
||||
return library.value.filter((field) => field.name.toLowerCase().includes(keyword))
|
||||
return library.value.filter((title) => title.name.toLowerCase().includes(keyword))
|
||||
})
|
||||
|
||||
/** The selection in display order — ascending `sort`, ties by insertion. */
|
||||
@@ -98,15 +98,15 @@ const rows = computed(() =>
|
||||
// property name `key` rather than a function expression.
|
||||
key: placement.key,
|
||||
placement,
|
||||
field: fieldMap.value.get(placement.field_id),
|
||||
title: titleMap.value.get(placement.title_id),
|
||||
})),
|
||||
)
|
||||
|
||||
/** How many times each library field is placed. */
|
||||
/** How many times each library title is placed. */
|
||||
const repeatCounts = computed(() => {
|
||||
const counts = new Map<number, number>()
|
||||
for (const placement of selected.value) {
|
||||
counts.set(placement.field_id, (counts.get(placement.field_id) ?? 0) + 1)
|
||||
counts.set(placement.title_id, (counts.get(placement.title_id) ?? 0) + 1)
|
||||
}
|
||||
return counts
|
||||
})
|
||||
@@ -114,7 +114,7 @@ const repeatCounts = computed(() => {
|
||||
const repeatedNames = computed(() =>
|
||||
[...repeatCounts.value.entries()]
|
||||
.filter(([, count]) => count > 1)
|
||||
.map(([id, count]) => `${fieldMap.value.get(id)?.name ?? `#${id}`} ×${count}`),
|
||||
.map(([id, count]) => `${titleMap.value.get(id)?.name ?? `#${id}`} ×${count}`),
|
||||
)
|
||||
|
||||
const duplicatedSorts = computed(() => {
|
||||
@@ -143,18 +143,18 @@ watch(
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
// The whole library, so a field that was placed before the keyword
|
||||
// The whole library, so a title that was placed before the keyword
|
||||
// filter existed still resolves to a name in the selection.
|
||||
library.value = await fetchAllTemplateFieldLibrary()
|
||||
library.value = await fetchAllTemplateTitle()
|
||||
|
||||
if (props.template) {
|
||||
const detail = await getTemplate(props.template.id)
|
||||
form.name = detail.name
|
||||
form.abstract = detail.abstract ?? ''
|
||||
selected.value = detail.fields.map((field) => ({
|
||||
selected.value = detail.placements.map((placement) => ({
|
||||
key: nextKey++,
|
||||
field_id: field.field_id,
|
||||
sort: field.sort,
|
||||
title_id: placement.title_id,
|
||||
sort: placement.sort,
|
||||
}))
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -166,9 +166,9 @@ watch(
|
||||
)
|
||||
|
||||
/** Append a placement, at the end of the current order. */
|
||||
function addField(field: TemplateFieldLibrary): void {
|
||||
function addTitle(title: TemplateTitle): void {
|
||||
const highest = selected.value.reduce((max, item) => Math.max(max, item.sort), 0)
|
||||
selected.value.push({ key: nextKey++, field_id: field.id, sort: highest + 1 })
|
||||
selected.value.push({ key: nextKey++, title_id: title.id, sort: highest + 1 })
|
||||
}
|
||||
|
||||
function removePlacement(key: number): void {
|
||||
@@ -208,7 +208,7 @@ function autoSort(): void {
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the field library in a second tab.
|
||||
* Open the title library in a second tab.
|
||||
*
|
||||
* Deliberately not an in-place navigation: a half-filled template form would
|
||||
* be lost, and the usual reason to go there is "the field I need does not
|
||||
@@ -240,14 +240,14 @@ async function submit(): Promise<void> {
|
||||
// Sent in display order, so that equal `sort` values get placement ids in
|
||||
// the same order the user sees and the backend's id tie-break agrees with
|
||||
// the screen.
|
||||
const fields: TemplateFieldInput[] = rows.value.map((row) => ({
|
||||
field_id: row.placement.field_id,
|
||||
const placements: TemplateTitlePlacementInput[] = rows.value.map((row) => ({
|
||||
title_id: row.placement.title_id,
|
||||
sort: row.placement.sort,
|
||||
}))
|
||||
const payload = {
|
||||
name: form.name.trim(),
|
||||
abstract: form.abstract.trim() || null,
|
||||
fields,
|
||||
placements,
|
||||
}
|
||||
|
||||
if (props.template) {
|
||||
@@ -321,18 +321,21 @@ async function submit(): Promise<void> {
|
||||
|
||||
<div class="picker-list">
|
||||
<button
|
||||
v-for="field in filteredLibrary"
|
||||
:key="field.id"
|
||||
v-for="title in filteredLibrary"
|
||||
:key="title.id"
|
||||
type="button"
|
||||
class="lib-item"
|
||||
@click="addField(field)"
|
||||
@click="addTitle(title)"
|
||||
>
|
||||
<span class="lib-name" :style="{ paddingLeft: levelIndent(field.level), ...typographyStyle(field) }">
|
||||
{{ field.name }}
|
||||
<span
|
||||
class="lib-name"
|
||||
:style="{ paddingLeft: levelIndent(title.level), ...typographyStyle(title) }"
|
||||
>
|
||||
{{ title.name }}
|
||||
</span>
|
||||
<span class="lib-side">
|
||||
<el-tag v-if="repeatCounts.get(field.id)" size="small" type="warning" effect="plain">
|
||||
×{{ repeatCounts.get(field.id) }}
|
||||
<el-tag v-if="repeatCounts.get(title.id)" size="small" type="warning" effect="plain">
|
||||
×{{ repeatCounts.get(title.id) }}
|
||||
</el-tag>
|
||||
<el-icon class="lib-add"><Plus /></el-icon>
|
||||
</span>
|
||||
@@ -404,7 +407,7 @@ async function submit(): Promise<void> {
|
||||
>
|
||||
{{ row.field.name }}
|
||||
</span>
|
||||
<span v-else class="missing">字段 #{{ row.placement.field_id }} 已不存在</span>
|
||||
<span v-else class="missing">标题 #{{ row.placement.title_id }} 已不存在</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
@@ -516,7 +519,7 @@ async function submit(): Promise<void> {
|
||||
scrollbar-width: thin;
|
||||
}
|
||||
|
||||
/* A button per field: clickable, focusable and keyboard-operable for free. */
|
||||
/* A button per title: clickable, focusable and keyboard-operable for free. */
|
||||
.lib-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
* 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 { TemplateField } from '@/api/templates'
|
||||
import type { TemplateTitlePlacement } from '@/api/templates'
|
||||
import { levelIndent, typographyStyle } from '@/utils/format'
|
||||
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
fields: TemplateField[]
|
||||
placements: TemplateTitlePlacement[]
|
||||
/** Show the sort value and typography under each heading. */
|
||||
showMeta?: boolean
|
||||
}>(),
|
||||
@@ -22,10 +22,10 @@ withDefaults(
|
||||
|
||||
<template>
|
||||
<div class="outline">
|
||||
<el-empty v-if="fields.length === 0" description="这个模板还没有选择任何字段" />
|
||||
<el-empty v-if="placements.length === 0" description="这个模板还没有选择任何字段" />
|
||||
|
||||
<ol v-else class="outline-list">
|
||||
<li v-for="field in fields" :key="field.id" class="outline-row">
|
||||
<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) }">
|
||||
|
||||
@@ -12,7 +12,7 @@ import { useRouter } from 'vue-router'
|
||||
import { Files, Notebook, Setting } from '@element-plus/icons-vue'
|
||||
|
||||
import { listPapers } from '@/api/papers'
|
||||
import { listTemplateFieldLibrary } from '@/api/templateFieldLibrary'
|
||||
import { listTemplateTitle } from '@/api/templateTitles'
|
||||
import { listTemplates } from '@/api/templates'
|
||||
import AppLogo from '@/components/AppLogo.vue'
|
||||
|
||||
@@ -20,7 +20,7 @@ const router = useRouter()
|
||||
|
||||
const paperCount = ref<number | null>(null)
|
||||
const templateCount = ref<number | null>(null)
|
||||
const fieldCount = 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 {
|
||||
@@ -30,14 +30,14 @@ function display(value: number | null): string {
|
||||
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, fields] = await Promise.allSettled([
|
||||
const [papers, templates, titles] = await Promise.allSettled([
|
||||
listPapers({ page: 1, page_size: 1 }),
|
||||
listTemplates({ page: 1, page_size: 1 }),
|
||||
listTemplateFieldLibrary({ 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 (fields.status === 'fulfilled') fieldCount.value = fields.value.total
|
||||
if (titles.status === 'fulfilled') titleCount.value = titles.value.total
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -81,7 +81,7 @@ onMounted(async () => {
|
||||
<div class="stat">
|
||||
<el-icon class="stat-icon"><Setting /></el-icon>
|
||||
<div>
|
||||
<div class="stat-value">{{ display(fieldCount) }}</div>
|
||||
<div class="stat-value">{{ display(titleCount) }}</div>
|
||||
<div class="stat-label">字段库</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -14,18 +14,18 @@ import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
|
||||
import { errorMessage } from '@/api/client'
|
||||
import {
|
||||
batchDeleteTemplateFieldLibrary,
|
||||
deleteTemplateFieldLibrary,
|
||||
listTemplateFieldLibrary,
|
||||
type TemplateFieldLibrary,
|
||||
} from '@/api/templateFieldLibrary'
|
||||
batchDeleteTemplateTitle,
|
||||
deleteTemplateTitle,
|
||||
listTemplateTitle,
|
||||
type TemplateTitle,
|
||||
} from '@/api/templateTitles'
|
||||
import FieldFormDialog from '@/components/fields/FieldFormDialog.vue'
|
||||
import { formatDateTime, levelIndent, typographyStyle } from '@/utils/format'
|
||||
|
||||
const loading = ref(false)
|
||||
const rows = ref<TemplateFieldLibrary[]>([])
|
||||
const rows = ref<TemplateTitle[]>([])
|
||||
const total = ref(0)
|
||||
const selection = ref<TemplateFieldLibrary[]>([])
|
||||
const selection = ref<TemplateTitle[]>([])
|
||||
|
||||
const query = reactive({
|
||||
keyword: '',
|
||||
@@ -35,7 +35,7 @@ const query = reactive({
|
||||
})
|
||||
|
||||
const dialogVisible = ref(false)
|
||||
const editing = ref<TemplateFieldLibrary | null>(null)
|
||||
const editing = ref<TemplateTitle | null>(null)
|
||||
|
||||
const LEVEL_FILTERS = [
|
||||
{ value: null, label: '全部等级' },
|
||||
@@ -47,7 +47,7 @@ const LEVEL_FILTERS = [
|
||||
async function load(): Promise<void> {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await listTemplateFieldLibrary(query)
|
||||
const result = await listTemplateTitle(query)
|
||||
rows.value = result.items
|
||||
total.value = result.total
|
||||
|
||||
@@ -81,12 +81,12 @@ function onCreate(): void {
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
function onEdit(row: TemplateFieldLibrary): void {
|
||||
function onEdit(row: TemplateTitle): void {
|
||||
editing.value = row
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
async function onDelete(row: TemplateFieldLibrary): Promise<void> {
|
||||
async function onDelete(row: TemplateTitle): Promise<void> {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定删除字段「${row.name}」?`, '删除字段', {
|
||||
type: 'warning',
|
||||
@@ -98,7 +98,7 @@ async function onDelete(row: TemplateFieldLibrary): Promise<void> {
|
||||
}
|
||||
|
||||
try {
|
||||
await deleteTemplateFieldLibrary(row.id)
|
||||
await deleteTemplateTitle(row.id)
|
||||
ElMessage.success('已删除')
|
||||
await load()
|
||||
} catch (error) {
|
||||
@@ -121,7 +121,7 @@ async function onBatchDelete(): Promise<void> {
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await batchDeleteTemplateFieldLibrary(ids)
|
||||
const result = await batchDeleteTemplateTitle(ids)
|
||||
ElMessage.success(`已删除 ${result.deleted} 个字段`)
|
||||
selection.value = []
|
||||
await load()
|
||||
@@ -195,7 +195,7 @@ onMounted(load)
|
||||
stripe
|
||||
class="table table-fill"
|
||||
height="100%"
|
||||
@selection-change="(value: TemplateFieldLibrary[]) => (selection = value)"
|
||||
@selection-change="(value: TemplateTitle[]) => (selection = value)"
|
||||
>
|
||||
<el-table-column type="selection" width="46" reserve-selection />
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* The full CRUD surface: search, create, edit, single and batch delete, with a
|
||||
* preview drawer that renders a template's outline exactly as it will read.
|
||||
* The drawer is the quickest way to confirm that a template's fields really do
|
||||
* The drawer is the quickest way to confirm that a template's titles really do
|
||||
* come out in `sort` order before committing to write against it.
|
||||
*/
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
@@ -210,7 +210,7 @@ onMounted(load)
|
||||
|
||||
<el-table-column label="段落数" width="100" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-tag size="small" effect="plain">{{ row.field_count }}</el-tag>
|
||||
<el-tag size="small" effect="plain">{{ row.placement_count }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
@@ -262,7 +262,7 @@ onMounted(load)
|
||||
<div class="preview-meta">
|
||||
<el-tag size="small" effect="plain">
|
||||
<el-icon><Files /></el-icon>
|
||||
{{ preview.fields.length }} 个段落
|
||||
{{ preview.placements.length }} 个段落
|
||||
</el-tag>
|
||||
<span class="muted">更新于 {{ formatDateTime(preview.updated_at) }}</span>
|
||||
</div>
|
||||
@@ -274,7 +274,7 @@ onMounted(load)
|
||||
<span class="divider-hint">已按 sort 升序排列</span>
|
||||
</el-divider>
|
||||
|
||||
<TemplateOutline :fields="preview.fields" />
|
||||
<TemplateOutline :placements="preview.placements" />
|
||||
</template>
|
||||
</div>
|
||||
</el-drawer>
|
||||
|
||||
Reference in New Issue
Block a user