diff --git a/components.d.ts b/components.d.ts index 4e3b52d..690c297 100644 --- a/components.d.ts +++ b/components.d.ts @@ -12,6 +12,7 @@ export {} /* prettier-ignore */ declare module 'vue' { export interface GlobalComponents { + ChangePasswordForm: typeof import('./src/components/change-password-form.vue')['default'] ElBreadcrumb: typeof import('element-plus/es')['ElBreadcrumb'] ElBreadcrumbItem: typeof import('element-plus/es')['ElBreadcrumbItem'] ElButton: typeof import('element-plus/es')['ElButton'] @@ -70,6 +71,7 @@ declare module 'vue' { // For TSX support declare global { + const ChangePasswordForm: typeof import('./src/components/change-password-form.vue')['default'] const ElBreadcrumb: typeof import('element-plus/es')['ElBreadcrumb'] const ElBreadcrumbItem: typeof import('element-plus/es')['ElBreadcrumbItem'] const ElButton: typeof import('element-plus/es')['ElButton'] diff --git a/src/api/auth.ts b/src/api/auth.ts index 90fad6b..0443340 100644 --- a/src/api/auth.ts +++ b/src/api/auth.ts @@ -21,3 +21,8 @@ export function register(data: { }): Promise<{ id: string; username: string }> { return http.post<{ id: string; username: string }>('/auth/register', data) } + +/** 修改本人密码。 */ +export function changePassword(oldPassword: string, newPassword: string): Promise { + return http.patch('/auth/me/password', { oldPassword, newPassword }) +} diff --git a/src/components/change-password-form.vue b/src/components/change-password-form.vue new file mode 100644 index 0000000..d6bd31a --- /dev/null +++ b/src/components/change-password-form.vue @@ -0,0 +1,48 @@ + + + diff --git a/src/components/ty-header.vue b/src/components/ty-header.vue index ed84235..904b63d 100644 --- a/src/components/ty-header.vue +++ b/src/components/ty-header.vue @@ -56,6 +56,7 @@ @@ -143,6 +144,7 @@ const emit = defineEmits<{ (e: 'toggle-fullscreen'): void (e: 'open-settings'): void (e: 'navigate', path: string): void + (e: 'change-password'): void (e: 'logout'): void }>() @@ -152,6 +154,7 @@ function onNavSelect(index: string): void { function onUserCommand(command: string): void { if (command === 'logout') emit('logout') + else if (command === 'change-password') emit('change-password') } diff --git a/src/layouts/default.vue b/src/layouts/default.vue index 8b9b212..5553c6d 100644 --- a/src/layouts/default.vue +++ b/src/layouts/default.vue @@ -22,6 +22,7 @@ @toggle-fullscreen="toggleFullscreen" @open-settings="settingsOpen = true" @navigate="handleNavigate" + @change-password="handleChangePassword" @logout="handleLogout" /> @@ -69,6 +70,7 @@