Demo entry 6641345

login

   

Submitted by anonymous on Sep 18, 2017 at 04:29
Language: HTML. Code size: 7.1 kB.

<!DOCTYPE html>
<html class="ui-page-login">

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<link href="css/mui.min.css" rel="stylesheet" />
		<style>
			body {
				z-index: -2;
			}
			
			.area {
				margin: 20px auto 0px auto;
			}
			
			.mui-input-group {
				margin-top: 10px;
			}
			
			.mui-input-group:first-child {
				margin-top: 20px;
			}
			
			.mui-input-group label {
				width: 22%;
			}
			
			.mui-input-row label~input,
			.mui-input-row label~select,
			.mui-input-row label~textarea {
				width: 78%;
			}
			
			.mui-checkbox input[type=checkbox],
			.mui-radio input[type=radio] {
				top: 6px;
			}
			
			.mui-content-padded {
				margin-top: 25px;
			}
			
			.mui-btn {
				padding: 10px;
			}
			
			.link-area {
				display: block;
				margin-top: 25px;
				text-align: center;
			}
			
			.spliter {
				color: #bbb;
				padding: 0px 8px;
			}
			
			.oauth-area {
				position: absolute;
				bottom: 20px;
				left: 0px;
				text-align: center;
				width: 100%;
				padding: 0px;
				margin: 0px;
			}
			
			.oauth-area .oauth-btn {
				display: inline-block;
				width: 50px;
				height: 50px;
				background-size: 30px 30px;
				background-position: center center;
				background-repeat: no-repeat;
				margin: 0px 20px;
				/*-webkit-filter: grayscale(100%); */
				border: solid 1px #ddd;
				border-radius: 25px;
			}
			
			.oauth-area .oauth-btn:active {
				border: solid 1px #aaa;
			}
			
			.oauth-area .oauth-btn.disabled {
				background-color: #ddd;
			}
		</style>

	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<h1 class="mui-title">登录</h1>
		</header>
		<div class="mui-content">
			<form id='login-form' class="mui-input-group">
				<div class="mui-input-row">
					<label>账号</label>
					<input id='username' type="text" class="mui-input-clear mui-input" placeholder="请输入账号" maxlength="11" autocapitalize="off">
				</div>
				<div class="mui-input-row">
					<label>密码</label>
					<input id='password' type="password" class="mui-input-clear mui-input" placeholder="请输入密码" maxlength="16">
				</div>
			</form>
			<form class="mui-input-group">
				<ul class="mui-table-view mui-table-view-chevron">
					<li class="mui-table-view-cell">
						记住密码
						<div id="chkRem" class="mui-switch">
							<div class="mui-switch-handle"></div>
						</div>
					</li>
				</ul>
			</form>
			<div class="mui-content-padded">
				<button id='login' class="mui-btn mui-btn-block mui-btn-primary">登录</button>
				<div class="link-area">
					<a id='reg'>注册账号</a> <span class="spliter">|</span>
					<a id='forgetPassword'>忘记密码</a>
				</div>
			</div>
			<div class="mui-content-padded oauth-area">

			</div>
		</div>
		<script type="text/javascript" src="js/mui.min.js"></script>
		<script type="text/javascript" src="js/md5.js"></script>
		<!--<script src="js/mui.enterfocus.js"></script>
		<script src="js/app.js"></script>-->
		<script>
			mui.init();
			mui.plusReady(function() {
				var username = localStorage.getItem("username");
				if(username != null) //如果缓存中有数据,则加载出来
				{
					document.getElementById("username").value = username;
					document.getElementById("password").value = localStorage.getItem("password");
					document.getElementById("chkRem").setAttribute("class", "mui-switch mui-active");
					//					console.log("加载密码")
				}
			});

			var toMain = function() {
				mui.openWindow({
					url: 'index.html',
					id: 'index.html',
					extras: {
						login: plus.webview.currentWebview(),
					}
				});
			}
			mui.plusReady(function() {
				var zg = plus.webview.currentWebview();
				zg.setStyle({
					zindex: -2
				})
				var reg = document.getElementById("reg");
				var login = document.getElementById("login");
				//测试
				//				toMain();
				reg.addEventListener('tap', function() {
					mui.openWindow({
						url: 'reg.html',
						id: 'reg'
					})
				});
				login.addEventListener('tap', function() {
					user = document.getElementById("username").value;
					pwd = document.getElementById("password").value;
					if(user.length == 0) {
						plus.nativeUI.toast("用户名不能为空");
						return;
					}
					if(pwd.length == 0) {
						plus.nativeUI.toast("密码不能为空");
						return;
					}
					//md5加密
					if(pwd.length != 32) {
						pwd = md5(pwd);
						document.getElementById("password").value = pwd;
					}
					//是否记住密码
					remPwd();
					//Client_key
					var client_key = "ZDXY";
					//token
					var token = get_token();
					var myDate = new Date();
					var year = myDate.getFullYear();
					var month = myDate.getMonth() + 1;
					if(month < 10) {
						month = "0" + month;
					}
					var token = md5(user + pwd + year + month + client_key);
					//					console.log(token);
					mui.ajax('http://114.115.212.242/login.php', {
						data: {
							username: user,
							password: pwd,
							token: token,
							client_key: client_key
						},
						dataType: 'json',
						type: 'POST',
						timeout: 5000,
						//						headers:{'Content-Type':'application/json'},
						success: function(data) {
							if(data.errcode == 0) {
								plus.nativeUI.toast(data.errmsg)
								toMain();
							} else {
								plus.nativeUI.toast(data.errmsg)
							}

						},
						error: function(data) {
							plus.nativeUI.toast(服务器错误);
							var str = JSON.stringify(data);
							console.log(str);
						}
					})
				})

			})
			//将账号与密码保存到Localstore
			function remPwd() {
				//					var check = document.getElementById("chkRem");
				var isActive = document.getElementById("chkRem").classList.contains("mui-active");
				if(isActive) //判断记住密码项是否勾选,是则记住密码到本地缓存 
				{
					var user = document.getElementById("username").value;
					var pwd = document.getElementById("password").value;
					localStorage.setItem("username", user);
					localStorage.setItem("password", pwd);
				} else //否则就移除本地缓存 
				{
					localStorage.removeItem("username");
					localStorage.removeItem("password");
					//					console.log("删除密码")
				}
			}
			document.getElementById("password").addEventListener('tap', function() {
				document.getElementById("password").value = "";
			});
			//获取token
			var token;
			function get_token() {
				mui.ajax('http://114.115.212.242/get_token.php', {
					data: {
						appid: '565209806',
						appsecret: '3f4be92db75f9c8b1d497bce21998a15',
						granttype: 'client_credential'
					},
					async: false,
					dataType: 'json', //服务器返回json格式数据
					type: 'get', //HTTP请求类型
					success: function(data) {
						if(data.errcode != 0) {
							console.log('token获取错误');
						} else {
							token = {
								"token": data.token,
								"expires_in": data.expires_in
							};
						}

					}
				});
				return token;
			}
		</script>
	</body>

</html>

This snippet took 0.02 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).