任务视图增加系统视图

This commit is contained in:
whyour 2022-11-26 20:34:07 +08:00
parent 799cda1e3e
commit 1446e925ec
7 changed files with 58 additions and 16 deletions

View File

@ -58,8 +58,12 @@ export default (app: Router) => {
async (req: Request, res: Response, next: NextFunction) => {
try {
const cronViewService = Container.get(CronViewService);
const data = await cronViewService.update(req.body);
return res.send({ code: 200, data });
if (req.body.type === 1) {
return res.send({ code: 400, message: '参数错误' });
} else {
const data = await cronViewService.update(req.body);
return res.send({ code: 200, data });
}
} catch (e) {
return next(e);
}

View File

@ -1 +1 @@
export const LOG_END_SYMBOL = '\n          ';
export const LOG_END_SYMBOL = '\n          ';

View File

@ -1,6 +1,11 @@
import { sequelize } from '.';
import { DataTypes, Model } from 'sequelize';
export enum CronViewType {
'系统' = 1,
'个人',
}
interface SortType {
type: 'ASC' | 'DESC';
value: string;
@ -20,6 +25,7 @@ export class CrontabView {
filters?: FilterType[];
sorts?: SortType[];
filterRelation?: 'and' | 'or';
type?: CronViewType;
constructor(options: CrontabView) {
this.name = options.name;
@ -29,6 +35,7 @@ export class CrontabView {
this.filters = options.filters;
this.sorts = options.sorts;
this.filterRelation = options.filterRelation;
this.type = options.type || CronViewType.;
}
}
@ -50,5 +57,6 @@ export const CrontabViewModel = sequelize.define<CronViewInstance>(
type: DataTypes.STRING,
allowNull: true,
},
type: DataTypes.NUMBER,
},
);

View File

@ -10,7 +10,7 @@ import { fileExist } from '../config/util';
import { SubscriptionModel } from '../data/subscription';
import { CrontabViewModel } from '../data/cronView';
import config from '../config';
import { sequelize } from '../data'
import { sequelize } from '../data';
export default async () => {
try {
@ -24,10 +24,17 @@ export default async () => {
// 初始化新增字段
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) {}
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) {}
// 2.10-2.11 升级

View File

@ -8,13 +8,28 @@ import groupBy from 'lodash/groupBy';
import { DependenceModel } from '../data/dependence';
import { Op } from 'sequelize';
import config from '../config';
import { CrontabViewModel } from '../data/cronView';
import { CrontabViewModel, CronViewType } from '../data/cronView';
import { initPosition } from '../data/env';
export default async () => {
const cronService = Container.get(CronService);
const envService = Container.get(EnvService);
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(
{ status: CrontabStatus.idle },

View File

@ -857,7 +857,7 @@ const Crontab = () => {
useEffect(() => {
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);
}
}, [viewConf, enabledCronViews]);
@ -894,7 +894,7 @@ const Crontab = () => {
viewAction(key);
}}
items={[
...[...enabledCronViews].slice(2).map((x) => ({
...[...enabledCronViews].slice(4).map((x) => ({
label: (
<Space style={{ display: 'flex', justifyContent: 'space-between' }}>
<span>{x.name}</span>
@ -990,11 +990,7 @@ const Crontab = () => {
}
onTabClick={tabClick}
items={[
{
key: 'all',
label: '全部任务',
},
...[...enabledCronViews].slice(0, 2).map((x) => ({
...[...enabledCronViews].slice(0, 4).map((x) => ({
key: x.id,
label: x.name,
})),

View File

@ -81,6 +81,16 @@ const ViewManageModal = ({
dataIndex: 'name',
key: 'name',
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: '显示',
@ -100,10 +110,10 @@ const ViewManageModal = ({
{
title: '操作',
key: 'action',
width: 140,
width: 100,
align: 'center' as const,
render: (text: string, record: any, index: number) => {
return (
return record.type !== 1 ? (
<Space size="middle">
<a onClick={() => editView(record, index)}>
<EditOutlined />
@ -112,6 +122,8 @@ const ViewManageModal = ({
<DeleteOutlined />
</a>
</Space>
) : (
'-'
);
},
},