<script>
	import { getToken, setToken, getCurrentUserInfo } from './utils/api'
	import { useWebSocket } from './composables/useWebSocket'

	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()
			} 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>
