From daf6f94c51629d4c00ea6607c4beda01e4948807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=AF=E5=A4=A7=E4=BE=A0?= Date: Tue, 6 Sep 2022 00:25:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=BB=E5=8A=A1=E8=A7=86?= =?UTF-8?q?=E5=9B=BEbug=20(#1612)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修复了视图无排序时无法再次修改的问题 * 修复在视图管理中编辑、新建视图点击确定后不能关闭页面的问题 * 修复#1611 避免查询条件被覆盖 * 修复视图筛选不能正确处理`不包含` --- back/api/cron.ts | 4 ++-- back/services/cron.ts | 27 ++++++++++++++++++++------- src/pages/crontab/viewManageModal.tsx | 7 +++++-- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/back/api/cron.ts b/back/api/cron.ts index 7b69b005..b2435464 100644 --- a/back/api/cron.ts +++ b/back/api/cron.ts @@ -28,7 +28,7 @@ export default (app: Router) => { celebrate({ body: Joi.object({ name: Joi.string().required(), - sorts: Joi.array().optional(), + sorts: Joi.array().optional().allow(null), filters: Joi.array().optional(), }), }), @@ -49,7 +49,7 @@ export default (app: Router) => { body: Joi.object({ name: Joi.string().required(), id: Joi.number().required(), - sorts: Joi.array().optional(), + sorts: Joi.array().optional().allow(null), filters: Joi.array().optional(), }), }), diff --git a/back/services/cron.ts b/back/services/cron.ts index 50744b3d..c6ea3e3f 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -115,18 +115,25 @@ export default class CronService { private formatViewQuery(query: any, viewQuery: any) { if (viewQuery.filters && viewQuery.filters.length > 0) { + if (!query[Op.and]) { + query[Op.and] = []; + } for (const col of viewQuery.filters) { const { property, value, operation } = col; + let q: any = {}; + let operate2 = null; let operate = null; switch (operation) { case 'Reg': operate = Op.like; + operate2 = Op.or; break; case 'NotReg': operate = Op.notLike; + operate2 = Op.and; break; case 'In': - query[Op.or] = [ + q[Op.or] = [ { [property]: value, }, @@ -136,7 +143,7 @@ export default class CronService { ]; break; case 'Nin': - query[Op.and] = [ + q[Op.and] = [ { [property]: { [Op.notIn]: value, @@ -150,20 +157,25 @@ export default class CronService { default: break; } - if (operate) { - query[property] = { - [Op.or]: [ + if (operate && operate2) { + q[property] = { + [operate2]: [ { [operate]: `%${value}%` }, { [operate]: `%${encodeURIComponent(value)}%` }, ], }; } + query[Op.and].push(q); } } } private formatSearchText(query: any, searchText: string | undefined) { if (searchText) { + if (!query[Op.and]) { + query[Op.and] = []; + } + let q: any = {}; const textArray = searchText.split(':'); switch (textArray[0]) { case 'name': @@ -171,7 +183,7 @@ export default class CronService { case 'schedule': case 'label': const column = textArray[0] === 'label' ? 'labels' : textArray[0]; - query[column] = { + q[column] = { [Op.or]: [ { [Op.like]: `%${textArray[1]}%` }, { [Op.like]: `%${encodeURIComponent(textArray[1])}%` }, @@ -185,7 +197,7 @@ export default class CronService { { [Op.like]: `%${encodeURIComponent(searchText)}%` }, ], }; - query[Op.or] = [ + q[Op.or] = [ { name: reg, }, @@ -201,6 +213,7 @@ export default class CronService { ]; break; } + query[Op.and].push(q); } } diff --git a/src/pages/crontab/viewManageModal.tsx b/src/pages/crontab/viewManageModal.tsx index 066fbda9..f4030f65 100644 --- a/src/pages/crontab/viewManageModal.tsx +++ b/src/pages/crontab/viewManageModal.tsx @@ -231,7 +231,10 @@ const ViewManageModal = ({ @@ -258,8 +261,8 @@ const ViewManageModal = ({ view={editedView} visible={isCreateViewModalVisible} handleCancel={(data) => { - cronViewChange(data); setIsCreateViewModalVisible(false); + cronViewChange(data); }} />