diff --git a/back/api/cron.ts b/back/api/cron.ts index 027e0f84..275ac595 100644 --- a/back/api/cron.ts +++ b/back/api/cron.ts @@ -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); } diff --git a/back/config/const.ts b/back/config/const.ts index 7bddf45c..3c412fd3 100644 --- a/back/config/const.ts +++ b/back/config/const.ts @@ -1 +1 @@ -export const LOG_END_SYMBOL = '\n          '; \ No newline at end of file +export const LOG_END_SYMBOL = '\n          '; diff --git a/back/data/cronView.ts b/back/data/cronView.ts index cf7bb84a..70c6c1ab 100644 --- a/back/data/cronView.ts +++ b/back/data/cronView.ts @@ -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( type: DataTypes.STRING, allowNull: true, }, + type: DataTypes.NUMBER, }, ); diff --git a/back/loaders/db.ts b/back/loaders/db.ts index 03e491bb..9145669f 100644 --- a/back/loaders/db.ts +++ b/back/loaders/db.ts @@ -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 升级 diff --git a/back/loaders/initData.ts b/back/loaders/initData.ts index 7571a787..19b519f5 100644 --- a/back/loaders/initData.ts +++ b/back/loaders/initData.ts @@ -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 }, diff --git a/src/pages/crontab/index.tsx b/src/pages/crontab/index.tsx index c50c7f50..eb6d9dd5 100644 --- a/src/pages/crontab/index.tsx +++ b/src/pages/crontab/index.tsx @@ -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: ( {x.name} @@ -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, })), diff --git a/src/pages/crontab/viewManageModal.tsx b/src/pages/crontab/viewManageModal.tsx index 820603cb..b0c4124c 100644 --- a/src/pages/crontab/viewManageModal.tsx +++ b/src/pages/crontab/viewManageModal.tsx @@ -81,6 +81,16 @@ const ViewManageModal = ({ dataIndex: 'name', key: 'name', align: 'center' as const, + render: (text) => ( +
{text}
+ ), + }, + { + 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 ? ( editView(record, index)}> @@ -112,6 +122,8 @@ const ViewManageModal = ({ + ) : ( + '-' ); }, },