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

This commit is contained in:
cddjr 2022-09-05 00:04:12 +08:00
parent 362abf5f99
commit 2816dcee52
No known key found for this signature in database
GPG Key ID: 0D1E625DFCF77A9F

View File

@ -115,8 +115,12 @@ export default class CronService {
private formatViewQuery(query: any, viewQuery: any) { private formatViewQuery(query: any, viewQuery: any) {
if (viewQuery.filters && viewQuery.filters.length > 0) { if (viewQuery.filters && viewQuery.filters.length > 0) {
if (!query[Op.and]) {
query[Op.and] = [];
}
for (const col of viewQuery.filters) { for (const col of viewQuery.filters) {
const { property, value, operation } = col; const { property, value, operation } = col;
let q: any = {};
let operate = null; let operate = null;
switch (operation) { switch (operation) {
case 'Reg': case 'Reg':
@ -126,7 +130,7 @@ export default class CronService {
operate = Op.notLike; operate = Op.notLike;
break; break;
case 'In': case 'In':
query[Op.or] = [ q[Op.or] = [
{ {
[property]: value, [property]: value,
}, },
@ -136,7 +140,7 @@ export default class CronService {
]; ];
break; break;
case 'Nin': case 'Nin':
query[Op.and] = [ q[Op.and] = [
{ {
[property]: { [property]: {
[Op.notIn]: value, [Op.notIn]: value,
@ -151,19 +155,24 @@ export default class CronService {
break; break;
} }
if (operate) { if (operate) {
query[property] = { q[property] = {
[Op.or]: [ [Op.or]: [
{ [operate]: `%${value}%` }, { [operate]: `%${value}%` },
{ [operate]: `%${encodeURIComponent(value)}%` }, { [operate]: `%${encodeURIComponent(value)}%` },
], ],
}; };
} }
query[Op.and].push(q);
} }
} }
} }
private formatSearchText(query: any, searchText: string | undefined) { private formatSearchText(query: any, searchText: string | undefined) {
if (searchText) { if (searchText) {
if (!query[Op.and]) {
query[Op.and] = [];
}
let q: any = {};
const textArray = searchText.split(':'); const textArray = searchText.split(':');
switch (textArray[0]) { switch (textArray[0]) {
case 'name': case 'name':
@ -171,7 +180,7 @@ export default class CronService {
case 'schedule': case 'schedule':
case 'label': case 'label':
const column = textArray[0] === 'label' ? 'labels' : textArray[0]; const column = textArray[0] === 'label' ? 'labels' : textArray[0];
query[column] = { q[column] = {
[Op.or]: [ [Op.or]: [
{ [Op.like]: `%${textArray[1]}%` }, { [Op.like]: `%${textArray[1]}%` },
{ [Op.like]: `%${encodeURIComponent(textArray[1])}%` }, { [Op.like]: `%${encodeURIComponent(textArray[1])}%` },
@ -185,7 +194,7 @@ export default class CronService {
{ [Op.like]: `%${encodeURIComponent(searchText)}%` }, { [Op.like]: `%${encodeURIComponent(searchText)}%` },
], ],
}; };
query[Op.or] = [ q[Op.or] = [
{ {
name: reg, name: reg,
}, },
@ -201,6 +210,7 @@ export default class CronService {
]; ];
break; break;
} }
query[Op.and].push(q);
} }
} }