feat(export): add session name prefix toggle in layout dropdown

This commit is contained in:
tisonhuang
2026-03-05 10:36:29 +08:00
parent ecae83f659
commit 36f1476782
5 changed files with 233 additions and 11 deletions

View File

@@ -271,6 +271,68 @@
line-height: 1.45;
}
.layout-prefix-toggle {
margin-top: 4px;
padding: 10px;
border-top: 1px solid color-mix(in srgb, var(--border-color) 85%, transparent);
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.layout-prefix-copy {
display: flex;
flex-direction: column;
gap: 2px;
min-width: 0;
}
.layout-prefix-label {
font-size: 12px;
color: var(--text-primary);
font-weight: 600;
line-height: 1.35;
}
.layout-prefix-desc {
font-size: 11px;
color: var(--text-secondary);
line-height: 1.4;
}
.layout-prefix-switch {
width: 38px;
height: 22px;
border-radius: 999px;
border: 1px solid var(--border-color);
background: var(--bg-secondary);
cursor: pointer;
padding: 2px;
display: inline-flex;
align-items: center;
transition: background 0.15s ease, border-color 0.15s ease;
flex-shrink: 0;
.layout-prefix-switch-thumb {
width: 16px;
height: 16px;
border-radius: 50%;
background: #fff;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.22);
transition: transform 0.15s ease;
}
&.on {
background: rgba(var(--primary-rgb), 0.9);
border-color: rgba(var(--primary-rgb), 0.95);
.layout-prefix-switch-thumb {
transform: translateX(16px);
}
}
}
.task-center-control {
display: flex;
flex-direction: column;

View File

@@ -750,10 +750,14 @@ const normalizeMessageCount = (value: unknown): number | undefined => {
const WriteLayoutSelector = memo(function WriteLayoutSelector({
writeLayout,
onChange
onChange,
sessionNameWithTypePrefix,
onSessionNameWithTypePrefixChange
}: {
writeLayout: configService.ExportWriteLayout
onChange: (value: configService.ExportWriteLayout) => Promise<void>
sessionNameWithTypePrefix: boolean
onSessionNameWithTypePrefixChange: (enabled: boolean) => Promise<void>
}) {
const [isOpen, setIsOpen] = useState(false)
const containerRef = useRef<HTMLDivElement | null>(null)
@@ -797,6 +801,23 @@ const WriteLayoutSelector = memo(function WriteLayoutSelector({
<span className="layout-option-desc">{option.desc}</span>
</button>
))}
<div className="layout-prefix-toggle">
<div className="layout-prefix-copy">
<span className="layout-prefix-label"></span>
<span className="layout-prefix-desc">使____前缀</span>
</div>
<button
type="button"
className={`layout-prefix-switch ${sessionNameWithTypePrefix ? 'on' : ''}`}
onClick={async () => {
await onSessionNameWithTypePrefixChange(!sessionNameWithTypePrefix)
}}
aria-label="聊天文本文件和会话文件夹带前缀"
aria-pressed={sessionNameWithTypePrefix}
>
<span className="layout-prefix-switch-thumb" />
</button>
</div>
</div>
</div>
)
@@ -1082,6 +1103,7 @@ function ExportPage() {
const [exportFolder, setExportFolder] = useState('')
const [writeLayout, setWriteLayout] = useState<configService.ExportWriteLayout>('B')
const [sessionNameWithTypePrefix, setSessionNameWithTypePrefix] = useState(true)
const [snsExportFormat, setSnsExportFormat] = useState<SnsTimelineExportFormat>('html')
const [snsExportImages, setSnsExportImages] = useState(false)
const [snsExportLivePhotos, setSnsExportLivePhotos] = useState(false)
@@ -1456,7 +1478,7 @@ function ExportPage() {
setIsBaseConfigLoading(true)
let isReady = true
try {
const [savedPath, savedMedia, savedVoiceAsText, savedExcelCompactColumns, savedTxtColumns, savedConcurrency, savedSessionMap, savedContentMap, savedSessionRecordMap, savedSnsPostCount, savedWriteLayout, exportCacheScope] = await Promise.all([
const [savedPath, savedMedia, savedVoiceAsText, savedExcelCompactColumns, savedTxtColumns, savedConcurrency, savedSessionMap, savedContentMap, savedSessionRecordMap, savedSnsPostCount, savedWriteLayout, savedSessionNameWithTypePrefix, exportCacheScope] = await Promise.all([
configService.getExportPath(),
configService.getExportDefaultMedia(),
configService.getExportDefaultVoiceAsText(),
@@ -1468,6 +1490,7 @@ function ExportPage() {
configService.getExportSessionRecordMap(),
configService.getExportLastSnsPostCount(),
configService.getExportWriteLayout(),
configService.getExportSessionNamePrefixEnabled(),
ensureExportCacheScope()
])
@@ -1481,6 +1504,7 @@ function ExportPage() {
}
setWriteLayout(savedWriteLayout)
setSessionNameWithTypePrefix(savedSessionNameWithTypePrefix)
setLastExportBySession(savedSessionMap)
setLastExportByContent(savedContentMap)
setExportRecordsBySession(savedSessionRecordMap)
@@ -2266,6 +2290,7 @@ function ExportPage() {
displayNamePreference: options.displayNamePreference,
exportConcurrency: options.exportConcurrency,
sessionLayout,
sessionNameWithTypePrefix,
dateRange: options.useAllTime
? null
: options.dateRange
@@ -3708,6 +3733,11 @@ function ExportPage() {
setWriteLayout(value)
await configService.setExportWriteLayout(value)
}}
sessionNameWithTypePrefix={sessionNameWithTypePrefix}
onSessionNameWithTypePrefixChange={async (enabled) => {
setSessionNameWithTypePrefix(enabled)
await configService.setExportSessionNamePrefixEnabled(enabled)
}}
/>
<div className="task-center-control">

View File

@@ -33,6 +33,7 @@ export const CONFIG_KEYS = {
EXPORT_DEFAULT_TXT_COLUMNS: 'exportDefaultTxtColumns',
EXPORT_DEFAULT_CONCURRENCY: 'exportDefaultConcurrency',
EXPORT_WRITE_LAYOUT: 'exportWriteLayout',
EXPORT_SESSION_NAME_PREFIX_ENABLED: 'exportSessionNamePrefixEnabled',
EXPORT_LAST_SESSION_RUN_MAP: 'exportLastSessionRunMap',
EXPORT_LAST_CONTENT_RUN_MAP: 'exportLastContentRunMap',
EXPORT_SESSION_RECORD_MAP: 'exportSessionRecordMap',
@@ -410,6 +411,16 @@ export async function setExportWriteLayout(layout: ExportWriteLayout): Promise<v
await config.set(CONFIG_KEYS.EXPORT_WRITE_LAYOUT, layout)
}
export async function getExportSessionNamePrefixEnabled(): Promise<boolean> {
const value = await config.get(CONFIG_KEYS.EXPORT_SESSION_NAME_PREFIX_ENABLED)
if (typeof value === 'boolean') return value
return true
}
export async function setExportSessionNamePrefixEnabled(enabled: boolean): Promise<void> {
await config.set(CONFIG_KEYS.EXPORT_SESSION_NAME_PREFIX_ENABLED, enabled)
}
export async function getExportLastSessionRunMap(): Promise<Record<string, number>> {
const value = await config.get(CONFIG_KEYS.EXPORT_LAST_SESSION_RUN_MAP)
if (!value || typeof value !== 'object') return {}

View File

@@ -801,6 +801,7 @@ export interface ExportOptions {
excelCompactColumns?: boolean
txtColumns?: string[]
sessionLayout?: 'shared' | 'per-session'
sessionNameWithTypePrefix?: boolean
displayNamePreference?: 'group-nickname' | 'remark' | 'nickname'
exportConcurrency?: number
}