feat: add cronmessage sendNow
This commit is contained in:
@@ -69,6 +69,44 @@ const handleCancel = () => {
|
||||
emit('cancel')
|
||||
emit('update:open', false)
|
||||
}
|
||||
|
||||
// 立即发送(新增模式也支持,可以在创建前测试发送效果)
|
||||
const handleSendNow = async () => {
|
||||
// 验证必填字段
|
||||
if (!formData.task_id) {
|
||||
toast.error('请先选择关联的发信任务')
|
||||
return
|
||||
}
|
||||
if (!formData.title) {
|
||||
toast.error('请先填写消息标题')
|
||||
return
|
||||
}
|
||||
if (!formData.content) {
|
||||
toast.error('请先填写消息内容')
|
||||
return
|
||||
}
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
const postData = {
|
||||
task_id: formData.task_id,
|
||||
title: formData.title,
|
||||
content: formData.content,
|
||||
url: formData.url
|
||||
}
|
||||
|
||||
const rsp = await request.post('/cronmessages/sendnow', postData)
|
||||
if (rsp.data.code === 200) {
|
||||
toast.success(rsp.data.msg)
|
||||
} else {
|
||||
toast.error(rsp.data.msg)
|
||||
}
|
||||
} catch (error) {
|
||||
toast.error('发送失败,请稍后重试')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -82,6 +120,7 @@ const handleCancel = () => {
|
||||
:loading="loading"
|
||||
@submit="handleSubmit"
|
||||
@cancel="handleCancel"
|
||||
@send-now="handleSendNow"
|
||||
/>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import { Textarea } from '@/components/ui/textarea'
|
||||
import { request } from '@/api/api'
|
||||
|
||||
interface CronMessageFormData {
|
||||
id?: number
|
||||
id?: string
|
||||
name: string
|
||||
cron_expression: string
|
||||
title: string
|
||||
@@ -27,6 +27,7 @@ interface Emits {
|
||||
(e: 'update:modelValue', value: CronMessageFormData): void
|
||||
(e: 'submit'): void
|
||||
(e: 'cancel'): void
|
||||
(e: 'sendNow'): void
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
@@ -92,6 +93,11 @@ const handleCancel = () => {
|
||||
emit('cancel')
|
||||
}
|
||||
|
||||
// 立即发送
|
||||
const handleSendNow = () => {
|
||||
emit('sendNow')
|
||||
}
|
||||
|
||||
// 组件挂载时加载数据
|
||||
loadAvailableTasks()
|
||||
</script>
|
||||
@@ -117,6 +123,9 @@ loadAvailableTasks()
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<p class="text-xs text-gray-500">
|
||||
⚠️ 请确保所选任务已配置至少一个发送实例,否则无法发送
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="space-y-1">
|
||||
@@ -152,6 +161,9 @@ loadAvailableTasks()
|
||||
<Button variant="outline" @click="handleCancel" size="sm" :disabled="loading">
|
||||
取消
|
||||
</Button>
|
||||
<Button variant="secondary" @click="handleSendNow" size="sm" :disabled="loading">
|
||||
立即发送
|
||||
</Button>
|
||||
<Button @click="handleSubmit" size="sm" :disabled="loading">
|
||||
{{ mode === 'add' ? '创建定时消息' : '更新定时消息' }}
|
||||
</Button>
|
||||
|
||||
@@ -89,6 +89,44 @@ const handleCancel = () => {
|
||||
emit('update:open', false)
|
||||
}
|
||||
|
||||
// 立即发送
|
||||
const handleSendNow = async () => {
|
||||
// 验证必填字段
|
||||
if (!formData.task_id) {
|
||||
toast.error('请先选择关联的发信任务')
|
||||
return
|
||||
}
|
||||
if (!formData.title) {
|
||||
toast.error('请先填写消息标题')
|
||||
return
|
||||
}
|
||||
if (!formData.content) {
|
||||
toast.error('请先填写消息内容')
|
||||
return
|
||||
}
|
||||
|
||||
loading.value = true
|
||||
try {
|
||||
const postData = {
|
||||
task_id: formData.task_id,
|
||||
title: formData.title,
|
||||
content: formData.content,
|
||||
url: formData.url
|
||||
}
|
||||
|
||||
const rsp = await request.post('/cronmessages/sendnow', postData)
|
||||
if (rsp.data.code === 200) {
|
||||
toast.success(rsp.data.msg)
|
||||
} else {
|
||||
toast.error(rsp.data.msg)
|
||||
}
|
||||
} catch (error) {
|
||||
toast.error('发送失败,请稍后重试')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 监听 cronMessage 变化,更新表单数据
|
||||
watch(
|
||||
() => props.cronMessage,
|
||||
@@ -114,6 +152,7 @@ watch(
|
||||
:loading="loading"
|
||||
@submit="handleSubmit"
|
||||
@cancel="handleCancel"
|
||||
@send-now="handleSendNow"
|
||||
/>
|
||||
</template>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user