<template>
	<div>
		<el-row>
			<el-col :span="7">
				<div class="grid-content bg-purple">
					<div class="logo_div">地铁站台门与列车间异物监测系统</div>
				</div>
			</el-col>
			<el-col :span="10">
				<div class="grid-content bg-purple-light">
					<div class="nav_div">
						<!-- <el-menu  class="el-menu-demo" mode="horizontal"
							background-color="#273f70" active-text-color="#fbe103" text-color="#ffffff"
							:default-active="indextab"> -->
						<el-menu  class="el-menu-demo" mode="horizontal"
							background-color="#273f70" active-text-color="#fbe103" text-color="#ffffff"
							router :default-active="$route.path">
							<!-- <el-menu-item index="1" onclick="javascript:window.location.href='../../src/components/login.vue'">日常监测</el-menu-item> -->
							<!-- <el-menu-item v-for="n in userMenuList" :index="n.id.toString()" @click="topage(n.name)" :key=n.id>{{n.title}}</el-menu-item> -->
							<el-menu-item v-for="n in userMenuList" :index="'/'+n.name" :key=n.id>{{n.title}}</el-menu-item>

							<!-- <el-menu-item index="/">日常监测</el-menu-item>
							<el-menu-item index="/list">告警记录</el-menu-item> -->
							<!-- <el-menu-item index="2"onclick="javascript:window.location.href='./list.html'">告警记录</el-menu-item> -->
							<!-- <el-menu-item index="/configurationFile">配置文件</el-menu-item>
							<el-menu-item index="/passengerFlow">客流信息</el-menu-item> -->

						</el-menu>
					</div>
				</div>
			</el-col>
			<el-col :span="7">
				<div class="grid-content bg-purple">
					<div class="user_div">
						<ul class="cl">
							<li class="time">{{nowtime}}</li>
							<li class="user"><a @click="showLogin()" style="color:#fff">{{username}}</a></li>
							<!-- <li class="user"><a href="../../src/components/login.vue" style="color:#fff">{{username}}</a></li> -->
							<li class="bnt_colse" @click="logout()"></li>
							
						</ul>
					</div>
				</div>
			</el-col>
		</el-row>
	</div>
</template>

<script>
// import { log } from 'shelljs/src/common';
export default {
	
	data() {
		return {
			nowtime:"",
			username:"登录",
			userMenuList:[]


		}
	},
	props:['indextab','server_date'],
	methods: {//这里定义的组件的方法，利用$emit()进行父子组件通信，子组件通过点击事件告诉父组件触发一个自定义事件，$emit()方法第二个参数也可以用来传递数据
		// handleSelect(key, keyPath) {
		// 	console.log(key, keyPath);
		// },
		getTime(){
			var nowtime="";
			var d = new Date(this.server_date * 1000);
			var y = d.getFullYear();
			var m = d.getMonth()+1;
			var ds = d.getDate();
			if (ds <=9){
				ds ='0'+ds;
			}
			var h = d.getHours();
			if(h <=9){
				h = '0'+h;
			}
			var f = d.getMinutes();
			if(f <=9){
				f = '0'+f;
			}
			var s = d.getSeconds();
			if(s <=9){
				s = '0'+s;
			}
			var days = d.getDay();
			switch(days){
				case 1:
					days='星期一';
					break;
				case 2:
					days='星期二';
					break;
				case 3:
					days='星期三';
					break;
				case 4:
					days='星期四';
					break;
				case 5:
					days='星期五';
					break;
				case 6:
					days='星期六';
					break;
				case 0:
					days='星期日';
					break;
		
			}
			this.nowtime= y+'-'+m+'-'+ds+' '+h+':'+f+':'+s+' '+days;
		},
		logout(){
			// if(){}
			// console.log(sessionStorage.getItem('token'),11111+'token')
			sessionStorage.removeItem('token');
			sessionStorage.removeItem('username');
			sessionStorage.removeItem('userid');
			//返回到登陆页面
			this.$router.push({
				name: "login",
			});
			// window.location.href="../../src/components/login.vue";

		},
		// showIndex(){
		// 	this.$router.push("/");
		// },
		// showLogin(){
		// 	this.$router.push("/login")
		// },
		// showList(){
		// 	this.$router.push("/list")
		// },
		getmenu(userid){
			let that=this
			that.$axios(that.$api.getUserMenuList, null, 'GET', function (data) {
					if(data.code == 200){
						// console.log(data.data);
						that.userMenuList = data.data 
					} else {
						that.$message({
							message: data.message,
							type: 'error'
						});
					}
				},null,userid);
		},
		topage(name){
			// window.location.href=name
			this.$router.push("/"+name)
		}

	},
	watch: {
		server_date: function(){
			this.getTime();
		}
	},
	mounted: function() {
		var that = this; // 声明一个变量指向Vue实例this，保证作用域一致
		var user=sessionStorage.getItem('username');
		if(user!=null){
			that.username=sessionStorage.getItem('username');
			that.getmenu(sessionStorage.getItem('userid'))

		}

		
	},
	beforeDestroy () {
		if(this.timer){
			clearInterval(this.timer);// 在Vue实例销毁前，清除我们的定时器
		}
	}
}
</script>

<style>

</style>