TradeLayout.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <div class="market-layout">
  3. <div class="market-nav">
  4. <div class="nav-left">
  5. <div
  6. class="nav-item pf600 "
  7. :class="isCurrent('Cryptocurrency') ? 'fs18 fc121212' : 'fs14 fcA8A8A8'"
  8. @click="switchTab('Cryptocurrency')"
  9. >
  10. 币币
  11. <div v-if="isCurrent('Cryptocurrency')" class="active-line"></div>
  12. </div>
  13. <div
  14. class="nav-item pf600 sys-notifi"
  15. :class="isCurrent('TradeContract') ? 'fs18 fc121212' : 'fs14 fcA8A8A8'"
  16. @click="switchTab('TradeContract')"
  17. >
  18. 合约
  19. <div v-if="isCurrent('TradeContract')" class="active-line"></div>
  20. </div>
  21. <div
  22. class="nav-item pf600 sys-notifi"
  23. :class="isCurrent('TradeSeconds') ? 'fs18 fc121212' : 'fs14 fcA8A8A8'"
  24. @click="switchTab('TradeSeconds')"
  25. >
  26. 秒合约
  27. <div v-if="isCurrent('TradeSeconds')" class="active-line"></div>
  28. </div>
  29. <div
  30. class="nav-item pf600 sys-notifi"
  31. :class="isCurrent('TradeOptions') ? 'fs18 fc121212' : 'fs14 fcA8A8A8'"
  32. @click="switchTab('TradeOptions')"
  33. >
  34. 期权
  35. <div v-if="isCurrent('TradeOptions')" class="active-line"></div>
  36. </div>
  37. </div>
  38. </div>
  39. <router-view :key="$route.fullPath"></router-view>
  40. </div>
  41. </template>
  42. <script setup>
  43. import { onMounted, onUnmounted, ref , watch} from 'vue'
  44. import { useRouter, useRoute } from 'vue-router';
  45. const router = useRouter();
  46. const route = useRoute();
  47. // 监听路由路径变化
  48. watch(
  49. () => route.path,
  50. () => {
  51. window.scrollTo(0, 0);
  52. const scrollBox = document.querySelector('.page-container');
  53. if (scrollBox) {
  54. scrollBox.scrollTop = 0;
  55. }
  56. }
  57. );
  58. const switchTab = (name) => {
  59. router.push({ name })
  60. };
  61. const isCurrent = (name) => {
  62. return route.name === name;
  63. };
  64. </script>
  65. <style lang="less" scoped>
  66. .market-layout {
  67. display: flex;
  68. align-items: center;
  69. width: 100%;
  70. height: auto;
  71. z-index: auto;
  72. /* 确保导航栏样式正常 */
  73. .market-nav {
  74. display: flex;
  75. flex-direction: row;
  76. justify-content: space-between;
  77. align-items: center;
  78. padding:0 15px;
  79. //width: 100px;
  80. height: 48px;
  81. position: fixed;
  82. top: 0;
  83. left: 0;
  84. z-index: 999;
  85. background-color: #FFFFFF;
  86. /* 既然只放Tabs,可能需要一点底部间距,以免紧贴着下面的内容 */
  87. margin-bottom: 18px;
  88. .nav-left {
  89. display: flex;
  90. flex-direction: row;
  91. justify-content: flex-start;
  92. align-items: flex-end;
  93. width: 345px;
  94. height: 24px;
  95. .nav-item {
  96. position: relative;
  97. cursor: pointer;
  98. transition: all 0.2s;
  99. .active-line {
  100. position: absolute;
  101. bottom: -6px;
  102. left: 50%;
  103. transform: translateX(-50%);
  104. width: 20px;
  105. height: 3px;
  106. background-color: #323233;
  107. border-radius: 2px;
  108. }
  109. }
  110. .sys-notifi {
  111. margin-left: 35px;
  112. }
  113. }
  114. }
  115. }
  116. </style>