<script>
import storage from "@/utils/storage.js";
export default {
  onLaunch: function() {
    console.log('App Launch');
    this.checkLoginStatus();
  },
  onShow: function() {
    console.log('App Show');
  },
  onHide: function() {
    console.log('App Hide');
  },
  methods: {
    checkLoginStatus() {
      // 登录状态检查，对敏感页面进行拦截
      const pages = ['pages/dashboard/index', 'pages/user/index', 'pages/activity/index', 'pages/device/index']; 
      
      uni.addInterceptor('navigateTo', {
        invoke(e) {
          const url = e.url;
          // 检查是否属于需要登录的页面
          const needLogin = pages.some(page => url.indexOf(page) > -1);
          
          if (needLogin && !storage.isLoggedIn()) {
            uni.navigateTo({
              url: '/pages/login/index'
            });
            return false;
          }
          return true;
        }
      });
      
      uni.addInterceptor('switchTab', {
        invoke(e) {
          const url = e.url;
          // 检查是否属于需要登录的页面
          const needLogin = pages.some(page => url.indexOf(page) > -1);
          
          if (needLogin && !storage.isLoggedIn()) {
            uni.navigateTo({
              url: '/pages/login/index'
            });
            return false;
          }
          return true;
        }
      });
    }
  }
}
</script>

<template>
  <view class="content">
    <slot />
  </view>
</template>

<style>
/* 全局基础样式 */
page {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
  font-size: 28rpx;
  line-height: 1.5;
  color: #333;
  background-color: #f5f5f5;
}

/* 去除按钮默认边框 */
button::after {
  border: none;
}

/* 隐藏滚动条 */
::-webkit-scrollbar {
  width: 0;
  height: 0;
  color: transparent;
}
</style>
