76 lines
1.6 KiB
Vue
76 lines
1.6 KiB
Vue
<script setup>
|
||
import { Push } from '@/common/push'
|
||
import mitt from "@/utils/mitt";
|
||
import {useRoute, useRouter} from "vue-router";
|
||
import { useAppStore } from "@/store/app.js";
|
||
|
||
|
||
const route = useRoute();
|
||
const router = useRouter();
|
||
|
||
const appSotre = useAppStore();
|
||
|
||
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'
|
||
})
|
||
}
|
||
}
|
||
|
||
const connection = new Push({
|
||
url: 'wss://chat.lihaink.cn/tts', // websocket地址
|
||
app_key: 'aaea61749929eb53a4bd75a1474c1d27',
|
||
});
|
||
// 假设用户uid为1
|
||
const uid = 5;
|
||
// 浏览器监听user-2频道的消息,也就是用户uid为1的用户消息
|
||
const user_channel = connection.subscribe('user-' + uid);
|
||
|
||
// 当user-2频道有message事件的消息时
|
||
user_channel.on('message', function (data) {
|
||
if(data.content.event=='refresh') refresh();
|
||
if(data.content.event=='back') back();
|
||
else mitt.emit(data.content.event, data.content.data);
|
||
|
||
console.log("收到消息--",data)
|
||
|
||
});
|
||
// 断线事件
|
||
user_channel.on('close', function () {
|
||
|
||
});
|
||
</script>
|
||
|
||
<template>
|
||
<router-view></router-view>
|
||
</template>
|
||
|
||
<style scoped lang="scss">
|
||
* {
|
||
margin: 0;
|
||
padding: 0;
|
||
}
|
||
</style>
|