From 89b8494ad01359db82f7376d2e1fa366d7dd2b6b Mon Sep 17 00:00:00 2001 From: hanhh <18330117883@163.com> Date: Mon, 23 Aug 2021 13:44:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=8E=B7=E5=8F=96ip=20api?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E6=97=B6=EF=BC=8C=E6=97=A0=E6=B3=95=E7=99=BB?= =?UTF-8?q?=E9=99=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复禁用或者运行定时任务出现重复 --- back/config/util.ts | 12 ++++++++---- src/pages/crontab/index.tsx | 12 ++++++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/back/config/util.ts b/back/config/util.ts index cb0c98ea..13253d0e 100644 --- a/back/config/util.ts +++ b/back/config/util.ts @@ -165,9 +165,13 @@ export async function getNetIp(req: any) { .json(); return { address: data[0].location, ip }; } catch (error) { - const { country, regionName, city } = await got - .get(`http://ip-api.com/json/${ip}?lang=zh-CN`) - .json(); - return { address: `${country} ${regionName} ${city}`, ip }; + try { + const { country, regionName, city } = await got + .get(`http://ip-api.com/json/${ip}?lang=zh-CN`) + .json(); + return { address: `${country} ${regionName} ${city}`, ip }; + } catch (err) { + return { address: `获取失败`, ip }; + } } } diff --git a/src/pages/crontab/index.tsx b/src/pages/crontab/index.tsx index fe72c425..91d630bf 100644 --- a/src/pages/crontab/index.tsx +++ b/src/pages/crontab/index.tsx @@ -274,7 +274,8 @@ const Crontab = ({ headerStyle, isPhone }: any) => { if (data.code === 200) { message.success('删除成功'); const result = [...value]; - result.splice(index + pageSize * (currentPage - 1), 1); + const i = result.findIndex((x) => x._id === record._id); + result.splice(i, 1); setValue(result); } else { message.error(data); @@ -305,7 +306,8 @@ const Crontab = ({ headerStyle, isPhone }: any) => { .then((data: any) => { if (data.code === 200) { const result = [...value]; - result.splice(index + pageSize * (currentPage - 1), 1, { + const i = result.findIndex((x) => x._id === record._id); + result.splice(i, 1, { ...record, status: CrontabStatus.running, }); @@ -339,7 +341,8 @@ const Crontab = ({ headerStyle, isPhone }: any) => { .then((data: any) => { if (data.code === 200) { const result = [...value]; - result.splice(index + pageSize * (currentPage - 1), 1, { + const i = result.findIndex((x) => x._id === record._id); + result.splice(i, 1, { ...record, pid: null, status: CrontabStatus.idle, @@ -383,7 +386,8 @@ const Crontab = ({ headerStyle, isPhone }: any) => { if (data.code === 200) { const newStatus = record.isDisabled === 1 ? 0 : 1; const result = [...value]; - result.splice(index + pageSize * (currentPage - 1), 1, { + const i = result.findIndex((x) => x._id === record._id); + result.splice(i, 1, { ...record, isDisabled: newStatus, });