123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <script>
- import WebSocketManager from '@/utils/WebSocketManager.js';
- import { watch } from 'vue';
- import store from '@/store'
- export default {
- data:{
- userId: uni.getStorageSync('userId') //读取本地存储
- },
- onLaunch: function () {
- console.log('App Launch')
-
- },
- onShow: function () {
- console.log('App Show')
- },
- onHide: function () {
- console.log('App Hide')
- },
- watch: {
- userId: {
- handler() {
- console.log('yong---------------',this.userId);
- const wsManager = new WebSocketManager(this.userId);
- // 设置消息回调
- wsManager.onMessage(data => {
- console.log('app-接收到的消息:', data);
- // 处理消息逻辑
- if(data.type === 'msgUnreadCount'){
- store.dispatch('handleMessageCount',data.data)
- }
- });
- // 建立连接
- wsManager.connect();
- },
- immediate: true,
- deep: true
- }
- },
- }
- </script>
- <style lang="scss">
- @import "uview-plus/index.scss";
- @import '@/static/scss/index.scss';
- </style>
|