hi-ucs/front/src/App.vue

72 lines
1.9 KiB
Vue
Raw Normal View History

2022-06-14 09:32:49 +08:00
<!--
* @Author: hisense.wuhongjian
* @Date: 2022-05-06 11:12:00
2022-07-21 15:36:01 +08:00
* @LastEditors: hisense.liangjunhua
2022-07-26 14:05:58 +08:00
* @LastEditTime: 2022-07-26 11:27:50
2022-06-14 09:32:49 +08:00
* @Description: 告诉大家这是什么
-->
<template>
<div id="vue-admin-beautiful">
<a-config-provider :locale="locale">
<router-view />
</a-config-provider>
</div>
</template>
2022-07-21 15:36:01 +08:00
<script setup>
2022-06-14 09:32:49 +08:00
import zhCN from 'ant-design-vue/es/locale/zh_CN'
2022-07-21 15:36:01 +08:00
import Cookies from 'js-cookie'
import { onBeforeUnmount } from 'vue'
import { useRouter } from 'vue-router'
2022-07-21 15:36:01 +08:00
import mybus from '@/myplugins/mybus'
const router = useRouter()
2022-06-14 09:32:49 +08:00
2022-07-21 15:36:01 +08:00
// export default {
// name: 'App',
// data() {
// return {
// ,
// }
// },
// }
const locale = zhCN
const token = Cookies.get('ucsToken')
console.log('token=================>', token)
2022-07-26 14:05:58 +08:00
let ws = new WebSocket(
2022-07-21 15:36:01 +08:00
`ws://${window.SITE_CONFIG['websocketURL']}/websocket?token=${token}`
)
// ws.send()给服务器发送信息
// 服务器每次返回信息都会执行一次onmessage方法
ws.onmessage = function (e) {
2022-07-26 14:05:58 +08:00
console.log('WebSocket服务器返回的信息: ' + e.data)
2022-07-21 15:36:01 +08:00
mybus.emit('getMynotice')
// 判断当前路由是否是消息中心
if (router.currentRoute.value.name === 'mynoticeView') {
mybus.emit('noticeListInit')
}
2022-06-14 09:32:49 +08:00
}
2022-07-26 14:05:58 +08:00
ws.onerror = function (e) {
console.log('WebSocket连接异常============================>', e)
ws = new WebSocket(
`ws://${window.SITE_CONFIG['websocketURL']}/websocket?token=${token}`
)
}
ws.onclose = function (e) {
console.log('WebSocket连接断开============================>', e)
}
2022-07-21 15:36:01 +08:00
onBeforeUnmount(() => {
// 4.卸载前, 关闭链接
ws.close()
})
2022-06-14 09:32:49 +08:00
</script>
<style lang="less">
@import '~@/vab/styles/vab.less';
2022-07-20 15:01:14 +08:00
#vue-admin-beautiful {
2022-06-21 17:06:05 +08:00
max-width: 1920px;
2022-07-06 18:42:23 +08:00
// max-height: 1080px;
2022-06-21 17:06:05 +08:00
margin: auto;
height: 100%;
position: relative;
2022-07-20 15:01:14 +08:00
background-color: #fff;
2022-06-21 17:06:05 +08:00
}
2022-06-14 09:32:49 +08:00
</style>