修复获取ip api失败时,无法登陆

修复禁用或者运行定时任务出现重复
This commit is contained in:
hanhh 2021-08-23 13:44:54 +08:00
parent 64ecd75bd5
commit 89b8494ad0
2 changed files with 16 additions and 8 deletions

View File

@ -165,9 +165,13 @@ export async function getNetIp(req: any) {
.json(); .json();
return { address: data[0].location, ip }; return { address: data[0].location, ip };
} catch (error) { } catch (error) {
try {
const { country, regionName, city } = await got const { country, regionName, city } = await got
.get(`http://ip-api.com/json/${ip}?lang=zh-CN`) .get(`http://ip-api.com/json/${ip}?lang=zh-CN`)
.json(); .json();
return { address: `${country} ${regionName} ${city}`, ip }; return { address: `${country} ${regionName} ${city}`, ip };
} catch (err) {
return { address: `获取失败`, ip };
}
} }
} }

View File

@ -274,7 +274,8 @@ const Crontab = ({ headerStyle, isPhone }: any) => {
if (data.code === 200) { if (data.code === 200) {
message.success('删除成功'); message.success('删除成功');
const result = [...value]; 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); setValue(result);
} else { } else {
message.error(data); message.error(data);
@ -305,7 +306,8 @@ const Crontab = ({ headerStyle, isPhone }: any) => {
.then((data: any) => { .then((data: any) => {
if (data.code === 200) { if (data.code === 200) {
const result = [...value]; const result = [...value];
result.splice(index + pageSize * (currentPage - 1), 1, { const i = result.findIndex((x) => x._id === record._id);
result.splice(i, 1, {
...record, ...record,
status: CrontabStatus.running, status: CrontabStatus.running,
}); });
@ -339,7 +341,8 @@ const Crontab = ({ headerStyle, isPhone }: any) => {
.then((data: any) => { .then((data: any) => {
if (data.code === 200) { if (data.code === 200) {
const result = [...value]; const result = [...value];
result.splice(index + pageSize * (currentPage - 1), 1, { const i = result.findIndex((x) => x._id === record._id);
result.splice(i, 1, {
...record, ...record,
pid: null, pid: null,
status: CrontabStatus.idle, status: CrontabStatus.idle,
@ -383,7 +386,8 @@ const Crontab = ({ headerStyle, isPhone }: any) => {
if (data.code === 200) { if (data.code === 200) {
const newStatus = record.isDisabled === 1 ? 0 : 1; const newStatus = record.isDisabled === 1 ? 0 : 1;
const result = [...value]; const result = [...value];
result.splice(index + pageSize * (currentPage - 1), 1, { const i = result.findIndex((x) => x._id === record._id);
result.splice(i, 1, {
...record, ...record,
isDisabled: newStatus, isDisabled: newStatus,
}); });