<template>
	<div class="activateBox">
		<common-page>
			<div class="cardMain">
				<div class="headerBox">电子邮件确认链接</div>
				<div class="mainBox">
					<div class="msg">电子邮件确认链接</div>
					<el-button type="primary" @click="getActivation">点此激活账号并登录</el-button>
					<div class="text">您最近是否申请过帐户，但未确认您的电子邮件地址?如果您尚未确认您的电子邮件地址，您可能需要创建一个新帐户。如果您有问题，请参阅帐户帮助。</div>
				</div>
			</div>
		</common-page>
	</div>
</template>

<script>
import commonPage from './components/commonPage'
export default {
	name: "activate",
	components:{
		commonPage
	},
	data(){
		return{

		}
	},
	created() {
		let token = this.$route.query.token;
		if(token){
			this.$TOOL.cookie.set("TOKEN", token)
		}
	},
	mounted() {

	},
	methods:{
		async getActivation() {
			const user = await this.$API.user.active.post();
			if(user.code == 200){
				await this.setLoginData(user);
			}
		},

		async setLoginData(user) {
			this.$TOOL.cookie.set("TOKEN", user.data.token, {
				expires: 0
			})
			this.$TOOL.data.set("USER_INFO", user.data.user)
			if(user.data.user.avatar!=''){
				this.$store.commit("SET_LOGIN_AVATAR", user.data.user.avatar);
			}
			this.$store.commit("SET_LOGIN_NAME", user.data.user.name);

			if(user.data.user.company_id === 0){
				this.$router.replace({
					path: '/maintenance'
				})
				this.islogin = false
				return
			}

			//获取菜单
			let menu = null;
			menu = await this.$API.system.menu.myMenus.get()
			if (menu.code === 200) {
				if (menu.data.menu.length === 0) {
					this.islogin = false
					await this.$alert("当前用户无任何菜单权限，请联系系统管理员", "无权限访问", {
						type: 'error',
						center: true
					})
					return false
				}
				this.$TOOL.data.set("MENU", menu.data.menu)
				const data_auth = this.$TOOL.objCopy(menu.data.permissions);
				data_auth.auth = this.$TOOL.authPermissions(data_auth.data_permissions);
				this.$TOOL.data.set("PERMISSIONS", data_auth)
				this.$TOOL.data.set("DASHBOARDGRID", menu.data.dashboardGrid)
			} else {
				this.$message.warning(menu.msg)
				return false
			}
			this.$router.replace({
				path: '/'
			})
		},
	}
}
</script>

<style scoped lang="scss">
	.activateBox{
		::v-deep .common-main{
			background: #F6F8F9;
		}
	}
	.cardMain{
		background: var(--el-color-white);
		width: 580px;
		margin: 20px auto;
		border-radius: 6px;
		box-shadow: 0 2px 8px rgba(0,0,0,0.1);
		.headerBox{
			padding: 20px;
			border-bottom: 1px solid #DCDFE6;
			display: flex;
			align-items: center;
			font-size: 16px;
			font-weight: 600;
		}
		.mainBox{
			padding: 20px;
			.msg{
				margin-bottom: 20px;
				font-size: 14px;
			}
			.text{
				margin-top: 20px;
				line-height: 20px;
			}
		}
	}
</style>
