From e243f8a2b992421c933e38677b8437ca474469bd Mon Sep 17 00:00:00 2001 From: baozhoutao Date: Thu, 21 Mar 2024 13:56:52 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E5=AF=B9=E8=B1=A1=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=87=8D=E7=BD=AE=E6=8C=89=E9=92=AE,=20=E9=87=8D=E7=BD=AE?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E6=97=B6,=E5=B0=86=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E4=B9=9F=E9=87=8D=E7=BD=AE.=20=E9=87=8D=E7=BD=AE:=E5=B0=86db?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E5=BD=93=E5=89=8D=E5=AF=B9=E8=B1=A1=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E3=80=81=E5=AD=97=E6=AE=B5=E4=BF=A1=E6=81=AF=E5=85=A8?= =?UTF-8?q?=E9=83=A8=E6=B8=85=E7=90=86=E6=8E=89.=20#6537?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../objects/objects/buttons/reset.button.js | 16 ++++ .../objects/objects/buttons/reset.button.yml | 79 +++++++++++++++++++ .../services/database-objects.service.js | 21 ++++- 3 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 services/standard-object-database/main/default/objects/objects/buttons/reset.button.js create mode 100644 services/standard-object-database/main/default/objects/objects/buttons/reset.button.yml diff --git a/services/standard-object-database/main/default/objects/objects/buttons/reset.button.js b/services/standard-object-database/main/default/objects/objects/buttons/reset.button.js new file mode 100644 index 0000000000..f04b159622 --- /dev/null +++ b/services/standard-object-database/main/default/objects/objects/buttons/reset.button.js @@ -0,0 +1,16 @@ +/* + * @Author: baozhoutaon@hotoa.com + * @Date: 2022-03-29 20:33:44 + * @LastEditors: baozhoutao@steedos.com + * @LastEditTime: 2024-03-21 10:45:57 + * @Description: + */ +module.exports = { + resetVisible: function (object_name, record_id, permission, data) { + if(Meteor.settings.public.enable_saas){ + return false; + } + var record = data && data.record; + return record && record.is_system && record.is_customize && record.created; + } +} \ No newline at end of file diff --git a/services/standard-object-database/main/default/objects/objects/buttons/reset.button.yml b/services/standard-object-database/main/default/objects/objects/buttons/reset.button.yml new file mode 100644 index 0000000000..d36bf67b62 --- /dev/null +++ b/services/standard-object-database/main/default/objects/objects/buttons/reset.button.yml @@ -0,0 +1,79 @@ +name: reset +amis_schema: |- + { + "type": "service", + "body": [ + { + "type": "button", + "label": "重置", + "id": "u:delete_object", + "onEvent": { + "click": { + "actions": [ + { + "actionType": "dialog", + "dialog": { + "type": "dialog", + "title": "重置对象: ${record.label}", + "body": [ + { + "type": "tpl", + "tpl": "
\n
重置一个自定义对象进行以下操作:
\n\n
", + "inline": true, + "id": "u:6d0819fc0bda" + } + ], + "id": "u:b5c0f98dc113", + "closeOnEsc": false, + "closeOnOutside": false, + "showCloseButton": true, + "data": { + "&": "$$", + "recordId": "${recordId}" + }, + "onEvent": { + "confirm": { + "weight": 0, + "actions": [ + { + "componentId": "", + "args": { + "api": { + "url": "/service/api/~database-objects/reset", + "method": "post", + "data": { + "objectName": "${record.name}" + } + }, + "messages": {} + }, + "actionType": "ajax" + }, + { + "actionType": "custom", + "script": "window.location.reload();" + } + ] + } + } + } + } + ], + "weight": 0 + } + } + } + ], + "regions": [ + "body" + ], + "data": { + }, + "bodyClassName": "p-0", + "id": "u:46d1821365fc" + } +is_enable: true +label: 重置 +'on': record_only_more +type: amis_button +visible: true \ No newline at end of file diff --git a/services/standard-object-database/main/default/services/database-objects.service.js b/services/standard-object-database/main/default/services/database-objects.service.js index 92bf800885..4ed9b446e2 100644 --- a/services/standard-object-database/main/default/services/database-objects.service.js +++ b/services/standard-object-database/main/default/services/database-objects.service.js @@ -2,10 +2,15 @@ * @Author: baozhoutao@steedos.com * @Date: 2023-04-21 16:25:07 * @LastEditors: baozhoutao@steedos.com - * @LastEditTime: 2023-05-18 09:26:18 + * @LastEditTime: 2024-03-21 11:58:43 * @Description: */ var packageServiceName = '~database-objects' + +const { getObject } = require('@steedos/objectql'); + +const sleep = async (ms) => new Promise(resolve => setTimeout(resolve, ms)); + function isPatternTrigger(data){ const {listenTo} = data; if(listenTo === '*'){ @@ -36,7 +41,19 @@ module.exports = { * Actions */ actions: { - + resetObject: { + rest: { + method: "POST", + path: "/reset" + }, + async handler(ctx) { + const { objectName } = ctx.params; + await getObject('objects').directDelete({filters: ['name','=', objectName]}); + await getObject('object_fields').directDelete({filters: ['object','=', objectName]}); + await sleep(2 * 1000) + return true; + } + } }, /**