From d24b7a308f61c9fc29b72e99e469193b8946806c Mon Sep 17 00:00:00 2001 From: xuxueli <931591021@qq.com> Date: Wed, 17 Jan 2018 21:36:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BD=E9=99=85=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../interceptor/CookieInterceptor.java | 10 +++++++- .../com/xxl/job/admin/core/util/FtlUtil.java | 25 +++++++++++++++++++ .../com/xxl/job/admin/core/util/I18nUtil.java | 8 +++++- .../main/resources/i18n/message.properties | 22 +++++++++++++++- .../main/resources/i18n/message_en.properties | 6 +++++ .../main/resources/i18n/message_zh.properties | 6 +++++ .../WEB-INF/template/common/common.macro.ftl | 18 ++++++++++--- .../src/main/webapp/WEB-INF/template/help.ftl | 4 +-- .../main/webapp/WEB-INF/template/index.ftl | 5 ++-- .../template/jobcode/jobcode.index.ftl | 2 +- .../template/jobgroup/jobgroup.index.ftl | 4 +-- .../template/jobinfo/jobinfo.index.ftl | 4 +-- .../WEB-INF/template/joblog/joblog.detail.ftl | 2 +- .../WEB-INF/template/joblog/joblog.index.ftl | 4 +-- .../main/webapp/WEB-INF/template/login.ftl | 24 +++++++++++++----- .../src/main/webapp/static/js/common.1.js | 9 ++++--- .../src/main/webapp/static/js/index.js | 2 -- .../src/main/webapp/static/js/login.1.js | 20 +++++++-------- 18 files changed, 134 insertions(+), 41 deletions(-) create mode 100644 xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/FtlUtil.java create mode 100644 xxl-job-admin/src/main/resources/i18n/message_zh.properties diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/interceptor/CookieInterceptor.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/interceptor/CookieInterceptor.java index bd84534f..9337d1b0 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/interceptor/CookieInterceptor.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/interceptor/CookieInterceptor.java @@ -1,5 +1,7 @@ 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.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; @@ -19,7 +21,8 @@ public class CookieInterceptor extends HandlerInterceptorAdapter { @Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { - + + // cookie if (modelAndView!=null && ArrayUtils.isNotEmpty(request.getCookies())) { HashMap cookieMap = new HashMap(); for (Cookie ck : request.getCookies()) { @@ -27,6 +30,11 @@ public class CookieInterceptor extends HandlerInterceptorAdapter { } modelAndView.addObject("cookieMap", cookieMap); } + + // static method + if (modelAndView != null) { + modelAndView.addObject("I18nUtil", FtlUtil.generateStaticModel(I18nUtil.class.getName())); + } super.postHandle(request, response, handler, modelAndView); } diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/FtlUtil.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/FtlUtil.java new file mode 100644 index 00000000..fe888a1c --- /dev/null +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/FtlUtil.java @@ -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; + } + +} diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/I18nUtil.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/I18nUtil.java index 87a18a45..e4dc8b1a 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/I18nUtil.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/I18nUtil.java @@ -10,14 +10,20 @@ import org.springframework.core.io.support.PropertiesLoaderUtils; import java.io.IOException; import java.util.Properties; +/** + * i18n util + * + * @author xuxueli 2018-01-17 20:39:06 + */ public class I18nUtil { private static Logger logger = LoggerFactory.getLogger(I18nUtil.class); private static final String i18n_file = "i18n/message.properties"; private static Properties prop = null; + private static boolean prop_cache = false; public static Properties loadI18nProp(){ - if (prop == null) { + if (prop_cache && prop == null) { try { Resource resource = new ClassPathResource(i18n_file); EncodedResource encodedResource = new EncodedResource(resource,"UTF-8"); diff --git a/xxl-job-admin/src/main/resources/i18n/message.properties b/xxl-job-admin/src/main/resources/i18n/message.properties index 31126984..1ddd6895 100644 --- a/xxl-job-admin/src/main/resources/i18n/message.properties +++ b/xxl-job-admin/src/main/resources/i18n/message.properties @@ -1 +1,21 @@ -admin_name=任务调度中心 \ No newline at end of file +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 \ No newline at end of file diff --git a/xxl-job-admin/src/main/resources/i18n/message_en.properties b/xxl-job-admin/src/main/resources/i18n/message_en.properties index e69de29b..689fda5d 100644 --- a/xxl-job-admin/src/main/resources/i18n/message_en.properties +++ b/xxl-job-admin/src/main/resources/i18n/message_en.properties @@ -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 \ No newline at end of file diff --git a/xxl-job-admin/src/main/resources/i18n/message_zh.properties b/xxl-job-admin/src/main/resources/i18n/message_zh.properties new file mode 100644 index 00000000..28c9b488 --- /dev/null +++ b/xxl-job-admin/src/main/resources/i18n/message_zh.properties @@ -0,0 +1,6 @@ +admin_name=任务调度中心 + +login_btn=登录 +login_remember_me=记住密码 +login_username_placeholder=请输入登录账号 +login_password_placeholder=请输入登录密码 \ No newline at end of file diff --git a/xxl-job-admin/src/main/webapp/WEB-INF/template/common/common.macro.ftl b/xxl-job-admin/src/main/webapp/WEB-INF/template/common/common.macro.ftl index 2a9109c2..b94530c1 100644 --- a/xxl-job-admin/src/main/webapp/WEB-INF/template/common/common.macro.ftl +++ b/xxl-job-admin/src/main/webapp/WEB-INF/template/common/common.macro.ftl @@ -53,7 +53,17 @@ <#-- common --> - + @@ -61,7 +71,7 @@