| 123456789101112131415161718192021222324252627282930313233343536 |
- <script>
- import { getToken, setToken, getCurrentUserInfo } from './utils/api'
- import { useWebSocket } from './composables/useWebSocket'
- import { setupAppNotifications } from './utils/notificationSetup'
- export default {
- onLaunch: async function() {
- try {
- const token = getToken()
- if (!token) {
- uni.reLaunch({ url: '/pages/login/index' })
- return
- }
- await getCurrentUserInfo(token)
- // token 有效时建立 WebSocket,保证任意页面都能实时收消息(含聊天页)
- useWebSocket(() => {}).connect()
- // #ifdef APP-PLUS
- setupAppNotifications()
- // #endif
- } catch (e) {
- setToken('')
- uni.reLaunch({ url: '/pages/login/index' })
- }
- },
- onShow: function() {
- console.log('App Show')
- },
- onHide: function() {
- console.log('App Hide')
- }
- }
- </script>
- <style>
- /*每个页面公共css */
- </style>
|