index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <div class="root">
  3. <a-menu mode="horizontal" class="menu" :selected-keys="['99']">
  4. <a-menu-item key="0"
  5. :style="{ cursor: 'pointer', padding: 0, marginRight: '650px', background: 'transparent', color: props.color }"
  6. disabled>
  7. <div class="logo" @click="$router.push('/')">
  8. <img alt="RunForge" src="/logo.svg" height="40">
  9. <span class="title">RunForge</span>
  10. </div>
  11. </a-menu-item>
  12. <a-menu-item key="4" :style="{ background: 'transparent', color: props.color }" v-if="!user"
  13. @click="$router.push('/login')">
  14. 用户登录
  15. </a-menu-item>
  16. <a-sub-menu key="5" :style="{ background: 'transparent', color: props.color }" v-else>
  17. <template #expand-icon-down></template>
  18. <template #title>
  19. <div class="userinfo">
  20. <a-avatar :size="30"><img alt="avatar" :src="user.avatar" /></a-avatar>
  21. <span>{{ user.username }}</span>
  22. </div>
  23. </template>
  24. <a-menu-item key="5_0" @click="$router.push('/user')"><icon-user /> 个人中心</a-menu-item>
  25. <a-menu-item key="5_1" @click="logout"><icon-export /> 退出登录</a-menu-item>
  26. </a-sub-menu>
  27. </a-menu>
  28. </div>
  29. </template>
  30. <script setup>
  31. import { useUserStore } from '@/store/modules/user'
  32. import { ref } from 'vue'
  33. import { Message, Modal } from '@arco-design/web-vue'
  34. const props = defineProps({
  35. color: {
  36. type: String,
  37. default: 'black'
  38. }
  39. })
  40. const user = ref('')
  41. const getuser = async () => {
  42. const userStore = useUserStore()
  43. let userInfo = await userStore.getInfo()
  44. if (userInfo?.avatar && userInfo?.username && userInfo?.uuid && userInfo?.session)
  45. user.value = userInfo
  46. }
  47. const logout = () => {
  48. Modal.confirm({
  49. title: '退出登录',
  50. content: '您即将退出登录,是否继续?',
  51. onOk: () => {
  52. const userStore = useUserStore()
  53. userStore.logout()
  54. Message.success('退出成功!')
  55. setTimeout(() => { window.location.reload() }, 1000)
  56. },
  57. onCancel: () => {
  58. }
  59. });
  60. }
  61. getuser()
  62. </script>
  63. <style scoped>
  64. .root {
  65. position: absolute;
  66. top: 0;
  67. left: 50%;
  68. transform: translateX(-50%);
  69. width: 80%;
  70. min-width: 1280px;
  71. z-index: 100;
  72. user-select: none;
  73. }
  74. .menu {
  75. width: 100%;
  76. background: transparent;
  77. }
  78. .logo {
  79. display: flex;
  80. }
  81. .logo span {
  82. font-size: 1.5em;
  83. margin: 5px 8px;
  84. }
  85. .userinfo {
  86. margin-top: -15px;
  87. transform: translateY(23px);
  88. }
  89. .userinfo span {
  90. margin-left: 7px;
  91. }
  92. </style>