reset password

This commit is contained in:
2025-08-30 14:41:51 +08:00
parent 69df06b2ab
commit 9dfb53889f
3 changed files with 33 additions and 2 deletions

View File

@@ -97,6 +97,11 @@ export function editUser(user: User) {
return http.put("admin/user", user)
}
// 重置用户密码
export function resetPassword(userID: number) {
return http.post("admin/reset_password", { id: userID })
}
// 导入用户
export function importUsers(users: string[][]) {
return http.post("admin/user", { users })

View File

@@ -10,6 +10,7 @@ const emit = defineEmits<{
(e: "deleteUser", value: number[]): void
(e: "userBanned", value: User): void
(e: "openEditModal", value: User): void
(e: "resetPassword", value: User): void
}>()
async function banUser() {
@@ -20,6 +21,14 @@ async function banUser() {
</script>
<template>
<n-flex>
<n-button
size="small"
type="error"
secondary
@click="$emit('resetPassword', props.user)"
>
重置密码
</n-button>
<n-button
size="small"
type="primary"

View File

@@ -3,7 +3,13 @@ import { DataTableRowKey, SelectOption } from "naive-ui"
import Pagination from "~/shared/components/Pagination.vue"
import { parseTime } from "~/utils/functions"
import { User } from "~/utils/types"
import { deleteUsers, editUser, getUserList, importUsers } from "../api"
import {
deleteUsers,
editUser,
getUserList,
importUsers,
resetPassword,
} from "../api"
import Actions from "./components/Actions.vue"
import Name from "./components/Name.vue"
@@ -58,13 +64,14 @@ const columns: DataTableColumn<User>[] = [
{
key: "actions",
title: "选项",
width: 200,
width: 260,
render: (row) =>
h(Actions, {
user: row,
onDeleteUser: onDeleteUsers,
onUserBanned,
onOpenEditModal,
onResetPassword,
}),
},
]
@@ -92,6 +99,16 @@ async function onDeleteUsers(userIDs: DataTableRowKey[] | Ref<number[]>) {
listUsers()
}
async function onResetPassword(user: User) {
const res = await resetPassword(user.id)
users.value = users.value.map((it) => {
if (it.id === user.id) {
it.password = res.data.new_password
}
return it
})
}
async function onUserBanned(user: User) {
users.value = users.value.map((it) => {
if (it.id === user.id) {