opt: update the main chat compnent after updating the user profile

This commit is contained in:
RockYang 2023-06-15 11:29:16 +08:00
parent 1e84332119
commit 088fd14c03
3 changed files with 18 additions and 12 deletions

View File

@ -69,7 +69,7 @@ func (h *ChatHandler) ChatHandle(c *gin.Context) {
session.ChatId = chatId
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)
var chatRole model.ChatRole
res = h.db.First(&chatRole, roleId)

View File

@ -73,6 +73,7 @@ import {ElMessage} from "element-plus";
const props = defineProps({
show: Boolean,
user: Object,
models: Array,
});
@ -102,6 +103,8 @@ const save = function () {
appendTo: document.getElementById('user-info'),
onClose: () => emits('update:show', false)
})
//
emits('update-user', {nickname:form.value['nickname'], avatar: form.value['avatar']});
}).catch(() => {
ElMessage.error({
message: '更新失败',

View File

@ -169,7 +169,7 @@
</el-main>
</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>
@ -213,29 +213,28 @@ const mainWinHeight = ref(0); // 主窗口高度
const chatBoxHeight = ref(0); //
const leftBoxHeight = ref(0);
const loading = ref(true);
const user = getLoginUser();
const user = ref(getLoginUser());
const roles = ref([]);
const roleId = ref(0)
const newChatItem = ref(null);
const router = useRouter();
const showConfigDialog = ref(false);
if (!user) {
if (!user.value) {
router.push("login");
} else {
onMounted(() => {
resizeElement();
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;
roleId.value = roles.value[0]['id'];
//
loadChats();
//
newChat();
}).catch((e) => {
console.log(e)
}).catch(() => {
ElMessage.error('获取聊天角色失败')
})
}).catch(() => {
@ -247,8 +246,7 @@ if (!user) {
ElMessage.success('复制成功!');
})
clipboard.on('error', (e) => {
console.log(e)
clipboard.on('error', () => {
ElMessage.error('复制失败!');
})
});
@ -274,7 +272,7 @@ const checkSession = 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) {
chatList.value = res.data;
allChats.value = res.data;
@ -355,7 +353,6 @@ const editChatTitle = function (event, chat) {
//
const confirm = function (event, chat) {
console.log(chat)
event.stopPropagation();
if (curOpt.value === 'edit') {
if (tmpChatTitle.value === '') {
@ -556,7 +553,7 @@ const sendMessage = function () {
chatData.value.push({
type: "prompt",
id: randString(32),
icon: user['avatar'],
icon: user.value.avatar,
content: renderInputText(prompt.value),
created_at: new Date().getTime(),
});
@ -596,6 +593,7 @@ const clearAllChats = function () {
ElMessage.success("操作成功!");
chatData.value = [];
chatList.value = [];
newChat();
}).catch(e => {
ElMessage.error("操作失败:" + e.message)
})
@ -687,6 +685,11 @@ const searchChat = function () {
}
chatList.value = roles;
}
const updateUser = function (data) {
user.value.avatar = data.avatar;
user.value.nickname = data.nickname;
}
</script>
<style lang="stylus">