index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <!-- @format -->
  2. <script setup lang="ts">
  3. import { useUserStore } from '@/stores/modules/user'
  4. const userStore = useUserStore()
  5. const { isLogin, userInfo } = storeToRefs(userStore)
  6. const { openLoginModal } = useLoginModal()
  7. const userName = computed(() => {
  8. console.log('userInfo.value', userInfo.value)
  9. return (userInfo.value?.firstName || userInfo.value?.lastName) ? `${userInfo.value?.firstName} ${userInfo.value?.lastName}` : 'EJET Spark'
  10. })
  11. async function clickLogin() {
  12. try {
  13. const { status } = await openLoginModal()
  14. console.log('Login status:', status)
  15. // if (status)
  16. // location.reload()
  17. }
  18. catch (error) {
  19. console.log(error)
  20. }
  21. }
  22. function onLogout() {
  23. userStore.logout()
  24. }
  25. </script>
  26. <template>
  27. <div>
  28. <div v-if="!isLogin">
  29. <el-button
  30. class="!b-0px !bg-#9B6CFF custom-btn-login !text-#fff !w-100px !h-32px !text-16px !b-rd-410px"
  31. @click="clickLogin"
  32. >
  33. Sign In
  34. </el-button>
  35. </div>
  36. <div v-else>
  37. <el-popover
  38. placement="bottom-end"
  39. :width="360"
  40. >
  41. <template #reference>
  42. <div class="b-rd-50% w-40px h-40px fw-800 text-#9B6CFF lh-40px text-center bg-#EAE5FA text-#3D3D3D cursor-pointer">
  43. {{ userName.charAt(0) }}
  44. </div>
  45. </template>
  46. <template #default>
  47. <div class=" bg-#fff b-rd-8px flex justify-between items-center">
  48. <div class="flex items-center">
  49. <div class="b-rd-50% w-40px fw-800 h-40px lh-40px text-center text-#9B6CFF bg-#EAE5FA text-#3D3D3D cursor-pointer">
  50. {{ userName.charAt(0) }}
  51. </div>
  52. <div class="ml-18px">
  53. <div class="custom-title-font text-#333 text-18px">
  54. {{ userName }}
  55. </div>
  56. <div class="mt-4px text-#767676">
  57. {{ userInfo?.email }}
  58. </div>
  59. </div>
  60. </div>
  61. <div class="cursor-pointer" @click="onLogout">
  62. <img src="@/assets/images/logout.png" class="w-24px h-24px" alt="">
  63. </div>
  64. </div>
  65. </template>
  66. </el-popover>
  67. </div>
  68. </div>
  69. </template>
  70. <style lang="less">
  71. .custom-btn-login {
  72. .el-icon {
  73. font-size: 24px;
  74. }
  75. }
  76. .el-popover.el-popper{
  77. border-radius: 10px!important;
  78. margin-top: 10px;
  79. padding: 20px!important;
  80. padding-right: 30px !important;
  81. }
  82. .custom-dropdown {
  83. &.el-dropdown__popper {
  84. border-radius: 10px;
  85. .el-scrollbar {
  86. .el-dropdown__list {
  87. width: 415px;
  88. padding: 30px !important;
  89. }
  90. .el-dropdown-menu {
  91. .el-dropdown-menu__item {
  92. padding-bottom: 20px;
  93. padding-left: 0 !important;
  94. padding-right: 0 !important;
  95. padding-top: 0 !important;
  96. &:last-child {
  97. padding-bottom: 0;
  98. }
  99. }
  100. }
  101. }
  102. }
  103. }
  104. </style>