mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-11-09 18:53:43 +08:00
1. 优化 ChatFree 页面左侧会话列表展示逻辑
2. 渲染 Prompt 组件换行符
This commit is contained in:
@@ -73,6 +73,7 @@ export function dateFormat(timestamp, format) {
|
||||
return timeDate;
|
||||
}
|
||||
|
||||
// 判断数组中是否包含某个元素
|
||||
export function arrayContains(array, value, compare) {
|
||||
if (typeof compare !== 'function') {
|
||||
compare = function (v1, v2) {
|
||||
@@ -85,4 +86,27 @@ export function arrayContains(array, value, compare) {
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// 删除数组中指定的元素
|
||||
export function removeArrayItem(array, value, compare) {
|
||||
if (typeof compare !== 'function') {
|
||||
compare = function (v1, v2) {
|
||||
return v1 === v2;
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < array.length; i++) {
|
||||
if (compare(array[i], value)) {
|
||||
array.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
// 渲染输入的换行符
|
||||
export function renderInputText(text) {
|
||||
const replaceRegex = /(\n\r|\r\n|\r|\n)/g;
|
||||
text = text || '';
|
||||
return text.replace(replaceRegex, "<br/>");
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/* eslint-disable no-constant-condition */
|
||||
import {dateFormat} from "@/utils/libs";
|
||||
import {dateFormat, removeArrayItem} from "@/utils/libs";
|
||||
import Storage from 'good-storage'
|
||||
|
||||
/**
|
||||
@@ -69,32 +69,32 @@ export function getChatHistory(chatId) {
|
||||
}
|
||||
|
||||
export function getChatList() {
|
||||
return Storage.get(ChatListKey);
|
||||
}
|
||||
|
||||
export function getChat(chatId) {
|
||||
let chatList = Storage.get(ChatListKey);
|
||||
if (!chatList) {
|
||||
return null;
|
||||
const list = Storage.get(ChatListKey);
|
||||
if (list) {
|
||||
if (typeof list.reverse !== 'function') {
|
||||
Storage.remove(ChatListKey)
|
||||
return null;
|
||||
}
|
||||
return list.reverse();
|
||||
}
|
||||
|
||||
return chatList[chatId] ? chatList[chatId] : null;
|
||||
}
|
||||
|
||||
export function setChat(chat) {
|
||||
let chatList = Storage.get(ChatListKey);
|
||||
if (!chatList) {
|
||||
chatList = {};
|
||||
chatList = [];
|
||||
}
|
||||
|
||||
chatList[chat.id] = chat;
|
||||
chatList.push(chat);
|
||||
Storage.set(ChatListKey, chatList);
|
||||
}
|
||||
|
||||
export function removeChat(chatId) {
|
||||
const chatList = Storage.get(ChatListKey);
|
||||
export function removeChat(chat) {
|
||||
let chatList = Storage.get(ChatListKey);
|
||||
if (chatList) {
|
||||
delete chatList[chatId];
|
||||
chatList = removeArrayItem(chatList, chat, function (v1, v2) {
|
||||
return v1.id === v2.id
|
||||
})
|
||||
Storage.set(ChatListKey, chatList);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user