<template>
  <router-view />
  <chat-g-p-t-button v-if="$website.aiSwitch"/>
</template>

<script setup>
import { useRouter } from 'vue-router';
import { onMounted } from 'vue';
import { getList } from '@/api/glob'
const { currentRoute } = useRouter();

onMounted(async () => {
  if (currentRoute.value.query.token) {
    window.$website.clientOption.accessToken = currentRoute.value.query.token; 
    localStorage.setItem(window.$website.clientOption.accessToken, currentRoute.value.query.token);

    console.log(currentRoute.value.query.token, "currentRoute.value.query.toke",window.$website)

    console.log(currentRoute.value.query.token, "currentRoute.value.query.toke",window.$website)


  }

  await initGlob();
})
  async function initGlob () {
      try {
          let res = await getList({current: 1,size: 100,})
          if(res&&res.data&&res.data.data&&res.data.data.records&&res.data.data.records.length>0){
          res.data.data.records.forEach(ele => {
              window.$glob[ele.globalKey] = ele.globalValue
            })
          }
        
      } catch (error) {
        console.log('error: ', error);
        
      }

    }

</script>
 