fix:401、403错误提示,对话角色更改assistant,模型选择持久化

This commit is contained in:
Gsh
2025-07-05 15:49:29 +08:00
parent 7e4c835ced
commit 23cecb9360
8 changed files with 25 additions and 19 deletions

View File

@@ -102,7 +102,6 @@ async function handleReset() {
}
catch (error) {
if (error !== 'cancel') {
console.error('重置失败:', error);
ElMessage.error('重置失败');
}
}

View File

@@ -19,7 +19,7 @@ import { useUserStore } from '@/stores/modules/user';
type MessageItem = BubbleProps & {
key: number;
role: 'ai' | 'user' | 'system';
role: 'ai' | 'user' | 'assistant';
avatar: string;
thinkingStatus?: ThinkingStatus;
thinlCollapse?: boolean;
@@ -81,8 +81,6 @@ watch(
const v = localStorage.getItem('chatContent');
if (v) {
// 发送消息
console.log('发送消息 v', v);
console.log('发送消息--error', bubbleItems);
setTimeout(() => {
startSSE(v);
}, 350);
@@ -181,7 +179,7 @@ async function startSSE(chatContent: string) {
.slice(-6) // 然后取倒数第2到第7条总共6条
.map((item: MessageItem) => ({
role: item.role,
content: (item.role === 'ai' || item.role === 'system') && item.content.length > 2000
content: (item.role === 'ai' || item.role === 'assistant') && item.content.length > 2000
? `${item.content.substring(0, 2000)}...(内容过长,已省略)`
: item.content,
})),
@@ -222,7 +220,7 @@ function addMessage(message: string, isUser: boolean) {
? avatar.value
: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
avatarSize: '32px',
role: isUser ? 'user' : 'system',
role: isUser ? 'user' : 'assistant',
placement: isUser ? 'end' : 'start',
isMarkdown: !isUser,
loading: !isUser,

View File

@@ -4,21 +4,21 @@ import { getModelList } from '@/api';
// 模型管理
export const useModelStore = defineStore('model', () => {
// 当前模型
// 当前模型(需要持久化)
const currentModelInfo = ref<GetSessionListVO>({});
// 模型菜单列表(不需要持久化)
const modelList = ref<GetSessionListVO[]>([]);
// 设置当前模型
const setCurrentModelInfo = (modelInfo: GetSessionListVO) => {
currentModelInfo.value = modelInfo;
};
// 模型菜单列表
const modelList = ref<GetSessionListVO[]>([]);
// 请求模型菜单列表
const requestModelList = async () => {
try {
const res = await getModelList();
console.log('res', res);
modelList.value = res.data;
}
catch (error) {
@@ -32,4 +32,8 @@ export const useModelStore = defineStore('model', () => {
modelList,
requestModelList,
};
}, {
persist: {
paths: ['currentModelInfo'], // 只持久化 currentModelInfo
},
});

View File

@@ -108,6 +108,7 @@ function jwtPlugin(): {
}
if (response.result?.code === 401) {
ElMessage.error('登录已过期,请重新登录');
userStore.logout();
userStore.openLoginDialog();
}
@@ -118,9 +119,17 @@ function jwtPlugin(): {
onError: async (error) => {
if (error.status === 403) {
const data = await (error.response.json());
// 弹窗提示
ElMessage.error('业务错误,请稍后再试');
console.error('Fetch error:', error);
ElMessage.error(data.error.message);
return Promise.reject(data);
}
if (error.status === 401) {
ElMessage.error('登录已过期,请重新登录!');
// 弹窗提示
userStore.logout();
userStore.openLoginDialog();
}
},
};