From 9b1c02b63c5a4d6426ca8d4f8024edfb47b43773 Mon Sep 17 00:00:00 2001 From: by <738326776@qq.com> Date: Mon, 18 Dec 2023 20:45:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20a=20secondary=20confirmation=20fu?= =?UTF-8?q?nction=20to=20the=20direct=20execution=20o=E2=80=A6=20(#3161)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: add a secondary confirmation function to the direct execution of the move operation button * feat: add a secondary confirmation function to the direct execution of the move operation button * fix: fix the problem of uncontrolled confirm * fix: copywriting repair --------- Co-authored-by: zhangboya3 Co-authored-by: chenos --- packages/core/client/src/locale/zh-CN.json | 3 + .../antd/action/Action.Designer.tsx | 63 +++++++++++++++++++ .../schema-component/antd/action/Action.tsx | 6 +- 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/packages/core/client/src/locale/zh-CN.json b/packages/core/client/src/locale/zh-CN.json index f2c0ca190..aa550f57f 100644 --- a/packages/core/client/src/locale/zh-CN.json +++ b/packages/core/client/src/locale/zh-CN.json @@ -830,6 +830,9 @@ "Please use a valid SELECT or WITH AS statement": "请使用有效的 SELECT 或 WITH AS 语句", "Please confirm the SQL statement first": "请先确认 SQL 语句", "Automatically drop objects that depend on the collection (such as views), and in turn all objects that depend on those objects": "自动删除依赖于该表的对象,以及依赖这些对象的对象", + "Second confirmation": "二次确认", + "Perform the {{title}}": "执行{{title}}", + "Are you sure you want to perform the {{title}} action?": "你确定执行{{title}}操作吗?", "Sign in with another account": "登录其他账号", "Return to the main application": "返回主应用", "Permission denied": "没有权限" diff --git a/packages/core/client/src/schema-component/antd/action/Action.Designer.tsx b/packages/core/client/src/schema-component/antd/action/Action.Designer.tsx index d0256ab5b..9d4fd8a95 100644 --- a/packages/core/client/src/schema-component/antd/action/Action.Designer.tsx +++ b/packages/core/client/src/schema-component/antd/action/Action.Designer.tsx @@ -28,6 +28,7 @@ import { import { DefaultValueProvider } from '../../../schema-settings/hooks/useIsAllowToSetDefaultValue'; import { useLinkageAction } from './hooks'; import { requestSettingsSchema } from './utils'; +import { Field } from '@formily/core'; const Tree = connect( AntdTree, @@ -695,6 +696,33 @@ export const actionSettingsItems: SchemaSettingOptions['items'] = [ }; }, }, + { + name: 'updateMode', + Component: UpdateMode, + useVisible() { + const fieldSchema = useFieldSchema(); + const isUpdateModePopupAction = ['customize:bulkUpdate', 'customize:bulkEdit'].includes( + fieldSchema['x-action'], + ); + return isUpdateModePopupAction; + }, + }, + { + name: 'secondConFirm', + Component: SecondConFirm, + useVisible() { + const fieldSchema = useFieldSchema(); + const isPopupAction = [ + 'create', + 'update', + 'view', + 'customize:popup', + 'duplicate', + 'customize:create', + ].includes(fieldSchema['x-action'] || ''); + return !isPopupAction; + }, + }, { name: 'assignFieldValues', Component: AssignedFieldValues, @@ -769,7 +797,42 @@ export const actionSettingsItems: SchemaSettingOptions['items'] = [ ], }, ]; +function SecondConFirm() { + const { dn } = useDesignable(); + const fieldSchema = useFieldSchema(); + const { t } = useTranslation(); + const field = useField(); + return ( + { + if (!fieldSchema['x-component-props']) { + fieldSchema['x-component-props'] = {}; + } + if (value) { + fieldSchema['x-component-props'].confirm = value + ? { + title: 'Perform the {{title}}', + content: 'Are you sure you want to perform the {{title}} action?', + } + : {}; + } else { + fieldSchema['x-component-props'].confirm = {}; + } + field.componentProps.confirm = { ...fieldSchema['x-component-props']?.confirm }; + + dn.emit('patch', { + schema: { + ['x-uid']: fieldSchema['x-uid'], + 'x-component-props': { ...fieldSchema['x-component-props'] }, + }, + }); + }} + /> + ); +} export const actionSettings = new SchemaSettings({ name: 'ActionSettings', items: actionSettingsItems, diff --git a/packages/core/client/src/schema-component/antd/action/Action.tsx b/packages/core/client/src/schema-component/antd/action/Action.tsx index 1c5ba4747..b88b73a6f 100644 --- a/packages/core/client/src/schema-component/antd/action/Action.tsx +++ b/packages/core/client/src/schema-component/antd/action/Action.tsx @@ -65,7 +65,6 @@ export const Action: ComposedAction = observer( const variables = useVariables(); const localVariables = useLocalVariables({ currentForm: { values: record } as any }); const { getAriaLabel } = useGetAriaLabelOfAction(title); - let actionTitle = title || compile(fieldSchema.title); actionTitle = lodash.isString(actionTitle) ? t(actionTitle) : actionTitle; @@ -106,9 +105,10 @@ export const Action: ComposedAction = observer( setVisible(true); run(); }; - if (confirm) { + if (confirm?.content) { modal.confirm({ - ...confirm, + title: t(confirm.title, { title: actionTitle }), + content: t(confirm.content, { title: actionTitle }), onOk, }); } else {