mirror of
https://github.com/201206030/novel-plus.git
synced 2025-04-26 17:20:52 +00:00
feat: 手机端登录页面适配
This commit is contained in:
parent
dce8a21c0d
commit
dabfb9d1e8
@ -91,6 +91,14 @@ public class PageController extends BaseController {
|
||||
return ThreadLocalUtil.getTemplateDir() + "index";
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录页
|
||||
*/
|
||||
@RequestMapping("user/login.html")
|
||||
public String login() {
|
||||
return ThreadLocalUtil.getTemplateDir() + "user/login";
|
||||
}
|
||||
|
||||
/**
|
||||
* 作品页
|
||||
*/
|
||||
|
@ -4,6 +4,49 @@ var needLoginPath = ['/user/favorites.html','/user/comment.html','/user/feedback
|
||||
"/pay/index.html," +
|
||||
"/author/register.html","/author/index.html"];
|
||||
var isLogin = false;
|
||||
var url = window.location.search;
|
||||
//key(需要检索的键)
|
||||
function getSearchString(key) {
|
||||
var str = url;
|
||||
str = str.substring(1, str.length); // 获取URL中?之后的字符(去掉第一位的问号)
|
||||
// 以&分隔字符串,获得类似name=xiaoli这样的元素数组
|
||||
var arr = str.split("&");
|
||||
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
var tmp_arr = arr[i].split("=");
|
||||
if(tmp_arr[0] == key){
|
||||
return decodeURIComponent(tmp_arr[1]);
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
var keyword = getSearchString("k");
|
||||
if(keyword != undefined) {
|
||||
$("#searchKey").val(keyword);
|
||||
$("#workDirection").remove();
|
||||
$("#idGirl").remove();
|
||||
}
|
||||
|
||||
function searchByK(k){
|
||||
if(!k){
|
||||
window.location.href='/book/bookclass.html?k='+encodeURIComponent(document.getElementById("searchKey").value)
|
||||
}else{
|
||||
window.location.href='/book/bookclass.html?k='+encodeURIComponent(k)
|
||||
}
|
||||
}
|
||||
$("#searchKey").keypress(function (even) {
|
||||
if (even.which == 13) {
|
||||
even.stopPropagation();
|
||||
//enter键按下
|
||||
searchByK();
|
||||
}
|
||||
});
|
||||
Array.prototype.indexOf = function (val) {
|
||||
for (var i = 0; i < this.length; i++) {
|
||||
if (this[i] == val) return i;
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
|
||||
jQuery.cookie = function (name, value, options) {
|
||||
if (typeof value != 'undefined') {
|
||||
@ -129,5 +172,26 @@ function getQueryVariable(variable) {
|
||||
return (false);
|
||||
}
|
||||
|
||||
String.prototype.isPhone = function () {
|
||||
var strTemp = /^1[3|4|5|6|7|8|9][0-9]{9}$/;
|
||||
if (strTemp.test(this)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
String.prototype.isBlank = function () {
|
||||
if(this == null || $.trim(this) == ""){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
String.prototype.isNickName = function () {
|
||||
var strTemp = /^[\u4E00-\u9FA5A-Za-z0-9_]+$/;
|
||||
if (strTemp.test(this)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
|
@ -1847,7 +1847,7 @@ a cite {
|
||||
}
|
||||
|
||||
.layui-btn-primary:hover {
|
||||
border-color: #009688;
|
||||
border-color: #f80;
|
||||
color: #333
|
||||
}
|
||||
|
||||
@ -2230,11 +2230,11 @@ a cite {
|
||||
}
|
||||
|
||||
.layui-form-checked span, .layui-form-checked:hover span {
|
||||
background-color: #5FB878
|
||||
background-color: #f80
|
||||
}
|
||||
|
||||
.layui-form-checked i, .layui-form-checked:hover i {
|
||||
color: #5FB878
|
||||
color: #f80
|
||||
}
|
||||
|
||||
.layui-form-item .layui-form-checkbox {
|
||||
|
@ -5,109 +5,117 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||
<title>登录|注册</title>
|
||||
|
||||
<div th:include="common/css :: css"></div>
|
||||
<title>登录</title>
|
||||
|
||||
<div th:include="mobile/common/css :: css"></div>
|
||||
|
||||
|
||||
</head>
|
||||
<body id="read" >
|
||||
|
||||
</div>
|
||||
<body id="read">
|
||||
|
||||
<div style="height: 50px;line-height: 50px;text-align: center" class="layui-header header header-doc layui-bg-cyan">
|
||||
|
||||
<div style="float: left;margin-left: 10px">
|
||||
<div style="width:10%;float: left;margin-left: 10px">
|
||||
<a href="javascript:history.go(-1)">
|
||||
<i style="font-size: 20px;color: #92B8B1;" class="layui-icon"></i></a>
|
||||
<i style="font-size: 20px;color: #fff;" class="layui-icon"></i></a>
|
||||
</div>
|
||||
<b class="layui-icon">登录|注册</b>
|
||||
<div style="float: right;margin-right: 10px"><a href="/">
|
||||
<i style="font-size: 20px;color: #92B8B1;" class="layui-icon"></i>
|
||||
<b class="layui-icon">登录</b>
|
||||
<div style="width:10%;float: right;margin-right: 10px"><a href="/">
|
||||
<i style="font-size: 20px;color: #fff;" class="layui-icon"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form style="height: 500px;margin-top: 50px" class="layui-form" action="">
|
||||
<form lay-filter="loginForm" id="form1" style="height: 500px;padding-right: 20px" class="layui-form" action="">
|
||||
<input type="hidden" id="bookIdHidden" name="bookId" th:value="${bookId}"/>
|
||||
<div>
|
||||
<h3 style="text-align:center; line-height:50px;margin: 20px auto" th:text="'登录'+${application.website.name}"></h3>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">登录名</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" id="loginName" name="loginName" required lay-verify="required" placeholder="请输入登录名" autocomplete="off" class="layui-input">
|
||||
<label class="layui-form-label">手机号码</label>
|
||||
<div class="layui-input-inline">
|
||||
<input name="txtUName" type="text" id="txtUName" placeholder="请输入手机号"
|
||||
autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">密码</label>
|
||||
<div class="layui-input-inline">
|
||||
<input id="password" type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
|
||||
<input name="txtPassword" type="password" id="txtPassword" placeholder="请输入密码"
|
||||
autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux">如果登录名不存在,则直接注册!</div>
|
||||
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-block">
|
||||
<button class="layui-btn" lay-submit lay-filter="formDemo">登录|注册</button>
|
||||
<input id="autoLogin" type="checkbox" title="下次自动登录">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-block">
|
||||
<input type="button" value="登录" id="btnLogin" class="layui-btn" />
|
||||
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
|
||||
<div th:replace="common/footer :: footer">
|
||||
<div th:replace="mobile/common/footer :: footer">
|
||||
</div>
|
||||
|
||||
<a name="buttom"></a>
|
||||
</body>
|
||||
<div th:replace="common/js :: js"></div>
|
||||
|
||||
<script>
|
||||
$.get("/book/addVisit",{"bookId":$("#bookIdHidden").val()},function(){});
|
||||
|
||||
</script>
|
||||
|
||||
<script>
|
||||
//Demo
|
||||
layui.use('form', function(){
|
||||
var form = layui.form;
|
||||
|
||||
//监听提交
|
||||
form.on('submit(formDemo)', function(){
|
||||
$.post("/user/loginOrRegist",{"bookId":$("#bookIdHidden").val(),"loginName":$("#loginName").val(),"password":$("#password").val()},function (data) {
|
||||
if(data.code == 1 || data.code == 2){
|
||||
localStorage.setItem("token",data.token);
|
||||
layer.alert(data.desc);
|
||||
setTimeout(function () {
|
||||
var bookId = $("#bookIdHidden").val();
|
||||
if(bookId){
|
||||
//加入书架
|
||||
window.location.href="/book/"+bookId+".html";
|
||||
}else{
|
||||
//我的书架
|
||||
window.location.href="/book/search?token="+data.token;
|
||||
}
|
||||
},3000)
|
||||
|
||||
}else{
|
||||
layer.alert(data.desc);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
|
||||
|
||||
|
||||
function toMyCollect(){
|
||||
var token = localStorage.getItem("token");
|
||||
if(token) {
|
||||
window.location.href = "/book/search?token=" + token;
|
||||
}else{
|
||||
window.location.href = "/user/login.html";
|
||||
}
|
||||
<div th:replace="mobile/common/js :: js">
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$("#form1").css("height",($(window).height() - 130)+"px")
|
||||
if(localStorage.getItem("autoLogin")==1){
|
||||
$("#autoLogin").prop("checked",'true');
|
||||
layui.form.render('checkbox','loginForm');
|
||||
}else{
|
||||
$("#autoLogin").removeAttr("checked");
|
||||
}
|
||||
$("#btnLogin").click(function () {
|
||||
var username = $("#txtUName").val();
|
||||
if(username.isBlank()){
|
||||
layer.alert("手机号不能为空!");
|
||||
return;
|
||||
}
|
||||
if(!username.isPhone()){
|
||||
layer.alert("手机号格式不正确!");
|
||||
return;
|
||||
}
|
||||
var password = $("#txtPassword").val();
|
||||
if(password.isBlank()){
|
||||
layer.alert("密码不能为空!");
|
||||
return;
|
||||
}
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/user/login",
|
||||
data: {"username": username, "password": password},
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (data.code == 200) {
|
||||
if($("#autoLogin").is(':checked')){
|
||||
$.cookie('Authorization', data.data.token, { expires: 7 ,path: '/' });
|
||||
localStorage.setItem("autoLogin","1");
|
||||
}else {
|
||||
$.cookie('Authorization', data.data.token,{ path: '/' });
|
||||
localStorage.setItem("autoLogin","0");
|
||||
}
|
||||
var orginUrl = getSearchString("originUrl");
|
||||
window.location.href = orginUrl == undefined || orginUrl.isBlank() ? "/" : orginUrl;
|
||||
} else {
|
||||
layer.alert(data.msg);
|
||||
}
|
||||
|
||||
},
|
||||
error: function () {
|
||||
layer.alert('网络异常');
|
||||
}
|
||||
})
|
||||
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user