import { NGrid, NFormItemGi, NInput, NSwitch, NTooltip } from 'naive-ui' import { useForm, useModalHooks } from '@baota/naive-ui/hooks' import { useError } from '@baota/hooks/error' import { $t } from '@locales/index' import { useEmailChannelFormController } from '../useController' import { useStore } from '../useStore' import type { ReportMail, ReportType } from '@/types/setting' /** * 邮箱通知渠道表单组件 */ export default defineComponent({ name: 'EmailChannelForm', props: { data: { type: Object as PropType | null>, default: () => null, }, }, setup(props: { data: ReportType | null }) { const { handleError } = useError() const { confirm } = useModalHooks() const { fetchNotifyChannels } = useStore() const { config, rules, emailChannelForm, submitForm } = useEmailChannelFormController() if (props.data) { const { name, config } = props.data emailChannelForm.value = { name, ...config, } } // 使用表单hooks const { component: EmailForm, example, data, } = useForm({ config, defaultValue: emailChannelForm, rules, }) // 关联确认按钮 confirm(async (close) => { try { const { name, ...other } = data.value await example.value?.validate() const res = await submitForm( { type: 'mail', name: name || '', config: other, }, example, props.data?.id, ) fetchNotifyChannels() if (res) close() } catch (error) { handleError(error) } }) return () => ( ) }, })