mirror of
https://github.com/yangjian102621/geekai.git
synced 2025-09-18 09:16:39 +08:00
opt: update the main chat compnent after updating the user profile
This commit is contained in:
parent
1e84332119
commit
088fd14c03
@ -69,7 +69,7 @@ func (h *ChatHandler) ChatHandle(c *gin.Context) {
|
|||||||
|
|
||||||
session.ChatId = chatId
|
session.ChatId = chatId
|
||||||
session.Model = chatModel
|
session.Model = chatModel
|
||||||
logger.Infof("New websocket connected, IP: %s, UserId: %s", c.Request.RemoteAddr, session.Username)
|
logger.Infof("New websocket connected, IP: %s, Username: %s", c.Request.RemoteAddr, session.Username)
|
||||||
client := core.NewWsClient(ws)
|
client := core.NewWsClient(ws)
|
||||||
var chatRole model.ChatRole
|
var chatRole model.ChatRole
|
||||||
res = h.db.First(&chatRole, roleId)
|
res = h.db.First(&chatRole, roleId)
|
||||||
|
@ -73,6 +73,7 @@ import {ElMessage} from "element-plus";
|
|||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
show: Boolean,
|
show: Boolean,
|
||||||
|
user: Object,
|
||||||
models: Array,
|
models: Array,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -102,6 +103,8 @@ const save = function () {
|
|||||||
appendTo: document.getElementById('user-info'),
|
appendTo: document.getElementById('user-info'),
|
||||||
onClose: () => emits('update:show', false)
|
onClose: () => emits('update:show', false)
|
||||||
})
|
})
|
||||||
|
// 更新用户数据
|
||||||
|
emits('update-user', {nickname:form.value['nickname'], avatar: form.value['avatar']});
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
ElMessage.error({
|
ElMessage.error({
|
||||||
message: '更新失败',
|
message: '更新失败',
|
||||||
|
@ -169,7 +169,7 @@
|
|||||||
</el-main>
|
</el-main>
|
||||||
</el-container>
|
</el-container>
|
||||||
|
|
||||||
<config-dialog v-model:show="showConfigDialog" :models="models"></config-dialog>
|
<config-dialog v-model:show="showConfigDialog" :models="models" @update-user="updateUser"></config-dialog>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
@ -213,29 +213,28 @@ const mainWinHeight = ref(0); // 主窗口高度
|
|||||||
const chatBoxHeight = ref(0); // 聊天内容框高度
|
const chatBoxHeight = ref(0); // 聊天内容框高度
|
||||||
const leftBoxHeight = ref(0);
|
const leftBoxHeight = ref(0);
|
||||||
const loading = ref(true);
|
const loading = ref(true);
|
||||||
const user = getLoginUser();
|
const user = ref(getLoginUser());
|
||||||
const roles = ref([]);
|
const roles = ref([]);
|
||||||
const roleId = ref(0)
|
const roleId = ref(0)
|
||||||
const newChatItem = ref(null);
|
const newChatItem = ref(null);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const showConfigDialog = ref(false);
|
const showConfigDialog = ref(false);
|
||||||
|
|
||||||
if (!user) {
|
if (!user.value) {
|
||||||
router.push("login");
|
router.push("login");
|
||||||
} else {
|
} else {
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
resizeElement();
|
resizeElement();
|
||||||
checkSession().then(() => {
|
checkSession().then(() => {
|
||||||
// 加载角色列表
|
// 加载角色列表
|
||||||
httpGet(`/api/chat/role/list?user_id=${user.id}`).then((res) => {
|
httpGet(`/api/chat/role/list?user_id=${user.value.id}`).then((res) => {
|
||||||
roles.value = res.data;
|
roles.value = res.data;
|
||||||
roleId.value = roles.value[0]['id'];
|
roleId.value = roles.value[0]['id'];
|
||||||
// 获取会话列表
|
// 获取会话列表
|
||||||
loadChats();
|
loadChats();
|
||||||
// 创建新的会话
|
// 创建新的会话
|
||||||
newChat();
|
newChat();
|
||||||
}).catch((e) => {
|
}).catch(() => {
|
||||||
console.log(e)
|
|
||||||
ElMessage.error('获取聊天角色失败')
|
ElMessage.error('获取聊天角色失败')
|
||||||
})
|
})
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
@ -247,8 +246,7 @@ if (!user) {
|
|||||||
ElMessage.success('复制成功!');
|
ElMessage.success('复制成功!');
|
||||||
})
|
})
|
||||||
|
|
||||||
clipboard.on('error', (e) => {
|
clipboard.on('error', () => {
|
||||||
console.log(e)
|
|
||||||
ElMessage.error('复制失败!');
|
ElMessage.error('复制失败!');
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@ -274,7 +272,7 @@ const checkSession = function () {
|
|||||||
|
|
||||||
// 加载会话
|
// 加载会话
|
||||||
const loadChats = function () {
|
const loadChats = function () {
|
||||||
httpGet("/api/chat/list?user_id=" + user.id).then((res) => {
|
httpGet("/api/chat/list?user_id=" + user.value.id).then((res) => {
|
||||||
if (res.data) {
|
if (res.data) {
|
||||||
chatList.value = res.data;
|
chatList.value = res.data;
|
||||||
allChats.value = res.data;
|
allChats.value = res.data;
|
||||||
@ -355,7 +353,6 @@ const editChatTitle = function (event, chat) {
|
|||||||
|
|
||||||
// 确认修改
|
// 确认修改
|
||||||
const confirm = function (event, chat) {
|
const confirm = function (event, chat) {
|
||||||
console.log(chat)
|
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
if (curOpt.value === 'edit') {
|
if (curOpt.value === 'edit') {
|
||||||
if (tmpChatTitle.value === '') {
|
if (tmpChatTitle.value === '') {
|
||||||
@ -556,7 +553,7 @@ const sendMessage = function () {
|
|||||||
chatData.value.push({
|
chatData.value.push({
|
||||||
type: "prompt",
|
type: "prompt",
|
||||||
id: randString(32),
|
id: randString(32),
|
||||||
icon: user['avatar'],
|
icon: user.value.avatar,
|
||||||
content: renderInputText(prompt.value),
|
content: renderInputText(prompt.value),
|
||||||
created_at: new Date().getTime(),
|
created_at: new Date().getTime(),
|
||||||
});
|
});
|
||||||
@ -596,6 +593,7 @@ const clearAllChats = function () {
|
|||||||
ElMessage.success("操作成功!");
|
ElMessage.success("操作成功!");
|
||||||
chatData.value = [];
|
chatData.value = [];
|
||||||
chatList.value = [];
|
chatList.value = [];
|
||||||
|
newChat();
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
ElMessage.error("操作失败:" + e.message)
|
ElMessage.error("操作失败:" + e.message)
|
||||||
})
|
})
|
||||||
@ -687,6 +685,11 @@ const searchChat = function () {
|
|||||||
}
|
}
|
||||||
chatList.value = roles;
|
chatList.value = roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const updateUser = function (data) {
|
||||||
|
user.value.avatar = data.avatar;
|
||||||
|
user.value.nickname = data.nickname;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="stylus">
|
<style lang="stylus">
|
||||||
|
Loading…
Reference in New Issue
Block a user