index.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <!-- <div class="banner">
  3. <div class="logo">
  4. <img src="@/assets/images/logo.png" alt="Logo" />
  5. </div>
  6. <el-menu
  7. class="menu"
  8. mode="horizontal"
  9. :router="true"
  10. :default-active="activeMenuItem"
  11. @select="handleMenuSelect"
  12. >
  13. <el-menu-item index="home">Home</el-menu-item>
  14. <el-menu-item index="products">Products</el-menu-item>
  15. <el-menu-item index="about">About</el-menu-item>
  16. <el-menu-item index="contact">Contact</el-menu-item>
  17. </el-menu>
  18. </div> -->
  19. <div class="nav flex-between" @scroll="handleScroll">
  20. <img class="logo" src="@/assets/images/logo.png" @click="goPage('/home')" alt="" />
  21. <el-menu :default-active="activeIndex" class="flex-item el-menu-demo" mode="horizontal">
  22. <el-menu-item class="nav-title menuitem" index="1" @click="goPage('/guideintro')" >Guidebooks</el-menu-item>
  23. <el-menu-item class="nav-title menuitem" index="2" @click="goPage('/blog')" >Blogs/Vlogs</el-menu-item>
  24. <el-menu-item class="nav-title menuitem" index="3" @click="goPage('/product')" >Travel Shop</el-menu-item>
  25. <el-menu-item class="nav-title menuitem" index="4" @click="goPage('/destination')" >Destinations</el-menu-item>
  26. </el-menu>
  27. <div class="flex-between">
  28. <!-- <div class="flex-between">
  29. <svg-icon icon-class="user"/>
  30. <el-select v-model="value1" class="m-2" size="mini" placeholder="请选择">
  31. <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"/>
  32. </el-select>
  33. </div> -->
  34. <span v-if="currentUser==''" class="login"><el-button type="primary" @click="goPage('/auth/register')">Register</el-button> / <el-button type="primary" @click="goPage('/auth/login')">Login</el-button></span>
  35. <el-dropdown style="cursor: pointer;" v-if="currentUser!=''">
  36. <span class="el-dropdown-link">
  37. {{ currentUser }}
  38. <el-icon class="el-icon--right">
  39. <arrow-down />
  40. </el-icon>
  41. </span>
  42. <template #dropdown>
  43. <el-dropdown-menu>
  44. <el-dropdown-item @click="goPage('/user')">My Content</el-dropdown-item>
  45. </el-dropdown-menu>
  46. <el-dropdown-menu>
  47. <el-dropdown-item @click="goPage('/user-info')">Edit Profile</el-dropdown-item>
  48. </el-dropdown-menu>
  49. <el-dropdown-menu>
  50. <el-dropdown-item @click="logout">Logout</el-dropdown-item>
  51. </el-dropdown-menu>
  52. </template>
  53. </el-dropdown>
  54. </div>
  55. </div>
  56. </template>
  57. <script setup>
  58. import VLazyImage from "v-lazy-image";
  59. import { useRouter } from 'vue-router';
  60. import router from "../../../router";
  61. import { ElNotification } from 'element-plus'
  62. import {AXIOS} from '@/common/http-commons'
  63. import { ArrowDown } from '@element-plus/icons-vue'
  64. const activeIndex = ref(1)
  65. const activeMenuItem =ref('home')
  66. function handleMenuSelect(index) {
  67. activeMenuItem.value = index;
  68. // Handle menu selection logic here
  69. }
  70. function handleScroll(el) {
  71. console.log("scoll me")
  72. if((el.srcElement.offsetHeight + el.srcElement.scrollTop) >= el.srcElement.scrollHeight) {
  73. this.hasScrolledToBottom = true;
  74. }
  75. }
  76. function goPage(val){
  77. router.push({ path: val })
  78. }
  79. function logout(){
  80. console.log("logging out...")
  81. AXIOS.post(
  82. "/logout",
  83. {},
  84. { headers: { "Content-Type": "application/x-www-form-urlencoded" } }
  85. )
  86. .then((response) => {
  87. location.reload();
  88. })
  89. .catch((e) => {
  90. location.reload();
  91. });
  92. }
  93. const currentUser = ref("")
  94. function whoami(){
  95. AXIOS.get("/api/v1/user/whoami")
  96. .then(function (response) {
  97. console.log("current user:" + response.data)
  98. currentUser.value = response.data
  99. })
  100. .catch(function (error) {
  101. console.log("not logged in err");
  102. // router.push({name: 'home'})
  103. });
  104. }
  105. onMounted(() => {
  106. whoami();
  107. })
  108. </script>
  109. <style scoped lang="scss">
  110. .nav {
  111. min-width: 1400px;
  112. height: 78px;
  113. padding: 0 54px 0 57px;
  114. .logo {
  115. margin-right: 67px;
  116. width: 114px;
  117. height: 60px;
  118. cursor: pointer;
  119. }
  120. .el-menu {
  121. border-bottom: none;
  122. }
  123. &-title {
  124. color: rgba(80, 80, 80, 1);
  125. font-size: 14px;
  126. line-height: 150%;
  127. text-align: left;
  128. }
  129. .el-select {
  130. margin-right: 55px;
  131. width: 100px;
  132. height: 32px;
  133. }
  134. .login {
  135. color: rgba(80, 80, 80, 1);
  136. font-size: 14px;
  137. line-height: 150%;
  138. text-align: left;
  139. }
  140. }
  141. .example-showcase .el-dropdown-link {
  142. cursor: pointer;
  143. color: var(--el-color-primary);
  144. display: flex;
  145. align-items: center;
  146. }
  147. .menuitem{
  148. margin-left: 20px;
  149. }
  150. // .banner {
  151. // display: flex;
  152. // justify-content: space-between;
  153. // align-items: center;
  154. // padding: 10px;
  155. // background-color: #f5f5f5;
  156. // }
  157. // .logo img {
  158. // height: 40px;
  159. // width: auto;
  160. // }
  161. // .menu {
  162. // background-color: #f5f5f5;
  163. // }
  164. </style>