<template>
	<div class="login_bg" style="background-image: url(img/login_images/login_base.png);background-color: #555;background-size: cover;background-position: center center;background-repeat: no-repeat;position: relative;">
		<div class="login_adv" >
			<img src="img/login_images/logo.png" style="margin-top:15%;margin-left:15%;">
			<!-- <div >
				<h2>SCUI</h2>
				<h4>{{ $t('login.slogan') }}</h4>
				<p>{{ $t('login.describe') }}</p>
				<div>
					<span>
						<el-icon><sc-icon-vue /></el-icon>
					</span>
					<span>
						<el-icon class="add"><el-icon-plus /></el-icon>
					</span>
					<span>
						<el-icon><el-icon-eleme-filled /></el-icon>
					</span>
				</div>
			</div> -->
		</div> 
		<div class="login_main" >
			<!-- <div class="login_config">
				<el-button :icon="config.theme=='dark'?'el-icon-sunny':'el-icon-moon'" circle type="info" @click="configTheme"></el-button>
				<el-dropdown trigger="click" placement="bottom-end" @command="configLang">
					<el-button circle>
						<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 512 512"><path d="M478.33 433.6l-90-218a22 22 0 0 0-40.67 0l-90 218a22 22 0 1 0 40.67 16.79L316.66 406h102.67l18.33 44.39A22 22 0 0 0 458 464a22 22 0 0 0 20.32-30.4zM334.83 362L368 281.65L401.17 362z" fill="currentColor"></path><path d="M267.84 342.92a22 22 0 0 0-4.89-30.7c-.2-.15-15-11.13-36.49-34.73c39.65-53.68 62.11-114.75 71.27-143.49H330a22 22 0 0 0 0-44H214V70a22 22 0 0 0-44 0v20H54a22 22 0 0 0 0 44h197.25c-9.52 26.95-27.05 69.5-53.79 108.36c-31.41-41.68-43.08-68.65-43.17-68.87a22 22 0 0 0-40.58 17c.58 1.38 14.55 34.23 52.86 83.93c.92 1.19 1.83 2.35 2.74 3.51c-39.24 44.35-77.74 71.86-93.85 80.74a22 22 0 1 0 21.07 38.63c2.16-1.18 48.6-26.89 101.63-85.59c22.52 24.08 38 35.44 38.93 36.1a22 22 0 0 0 30.75-4.9z" fill="currentColor"></path></svg>
					</el-button>
					<template #dropdown>
						<el-dropdown-menu>
							<el-dropdown-item v-for="item in lang" :key="item.value" :command="item" :class="{'selected':config.lang==item.value}">{{item.name}}</el-dropdown-item>
						</el-dropdown-menu>
					</template>
				</el-dropdown>
			</div> -->
			<div class="login-form" style="background-color: #fff;">
				<div class="login-header">
					<h2 style="font-size: 30px;text-align: center;padding-bottom: 20px;">{{ $t('login.signInTitle') }}</h2>
				</div>
				<el-form ref="loginForm" :model="ruleForm" :rules="rules" label-width="0" size="large" @keyup.enter="login">
					<el-form-item prop="user">
						<el-input v-model="ruleForm.user" prefix-icon="el-icon-user" clearable :placeholder="$t('login.userPlaceholder')">
							<template #append>
								<el-select v-model="userType" style="width: 125px;">
									<el-option :label="$t('login.admin')" value="admin"></el-option>
								</el-select>
							</template>
						</el-input>
					</el-form-item>
					<el-form-item prop="password">
						<el-input v-model="ruleForm.password" prefix-icon="el-icon-lock" clearable show-password :placeholder="$t('login.PWPlaceholder')"></el-input>
					</el-form-item>
					<el-form-item style="margin-bottom: 10px;">
						<el-row>
							<el-col :span="12">
								<el-checkbox :label="$t('login.rememberMe')" v-model="ruleForm.autologin"></el-checkbox>
							</el-col>
						</el-row>
					</el-form-item>
					<el-form-item>
						<el-button type="primary" style="width: 100%;" :loading="islogin" round @click="login" @keyup.enter="login">{{ $t('login.signIn') }}</el-button>
					</el-form-item>
				</el-form>
				<!-- 其他方式登录 -->
				<!-- <el-divider>{{ $t('login.signInOther') }}</el-divider>

				<div class="login-oauth">
					<el-button size="small" type="success" icon="sc-icon-wechat" circle></el-button>
				</div> -->
			</div>
			
			<div class="login_adv__bottom copyrightBottom">
				© {{$t('login.copyright')}}
			</div>
		</div>
	</div>
