top-window.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <view class="top-window-header">
  3. <view class="left-header logo">
  4. <navigator class="logo" open-type="reLaunch" url="/pages/component/view/view">
  5. <image src="../static/logo.png" mode="heightFix" style="width: 30px;"></image>
  6. <text>hello uni-app</text>
  7. </navigator>
  8. </view>
  9. <custom-tab-bar class="tab-bar-flex" direction="horizontal" :show-icon="false" :selected="current"
  10. @onTabItemTap="toSecondMenu" />
  11. <!-- online demo menus start -->
  12. <!-- <uni-link class="phone-link" href="https://m3w.cn/uniapp" text="体验手机版"></uni-link>
  13. <uni-link class="phone-link" href="http://hellouniapp.dcloud.net.cn/pages/component/view/view"
  14. text="体验 vue 2.x 版"></uni-link>
  15. <uni-link class="phone-link" href="http://vue
  16. 3-hellouniapp.dcloud.net.cn/pages/component/view/view" text="体验 vue 3.0 版"></uni-link>
  17. <svg t="1628163727478" class="new-icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"
  18. p-id="1334" width="40" height="40">
  19. <path
  20. d="M829.866667 313.6a64 64 0 0 1 64 64v213.333333a64 64 0 0 1-64 64H262.058667L168.32 746.666667v-106.666667h0.213333V377.6a64 64 0 0 1 64-64h597.333334z m-117.333334 78.293333H661.333333l-23.466666 138.56-19.2-136.533333h-51.2l34.133333 174.677333h68.266667l19.2-116.458666 17.066666 116.458666h68.266667l34.133333-174.677333h-51.2l-17.066666 138.538667-27.733334-140.544z m-151.466666 0h-125.866667v174.698667h125.866667v-36.138667h-78.933334v-38.165333h68.266667v-32.106667h-68.266667v-34.133333h78.933334v-34.133333z m-217.6 0h-70.4v174.698667H320v-128.512l32 128.512h70.4V391.893333h-46.933333v134.506667l-32-134.506667z"
  21. p-id="1335" fill="#d81e06"></path>
  22. </svg> -->
  23. <!-- online demo menus end -->
  24. </view>
  25. </template>
  26. <script>
  27. export default {
  28. data() {
  29. return {
  30. selected: {
  31. component: 0,
  32. API: 1,
  33. extUI: 2,
  34. template: 3
  35. },
  36. current: 0,
  37. indexPage: [{
  38. tabBar: '/pages/tabBar/component/component',
  39. index: '/pages/component/view/view'
  40. }, {
  41. tabBar: '/pages/tabBar/API/API',
  42. index: '/pages/API/set-navigation-bar-title/set-navigation-bar-title'
  43. }, {
  44. tabBar: '/pages/tabBar/extUI/extUI',
  45. index: '/pages/extUI/badge/badge'
  46. }, {
  47. tabBar: '/pages/tabBar/template/template',
  48. index: '/pages/template/nav-button/nav-button'
  49. }]
  50. }
  51. },
  52. watch: {
  53. $route: {
  54. immediate: true,
  55. handler(newRoute) {
  56. const width = uni.getSystemInfoSync().screenWidth
  57. if (width >= 768) {
  58. let path = newRoute.path
  59. let comp
  60. if (path === '/') {
  61. comp = 'component'
  62. path = '/pages/tabBar/component/component'
  63. } else {
  64. comp = path.split('/')[2]
  65. }
  66. this.current = this.selected[comp]
  67. for (const item of this.indexPage) {
  68. if (path === item.tabBar) {
  69. uni.redirectTo({
  70. url: item.index
  71. })
  72. }
  73. }
  74. }
  75. }
  76. }
  77. },
  78. mounted() {},
  79. methods: {
  80. toSecondMenu(e) {
  81. const activeTabBar = '/' + e.pagePath
  82. for (const item of this.indexPage) {
  83. if (activeTabBar === item.tabBar) {
  84. uni.redirectTo({
  85. url: item.index
  86. })
  87. }
  88. }
  89. }
  90. }
  91. }
  92. </script>
  93. <style>
  94. .top-window-header {
  95. height: 60px;
  96. padding: 0 15px;
  97. display: flex;
  98. flex-direction: row;
  99. justify-content: space-between;
  100. align-items: center;
  101. box-sizing: border-box;
  102. border-bottom: 1px solid #e1e1e1;
  103. background-color: #FFFFFF;
  104. color: #333;
  105. }
  106. .logo {
  107. display: flex;
  108. flex-direction: row;
  109. align-items: center;
  110. flex: 1;
  111. }
  112. .logo image {
  113. height: 30px;
  114. width: 30px;
  115. }
  116. .logo text {
  117. margin-left: 8px;
  118. }
  119. .right-header {
  120. display: flex;
  121. flex-direction: row;
  122. color: #333;
  123. }
  124. .right-header-item {
  125. line-height: 25px;
  126. margin-left: 40px;
  127. cursor: pointer;
  128. font-size: 16px;
  129. }
  130. .active {
  131. color: #4cd964;
  132. border-bottom: 2px solid;
  133. }
  134. .tab-bar-flex {
  135. width: 360px;
  136. }
  137. .phone-link {
  138. padding-left: 20px;
  139. cursor: pointer;
  140. }
  141. .new-icon {
  142. margin-left: -3px;
  143. /* margin-right: 5px; */
  144. margin-top: -20px;
  145. }
  146. </style>