top-window.uvue 2.7 KB
Newer Older
1 2 3
<template>
	<view class="top-window-header">
    <view class="left-header">
4
    	<navigator class="left-header" open-type="reLaunch" url="/pages/component/global-properties/global-properties">
5 6 7 8 9 10 11 12 13 14 15 16 17
    		<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 ;
Anne_LXM's avatar
Anne_LXM 已提交
18 19 20 21 22
  }
  type OnTabItemTapEvent = {
  	pagePath: string ;
  	text: string ;
  	index: number ;
23 24 25 26 27 28 29 30 31 32 33 34 35
  }
	export default {
		data() {
			return {
        selected: {
        	component: 0,
        	API: 1,
        	CSS: 2,
        	template: 3
        },
        current: 0,
        indexPage: [{
        	tabBar: '/pages/tabBar/component',
36
        	index: '/pages/component/global-properties/global-properties'
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
        }, {
        	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'
59
    					path = '/pages/component/global-properties/global-properties'
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
    				} 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: {
Anne_LXM's avatar
Anne_LXM 已提交
76 77
      // UniEvent类型报错,临时处理
      toSecondMenu(e: OnTabItemTapEvent) {
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 110 111 112 113 114 115
      	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>