import { useForm, useModalHooks } from '@baota/naive-ui/hooks' import { useError } from '@baota/hooks/error' import { useWebhookChannelFormController } from './useController' import { useStore } from '@settings/useStore' import type { ReportWebhook, ReportType } from '@/types/setting' /** * Webhook通知渠道表单组件 */ export default defineComponent({ name: 'WebhookChannelModel', 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, webhookChannelForm, submitForm } = useWebhookChannelFormController() if (props.data) { const { name, config } = props.data webhookChannelForm.value = { name, ...config, } } // 使用表单hooks const { component: WebhookForm, example, data, } = useForm({ config, defaultValue: webhookChannelForm, rules, }) // 关联确认按钮 confirm(async (close) => { try { const { name, ...other } = data.value await example.value?.validate() const res = await submitForm( { type: 'webhook', name: name || '', config: other, }, example, props.data?.id, ) fetchNotifyChannels() if (res) close() } catch (error) { handleError(error) } }) return () => (
{/* 模板变量说明 */}
模板变量将在发送时替换成实际值:
__subject__:通知主题
__body__:通知内容
) }, })