保留历史消息时间并恢复订单卡片操作
This commit is contained in:
+18
-10
@@ -807,12 +807,13 @@ function openConversation(id){
|
||||
msgs.forEach(m=>{
|
||||
if(m.role === "assistant" && m.content.indexOf(CARD_PREFIX) === 0){
|
||||
try{
|
||||
addTrackCard(JSON.parse(m.content.slice(CARD_PREFIX.length)));
|
||||
const bubble = addTrackCard(JSON.parse(m.content.slice(CARD_PREFIX.length)), m.ctime);
|
||||
attachActions(bubble, m.content, '', false);
|
||||
}catch(e){
|
||||
addMsg(m.content, false);
|
||||
addMsg(m.content, false, undefined, m.ctime);
|
||||
}
|
||||
}else{
|
||||
const b = addMsg(m.content, m.role === "user");
|
||||
const b = addMsg(m.content, m.role === "user", undefined, m.ctime);
|
||||
if(m.role === "assistant" && b) attachActions(b, m.content, "", false);
|
||||
}
|
||||
});
|
||||
@@ -925,12 +926,23 @@ function createMessageRow(isUser, authorRole){
|
||||
return row;
|
||||
}
|
||||
|
||||
function addTrackCard(card){
|
||||
function appendMessageTime(row, timeStr){
|
||||
const ts = document.createElement('div');
|
||||
ts.className = 'msg-time';
|
||||
const stored = typeof timeStr === 'string' && timeStr.match(/(?:^|[T\s])(\d{2}:\d{2})/);
|
||||
const now = new Date();
|
||||
ts.textContent = stored ? stored[1] : String(now.getHours()).padStart(2,'0') + ':' + String(now.getMinutes()).padStart(2,'0');
|
||||
if(timeStr) ts.title = timeStr;
|
||||
row.appendChild(ts);
|
||||
}
|
||||
|
||||
function addTrackCard(card, timeStr){
|
||||
const row = createMessageRow(false);
|
||||
const bubble = document.createElement("div");
|
||||
bubble.className = "robot-message track-card";
|
||||
fillTrackCard(bubble, card);
|
||||
row.appendChild(bubble);
|
||||
appendMessageTime(row, timeStr);
|
||||
chatDom.appendChild(row);
|
||||
scrollChatToEnd();
|
||||
return bubble;
|
||||
@@ -1180,7 +1192,7 @@ function startHumanPoll(){
|
||||
humanPollTimer = pollTimer;
|
||||
}
|
||||
|
||||
function addMsg(content, isUser, authorRole){
|
||||
function addMsg(content, isUser, authorRole, timeStr){
|
||||
if(chatDom.querySelector('.ai-welcome-card')) chatDom.innerHTML = "";
|
||||
const rowDiv = createMessageRow(isUser, authorRole);
|
||||
let robotMsg;
|
||||
@@ -1236,11 +1248,7 @@ function addMsg(content, isUser, authorRole){
|
||||
rowDiv.appendChild(robotMsg);
|
||||
}
|
||||
// 时间戳
|
||||
const ts = document.createElement("div");
|
||||
ts.className = "msg-time";
|
||||
const d = new Date();
|
||||
ts.textContent = String(d.getHours()).padStart(2,'0') + ":" + String(d.getMinutes()).padStart(2,'0');
|
||||
rowDiv.appendChild(ts);
|
||||
appendMessageTime(rowDiv, timeStr);
|
||||
chatDom.appendChild(rowDiv);
|
||||
scrollChatToEnd(Boolean(isUser));
|
||||
if(!isUser){
|
||||
|
||||
Reference in New Issue
Block a user