<script setup>
import config from "./config";
import store from "@/store";
import { getToken, setToken, removeToken } from "@/utils/auth";

import { defineComponent, getCurrentInstance, inject, nextTick, onMounted, watchEffect } from "vue";
import { onLoad, onShow, onHide, onLaunch, onReady } from "@dcloudio/uni-app";

let tab = inject("$tab");
const { proxy } = getCurrentInstance();

function initApp() {
  // 初始化应用配置
  initConfig();
  // 检查用户登录状态
  //#ifdef H5
  // checkLogin();
  //#endif

  //初始化获取安全区高度
  proxy.$settingStore.systemHeightTop();
}

function initConfig() {
  getApp().globalData.config = config;
}

function checkLogin() {
  if (!getToken()) {
    proxy.$tab.reLaunch("/pages/login");
  }
}

watchEffect(() => {
  //#ifdef APP-PLUS
  if (uni.getStorageSync("serveUrl")) {
    config.baseUrl = "http://" + uni.getStorageSync("serveUrl") + "/prod-api";
  }
  //#endif
});

onLaunch(() => {
  console.log("App Launch");
  uni.hideTabBar(); //隐藏自带tabbar

  // #ifdef APP-PLUS
  plus.screen.lockOrientation("portrait-primary"); //设置不可横屏
  // #endif

  //初始化默认主题
  if (!proxy.$settingStore.$state.themeColor) {
    proxy.$settingStore.SET_THEMECOLOR(proxy.$constData.themeList[0]);
  } else {
    proxy.$settingStore.SET_THEMECOLOR(proxy.$settingStore.$state.themeColor);
  }

  // setToken(
  //   "eyJhbGciOiJIUzUxMiJ9.eyIiOjEwMzIsInVzZXJfaWQiOjYzLCJ1c2VyX2tleSI6IjYwMjNkZjg1OTIyODRlYTM5MmEwMWEzMzgyOTViZmRhIiwidXNlcm5hbWUiOiJmaHMxIn0.6GsrVyPh7T3vWmX6iB1fPv3wi-noOtgGcrDwBPctB3LLGcWqw89He6DK7waMCWZFBsOy0HLRD2PJdQs489hAxw"
  // );
  // proxy.$tab.reLaunch("/pages/mine/index");
  // proxy.$tab.reLaunch("/pages/index");
  // proxy.$tab.reLaunch("/pages/info/info");
  // proxy.$tab.reLaunch("/pages/business/mhxf/xunJian/collect/index");

  initApp();
});

onLoad(() => {});

onReady(() => {});

onShow(() => {
  console.log("App Show");
});

onHide(() => {
  console.log("App Hide");
});
</script>

<style lang="scss">
@import "@/static/scss/index.scss";
</style>

<style lang="scss">
@import "@/uni_modules/uview-plus/index.scss";

uni-page-body,
uni-page-refresh {
  height: 100%;
}

//默认返回按钮样式
:deep(.uni-page-head-btn) {
  background-color: rgba(0, 0, 0, 0) !important;
}

//默认头部导航title样式
:deep(.uni-page-head__title) {
  font-size: 16px;
  font-weight: 600;
}

//uview-plus导航栏title样式
:deep(.u-navbar__content__title) {
  font-size: 16px;
  font-weight: bold;
}

:deep(.u-nav-slot .u-navbar__content__title) {
  font-size: 18px;
}
</style>
