ui-nav-bar.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <div
  3. class="h-80px w-screen bg-primary flex justify-center overflow-hidden items-center"
  4. >
  5. <div class="flex items-center h-full">
  6. <div class="w-80px"></div>
  7. <div
  8. @click="$router.push('/home')"
  9. :class="`menu-item ${currentPath === '/home' ? 'selected' : ''}`"
  10. >
  11. {{ $t("首页") }}
  12. </div>
  13. <div class="w-40px"></div>
  14. <div
  15. @click="$router.push('/recommend')"
  16. :class="`menu-item ${currentPath === '/recommend' ? 'selected' : ''}`"
  17. >
  18. {{ $t("推荐") }}
  19. </div>
  20. <div class="w-40px"></div>
  21. <div
  22. @mouseenter="typeVisible = true"
  23. :class="`menu-item ${currentPath === '/specific-article' ? 'selected' : ''}`"
  24. >
  25. {{ $t("分类浏览") }}
  26. <img src="/imgs/arrow-down.png" class="w-14px h-6px ml-6px" />
  27. </div>
  28. <div class="w-40px"></div>
  29. <div
  30. @click="$router.push('/realtime-news')"
  31. :class="`menu-item ${currentPath === '/realtime-news' ? 'selected' : ''}`"
  32. >
  33. {{ $t("实时新闻") }}
  34. </div>
  35. <div class="w-40px"></div>
  36. <div
  37. @click="$router.push('/vip')"
  38. :class="`menu-item ${currentPath === '/vip' ? 'selected' : ''}`"
  39. >
  40. {{ $t("vip专区") }}
  41. </div>
  42. <div class="w-40px"></div>
  43. <div
  44. @click="$router.push('/aboutus')"
  45. :class="`menu-item ${currentPath === '/aboutus' ? 'selected' : ''}`"
  46. >
  47. {{ $t("关于我们") }}
  48. </div>
  49. <div class="w-260px"></div>
  50. <div
  51. @click="$router.push('/publish')"
  52. :class="`menu-item ${currentPath === '/publish' ? 'selected' : ''}`"
  53. >
  54. <img class="w-30px object-contain" src="/imgs/tougao.png" />
  55. {{ $t("投稿") }}
  56. </div>
  57. <div class="w-36px"></div>
  58. <div
  59. @click="$router.push('/search')"
  60. :class="`menu-item ${currentPath === '/search' ? 'selected' : ''}`"
  61. >
  62. <img class="w-30px object-contain" src="/imgs/search.png" />
  63. {{ $t("搜索") }}
  64. </div>
  65. <div class="w-40px"></div>
  66. <div
  67. v-if="!$store.state.userinfo"
  68. @click="$router.push('/login')"
  69. :class="`menu-item ${currentPath === '/login' ? 'selected' : ''}`"
  70. >
  71. {{ $t("登录注册") }}
  72. </div>
  73. <div
  74. v-else
  75. @click="$router.push('/user/personal-center')"
  76. :class="`menu-item ${currentPath === '/login' ? 'selected' : ''}`"
  77. class="-align-center"
  78. >
  79. <img class="w-40px h-40px rounded-full mr-12px" v-if="$store.state.userinfo.avatar" :src="$store.state.userinfo.avatarUrl">
  80. <span class="font-size-20px">{{$store.state.userinfo.nickname}}</span>
  81. </div>
  82. <div class="w-44px"></div>
  83. <div
  84. @click="changeLang"
  85. class="w-30px h-30px rounded-full border-white-2px text-white align-middle text-center cursor-pointer"
  86. >
  87. {{ $t("cn") }}
  88. </div>
  89. </div>
  90. <div
  91. v-if="typeVisible"
  92. @mouseenter="typeVisible = true"
  93. @mouseleave="typeVisible = false"
  94. class="min-h-272px w-screen bg-white absolute top-80px z-50 flex justify-center pb-30px"
  95. >
  96. <div class="w-1200px flex flex-wrap">
  97. <div
  98. @click="() => {
  99. $router.push('/specific-article?category=' + item.code + '&name=' + item.name)
  100. typeVisible = false
  101. }"
  102. :class="`type-tag ${$route.query.category === item.code ? 'selected' : ''}`"
  103. v-for="(item, index) in cmsCategorys"
  104. :key="item"
  105. >
  106. <div class="name">{{item.name}}</div>
  107. <div class="count">{{item.artcileNum}}篇文章</div>
  108. </div>
  109. </div>
  110. </div>
  111. </div>
  112. </template>
  113. <script>
  114. export default {
  115. mounted() {
  116. },
  117. methods:{
  118. changeLang(){
  119. this.$i18n.locale = this.lang[0];
  120. this.lang = this.lang.reverse()
  121. }
  122. },
  123. watch: {
  124. $route: function (next) {
  125. console.log(next.path);
  126. this.currentPath = next.path;
  127. },
  128. },
  129. data() {
  130. return {
  131. typeVisible: false,
  132. currentPath: this.$route.path,
  133. lang: ['zh-CN','zh-TW'],
  134. cmsCategorys:[]
  135. };
  136. },
  137. async created() {
  138. let resp = await this.$http.post(this.$api.cms.categorys);
  139. if(resp.data.status === 200){
  140. this.cmsCategorys = resp.data.data.cmsCategorys;
  141. }
  142. }
  143. };
  144. </script>
  145. <style>
  146. .menu-item {
  147. @apply text-white text-size-20px cursor-pointer relative h-full flex items-center;
  148. }
  149. .menu-item.selected::after {
  150. content: "";
  151. width: 100%;
  152. height: 3px;
  153. background: #fff;
  154. position: absolute;
  155. bottom: 14px;
  156. left: 0;
  157. border-radius: 3px;
  158. }
  159. .type-tag {
  160. @apply w-110px h-60px bg-[#F7F7F7] flex flex-col justify-center mt-30px pl-15px cursor-pointer;
  161. }
  162. .type-tag.selected {
  163. @apply bg-primary;
  164. }
  165. .type-tag:not(:nth-child(8n)) {
  166. @apply mr-40px;
  167. }
  168. .type-tag > .name {
  169. @apply text-size-16px mb-6px;
  170. }
  171. .type-tag.selected > .name {
  172. @apply text-white;
  173. }
  174. .type-tag > .count {
  175. @apply text-size-14px text-[#B8B8B8];
  176. }
  177. </style>