<template>
	<el-container class="mainNoBack userBox">
		<el-aside class="userAside" style="width: 220px;">
			<el-container>
				<el-main class="nopadding">
					<el-menu class="menu mainMenu" :default-active="page">
						<div v-for="group in menu" :key="group.groupName">
							<el-menu-item-group v-if="group.show" :title="group.groupName">
								<div v-for="item in group.list" :key="item.component">
									<el-menu-item v-authSetup="item.actions" :index="item.component" @click="openPage">
										<el-icon v-if="item.icon"><component :is="item.icon"/></el-icon>
										<template #title>
											<span>{{item.title}}</span>
										</template>
									</el-menu-item>
								</div>
							</el-menu-item-group>
						</div>
					</el-menu>
				</el-main>
			</el-container>
		</el-aside>
		<el-main class="userMain userMainPadding_0">
			<Suspense>
				<template #default>
					<component :is="page" />
				</template>
				<template #fallback>
					<el-skeleton :rows="3" />
				</template>
			</Suspense>
		</el-main>
	</el-container>
</template>

<script>
import { defineAsyncComponent } from 'vue'

export default {
	name:"log",
	components: {
		xtLog: defineAsyncComponent(() => import('./components/ability')),
		commandLog: defineAsyncComponent(() => import('./components/command')),
	},
	data() {
		return {
			menu: [
				{
					groupName: "系统操作日志",
					show:true,
					list: [
						{
							icon: "sc-icon-UserLog",
							title: "操作系统功能日志",
							component: "xtLog",
							actions:'logsList',
						},
					]
				},
				{
					groupName: "系统命令日志",
					show:true,
					list: [
						{
							icon: "sc-icon-Log",
							title: "操作系统命令日志",
							component: "commandLog",
							actions:'sysLogCommandList'
						},
					]
				},
			],
			user: {
				avatar:this.$store.state.global.login_avatar,
				name: this.$store.state.global.login_name,
				role: "",
			},
			userNameF:'',
			page: "xtLog"
		}
	},
	//路由跳转进来 判断from是否有特殊标识做特殊处理
	beforeRouteEnter (to, from, next){
		next((vm)=>{
			if(from.is){
				//删除特殊标识，防止标签刷新重复执行
				delete from.is
				//执行特殊方法
				vm.$alert('路由跳转过来后含有特殊标识，做特殊处理', '提示', {
					type: 'success',
					center: true
				}).then(() => {}).catch(() => {})
			}
		})
	},
	created() {
		const userInfo = this.$TOOL.data.get('USER_INFO');
		this.user.role = userInfo.user_roles && userInfo.user_roles.role_names.length>0?userInfo.user_roles.role_names[0]:'';
		const permissions = this.$TOOL.data.get("PERMISSIONS");
		this.menu.forEach(item=>{
			item.show = false;
			item.list.forEach(em=>{
				if(permissions.auth.indexOf(em.actions)!=-1){
					item.show = true;
				}
			})
		})
		if(this.menu.find(item=> item.show === true)){
			let pageView = this.menu.find(item=> item.show === true).list.find(em=> permissions.auth.indexOf(em.actions)!=-1);
			this.page = pageView.component;
		}
	},
	methods: {
		openPage(item){
			this.page = item.index
		},
	}
}
</script>
<style scoped lang="scss">
.noBorderRadius{border-radius: 0 !important;}
</style>
