index.vue 2.8 KB

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