app.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <script setup>
  2. import { ref, onMounted } from 'vue';
  3. import serverConfig from "./serverConfig"
  4. // import AppHeader from './components/AppHeader.vue';
  5. // import language from './assets/language/index.js'
  6. const userInfo = useUserInfoStore()
  7. const layout = ref("default")
  8. onMounted(() => {
  9. setTimeout(() => {
  10. loginData()
  11. }, 10);
  12. window.onresize = () => {
  13. let w = window.innerWidth
  14. console.log(window.innerWidth)
  15. if (w <= 690) {
  16. layout.value = "mobile"
  17. } else {
  18. layout.value = "default"
  19. }
  20. }
  21. })
  22. console.log(process)
  23. const loginData = async () => {
  24. let LoginState = await useFetch(serverConfig.host + '/api/state', {
  25. method: 'GET',
  26. credentials: 'include',
  27. mode: 'cors',
  28. // cache: false
  29. }).then(r => {
  30. return r
  31. })
  32. console.log(LoginState)
  33. if (LoginState.data.value == "Logged") {
  34. Error.value = false
  35. await useFetch(serverConfig.host + '/api/profile', {
  36. method: 'GET',
  37. credentials: 'include',
  38. mode: 'cors',
  39. // cache: false
  40. }).then(r => {
  41. if (r.data.value && r.data.value.username) {
  42. let data = r.data.value
  43. let obj = {
  44. username: data.username,
  45. alias: data.alias,
  46. userid: data.userid,
  47. isLoading: true,
  48. googleId: data.gender,
  49. login: true,
  50. gender: data.gender,
  51. defaultSchool: data.defaultSchool,
  52. defaultAddress: data.defaultAddress,
  53. apiKey: data.apiKey
  54. }
  55. userInfo.value = obj
  56. try {
  57. window.parent.postMessage({ id: 'loginVerify', status: 'logged', data }, "*");
  58. } catch (error) {
  59. console.log(error);
  60. }
  61. }
  62. })
  63. }
  64. }
  65. </script>
  66. <template>
  67. <div>
  68. <NuxtLayout :name="layout">
  69. </NuxtLayout>
  70. </div>
  71. </template>