top-window.uvue 3.1 KB
Newer Older
1 2 3 4
<template>
  <view class="top-window-header">
    <view class="left-header">
      <navigator class="left-header" open-type="reLaunch" url="/pages/component/global-properties/global-properties">
5 6
        <image src="/static/uni.png" class="logo" mode="heightFix"></image>
        <text>hello uni-app x</text>
7 8 9 10 11 12 13 14 15
      </navigator>
    </view>
    <custom-tab-bar class="tab-bar-flex" direction="horizontal" :show-icon="false" :selected="current"
      @onTabItemTap="toSecondMenu" />
  </view>
</template>

<script lang="uts">
  type IndexPageItem = {
16 17
    tabBar : string.PageURIString;
    indexPageUrl : string.PageURIString;
18 19 20 21 22 23 24 25 26 27 28 29 30
  }
  export default {
    data() {
      return {
        selected: {
          component: 0,
          API: 1,
          CSS: 2,
          template: 3
        },
        current: 0,
        indexPage: [{
          tabBar: '/pages/tabBar/component',
Anne_LXM's avatar
Anne_LXM 已提交
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 42 43 44 45
        }] as IndexPageItem[]
      }
    },
    watch: {
      $route: {
雪洛's avatar
雪洛 已提交
46
        // immediate: true,
47 48 49 50 51 52 53 54
        handler(newRoute) {
          const width = uni.getSystemInfoSync().windowWidth
          if (width <= 768) {
            return
          }
          let path = newRoute.path
          let category
          if (path === '/') {
雪洛's avatar
雪洛 已提交
55 56
            category = 'component'
            uni.redirectTo({
Anne_LXM's avatar
Anne_LXM 已提交
57
              url: '/pages/component/view/view'
雪洛's avatar
雪洛 已提交
58 59
            })
            return
60 61 62 63 64 65 66
          } else if (path.indexOf('/pages/tabBar') === 0) {
            const indexPageItem = this.indexPage.find(item => item.tabBar === path)
            if (!indexPageItem) {
              console.error('Invalid page path: ', path)
              return
            }
            uni.redirectTo({
67
              url: indexPageItem.indexPageUrl
雪洛's avatar
雪洛 已提交
68 69
            })
            return
70 71 72 73 74 75 76 77
          } else {
            category = path.split('/')[2]
          }
          this.current = this.selected[category]
        }
      }
    },
    methods: {
Anne_LXM's avatar
Anne_LXM 已提交
78
      toSecondMenu(e : OnTabItemTapOption) {
79 80 81 82
        const activeTabBar = '/' + e.pagePath
        for (const item of this.indexPage) {
          if (activeTabBar === item.tabBar) {
            uni.redirectTo({
83
              url: item.indexPageUrl
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
            })
          }
        }
      }
    }
  }
</script>

<style>
  .top-window-header {
    height: 60px;
    padding: 0 15px;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    box-sizing: border-box;
    border-bottom: 1px solid #e1e1e1;
    background-color: #FFFFFF;
  }

  .left-header {
    flex-direction: row;
    align-items: center;
    flex: 1;
  }

  .logo {
    height: 30px;
    width: 30px;
    margin-right: 8px;
  }

  .tab-bar-flex {
    width: 360px;
  }
119
</style>