From db0e420a8faad7abca50bd733d2ec1449975fa47 Mon Sep 17 00:00:00 2001 From: zhenhui <1276357500@qq.com> Date: Thu, 19 Mar 2026 14:43:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BF=BB=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/locales/langs/en/system/dept.json | 25 +++++++++- saiadmin-artd/src/locales/langs/zh.json | 2 +- .../src/locales/langs/zh/system/dept.json | 25 +++++++++- saiadmin-artd/src/locales/pageLocaleLoader.ts | 27 +++++++++-- saiadmin-artd/src/router/guards/beforeEach.ts | 19 +++++++- .../views/system/dept/modules/edit-dialog.vue | 48 ++++++++++--------- 6 files changed, 113 insertions(+), 33 deletions(-) diff --git a/saiadmin-artd/src/locales/langs/en/system/dept.json b/saiadmin-artd/src/locales/langs/en/system/dept.json index 7cac943..2abe77e 100644 --- a/saiadmin-artd/src/locales/langs/en/system/dept.json +++ b/saiadmin-artd/src/locales/langs/en/system/dept.json @@ -1,6 +1,6 @@ { "search": { - "deptName": "Dept Name", + "deptName": "channel(Department) Name", "deptCode": "Dept Code", "status": "Status", "placeholderDeptName": "Please enter dept name", @@ -8,11 +8,32 @@ "searchSelectPlaceholder": "Please select" }, "table": { - "deptName": "Dept Name", + "deptName": "channel(Department) Name", "deptCode": "Dept Code", "leader": "Leader", "sort": "Sort", "status": "Status", "createTime": "Create Time" + }, + "form": { + "titleAdd": "Add Department", + "titleEdit": "Edit Department", + "labelParentDept": "Parent Department", + "labelDeptName": "Dept Name", + "labelDeptCode": "Dept Code", + "labelLeader": "Leader", + "labelRemark": "Description", + "labelSort": "Sort", + "labelStatus": "Enabled", + "placeholderDeptName": "Please enter dept name", + "placeholderDeptCode": "Please enter dept code", + "placeholderRemark": "Please enter description", + "placeholderSort": "Please enter sort", + "noParentDept": "No parent department", + "ruleParentDeptRequired": "Please select parent department", + "ruleDeptNameRequired": "Please enter dept name", + "ruleDeptCodeRequired": "Please enter dept code", + "addSuccess": "Added successfully", + "editSuccess": "Updated successfully" } } diff --git a/saiadmin-artd/src/locales/langs/zh.json b/saiadmin-artd/src/locales/langs/zh.json index 785cb23..f6175ed 100644 --- a/saiadmin-artd/src/locales/langs/zh.json +++ b/saiadmin-artd/src/locales/langs/zh.json @@ -323,7 +323,7 @@ "role": "角色管理", "userCenter": "个人中心", "menu": "菜单管理", - "dept": "部门管理", + "dept": "渠道(部门)管理", "post": "岗位管理", "config": "系统配置" }, diff --git a/saiadmin-artd/src/locales/langs/zh/system/dept.json b/saiadmin-artd/src/locales/langs/zh/system/dept.json index 653c83a..1018a2d 100644 --- a/saiadmin-artd/src/locales/langs/zh/system/dept.json +++ b/saiadmin-artd/src/locales/langs/zh/system/dept.json @@ -1,6 +1,6 @@ { "search": { - "deptName": "部门名称", + "deptName": "渠道(部门)名称", "deptCode": "部门编码", "status": "状态", "placeholderDeptName": "请输入部门名称", @@ -8,11 +8,32 @@ "searchSelectPlaceholder": "请选择" }, "table": { - "deptName": "部门名称", + "deptName": "渠道(部门)名称", "deptCode": "部门编码", "leader": "部门领导", "sort": "排序", "status": "状态", "createTime": "创建时间" + }, + "form": { + "titleAdd": "新增部门", + "titleEdit": "编辑部门", + "labelParentDept": "上级部门", + "labelDeptName": "部门名称", + "labelDeptCode": "部门编码", + "labelLeader": "部门领导", + "labelRemark": "描述", + "labelSort": "排序", + "labelStatus": "启用", + "placeholderDeptName": "请输入部门名称", + "placeholderDeptCode": "请输入部门编码", + "placeholderRemark": "请输入部门描述", + "placeholderSort": "请输入排序", + "noParentDept": "无上级部门", + "ruleParentDeptRequired": "请选择上级部门", + "ruleDeptNameRequired": "请输入部门名称", + "ruleDeptCodeRequired": "请输入部门编码", + "addSuccess": "新增成功", + "editSuccess": "修改成功" } } diff --git a/saiadmin-artd/src/locales/pageLocaleLoader.ts b/saiadmin-artd/src/locales/pageLocaleLoader.ts index 8bb67ce..f3c9c03 100644 --- a/saiadmin-artd/src/locales/pageLocaleLoader.ts +++ b/saiadmin-artd/src/locales/pageLocaleLoader.ts @@ -43,14 +43,33 @@ export async function loadPageLocale(routePath: string): Promise { return } const locale = getCurrentLocale() - const key = getModuleKey(locale, path) const modules = locale === LanguageEnum.EN ? enModules : zhModules - const loader = modules[key] + + const tryPaths: string[] = [path] + // 兼容别名路由:例如 /user 实际页面为 /system/user + if (!path.includes('/')) { + tryPaths.push(`system/${path}`) + } + if (path === 'user') { + tryPaths.push('system/user') + } + + let matchedPath: string | null = null + let loader: (() => Promise) | undefined + for (const p of tryPaths) { + const key = getModuleKey(locale, p) + const l = modules[key] + if (l) { + matchedPath = p + loader = l + break + } + } if (!loader) { clearPageLocale() return } - if (lastLoadedPath === path && lastLoadedLocale === locale) { + if (lastLoadedPath === matchedPath && lastLoadedLocale === locale) { return } try { @@ -58,7 +77,7 @@ export async function loadPageLocale(routePath: string): Promise { const message = mod?.default if (message && typeof message === 'object') { i18n.global.mergeLocaleMessage(locale, { page: message }) - lastLoadedPath = path + lastLoadedPath = matchedPath lastLoadedLocale = locale } } catch { diff --git a/saiadmin-artd/src/router/guards/beforeEach.ts b/saiadmin-artd/src/router/guards/beforeEach.ts index cd07722..17137de 100644 --- a/saiadmin-artd/src/router/guards/beforeEach.ts +++ b/saiadmin-artd/src/router/guards/beforeEach.ts @@ -209,8 +209,23 @@ function handleLoginStatus( userStore: ReturnType, next: NavigationGuardNext ): boolean { - // 已登录或访问登录页或静态路由,直接放行 - if (userStore.isLogin || to.path === RoutesAlias.Login || isStaticRoute(to.path)) { + // 已登录或访问登录页,直接放行 + if (userStore.isLogin || to.path === RoutesAlias.Login) { + return true + } + + // 未登录时访问根路径(首页),重定向到登录页 + if (to.path === '/') { + userStore.logOut() + next({ + name: 'Login', + query: { redirect: to.fullPath } + }) + return false + } + + // 其他静态路由(注册、忘记密码、错误页等)放行 + if (isStaticRoute(to.path)) { return true } diff --git a/saiadmin-artd/src/views/system/dept/modules/edit-dialog.vue b/saiadmin-artd/src/views/system/dept/modules/edit-dialog.vue index be9f318..1ce0f78 100644 --- a/saiadmin-artd/src/views/system/dept/modules/edit-dialog.vue +++ b/saiadmin-artd/src/views/system/dept/modules/edit-dialog.vue @@ -1,14 +1,14 @@ @@ -52,6 +52,7 @@ import api from '@/api/system/dept' import { ElMessage } from 'element-plus' import type { FormInstance, FormRules } from 'element-plus' + import { useI18n } from 'vue-i18n' interface Props { modelValue: boolean @@ -71,6 +72,7 @@ }) const emit = defineEmits() + const { t } = useI18n() const formRef = ref() const optionData = reactive({ @@ -88,11 +90,13 @@ /** * 表单验证规则 */ - const rules = reactive({ - parent_id: [{ required: true, message: '请选择上级部门', trigger: 'change' }], - name: [{ required: true, message: '请输入部门名称', trigger: 'blur' }], - code: [{ required: true, message: '请输入部门编码', trigger: 'blur' }] - }) + const rules = computed(() => ({ + parent_id: [ + { required: true, message: t('page.form.ruleParentDeptRequired'), trigger: 'change' } + ], + name: [{ required: true, message: t('page.form.ruleDeptNameRequired'), trigger: 'blur' }], + code: [{ required: true, message: t('page.form.ruleDeptCodeRequired'), trigger: 'blur' }] + })) /** * 初始数据 @@ -138,7 +142,7 @@ { id: 0, value: 0, - label: '无上级部门', + label: t('page.form.noParentDept'), children: data } ] @@ -180,10 +184,10 @@ await formRef.value.validate() if (props.dialogType === 'add') { await api.save(formData) - ElMessage.success('新增成功') + ElMessage.success(t('page.form.addSuccess')) } else { await api.update(formData) - ElMessage.success('修改成功') + ElMessage.success(t('page.form.editSuccess')) } emit('success') handleClose()