使用sqlite替换nedb

This commit is contained in:
whyour
2022-01-06 22:51:12 +08:00
parent 653b1cef20
commit 5d19ee0ab5
38 changed files with 1040 additions and 856 deletions
+16 -16
View File
@@ -82,7 +82,7 @@ const Crontab = ({ headerStyle, isPhone }: any) => {
goToScriptManager(record);
}}
>
{record.name || record._id}{' '}
{record.name || record.id}{' '}
{record.isPinned ? (
<span>
<PushpinOutlined />
@@ -408,12 +408,12 @@ const Crontab = ({ headerStyle, isPhone }: any) => {
),
onOk() {
request
.delete(`${config.apiPrefix}crons`, { data: [record._id] })
.delete(`${config.apiPrefix}crons`, { data: [record.id] })
.then((data: any) => {
if (data.code === 200) {
message.success('删除成功');
const result = [...value];
const i = result.findIndex((x) => x._id === record._id);
const i = result.findIndex((x) => x.id === record.id);
result.splice(i, 1);
setValue(result);
} else {
@@ -441,11 +441,11 @@ const Crontab = ({ headerStyle, isPhone }: any) => {
),
onOk() {
request
.put(`${config.apiPrefix}crons/run`, { data: [record._id] })
.put(`${config.apiPrefix}crons/run`, { data: [record.id] })
.then((data: any) => {
if (data.code === 200) {
const result = [...value];
const i = result.findIndex((x) => x._id === record._id);
const i = result.findIndex((x) => x.id === record.id);
result.splice(i, 1, {
...record,
status: CrontabStatus.running,
@@ -476,11 +476,11 @@ const Crontab = ({ headerStyle, isPhone }: any) => {
),
onOk() {
request
.put(`${config.apiPrefix}crons/stop`, { data: [record._id] })
.put(`${config.apiPrefix}crons/stop`, { data: [record.id] })
.then((data: any) => {
if (data.code === 200) {
const result = [...value];
const i = result.findIndex((x) => x._id === record._id);
const i = result.findIndex((x) => x.id === record.id);
result.splice(i, 1, {
...record,
pid: null,
@@ -518,14 +518,14 @@ const Crontab = ({ headerStyle, isPhone }: any) => {
record.isDisabled === 1 ? 'enable' : 'disable'
}`,
{
data: [record._id],
data: [record.id],
},
)
.then((data: any) => {
if (data.code === 200) {
const newStatus = record.isDisabled === 1 ? 0 : 1;
const result = [...value];
const i = result.findIndex((x) => x._id === record._id);
const i = result.findIndex((x) => x.id === record.id);
result.splice(i, 1, {
...record,
isDisabled: newStatus,
@@ -562,14 +562,14 @@ const Crontab = ({ headerStyle, isPhone }: any) => {
record.isPinned === 1 ? 'unpin' : 'pin'
}`,
{
data: [record._id],
data: [record.id],
},
)
.then((data: any) => {
if (data.code === 200) {
const newStatus = record.isPinned === 1 ? 0 : 1;
const result = [...value];
const i = result.findIndex((x) => x._id === record._id);
const i = result.findIndex((x) => x.id === record.id);
result.splice(i, 1, {
...record,
isPinned: newStatus,
@@ -661,7 +661,7 @@ const Crontab = ({ headerStyle, isPhone }: any) => {
};
const handleCrons = (cron: any) => {
const index = value.findIndex((x) => x._id === cron._id);
const index = value.findIndex((x) => x.id === cron.id);
const result = [...value];
cron.nextRunTime = cron_parser
.parseExpression(cron.schedule)
@@ -679,9 +679,9 @@ const Crontab = ({ headerStyle, isPhone }: any) => {
const getCronDetail = (cron: any) => {
request
.get(`${config.apiPrefix}crons/${cron._id}`)
.get(`${config.apiPrefix}crons/${cron.id}`)
.then((data: any) => {
const index = value.findIndex((x) => x._id === cron._id);
const index = value.findIndex((x) => x.id === cron.id);
const result = [...value];
data.data.nextRunTime = cron_parser
.parseExpression(data.data.schedule)
@@ -774,7 +774,7 @@ const Crontab = ({ headerStyle, isPhone }: any) => {
useEffect(() => {
if (logCron) {
localStorage.setItem('logCron', logCron._id);
localStorage.setItem('logCron', logCron.id);
setIsLogModalVisible(true);
}
}, [logCron]);
@@ -873,7 +873,7 @@ const Crontab = ({ headerStyle, isPhone }: any) => {
pageSizeOptions: [10, 20, 50, 100, 200, 500, 1000],
}}
dataSource={value}
rowKey="_id"
rowKey="id"
size="middle"
scroll={{ x: 1000, y: tableScrollHeight }}
loading={loading}
+2 -2
View File
@@ -36,9 +36,9 @@ const CronLogModal = ({
setLoading(true);
}
request
.get(`${config.apiPrefix}crons/${cron._id}/log`)
.get(`${config.apiPrefix}crons/${cron.id}/log`)
.then((data: any) => {
if (localStorage.getItem('logCron') === cron._id) {
if (localStorage.getItem('logCron') === cron.id) {
const log = data.data as string;
setValue(log || '暂无日志');
setExecuting(
+1 -1
View File
@@ -21,7 +21,7 @@ const CronModal = ({
const method = cron ? 'put' : 'post';
const payload = { ...values };
if (cron) {
payload._id = cron._id;
payload.id = cron.id;
}
const { code, data } = await request[method](`${config.apiPrefix}crons`, {
data: payload,
+17 -11
View File
@@ -82,6 +82,12 @@ const Dependence = ({ headerStyle, isPhone, socketMessage }: any) => {
);
},
},
{
title: '备注',
dataIndex: 'remark',
key: 'remark',
align: 'center' as const,
},
{
title: '创建时间',
key: 'created',
@@ -175,7 +181,7 @@ const Dependence = ({ headerStyle, isPhone, socketMessage }: any) => {
),
onOk() {
request
.delete(`${config.apiPrefix}dependencies`, { data: [record._id] })
.delete(`${config.apiPrefix}dependencies`, { data: [record.id] })
.then((data: any) => {
if (data.code === 200) {
handleDependence(data.data[0]);
@@ -205,7 +211,7 @@ const Dependence = ({ headerStyle, isPhone, socketMessage }: any) => {
onOk() {
request
.put(`${config.apiPrefix}dependencies/reinstall`, {
data: [record._id],
data: [record.id],
})
.then((data: any) => {
if (data.code === 200) {
@@ -231,7 +237,7 @@ const Dependence = ({ headerStyle, isPhone, socketMessage }: any) => {
if (Array.isArray(dependence)) {
result.push(...dependence);
} else {
const index = value.findIndex((x) => x._id === dependence._id);
const index = value.findIndex((x) => x.id === dependence.id);
result.splice(index, 1, {
...dependence,
});
@@ -278,9 +284,9 @@ const Dependence = ({ headerStyle, isPhone, socketMessage }: any) => {
const getDependenceDetail = (dependence: any) => {
request
.get(`${config.apiPrefix}dependencies/${dependence._id}`)
.get(`${config.apiPrefix}dependencies/${dependence.id}`)
.then((data: any) => {
const index = value.findIndex((x) => x._id === dependence._id);
const index = value.findIndex((x) => x.id === dependence.id);
const result = [...value];
result.splice(index, 1, {
...dependence,
@@ -307,7 +313,7 @@ const Dependence = ({ headerStyle, isPhone, socketMessage }: any) => {
useEffect(() => {
if (logDependence) {
localStorage.setItem('logDependence', logDependence._id);
localStorage.setItem('logDependence', logDependence.id);
setIsLogModalVisible(true);
}
}, [logDependence]);
@@ -328,7 +334,7 @@ const Dependence = ({ headerStyle, isPhone, socketMessage }: any) => {
}
const result = [...value];
for (let i = 0; i < references.length; i++) {
const index = value.findIndex((x) => x._id === references[i]);
const index = value.findIndex((x) => x.id === references[i]);
result.splice(index, 1, {
...result[index],
status,
@@ -340,7 +346,7 @@ const Dependence = ({ headerStyle, isPhone, socketMessage }: any) => {
setTimeout(() => {
const _result = [...value];
for (let i = 0; i < references.length; i++) {
const index = value.findIndex((x) => x._id === references[i]);
const index = value.findIndex((x) => x.id === references[i]);
_result.splice(index, 1);
}
setValue(_result);
@@ -372,7 +378,7 @@ const Dependence = ({ headerStyle, isPhone, socketMessage }: any) => {
rowSelection={rowSelection}
pagination={false}
dataSource={value}
rowKey="_id"
rowKey="id"
size="middle"
scroll={{ x: 768, y: tableScrollHeight }}
loading={loading}
@@ -432,11 +438,11 @@ const Dependence = ({ headerStyle, isPhone, socketMessage }: any) => {
handleCancel={(needRemove?: boolean) => {
setIsLogModalVisible(false);
if (needRemove) {
const index = value.findIndex((x) => x._id === logDependence._id);
const index = value.findIndex((x) => x.id === logDependence.id);
const result = [...value];
result.splice(index, 1);
setValue(result);
} else if ([...value].map((x) => x._id).includes(logDependence._id)) {
} else if ([...value].map((x) => x.id).includes(logDependence.id)) {
getDependenceDetail(logDependence);
}
}}
+3 -3
View File
@@ -46,9 +46,9 @@ const DependenceLogModal = ({
const getDependenceLog = () => {
setLoading(true);
request
.get(`${config.apiPrefix}dependencies/${dependence._id}`)
.get(`${config.apiPrefix}dependencies/${dependence.id}`)
.then((data: any) => {
if (localStorage.getItem('logDependence') === dependence._id) {
if (localStorage.getItem('logDependence') === dependence.id) {
const log = (data.data.log || []).join('\n') as string;
setValue(log);
setExecuting(!log.includes('结束时间'));
@@ -64,7 +64,7 @@ const DependenceLogModal = ({
setRemoveLoading(true);
request
.delete(`${config.apiPrefix}dependencies/force`, {
data: [dependence._id],
data: [dependence.id],
})
.then((data: any) => {
cancel(true);
+1 -1
View File
@@ -42,7 +42,7 @@ const DependenceModal = ({
payload = [{ name, type }];
}
} else {
payload = { ...values, _id: dependence._id };
payload = { ...values, id: dependence.id };
}
try {
const { code, data } = await request[method](
+7 -7
View File
@@ -101,7 +101,7 @@ const Env = ({ headerStyle, isPhone, theme }: any) => {
{
title: '序号',
align: 'center' as const,
width: 50,
width: 60,
render: (text: string, record: any, index: number) => {
return <span style={{ cursor: 'text' }}>{index + 1} </span>;
},
@@ -197,7 +197,7 @@ const Env = ({ headerStyle, isPhone, theme }: any) => {
{
title: '操作',
key: 'action',
width: 100,
width: 120,
align: 'center' as const,
render: (text: string, record: any, index: number) => {
const isPc = !isPhone;
@@ -270,7 +270,7 @@ const Env = ({ headerStyle, isPhone, theme }: any) => {
record.status === Status. ? 'enable' : 'disable'
}`,
{
data: [record._id],
data: [record.id],
},
)
.then((data: any) => {
@@ -321,7 +321,7 @@ const Env = ({ headerStyle, isPhone, theme }: any) => {
),
onOk() {
request
.delete(`${config.apiPrefix}envs`, { data: [record._id] })
.delete(`${config.apiPrefix}envs`, { data: [record.id] })
.then((data: any) => {
if (data.code === 200) {
message.success('删除成功');
@@ -351,7 +351,7 @@ const Env = ({ headerStyle, isPhone, theme }: any) => {
const handleEnv = (env: any) => {
const result = [...value];
const index = value.findIndex((x) => x._id === env._id);
const index = value.findIndex((x) => x.id === env.id);
if (index === -1) {
env = Array.isArray(env) ? env : [env];
result.push(...env);
@@ -376,7 +376,7 @@ const Env = ({ headerStyle, isPhone, theme }: any) => {
}
const dragRow = value[dragIndex];
request
.put(`${config.apiPrefix}envs/${dragRow._id}/move`, {
.put(`${config.apiPrefix}envs/${dragRow.id}/move`, {
data: { fromIndex: dragIndex, toIndex: hoverIndex },
})
.then((data: any) => {
@@ -534,7 +534,7 @@ const Env = ({ headerStyle, isPhone, theme }: any) => {
rowSelection={rowSelection}
pagination={false}
dataSource={value}
rowKey="_id"
rowKey="id"
size="middle"
scroll={{ x: 1000, y: tableScrollHeight }}
components={components}
+1 -1
View File
@@ -34,7 +34,7 @@ const EnvModal = ({
payload = [{ value, name, remarks }];
}
} else {
payload = { ...values, _id: env._id };
payload = { ...values, id: env.id };
}
const { code, data } = await request[method](`${config.apiPrefix}envs`, {
data: payload,
+34 -17
View File
@@ -1,12 +1,11 @@
import { useState, useEffect, useCallback, Key, useRef } from 'react';
import { TreeSelect, Tree, Input } from 'antd';
import { TreeSelect, Tree, Input, Empty } from 'antd';
import config from '@/utils/config';
import { PageContainer } from '@ant-design/pro-layout';
import Editor from '@monaco-editor/react';
import { request } from '@/utils/http';
import styles from './index.module.less';
import { Controlled as CodeMirror } from 'react-codemirror2';
import { useCtx, useTheme } from '@/utils/hooks';
import SplitPane from 'react-split-pane';
function getFilterData(keyword: string, data: any) {
@@ -143,21 +142,39 @@ const Log = ({ headerStyle, isPhone, theme }: any) => {
{!isPhone && (
<SplitPane split="vertical" size={200} maxSize={-100}>
<div className={styles['left-tree-container']}>
<Input.Search
className={styles['left-tree-search']}
onChange={onSearch}
></Input.Search>
<div className={styles['left-tree-scroller']} ref={treeDom}>
<Tree
className={styles['left-tree']}
treeData={filterData}
showIcon={true}
height={height}
selectedKeys={[select]}
showLine={{ showLeafIcon: true }}
onSelect={onTreeSelect}
></Tree>
</div>
{data.length > 0 ? (
<>
<Input.Search
className={styles['left-tree-search']}
onChange={onSearch}
></Input.Search>
<div className={styles['left-tree-scroller']} ref={treeDom}>
<Tree
className={styles['left-tree']}
treeData={filterData}
showIcon={true}
height={height}
selectedKeys={[select]}
showLine={{ showLeafIcon: true }}
onSelect={onTreeSelect}
></Tree>
</div>
</>
) : (
<div
style={{
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
height: '100%',
}}
>
<Empty
description="暂无日志"
image={Empty.PRESENTED_IMAGE_SIMPLE}
/>
</div>
)}
</div>
<Editor
language="shell"
+36 -17
View File
@@ -10,6 +10,7 @@ import {
Tooltip,
Dropdown,
Menu,
Empty,
} from 'antd';
import config from '@/utils/config';
import { PageContainer } from '@ant-design/pro-layout';
@@ -470,23 +471,41 @@ const Script = ({ headerStyle, isPhone, theme, socketMessage }: any) => {
{!isPhone && (
<SplitPane split="vertical" size={200} maxSize={-100}>
<div className={styles['left-tree-container']}>
<Input.Search
className={styles['left-tree-search']}
onChange={onSearch}
></Input.Search>
<div className={styles['left-tree-scroller']} ref={treeDom}>
<Tree
className={styles['left-tree']}
treeData={filterData}
showIcon={true}
height={height}
selectedKeys={[select]}
expandedKeys={expandedKeys}
onExpand={onExpand}
showLine={{ showLeafIcon: true }}
onSelect={onTreeSelect}
></Tree>
</div>
{data.length > 0 ? (
<>
<Input.Search
className={styles['left-tree-search']}
onChange={onSearch}
></Input.Search>
<div className={styles['left-tree-scroller']} ref={treeDom}>
<Tree
className={styles['left-tree']}
treeData={filterData}
showIcon={true}
height={height}
selectedKeys={[select]}
expandedKeys={expandedKeys}
onExpand={onExpand}
showLine={{ showLeafIcon: true }}
onSelect={onTreeSelect}
></Tree>
</div>
</>
) : (
<div
style={{
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
height: '100%',
}}
>
<Empty
description="暂无脚本"
image={Empty.PRESENTED_IMAGE_SIMPLE}
/>
</div>
)}
</div>
<Editor
language={mode}
+1 -1
View File
@@ -20,7 +20,7 @@ const AppModal = ({
const method = app ? 'put' : 'post';
const payload = { ...values };
if (app) {
payload._id = app._id;
payload.id = app.id;
}
const { code, data } = await request[method](`${config.apiPrefix}apps`, {
data: payload,
+4 -4
View File
@@ -164,7 +164,7 @@ const Setting = ({
),
onOk() {
request
.delete(`${config.apiPrefix}apps`, { data: [record._id] })
.delete(`${config.apiPrefix}apps`, { data: [record.id] })
.then((data: any) => {
if (data.code === 200) {
message.success('删除成功');
@@ -198,7 +198,7 @@ const Setting = ({
),
onOk() {
request
.put(`${config.apiPrefix}apps/${record._id}/reset-secret`)
.put(`${config.apiPrefix}apps/${record.id}/reset-secret`)
.then((data: any) => {
if (data.code === 200) {
message.success('重置成功');
@@ -222,7 +222,7 @@ const Setting = ({
};
const handleApp = (app: any) => {
const index = dataSource.findIndex((x) => x._id === app._id);
const index = dataSource.findIndex((x) => x.id === app.id);
const result = [...dataSource];
if (index === -1) {
result.push(app);
@@ -339,7 +339,7 @@ const Setting = ({
columns={columns}
pagination={false}
dataSource={dataSource}
rowKey="_id"
rowKey="id"
size="middle"
scroll={{ x: 768 }}
loading={loading}
+1 -1
View File
@@ -73,7 +73,7 @@ const LoginLog = ({ data }: any) => {
columns={columns}
pagination={false}
dataSource={data}
rowKey="_id"
rowKey="id"
size="middle"
scroll={{ x: 768 }}
/>