重构前端错误提示

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -255,8 +255,10 @@ const Env = () => {
setLoading(true); setLoading(true);
request request
.get(`${config.apiPrefix}envs?searchValue=${searchText}`) .get(`${config.apiPrefix}envs?searchValue=${searchText}`)
.then((data: any) => { .then(({ code, data }) => {
setValue(data.data); if (code === 200) {
setValue(data);
}
}) })
.finally(() => setLoading(false)); .finally(() => setLoading(false));
}; };
@ -284,8 +286,8 @@ const Env = () => {
data: [record.id], data: [record.id],
}, },
) )
.then((data: any) => { .then(({ code, data }) => {
if (data.code === 200) { if (code === 200) {
message.success( message.success(
`${record.status === Status. ? '启用' : '禁用'}成功`, `${record.status === Status. ? '启用' : '禁用'}成功`,
); );
@ -297,8 +299,6 @@ const Env = () => {
status: newStatus, status: newStatus,
}); });
setValue(result); setValue(result);
} else {
message.error(data);
} }
}); });
}, },
@ -333,14 +333,12 @@ const Env = () => {
onOk() { onOk() {
request request
.delete(`${config.apiPrefix}envs`, { data: [record.id] }) .delete(`${config.apiPrefix}envs`, { data: [record.id] })
.then((data: any) => { .then(({ code, data }) => {
if (data.code === 200) { if (code === 200) {
message.success('删除成功'); message.success('删除成功');
const result = [...value]; const result = [...value];
result.splice(index, 1); result.splice(index, 1);
setValue(result); setValue(result);
} else {
message.error(data);
} }
}); });
}, },
@ -390,14 +388,12 @@ const Env = () => {
.put(`${config.apiPrefix}envs/${dragRow.id}/move`, { .put(`${config.apiPrefix}envs/${dragRow.id}/move`, {
data: { fromIndex: dragIndex, toIndex: hoverIndex }, data: { fromIndex: dragIndex, toIndex: hoverIndex },
}) })
.then((data: any) => { .then(({ code, data }) => {
if (data.code === 200) { if (code === 200) {
const newData = [...value]; const newData = [...value];
newData.splice(dragIndex, 1); newData.splice(dragIndex, 1);
newData.splice(hoverIndex, 0, { ...dragRow, ...data.data }); newData.splice(hoverIndex, 0, { ...dragRow, ...data.data });
setValue([...newData]); setValue([...newData]);
} else {
message.error(data);
} }
}); });
}, },
@ -426,13 +422,11 @@ const Env = () => {
onOk() { onOk() {
request request
.delete(`${config.apiPrefix}envs`, { data: selectedRowIds }) .delete(`${config.apiPrefix}envs`, { data: selectedRowIds })
.then((data: any) => { .then(({ code, data }) => {
if (data.code === 200) { if (code === 200) {
message.success('批量删除成功'); message.success('批量删除成功');
setSelectedRowIds([]); setSelectedRowIds([]);
getEnvs(); getEnvs();
} else {
message.error(data);
} }
}); });
}, },
@ -451,11 +445,9 @@ const Env = () => {
.put(`${config.apiPrefix}envs/${OperationPath[operationStatus]}`, { .put(`${config.apiPrefix}envs/${OperationPath[operationStatus]}`, {
data: selectedRowIds, data: selectedRowIds,
}) })
.then((data: any) => { .then(({ code, data }) => {
if (data.code === 200) { if (code === 200) {
getEnvs(); getEnvs();
} else {
message.error(data);
} }
}); });
}, },

View File

@ -44,8 +44,6 @@ const EnvModal = ({
if (code === 200) { if (code === 200) {
message.success(env ? '更新变量成功' : '新建变量成功'); message.success(env ? '更新变量成功' : '新建变量成功');
handleCancel(data); handleCancel(data);
} else {
message.error(data);
} }
setLoading(false); setLoading(false);
} catch (error: any) { } catch (error: any) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -9,6 +9,7 @@ message.config({
const time = Date.now(); const time = Date.now();
const errorHandler = function (error: any) { const errorHandler = function (error: any) {
console.log(error);
if (error.response) { if (error.response) {
const msg = error.data const msg = error.data
? error.data.message || error.message || 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) => { _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; return response;
}); });