<template>
	<div>
		<v-header :userName="userName" :authList="authList"></v-header>
    	<v-slidebar :tokenValue="token"></v-slidebar>
		<el-container>
			<div class="content" id="body-content">
				<transition name="router-fade" mode="out-in">
					<keep-alive>
						<router-view v-if="$route.meta.keepAlive"></router-view>
					</keep-alive>
				</transition>
				<transition name="router-fade" mode="out-in">
					<router-view v-if="!$route.meta.keepAlive"></router-view>
				</transition>
				<v-footer></v-footer>
			</div>
		</el-container>
    </div>
</template>
<script>
import VHeader from './views/layout/header.vue'
import VSlidebar from './views/layout/slidebar.vue'
import VFooter from './views/layout/footer.vue'
import { base64decode, isNotEmptyUtils, getUrlParamsMap, ssoLogin } from "./utils/utils.js"
import { mapActions, mapGetters } from 'vuex'
import { getLoginUrl, getInnerLoginUrl } from './utils/index.js'
let vm = null
export default {
	components:{
		VHeader,
		VSlidebar,
		VFooter
	},
	data() {
		return {
			idType: 0,
			token: '',
			userName: '',
			authList: []
		}
	},
	computed:{
		...mapGetters([
			'_token'
		])
	},
	created() {
		vm = this
		vm.getToken()
	},
	mounted() {
	
	},
	methods: {
		// 解密token
		getToken() {
			let href = window.location.href
			let offset = href.indexOf("?")

			// --------------本地调试使用---------------------------------
			localStorage.setItem('storageToken','1920D1B777934AFF8585D2BEA0522249')
			// --------------本地调试使用---------------------------------
			
			if(offset !== -1) {
				let paramStr = href.substring(offset + 1, href.length)
				let pars = base64decode(paramStr)
				let paramMap = getUrlParamsMap(pars, "&")
				if (isNotEmptyUtils(paramMap["token"]) && isNotEmptyUtils(paramMap["ssoOrigin"])) {
					vm.token = paramMap["token"]
					localStorage.setItem('storageToken', vm.token)
					ssoLogin(href, paramMap)
				    //vm.$router.push({ path: 'home' })
				} else {
					if(!localStorage.getItem('storageToken')) {
						window.location.href = getInnerLoginUrl()  // 没有token返回登录页面
						return 
					} 
				}
			}else {
				if(!localStorage.getItem('storageToken')) {
					window.location.href = getInnerLoginUrl()  // 没有token返回登录页面
					return 
				}
			}
			vm.changeToken(vm.token)
			vm.getUserAuth()
		},
		// 修改token
		...mapActions([
			'changeToken',
			'changeIdType'
		]),
		// 获取用户权限
		getUserAuth(token) {
			let req = null
			req = {
				system_type: '26'
			}
			vm.POST('/contents/login/header',req).then((res) => {
				if(res.code == '000000') {
					vm.userName = res.data.userName
					vm.authList = res.data.systemInfoList
				}
			})
		}
	}
}
</script>
<style lang="scss">
  	// @import './style/common';
  	@import './style/global';
  	@import './style/mixin.scss';
	.router-fade-enter-active, .router-fade-leave-active {
	  	transition: opacity .1s;
	}
	.router-fade-enter, .router-fade-leave-active {
	  	opacity: 0;
	}
	.el-container {
		margin-left: 255px;
		overflow: hidden;
		.content {
			background: #F0F2F5;
			position: absolute;
			left: 255px;
			right: 0;
			top: 64px;
			bottom: 0;
			width: auto;
			box-sizing: border-box;
			overflow-y: scroll;
		}
	}
</style>
