<template>
  <ie-page>
    <ie-navbar title="hahah" />
    <view>1111</view>
  </ie-page>
</template>

<script lang="ts" setup>
import { useTransferPage } from '@/hooks/useTransferPage';
import { useUserStore } from '@/store/userStore';

const userStore = useUserStore();
const { prevData, transferTo, routes } = useTransferPage();
const initSuccess = ref(false);
const loading = ref(false);

const init = async () => {
  const { token, redirect, params } = prevData.value;
  console.log('开始初始化')
  console.log(prevData.value)
  if (token) {
    loading.value = true;
    try {
      const { success, userInfo } = await userStore.login(token);
      if (success) {
        let pageUrl = '';
        // if (params) {
        //   const parseParams = JSON.parse(params);
        //   Object.entries(parseParams).forEach(([key, value]) => {
        //     pageUrl += `${key}=${value}&`;
        //   });
        // }
        initSuccess.value = true;
        pageUrl = pageUrl ? `?${pageUrl}` : '';
        console.log('pageUrl', pageUrl)
        console.log('redirect', redirect)
        transferTo(`${redirect}${pageUrl}`, {
          type: 'navigateTo'
        });
      }
    } catch (error) {
      initSuccess.value = false;
    } finally {
      loading.value = false;
    }
  } else {
    initSuccess.value = false;
  }
}
onLoad(() => {
  init();
});
</script>

<style lang="scss"></style>