重构前端错误提示

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

View File

@ -68,8 +68,6 @@ export default function () {
} else {
getUser();
}
} else {
message.error(data);
}
})
.catch((error) => {
@ -87,8 +85,6 @@ export default function () {
if (location.pathname === '/') {
history.push('/crontab');
}
} else {
message.error(data);
}
needLoading && setLoading(false);
})

View File

@ -25,8 +25,10 @@ const Config = () => {
const [confirmLoading, setConfirmLoading] = useState(false);
const getConfig = (name: string) => {
request.get(`${config.apiPrefix}configs/${name}`).then((data: any) => {
setValue(data.data);
request.get(`${config.apiPrefix}configs/${name}`).then(({ code, data }) => {
if (code === 200) {
setValue(data);
}
});
};
@ -34,8 +36,10 @@ const Config = () => {
setLoading(true);
request
.get(`${config.apiPrefix}configs/files`)
.then((data: any) => {
setData(data.data);
.then(({ code, data }) => {
if (code === 200) {
setData(data);
}
})
.finally(() => setLoading(false));
};
@ -50,8 +54,10 @@ const Config = () => {
.post(`${config.apiPrefix}configs/save`, {
data: { content, name: select },
})
.then((data: any) => {
message.success(data.message);
.then(({ code, data }) => {
if (code === 200) {
message.success('保存成功');
}
setConfirmLoading(false);
});
};

View File

@ -123,9 +123,11 @@ const CronDetailModal = ({
.get(
`${config.apiPrefix}logs/${item.filename}?path=${item.directory || ''}`,
)
.then((data) => {
setLog(data.data);
setIsLogModalVisible(true);
.then(({ code, data }) => {
if (code === 200) {
setLog(data);
setIsLogModalVisible(true);
}
});
};
@ -137,9 +139,9 @@ const CronDetailModal = ({
setLoading(true);
request
.get(`${config.apiPrefix}crons/${cron.id}/logs`)
.then((data: any) => {
if (data.code === 200) {
setLogs(data.data);
.then(({ code, data }) => {
if (code === 200) {
setLogs(data);
}
})
.finally(() => setLoading(false));
@ -165,8 +167,10 @@ const CronDetailModal = ({
setScriptInfo({ parent: p, filename: s });
request
.get(`${config.apiPrefix}scripts/${s}?path=${p || ''}`)
.then((data) => {
setValue(data.data);
.then(({ code, data }) => {
if (code === 200) {
setValue(data);
}
});
} else {
setValidTabs([validTabs[0]]);
@ -198,12 +202,10 @@ const CronDetailModal = ({
content,
},
})
.then((_data: any) => {
if (_data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
setValue(content);
message.success(`保存成功`);
} else {
message.error(_data);
}
resolve(null);
})
@ -231,14 +233,12 @@ const CronDetailModal = ({
onOk() {
request
.put(`${config.apiPrefix}crons/run`, { data: [currentCron.id] })
.then((data: any) => {
if (data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
setCurrentCron({ ...currentCron, status: CrontabStatus.running });
setTimeout(() => {
getLogs();
}, 1000);
} else {
message.error(data);
}
});
},
@ -263,11 +263,9 @@ const CronDetailModal = ({
onOk() {
request
.put(`${config.apiPrefix}crons/stop`, { data: [currentCron.id] })
.then((data: any) => {
if (data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
setCurrentCron({ ...currentCron, status: CrontabStatus.idle });
} else {
message.error(data);
}
});
},
@ -300,14 +298,12 @@ const CronDetailModal = ({
data: [currentCron.id],
},
)
.then((data: any) => {
if (data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
setCurrentCron({
...currentCron,
isDisabled: currentCron.isDisabled === 1 ? 0 : 1,
});
} else {
message.error(data);
}
});
},
@ -340,14 +336,12 @@ const CronDetailModal = ({
data: [currentCron.id],
},
)
.then((data: any) => {
if (data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
setCurrentCron({
...currentCron,
isPinned: currentCron.isPinned === 1 ? 0 : 1,
});
} else {
message.error(data);
}
});
},

View File

@ -433,20 +433,22 @@ const Crontab = () => {
}
request
.get(url)
.then((_data: any) => {
const { data, total } = _data.data;
setValue(
data.map((x) => {
return {
...x,
nextRunTime: cron_parser
.parseExpression(x.schedule)
.next()
.toDate(),
};
}),
);
setTotal(total);
.then(({ code, data: _data }) => {
if (code === 200) {
const { data, total } = _data;
setValue(
data.map((x) => {
return {
...x,
nextRunTime: cron_parser
.parseExpression(x.schedule)
.next()
.toDate(),
};
}),
);
setTotal(total);
}
})
.finally(() => setLoading(false));
};
@ -476,8 +478,8 @@ const Crontab = () => {
onOk() {
request
.delete(`${config.apiPrefix}crons`, { data: [record.id] })
.then((data: any) => {
if (data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
message.success('删除成功');
const result = [...value];
const i = result.findIndex((x) => x.id === record.id);
@ -485,8 +487,6 @@ const Crontab = () => {
result.splice(i, 1);
setValue(result);
}
} else {
message.error(data);
}
});
},
@ -511,8 +511,8 @@ const Crontab = () => {
onOk() {
request
.put(`${config.apiPrefix}crons/run`, { data: [record.id] })
.then((data: any) => {
if (data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
const result = [...value];
const i = result.findIndex((x) => x.id === record.id);
if (i !== -1) {
@ -522,8 +522,6 @@ const Crontab = () => {
});
setValue(result);
}
} else {
message.error(data);
}
});
},
@ -548,8 +546,8 @@ const Crontab = () => {
onOk() {
request
.put(`${config.apiPrefix}crons/stop`, { data: [record.id] })
.then((data: any) => {
if (data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
const result = [...value];
const i = result.findIndex((x) => x.id === record.id);
if (i !== -1) {
@ -560,8 +558,6 @@ const Crontab = () => {
});
setValue(result);
}
} else {
message.error(data);
}
});
},
@ -594,8 +590,8 @@ const Crontab = () => {
data: [record.id],
},
)
.then((data: any) => {
if (data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
const newStatus = record.isDisabled === 1 ? 0 : 1;
const result = [...value];
const i = result.findIndex((x) => x.id === record.id);
@ -606,8 +602,6 @@ const Crontab = () => {
});
setValue(result);
}
} else {
message.error(data);
}
});
},
@ -640,8 +634,8 @@ const Crontab = () => {
data: [record.id],
},
)
.then((data: any) => {
if (data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
const newStatus = record.isPinned === 1 ? 0 : 1;
const result = [...value];
const i = result.findIndex((x) => x.id === record.id);
@ -652,8 +646,6 @@ const Crontab = () => {
});
setValue(result);
}
} else {
message.error(data);
}
});
},
@ -755,19 +747,21 @@ const Crontab = () => {
const getCronDetail = (cron: any) => {
request
.get(`${config.apiPrefix}crons/${cron.id}`)
.then((data: any) => {
const index = value.findIndex((x) => x.id === cron.id);
const result = [...value];
data.data.nextRunTime = cron_parser
.parseExpression(data.data.schedule)
.next()
.toDate();
if (index !== -1) {
result.splice(index, 1, {
...cron,
...data.data,
});
setValue(result);
.then(({ code, data }) => {
if (code === 200) {
const index = value.findIndex((x) => x.id === cron.id);
const result = [...value];
data.nextRunTime = cron_parser
.parseExpression(data.schedule)
.next()
.toDate();
if (index !== -1) {
result.splice(index, 1, {
...cron,
...data,
});
setValue(result);
}
}
})
.finally(() => setLoading(false));
@ -795,13 +789,11 @@ const Crontab = () => {
onOk() {
request
.delete(`${config.apiPrefix}crons`, { data: selectedRowIds })
.then((data: any) => {
if (data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
message.success('批量删除成功');
setSelectedRowIds([]);
getCrons();
} else {
message.error(data);
}
});
},
@ -820,11 +812,9 @@ const Crontab = () => {
.put(`${config.apiPrefix}crons/${OperationPath[operationStatus]}`, {
data: selectedRowIds,
})
.then((data: any) => {
if (data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
getCrons();
} else {
message.error(data);
}
});
},
@ -1029,9 +1019,11 @@ const Crontab = () => {
setLoading(true);
request
.get(`${config.apiPrefix}crons/views`)
.then((data: any) => {
setCronViews(data.data);
setEnabledCronViews(data.data.filter((x) => !x.isDisabled));
.then(({ code, data }) => {
if (code === 200) {
setCronViews(data);
setEnabledCronViews(data.filter((x) => !x.isDisabled));
}
})
.finally(() => {
setLoading(false);

View File

@ -41,9 +41,12 @@ const CronLogModal = ({
}
request
.get(logUrl ? logUrl : `${config.apiPrefix}crons/${cron.id}/log`)
.then((data: any) => {
if (localStorage.getItem('logCron') === String(cron.id)) {
const log = data.data as string;
.then(({ code, data }) => {
if (
code === 200 &&
localStorage.getItem('logCron') === String(cron.id)
) {
const log = data as string;
setValue(log || '暂无日志');
setExecuting(
log && !log.includes('执行结束') && !log.includes('重启面板'),

View File

@ -32,8 +32,6 @@ const CronModal = ({
if (code === 200) {
message.success(cron ? '更新Cron成功' : '新建Cron成功');
handleCancel(data);
} else {
message.error(data);
}
setLoading(false);
} catch (error: any) {
@ -142,8 +140,6 @@ const CronLabelModal = ({
action === 'post' ? '添加Labels成功' : '删除Labels成功',
);
handleCancel(true);
} else {
message.error(data);
}
setLoading(false);
} catch (error) {

View File

@ -66,9 +66,7 @@ const ViewCreateModal = ({
},
);
if (code !== 200) {
message.error(data);
} else {
if (code === 200) {
handleCancel(data);
}
setLoading(false);

View File

@ -141,12 +141,10 @@ const ViewManageModal = ({
onOk() {
request
.delete(`${config.apiPrefix}crons/views`, { data: [record.id] })
.then((data: any) => {
if (data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
message.success('删除成功');
cronViewChange();
} else {
message.error(data);
}
});
},
@ -162,14 +160,12 @@ const ViewManageModal = ({
.put(`${config.apiPrefix}crons/views/${checked ? 'enable' : 'disable'}`, {
data: [record.id],
})
.then((data: any) => {
if (data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
const _list = [...list];
_list.splice(index, 1, { ...list[index], isDisabled: !checked });
setList(_list);
cronViewChange();
} else {
message.error(data);
}
});
};
@ -190,15 +186,13 @@ const ViewManageModal = ({
.put(`${config.apiPrefix}crons/views/move`, {
data: { fromIndex: dragIndex, toIndex: hoverIndex, id: dragRow.id },
})
.then((data: any) => {
if (data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
const newData = [...list];
newData.splice(dragIndex, 1);
newData.splice(hoverIndex, 0, { ...dragRow, ...data.data });
newData.splice(hoverIndex, 0, { ...dragRow, ...data });
setList(newData);
cronViewChange();
} else {
message.error(data);
}
});
},

View File

@ -175,8 +175,10 @@ const Dependence = () => {
.get(
`${config.apiPrefix}dependencies?searchValue=${searchText}&type=${type}`,
)
.then((data: any) => {
setValue(data.data);
.then(({ code, data }) => {
if (code === 200) {
setValue(data);
}
})
.finally(() => setLoading(false));
};
@ -212,18 +214,14 @@ const Dependence = () => {
.delete(`${config.apiPrefix}dependencies${force ? '/force' : ''}`, {
data: [record.id],
})
.then((data: any) => {
if (data.code === 200) {
if (force) {
const i = value.findIndex((x) => x.id === data.data[0].id);
if (i !== -1) {
const result = [...value];
result.splice(i, 1);
setValue(result);
}
.then(({ code, data }) => {
if (code === 200 && force) {
const i = value.findIndex((x) => x.id === data.data[0].id);
if (i !== -1) {
const result = [...value];
result.splice(i, 1);
setValue(result);
}
} else {
message.error(data);
}
});
},
@ -250,11 +248,9 @@ const Dependence = () => {
.put(`${config.apiPrefix}dependencies/reinstall`, {
data: [record.id],
})
.then((data: any) => {
if (data.code === 200) {
handleDependence(data.data[0]);
} else {
message.error(data);
.then(({ code, data }) => {
if (code === 200) {
handleDependence(data[0]);
}
});
},
@ -309,12 +305,10 @@ const Dependence = () => {
.delete(`${config.apiPrefix}dependencies${forceUrl}`, {
data: selectedRowIds,
})
.then((data: any) => {
if (data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
setSelectedRowIds([]);
getDependencies();
} else {
message.error(data);
}
});
},
@ -333,12 +327,10 @@ const Dependence = () => {
.put(`${config.apiPrefix}dependencies/reinstall`, {
data: selectedRowIds,
})
.then((data: any) => {
if (data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
setSelectedRowIds([]);
getDependencies();
} else {
message.error(data);
}
});
},
@ -351,15 +343,17 @@ const Dependence = () => {
const getDependenceDetail = (dependence: any) => {
request
.get(`${config.apiPrefix}dependencies/${dependence.id}`)
.then((data: any) => {
const index = value.findIndex((x) => x.id === dependence.id);
const result = [...value];
if (index !== -1) {
result.splice(index, 1, {
...dependence,
...data.data,
});
setValue(result);
.then(({ code, data }) => {
if (code === 200) {
const index = value.findIndex((x) => x.id === dependence.id);
const result = [...value];
if (index !== -1) {
result.splice(index, 1, {
...dependence,
...data,
});
setValue(result);
}
}
})
.finally(() => setLoading(false));

View File

@ -48,9 +48,12 @@ const DependenceLogModal = ({
setLoading(true);
request
.get(`${config.apiPrefix}dependencies/${dependence.id}`)
.then((data: any) => {
if (localStorage.getItem('logDependence') === String(dependence.id)) {
const log = (data.data.log || []).join('') as string;
.then(({ code, data }) => {
if (
code === 200 &&
localStorage.getItem('logDependence') === String(dependence.id)
) {
const log = (data.log || []).join('') as string;
setValue(log);
setExecuting(!log.includes('结束时间'));
setIsRemoveFailed(log.includes('删除失败'));
@ -67,8 +70,10 @@ const DependenceLogModal = ({
.delete(`${config.apiPrefix}dependencies/force`, {
data: [dependence.id],
})
.then((data: any) => {
cancel(true);
.then(({ code, data }) => {
if (code === 200) {
cancel(true);
}
})
.finally(() => {
setRemoveLoading(false);

View File

@ -53,9 +53,7 @@ const DependenceModal = ({
},
);
if (code !== 200) {
message.error(data);
} else {
if (code === 200) {
handleCancel(data);
}
setLoading(false);

View File

@ -22,15 +22,23 @@ const Diff = () => {
const editorRef = useRef<any>(null);
const getConfig = () => {
request.get(`${config.apiPrefix}configs/${current}`).then((data) => {
setCurrentValue(data.data);
});
request
.get(`${config.apiPrefix}configs/${current}`)
.then(({ code, data }) => {
if (code === 200) {
setCurrentValue(data);
}
});
};
const getSample = () => {
request.get(`${config.apiPrefix}configs/${origin}`).then((data) => {
setOriginValue(data.data);
});
request
.get(`${config.apiPrefix}configs/${origin}`)
.then(({ code, data }) => {
if (code === 200) {
setOriginValue(data);
}
});
};
const updateConfig = () => {
@ -42,8 +50,10 @@ const Diff = () => {
.post(`${config.apiPrefix}configs/save`, {
data: { content, name: current },
})
.then((data: any) => {
message.success(data.message);
.then(({ code, data }) => {
if (code === 200) {
message.success('保存成功');
}
});
};
@ -51,8 +61,10 @@ const Diff = () => {
setLoading(true);
request
.get(`${config.apiPrefix}configs/files`)
.then((data: any) => {
setFiles(data.data);
.then(({ code, data }) => {
if (code === 200) {
setFiles(data);
}
})
.finally(() => setLoading(false));
};

View File

@ -28,8 +28,6 @@ const EditNameModal = ({
if (code === 200) {
message.success('更新环境变量名称成功');
handleCancel();
} else {
message.error(data);
}
setLoading(false);
} catch (error) {

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);
}
});
},

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) {

View File

@ -17,8 +17,10 @@ const Error = () => {
setLoading(true);
request
.get(`${config.apiPrefix}public/panel/log`)
.then((data: any) => {
setData(data.data);
.then(({ code, data }) => {
if (code === 200) {
setData(data);
}
})
.finally(() => setLoading(false));
};

View File

@ -41,11 +41,9 @@ const Initialization = () => {
password: values.password,
},
})
.then((data) => {
if (data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
next();
} else {
message.error(data.message);
}
})
.finally(() => setLoading(false));
@ -59,11 +57,9 @@ const Initialization = () => {
...values,
},
})
.then((_data: any) => {
if (_data && _data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
next();
} else {
message.error(_data.message);
}
})
.finally(() => setLoading(false));

View File

@ -54,9 +54,11 @@ const Log = () => {
setLoading(true);
request
.get(`${config.apiPrefix}logs`)
.then((data) => {
setData(data.data);
setFilterData(data.data);
.then(({ code, data }) => {
if (code === 200) {
setData(data);
setFilterData(data);
}
})
.finally(() => setLoading(false));
};
@ -64,8 +66,10 @@ const Log = () => {
const getLog = (node: any) => {
request
.get(`${config.apiPrefix}logs/${node.title}?path=${node.parent || ''}`)
.then((data) => {
setValue(data.data);
.then(({ code, data }) => {
if (code === 200) {
setValue(data);
}
});
};

View File

@ -40,15 +40,7 @@ const Login = () => {
},
})
.then((data) => {
if (data.code === 420) {
setLoginInfo({
username: values.username,
password: values.password,
});
setTwoFactor(true);
} else {
checkResponse(data);
}
checkResponse(data, values);
setLoading(false);
})
.catch(function (error) {
@ -64,11 +56,7 @@ const Login = () => {
data: { ...loginInfo, code: values.code },
})
.then((data: any) => {
if (data.code === 430) {
message.error(data.message);
} else {
checkResponse(data);
}
checkResponse(data);
setVerifying(false);
})
.catch((error: any) => {
@ -77,8 +65,11 @@ const Login = () => {
});
};
const checkResponse = (data: any) => {
if (data.code === 200) {
const checkResponse = (
{ code, data, message: _message }: any,
values?: any,
) => {
if (code === 200) {
const {
token,
lastip,
@ -86,7 +77,7 @@ const Login = () => {
lastlogon,
retries = 0,
platform,
} = data.data;
} = data;
localStorage.setItem(config.authKey, token);
notification.success({
message: '登录成功!',
@ -105,13 +96,14 @@ const Login = () => {
});
reloadUser(true);
history.push('/crontab');
} else if (data.code === 100) {
message.warn(data.message);
} else if (data.code === 410) {
message.error(data.message);
setWaitTime(data.data);
} else {
message.error(data.message);
} else if (code === 410) {
setWaitTime(data);
} else if (code === 420) {
setLoginInfo({
username: values.username,
password: values.password,
});
setTwoFactor(true);
}
};

View File

@ -67,8 +67,10 @@ const EditModal = ({
const getDetail = (node: any) => {
request
.get(`${config.apiPrefix}scripts/${node.title}?path=${node.parent || ''}`)
.then((data) => {
setValue(data.data);
.then(({ code, data }) => {
if (code === 200) {
setValue(data);
}
});
};
@ -83,8 +85,10 @@ const EditModal = ({
content,
},
})
.then((data) => {
setIsRunning(true);
.then(({ code, data }) => {
if (code === 200) {
setIsRunning(true);
}
});
};
@ -101,8 +105,10 @@ const EditModal = ({
content,
},
})
.then((data) => {
setIsRunning(false);
.then(({ code, data }) => {
if (code === 200) {
setIsRunning(false);
}
});
};

View File

@ -57,8 +57,6 @@ const EditScriptNameModal = ({
path,
key: `${key}${filename}`,
});
} else {
message.error(data);
}
setLoading(false);
})

View File

@ -99,10 +99,12 @@ const Script = () => {
setLoading(true);
request
.get(`${config.apiPrefix}scripts`)
.then((data) => {
setData(data.data);
setFilterData(data.data);
initGetScript();
.then(({ code, data }) => {
if (code === 200) {
setData(data);
setFilterData(data);
initGetScript();
}
})
.finally(() => setLoading(false));
};
@ -110,8 +112,10 @@ const Script = () => {
const getDetail = (node: any) => {
request
.get(`${config.apiPrefix}scripts/${node.title}?path=${node.parent || ''}`)
.then((data) => {
setValue(data.data);
.then(({ code, data }) => {
if (code === 200) {
setValue(data);
}
});
};
@ -231,13 +235,11 @@ const Script = () => {
content,
},
})
.then((_data: any) => {
if (_data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
message.success(`保存成功`);
setValue(content);
setIsEditing(false);
} else {
message.error(_data);
}
resolve(null);
})
@ -270,8 +272,8 @@ const Script = () => {
path: currentNode.parent || '',
},
})
.then((_data: any) => {
if (_data.code === 200) {
.then(({ code }) => {
if (code === 200) {
message.success(`删除成功`);
let newData = [...data];
if (currentNode.parent) {
@ -295,8 +297,6 @@ const Script = () => {
}
}
setData(newData);
} else {
message.error(_data);
}
});
},
@ -346,15 +346,17 @@ const Script = () => {
filename: currentNode.title,
},
})
.then((_data: any) => {
const blob = new Blob([_data], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = currentNode.title;
document.documentElement.appendChild(a);
a.click();
document.documentElement.removeChild(a);
.then(({ code, data }) => {
if (code === 200) {
const blob = new Blob([data], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = currentNode.title;
document.documentElement.appendChild(a);
a.click();
document.documentElement.removeChild(a);
}
});
};

View File

@ -26,8 +26,6 @@ const SaveModal = ({
if (code === 200) {
message.success('保存文件成功');
handleCancel(data);
} else {
message.error(data);
}
setLoading(false);
});

View File

@ -26,8 +26,6 @@ const SettingModal = ({
if (code === 200) {
message.success('保存文件成功');
handleCancel(data);
} else {
message.error(data);
}
setLoading(false);
});

View File

@ -30,8 +30,6 @@ const AppModal = ({
if (code === 200) {
message.success(app ? '更新应用成功' : '新建应用成功');
handleCancel(data);
} else {
message.error(data);
}
setLoading(false);
} catch (error) {

View File

@ -17,17 +17,14 @@ const CheckUpdate = ({ socketMessage }: any) => {
message.loading('检查更新中...', 0);
request
.put(`${config.apiPrefix}system/update-check`)
.then((_data: any) => {
.then(({ code, data }) => {
message.destroy();
const { code, data } = _data;
if (code === 200) {
if (data.hasNewVersion) {
showConfirmUpdateModal(data);
} else {
showForceUpdateModal();
}
} else {
message.error(data);
}
})
.catch((error: any) => {

View File

@ -144,8 +144,10 @@ const Setting = () => {
setLoading(true);
request
.get(`${config.apiPrefix}apps`)
.then((data: any) => {
setDataSource(data.data);
.then(({ code, data }) => {
if (code === 200) {
setDataSource(data);
}
})
.finally(() => setLoading(false));
};
@ -175,14 +177,12 @@ const Setting = () => {
onOk() {
request
.delete(`${config.apiPrefix}apps`, { data: [record.id] })
.then((data: any) => {
if (data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
message.success('删除成功');
const result = [...dataSource];
result.splice(index, 1);
setDataSource(result);
} else {
message.error(data);
}
});
},
@ -209,12 +209,10 @@ const Setting = () => {
onOk() {
request
.put(`${config.apiPrefix}apps/${record.id}/reset-secret`)
.then((data: any) => {
if (data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
message.success('重置成功');
handleApp(data.data);
} else {
message.error(data);
handleApp(data);
}
});
},
@ -247,8 +245,10 @@ const Setting = () => {
const getLoginLog = () => {
request
.get(`${config.apiPrefix}user/login-log`)
.then((data: any) => {
setLoginLogData(data.data);
.then(({ code, data }) => {
if (code === 200) {
setLoginLogData(data);
}
})
.catch((error: any) => {
console.log(error);
@ -271,8 +271,10 @@ const Setting = () => {
const getNotification = () => {
request
.get(`${config.apiPrefix}user/notification`)
.then((data: any) => {
setNotificationInfo(data.data);
.then(({ code, data }) => {
if (code === 200) {
setNotificationInfo(data);
}
})
.catch((error: any) => {
console.log(error);
@ -282,9 +284,9 @@ const Setting = () => {
const getLogRemoveFrequency = () => {
request
.get(`${config.apiPrefix}system/log/remove`)
.then((data: any) => {
if (data.data.info) {
const { frequency } = data.data.info;
.then(({ code, data }) => {
if (code === 200 && data.info) {
const { frequency } = data.info;
setLogRemoveFrequency(frequency);
}
})
@ -299,8 +301,10 @@ const Setting = () => {
.put(`${config.apiPrefix}system/log/remove`, {
data: { frequency: logRemoveFrequency },
})
.then((data: any) => {
message.success('更新成功');
.then(({ code, data }) => {
if (code === 200) {
message.success('更新成功');
}
})
.catch((error: any) => {
console.log(error);

View File

@ -23,11 +23,9 @@ const NotificationSetting = ({ data }: any) => {
...values,
},
})
.then((_data: any) => {
if (_data && _data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
message.success(values.type ? '通知发送成功' : '通知关闭成功');
} else {
message.error(_data.message);
}
})
.catch((error: any) => {
@ -75,22 +73,20 @@ const NotificationSetting = ({ data }: any) => {
rules={[{ required: x.required }]}
style={{ maxWidth: 400 }}
>
{
x.items ? (
<Select placeholder={x.placeholder || `请选择${x.label}`}>
{x.items.map((y) => (
<Option key={y.value} value={y.value}>
{y.label || y.value}
</Option>
))}
</Select>
) : (
<Input.TextArea
autoSize={true}
placeholder={x.placeholder || `请输入${x.label}`}
/>
)
}
{x.items ? (
<Select placeholder={x.placeholder || `请选择${x.label}`}>
{x.items.map((y) => (
<Option key={y.value} value={y.value}>
{y.label || y.value}
</Option>
))}
</Select>
) : (
<Input.TextArea
autoSize={true}
placeholder={x.placeholder || `请输入${x.label}`}
/>
)}
</Form.Item>
))}
<Button type="primary" htmlType="submit">

View File

@ -27,9 +27,11 @@ const SecuritySettings = ({ user, userChange }: any) => {
password: values.password,
},
})
.then((data: any) => {
localStorage.removeItem(config.authKey);
history.push('/login');
.then(({ code, data }) => {
if (code === 200) {
localStorage.removeItem(config.authKey);
history.push('/login');
}
})
.catch((error: any) => {
console.log(error);
@ -48,8 +50,8 @@ const SecuritySettings = ({ user, userChange }: any) => {
const deactiveTowFactor = () => {
request
.put(`${config.apiPrefix}user/two-factor/deactive`)
.then((data: any) => {
if (data.data) {
.then(({ code, data }) => {
if (code === 200 && data) {
setTwoFactorActivated(false);
userChange();
}
@ -63,14 +65,16 @@ const SecuritySettings = ({ user, userChange }: any) => {
setLoading(true);
request
.put(`${config.apiPrefix}user/two-factor/active`, { data: { code } })
.then((data: any) => {
if (data.data) {
message.success('激活成功');
setTwoFactoring(false);
setTwoFactorActivated(true);
userChange();
} else {
message.success('验证失败');
.then(({ code, data }) => {
if (code === 200) {
if (data) {
message.success('激活成功');
setTwoFactoring(false);
setTwoFactorActivated(true);
userChange();
} else {
message.success('验证失败');
}
}
})
.catch((error: any) => {
@ -82,8 +86,10 @@ const SecuritySettings = ({ user, userChange }: any) => {
const getTwoFactorInfo = () => {
request
.get(`${config.apiPrefix}user/two-factor/init`)
.then((data: any) => {
setTwoFactorInfo(data.data);
.then(({ code, data }) => {
if (code === 200) {
setTwoFactorInfo(data);
}
})
.catch((error: any) => {
console.log(error);

View File

@ -263,8 +263,8 @@ const Subscription = () => {
onOk() {
request
.put(`${config.apiPrefix}subscriptions/run`, { data: [record.id] })
.then((data: any) => {
if (data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
const result = [...value];
const i = result.findIndex((x) => x.id === record.id);
if (i !== -1) {
@ -274,8 +274,6 @@ const Subscription = () => {
});
setValue(result);
}
} else {
message.error(data);
}
});
},
@ -300,8 +298,8 @@ const Subscription = () => {
onOk() {
request
.put(`${config.apiPrefix}subscriptions/stop`, { data: [record.id] })
.then((data: any) => {
if (data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
const result = [...value];
const i = result.findIndex((x) => x.id === record.id);
if (i !== -1) {
@ -312,8 +310,6 @@ const Subscription = () => {
});
setValue(result);
}
} else {
message.error(data);
}
});
},
@ -327,9 +323,11 @@ const Subscription = () => {
setLoading(true);
request
.get(`${config.apiPrefix}subscriptions?searchValue=${searchText}`)
.then((data: any) => {
setValue(data.data);
setCurrentPage(1);
.then(({ code, data }) => {
if (code === 200) {
setValue(data);
setCurrentPage(1);
}
})
.finally(() => setLoading(false));
};
@ -359,8 +357,8 @@ const Subscription = () => {
onOk() {
request
.delete(`${config.apiPrefix}subscriptions`, { data: [record.id] })
.then((data: any) => {
if (data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
message.success('删除成功');
const result = [...value];
const i = result.findIndex((x) => x.id === record.id);
@ -368,8 +366,6 @@ const Subscription = () => {
result.splice(i, 1);
setValue(result);
}
} else {
message.error(data);
}
});
},
@ -402,8 +398,8 @@ const Subscription = () => {
data: [record.id],
},
)
.then((data: any) => {
if (data.code === 200) {
.then(({ code, data }) => {
if (code === 200) {
const newStatus = record.is_disabled === 1 ? 0 : 1;
const result = [...value];
const i = result.findIndex((x) => x.id === record.id);
@ -414,8 +410,6 @@ const Subscription = () => {
});
setValue(result);
}
} else {
message.error(data);
}
});
},

View File

@ -36,11 +36,12 @@ const SubscriptionLogModal = ({
? logUrl
: `${config.apiPrefix}subscriptions/${subscription.id}/log`,
)
.then((data: any) => {
.then(({ code, data }) => {
if (
code === 200 &&
localStorage.getItem('logSubscription') === String(subscription.id)
) {
const log = data.data as string;
const log = data as string;
setValue(log || '暂无日志');
setExecuting(log && !log.includes('执行结束'));
if (log && !log.includes('执行结束')) {

View File

@ -40,8 +40,6 @@ const SubscriptionModal = ({
if (code === 200) {
message.success(subscription ? '更新订阅成功' : '新建订阅成功');
handleCancel(data);
} else {
message.error(data);
}
setLoading(false);
} catch (error: any) {
@ -208,8 +206,8 @@ const SubscriptionModal = ({
type === 'raw'
? 'file'
: url.startsWith('http')
? 'public-repo'
: 'private-repo';
? 'public-repo'
: 'private-repo';
form.setFieldsValue({
type: _type,
@ -252,9 +250,7 @@ const SubscriptionModal = ({
return (
<Modal
title={
subscription ? '编辑订阅' : '新建订阅'
}
title={subscription ? '编辑订阅' : '新建订阅'}
open={visible}
forceRender
centered
@ -274,7 +270,10 @@ const SubscriptionModal = ({
>
<Form form={form} name="form_in_modal" layout="vertical">
<Form.Item name="name" label="名称">
<Input placeholder="支持拷贝ql repo/raw命令粘贴导入" onPaste={onNamePaste} />
<Input
placeholder="支持拷贝ql repo/raw命令粘贴导入"
onPaste={onNamePaste}
/>
</Form.Item>
<Form.Item
name="type"

View File

@ -9,6 +9,7 @@ message.config({
const time = Date.now();
const errorHandler = function (error: any) {
console.log(error);
if (error.response) {
const msg = error.data
? error.data.message || error.message || error.data
@ -54,7 +55,23 @@ _request.interceptors.request.use((url, options) => {
});
_request.interceptors.response.use(async (response) => {
const res = await response.clone();
const responseStatus = response.status;
if ([502, 504].includes(responseStatus)) {
message.error('服务异常,请稍后刷新!');
history.push('/error');
} else if (responseStatus === 401) {
if (history.location.pathname !== '/login') {
localStorage.removeItem(config.authKey);
history.push('/login');
}
} else {
const res = await response.clone().json();
if (res.code !== 200) {
const msg = res.message || res.data;
message.error(msg);
}
return res;
}
return response;
});