From 05d65c19a732b79c405de1ad904b56bda55a2688 Mon Sep 17 00:00:00 2001 From: xiongxiaoyang <1179705413@qq.com> Date: Thu, 12 Oct 2023 09:42:28 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=89=8B=E6=9C=BA=E7=AB=AF=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/static/mobile/js/common.js | 62 ++++++++++--------- .../resources/templates/mobile/index.html | 20 +++--- .../templates/mobile/user/userinfo.html | 25 +++++++- 3 files changed, 70 insertions(+), 37 deletions(-) diff --git a/novel-front/src/main/resources/static/mobile/js/common.js b/novel-front/src/main/resources/static/mobile/js/common.js index 214592f..bc6a3ea 100644 --- a/novel-front/src/main/resources/static/mobile/js/common.js +++ b/novel-front/src/main/resources/static/mobile/js/common.js @@ -1,10 +1,11 @@ -var needLoginPath = ['/user/favorites.html','/user/comment.html','/user/feedback.html', - '/user/feedback_list.html','/user/read_history.html','/user/set_name.html', - '/user/set_password.html','/user/set_sex.html','/user/setup.html','/user/userinfo.html', +var needLoginPath = ['/user/favorites.html', '/user/comment.html', '/user/feedback.html', + '/user/feedback_list.html', '/user/read_history.html', '/user/set_name.html', + '/user/set_password.html', '/user/set_sex.html', '/user/setup.html', '/user/userinfo.html', "/pay/index.html," + - "/author/register.html","/author/index.html"]; + "/author/register.html", "/author/index.html"]; var isLogin = false; var url = window.location.search; + //key(需要检索的键) function getSearchString(key) { var str = url; @@ -14,26 +15,28 @@ function getSearchString(key) { for (var i = 0; i < arr.length; i++) { var tmp_arr = arr[i].split("="); - if(tmp_arr[0] == key){ + if (tmp_arr[0] == key) { return decodeURIComponent(tmp_arr[1]); } } return undefined; } + var keyword = getSearchString("k"); -if(keyword != undefined) { +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) +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(); @@ -101,35 +104,37 @@ Array.prototype.remove = function (val) { }; var token = $.cookie('Authorization'); -if(!token){ - if(needLoginPath.indexOf(window.location.pathname) != -1){ - location.href = '/user/login.html?originUrl='+decodeURIComponent(location.href); +if (!token) { + if (needLoginPath.indexOf(window.location.pathname) != -1) { + location.href = '/user/login.html?originUrl=' + decodeURIComponent(location.href); } $(".user_link").html("登录|注册"); -}else{ +} else { $.ajax({ type: "POST", url: "/user/refreshToken", data: {}, dataType: "json", - success: function(data){ - if(data.code == 200){ - $(".user_link").html(""+(data.data.nickName.substring(0,3))+"... 退出"); - ; - if("/user/login.html" == window.location.pathname){ + success: function (data) { + if (data.code == 200) { + $(".user_link").html("" + + "\n" + + ""); + if ("/user/login.html" == window.location.pathname) { var orginUrl = getSearchString("originUrl"); window.location.href = orginUrl == undefined || orginUrl.isBlank() ? "/" : orginUrl; return; } isLogin = true; - if(localStorage.getItem("autoLogin") == 1){ - $.cookie('Authorization', data.data.token, { expires: 7 ,path: '/' }); - }else { - $.cookie('Authorization', data.data.token,{ path: '/' }); + if (localStorage.getItem("autoLogin") == 1) { + $.cookie('Authorization', data.data.token, {expires: 7, path: '/'}); + } else { + $.cookie('Authorization', data.data.token, {path: '/'}); } - }else{ - if(needLoginPath.indexOf(window.location.pathname) != -1){ + } else { + if (needLoginPath.indexOf(window.location.pathname) != -1) { location.href = '/user/login.html'; } $(".user_link").html("登录|注册"); @@ -143,12 +148,11 @@ if(!token){ } function logout() { - $.cookie('Authorization', null,{ path: '/' }); + $.cookie('Authorization', null, {path: '/'}); location.reload(); } - function readHistory() { var books = localStorage.getItem("historyBooks"); @@ -181,7 +185,7 @@ String.prototype.isPhone = function () { }; String.prototype.isBlank = function () { - if(this == null || $.trim(this) == ""){ + if (this == null || $.trim(this) == "") { return true; } return false; diff --git a/novel-front/src/main/resources/templates/mobile/index.html b/novel-front/src/main/resources/templates/mobile/index.html index 251ed03..25e1aa8 100644 --- a/novel-front/src/main/resources/templates/mobile/index.html +++ b/novel-front/src/main/resources/templates/mobile/index.html @@ -40,16 +40,17 @@ -webkit-transition: all .3s; } - .user_link{ + .user_link { position: relative; display: inline-block; vertical-align: middle; line-height: 50px; - padding: 0 20px; + padding: 0 5px; color: #fff; float: right; } - .user_link a{ + + .user_link a { color: #fff; } @@ -187,7 +188,8 @@