86 lines
2.0 KiB
Vue
86 lines
2.0 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'
|
||
})
|
||
}
|
||
}
|
||
|
||
// 获取 URL 中的查询参数部分
|
||
const queryString = window.location.search;
|
||
|
||
// 解析查询参数字符串
|
||
const searchParams = new URLSearchParams(queryString);
|
||
|
||
// 读取名为 id 的参数
|
||
const uid = searchParams.get('local') || localStorage.getItem('local');
|
||
|
||
if(searchParams.get('local')) localStorage.setItem('local', searchParams.get('local'));
|
||
|
||
const connection = new Push({
|
||
url: 'wss://chat.lihaink.cn/tts', // websocket地址
|
||
app_key: 'aaea61749929eb53a4bd75a1474c1d27',
|
||
});
|
||
|
||
// 浏览器监听user-2频道的消息,也就是用户uid为1的用户消息
|
||
const user_channel = connection.subscribe(uid + 'user-logistics-datav');
|
||
|
||
// 当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>
|