From 5fda4e4df83029c2d6f3d042565ee42c56ab2f6f Mon Sep 17 00:00:00 2001 From: "34701892@qq.com" <34701892@qq.com> Date: Sat, 13 Dec 2025 12:30:30 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=94=A8=E6=88=B7):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=87=8D=E7=BD=AE=E5=AF=86=E7=A0=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在用户下拉菜单中新增重置密码选项 - 实现密码重置对话框及表单验证 - 添加API接口处理密码重置请求 --- src/api/jnh/index.ts | 9 ++++ src/layout/navBars/topBar/user.vue | 69 ++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/src/api/jnh/index.ts b/src/api/jnh/index.ts index b4995b2..ad8f6e2 100644 --- a/src/api/jnh/index.ts +++ b/src/api/jnh/index.ts @@ -43,3 +43,12 @@ export const getUploadUrl = (data: any) => { data, }); }; + +// 重置密码 +export const resetPassword = (params: any) => { + return request({ + url: '/user/password/reset', + method: 'post', + params, + }); +}; diff --git a/src/layout/navBars/topBar/user.vue b/src/layout/navBars/topBar/user.vue index a6f9e71..3e052db 100644 --- a/src/layout/navBars/topBar/user.vue +++ b/src/layout/navBars/topBar/user.vue @@ -78,11 +78,27 @@ {{ $t('message.user.dropdown2') }} {{ $t('message.user.dropdown3') }} {{ $t('message.user.dropdown4') }} --> + 重置密码 {{ $t('message.user.dropdown5') }} + + + + + + + + + + + + @@ -98,6 +114,7 @@ import { useThemeConfig } from '/@/stores/themeConfig'; import other from '/@/utils/other'; import mittBus from '/@/utils/mitt'; import { Session, Local } from '/@/utils/storage'; +import { resetPassword } from '/@/api/jnh'; // 引入组件 const UserNews = defineAsyncComponent(() => import('/@/layout/navBars/topBar/userNews.vue')); @@ -148,6 +165,55 @@ const onUserNewsClick = () => { const onLayoutSetingClick = () => { mittBus.emit('openSetingsDrawer'); }; + +// 自定义校验函数:对比两次密码是否一致 +/** + * @param {Object} rule - 校验规则对象 + * @param {String} value - 当前字段(confirmPassword)的值 + * @param {Function} callback - 校验完成的回调(必须调用) + */ +const validateConfirmPassword = (rule, value, callback) => { + // 1. 先判断确认密码是否为空(可选,避免空值触发“不一致”提示) + if (!value) { + return callback(new Error('请确认密码')); + } + // 2. 对比两次密码值 + if (value !== restForm.value.password) { + callback(new Error('两次密码输入不一致')); // 不一致:返回错误提示 + } else { + callback(); // 一致:校验通过(必须调用 callback()) + } +}; + +const restForm = ref({}); +const restDialogVisible = ref(false); +const rules = reactive({ + // 密码的基础校验(必填 + 长度限制) + password: [ + { required: true, message: '请输入密码', trigger: 'blur' }, + { min: 6, max: 20, message: '密码长度在 6 到 20 个字符', trigger: 'blur' }, + ], + // 确认密码的校验(必填 + 自定义对比规则) + confirmPassword: [ + { required: true, message: '请确认密码', trigger: 'blur' }, + // 自定义校验规则:对比两次密码 + { + validator: validateConfirmPassword, // 自定义校验函数 + trigger: ['blur', 'change'], // 失焦/内容变化时触发校验 + }, + ], +}); +const formRef = ref(null); +async function handleRestPwd() { + await formRef.value.validate(); + + resetPassword(restForm.value).then((res) => { + if (res.code == 200) { + ElMessage.success('重置密码成功'); + restDialogVisible.value = false; + } + }); +} // 下拉菜单点击时 const onHandleCommandClick = (path: string) => { if (path === 'logOut') { @@ -182,12 +248,15 @@ const onHandleCommandClick = (path: string) => { window.location.reload(); }) .catch(() => {}); + } else if (path === 'restPwd') { + restDialogVisible.value = true; } else if (path === 'wareHouse') { window.open('https://gitee.com/lyt-top/vue-next-admin'); } else { router.push(path); } }; + // 菜单搜索点击 const onSearchClick = () => { searchRef.value.openSearch();