From 1f61c0c84a7466cc61e6f779237f6d84d03fe022 Mon Sep 17 00:00:00 2001 From: liuhanqing Date: Fri, 23 May 2025 10:33:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BD=E9=99=85=E5=8C=96=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/system/SysLoginController.java | 14 ++- .../framework/config/SecurityConfig.java | 8 +- ruoyi-ui/package.json | 3 +- ruoyi-ui/src/api/login.js | 16 ++- ruoyi-ui/src/components/LangSelect/index.vue | 38 ++++++ ruoyi-ui/src/lang/en.js | 68 +++++++++++ ruoyi-ui/src/lang/index.js | 29 +++++ ruoyi-ui/src/lang/zh.js | 67 +++++++++++ ruoyi-ui/src/main.js | 5 +- ruoyi-ui/src/store/getters.js | 1 + ruoyi-ui/src/store/modules/app.js | 10 +- ruoyi-ui/src/views/login.vue | 71 +++++------ .../src/views/receive/stockin/add/index.vue | 110 +++++++++--------- 13 files changed, 339 insertions(+), 101 deletions(-) create mode 100644 ruoyi-ui/src/components/LangSelect/index.vue create mode 100644 ruoyi-ui/src/lang/en.js create mode 100644 ruoyi-ui/src/lang/index.js create mode 100644 ruoyi-ui/src/lang/zh.js diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java index c0d4981..4c518fa 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java @@ -21,7 +21,7 @@ import com.ruoyi.system.service.ISysMenuService; /** * 登录验证 - * + * * @author ruoyi */ @RestController @@ -41,7 +41,7 @@ public class SysLoginController /** * 登录方法 - * + * * @param loginBody 登录信息 * @return 结果 */ @@ -58,7 +58,7 @@ public class SysLoginController /** * 获取用户信息 - * + * * @return 用户信息 */ @GetMapping("getInfo") @@ -84,7 +84,7 @@ public class SysLoginController /** * 获取路由信息 - * + * * @return 路由信息 */ @GetMapping("getRouters") @@ -94,4 +94,10 @@ public class SysLoginController List menus = menuService.selectMenuTreeByUserId(userId); return AjaxResult.success(menuService.buildMenus(menus)); } + + @GetMapping("/changeLanguage") + public AjaxResult changeLanguage(String lang) + { + return AjaxResult.success(); + } } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java index 511842b..f9627a3 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java @@ -23,7 +23,7 @@ import com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl; /** * spring security配置 - * + * * @author ruoyi */ @EnableMethodSecurity(prePostEnabled = true, securedEnabled = true) @@ -35,7 +35,7 @@ public class SecurityConfig */ @Autowired private UserDetailsService userDetailsService; - + /** * 认证失败处理类 */ @@ -53,7 +53,7 @@ public class SecurityConfig */ @Autowired private JwtAuthenticationTokenFilter authenticationTokenFilter; - + /** * 跨域过滤器 */ @@ -114,7 +114,7 @@ public class SecurityConfig requests.antMatchers("/login", "/register", "/captchaImage").permitAll() // 静态资源,可匿名访问 .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll() - .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll() + .antMatchers("/swagger-ui.html","/changeLanguage", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll() // 除上面外的所有请求全部需要鉴权认证 .anyRequest().authenticated(); }) diff --git a/ruoyi-ui/package.json b/ruoyi-ui/package.json index bec069f..c1adda4 100644 --- a/ruoyi-ui/package.json +++ b/ruoyi-ui/package.json @@ -46,7 +46,8 @@ "vue-cropper": "0.5.5", "vue-router": "3.4.9", "vuedraggable": "2.24.3", - "vuex": "3.6.0" + "vuex": "3.6.0", + "vue-i18n": "7.3.2" }, "devDependencies": { "@vue/cli-plugin-babel": "4.4.6", diff --git a/ruoyi-ui/src/api/login.js b/ruoyi-ui/src/api/login.js index 7b7388f..19451f9 100644 --- a/ruoyi-ui/src/api/login.js +++ b/ruoyi-ui/src/api/login.js @@ -31,6 +31,20 @@ export function register(data) { }) } +// 修改语言 +export function changeLanguage(lang){ + return request({ + url: '/changeLanguage', + method: 'get', + headers: { + isToken: false, + }, + params: { + lang: lang + } + }) +} + // 获取用户详细信息 export function getInfo() { return request({ @@ -57,4 +71,4 @@ export function getCodeImg() { method: 'get', timeout: 20000 }) -} \ No newline at end of file +} diff --git a/ruoyi-ui/src/components/LangSelect/index.vue b/ruoyi-ui/src/components/LangSelect/index.vue new file mode 100644 index 0000000..f4ab3a3 --- /dev/null +++ b/ruoyi-ui/src/components/LangSelect/index.vue @@ -0,0 +1,38 @@ + + + diff --git a/ruoyi-ui/src/lang/en.js b/ruoyi-ui/src/lang/en.js new file mode 100644 index 0000000..659c19d --- /dev/null +++ b/ruoyi-ui/src/lang/en.js @@ -0,0 +1,68 @@ +// en.js +export default { + login: { + title: 'RuoYi Login Form', + logIn: 'Login in', + username: 'Username', + password: 'Password', + code: 'Code', + rememberMe: 'Remember Me' + }, + tagsView: { + refresh: 'Refresh', + close: 'Close', + closeOthers: 'Close Others', + closeAll: 'Close All' + }, + settings: { + title: 'Page style setting', + theme: 'Theme Color', + tagsView: 'Open Tags-View', + fixedHeader: 'Fixed Header', + sidebarLogo: 'Sidebar Logo' + }, + receiveStockinAdd:{ + title: 'Add Receive Stockin', + warehouse: 'Warehouse', + supplier: 'Supplier', + remark: 'Remark', + InboundMaterials: 'Inbound Materials', + AddMaterials: 'Add Materials', + ImportMaterials: 'Import Materials', + selectWarehouse: 'Please select warehouse', + selectSupplier: 'Please select supplier', + inputRemark: 'Please input remark', + warehouseRequired: 'Please select warehouse', + supplierRequired: 'Please select supplier', + addMaterialsRequired: 'Please add inbound materials', + materialInfoRequired: 'Please fill in correct material information', + addSuccess: 'Add stockin successfully', + uploadTitle: 'Import Materials', + dragText: 'Drag files here, or', + clickUpload: 'click to upload', + uploadTip: 'Only xlsx and xls files are allowed.', + downloadTemplate: 'Download Template', + confirm: 'Confirm', + cancel: 'Cancel', + serialNumber: 'No.', + guid: 'GUID', + parentId: 'Parent ID', + productCode: 'Product Code', + productName: 'Product Name', + price: 'Price', + brand: 'Brand', + unit: 'Unit', + spec: 'Specification', + description: 'Description', + batchNumber: 'Batch No.', + quantity: 'Quantity', + unitPrice: 'Unit Price', + amount: 'Amount', + operation: 'Operation', + delete: 'Delete', + totalQuantity: 'Total Quantity', + totalAmount: 'Total Amount', + submit: 'Submit', + selectProduct: 'Select Product' + } +} diff --git a/ruoyi-ui/src/lang/index.js b/ruoyi-ui/src/lang/index.js new file mode 100644 index 0000000..093f045 --- /dev/null +++ b/ruoyi-ui/src/lang/index.js @@ -0,0 +1,29 @@ +import Vue from 'vue' +import VueI18n from 'vue-i18n' +import Cookies from 'js-cookie' +import elementEnLocale from 'element-ui/lib/locale/lang/en' // element-ui lang +import elementZhLocale from 'element-ui/lib/locale/lang/zh-CN'// element-ui lang +import enLocale from './en' +import zhLocale from './zh' + +Vue.use(VueI18n) + +const messages = { + en_US: { + ...enLocale, + ...elementEnLocale + }, + zh_CN: { + ...zhLocale, + ...elementZhLocale + } +} + +const i18n = new VueI18n({ + // 设置语言 选项 en | zh + locale: Cookies.get('language') || 'zh_CN', + // 设置文本内容 + messages +}) + +export default i18n diff --git a/ruoyi-ui/src/lang/zh.js b/ruoyi-ui/src/lang/zh.js new file mode 100644 index 0000000..d6e1d12 --- /dev/null +++ b/ruoyi-ui/src/lang/zh.js @@ -0,0 +1,67 @@ +export default { + login: { + title: '若依后台管理系统', + logIn: '登录', + username: '账号', + password: '密码', + code: '验证码', + rememberMe: '记住密码' + }, + tagsView: { + refresh: '刷新', + close: '关闭', + closeOthers: '关闭其它', + closeAll: '关闭所有' + }, + settings: { + title: '系统布局配置', + theme: '主题色', + tagsView: '开启 Tags-View', + fixedHeader: '固定 Header', + sidebarLogo: '侧边栏 Logo' + }, + receiveStockinAdd:{ + title: '新增收货单据', + warehouse: '仓库', + supplier: '供应商', + remark: '备注', + InboundMaterials: '入库物料', + AddMaterials: '添加物料', + ImportMaterials: '导入物料', + selectWarehouse: '请选择仓库', + selectSupplier: '请选择供应商', + inputRemark: '请输入备注信息', + warehouseRequired: '请选择仓库', + supplierRequired: '请选择供应商', + addMaterialsRequired: '请添加入库物料', + materialInfoRequired: '请填写正确的物料信息', + addSuccess: '新增收货单成功', + uploadTitle: '物料导入', + dragText: '将文件拖到此处,或', + clickUpload: '点击上传', + uploadTip: '仅允许导入xls、xlsx格式文件。', + downloadTemplate: '下载模板', + confirm: '确 定', + cancel: '取 消', + serialNumber: '序号', + guid: 'GUID', + parentId: '父节点ID', + productCode: '物料编码', + productName: '物料名称', + price: '价格', + brand: '品牌', + unit: '单位', + spec: '规格', + description: '描述', + batchNumber: '批号', + quantity: '数量', + unitPrice: '单价', + amount: '金额', + operation: '操作', + delete: '删除', + totalQuantity: '总数量', + totalAmount: '总金额', + submit: '提交', + selectProduct: '选择物料' + } +} diff --git a/ruoyi-ui/src/main.js b/ruoyi-ui/src/main.js index da01750..b13a2e6 100644 --- a/ruoyi-ui/src/main.js +++ b/ruoyi-ui/src/main.js @@ -19,6 +19,7 @@ import './permission' // permission control import { getDicts } from "@/api/system/dict/data" import { getConfigKey } from "@/api/system/config" import { parseTime, resetForm, addDateRange, selectDictLabel, selectDictLabels, handleTree } from "@/utils/ruoyi" +import i18n from './lang' // 分页组件 import Pagination from "@/components/Pagination" // 自定义表格工具组件 @@ -70,7 +71,8 @@ DictData.install() */ Vue.use(Element, { - size: Cookies.get('size') || 'medium' // set element-ui default size + i18n: (key, value) => i18n.t(key, value), + size: Cookies.get('size') || 'medium' }) Vue.config.productionTip = false @@ -79,5 +81,6 @@ new Vue({ el: '#app', router, store, + i18n, render: h => h(App) }) diff --git a/ruoyi-ui/src/store/getters.js b/ruoyi-ui/src/store/getters.js index 3680f95..466abfe 100644 --- a/ruoyi-ui/src/store/getters.js +++ b/ruoyi-ui/src/store/getters.js @@ -16,6 +16,7 @@ const getters = { permission_routes: state => state.permission.routes, topbarRouters: state => state.permission.topbarRouters, defaultRoutes: state => state.permission.defaultRoutes, + language: state => state.app.language, sidebarRouters: state => state.permission.sidebarRouters } export default getters diff --git a/ruoyi-ui/src/store/modules/app.js b/ruoyi-ui/src/store/modules/app.js index 9f99f39..60fde8c 100644 --- a/ruoyi-ui/src/store/modules/app.js +++ b/ruoyi-ui/src/store/modules/app.js @@ -7,7 +7,8 @@ const state = { hide: false }, device: 'desktop', - size: Cookies.get('size') || 'medium' + size: Cookies.get('size') || 'medium', + language: Cookies.get('language') || 'en' } const mutations = { @@ -37,6 +38,10 @@ const mutations = { }, SET_SIDEBAR_HIDE: (state, status) => { state.sidebar.hide = status + }, + SET_LANGUAGE: (state, language) => { + state.language = language + Cookies.set('language', language) } } @@ -55,6 +60,9 @@ const actions = { }, toggleSideBarHide({ commit }, status) { commit('SET_SIDEBAR_HIDE', status) + }, + setLanguage({ commit }, language) { + commit('SET_LANGUAGE', language) } } diff --git a/ruoyi-ui/src/views/login.vue b/ruoyi-ui/src/views/login.vue index 5bdda11..afda156 100644 --- a/ruoyi-ui/src/views/login.vue +++ b/ruoyi-ui/src/views/login.vue @@ -1,13 +1,14 @@