参会角色变化时,清空local storage中的数据

This commit is contained in:
cxc
2022-06-15 10:33:24 +08:00
parent a53c78fba2
commit 95beed3435
3 changed files with 23 additions and 20 deletions

View File

@ -67,13 +67,14 @@ router.beforeEach(async (to) => {
if (!store.state.meeting.id && to.params.meetingId) {
await store.dispatch("getMeetingInfo", to.params.meetingId);
}
// 当路由类型host,panelist,meeting,supervisor改变时,清空用户信息、消息列表
// if (store.state.routeType !== to.name) {
// store.commit("setMessagesList", []);
// store.commit("setJoinUser", {});
// }
// store.commit("setRouteType", to.name);
if (["Meeting", "Host", "Panelist", "Supervisor"].includes(to.params)) {
// 当参会角色host,panelist,meeting,supervisor改变时,清空用户信息、消息列表
// console.log(["Meeting", "Host", "Panelist", "Supervisor"].includes(to.name));
if (["Meeting", "Host", "Panelist", "Supervisor"].includes(to.name)) {
console.log(to.name);
if (store.state.joinRole && store.state.joinRole !== to.name) {
store.commit("setJoinUser", {});
store.commit("setMessagesList", []);
}
store.commit("setJoinRole", to.name);
}
// 如果前往页面的会议id于之前的不同就清除用户信息、消息列表

View File

@ -46,7 +46,7 @@ const store = createStore({
state.messagesList = data;
localStorage.setItem("MESSAGES", JSON.stringify(data));
},
setjoinRole(state, data) {
setJoinRole(state, data) {
state.joinRole = data;
localStorage.setItem("JOINROLE", data);
},

View File

@ -559,7 +559,8 @@ const initWebSocket = () => {
// 监听websocket消息
socket.addEventListener("message", async (event) => {
// console.log(JSON.parse(event.data));
console.log(JSON.parse(event.data));
console.log(event.data);
let data;
try {
data = JSON.parse(JSON.parse(event.data));
@ -567,7 +568,7 @@ const initWebSocket = () => {
console.log(error);
data = JSON.parse(event.data);
}
console.log(data);
// 会议信息更新时
if (data.type === "isRefreshMeeting") {
await store.dispatch("getMeetingInfo", store.getters.meetingId);
@ -579,10 +580,8 @@ const initWebSocket = () => {
}
// 收到聊天消息时
else if (data.type === "isChat") {
console.log(data.content);
console.log(JSON.parse(JSON.parse(JSON.parse(data.content).msg)));
messages.value.push({
...JSON.parse(JSON.parse(JSON.parse(data.content).msg)),
...JSON.parse(data.content),
id: uniqueId(),
time: dayjs().format("YYYY-MM-DD HH:mm:ss"),
});
@ -654,14 +653,17 @@ initWebSocket();
const messages = ref([]);
messages.value = store.state.messagesList.map((msg) => msg);
const sendMessage = (msgObj) => {
console.log(JSON.stringify(JSON.stringify(msgObj)));
console.log(
JSON.stringify({
account: joinName.value,
msg: msgObj.msg,
})
);
socket.send(
JSON.stringify(
JSON.stringify({
account: joinName.value,
msg: msgObj.msg,
})
)
JSON.stringify({
account: joinName.value,
msg: msgObj.msg,
})
);
messages.value.push(msgObj);
nextTick(() => {