mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 01:09:19 +08:00
feat: 个人信息页和修改密码页支持深色模式,添加独立修改密码功能
- 个人信息页和修改密码页适配 Vben 深色模式 - 头像下拉菜单新增修改密码入口,跳转 /system/change-password - 新增独立修改密码页面(/system/change-password) - 新增 changePasswordApi 调用后端 /user/change-password 接口 - 新增路由文件和相关 locale
This commit is contained in:
@@ -3,6 +3,11 @@ import { useAccessStore } from '@vben/stores';
|
|||||||
import { baseRequestClient, requestClient } from '#/api/request';
|
import { baseRequestClient, requestClient } from '#/api/request';
|
||||||
|
|
||||||
export namespace AuthApi {
|
export namespace AuthApi {
|
||||||
|
/** 修改密码参数 */
|
||||||
|
export interface ChangePasswordParams {
|
||||||
|
oldPassword: string;
|
||||||
|
newPassword: string;
|
||||||
|
}
|
||||||
/** 登录接口参数 */
|
/** 登录接口参数 */
|
||||||
export interface LoginParams {
|
export interface LoginParams {
|
||||||
account: string;
|
account: string;
|
||||||
@@ -112,3 +117,10 @@ export async function getAccessCodesApi() {
|
|||||||
export async function switchAccountApi(userId: number) {
|
export async function switchAccountApi(userId: number) {
|
||||||
return requestClient.post<AuthApi.LoginResult>(`/auth/switch/${userId}`);
|
return requestClient.post<AuthApi.LoginResult>(`/auth/switch/${userId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改密码
|
||||||
|
*/
|
||||||
|
export async function changePasswordApi(data: AuthApi.ChangePasswordParams) {
|
||||||
|
return requestClient.post('/user/change-password', data);
|
||||||
|
}
|
||||||
|
|||||||
@@ -75,6 +75,8 @@ const switchAccountModalRef = ref();
|
|||||||
const SwitchAccountIcon = createIconifyIcon('lucide:arrow-left-right');
|
const SwitchAccountIcon = createIconifyIcon('lucide:arrow-left-right');
|
||||||
// 用户图标
|
// 用户图标
|
||||||
const UserIcon = createIconifyIcon('lucide:user');
|
const UserIcon = createIconifyIcon('lucide:user');
|
||||||
|
// 锁图标
|
||||||
|
const LockIcon = createIconifyIcon('lucide:lock');
|
||||||
|
|
||||||
const menus = computed(() => {
|
const menus = computed(() => {
|
||||||
const menuItems = [];
|
const menuItems = [];
|
||||||
@@ -87,6 +89,14 @@ const menus = computed(() => {
|
|||||||
icon: UserIcon,
|
icon: UserIcon,
|
||||||
text: '个人信息',
|
text: '个人信息',
|
||||||
});
|
});
|
||||||
|
// 修改密码
|
||||||
|
menuItems.push({
|
||||||
|
handler: () => {
|
||||||
|
router.push('/system/change-password');
|
||||||
|
},
|
||||||
|
icon: LockIcon,
|
||||||
|
text: '修改密码',
|
||||||
|
});
|
||||||
|
|
||||||
// 只有超级管理员才显示切换账户功能
|
// 只有超级管理员才显示切换账户功能
|
||||||
if (accessStore.userRole === 'super') {
|
if (accessStore.userRole === 'super') {
|
||||||
@@ -99,6 +109,8 @@ const menus = computed(() => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return menuItems;
|
return menuItems;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,14 @@
|
|||||||
{
|
{
|
||||||
|
"profile": {
|
||||||
|
"title": "Profile",
|
||||||
|
"changePassword": "Change Password",
|
||||||
|
"oldPassword": "Old Password",
|
||||||
|
"newPassword": "New Password",
|
||||||
|
"confirmPassword": "Confirm Password",
|
||||||
|
"passwordMismatch": "Passwords do not match",
|
||||||
|
"changeSuccess": "Password changed successfully",
|
||||||
|
"changeFail": "Failed to change password"
|
||||||
|
},
|
||||||
"auth": {
|
"auth": {
|
||||||
"login": "Login",
|
"login": "Login",
|
||||||
"register": "Register",
|
"register": "Register",
|
||||||
|
|||||||
@@ -1,4 +1,14 @@
|
|||||||
{
|
{
|
||||||
|
"profile": {
|
||||||
|
"title": "个人信息",
|
||||||
|
"changePassword": "修改密码",
|
||||||
|
"oldPassword": "旧密码",
|
||||||
|
"newPassword": "新密码",
|
||||||
|
"confirmPassword": "确认密码",
|
||||||
|
"passwordMismatch": "两次输入的密码不一致",
|
||||||
|
"changeSuccess": "密码修改成功",
|
||||||
|
"changeFail": "密码修改失败"
|
||||||
|
},
|
||||||
"auth": {
|
"auth": {
|
||||||
"login": "登录",
|
"login": "登录",
|
||||||
"register": "注册",
|
"register": "注册",
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import type { RouteRecordRaw } from 'vue-router';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改密码静态路由
|
||||||
|
*/
|
||||||
|
const staticRoutes: RouteRecordRaw[] = [
|
||||||
|
{
|
||||||
|
name: 'ChangePassword',
|
||||||
|
path: '/system/change-password',
|
||||||
|
component: () =>
|
||||||
|
import(
|
||||||
|
'#/views/system/profile/modules/ChangePasswordModal.vue'
|
||||||
|
),
|
||||||
|
meta: {
|
||||||
|
title: '修改密码',
|
||||||
|
hideInMenu: true,
|
||||||
|
ignoreAccess: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export default staticRoutes;
|
||||||
@@ -127,16 +127,22 @@ fetchUserInfo();
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Page>
|
<Page
|
||||||
|
title="个人信息"
|
||||||
|
auto-content-height
|
||||||
|
class="bg-[#f8fafc] dark:bg-[hsl(222.34deg_10.43%_12.27%)]"
|
||||||
|
>
|
||||||
<div class="mx-auto max-w-2xl">
|
<div class="mx-auto max-w-2xl">
|
||||||
<Spin :spinning="loading">
|
<Spin :spinning="loading">
|
||||||
<div
|
<div
|
||||||
class="overflow-hidden rounded-2xl border border-slate-200/80 bg-white shadow-sm"
|
class="overflow-hidden rounded-2xl border border-slate-200/80 bg-white shadow-sm dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(222.34deg_10.43%_12.27%)]"
|
||||||
>
|
>
|
||||||
<!-- 头部 -->
|
<!-- 头部 -->
|
||||||
<div class="border-b border-slate-100 bg-slate-50/50 px-8 py-6">
|
<div class="border-b border-slate-100 bg-slate-50/50 px-8 py-6 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(240deg_3.7%_15.9%/30%)]">
|
||||||
<h2 class="text-xl font-bold text-slate-800">个人信息</h2>
|
<h2 class="text-xl font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
||||||
<p class="mt-1 text-sm text-slate-500">
|
个人信息
|
||||||
|
</h2>
|
||||||
|
<p class="mt-1 text-sm text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||||
编辑您的个人信息和头像
|
编辑您的个人信息和头像
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -160,7 +166,7 @@ fetchUserInfo();
|
|||||||
<div class="relative cursor-pointer">
|
<div class="relative cursor-pointer">
|
||||||
<Spin
|
<Spin
|
||||||
v-if="avatarLoading"
|
v-if="avatarLoading"
|
||||||
class="absolute inset-0 flex items-center justify-center bg-white/80 z-10"
|
class="absolute inset-0 z-10 flex items-center justify-center bg-white/80"
|
||||||
/>
|
/>
|
||||||
<img
|
<img
|
||||||
v-if="avatarSrc"
|
v-if="avatarSrc"
|
||||||
@@ -170,7 +176,7 @@ fetchUserInfo();
|
|||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
v-else
|
v-else
|
||||||
class="flex h-24 w-24 items-center justify-center rounded-full bg-slate-200 text-2xl text-slate-400"
|
class="flex h-24 w-24 items-center justify-center rounded-full bg-slate-200 text-2xl text-slate-400 dark:bg-[hsl(240deg_3.7%_22%)] dark:text-[hsl(240deg_5%_64.9%)]"
|
||||||
>
|
>
|
||||||
{{ userInfo?.realName?.charAt(0) || '?' }}
|
{{ userInfo?.realName?.charAt(0) || '?' }}
|
||||||
</div>
|
</div>
|
||||||
@@ -183,8 +189,10 @@ fetchUserInfo();
|
|||||||
</Upload>
|
</Upload>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<p class="font-medium text-slate-800">头像</p>
|
<p class="font-medium text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
||||||
<p class="mt-1 text-xs text-slate-500">
|
头像
|
||||||
|
</p>
|
||||||
|
<p class="mt-1 text-xs text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||||
点击选择新头像,保存后生效,建议大小不超过 2MB
|
点击选择新头像,保存后生效,建议大小不超过 2MB
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -229,7 +237,7 @@ fetchUserInfo();
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 底部按钮 -->
|
<!-- 底部按钮 -->
|
||||||
<div class="flex justify-end gap-3 border-t border-slate-100 bg-slate-50/50 px-8 py-4">
|
<div class="flex justify-end gap-3 border-t border-slate-100 bg-slate-50/50 px-8 py-4 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(240deg_3.7%_15.9%/30%)]">
|
||||||
<Button @click="handleReset">重置</Button>
|
<Button @click="handleReset">重置</Button>
|
||||||
<Button type="primary" :loading="submitting" @click="handleSubmit">
|
<Button type="primary" :loading="submitting" @click="handleSubmit">
|
||||||
保存
|
保存
|
||||||
|
|||||||
+147
@@ -0,0 +1,147 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
import { reactive, ref } from 'vue';
|
||||||
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
|
import { Page } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import type { FormItemProps } from 'ant-design-vue';
|
||||||
|
|
||||||
|
import { Button, Form, Input, message, Spin } from 'ant-design-vue';
|
||||||
|
|
||||||
|
import { changePasswordApi } from '#/api/core/auth';
|
||||||
|
|
||||||
|
defineOptions({ name: 'ChangePassword' });
|
||||||
|
|
||||||
|
const router = useRouter();
|
||||||
|
const loading = ref(false);
|
||||||
|
|
||||||
|
const formRef = ref<any>(null);
|
||||||
|
const formData = reactive({
|
||||||
|
oldPassword: '',
|
||||||
|
newPassword: '',
|
||||||
|
confirmPassword: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
/** 放在 script 中,避免模板内联 validator 里 Promise 被误解析为组件属性 */
|
||||||
|
const confirmPasswordRules: NonNullable<FormItemProps['rules']> = [
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
async validator(_rule: unknown, value: string) {
|
||||||
|
if (!value?.trim()) {
|
||||||
|
throw new Error('请确认密码');
|
||||||
|
}
|
||||||
|
if (value !== formData.newPassword) {
|
||||||
|
throw new Error('两次输入的密码不一致');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
trigger: 'change',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
async function handleSubmit() {
|
||||||
|
try {
|
||||||
|
await formRef.value?.validate();
|
||||||
|
} catch {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
await changePasswordApi({
|
||||||
|
oldPassword: formData.oldPassword,
|
||||||
|
newPassword: formData.newPassword,
|
||||||
|
});
|
||||||
|
message.success('密码修改成功');
|
||||||
|
formRef.value?.resetFields();
|
||||||
|
router.push('/system/profile');
|
||||||
|
} catch (err: any) {
|
||||||
|
message.error(err?.message || '密码修改失败');
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleReset() {
|
||||||
|
formRef.value?.resetFields();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Page
|
||||||
|
title="修改密码"
|
||||||
|
auto-content-height
|
||||||
|
class="bg-[#f8fafc] dark:bg-[hsl(222.34deg_10.43%_12.27%)]"
|
||||||
|
>
|
||||||
|
<div class="mx-auto max-w-2xl">
|
||||||
|
<div
|
||||||
|
class="overflow-hidden rounded-2xl border border-slate-200/80 bg-white shadow-sm dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(222.34deg_10.43%_12.27%)]"
|
||||||
|
>
|
||||||
|
<!-- 头部 -->
|
||||||
|
<div class="border-b border-slate-100 bg-slate-50/50 px-8 py-6 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(240deg_3.7%_15.9%/30%)]">
|
||||||
|
<h2 class="text-xl font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
||||||
|
修改密码
|
||||||
|
</h2>
|
||||||
|
<p class="mt-1 text-sm text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||||
|
请妥善保管您的新密码
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 表单 -->
|
||||||
|
<div class="px-8 py-6">
|
||||||
|
<Spin :spinning="loading">
|
||||||
|
<Form
|
||||||
|
ref="formRef"
|
||||||
|
:model="formData"
|
||||||
|
layout="vertical"
|
||||||
|
class="space-y-6"
|
||||||
|
>
|
||||||
|
<!-- 旧密码 -->
|
||||||
|
<Form.Item
|
||||||
|
label="旧密码"
|
||||||
|
name="oldPassword"
|
||||||
|
:rules="[{ required: true, message: '请输入旧密码' }]"
|
||||||
|
>
|
||||||
|
<Input.Password
|
||||||
|
v-model:value="formData.oldPassword"
|
||||||
|
placeholder="请输入旧密码"
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<!-- 新密码 -->
|
||||||
|
<Form.Item
|
||||||
|
label="新密码"
|
||||||
|
name="newPassword"
|
||||||
|
:rules="[{ required: true, message: '请输入新密码' }]"
|
||||||
|
>
|
||||||
|
<Input.Password
|
||||||
|
v-model:value="formData.newPassword"
|
||||||
|
placeholder="请输入新密码"
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
|
||||||
|
<!-- 确认密码 -->
|
||||||
|
<Form.Item
|
||||||
|
label="确认密码"
|
||||||
|
name="confirmPassword"
|
||||||
|
:rules="confirmPasswordRules"
|
||||||
|
>
|
||||||
|
<Input.Password
|
||||||
|
v-model:value="formData.confirmPassword"
|
||||||
|
placeholder="请再次输入新密码"
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
|
</Form>
|
||||||
|
</Spin>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 底部按钮 -->
|
||||||
|
<div class="flex justify-end gap-3 border-t border-slate-100 bg-slate-50/50 px-8 py-4 dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(240deg_3.7%_15.9%/30%)]">
|
||||||
|
<Button @click="handleReset">重置</Button>
|
||||||
|
<Button type="primary" :loading="loading" @click="handleSubmit">
|
||||||
|
确定
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Page>
|
||||||
|
</template>
|
||||||
Reference in New Issue
Block a user