frontend: add the template configuration UI
The shell: the app mark at both ends of the header, the two top-level
entries between them, and the second-level menu on the right. That menu is
driven entirely by `route.meta.section`, so a route declares which menu it
belongs to and a deep link renders the right one on first paint; routes with
no section (the welcome page) show none.
Screens:
/ welcome, with live template and field counts so the
page doubles as a connectivity check
/papers 论文, content still to be decided
/templates/list the template table: search, create, edit, preview,
delete, batch delete, pagination
/templates/fields the field library: the same CRUD, plus level filter
The template form is the centre of it. Fields are chosen from the flat
library by clicking — any subset, any order, the same field more than once —
and the selection is always rendered sorted by `sort`, so editing a number
reorders the outline immediately. Repeats and duplicate sorts are surfaced as
warnings rather than blocked, because a repeat is often deliberate and a tie
is legal; a "自动排序" button renumbers the selection 1..N. The panel on the
right of the picker opens 字段管理 in a second tab, so a half-filled form is
never lost to a navigation.
The preview drawer renders the outline exactly as it will read, at each
field's own size and colour, with the sort value shown alongside — the
quickest way to confirm the ordering before writing against a template.
Also in this change:
- ApiError now extends Error. It was a plain object, so the common
`error instanceof Error ? error.message : ...` idiom fell through to a
generic message and threw away what the server actually said — such as
which template name is already taken. Server messages now reach the user.
- font colours are normalised client-side on blur, matching the backend,
so a hand-typed rgb(255, 0, 0) is tidied up rather than rejected later.
- api/health.ts is removed: the rewritten welcome page was its only
consumer, and the counts already prove connectivity.
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
<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 { TemplateField } from '@/api/templates'
|
||||
import { levelIndent, typographyStyle } from '@/utils/format'
|
||||
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
fields: TemplateField[]
|
||||
/** Show the sort value and typography under each heading. */
|
||||
showMeta?: boolean
|
||||
}>(),
|
||||
{ showMeta: true },
|
||||
)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="outline">
|
||||
<el-empty v-if="fields.length === 0" description="这个模板还没有选择任何字段" />
|
||||
|
||||
<ol v-else class="outline-list">
|
||||
<li v-for="field in fields" :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>
|
||||
Reference in New Issue
Block a user