pull/6/head
xuxueli 7 years ago
parent 82d6375e63
commit d24b7a308f

@ -1,5 +1,7 @@
package com.xxl.job.admin.controller.interceptor; package com.xxl.job.admin.controller.interceptor;
import com.xxl.job.admin.core.util.FtlUtil;
import com.xxl.job.admin.core.util.I18nUtil;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
@ -19,7 +21,8 @@ public class CookieInterceptor extends HandlerInterceptorAdapter {
@Override @Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception { ModelAndView modelAndView) throws Exception {
// cookie
if (modelAndView!=null && ArrayUtils.isNotEmpty(request.getCookies())) { if (modelAndView!=null && ArrayUtils.isNotEmpty(request.getCookies())) {
HashMap<String, Cookie> cookieMap = new HashMap<String, Cookie>(); HashMap<String, Cookie> cookieMap = new HashMap<String, Cookie>();
for (Cookie ck : request.getCookies()) { for (Cookie ck : request.getCookies()) {
@ -27,6 +30,11 @@ public class CookieInterceptor extends HandlerInterceptorAdapter {
} }
modelAndView.addObject("cookieMap", cookieMap); modelAndView.addObject("cookieMap", cookieMap);
} }
// static method
if (modelAndView != null) {
modelAndView.addObject("I18nUtil", FtlUtil.generateStaticModel(I18nUtil.class.getName()));
}
super.postHandle(request, response, handler, modelAndView); super.postHandle(request, response, handler, modelAndView);
} }

@ -0,0 +1,25 @@
package com.xxl.job.admin.core.util;
import freemarker.ext.beans.BeansWrapper;
import freemarker.template.TemplateHashModel;
/**
* ftl util
*
* @author xuxueli 2018-01-17 20:37:48
*/
public class FtlUtil {
public static TemplateHashModel generateStaticModel(String packageName) {
try {
BeansWrapper wrapper = BeansWrapper.getDefaultInstance();
TemplateHashModel staticModels = wrapper.getStaticModels();
TemplateHashModel fileStatics = (TemplateHashModel) staticModels.get(packageName);
return fileStatics;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

@ -10,14 +10,20 @@ import org.springframework.core.io.support.PropertiesLoaderUtils;
import java.io.IOException; import java.io.IOException;
import java.util.Properties; import java.util.Properties;
/**
* i18n util
*
* @author xuxueli 2018-01-17 20:39:06
*/
public class I18nUtil { public class I18nUtil {
private static Logger logger = LoggerFactory.getLogger(I18nUtil.class); private static Logger logger = LoggerFactory.getLogger(I18nUtil.class);
private static final String i18n_file = "i18n/message.properties"; private static final String i18n_file = "i18n/message.properties";
private static Properties prop = null; private static Properties prop = null;
private static boolean prop_cache = false;
public static Properties loadI18nProp(){ public static Properties loadI18nProp(){
if (prop == null) { if (prop_cache && prop == null) {
try { try {
Resource resource = new ClassPathResource(i18n_file); Resource resource = new ClassPathResource(i18n_file);
EncodedResource encodedResource = new EncodedResource(resource,"UTF-8"); EncodedResource encodedResource = new EncodedResource(resource,"UTF-8");

@ -1 +1,21 @@
admin_name=任务调度中心 admin_name=任务调度中心
login_btn=登录
login_remember_me=记住密码
login_username_placeholder=请输入登录账号
login_password_placeholder=请输入登录密码
login_username_empty=请输入登录账号
login_username_lt_5=登录账号不应低于5位
login_password_empty=请输入登录密码
login_password_lt_5=登录密码不应低于5位
login_success=登录成功
login_fail=登录失败
logout_btn=注销
logout_confirm=确认注销登录?
logout_success=注销成功
logout_fail=注销失败
system_tips=系统提示
system_ok=确定2
system_close=关闭2

@ -0,0 +1,6 @@
admin_name=Job Scheduling Center
login_btn=Login
login_remember_me=Remember Me
login_username_placeholder=Please input username
login_password_placeholder=Please input password

@ -0,0 +1,6 @@
admin_name=任务调度中心
login_btn=登录
login_remember_me=记住密码
login_username_placeholder=请输入登录账号
login_password_placeholder=请输入登录密码

@ -53,7 +53,17 @@
<#-- common --> <#-- common -->
<script src="${request.contextPath}/static/js/common.1.js"></script> <script src="${request.contextPath}/static/js/common.1.js"></script>
<script>var base_url = '${request.contextPath}';</script> <script>
var base_url = '${request.contextPath}';
var system_tips = '${I18nUtil.getString("system_tips")}';
var system_ok = '${I18nUtil.getString("system_ok")}';
var system_close = '${I18nUtil.getString("system_close")}';
var logout_confirm = '${I18nUtil.getString("logout_confirm")}';
var logout_success = '${I18nUtil.getString("logout_success")}';
var logout_fail = '${I18nUtil.getString("logout_fail")}';
</script>
</#macro> </#macro>
@ -61,7 +71,7 @@
<header class="main-header"> <header class="main-header">
<a href="${request.contextPath}/" class="logo"> <a href="${request.contextPath}/" class="logo">
<span class="logo-mini"><b>XXL</b></span> <span class="logo-mini"><b>XXL</b></span>
<span class="logo-lg"><b></b></span> <span class="logo-lg"><b>${I18nUtil.getString("admin_name")}</b></span>
</a> </a>
<nav class="navbar navbar-static-top" role="navigation"> <nav class="navbar navbar-static-top" role="navigation">
<a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button"><span class="sr-only"></span></a> <a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button"><span class="sr-only"></span></a>
@ -69,7 +79,7 @@
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
<li class="dropdown user user-menu"> <li class="dropdown user user-menu">
<a href=";" id="logoutBtn" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false"> <a href=";" id="logoutBtn" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
<span class="hidden-xs"></span> <span class="hidden-xs">${I18nUtil.getString("logout_btn")}</span>
</a> </a>
</li> </li>
</ul> </ul>
@ -175,7 +185,7 @@
<#macro commonFooter > <#macro commonFooter >
<footer class="main-footer"> <footer class="main-footer">
Powered by <b>XXL-JOB</b> 1.9.1 Powered by <b>XXL-JOB</b> 1.9.1SNAPSHOT
<div class="pull-right hidden-xs"> <div class="pull-right hidden-xs">
<strong>Copyright &copy; 2015-${.now?string('yyyy')} &nbsp; <strong>Copyright &copy; 2015-${.now?string('yyyy')} &nbsp;
<a href="http://www.xuxueli.com/" target="_blank" >xuxueli</a> <a href="http://www.xuxueli.com/" target="_blank" >xuxueli</a>

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title></title> <title>${I18nUtil.getString("admin_name")}</title>
<#import "/common/common.macro.ftl" as netCommon> <#import "/common/common.macro.ftl" as netCommon>
<@netCommon.commonStyle /> <@netCommon.commonStyle />
</head> </head>
@ -16,7 +16,7 @@
<div class="content-wrapper"> <div class="content-wrapper">
<!-- Content Header (Page header) --> <!-- Content Header (Page header) -->
<section class="content-header"> <section class="content-header">
<h1>使<small></small></h1> <h1>使</h1>
<!-- <!--
<ol class="breadcrumb"> <ol class="breadcrumb">
<li><a><i class="fa fa-dashboard"></i></a></li> <li><a><i class="fa fa-dashboard"></i></a></li>

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title></title> <title>${I18nUtil.getString("admin_name")}</title>
<#import "/common/common.macro.ftl" as netCommon> <#import "/common/common.macro.ftl" as netCommon>
<@netCommon.commonStyle /> <@netCommon.commonStyle />
<!-- daterangepicker --> <!-- daterangepicker -->
@ -18,8 +18,9 @@
<div class="content-wrapper"> <div class="content-wrapper">
<!-- Content Header (Page header) --> <!-- Content Header (Page header) -->
<section class="content-header"> <section class="content-header">
<h1><small></small></h1> <h1></h1>
<!-- <!--
<h1><small></small></h1>
<ol class="breadcrumb"> <ol class="breadcrumb">
<li><a><i class="fa fa-dashboard"></i></a></li> <li><a><i class="fa fa-dashboard"></i></a></li>
<li class="active">使</li> <li class="active">使</li>

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title></title> <title>${I18nUtil.getString("admin_name")}</title>
<#import "/common/common.macro.ftl" as netCommon> <#import "/common/common.macro.ftl" as netCommon>
<@netCommon.commonStyle /> <@netCommon.commonStyle />
<link rel="stylesheet" href="${request.contextPath}/static/plugins/codemirror/lib/codemirror.css"> <link rel="stylesheet" href="${request.contextPath}/static/plugins/codemirror/lib/codemirror.css">

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title></title> <title>${I18nUtil.getString("admin_name")}</title>
<#import "/common/common.macro.ftl" as netCommon> <#import "/common/common.macro.ftl" as netCommon>
<@netCommon.commonStyle /> <@netCommon.commonStyle />
<!-- DataTables --> <!-- DataTables -->
@ -18,7 +18,7 @@
<div class="content-wrapper"> <div class="content-wrapper">
<!-- Content Header (Page header) --> <!-- Content Header (Page header) -->
<section class="content-header"> <section class="content-header">
<h1><small></small></h1> <h1></h1>
</section> </section>
<!-- Main content --> <!-- Main content -->

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title></title> <title>${I18nUtil.getString("admin_name")}</title>
<#import "/common/common.macro.ftl" as netCommon> <#import "/common/common.macro.ftl" as netCommon>
<@netCommon.commonStyle /> <@netCommon.commonStyle />
<!-- DataTables --> <!-- DataTables -->
@ -19,7 +19,7 @@
<div class="content-wrapper"> <div class="content-wrapper">
<!-- Content Header (Page header) --> <!-- Content Header (Page header) -->
<section class="content-header"> <section class="content-header">
<h1><small></small></h1> <h1></h1>
<!-- <!--
<ol class="breadcrumb"> <ol class="breadcrumb">
<li><a><i class="fa fa-dashboard"></i></a></li> <li><a><i class="fa fa-dashboard"></i></a></li>

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title></title> <title>${I18nUtil.getString("admin_name")}</title>
<#import "/common/common.macro.ftl" as netCommon> <#import "/common/common.macro.ftl" as netCommon>
<@netCommon.commonStyle /> <@netCommon.commonStyle />
</head> </head>

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title></title> <title>${I18nUtil.getString("admin_name")}</title>
<#import "/common/common.macro.ftl" as netCommon> <#import "/common/common.macro.ftl" as netCommon>
<@netCommon.commonStyle /> <@netCommon.commonStyle />
<!-- DataTables --> <!-- DataTables -->
@ -20,7 +20,7 @@
<div class="content-wrapper"> <div class="content-wrapper">
<!-- Content Header (Page header) --> <!-- Content Header (Page header) -->
<section class="content-header"> <section class="content-header">
<h1><small></small></h1> <h1></h1>
<!-- <!--
<ol class="breadcrumb"> <ol class="breadcrumb">
<li><a><i class="fa fa-dashboard"></i></a></li> <li><a><i class="fa fa-dashboard"></i></a></li>

@ -1,7 +1,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title></title> <title>${I18nUtil.getString("admin_name")}</title>
<#import "/common/common.macro.ftl" as netCommon> <#import "/common/common.macro.ftl" as netCommon>
<@netCommon.commonStyle /> <@netCommon.commonStyle />
<link rel="stylesheet" href="${request.contextPath}/static/adminlte/plugins/iCheck/square/blue.css"> <link rel="stylesheet" href="${request.contextPath}/static/adminlte/plugins/iCheck/square/blue.css">
@ -13,31 +13,43 @@
</div> </div>
<form id="loginForm" method="post" > <form id="loginForm" method="post" >
<div class="login-box-body"> <div class="login-box-body">
<p class="login-box-msg"></p> <p class="login-box-msg">${I18nUtil.getString("admin_name")}</p>
<div class="form-group has-feedback"> <div class="form-group has-feedback">
<input type="text" name="userName" class="form-control" placeholder="请输入登录账号" value="admin" > <input type="text" name="userName" class="form-control" placeholder="${I18nUtil.getString("login_username_placeholder")}" value="admin" maxlength="18" >
<span class="glyphicon glyphicon-envelope form-control-feedback"></span> <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
</div> </div>
<div class="form-group has-feedback"> <div class="form-group has-feedback">
<input type="password" name="password" class="form-control" placeholder="请输入登录密码" value="123456" > <input type="password" name="password" class="form-control" placeholder="${I18nUtil.getString("login_password_placeholder")}" value="123456" maxlength="18" >
<span class="glyphicon glyphicon-lock form-control-feedback"></span> <span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div> </div>
<div class="row"> <div class="row">
<div class="col-xs-8"> <div class="col-xs-8">
<div class="checkbox icheck"> <div class="checkbox icheck">
<label> <label>
<input type="checkbox" name="ifRemember" > Remember Me <input type="checkbox" name="ifRemember" > ${I18nUtil.getString("login_remember_me")}
</label> </label>
</div> </div>
</div><!-- /.col --> </div><!-- /.col -->
<div class="col-xs-4"> <div class="col-xs-4">
<button type="submit" class="btn btn-primary btn-block btn-flat"></button> <button type="submit" class="btn btn-primary btn-block btn-flat">${I18nUtil.getString("login_btn")}</button>
</div> </div>
</div> </div>
</div> </div>
</form> </form>
</div> </div>
<@netCommon.commonScript /> <@netCommon.commonScript />
<script>
var login_username_empty = '${I18nUtil.getString("login_username_empty")}';
var login_username_lt_5 = '${I18nUtil.getString("login_username_lt_5")}';
var login_password_empty = '${I18nUtil.getString("login_password_empty")}';
var login_password_lt_5 = '${I18nUtil.getString("login_password_lt_5")}';
var login_success = '${I18nUtil.getString("login_success")}';
var login_fail = '${I18nUtil.getString("login_fail")}';
var system_tips = '${I18nUtil.getString("system_tips")}';
var system_ok = '${I18nUtil.getString("system_ok")}';
</script>
<script src="${request.contextPath}/static/plugins/jquery/jquery.validate.min.js"></script> <script src="${request.contextPath}/static/plugins/jquery/jquery.validate.min.js"></script>
<script src="${request.contextPath}/static/adminlte/plugins/iCheck/icheck.min.js"></script> <script src="${request.contextPath}/static/adminlte/plugins/iCheck/icheck.min.js"></script>
<script src="${request.contextPath}/static/js/login.1.js"></script> <script src="${request.contextPath}/static/js/login.1.js"></script>

@ -2,12 +2,12 @@ $(function(){
// logout // logout
$("#logoutBtn").click(function(){ $("#logoutBtn").click(function(){
layer.confirm('?', {icon: 3, title:''}, function(index){ layer.confirm(logout_confirm, {icon: 3, title:system_tips}, function(index){
layer.close(index); layer.close(index);
$.post(base_url + "/logout", function(data, status) { $.post(base_url + "/logout", function(data, status) {
if (data.code == "200") { if (data.code == "200") {
layer.msg(''); layer.msg(logout_success);
setTimeout(function(){ setTimeout(function(){
window.location.href = base_url + "/"; window.location.href = base_url + "/";
}, 500); }, 500);
@ -21,8 +21,9 @@ $(function(){
});*/ });*/
} else { } else {
layer.open({ layer.open({
title: '', title: system_tips,
content: (data.msg || "操作失败"), btn: [system_ok, system_close],
content: (data.msg || logout_fail),
icon: '2' icon: '2'
}); });
} }

@ -1,8 +1,6 @@
/** /**
* Created by xuxueli on 17/4/24. * Created by xuxueli on 17/4/24.
*/ */
$(function () { $(function () {
// 过滤时间 // 过滤时间

@ -25,14 +25,13 @@ $(function(){
}, },
messages : { messages : {
userName : { userName : {
required :"请输入登录账号." , required : login_username_empty,
minlength:"登录账号不应低于5位", minlength : login_username_lt_5
maxlength:"登录账号不应超过18位" },
},
password : { password : {
required :"请输入登录密码." , required : login_password_empty ,
minlength:"登录密码不应低于5位", minlength : login_password_lt_5
maxlength:"登录密码不应超过18位" /*,maxlength:"登录密码不应超过18位"*/
} }
}, },
highlight : function(element) { highlight : function(element) {
@ -48,7 +47,7 @@ $(function(){
submitHandler : function(form) { submitHandler : function(form) {
$.post(base_url + "/login", $("#loginForm").serialize(), function(data, status) { $.post(base_url + "/login", $("#loginForm").serialize(), function(data, status) {
if (data.code == "200") { if (data.code == "200") {
layer.msg(''); layer.msg(login_success);
setTimeout(function(){ setTimeout(function(){
window.location.href = base_url; window.location.href = base_url;
}, 500); }, 500);
@ -62,8 +61,9 @@ $(function(){
});*/ });*/
} else { } else {
layer.open({ layer.open({
title: '', title: system_tips,
content: (data.msg || "登录失败"), btn: [system_ok],
content: (data.msg || login_fail),
icon: '2' icon: '2'
}); });
} }

Loading…
Cancel
Save