<script type="text/html" template>
	<link rel="stylesheet" href="{{ layui.setter.base }}style/login.css?v={{ layui.admin.v }}-1" media="all">
</script>

<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
	<div class="layadmin-user-login-main">
		<div class="layadmin-user-login-box layadmin-user-login-header">
			<h2>瑶浴</h2>
			<p>数据管理系统</p>
		</div>
		<div class="layadmin-user-login-box layadmin-user-login-body layui-form">
			<div class="layui-form-item">
				<label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
				<input type="text" name="username" id="LAY-user-login-username" lay-verify="required" placeholder="用户名" class="layui-input">
			</div>
			<div class="layui-form-item">
				<label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
				<input type="password" name="passwd" id="LAY-user-login-password" lay-verify="required" placeholder="密码" class="layui-input">
			</div>
			<div class="layui-form-item">
				<button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit">登 入</button>
			</div>
		</div>
	</div>
</div>

<script>
	layui.use(['form'], function() {
		var $ = layui.$,
			setter = layui.setter,
			admin = layui.admin,
			form = layui.form,
			router = layui.router(),
			search = router.search;

		form.render();

		//提交
		form.on('submit(LAY-user-login-submit)', function(obj) {
			//请求登入接口
			var res = admin.useAjax("yyds/login/index", 'POST', obj.field);
			layer.msg(res.msg, {
				offset: '15px',
				icon: 1,
				time: 1000
			}, function() {
				if (res.code) {
					//请求成功后，写入 jwt_token
					layui.data(setter.tableName, {
						key: setter.request.tokenName,
						value: res.data.jwt
					});
					layui.data(setter.tableName, {
						key: "username",
						value: res.data.username
					});
					location.hash = search.redirect ? decodeURIComponent(search.redirect) : '/';
				}
			});
		});
	});
</script>
