mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 14:56:07 +08:00
修复添加ck和cron未更新列表
This commit is contained in:
parent
fb98bc44e4
commit
f9c299cfbe
|
@ -120,7 +120,7 @@ export default class CookieService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async create(payload: string[]): Promise<void> {
|
public async create(payload: string[]): Promise<Cookie[]> {
|
||||||
const cookies = await this.cookies('', { postion: 1 });
|
const cookies = await this.cookies('', { postion: 1 });
|
||||||
let position = initCookiePosition;
|
let position = initCookiePosition;
|
||||||
if (cookies && cookies.length > 0) {
|
if (cookies && cookies.length > 0) {
|
||||||
|
@ -131,16 +131,47 @@ export default class CookieService {
|
||||||
position = position / 2;
|
position = position / 2;
|
||||||
return cookie;
|
return cookie;
|
||||||
});
|
});
|
||||||
this.cronDb.insert(tabs);
|
const docs = await this.insert(tabs);
|
||||||
await this.set_cookies();
|
await this.set_cookies();
|
||||||
|
return docs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async update(payload: Cookie): Promise<void> {
|
public async insert(payload: Cookie[]): Promise<Cookie[]> {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
this.cronDb.insert(payload, (err, docs) => {
|
||||||
|
if (err) {
|
||||||
|
this.logger.error(err);
|
||||||
|
} else {
|
||||||
|
resolve(docs);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public async update(payload: Cookie): Promise<Cookie> {
|
||||||
const { _id, ...other } = payload;
|
const { _id, ...other } = payload;
|
||||||
const doc = await this.get(_id);
|
const doc = await this.get(_id);
|
||||||
const tab = new Cookie({ ...doc, ...other });
|
const tab = new Cookie({ ...doc, ...other });
|
||||||
this.cronDb.update({ _id }, tab, { returnUpdatedDocs: true });
|
const newDoc = await this.updateDb(tab);
|
||||||
await this.set_cookies();
|
await this.set_cookies();
|
||||||
|
return newDoc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async updateDb(payload: Cookie): Promise<Cookie> {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
this.cronDb.update(
|
||||||
|
{ _id: payload._id },
|
||||||
|
payload,
|
||||||
|
{ returnUpdatedDocs: true },
|
||||||
|
(err, docs) => {
|
||||||
|
if (err) {
|
||||||
|
this.logger.error(err);
|
||||||
|
} else {
|
||||||
|
resolve(docs as Cookie);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async remove(_id: string) {
|
public async remove(_id: string) {
|
||||||
|
@ -163,8 +194,8 @@ export default class CookieService {
|
||||||
const cookies = await this.cookies();
|
const cookies = await this.cookies();
|
||||||
if (toIndex === 0 || toIndex === cookies.length - 1) {
|
if (toIndex === 0 || toIndex === cookies.length - 1) {
|
||||||
targetPosition = isUpward
|
targetPosition = isUpward
|
||||||
? (cookies[0].position * 2 + 1) / 2
|
? cookies[0].position * 2
|
||||||
: (cookies[toIndex].position * 2 - 1) / 2;
|
: cookies[toIndex].position / 2;
|
||||||
} else {
|
} else {
|
||||||
targetPosition = isUpward
|
targetPosition = isUpward
|
||||||
? (cookies[toIndex].position + cookies[toIndex - 1].position) / 2
|
? (cookies[toIndex].position + cookies[toIndex - 1].position) / 2
|
||||||
|
|
|
@ -22,21 +22,52 @@ export default class CronService {
|
||||||
return this.cronDb;
|
return this.cronDb;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async create(payload: Crontab): Promise<void> {
|
public async create(payload: Crontab): Promise<Crontab> {
|
||||||
const tab = new Crontab(payload);
|
const tab = new Crontab(payload);
|
||||||
tab.created = new Date().valueOf();
|
tab.created = new Date().valueOf();
|
||||||
tab.saved = false;
|
tab.saved = false;
|
||||||
this.cronDb.insert(tab);
|
const doc = await this.insert(tab);
|
||||||
await this.set_crontab();
|
await this.set_crontab();
|
||||||
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async update(payload: Crontab): Promise<void> {
|
public async insert(payload: Crontab): Promise<Crontab> {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
this.cronDb.insert(payload, (err, docs) => {
|
||||||
|
if (err) {
|
||||||
|
this.logger.error(err);
|
||||||
|
} else {
|
||||||
|
resolve(docs);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public async update(payload: Crontab): Promise<Crontab> {
|
||||||
const { _id, ...other } = payload;
|
const { _id, ...other } = payload;
|
||||||
const doc = await this.get(_id);
|
const doc = await this.get(_id);
|
||||||
const tab = new Crontab({ ...doc, ...other });
|
const tab = new Crontab({ ...doc, ...other });
|
||||||
tab.saved = false;
|
tab.saved = false;
|
||||||
this.cronDb.update({ _id }, tab, { returnUpdatedDocs: true });
|
const newDoc = await this.update(tab);
|
||||||
await this.set_crontab();
|
await this.set_crontab();
|
||||||
|
return newDoc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async updateDb(payload: Crontab): Promise<Crontab> {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
this.cronDb.update(
|
||||||
|
{ _id: payload._id },
|
||||||
|
payload,
|
||||||
|
{ returnUpdatedDocs: true },
|
||||||
|
(err, num, docs: any) => {
|
||||||
|
if (err) {
|
||||||
|
this.logger.error(err);
|
||||||
|
} else {
|
||||||
|
resolve(docs);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async status(_id: string, stopped: boolean) {
|
public async status(_id: string, stopped: boolean) {
|
||||||
|
|
|
@ -322,26 +322,24 @@ const Config = () => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCancel = (needUpdate?: boolean) => {
|
const handleCancel = (cookie: any) => {
|
||||||
setIsModalVisible(false);
|
setIsModalVisible(false);
|
||||||
if (needUpdate) {
|
if (cookie) {
|
||||||
getCookieDetail(editedCookie);
|
handleCookies(cookie);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getCookieDetail = (cookie: any) => {
|
const handleCookies = (cookie: any) => {
|
||||||
request
|
const index = value.findIndex((x) => x._id === cookie._id);
|
||||||
.get(`${config.apiPrefix}cookies/${cookie._id}`)
|
const result = [...value];
|
||||||
.then((data: any) => {
|
if (index === -1) {
|
||||||
const index = value.findIndex((x) => x._id === cookie._id);
|
result.push(...cookie);
|
||||||
const result = [...value];
|
} else {
|
||||||
result.splice(index, 1, {
|
result.splice(index, 1, {
|
||||||
...cookie,
|
...cookie,
|
||||||
...data.data,
|
});
|
||||||
});
|
}
|
||||||
setValue(result);
|
setValue(result);
|
||||||
})
|
|
||||||
.finally(() => setLoading(false));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const components = {
|
const components = {
|
||||||
|
@ -352,6 +350,9 @@ const Config = () => {
|
||||||
|
|
||||||
const moveRow = useCallback(
|
const moveRow = useCallback(
|
||||||
(dragIndex, hoverIndex) => {
|
(dragIndex, hoverIndex) => {
|
||||||
|
if (dragIndex === hoverIndex) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const dragRow = value[dragIndex];
|
const dragRow = value[dragIndex];
|
||||||
const newData = [...value];
|
const newData = [...value];
|
||||||
newData.splice(dragIndex, 1);
|
newData.splice(dragIndex, 1);
|
||||||
|
|
|
@ -43,7 +43,7 @@ const CookieModal = ({
|
||||||
message: data,
|
message: data,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
handleCancel(true);
|
handleCancel(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -347,10 +347,10 @@ const Crontab = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCancel = (needUpdate?: boolean) => {
|
const handleCancel = (cron?: any) => {
|
||||||
setIsModalVisible(false);
|
setIsModalVisible(false);
|
||||||
if (needUpdate) {
|
if (cron) {
|
||||||
getCronDetail(editedCron);
|
handleCrons(cron);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -358,6 +358,19 @@ const Crontab = () => {
|
||||||
setSearchText(value);
|
setSearchText(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleCrons = (cron: any) => {
|
||||||
|
const index = value.findIndex((x) => x._id === cron._id);
|
||||||
|
const result = [...value];
|
||||||
|
if (index === -1) {
|
||||||
|
result.push(cron);
|
||||||
|
} else {
|
||||||
|
result.splice(index, 1, {
|
||||||
|
...cron,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
setValue(result);
|
||||||
|
};
|
||||||
|
|
||||||
const getCronDetail = (cron: any) => {
|
const getCronDetail = (cron: any) => {
|
||||||
request
|
request
|
||||||
.get(`${config.apiPrefix}crons/${cron._id}`)
|
.get(`${config.apiPrefix}crons/${cron._id}`)
|
||||||
|
|
|
@ -33,7 +33,7 @@ const CronModal = ({
|
||||||
message: data,
|
message: data,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
handleCancel(true);
|
handleCancel(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user