index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <header v-if="showAdjust">
  3. <div v-if="project">{{ project.projectName }}</div>
  4. </header>
  5. <header v-else>
  6. <div v-if="project">{{ project.projectName }}</div>
  7. <div class="user">
  8. <ul>
  9. <li>
  10. <i class="iconfont icon-share"></i>
  11. </li>
  12. <li><em></em></li>
  13. <li v-if="user" class="uinfo" @click="showDrop = true">
  14. <img :src="user.head + '&x-oss-process=image/resize,m_fill,w_64,h_64/quality,q_70'" alt="" />
  15. <div class="menu">
  16. <ul>
  17. <li><a href="">个人信息</a></li>
  18. <li class="split"></li>
  19. <li><span>退出登录</span></li>
  20. </ul>
  21. </div>
  22. </li>
  23. <li v-else class="login" @click="showLogin = true"><span>登录</span></li>
  24. </ul>
  25. </div>
  26. <Login v-if="showLogin" @close="showLogin = false" @user="info => (user = info)" />
  27. </header>
  28. </template>
  29. <script setup>
  30. import { ref, defineProps, onMounted } from 'vue'
  31. import { http } from '@/utils/request'
  32. import browser from '@/utils/browser'
  33. import Login from './Login'
  34. const props = defineProps({
  35. project: Object,
  36. })
  37. const user = ref(null)
  38. const showLogin = ref(false)
  39. const showAdjust = ref(browser.urlHasValue('adjust'))
  40. const getUserInfo = () => {
  41. http.post(`smart-site/getUserInfo`)
  42. .then(response => {
  43. if (response.success) {
  44. user.value = {
  45. head: response.data.head,
  46. nickName: response.data.nickName,
  47. }
  48. } else {
  49. if (response.code == 4008) {
  50. // 未登录
  51. }
  52. }
  53. })
  54. .catch(() => {})
  55. }
  56. onMounted(() => {
  57. if (localStorage.getItem('token')) {
  58. getUserInfo()
  59. }
  60. })
  61. </script>
  62. <style lang="scss" scoped>
  63. ul,
  64. li {
  65. margin: 0;
  66. padding: 0;
  67. list-style: none;
  68. }
  69. header {
  70. position: relative;
  71. height: 60px;
  72. background-color: #1a1b1d;
  73. display: flex;
  74. justify-content: center;
  75. align-items: center;
  76. font-size: 16px;
  77. }
  78. .user {
  79. position: absolute;
  80. top: 0;
  81. right: 20px;
  82. bottom: 0;
  83. display: flex;
  84. align-items: center;
  85. justify-content: center;
  86. font-size: 14px;
  87. ul {
  88. display: flex;
  89. align-items: center;
  90. justify-content: center;
  91. }
  92. i {
  93. font-size: 18px;
  94. }
  95. em {
  96. margin: 0 20px;
  97. display: inline-block;
  98. width: 1px;
  99. height: 16px;
  100. vertical-align: -2px;
  101. background-color: rgba(255, 255, 255, 0.16);
  102. }
  103. .login {
  104. cursor: pointer;
  105. color: rgba(0, 118, 246, 1);
  106. }
  107. .uinfo {
  108. position: relative;
  109. display: flex;
  110. align-items: center;
  111. justify-content: center;
  112. width: 40px;
  113. height: 40px;
  114. font-size: 14px;
  115. &::after {
  116. content: '';
  117. position: absolute;
  118. right: 3px;
  119. bottom: 4px;
  120. width: 0;
  121. height: 0;
  122. border-color: rgba(255, 255, 255, 0.6) transparent;
  123. border-width: 0 0 5px 5px;
  124. border-style: solid;
  125. }
  126. &:hover{
  127. .menu{
  128. display: block;
  129. }
  130. }
  131. img {
  132. width: 32px;
  133. height: 32px;
  134. border-radius: 50%;
  135. background-size: cover;
  136. border: none;
  137. outline: none;
  138. overflow: hidden;
  139. cursor: pointer;
  140. }
  141. .menu {
  142. display: none;
  143. position: absolute;
  144. top: 40px;
  145. right: 0;
  146. z-index: 2000;
  147. a {
  148. color: #fff;
  149. text-decoration: none;
  150. }
  151. ul {
  152. background-color: #343535;
  153. width: 128px;
  154. flex-direction: column;
  155. border-radius: 4px;
  156. box-shadow: 0 0 4px #333;
  157. padding: 0 10px;
  158. margin-top: 15px
  159. }
  160. li {
  161. height: 45px;
  162. line-height: 45px;
  163. text-align: center;
  164. }
  165. }
  166. }
  167. }
  168. </style>