mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 23:06:06 +08:00
任务视图增加系统视图
This commit is contained in:
parent
799cda1e3e
commit
1446e925ec
|
@ -58,8 +58,12 @@ export default (app: Router) => {
|
||||||
async (req: Request, res: Response, next: NextFunction) => {
|
async (req: Request, res: Response, next: NextFunction) => {
|
||||||
try {
|
try {
|
||||||
const cronViewService = Container.get(CronViewService);
|
const cronViewService = Container.get(CronViewService);
|
||||||
|
if (req.body.type === 1) {
|
||||||
|
return res.send({ code: 400, message: '参数错误' });
|
||||||
|
} else {
|
||||||
const data = await cronViewService.update(req.body);
|
const data = await cronViewService.update(req.body);
|
||||||
return res.send({ code: 200, data });
|
return res.send({ code: 200, data });
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return next(e);
|
return next(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
import { sequelize } from '.';
|
import { sequelize } from '.';
|
||||||
import { DataTypes, Model } from 'sequelize';
|
import { DataTypes, Model } from 'sequelize';
|
||||||
|
|
||||||
|
export enum CronViewType {
|
||||||
|
'系统' = 1,
|
||||||
|
'个人',
|
||||||
|
}
|
||||||
|
|
||||||
interface SortType {
|
interface SortType {
|
||||||
type: 'ASC' | 'DESC';
|
type: 'ASC' | 'DESC';
|
||||||
value: string;
|
value: string;
|
||||||
|
@ -20,6 +25,7 @@ export class CrontabView {
|
||||||
filters?: FilterType[];
|
filters?: FilterType[];
|
||||||
sorts?: SortType[];
|
sorts?: SortType[];
|
||||||
filterRelation?: 'and' | 'or';
|
filterRelation?: 'and' | 'or';
|
||||||
|
type?: CronViewType;
|
||||||
|
|
||||||
constructor(options: CrontabView) {
|
constructor(options: CrontabView) {
|
||||||
this.name = options.name;
|
this.name = options.name;
|
||||||
|
@ -29,6 +35,7 @@ export class CrontabView {
|
||||||
this.filters = options.filters;
|
this.filters = options.filters;
|
||||||
this.sorts = options.sorts;
|
this.sorts = options.sorts;
|
||||||
this.filterRelation = options.filterRelation;
|
this.filterRelation = options.filterRelation;
|
||||||
|
this.type = options.type || CronViewType.个人;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,5 +57,6 @@ export const CrontabViewModel = sequelize.define<CronViewInstance>(
|
||||||
type: DataTypes.STRING,
|
type: DataTypes.STRING,
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
},
|
},
|
||||||
|
type: DataTypes.NUMBER,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { fileExist } from '../config/util';
|
||||||
import { SubscriptionModel } from '../data/subscription';
|
import { SubscriptionModel } from '../data/subscription';
|
||||||
import { CrontabViewModel } from '../data/cronView';
|
import { CrontabViewModel } from '../data/cronView';
|
||||||
import config from '../config';
|
import config from '../config';
|
||||||
import { sequelize } from '../data'
|
import { sequelize } from '../data';
|
||||||
|
|
||||||
export default async () => {
|
export default async () => {
|
||||||
try {
|
try {
|
||||||
|
@ -24,10 +24,17 @@ export default async () => {
|
||||||
|
|
||||||
// 初始化新增字段
|
// 初始化新增字段
|
||||||
try {
|
try {
|
||||||
await sequelize.query('alter table CrontabViews add column filterRelation VARCHAR(255)')
|
await sequelize.query(
|
||||||
|
'alter table CrontabViews add column filterRelation VARCHAR(255)',
|
||||||
|
);
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
try {
|
try {
|
||||||
await sequelize.query('alter table Subscriptions add column proxy VARCHAR(255)')
|
await sequelize.query(
|
||||||
|
'alter table Subscriptions add column proxy VARCHAR(255)',
|
||||||
|
);
|
||||||
|
} catch (error) {}
|
||||||
|
try {
|
||||||
|
await sequelize.query('alter table CrontabViews add column type NUMBER');
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
|
|
||||||
// 2.10-2.11 升级
|
// 2.10-2.11 升级
|
||||||
|
|
|
@ -8,13 +8,28 @@ import groupBy from 'lodash/groupBy';
|
||||||
import { DependenceModel } from '../data/dependence';
|
import { DependenceModel } from '../data/dependence';
|
||||||
import { Op } from 'sequelize';
|
import { Op } from 'sequelize';
|
||||||
import config from '../config';
|
import config from '../config';
|
||||||
import { CrontabViewModel } from '../data/cronView';
|
import { CrontabViewModel, CronViewType } from '../data/cronView';
|
||||||
|
import { initPosition } from '../data/env';
|
||||||
|
|
||||||
export default async () => {
|
export default async () => {
|
||||||
const cronService = Container.get(CronService);
|
const cronService = Container.get(CronService);
|
||||||
const envService = Container.get(EnvService);
|
const envService = Container.get(EnvService);
|
||||||
const dependenceService = Container.get(DependenceService);
|
const dependenceService = Container.get(DependenceService);
|
||||||
|
|
||||||
|
// 初始化新增默认全部任务视图
|
||||||
|
CrontabViewModel.findAll({
|
||||||
|
where: { type: CronViewType.系统, name: '全部任务' },
|
||||||
|
raw: true,
|
||||||
|
}).then((docs) => {
|
||||||
|
if (docs.length === 0) {
|
||||||
|
CrontabViewModel.create({
|
||||||
|
name: '全部任务',
|
||||||
|
type: CronViewType.系统,
|
||||||
|
position: initPosition / 2,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// 初始化更新所有任务状态为空闲
|
// 初始化更新所有任务状态为空闲
|
||||||
await CrontabModel.update(
|
await CrontabModel.update(
|
||||||
{ status: CrontabStatus.idle },
|
{ status: CrontabStatus.idle },
|
||||||
|
|
|
@ -857,7 +857,7 @@ const Crontab = () => {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (viewConf && enabledCronViews && enabledCronViews.length > 0) {
|
if (viewConf && enabledCronViews && enabledCronViews.length > 0) {
|
||||||
const view = enabledCronViews.slice(2).find((x) => x.id === viewConf.id);
|
const view = enabledCronViews.slice(4).find((x) => x.id === viewConf.id);
|
||||||
setMoreMenuActive(!!view);
|
setMoreMenuActive(!!view);
|
||||||
}
|
}
|
||||||
}, [viewConf, enabledCronViews]);
|
}, [viewConf, enabledCronViews]);
|
||||||
|
@ -894,7 +894,7 @@ const Crontab = () => {
|
||||||
viewAction(key);
|
viewAction(key);
|
||||||
}}
|
}}
|
||||||
items={[
|
items={[
|
||||||
...[...enabledCronViews].slice(2).map((x) => ({
|
...[...enabledCronViews].slice(4).map((x) => ({
|
||||||
label: (
|
label: (
|
||||||
<Space style={{ display: 'flex', justifyContent: 'space-between' }}>
|
<Space style={{ display: 'flex', justifyContent: 'space-between' }}>
|
||||||
<span>{x.name}</span>
|
<span>{x.name}</span>
|
||||||
|
@ -990,11 +990,7 @@ const Crontab = () => {
|
||||||
}
|
}
|
||||||
onTabClick={tabClick}
|
onTabClick={tabClick}
|
||||||
items={[
|
items={[
|
||||||
{
|
...[...enabledCronViews].slice(0, 4).map((x) => ({
|
||||||
key: 'all',
|
|
||||||
label: '全部任务',
|
|
||||||
},
|
|
||||||
...[...enabledCronViews].slice(0, 2).map((x) => ({
|
|
||||||
key: x.id,
|
key: x.id,
|
||||||
label: x.name,
|
label: x.name,
|
||||||
})),
|
})),
|
||||||
|
|
|
@ -81,6 +81,16 @@ const ViewManageModal = ({
|
||||||
dataIndex: 'name',
|
dataIndex: 'name',
|
||||||
key: 'name',
|
key: 'name',
|
||||||
align: 'center' as const,
|
align: 'center' as const,
|
||||||
|
render: (text) => (
|
||||||
|
<div style={{ textAlign: 'left', paddingLeft: 30 }}>{text}</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '类型',
|
||||||
|
dataIndex: 'type',
|
||||||
|
key: 'type',
|
||||||
|
align: 'center' as const,
|
||||||
|
render: (v) => (v === 1 ? '系统' : '个人'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '显示',
|
title: '显示',
|
||||||
|
@ -100,10 +110,10 @@ const ViewManageModal = ({
|
||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
key: 'action',
|
key: 'action',
|
||||||
width: 140,
|
width: 100,
|
||||||
align: 'center' as const,
|
align: 'center' as const,
|
||||||
render: (text: string, record: any, index: number) => {
|
render: (text: string, record: any, index: number) => {
|
||||||
return (
|
return record.type !== 1 ? (
|
||||||
<Space size="middle">
|
<Space size="middle">
|
||||||
<a onClick={() => editView(record, index)}>
|
<a onClick={() => editView(record, index)}>
|
||||||
<EditOutlined />
|
<EditOutlined />
|
||||||
|
@ -112,6 +122,8 @@ const ViewManageModal = ({
|
||||||
<DeleteOutlined />
|
<DeleteOutlined />
|
||||||
</a>
|
</a>
|
||||||
</Space>
|
</Space>
|
||||||
|
) : (
|
||||||
|
'-'
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue
Block a user