修正了列表修改后fetchUsers的问题
This commit is contained in:
parent
679bd25d7f
commit
f7b44a9a17
@ -39,6 +39,7 @@ const props = defineProps<{
|
|||||||
}>()
|
}>()
|
||||||
|
|
||||||
const dialogVisible = ref(false)
|
const dialogVisible = ref(false)
|
||||||
|
const options = ref<{ userId?: number, mode?: 'create' | 'edit', onConfirm?: () => void }>({})
|
||||||
const editForm = ref<UserResponse & { password?: string }>({
|
const editForm = ref<UserResponse & { password?: string }>({
|
||||||
id: 0,
|
id: 0,
|
||||||
username: '',
|
username: '',
|
||||||
@ -51,9 +52,10 @@ const editForm = ref<UserResponse & { password?: string }>({
|
|||||||
|
|
||||||
const emit = defineEmits(['confirm'])
|
const emit = defineEmits(['confirm'])
|
||||||
|
|
||||||
const open = async () => {
|
const open = async (opts: { userId?: number, mode?: 'create' | 'edit', onConfirm?: () => void }) => {
|
||||||
if (props.mode === 'edit' && props.userId) {
|
options.value = opts
|
||||||
const user = await userService.getUser(props.userId)
|
if (options.value.mode === 'edit' && options.value.userId) {
|
||||||
|
const user = await userService.getUser(options.value.userId)
|
||||||
editForm.value = { ...user }
|
editForm.value = { ...user }
|
||||||
} else {
|
} else {
|
||||||
editForm.value = {
|
editForm.value = {
|
||||||
@ -65,6 +67,9 @@ const open = async () => {
|
|||||||
updated_at: ''
|
updated_at: ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (options.value.onConfirm) {
|
||||||
|
emit('confirm', options.value.onConfirm)
|
||||||
|
}
|
||||||
dialogVisible.value = true
|
dialogVisible.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,6 +93,9 @@ const handleConfirm = async () => {
|
|||||||
await userService.updateUser(id, updateData)
|
await userService.updateUser(id, updateData)
|
||||||
}
|
}
|
||||||
emit('confirm', editForm.value)
|
emit('confirm', editForm.value)
|
||||||
|
if (options.value.onConfirm) {
|
||||||
|
options.value.onConfirm()
|
||||||
|
}
|
||||||
dialogVisible.value = false
|
dialogVisible.value = false
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('操作失败:', error)
|
console.error('操作失败:', error)
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
|
<div>
|
||||||
|
用户列表
|
||||||
|
</div>
|
||||||
<el-table :data="users" style="width: 100%">
|
<el-table :data="users" style="width: 100%">
|
||||||
<el-table-column prop="id" label="ID" width="100" />
|
<el-table-column prop="id" label="ID" width="100" />
|
||||||
<el-table-column prop="username" label="用户名" />
|
<el-table-column prop="username" label="用户名" />
|
||||||
@ -37,7 +40,9 @@ const isAdmin = store.isAdmin;
|
|||||||
|
|
||||||
const fetchUsers = async () => {
|
const fetchUsers = async () => {
|
||||||
try {
|
try {
|
||||||
users.value = await userService.getUsers();
|
const data = await userService.getUsers();
|
||||||
|
console.log('获取用户列表成功:', data);
|
||||||
|
users.value = data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取用户列表失败:', error);
|
console.error('获取用户列表失败:', error);
|
||||||
}
|
}
|
||||||
@ -46,9 +51,10 @@ const fetchUsers = async () => {
|
|||||||
const editDialogRef = ref<InstanceType<typeof EditUserDialog>>();
|
const editDialogRef = ref<InstanceType<typeof EditUserDialog>>();
|
||||||
|
|
||||||
const handleEdit = (user: UserResponse) => {
|
const handleEdit = (user: UserResponse) => {
|
||||||
editDialogRef.value?.open();
|
editDialogRef.value?.open({
|
||||||
editDialogRef.value?.$emit('confirm', () => {
|
userId: user.id,
|
||||||
fetchUsers();
|
mode: 'edit',
|
||||||
|
onConfirm: () => fetchUsers()
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user