2023-11-27 17:18:03 +08:00
|
|
|
|
<script setup>
|
2024-01-22 14:49:29 +08:00
|
|
|
|
import { Push } from '@/common/push'
|
|
|
|
|
import mitt from "@/utils/mitt";
|
2024-01-22 18:08:02 +08:00
|
|
|
|
import {useRoute, useRouter} from "vue-router";
|
|
|
|
|
import { useAppStore } from "@/store/app.js";
|
|
|
|
|
|
2024-01-22 14:49:29 +08:00
|
|
|
|
|
|
|
|
|
const route = useRoute();
|
2024-01-22 18:08:02 +08:00
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
|
|
const appSotre = useAppStore();
|
2024-01-22 14:49:29 +08:00
|
|
|
|
|
2024-01-22 18:08:02 +08:00
|
|
|
|
const refresh = ()=>{ //刷新命令
|
|
|
|
|
console.log(route.path=='/index');
|
|
|
|
|
if(route.path=='/index'){
|
|
|
|
|
if(appSotre.address.areaCode) router.push({
|
|
|
|
|
path: '/index',
|
|
|
|
|
query:{
|
|
|
|
|
areaCode: appSotre.address.areaCode
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
else router.push({
|
|
|
|
|
path: '/index'
|
|
|
|
|
})
|
|
|
|
|
}else location.reload();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const back = ()=>{
|
|
|
|
|
if(route.path!='/index'){
|
|
|
|
|
if(appSotre.address.areaCode) router.push({
|
|
|
|
|
path: '/index',
|
|
|
|
|
query:{
|
|
|
|
|
areaCode: appSotre.address.areaCode
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
else router.push({
|
|
|
|
|
path: '/index'
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-22 14:49:29 +08:00
|
|
|
|
|
2024-01-22 18:08:02 +08:00
|
|
|
|
const connection = new Push({
|
|
|
|
|
url: 'wss://chat.lihaink.cn/tts', // websocket地址
|
2024-01-22 14:49:29 +08:00
|
|
|
|
app_key: 'aaea61749929eb53a4bd75a1474c1d27',
|
|
|
|
|
});
|
|
|
|
|
// 假设用户uid为1
|
2024-01-22 18:08:02 +08:00
|
|
|
|
const uid = 5;
|
2024-01-22 14:49:29 +08:00
|
|
|
|
// 浏览器监听user-2频道的消息,也就是用户uid为1的用户消息
|
2024-01-22 18:08:02 +08:00
|
|
|
|
const user_channel = connection.subscribe('user-' + uid);
|
2024-01-22 14:49:29 +08:00
|
|
|
|
|
|
|
|
|
// 当user-2频道有message事件的消息时
|
|
|
|
|
user_channel.on('message', function (data) {
|
2024-01-22 18:08:02 +08:00
|
|
|
|
if(data.content.event=='refresh') refresh();
|
|
|
|
|
if(data.content.event=='back') back();
|
|
|
|
|
else mitt.emit(data.content.event, data.content.data);
|
2024-01-22 14:49:29 +08:00
|
|
|
|
|
|
|
|
|
console.log("收到消息--",data)
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
// 断线事件
|
|
|
|
|
user_channel.on('close', function () {
|
|
|
|
|
|
|
|
|
|
});
|
2023-11-27 17:18:03 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
2023-12-05 18:39:17 +08:00
|
|
|
|
<router-view></router-view>
|
2023-11-27 17:18:03 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
* {
|
|
|
|
|
margin: 0;
|
|
|
|
|
padding: 0;
|
|
|
|
|
}
|
|
|
|
|
</style>
|