</template>

<script>
	import routeConfig from "@/config/route";
	export default {
		data() {
			return {
				userType: 'admin',
				ruleForm: {
					// user: "admin",
					// password: "admin",
					autologin: this.$TOOL.data.get("AutoLogin") || false
				},
				rules: {
					user: [
						{required: true, message: this.$t('login.userError'), trigger: 'blur'}
					],
					password: [
						{required: true, message: this.$t('login.PWError'), trigger: 'blur'}
					]
				},
				islogin: false,
			}
		},
		watch:{
			// userType(val){
			// 	if(val == 'admin'){
			// 		var remeberUserInfo = this.$TOOL.data.get("RemeberUser");
			// 		if (remeberUserInfo)
			// 		{
			// 			this.ruleForm.user = remeberUserInfo.user;
			// 			this.ruleForm.password = remeberUserInfo.password;
			// 		}
			// 	}
			// 	else if(val == 'user'){
			// 		this.ruleForm.user = 'user'
			// 		this.ruleForm.password = 'user'
			// 	}
			// }
		},
		created: function() {
			var remeberUserInfo = this.$TOOL.data.get("RemeberUser");
			if (remeberUserInfo)
			{
				this.ruleForm.user = remeberUserInfo.user;
				this.ruleForm.password = remeberUserInfo.password;
			}
			this.$TOOL.data.remove("TOKEN")
			this.$TOOL.data.remove("USER_INFO")
			this.$TOOL.data.remove("MENU")
			this.$TOOL.data.remove("PERMISSIONS")
			this.$TOOL.data.remove("grid")
			this.$store.commit("clearViewTags")
			this.$store.commit("clearKeepLive")
			this.$store.commit("clearIframeList")
		},
		methods: {
			async login(){

				var validate = await this.$refs.loginForm.validate().catch(()=>{})
				if(!validate){ return false }

				this.islogin = true
				//获取token
				var token = await this.$API.authentication.login.post(this.ruleForm)
				if (token) {
					this.$TOOL.data.set("TOKEN", token)
					var userInfo = await this.$API.authentication.getInfo.post()
					if (userInfo) {
						userInfo.role = ["SA","admin","Auditor"]
						this.$TOOL.data.set("USER_INFO", userInfo)

						//获取菜单
						var featureInfo = await this.$API.authentication.getAdminRoleFeaturs.post(userInfo.RoleCodes[0])
						// if(this.ruleForm.user == 'Admin'){
						// 	menu = await this.$API.system.menu.myMenus.get()
						// }else{
						// 	menu = await this.$API.demo.menu.get()
						// }
						if(featureInfo){
							if(featureInfo.FeatureCodeList.length==0){
								this.islogin = false
								this.$alert("当前用户无任何菜单权限，请联系系统管理员", "无权限访问", {
									type: 'error',
									center: true
								})
								return false
							}
							var menu = [];
							menu.push({"name":"home","path":"/home","meta":{"title":this.$t('menu.home'),"icon":"el-icon-home-filled","type":"menu"},"children":[{"name":"dashboard","path":"/dashboard","meta":{"title":this.$t('menu.dashboard'),"icon":"sc-icon-dashboard","affix":true},"component":"home"},{"name":"userCenter","path":"/usercenter","meta":{"title":this.$t('menu.userCenter'),"icon":"sc-icon-user-info"},"component":"userCenter"}]});
							var menuList = routeConfig.getRouteList(routeConfig.routes, featureInfo.FeatureCodeList);
							menuList.forEach(em => {
								menu.push(em);
							});
							// menu.push({"name":"vab","path":"/vab","meta":{"title":"组件","icon":"el-icon-takeaway-box","type":"menu"},"children":[{"path":"/vab/mini","name":"minivab","meta":{"title":"原子组件","icon":"el-icon-magic-stick","type":"menu"},"component":"vab/mini"},{"path":"/vab/iconfont","name":"iconfont","meta":{"title":"扩展图标","icon":"el-icon-orange","type":"menu"},"component":"vab/iconfont"},{"path":"/vab/data","name":"vabdata","meta":{"title":"Data 数据展示","icon":"el-icon-histogram","type":"menu"},"children":[{"path":"/vab/chart","name":"chart","meta":{"title":"图表 Echarts","type":"menu"},"component":"vab/chart"},{"path":"/vab/statistic","name":"statistic","meta":{"title":"统计数值","type":"menu"},"component":"vab/statistic"},{"path":"/vab/video","name":"scvideo","meta":{"title":"视频播放器","type":"menu"},"component":"vab/video"},{"path":"/vab/qrcode","name":"qrcode","meta":{"title":"二维码","type":"menu"},"component":"vab/qrcode"}]},{"path":"/vab/form","name":"vabform","meta":{"title":"Form 数据录入","icon":"el-icon-edit","type":"menu"},"children":[{"path":"/vab/tableselect","name":"tableselect","meta":{"title":"表格选择器","type":"menu"},"component":"vab/tableselect"},{"path":"/vab/formtable","name":"formtable","meta":{"title":"表单表格","type":"menu"},"component":"vab/formtable"},{"path":"/vab/filterbar","name":"filterBar","meta":{"title":"过滤器v2","type":"menu"},"component":"vab/filterBar"},{"path":"/vab/upload","name":"upload","meta":{"title":"上传","type":"menu"},"component":"vab/upload"},{"path":"/vab/select","name":"scselect","meta":{"title":"异步选择器","type":"menu"},"component":"vab/select"},{"path":"/vab/iconselect","name":"iconSelect","meta":{"title":"图标选择器","type":"menu"},"component":"vab/iconselect"},{"path":"/vab/cron","name":"cron","meta":{"title":"Cron规则生成器","type":"menu"},"component":"vab/cron"},{"path":"/vab/editor","name":"editor","meta":{"title":"富文本编辑器","type":"menu"},"component":"vab/editor"}]},{"path":"/vab/feedback","name":"vabfeedback","meta":{"title":"Feedback 反馈","icon":"el-icon-mouse","type":"menu"},"children":[{"path":"/vab/drag","name":"drag","meta":{"title":"拖拽排序","type":"menu"},"component":"vab/drag"},{"path":"/vab/contextmenu","name":"contextmenu","meta":{"title":"右键菜单","type":"menu"},"component":"vab/contextmenu"},{"path":"/vab/cropper","name":"cropper","meta":{"title":"图像剪裁","type":"menu"},"component":"vab/cropper"},{"path":"/vab/fileselect","name":"fileselect","meta":{"title":"资源库选择器","type":"menu"},"component":"vab/fileselect"},{"path":"/vab/dialog","name":"dialogExtend","meta":{"title":"弹窗扩展","type":"menu"},"component":"vab/dialog"}]},{"path":"/vab/others","name":"vabothers","meta":{"title":"Others 其他","icon":"el-icon-more-filled","type":"menu"},"children":[{"path":"/vab/print","name":"print","meta":{"title":"打印","type":"menu"},"component":"vab/print"},{"path":"/vab/watermark","name":"watermark","meta":{"title":"水印","type":"menu"},"component":"vab/watermark"}]},{"path":"/vab/workflow","name":"workflow","meta":{"title":"工作流设计器","icon":"el-icon-share","type":"menu"},"component":"vab/workflow"},{"path":"/vab/formrender","name":"formRender","meta":{"title":"动态表单(Beta)","icon":"el-icon-message-box","type":"menu"},"component":"vab/form"}]});
							// menu.push({"name":"template","path":"/template","meta":{"title":"模板","icon":"el-icon-files","type":"menu"},"children":[{"path":"/template/blank","name":"blank","meta":{"title":"空白模板","icon":"el-icon-folder","type":"menu"},"component":"template/blank"},{"path":"/template/chartlist","name":"chartlist","meta":{"title":"统计列表","icon":"el-icon-data-analysis","type":"menu"},"component":"template/chartlist"},{"path":"/template/calendar","name":"calendar","meta":{"title":"日历计划","icon":"el-icon-calendar","type":"menu"},"component":"template/calendar"},{"path":"/template/list","name":"list","meta":{"title":"详细列表","icon":"el-icon-fold","type":"menu"},"component":"template/list"},{"path":"/template/list/save/:id?","name":"list-save","meta":{"title":"新标签","hidden":true,"active":"/template/list","type":"menu"},"component":"template/list/save"},{"path":"/template/svgmap","name":"svgmap","meta":{"title":"地理信息","icon":"el-icon-map-location","type":"menu"},"component":"template/svgmap"},{"path":"/template/tabinfo","name":"tabinfo","meta":{"title":"分栏明细","icon":"el-icon-document","type":"menu"},"component":"template/tabinfo"},{"path":"/template/server","name":"server","meta":{"title":"服务器监控","icon":"el-icon-cpu","type":"menu"},"component":"template/server"},{"path":"/template/stepform","name":"stepform","meta":{"title":"分步表单","icon":"el-icon-switch","type":"menu"},"component":"template/stepform"}]});
							// menu.push({"name":"other","path":"/other","meta":{"title":"其他","icon":"el-icon-more-filled","type":"menu"},"children":[{"path":"/other/directive","name":"directive","meta":{"title":"指令","icon":"el-icon-price-tag","type":"menu"},"component":"other/directive"},{"path":"/other/viewTags","name":"viewTags","meta":{"title":"标签操作","icon":"el-icon-files","type":"menu"},"component":"other/viewTags","children":[{"path":"/other/fullpage","name":"fullpage","meta":{"title":"整页路由","icon":"el-icon-monitor","fullpage":true,"hidden":true,"type":"menu"},"component":"other/fullpage"}]},{"path":"/link","name":"link","meta":{"title":"外部链接","icon":"el-icon-link","type":"menu"},"children":[{"path":"https://baidu.com","name":"百度","meta":{"title":"百度","type":"link"}},{"path":"https://www.google.cn","name":"谷歌","meta":{"title":"谷歌","type":"link"}}]},{"path":"/iframe","name":"Iframe","meta":{"title":"Iframe","icon":"el-icon-position","type":"menu"},"children":[{"path":"https://v3.cn.vuejs.org","name":"vue3","meta":{"title":"VUE 3","type":"iframe"}},{"path":"https://element-plus.gitee.io","name":"elementplus","meta":{"title":"Element Plus","type":"iframe"}},{"path":"https://lolicode.gitee.io/scui-doc","name":"scuidoc","meta":{"title":"SCUI文档","type":"iframe"}}]}]});
							// menu.push({"name":"test","path":"/test","meta":{"title":"实验室","icon":"el-icon-mouse","type":"menu"},"children":[{"path":"/test/autocode","name":"autocode","meta":{"title":"代码生成器","icon":"sc-icon-code","type":"menu"},"redirect":"/test/autocode/index","children":[{"path":"/test/autocode/index","name":"autocode-index","meta":{"title":"代码生成器","hidden":true,"hiddenBreadcrumb":true,"active":"/test/autocode","type":"menu"},"component":"test/autocode"},{"path":"/test/autocode/list","name":"autocode-list","meta":{"title":"列表生成器","hidden":true,"active":"/test/autocode","type":"menu"},"component":"test/autocode/list"}]},{"path":"/test/codebug","name":"codebug","meta":{"title":"异常处理","icon":"sc-icon-bug-line","type":"menu"},"component":"test/codebug"}]});
							// menu.push({"name":"setting","path":"/setting","meta":{"title":"配置","icon":"el-icon-setting","type":"menu"},"children":[{"path":"/setting/system","name":"system","meta":{"title":"系统设置","icon":"el-icon-tools","type":"menu"},"component":"setting/system"},{"path":"/setting/user","name":"user","meta":{"title":"用户管理","icon":"el-icon-user-filled","type":"menu"},"component":"setting/user"},{"path":"/setting/role","name":"role","meta":{"title":"角色管理","icon":"el-icon-notebook","type":"menu"},"component":"setting/role"},{"path":"/setting/dic","name":"dic","meta":{"title":"字典管理","icon":"el-icon-document","type":"menu"},"component":"setting/dic"},{"path":"/setting/table","name":"tableSetting","meta":{"title":"表格列管理","icon":"el-icon-scale-to-original","type":"menu"},"component":"setting/table"},{"path":"/setting/menu","name":"settingMenu","meta":{"title":"菜单管理","icon":"el-icon-fold","type":"menu"},"component":"setting/menu"},{"path":"/setting/task","name":"task","meta":{"title":"计划任务","icon":"el-icon-alarm-clock","type":"menu"},"component":"setting/task"},{"path":"/setting/client","name":"client","meta":{"title":"应用管理","icon":"el-icon-help-filled","type":"menu"},"component":"setting/client"},{"path":"/setting/log","name":"log","meta":{"title":"系统日志","icon":"el-icon-warning","type":"menu"},"component":"setting/log"}]});
							// menu.push({"path":"/other/about","name":"about","meta":{"title":"关于","icon":"el-icon-info-filled","type":"menu"},"component":"other/about"});
							this.$TOOL.data.set("MENU", menu)
							this.$TOOL.data.set("AutoLogin", this.ruleForm.autologin)
							if (this.ruleForm.autologin)
							{
								this.$TOOL.data.set("RemeberUser", {user:this.ruleForm.user,password:this.ruleForm.password})
							}
							else
							{
								this.$TOOL.data.remove("RemeberUser")
							}
							//this.$TOOL.data.set("PERMISSIONS", menu.data.permissions)
						}else{
							this.islogin = false
							this.$message.warning(this.$t('login.loadingMenuError'))
							return false
						}

						this.$router.replace({
							path: '/'
						})
						this.$message.success(this.$t('login.loginResult'))
						this.islogin = false
					}
				}
				else {
					this.islogin = false
					this.$message.warning(this.$t('login.loginError'))
					return false
				}
			}
		}
	}
