<template>
  <view class="wh-full">
    <BasicLoading
      :isShow="isShow"
      bgColor="#fff"
      isShowTitle
      textColor="#000"
      title="启动中..."
      :type="1"
    />
  </view>
</template>

<script lang="ts" setup>
import {onLoad} from "@dcloudio/uni-app";
import {useDataStore} from "@/store/modules/data";
import {useUserStore} from "@/store/modules/user";
import {checkOpenId} from "@/api/system/login";

const { setGlobal } = useDataStore();
const { afterLoginAction } = useUserStore();
const isShow = ref(true);

function toHome(data: any) {
  if (data.type == 1 || data.type == 2) {
    uni.reLaunch({
      url: "/pages/base/course-selection/notice",
    });
  } else {
    uni.reLaunch({
      url: "/pages/base/home/index",
    });
  }
}

onLoad(async (data: any) => {
  console.log(data);
  setGlobal(data);
  if (data && data.openId) {
    checkOpenId({ openId: data.openId, appCode: "JZ" })
      .then(async (res) => {
        if (res.resultCode == 1) {
          if (res.result) {
            afterLoginAction(res.result);
            toHome(data);
          } else {
            uni.reLaunch({
              url: "/pages/system/login/login",
            });
          }
        }
      })
      .catch((err) => {});
  }
});
</script>
