From 2afd61606b23dae918cfe4e5cae7abf47d3ba364 Mon Sep 17 00:00:00 2001 From: xiaopeng Date: Thu, 21 Nov 2024 19:46:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DinsertParam=20=E5=BD=93body?= =?UTF-8?q?=E4=B8=BA=E6=95=B0=E7=BB=84=E6=97=B6=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/package.json | 2 +- core/src/controller/base.ts | 24 +++++++++++++++++++----- core/src/package.json | 2 +- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/core/package.json b/core/package.json index 629af0e..8586570 100644 --- a/core/package.json +++ b/core/package.json @@ -1,6 +1,6 @@ { "name": "@cool-midway/core", - "version": "7.1.20", + "version": "7.1.21", "description": "", "main": "dist/index.js", "typings": "index.d.ts", diff --git a/core/src/controller/base.ts b/core/src/controller/base.ts index a1e91b0..da76d52 100644 --- a/core/src/controller/base.ts +++ b/core/src/controller/base.ts @@ -65,11 +65,25 @@ export abstract class BaseController { if (!curdOption?.insertParam) { return; } - this.baseCtx.request.body = { - // @ts-ignore - ...this.baseCtx.request.body, - ...(await curdOption.insertParam(this.baseCtx, this.baseApp)), - }; + const body = this.baseCtx.request.body; + if (body) { + // 判断body是否是数组 + if (Array.isArray(body)) { + for (let i = 0; i < body.length; i++) { + body[i] = { + ...body[i], + ...(await curdOption.insertParam(this.baseCtx, this.baseApp)), + }; + } + this.baseCtx.request.body = body; + return; + } + this.baseCtx.request.body = { + // @ts-ignore + ...this.baseCtx.request.body, + ...(await curdOption.insertParam(this.baseCtx, this.baseApp)), + }; + } } /** diff --git a/core/src/package.json b/core/src/package.json index 7aef125..1c88b70 100644 --- a/core/src/package.json +++ b/core/src/package.json @@ -1,6 +1,6 @@ { "name": "@cool-midway/core", - "version": "7.1.20", + "version": "7.1.21", "description": "", "main": "index.js", "typings": "index.d.ts",