From b4d3bc6902287960cac06f5f1794ee1225ad379b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=B5=A9=E6=9E=97?= Date: Mon, 29 Jul 2024 17:03:00 +0800 Subject: [PATCH] =?UTF-8?q?[Bug]:=20=E5=88=A0=E9=99=A4=E5=8F=B0=E8=B4=A6?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=97=B6=E5=BA=94=E5=90=8C=E6=97=B6=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E8=AE=B0=E5=BD=95=E9=99=84=E4=BB=B6=E5=AD=90=E8=A1=A8?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E5=92=8C=E9=99=84=E4=BB=B6=E6=96=87=E4=BB=B6?= =?UTF-8?q?=20#6957?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/standard-objects/base.trigger.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/packages/standard-objects/base.trigger.js b/packages/standard-objects/base.trigger.js index 7b482adda3..9bdd09642a 100644 --- a/packages/standard-objects/base.trigger.js +++ b/packages/standard-objects/base.trigger.js @@ -144,20 +144,33 @@ const afterDeleteBase = async function () { _.each(fieldsName, function (fieldName) { const fieldProps = fields[fieldName]; - const indexOfType = fieldProps && ['file','image'].indexOf(fieldProps.type); - if( indexOfType > -1 && previousDoc[fieldName] && previousDoc[fieldName].length ){ - const collection = [cfs.files,cfs.images][indexOfType]; + const indexOfType = fieldProps && ['file', 'image'].indexOf(fieldProps.type); + if (indexOfType > -1 && previousDoc[fieldName] && previousDoc[fieldName].length) { + const collection = [cfs.files, cfs.images][indexOfType]; let ids = previousDoc[fieldName] - if(typeof ids === 'string'){ + if (typeof ids === 'string') { ids = [ids] } - _.each(ids,function (id){ + _.each(ids, function (id) { collection.remove({ "_id": id }); }) } }); + if ("cms_files" != object_name) { + // 删除附件 + const cmsFilesObj = objectql.getObject('cms_files') + const cmsFiles = await cmsFilesObj.find({ + filters: [ + ["parent/o", "=", object_name], + ["parent/ids", "=", previousDoc._id] + ] + }) + for (const cmsFile of cmsFiles) { + await cmsFilesObj.delete(cmsFile._id) + } + } } module.exports = {