Feat: optimized code

This commit is contained in:
alongw 2023-09-03 00:16:42 +08:00
parent 6e47a5407e
commit 025e68b7b1

View File

@ -102,6 +102,21 @@ const handleToUserConfig = (user: any) => {
}
});
};
const fetchData = async () => {
const res = await execute({
params: {
userName: operationForm.value.name,
page: operationForm.value.currentPage,
page_size: operationForm.value.pageSize
}
});
data.value = res.value!;
total.value = res.value?.total ?? 0;
};
const reload = throttle(() => {
fetchData();
}, 2000);
const deleteUser = async (userList: string[]) => {
const { execute } = deleteUserApi();
@ -119,18 +134,6 @@ const handleDeleteUser = async (user: UserInfo) => {
await deleteUser([user.uuid]);
};
const fetchData = async () => {
const res = await execute({
params: {
userName: operationForm.value.name,
page: operationForm.value.currentPage,
page_size: operationForm.value.pageSize
}
});
data.value = res.value!;
total.value = res.value?.total ?? 0;
};
const handleBatchDelete = async () => {
if (selectedUsers.value.length === 0) {
return message.warn(t("请选择要删除的用户"));
@ -177,13 +180,11 @@ const newUserDialog = ref({
return message.error(t("请正确填写表单"));
try {
const res = await addUserExecute({
await addUserExecute({
data: newUserDialog.value.data
});
if (res.value === true) {
message.success(t("新增用户成功"));
newUserDialog.value.hidden();
}
message.success(t("新增用户成功"));
newUserDialog.value.hidden();
} catch (error: any) {
message.error(t("新增用户失败:") + error.response.data.data);
}
@ -191,10 +192,6 @@ const newUserDialog = ref({
}
});
const reload = throttle(() => {
fetchData();
}, 2000);
onMounted(async () => {
fetchData();
});