|
|
|
@@ -2,7 +2,7 @@
|
|
|
|
|
import { ref, computed, onMounted } from 'vue'
|
|
|
|
|
import { useRoute, useRouter } from 'vue-router'
|
|
|
|
|
import { message as toast } from '@/composables/useMessage'
|
|
|
|
|
import { ArrowLeft, Save, Upload, X, Eye, HelpCircle } from 'lucide-vue-next'
|
|
|
|
|
import { ArrowLeft, Save, Upload, X, Eye, HelpCircle, Play } from 'lucide-vue-next'
|
|
|
|
|
import PageLoading from '@/components/common/PageLoading.vue'
|
|
|
|
|
import { Button } from '@/components/ui/button'
|
|
|
|
|
import { Input } from '@/components/ui/input'
|
|
|
|
@@ -32,6 +32,10 @@ const formItems = ref<CpTaskFormItem[]>([])
|
|
|
|
|
const savingForm = ref(false)
|
|
|
|
|
const logicShowMap = ref<Record<string, boolean>>({})
|
|
|
|
|
|
|
|
|
|
// ---- 任务标题 ----
|
|
|
|
|
const taskTitle = ref('')
|
|
|
|
|
const savingTitle = ref(false)
|
|
|
|
|
const executingNow = ref(false)
|
|
|
|
|
// ---- 执行参数 ----
|
|
|
|
|
const executeParams = ref<CpTaskExecute>({
|
|
|
|
|
id: 0, frequency: 1, notification_type: 'none',
|
|
|
|
@@ -275,6 +279,7 @@ async function loadExecute() {
|
|
|
|
|
// getExecute 返回整个 cpTask 对象
|
|
|
|
|
cpUserId.value = data.edges?.cp_user?.id || data.cp_user_id || 0
|
|
|
|
|
taskType.value = data.task_type || ''
|
|
|
|
|
taskTitle.value = data.title || ''
|
|
|
|
|
executeParams.value = {
|
|
|
|
|
id: data.id || 0, frequency: data.frequency ?? 1,
|
|
|
|
|
notification_type: data.notification_type || 'none',
|
|
|
|
@@ -319,6 +324,27 @@ async function saveExecute() {
|
|
|
|
|
} finally { savingExecute.value = false }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function saveTitle() {
|
|
|
|
|
if (!taskTitle.value.trim()) { toast.error('标题不能为空'); return }
|
|
|
|
|
savingTitle.value = true
|
|
|
|
|
try {
|
|
|
|
|
await cpTaskApi.updateTitle(taskId.value, taskTitle.value.trim())
|
|
|
|
|
toast.success('标题修改成功')
|
|
|
|
|
} catch {
|
|
|
|
|
// 全局拦截器已处理错误提示
|
|
|
|
|
} finally { savingTitle.value = false }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function handleExecuteNow() {
|
|
|
|
|
executingNow.value = true
|
|
|
|
|
try {
|
|
|
|
|
await cpTaskApi.executeNow(taskId.value)
|
|
|
|
|
toast.success('任务已开始执行')
|
|
|
|
|
} catch {
|
|
|
|
|
// 全局拦截器已处理错误提示
|
|
|
|
|
} finally { executingNow.value = false }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
await Promise.all([loadForm(), loadExecute()])
|
|
|
|
|
loading.value = false
|
|
|
|
@@ -332,6 +358,12 @@ onMounted(async () => {
|
|
|
|
|
<ArrowLeft class="h-4 w-4" />
|
|
|
|
|
</Button>
|
|
|
|
|
<h2 class="text-2xl font-bold tracking-tight">任务配置</h2>
|
|
|
|
|
<div class="ml-auto flex items-center gap-2">
|
|
|
|
|
<Button variant="default" size="sm" :disabled="executingNow" @click="handleExecuteNow">
|
|
|
|
|
<Play class="mr-1 h-4 w-4" />
|
|
|
|
|
{{ executingNow ? '执行中...' : '立即执行' }}
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<PageLoading v-if="loading" text="加载中..." />
|
|
|
|
@@ -447,6 +479,18 @@ onMounted(async () => {
|
|
|
|
|
<CardContent>
|
|
|
|
|
<div v-if="executeLoading" class="text-sm text-muted-foreground py-4">加载中...</div>
|
|
|
|
|
<div v-else class="space-y-5">
|
|
|
|
|
<div class="space-y-2">
|
|
|
|
|
<Label for="taskTitle">任务标题</Label>
|
|
|
|
|
<div class="flex items-center gap-2">
|
|
|
|
|
<Input id="taskTitle" v-model="taskTitle" placeholder="请输入任务标题" class="flex-1" />
|
|
|
|
|
<Button size="sm" variant="outline" :disabled="savingTitle" @click="saveTitle">
|
|
|
|
|
{{ savingTitle ? '保存中' : '保存' }}
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<Separator />
|
|
|
|
|
|
|
|
|
|
<div class="space-y-2">
|
|
|
|
|
<Label for="frequency">执行次数</Label>
|
|
|
|
|
<Input id="frequency" type="number" v-model.number="executeParams.frequency" placeholder="请输入执行次数" :min="1" />
|
|
|
|
|