</script>

<style scoped>
	.login_bg {width: 100%;height: 100%;background: #fff;display: flex;}
	.login_adv {width: 33.33333%;}
	.login_adv__title {color: #fff;padding: 40px;}
	.login_adv__title h2 {font-size: 40px;}
	.login_adv__title h4 {font-size: 18px;margin-top: 10px;font-weight: normal;}
	.login_adv__title p {font-size: 14px;margin-top:10px;line-height: 1.8;color: rgba(255,255,255,0.6);}
	.login_adv__title div {margin-top: 10px;display: flex;align-items: center;}
	.login_adv__title div span {margin-right: 15px;}
	.login_adv__title div i {font-size: 40px;}
	.login_adv__title div i.add {font-size: 20px;color: rgba(255,255,255,0.6);}
	.login_adv__bottom {position: absolute;left:0px;right: 0px;bottom: 0px;color: #fff;padding-bottom: 40px;background-image:linear-gradient(transparent, #000);}

	.login_main {flex: 1;overflow: auto;display:flex;}
	.login-form {width: 400px;margin: auto;padding:20px 0;}
	.login-header {margin-bottom: 20px;}
	.login-header .logo {display: flex;align-items: center;}
	.login-header .logo img {width: 35px;height: 35px;vertical-align: bottom;margin-right: 10px;}
	.login-header .logo label {font-size: 24px;}
	.login-header h2 {font-size: 24px;font-weight: bold;margin-top: 50px;}
	.login-oauth {display: flex;justify-content:space-around;}
	.login-form .el-divider {margin-top:40px;}

	.login_config {position: absolute;top:20px;right: 20px;}
	.el-dropdown-menu__item.selected {color: var(--el-color-primary);}

	@media (max-width: 1200px){
		.login-form {width: 340px;margin-top:35%;}
	}
	@media (max-width: 1000px){
		.login_main {display: block;}
		.login-form {width:100%;padding:1px 40px;}
		.login_adv {display: none;}
		.copyrightBottom {text-align: right;padding-right:10%;}
	}
	@media (min-width: 1250px){
		.login_main {display: block;}
		.login-form {padding:1px 40px;margin-top:22%;margin-right:22%;}
		.copyrightBottom {text-align: right;padding-right:17%;}
	}
</style>


