From e5d8adf95527287ccadce102892786ec413e46ab Mon Sep 17 00:00:00 2001 From: whyour Date: Sat, 3 Sep 2022 02:15:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E8=A7=86=E5=9B=BE=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/data/cronView.ts | 4 ++-- back/services/cron.ts | 8 ++++---- src/pages/crontab/index.tsx | 5 ++++- src/pages/crontab/viewCreateModal.tsx | 14 ++++++-------- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/back/data/cronView.ts b/back/data/cronView.ts index c1da1bb5..36bd3d9c 100644 --- a/back/data/cronView.ts +++ b/back/data/cronView.ts @@ -2,7 +2,7 @@ import { sequelize } from '.'; import { DataTypes, Model } from 'sequelize'; interface SortType { - type: 'ASD' | 'DESC'; + type: 'ASC' | 'DESC'; value: string; } @@ -23,7 +23,7 @@ export class CrontabView { this.name = options.name; this.id = options.id; this.position = options.position; - this.isDisabled = options.isDisabled; + this.isDisabled = options.isDisabled || 0; this.filters = options.filters; this.sorts = options.sorts; } diff --git a/back/services/cron.ts b/back/services/cron.ts index 1e2eeb27..c7dcf7bd 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -114,7 +114,7 @@ export default class CronService { } private formatViewQuery(query: any, viewQuery: any) { - if (viewQuery.filters) { + if (viewQuery.filters && viewQuery.filters.length > 0) { for (const col of viewQuery.filters) { const { property, value, operation } = col; let operate = null; @@ -209,9 +209,9 @@ export default class CronService { } private formatViewSort(order: string[][], viewQuery: any) { - if (viewQuery.sorts) { - for (const [col, sortType] of viewQuery.sorts) { - order.unshift([col, sortType]); + if (viewQuery.sorts && viewQuery.sorts.length > 0) { + for (const { property, type } of viewQuery.sorts) { + order.unshift([property, type]); } } } diff --git a/src/pages/crontab/index.tsx b/src/pages/crontab/index.tsx index 179823ae..32d6c397 100644 --- a/src/pages/crontab/index.tsx +++ b/src/pages/crontab/index.tsx @@ -399,7 +399,10 @@ const Crontab = ({ headerStyle, isPhone, theme }: any) => { }`; } if (viewConf) { - url += `&queryString=${JSON.stringify({ filters: viewConf.filters })}`; + url += `&queryString=${JSON.stringify({ + filters: viewConf.filters, + sorts: viewConf.sorts, + })}`; } request .get(url) diff --git a/src/pages/crontab/viewCreateModal.tsx b/src/pages/crontab/viewCreateModal.tsx index 77294ddf..ae95e9d1 100644 --- a/src/pages/crontab/viewCreateModal.tsx +++ b/src/pages/crontab/viewCreateModal.tsx @@ -76,10 +76,14 @@ const ViewCreateModal = ({ }; useEffect(() => { - form.setFieldsValue(view || {}); if (!view) { form.resetFields(); } + form.setFieldsValue( + view || { + filters: [{ property: 'command', operation: 'Reg' }], + }, + ); }, [view, visible]); const operationElement = ( @@ -164,7 +168,6 @@ const ViewCreateModal = ({ {fields.map(({ key, name, ...restField }, index) => ( @@ -204,7 +207,6 @@ const ViewCreateModal = ({ ))} add({ property: 'command', operation: 'Reg' })} > @@ -220,7 +222,6 @@ const ViewCreateModal = ({ {fields.map(({ key, name, ...restField }, index) => ( @@ -246,10 +247,7 @@ const ViewCreateModal = ({ ))} - add({ property: 'command', operation: 'ASC' })} - > + add({ property: 'command', type: 'ASC' })}> 新增排序方式