user-header.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <div>
  3. <header class="header-box">
  4. <div class="logo">DeepBIO</div>
  5. <div class="nav-box">
  6. <div
  7. @click="toNewPage('home')"
  8. :class="[active === 'home' && 'active', 'item']"
  9. >
  10. <i class="el-icon-s-home"></i>Home
  11. </div>
  12. <!-- <div @click="toNewPage('server')" :class="[active === 'server' &&'active', 'item']"><i class="el-icon-s-operation"></i>Server</div>-->
  13. <!-- <div-->
  14. <!-- @click="toNewPage('service')"-->
  15. <!-- :class="[active === 'service' && 'active', 'item']"-->
  16. <!-- >-->
  17. <!-- <i class="el-icon-printer"></i>Service-->
  18. <!-- </div>-->
  19. <div
  20. @click="toNewPage('order')"
  21. :class="[active === 'order' && 'active', 'item']"
  22. >
  23. <i class="el-icon-s-claim"></i>Order
  24. </div>
  25. <!-- <div-->
  26. <!-- @click="toNewPage('task')"-->
  27. <!-- :class="[active === 'task' && 'active', 'item']"-->
  28. <!-- >-->
  29. <!-- <i class="el-icon-s-order"></i>Task-->
  30. <!-- </div>-->
  31. <div
  32. @click="toNewPage('about')"
  33. :class="[active === 'about' && 'active', 'item']"
  34. >
  35. <i class="el-icon-s-order"></i>Contact us
  36. </div>
  37. </div>
  38. <div class="user-box">
  39. <div class="login" @click="settingFn" v-if="userInfo && userInfo.id">
  40. {{ userInfo.name || "暂无名称" }}
  41. </div>
  42. <div class="login" v-else @click="$refs.loginCom.show()">login</div>
  43. </div>
  44. </header>
  45. <loginCom ref="loginCom"></loginCom>
  46. </div>
  47. </template>
  48. <script>
  49. import { userInfo } from "@/api";
  50. import loginCom from "./login.vue";
  51. export default {
  52. name: "userHeader",
  53. data() {
  54. return {
  55. userInfo: {},
  56. active: "",
  57. avatar:
  58. "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2F2b22236d-a6e4-4437-b9f6-4ca9a01bac3a%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1682345978&t=f6e3b830ea09df2467363b2681ee65c0",
  59. };
  60. },
  61. components: { loginCom },
  62. mounted() {
  63. setTimeout(async () => {
  64. this.active = this.$route.name;
  65. const token = localStorage.getItem("token");
  66. // const userInfoStr = localStorage.getItem("userInfo");
  67. if (token) {
  68. const res = await userInfo({ token });
  69. this.userInfo = res.data;
  70. this.$store.commit("setUserInfo", this.userInfo);
  71. }
  72. }, 300);
  73. },
  74. watch: {
  75. $route(to, from) {
  76. setTimeout(() => {
  77. this.active = this.$route.name;
  78. }, 100);
  79. },
  80. },
  81. methods: {
  82. toLogin() {
  83. console.log(61);
  84. },
  85. toNewPage(name) {
  86. // 判断是否登录
  87. if (!this.userInfo?.id && !/home|about/.test(name)) {
  88. this.$refs.loginCom.show();
  89. return;
  90. }
  91. this.$router.push({
  92. path: `/${name}`,
  93. });
  94. },
  95. settingFn() {
  96. this.$router.push({ name: "userInfo" });
  97. },
  98. },
  99. };
  100. </script>
  101. <style lang="less" scoped>
  102. .header-box {
  103. color: #ffffff;
  104. background-color: rgb(16, 126, 100);
  105. //background-color: #ffffff;
  106. font-size: 34px;
  107. display: flex;
  108. padding: 10px 40px;
  109. flex-direction: row;
  110. transition: box-shadow 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
  111. box-shadow: rgba(0, 0, 0, 0.2) 0px 2px 4px -1px,
  112. rgba(0, 0, 0, 0.14) 0px 4px 5px 0px, rgba(0, 0, 0, 0.12) 0px 1px 10px 0px;
  113. position: fixed;
  114. z-index: 100;
  115. right: 0;
  116. left: 0;
  117. top: 0;
  118. .logo {
  119. margin-right: 40px;
  120. }
  121. .nav-box {
  122. font-size: 20px;
  123. display: flex;
  124. margin-right: 30px;
  125. align-items: center;
  126. font-weight: bold;
  127. .item {
  128. margin-right: 24px;
  129. cursor: pointer;
  130. transition: all ease 50ms;
  131. &.active {
  132. color: #f6903d;
  133. //color: #409eff;
  134. position: relative;
  135. &:after {
  136. content: "";
  137. position: absolute;
  138. width: 100%;
  139. height: 2px;
  140. //background-color: #409eff;
  141. background-color: #f6903d;
  142. bottom: -20px;
  143. left: 0;
  144. right: 0;
  145. }
  146. }
  147. }
  148. }
  149. .user-box {
  150. color: #000000;
  151. font-size: 24px;
  152. line-height: 46.5px;
  153. align-items: center;
  154. .login {
  155. cursor: pointer;
  156. }
  157. //font-size: ;
  158. }
  159. }
  160. </style>