top-window.uvue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <view class="top-window-header" :class="isDarkMode ? 'theme-dark' : 'theme-light'">
  3. <view class="left-header">
  4. <navigator class="left-header" open-type="reLaunch" url="/pages/component/view/view">
  5. <image src="/static/uni.png" class="logo" mode="heightFix"></image>
  6. <text>hello uni-app x</text>
  7. </navigator>
  8. </view>
  9. <custom-tab-bar class="tab-bar-flex" direction="horizontal" :show-icon="false" :selected="current"
  10. @onTabItemTap="toSecondMenu" />
  11. </view>
  12. </template>
  13. <script lang="uts">
  14. type IndexPageItem = {
  15. tabBar : string.PageURIString;
  16. indexPageUrl : string.PageURIString;
  17. }
  18. import { state } from '@/store/index.uts'
  19. export default {
  20. data() {
  21. return {
  22. selected: {
  23. component: 0,
  24. API: 1,
  25. CSS: 2,
  26. template: 3
  27. },
  28. current: 0,
  29. indexPage: [{
  30. tabBar: '/pages/tabBar/component',
  31. indexPageUrl: '/pages/component/view/view'
  32. }, {
  33. tabBar: '/pages/tabBar/API',
  34. indexPageUrl: '/pages/API/get-app/get-app'
  35. }, {
  36. tabBar: '/pages/tabBar/CSS',
  37. indexPageUrl: '/pages/CSS/layout/width'
  38. }, {
  39. tabBar: '/pages/tabBar/template',
  40. indexPageUrl: '/pages/template/slider-100/slider-100'
  41. }] as IndexPageItem[]
  42. }
  43. },
  44. computed: {
  45. isDarkMode() : boolean {
  46. return state.isDarkMode
  47. }
  48. },
  49. watch: {
  50. $route: {
  51. // immediate: true,
  52. handler(newRoute) {
  53. const width = uni.getSystemInfoSync().windowWidth
  54. if (width <= 768) {
  55. return
  56. }
  57. let path = newRoute.path
  58. let category
  59. if (path === '/') {
  60. category = 'component'
  61. uni.redirectTo({
  62. url: '/pages/component/view/view'
  63. })
  64. return
  65. } else if (path.indexOf('/pages/tabBar') === 0) {
  66. const indexPageItem = this.indexPage.find(item => item.tabBar === path)
  67. if (!indexPageItem) {
  68. console.error('Invalid page path: ', path)
  69. return
  70. }
  71. uni.redirectTo({
  72. url: indexPageItem.indexPageUrl
  73. })
  74. return
  75. } else {
  76. category = path.split('/')[2]
  77. }
  78. this.current = this.selected[category]
  79. }
  80. }
  81. },
  82. methods: {
  83. toSecondMenu(e : OnTabItemTapOption) {
  84. const activeTabBar = '/' + e.pagePath
  85. for (const item of this.indexPage) {
  86. if (activeTabBar === item.tabBar) {
  87. uni.redirectTo({
  88. url: item.indexPageUrl
  89. })
  90. }
  91. }
  92. }
  93. }
  94. }
  95. </script>
  96. <style>
  97. .top-window-header {
  98. height: 60px;
  99. padding: 0 15px;
  100. flex-direction: row;
  101. justify-content: space-between;
  102. align-items: center;
  103. box-sizing: border-box;
  104. border-bottom: 1px solid #e1e1e1;
  105. color: var(--text-color, #333333);
  106. background-color: var(--list-background-color,#ffffff);
  107. }
  108. .left-header {
  109. flex-direction: row;
  110. align-items: center;
  111. flex: 1;
  112. }
  113. .logo {
  114. height: 30px;
  115. width: 30px;
  116. margin-right: 8px;
  117. }
  118. .tab-bar-flex {
  119. width: 360px;
  120. }
  121. </style>