<script>
	import { getUnreadCount } from './api/message.js';
	import { messageStore } from './store/message.js';
	export default {
		onLaunch: function() { // 强制刷新页面路由配置 - 2026-03-15 16:32
			console.log('App Launch - Route Refresh - My Secondary Pages') // Final Build Trigger
			// 自动登录：如果本地有缓存的 token，直接跳转首页，无需再走登录流程
			const token = uni.getStorageSync('token');
			if (token) {
				uni.switchTab({
					url: '/pages/jobs/jobs',
					fail: () => {
						uni.reLaunch({ url: '/pages/jobs/jobs' });
					}
				});
			}
		},
		onShow: function() {
			console.log('App Show');
			const token = uni.getStorageSync('token');
			if (!token) {
				// 未登录时重置未读数为 0
				messageStore.setUnreadCount(0);
				return;
			}
			// 每次进入前台都刷新真实未读数
			getUnreadCount()
				.then(res => {
					if (res && res.code === 200 && typeof res.data === 'number') {
						messageStore.setUnreadCount(res.data);
					}
				})
				.catch(() => {
					// 失败时保持当前值即可，不提示用户
				});
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	/* 全局样式：强制隐藏所有页面的系统滚动条，提升沉浸式体验 */
	
	/* 针对页面根节点、普通视图和滚动容器 */
	page, view, scroll-view {
		-ms-overflow-style: none; /* IE and Edge */
		scrollbar-width: none; /* Firefox */
		
		&::-webkit-scrollbar {
			display: none !important;
			width: 0 !important;
			height: 0 !important;
			-webkit-appearance: none;
			background: transparent;
			color: transparent;
		}
	}

	/* 额外确保在部分环境下彻底移除 */
	::-webkit-scrollbar {
		display: none !important;
		width: 0 !important;
		height: 0 !important;
	}
</style>
