top-window.uvue 2.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 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
<template>
	<view class="top-window-header">
    <view class="left-header">
    	<navigator class="left-header" open-type="reLaunch" url="/pages/component/public-properties/public-properties">
    		<image src="/static/logo.png" class="logo" mode="heightFix"></image>
    		<text>hello uni-app</text>
    	</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 = {
  	tabBar: string ;
  	index: string ;
  }
	export default {
		data() {
			return {
        selected: {
        	component: 0,
        	API: 1,
        	CSS: 2,
        	template: 3
        },
        current: 0,
        indexPage: [{
        	tabBar: '/pages/tabBar/component',
        	index: '/pages/component/public-properties/public-properties'
        }, {
        	tabBar: '/pages/tabBar/API',
        	index: '/pages/API/get-app/get-app'
        }, {
        	tabBar: '/pages/tabBar/CSS',
        	index: '/pages/CSS/layout/width'
        }, {
        	tabBar: '/pages/tabBar/template',
        	index: '/pages/template/long-list/long-list'
        }] as IndexPageItem[]
			}
		},
    watch: {
    	$route: {
    		immediate: true,
    		handler(newRoute) {
    			const width = uni.getSystemInfoSync().screenWidth
    			if (width >= 768) {
    				let path = newRoute.path
    				let comp
    				if (path === '/') {
    					comp = 'component'
    					path = '/pages/component/public-properties/public-properties'
    				} else {
    					comp = path.split('/')[2]
    				}
    				this.current = this.selected[comp]
    				for (const item of this.indexPage) {
    					if (path === item.tabBar) {
    						uni.redirectTo({
    							url: item.index
    						})
    					}
    				}
    			}
    		}
    	}
    },
		methods: {
      toSecondMenu(e) {
      	const activeTabBar = '/' + e.pagePath
      	for (const item of this.indexPage) {
      		if (activeTabBar === item.tabBar) {
      			uni.redirectTo({
      				url: item.index
      			})
      		}
      	}
      }
		}
	}
</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;
	}
</style>