ui模块优化 全部navigationmanager管理

实现pastgirllistpanel逻辑
完善图集
This commit is contained in:
2025-09-21 12:05:34 +08:00
parent 8e82ebf724
commit 7722ccf694
65 changed files with 773 additions and 2280 deletions
@@ -41,10 +41,22 @@ export class ChatHistoryManager {
public saveHistory(roleId: number, messages: ChatMessage[]): void {
const key = `chat_history_${roleId}`;
try {
// 检查是否已存在历史记录以保留创建时间
let createdAt = Date.now();
const existingData = sys.localStorage.getItem(key);
if (existingData) {
try {
const existingHistory: ChatHistory = JSON.parse(existingData);
createdAt = existingHistory.createdAt;
} catch (parseError) {
console.warn(`Failed to parse existing history for role ${roleId}, using current time as createdAt`);
}
}
const history: ChatHistory = {
roleId: roleId,
messages: messages,
createdAt: Date.now(),
createdAt: createdAt,
updatedAt: Date.now(),
};
@@ -200,6 +212,31 @@ export class ChatHistoryManager {
}
}
/**
* 获取指定角色的最后聊天时间
* @param roleId 角色ID
* @returns 最后聊天时间戳,如果没有历史记录则返回null
*/
public getLastChatTime(roleId: number): number | null {
const key = `chat_history_${roleId}`;
try {
const data = sys.localStorage.getItem(key);
if (data) {
const history: ChatHistory = JSON.parse(data);
if (history.messages && history.messages.length > 0) {
// 获取最后一条消息的时间戳
const lastMessage = history.messages[history.messages.length - 1];
return lastMessage.timestamp || history.updatedAt;
}
// 如果有历史但没有消息,返回创建时间
return history.createdAt;
}
} catch (error) {
console.error(`Failed to get last chat time for role ${roleId}:`, error);
}
return null;
}
/**
* 从远程服务器下载历史(预留接口)
* @param roleId 角色ID