Skip to content

Commit 45dfee8

Browse files
committed
feat(ai): add optional subtitle field to translation interfaces and components
Signed-off-by: Innei <tukon479@gmail.com>
1 parent ce9e5bc commit 45dfee8

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/api/ai.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export interface AITranslation {
7575
lang: string
7676
sourceLang: string
7777
title: string
78+
subtitle?: string
7879
text: string
7980
summary?: string
8081
tags?: string[]
@@ -321,6 +322,7 @@ export const aiApi = {
321322
id: string,
322323
data: {
323324
title?: string
325+
subtitle?: string
324326
text?: string
325327
summary?: string
326328
tags?: string[]

src/views/ai/components/translation-detail-panel.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ export const TranslationDetailPanel = defineComponent({
232232
id: string,
233233
updates: {
234234
title: string
235+
subtitle?: string
235236
text: string
236237
summary?: string
237238
content?: string
@@ -240,6 +241,7 @@ export const TranslationDetailPanel = defineComponent({
240241
const idx = translations.value.findIndex((t) => t.id === id)
241242
if (idx !== -1) {
242243
translations.value[idx].title = updates.title
244+
translations.value[idx].subtitle = updates.subtitle
243245
translations.value[idx].text = updates.text
244246
translations.value[idx].summary = updates.summary
245247
if (updates.content !== undefined) {
@@ -528,6 +530,7 @@ const TranslationEditPanel = defineComponent({
528530
id: string,
529531
updates: {
530532
title: string
533+
subtitle?: string
531534
text: string
532535
summary?: string
533536
content?: string
@@ -547,6 +550,7 @@ const TranslationEditPanel = defineComponent({
547550
)
548551

549552
const titleRef = ref(props.translation.title)
553+
const subtitleRef = ref(props.translation.subtitle || '')
550554
const textRef = ref(props.translation.text)
551555
const summaryRef = ref(props.translation.summary || '')
552556
const saving = ref(false)
@@ -560,6 +564,7 @@ const TranslationEditPanel = defineComponent({
560564
() => props.translation.id,
561565
() => {
562566
titleRef.value = props.translation.title
567+
subtitleRef.value = props.translation.subtitle || ''
563568
textRef.value = props.translation.text
564569
summaryRef.value = props.translation.summary || ''
565570
richContentRef.value = parseRichContent(props.translation.content)
@@ -580,6 +585,7 @@ const TranslationEditPanel = defineComponent({
580585
try {
581586
const payload: Parameters<typeof aiApi.updateTranslation>[1] = {
582587
title: titleRef.value,
588+
subtitle: subtitleRef.value || undefined,
583589
summary: summaryRef.value || undefined,
584590
}
585591

@@ -594,6 +600,7 @@ const TranslationEditPanel = defineComponent({
594600
await aiApi.updateTranslation(props.translation.id, payload)
595601
props.onSave(props.translation.id, {
596602
title: titleRef.value,
603+
subtitle: subtitleRef.value || undefined,
597604
text: textRef.value,
598605
summary: summaryRef.value || undefined,
599606
content: isLexical.value
@@ -614,7 +621,9 @@ const TranslationEditPanel = defineComponent({
614621
<RichEditor
615622
key={editorKey.value}
616623
class="h-full min-h-[400px] w-full"
617-
editorStyle={richEditorStyleOverride as Record<string, string | number>}
624+
editorStyle={
625+
richEditorStyleOverride as Record<string, string | number>
626+
}
618627
initialValue={richContentRef.value}
619628
variant="article"
620629
onChange={(value: SerializedEditorState) => {
@@ -696,6 +705,18 @@ const TranslationEditPanel = defineComponent({
696705
/>
697706
</div>
698707

708+
<div>
709+
<label class="mb-2 block text-sm font-medium text-neutral-700 dark:text-neutral-300">
710+
副标题
711+
<span class="ml-1 text-xs text-neutral-400">(可选)</span>
712+
</label>
713+
<NInput
714+
value={subtitleRef.value}
715+
onUpdateValue={(v) => (subtitleRef.value = v)}
716+
placeholder="翻译副标题"
717+
/>
718+
</div>
719+
699720
<div>
700721
<label class="mb-2 block text-sm font-medium text-neutral-700 dark:text-neutral-300">
701722
内容

0 commit comments

Comments
 (0)