From df204b32c088296909075b427f4a23336ad63807 Mon Sep 17 00:00:00 2001 From: xd <844539747@qq.com> Date: Wed, 20 Mar 2024 16:55:25 +0800 Subject: [PATCH] '123' --- pom.xml | 2 +- .../com/ruoyi/common/constant/Constants.java | 7 +++ .../ruoyi/framework/config/I18nConfig.java | 43 +++++++++++++++++++ ruoyi-ui/package.json | 2 +- ruoyi-ui/vue.config.js | 9 ++-- 5 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 ruoyi-framework/src/main/java/com/ruoyi/framework/config/I18nConfig.java diff --git a/pom.xml b/pom.xml index d81cf9e..653a158 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ 2.3.3 1.4.7 2.0.43 - 6.4.8 + 6.5.0 2.13.0 3.2.2 4.1.2 diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java b/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java index 97135fb..327eacc 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java @@ -2,6 +2,8 @@ package com.ruoyi.common.constant; import io.jsonwebtoken.Claims; +import java.util.Locale; + /** * 通用常量信息 * @@ -19,6 +21,11 @@ public class Constants */ public static final String GBK = "GBK"; + /** + * 系统语言 + */ + public static final Locale DEFAULT_LOCALE = Locale.SIMPLIFIED_CHINESE; + /** * www主域 */ diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/I18nConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/I18nConfig.java new file mode 100644 index 0000000..a3f9857 --- /dev/null +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/I18nConfig.java @@ -0,0 +1,43 @@ +package com.ruoyi.framework.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.LocaleResolver; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; +import org.springframework.web.servlet.i18n.SessionLocaleResolver; +import com.ruoyi.common.constant.Constants; + +/** + * 资源文件配置加载 + * + * @author ruoyi + */ +@Configuration +public class I18nConfig implements WebMvcConfigurer +{ + @Bean + public LocaleResolver localeResolver() + { + SessionLocaleResolver slr = new SessionLocaleResolver(); + // 默认语言 + slr.setDefaultLocale(Constants.DEFAULT_LOCALE); + return slr; + } + + @Bean + public LocaleChangeInterceptor localeChangeInterceptor() + { + LocaleChangeInterceptor lci = new LocaleChangeInterceptor(); + // 参数名 + lci.setParamName("lang"); + return lci; + } + + @Override + public void addInterceptors(InterceptorRegistry registry) + { + registry.addInterceptor(localeChangeInterceptor()); + } +} diff --git a/ruoyi-ui/package.json b/ruoyi-ui/package.json index 425da91..a5a114c 100644 --- a/ruoyi-ui/package.json +++ b/ruoyi-ui/package.json @@ -68,7 +68,7 @@ "babel-eslint": "10.1.0", "babel-plugin-dynamic-import-node": "2.3.3", "chalk": "4.1.0", - "compression-webpack-plugin": "5.0.2", + "compression-webpack-plugin": "6.1.2", "connect": "3.6.6", "eslint": "7.15.0", "eslint-plugin-vue": "7.2.0", diff --git a/ruoyi-ui/vue.config.js b/ruoyi-ui/vue.config.js index a84bde4..4fa72aa 100644 --- a/ruoyi-ui/vue.config.js +++ b/ruoyi-ui/vue.config.js @@ -62,10 +62,11 @@ module.exports = { // http://doc.ruoyi.vip/ruoyi-vue/other/faq.html#使用gzip解压缩静态文件 new CompressionPlugin({ cache: false, // 不启用文件缓存 - test: /\.(js|css|html)?$/i, // 压缩文件格式 - filename: '[path].gz[query]', // 压缩后的文件名 - algorithm: 'gzip', // 使用gzip压缩 - minRatio: 0.8 // 压缩率小于1才会压缩 + test: /\.(js|css|html|jpe?g|png|gif|svg)?$/i, // 压缩文件格式 + filename: '[path][base].gz[query]', // 压缩后的文件名 + algorithm: 'gzip', // 使用gzip压缩 + minRatio: 0.8, // 压缩率小于1才会压缩 + deleteOriginalAssets: false // 压缩后删除原文件 }) ], },