重构前端错误提示

This commit is contained in:
whyour
2022-09-22 23:59:23 +08:00
parent e274d3e2f9
commit f2fea47336
33 changed files with 347 additions and 363 deletions
-2
View File
@@ -28,8 +28,6 @@ const EditNameModal = ({
if (code === 200) {
message.success('更新环境变量名称成功');
handleCancel();
} else {
message.error(data);
}
setLoading(false);
} catch (error) {
+14 -22
View File
@@ -255,8 +255,10 @@ const Env = () => {
setLoading(true);
request
.get(`${config.apiPrefix}envs?searchValue=${searchText}`)
.then((data: any) => {
setValue(data.data);
.then(({ code, data }) => {
if (code === 200) {
setValue(data);
}
})
.finally(() => setLoading(false));
};
@@ -284,8 +286,8 @@ const Env = () => {
data: [record.id],
},
)
.then((data: any) => {
if (data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
message.success(
`${record.status === Status. ? '启用' : '禁用'}成功`,
);
@@ -297,8 +299,6 @@ const Env = () => {
status: newStatus,
});
setValue(result);
} else {
message.error(data);
}
});
},
@@ -333,14 +333,12 @@ const Env = () => {
onOk() {
request
.delete(`${config.apiPrefix}envs`, { data: [record.id] })
.then((data: any) => {
if (data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
message.success('删除成功');
const result = [...value];
result.splice(index, 1);
setValue(result);
} else {
message.error(data);
}
});
},
@@ -390,14 +388,12 @@ const Env = () => {
.put(`${config.apiPrefix}envs/${dragRow.id}/move`, {
data: { fromIndex: dragIndex, toIndex: hoverIndex },
})
.then((data: any) => {
if (data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
const newData = [...value];
newData.splice(dragIndex, 1);
newData.splice(hoverIndex, 0, { ...dragRow, ...data.data });
setValue([...newData]);
} else {
message.error(data);
}
});
},
@@ -426,13 +422,11 @@ const Env = () => {
onOk() {
request
.delete(`${config.apiPrefix}envs`, { data: selectedRowIds })
.then((data: any) => {
if (data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
message.success('批量删除成功');
setSelectedRowIds([]);
getEnvs();
} else {
message.error(data);
}
});
},
@@ -451,11 +445,9 @@ const Env = () => {
.put(`${config.apiPrefix}envs/${OperationPath[operationStatus]}`, {
data: selectedRowIds,
})
.then((data: any) => {
if (data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
getEnvs();
} else {
message.error(data);
}
});
},
-2
View File
@@ -44,8 +44,6 @@ const EnvModal = ({
if (code === 200) {
message.success(env ? '更新变量成功' : '新建变量成功');
handleCancel(data);
} else {
message.error(data);
}
setLoading(false);
} catch (error: any) {