mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-11-09 18:53:43 +08:00
refactor: refactor controller handler module and admin module
This commit is contained in:
@@ -1,20 +1,26 @@
|
||||
/* eslint-disable no-constant-condition */
|
||||
import {dateFormat, removeArrayItem} from "@/utils/libs";
|
||||
import Storage from 'good-storage'
|
||||
|
||||
/**
|
||||
* storage handler
|
||||
*/
|
||||
|
||||
const SessionUserKey = 'LOGIN_USER';
|
||||
const ChatHistoryKey = 'CHAT_HISTORY';
|
||||
const ChatListKey = 'CHAT_LIST';
|
||||
const SessionAdminKey = 'LOGIN_ADMIN';
|
||||
|
||||
export function getSessionId() {
|
||||
const user = getLoginUser();
|
||||
return user ? user['session_id'] : '';
|
||||
}
|
||||
|
||||
export function getLoginAdmin() {
|
||||
const value = sessionStorage.getItem(SessionAdminKey);
|
||||
if (value) {
|
||||
return JSON.parse(value);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function getLoginUser() {
|
||||
const value = sessionStorage.getItem(SessionUserKey);
|
||||
if (value) {
|
||||
@@ -28,73 +34,6 @@ export function setLoginUser(user) {
|
||||
sessionStorage.setItem(SessionUserKey, JSON.stringify(user))
|
||||
}
|
||||
|
||||
export function getUserInfo() {
|
||||
const data = getLoginUser();
|
||||
if (data !== null) {
|
||||
const user = data["user"];
|
||||
user['active_time'] = dateFormat(user['active_time']);
|
||||
user['expired_time'] = dateFormat(user['expired_time']);
|
||||
return user;
|
||||
}
|
||||
return {}
|
||||
}
|
||||
|
||||
// 追加历史记录
|
||||
export function appendChatHistory(chatId, message) {
|
||||
let history = Storage.get(ChatHistoryKey);
|
||||
if (!history) {
|
||||
history = {};
|
||||
}
|
||||
if (!history[chatId]) {
|
||||
history[chatId] = [message];
|
||||
} else {
|
||||
history[chatId].push(message);
|
||||
}
|
||||
Storage.set(ChatHistoryKey, history);
|
||||
}
|
||||
|
||||
export function clearChatHistory() {
|
||||
Storage.remove(ChatHistoryKey);
|
||||
Storage.remove(ChatListKey);
|
||||
}
|
||||
|
||||
// 获取指定会话的历史记录
|
||||
export function getChatHistory(chatId) {
|
||||
const history = Storage.get(ChatHistoryKey);
|
||||
if (!history) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return history[chatId] ? history[chatId] : null;
|
||||
}
|
||||
|
||||
export function getChatList() {
|
||||
const list = Storage.get(ChatListKey);
|
||||
if (list) {
|
||||
if (typeof list.reverse !== 'function') {
|
||||
Storage.remove(ChatListKey)
|
||||
return null;
|
||||
}
|
||||
return list.reverse();
|
||||
}
|
||||
}
|
||||
|
||||
export function setChat(chat) {
|
||||
let chatList = Storage.get(ChatListKey);
|
||||
if (!chatList) {
|
||||
chatList = [];
|
||||
}
|
||||
|
||||
chatList.push(chat);
|
||||
Storage.set(ChatListKey, chatList);
|
||||
}
|
||||
|
||||
export function removeChat(chat) {
|
||||
let chatList = Storage.get(ChatListKey);
|
||||
if (chatList) {
|
||||
chatList = removeArrayItem(chatList, chat, function (v1, v2) {
|
||||
return v1.id === v2.id
|
||||
})
|
||||
Storage.set(ChatListKey, chatList);
|
||||
}
|
||||
export function setLoginAdmin(admin) {
|
||||
sessionStorage.setItem(SessionAdminKey, JSON.stringify(admin))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user