修复sqlite数据操作类型

This commit is contained in:
whyour
2022-01-08 01:09:38 +08:00
parent 89ed8527d6
commit e75a683173
21 changed files with 199 additions and 217 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ const CronLogModal = ({
request
.get(`${config.apiPrefix}crons/${cron.id}/log`)
.then((data: any) => {
if (localStorage.getItem('logCron') === cron.id) {
if (localStorage.getItem('logCron') === String(cron.id)) {
const log = data.data as string;
setValue(log || '暂无日志');
setExecuting(
+39 -36
View File
@@ -20,19 +20,26 @@ const CronModal = ({
setLoading(true);
const method = cron ? 'put' : 'post';
const payload = { ...values };
if (typeof payload.labels === 'string') {
payload.labels = values.labels.split(/,|/);
}
if (cron) {
payload.id = cron.id;
}
const { code, data } = await request[method](`${config.apiPrefix}crons`, {
data: payload,
});
if (code === 200) {
message.success(cron ? '更新Cron成功' : '新建Cron成功');
} else {
message.error(data);
try {
const { code, data } = await request[method](`${config.apiPrefix}crons`, {
data: payload,
});
if (code === 200) {
message.success(cron ? '更新Cron成功' : '新建Cron成功');
} else {
message.error(data);
}
setLoading(false);
handleCancel(data);
} catch (error: any) {
setLoading(false);
}
setLoading(false);
handleCancel(data);
};
useEffect(() => {
@@ -41,16 +48,13 @@ const CronModal = ({
return (
<Modal
title={cron ? '编辑定时' : '新建定时'}
title={cron ? '编辑任务' : '新建任务'}
visible={visible}
forceRender
onOk={() => {
form
.validateFields()
.then((values) => {
if (typeof values.labels === "string") {
values.labels = values.labels.split(/,|/);
}
handleOk(values);
})
.catch((info) => {
@@ -69,9 +73,6 @@ const CronModal = ({
<Form.Item name="name" label="名称">
<Input placeholder="请输入任务名称" />
</Form.Item>
<Form.Item name="labels" label="标签">
<Input placeholder="请输入任务标签" />
</Form.Item>
<Form.Item
name="command"
label="命令"
@@ -101,6 +102,9 @@ const CronModal = ({
>
<Input placeholder="秒(可选) 分 时 天 月 周" />
</Form.Item>
<Form.Item name="labels" label="标签">
<Input placeholder="请输入任务标签" />
</Form.Item>
</Form>
</Modal>
);
@@ -118,20 +122,25 @@ const CronLabelModal = ({
const [form] = Form.useForm();
const [loading, setLoading] = useState(false);
const update = async (action: string) => {
const update = async (action: 'delete' | 'post') => {
form
.validateFields()
.then(async (values) => {
if (typeof values.labels === "string") {
if (typeof values.labels === 'string') {
values.labels = values.labels.split(/,|/);
}
setLoading(true);
const payload = { ids, labels: values.labels };
const { code, data } = await request.put(`${config.apiPrefix}crons/${action}`, {
data: payload,
});
const { code, data } = await request[action](
`${config.apiPrefix}crons/labels`,
{
data: payload,
},
);
if (code === 200) {
message.success(action === 'addLabels' ? '添加Labels成功' : '删除Labels成功');
message.success(
action === 'post' ? '添加Labels成功' : '删除Labels成功',
);
} else {
message.error(data);
}
@@ -141,38 +150,32 @@ const CronLabelModal = ({
.catch((info) => {
console.log('Validate Failed:', info);
});
}
};
useEffect(() => {
form.resetFields();
}, [ids, visible]);
const buttons = [
<Button onClick={() => handleCancel(false)} key="test">
</Button>,
<Button type="primary" danger onClick={() => update('removeLabels')}>
<Button onClick={() => handleCancel(false)}></Button>,
<Button type="primary" danger onClick={() => update('delete')}>
</Button>,
<Button type="primary" onClick={() => update('addLabels')}>
<Button type="primary" onClick={() => update('post')}>
</Button>
</Button>,
];
return (
<Modal
title='批量修改标签'
title="批量修改标签"
visible={visible}
footer={buttons}
forceRender
onCancel={() => handleCancel(false)}
confirmLoading={loading}
>
<Form
form={form}
layout="vertical"
name="form_in_label_modal"
>
<Form form={form} layout="vertical" name="form_in_label_modal">
<Form.Item name="labels" label="标签">
<Input placeholder="请输入任务标签" />
</Form.Item>
@@ -181,4 +184,4 @@ const CronLabelModal = ({
);
};
export { CronModal as default, CronLabelModal }
export { CronModal as default, CronLabelModal };
+3 -3
View File
@@ -90,11 +90,11 @@ const Dependence = ({ headerStyle, isPhone, socketMessage }: any) => {
},
{
title: '创建时间',
key: 'created',
dataIndex: 'created',
key: 'timestamp',
dataIndex: 'timestamp',
align: 'center' as const,
render: (text: string, record: any) => {
return <span>{new Date(record.created).toLocaleString()}</span>;
return <span>{new Date(record.timestamp).toLocaleString()}</span>;
},
},
{
+3 -3
View File
@@ -48,8 +48,8 @@ const DependenceLogModal = ({
request
.get(`${config.apiPrefix}dependencies/${dependence.id}`)
.then((data: any) => {
if (localStorage.getItem('logDependence') === dependence.id) {
const log = (data.data.log || []).join('\n') as string;
if (localStorage.getItem('logDependence') === String(dependence.id)) {
const log = (data.data.log || []).join('') as string;
setValue(log);
setExecuting(!log.includes('结束时间'));
setIsRemoveFailed(log.includes('删除失败'));
@@ -99,7 +99,7 @@ const DependenceLogModal = ({
setExecuting(false);
setIsRemoveFailed(message.includes('删除失败'));
}
setValue(`${value} \n ${message}`);
setValue(`${value}${message}`);
}, [socketMessage]);
useEffect(() => {
+3 -2
View File
@@ -26,7 +26,7 @@ const DependenceModal = ({
const handleOk = async (values: any) => {
setLoading(true);
const { name, split, type } = values;
const { name, split, type, remark } = values;
const method = dependence ? 'put' : 'post';
let payload;
if (!dependence) {
@@ -36,10 +36,11 @@ const DependenceModal = ({
return {
name: x,
type,
remark,
};
});
} else {
payload = [{ name, type }];
payload = [{ name, type, remark }];
}
} else {
payload = { ...values, id: dependence.id };
-1
View File
@@ -125,7 +125,6 @@ const Script = ({ headerStyle, isPhone, theme, socketMessage }: any) => {
setExpandedKeys([p]);
onTreeSelect([vkey], obj);
}
history.push('/script');
};
const onSelect = (value: any, node: any) => {
+1 -1
View File
@@ -139,7 +139,7 @@ const CheckUpdate = ({ socketMessage }: any) => {
return;
}
const newMessage = `${value}\n${_message}`;
const newMessage = `${value}${_message}`;
modalRef.current.update({
content: (
<div style={{ height: '60vh', overflowY: 'auto' }}>