diff --git a/apps/web-antd/src/utils/modal.tsx b/apps/web-antd/src/utils/modal.tsx new file mode 100644 index 00000000..c0ee4275 --- /dev/null +++ b/apps/web-antd/src/utils/modal.tsx @@ -0,0 +1,63 @@ +import type { Rule } from 'ant-design-vue/es/form'; + +import { reactive } from 'vue'; + +import { Alert, Form, Input, Modal, type ModalFuncProps } from 'ant-design-vue'; +import { isFunction } from 'lodash-es'; + +export interface ConfirmModalProps extends Omit { + confirmText?: string; + placeholder?: string; + onValidated?: () => Promise; +} + +export function confirmDeleteModal(props: ConfirmModalProps) { + const placeholder = props.placeholder || `输入'确认删除'以确认删除`; + const confirmText = props.confirmText || '确认删除'; + + const formValue = reactive({ + content: '', + }); + const rulesRef = reactive<{ [key: string]: Rule[] }>({ + content: [ + { + message: '校验不通过', + required: true, + trigger: 'change', + validator(_, value) { + if (value !== confirmText) { + return Promise.reject(new Error('校验不通过')); + } + return Promise.resolve(); + }, + }, + ], + }); + const useForm = Form.useForm; + const { validate, validateInfos } = useForm(formValue, rulesRef); + + Modal.confirm({ + ...props, + centered: true, + content: ( +
+ +
+ + + +
+
+ ), + okButtonProps: { danger: true, type: 'primary' }, + onOk: async () => { + await validate(); + isFunction(props.onValidated) && props.onValidated(); + }, + title: '提示', + type: 'warning', + }); +} diff --git a/apps/web-antd/src/views/monitor/logininfor/index.vue b/apps/web-antd/src/views/monitor/logininfor/index.vue index 95ef5a3e..22b6d91b 100644 --- a/apps/web-antd/src/views/monitor/logininfor/index.vue +++ b/apps/web-antd/src/views/monitor/logininfor/index.vue @@ -9,7 +9,8 @@ import { Page, useVbenModal } from '@vben/common-ui'; import { Space, Table } from 'ant-design-vue'; -import { loginInfoList } from '#/api/monitor/logininfo'; +import { loginInfoClean, loginInfoList } from '#/api/monitor/logininfo'; +import { confirmDeleteModal } from '#/utils/modal'; import { columns } from './data'; import loginInfoModal from './login-info-modal.vue'; @@ -30,10 +31,21 @@ function handlePreview(record: Recordable) { modalApi.setData(record); modalApi.open(); } + +function handleClear() { + confirmDeleteModal({ + onValidated: async () => { + await loginInfoClean(); + }, + }); +}