修复任务视图bug (#1612)

* 修复了视图无排序时无法再次修改的问题

* 修复在视图管理中编辑、新建视图点击确定后不能关闭页面的问题

* 修复#1611 避免查询条件被覆盖

* 修复视图筛选不能正确处理`不包含`
This commit is contained in:
景大侠
2022-09-06 00:25:05 +08:00
committed by GitHub
parent 687d16e21b
commit daf6f94c51
3 changed files with 27 additions and 11 deletions
+2 -2
View File
@@ -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(),
}),
}),
+20 -7
View File
@@ -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);
}
}