diff --git a/server/src/apps/surveyManage/index.ts b/server/src/apps/surveyManage/index.ts index 8fcd5fc2..eb318a9a 100644 --- a/server/src/apps/surveyManage/index.ts +++ b/server/src/apps/surveyManage/index.ts @@ -114,14 +114,14 @@ export default class SurveyManage { let filter = {}, order = {}; if (condition.filter) { try { - filter = this.getFilter(JSON.parse(condition.filter)); + filter = this.getFilter(JSON.parse(decodeURIComponent(condition.filter))); } catch (error) { throw new CommonError('filter参数格式不正确'); } } if (condition.order) { try { - order = this.getOrder(JSON.parse(condition.order)); + order = this.getOrder(JSON.parse(decodeURIComponent(condition.order))); } catch (error) { throw new CommonError('order参数格式不正确'); } @@ -178,13 +178,13 @@ export default class SurveyManage { private getOrder(order) { - const allowOrderField = ['createDate', 'updateDate']; + const allowOrderFields = ['createDate', 'updateDate', 'curStatus.date']; - const orderList = JSON.parse(order).filter((orderItem) => - allowOrderField.includes(orderItem.field), + const orderList = order.filter((orderItem) => + allowOrderFields.includes(orderItem.field), ); return orderList.reduce((pre, cur) => { - pre[cur.field] = cur.value; + pre[cur.field] = cur.value === 1 ? 1 : -1; return pre; }, {}); } diff --git a/server/src/apps/surveyManage/service/surveyService.ts b/server/src/apps/surveyManage/service/surveyService.ts index 7583fcbe..99090d97 100644 --- a/server/src/apps/surveyManage/service/surveyService.ts +++ b/server/src/apps/surveyManage/service/surveyService.ts @@ -182,13 +182,9 @@ class SurveyService { }, condition.filter, ); - const order = Object.assign( - {}, - { - createDate: -1, - }, - condition.order, - ) as Sort; + const order = condition.order && Object.keys(condition.order).length > 0 ? condition.order as Sort : { + createDate: -1, + } as Sort; const data = await surveyMeta.find(query) .sort(order) .limit(condition.pageSize)