refactor: 移除冗余的成功消息提示代码

统一移除各模块中API调用后的成功消息提示,简化代码结构
保留错误处理逻辑,仅通过控制台输出错误信息
This commit is contained in:
zhangtao
2025-06-09 22:47:59 +08:00
parent d960c154fc
commit 394ac34d84
15 changed files with 45 additions and 138 deletions
+1 -12
View File
@@ -193,10 +193,8 @@ const handleSave = async (item: any) => {
try {
await updateConfig(tempConfigState);
message.success(`${item.config_name} 保存成功`);
isEditing[item.config_key] = false; // 退出编辑模式
} catch (error) {
message.error(`${item.config_name} 保存失败: ${error.message}`);
console.error('保存失败:', error);
} finally {
isSaving[item.config_key] = false; // 重置保存状态
}
@@ -212,15 +210,6 @@ const beforeUpload = (file: File) => {
return true;
};
// 编辑操作
const handleEdit = (configKey: string) => {
isEditing[configKey] = true;
};
// 取消操作
const handleCancel = (configKey: string) => {
isEditing[configKey] = false;
};
// 生命周期钩子
onMounted(() => {
+2 -7
View File
@@ -364,8 +364,7 @@ const onInfoFormFinish = async (values: any) => {
try {
infoSubmitting.value = true;
values.avatar = infoFormState.avatar;
const response = await updateCurrentUserInfo(values);
message.success(response.data.msg);
await updateCurrentUserInfo(values);
await userStore.getUserInfo;
} catch (error) {
console.error(error);
@@ -395,9 +394,7 @@ const onPasswordFormFinish = async (values: any) => {
new_password: values.newPassword
};
const response = await changeCurrentUserPassword(data);
message.success(response.data.msg);
await changeCurrentUserPassword(data);
await logout({ token: storage.get('Access-Token') });
// 重置 store 状态
@@ -439,8 +436,6 @@ const handleUpload = async (options: any) => {
infoFormState.avatar = fileUrl;
fileList.value = [{ url: fileUrl }];
message.success(response.data.msg);
onSuccess(response, file);
} catch (error) {
onError(error);
+2 -4
View File
@@ -232,8 +232,7 @@ const onSubmit = async () => {
return;
}
await forgetPasswordFormRef.value.validate();
const response = await forgetPassword({ ...forgetPasswordForm });
message.success(response.data.msg);
await forgetPassword({ ...forgetPasswordForm });
Object.keys(forgetPasswordForm).forEach(key => delete forgetPasswordForm[key]);
modalVisible.value = false;
} else {
@@ -244,8 +243,7 @@ const onSubmit = async () => {
return;
}
await registerFormRef.value.validate();
const response = await registerUser({ ...registerForm });
message.success(response.data.msg);
await registerUser({ ...registerForm });
Object.keys(registerForm).forEach(key => delete registerForm[key]);
modalVisible.value = false;
}
+3 -8
View File
@@ -340,9 +340,7 @@ const modalHandle = (modalType: string, index?: number) => {
const deleteRow = async (row: tableType) => {
try {
tableLoading.value = true;
const response = await deleteConfig({ id: row.id })
const result = response.data;
message.success(result.msg);
await deleteConfig({ id: row.id })
loadingData();
} catch (error) {
console.log(error)
@@ -367,11 +365,9 @@ const handleModalSumbit = async () => {
delete createBody[key];
}
})
const response = await createConfig(createBody)
await createConfig(createBody)
openModal.value = false;
Object.keys(createState).forEach(key => delete createState[key]);
const result = response.data;
message.success(result.msg);
loadingData();
} catch (error) {
console.log(error)
@@ -382,9 +378,8 @@ const handleModalSumbit = async () => {
} else if (modalTitle.value === 'update') {
try {
await updateForm.value.validate();
const response = await updateConfig(updateState)
await updateConfig(updateState)
openModal.value = false;
message.success(response.data.msg);
loadingData();
} catch (error) {
console.log(error)
+4 -12
View File
@@ -383,9 +383,7 @@ const resetFields = () => {
//
const deleteRow = (row: tableDataType) => {
deleteDept({ id: row.id }).then(response => {
const result = response.data;
message.success(result.msg);
deleteDept({ id: row.id }).then(() => {
loadingData();
}).catch(error => {
console.log(error);
@@ -404,9 +402,7 @@ const handleMoreClick: MenuProps['onClick'] = e => {
content: e.key == 1 ? '是否确定启用选择项?' : '是否确定停用选择项?',
onOk() {
const body = { ids: selectedRowKeys.value, available: e.key == 1 ? true : false };
batchAvailableDept(body).then(response => {
const result = response.data;
message.success(result.msg);
batchAvailableDept(body).then(() => {
selectedRowKeys.value = [];
loadingData();
}).catch(error => {
@@ -468,13 +464,11 @@ const handleModalSumbit = () => {
}
});
createDept(createBody).then(response => {
const result = response.data;
createDept(createBody).then(() => {
modalSubmitLoading.value = false;
openModal.value = false;
Object.keys(createState).forEach(key => delete createState[key]);
createState.order = 1;
message.success(result.msg);
loadingData();
}).catch(error => {
console.error(error);
@@ -487,11 +481,9 @@ const handleModalSumbit = () => {
} else if (modalTitle.value === 'update') {
updateForm.value.validate().then(() => {
updateDept(updateState).then(response => {
updateDept(updateState).then(() => {
modalSubmitLoading.value = false;
openModal.value = false;
const result = response.data;
message.success(result.msg);
loadingData();
}).catch(error => {
+3 -8
View File
@@ -516,9 +516,7 @@ const modalHandle = (modalType: string, index?: number) => {
//
const deleteRow = (row: tableDictDataType) => {
deleteDictData({ id: row.id }).then(response => {
const result = response.data;
message.success(result.msg);
deleteDictData({ id: row.id }).then(() => {
loadingData();
}).catch(error => {
console.log(error)
@@ -542,12 +540,10 @@ const handleModalSumbit = () => {
}
})
createDictData(createBody).then(response => {
createDictData(createBody).then(() => {
modalSubmitLoading.value = false;
openModal.value = false;
Object.keys(createState).forEach(key => delete createState[key]);
const result = response.data;
message.success(result.msg);
loadingData();
}).catch(error => {
@@ -562,10 +558,9 @@ const handleModalSumbit = () => {
} else if (modalTitle.value === 'update') {
updateForm.value.validate().then(() => {
updateDictData(updateState).then(response => {
updateDictData(updateState).then(() => {
modalSubmitLoading.value = false;
openModal.value = false;
message.success(response.data.msg);
loadingData();
}).catch(error => {
modalSubmitLoading.value = false;
+3 -8
View File
@@ -366,9 +366,7 @@ const modalHandle = (modalType: string, index?: number) => {
//
const deleteRow = (row: tableDictType) => {
deleteDictType({ id: row.id }).then(response => {
const result = response.data;
message.success(result.msg);
deleteDictType({ id: row.id }).then(() => {
loadingData();
}).catch(error => {
console.log(error)
@@ -393,12 +391,10 @@ const handleModalSumbit = () => {
}
})
createDictType(createBody).then(response => {
createDictType(createBody).then(() => {
modalSubmitLoading.value = false;
openModal.value = false;
Object.keys(createState).forEach(key => delete createState[key]);
const result = response.data;
message.success(result.msg);
loadingData();
}).catch(error => {
@@ -413,10 +409,9 @@ const handleModalSumbit = () => {
} else if (modalTitle.value === 'update') {
updateForm.value.validate().then(() => {
updateDictType(updateState).then(response => {
updateDictType(updateState).then(() => {
modalSubmitLoading.value = false;
openModal.value = false;
message.success(response.data.msg);
loadingData();
}).catch(error => {
modalSubmitLoading.value = false;
+5 -14
View File
@@ -751,9 +751,7 @@ const modalHandle = (modalType: string, index?: number) => {
//
const deleteRow = (row: tableJobType) => {
deleteJob({ id: row.id }).then(response => {
const result = response.data;
message.success(result.msg);
deleteJob({ id: row.id }).then(() => {
loadingData();
}).catch(error => {
console.log(error)
@@ -777,12 +775,10 @@ const handleModalSumbit = () => {
}
})
createJob(createBody).then(response => {
createJob(createBody).then(() => {
modalSubmitLoading.value = false;
openModal.value = false;
Object.keys(createState).forEach(key => delete createState[key]);
const result = response.data;
message.success(result.msg);
loadingData();
}).catch(error => {
@@ -797,10 +793,9 @@ const handleModalSumbit = () => {
} else if (modalTitle.value === 'update') {
updateForm.value.validate().then(() => {
updateJob(updateState).then(response => {
updateJob(updateState).then(() => {
modalSubmitLoading.value = false;
openModal.value = false;
message.success(response.data.msg);
loadingData();
}).catch(error => {
modalSubmitLoading.value = false;
@@ -864,9 +859,7 @@ const handleClear = () => {
title: '警告',
content: '是否确认清空所有定时任务数据?',
onOk() {
clearJob().then(response => {
const result = response.data;
message.success(result.msg);
clearJob().then(() => {
loadingData();
})
}
@@ -875,9 +868,7 @@ const handleClear = () => {
// : 1: 2: 3:
const handleOption = (row: tableJobType, option: number) => {
OptionJob({ id: row.id, option: option }).then(response => {
const result = response.data;
message.success(result.msg);
OptionJob({ id: row.id, option: option }).then(() => {
loadingData();
})
}
+1 -3
View File
@@ -290,9 +290,7 @@ const resetFields = () => {
//
const deleteRow = (row: tableDataType) => {
deleteLog({ id: row.id }).then(response => {
const result = response.data;
message.success(result.msg);
deleteLog({ id: row.id }).then(() => {
loadingData();
}).catch(error => {
console.log(error)
+4 -12
View File
@@ -601,9 +601,7 @@ const modalHandle = (modalType: string, record?: tableDataType) => {
//
const deleteRow = (row: tableDataType) => {
deleteMenu({ id: row.id }).then(response => {
const result = response.data;
message.success(result.msg);
deleteMenu({ id: row.id }).then(() => {
loadingData();
}).catch(error => {
@@ -623,9 +621,7 @@ const handleMoreClick: MenuProps['onClick'] = e => {
content: e.key == 1 ? '是否确定启用选择项?' : '是否确定停用选择项?',
onOk() {
const body = { ids: selectedRowKeys.value, available: e.key == 1 ? true : false };
batchAvailableMenu(body).then(response => {
const result = response.data;
message.success(result.msg);
batchAvailableMenu(body).then(() => {
selectedRowKeys.value = [];
loadingData();
}).catch(error => {
@@ -651,7 +647,7 @@ const handleModalSumbit = () => {
}
})
createMenu(createBody).then(response => {
createMenu(createBody).then(() => {
modalSubmitLoading.value = false;
openModal.value = false;
Object.keys(createState).forEach(key => delete createState[key])
@@ -659,8 +655,6 @@ const handleModalSumbit = () => {
createState.order = 1;
createState.cache = true;
createState.hidden = false;
const result = response.data;
message.success(result.msg);
loadingData();
}).catch(error => {
@@ -675,11 +669,9 @@ const handleModalSumbit = () => {
} else if (modalTitle.value === 'update') {
updateForm.value.validate().then(() => {
updateMenu(updateState).then(response => {
updateMenu(updateState).then(() => {
modalSubmitLoading.value = false;
openModal.value = false;
const result = response.data;
message.success(result.msg);
loadingData();
}).catch(error => {
+4 -11
View File
@@ -400,9 +400,7 @@ const modalHandle = (modalType: string, index?: number) => {
//
const deleteRow = (row: tableDataType) => {
deleteNotice({ id: row.id }).then(response => {
const result = response.data;
message.success(result.msg);
deleteNotice({ id: row.id }).then(() => {
loadingData();
}).catch(error => {
console.log(error)
@@ -421,9 +419,7 @@ const handleMoreClick: MenuProps['onClick'] = e => {
content: e.key == 1 ? '是否确定启用选择项?' : '是否确定停用选择项?',
onOk() {
const body = { ids: selectedRowKeys.value, available: e.key == 1 ? true : false };
batchAvailableNotice(body).then(response => {
const result = response.data;
message.success(result.msg);
batchAvailableNotice(body).then(() => {
selectedRowKeys.value = [];
loadingData();
}).catch(error => {
@@ -450,12 +446,10 @@ const handleModalSumbit = () => {
}
})
createNotice(createBody).then(response => {
createNotice(createBody).then(() => {
modalSubmitLoading.value = false;
openModal.value = false;
Object.keys(createState).forEach(key => delete createState[key]);
const result = response.data;
message.success(result.msg);
loadingData();
}).catch(error => {
@@ -470,10 +464,9 @@ const handleModalSumbit = () => {
} else if (modalTitle.value === 'update') {
updateForm.value.validate().then(() => {
updateNotice(updateState).then(response => {
updateNotice(updateState).then(() => {
modalSubmitLoading.value = false;
openModal.value = false;
message.success(response.data.msg);
loadingData();
})
+4 -11
View File
@@ -369,9 +369,7 @@ const modalHandle = (modalType: string, index?: number) => {
//
const deleteRow = (row: tableDataType) => {
deletePosition({ id: row.id }).then(response => {
const result = response.data;
message.success(result.msg);
deletePosition({ id: row.id }).then(() => {
loadingData();
}).catch(error => {
console.log(error)
@@ -390,9 +388,7 @@ const handleMoreClick: MenuProps['onClick'] = e => {
content: e.key == 1 ? '是否确定启用选择项?' : '是否确定停用选择项?',
onOk() {
const body = { ids: selectedRowKeys.value, available: e.key == 1 ? true : false };
batchAvailablePosition(body).then(response => {
const result = response.data;
message.success(result.msg);
batchAvailablePosition(body).then(() => {
selectedRowKeys.value = [];
loadingData();
}).catch(error => {
@@ -419,13 +415,11 @@ const handleModalSumbit = () => {
}
})
createPosition(createBody).then(response => {
createPosition(createBody).then(() => {
modalSubmitLoading.value = false;
openModal.value = false;
Object.keys(createState).forEach(key => delete createState[key]);
createState.order = 1;
const result = response.data;
message.success(result.msg);
loadingData();
}).catch(error => {
@@ -440,10 +434,9 @@ const handleModalSumbit = () => {
} else if (modalTitle.value === 'update') {
updateForm.value.validate().then(() => {
updatePosition(updateState).then(response => {
updatePosition(updateState).then(() => {
modalSubmitLoading.value = false;
openModal.value = false;
message.success(response.data.msg);
loadingData();
})
@@ -189,8 +189,7 @@ const emit = defineEmits(['event']);
const handleDrawerSave = () => {
drawerSaving.value = true;
setPermission(permissionState.value).then(response => {
message.success(response.data.msg);
setPermission(permissionState.value).then(() => {
drawerSaving.value = false;
openDrawer.value = false;
emit('event');
+3 -11
View File
@@ -348,9 +348,7 @@ const resetFields = () => {
//
const deleteRow = (row: tableDataType) => {
deleteRole({ id: row.id }).then(response => {
const result = response.data;
message.success(result.msg);
deleteRole({ id: row.id }).then(() => {
loadingData();
}).catch(error => {
@@ -371,8 +369,6 @@ const handleMoreClick: MenuProps['onClick'] = e => {
onOk() {
const body = { ids: selectedRowKeys.value, available: e.key == 1 ? true : false };
batchAvailableRole(body).then(response => {
const result = response.data;
message.success(result.msg);
selectedRowKeys.value = [];
loadingData();
}).catch(error => {
@@ -445,13 +441,11 @@ const handleModalSumbit = () => {
}
})
createRole(createBody).then(response => {
const result = response.data;
createRole(createBody).then(() => {
modalSubmitLoading.value = false;
openModal.value = false;
Object.keys(createState).forEach(key => delete createState[key]);
createState.order = 1;
message.success(result.msg);
loadingData();
}).catch(error => {
@@ -466,11 +460,9 @@ const handleModalSumbit = () => {
} else if (modalTitle.value === 'update') {
updateForm.value.validate().then(() => {
updateRole(updateState).then(response => {
const result = response.data;
updateRole(updateState).then(() => {
modalSubmitLoading.value = false;
openModal.value = false;
message.success(result.msg);
loadingData();
}).catch(error => {
+5 -15
View File
@@ -698,11 +698,8 @@ const resetFields = () => {
//
const deleteRow = (row: tableDataType) => {
deleteUser({ id: row.id }).then(response => {
const result = response.data;
message.success(result.msg);
deleteUser({ id: row.id }).then(() => {
loadingData();
}).catch(error => {
console.log(error);
})
@@ -720,9 +717,7 @@ const handleMoreClick: MenuProps['onClick'] = e => {
content: e.key == 1 ? '是否确定启用选择项?' : '是否确定停用选择项?',
onOk() {
const body = { ids: selectedRowKeys.value, available: e.key == 1 ? true : false };
batchAvailableUser(body).then(response => {
const result = response.data;
message.success(result.msg);
batchAvailableUser(body).then(() => {
selectedRowKeys.value = [];
loadingData();
}).catch(error => {
@@ -838,12 +833,10 @@ const handleModalSumbit = () => {
}
})
createUser(createBody).then(response => {
const result = response.data;
createUser(createBody).then(() => {
modalSubmitLoading.value = false;
openModal.value = false;
Object.keys(createState).forEach(key => delete createState[key]);
message.success(result.msg);
loadingData();
}).catch(error => {
@@ -876,11 +869,9 @@ const handleModalSumbit = () => {
updateBody['password'] = updateState.password;
}
updateUser(updateBody).then(response => {
const result = response.data;
updateUser(updateBody).then(() => {
modalSubmitLoading.value = false;
openModal.value = false;
message.success(result.msg);
loadingData();
}).catch(error => {
@@ -1006,7 +997,6 @@ const customRequest = ({ file, onSuccess, onError, onProgress }: any) => {
fileItem.percent = 100;
upload.isUploading = false;
upload.open = false;
message.success(response.data.msg);
onSuccess(response);
loadingData(); //
})
@@ -1014,7 +1004,7 @@ const customRequest = ({ file, onSuccess, onError, onProgress }: any) => {
fileItem.status = 'error';
upload.isUploading = false;
onError(error);
message.error(error.response?.data?.detail || '用户导入失败');
console.error('导入失败:', error);
});
};