feat: 定时任务页面 UI 优化
All checks were successful
continuous-integration/drone/push Build is passing

1. 脚本编辑:增加全屏编辑按钮,打开大弹窗编辑
2. 执行时间:改为时间选择器 + 标签方式,支持可视化添加多个时间点
3. 任务参数:改为 Key-Value 表格形式,支持添加/删除,更直观
This commit is contained in:
2026-01-28 17:52:31 +08:00
parent 97d0aac734
commit d57f812513

View File

@@ -97,9 +97,17 @@ const testLoading = ref(false)
const testResult = ref(null) const testResult = ref(null)
const testParams = ref('{}') const testParams = ref('{}')
// 参数编辑 // 参数编辑key-value-remark 列表)
const paramsDialogVisible = ref(false) const paramsDialogVisible = ref(false)
const paramsJson = ref('{}') const paramsJson = ref('{}')
const paramsList = ref([]) // [{key: '', value: '', remark: ''}]
// 脚本全屏编辑
const scriptDialogVisible = ref(false)
const scriptContent = ref('')
// 时间点选择
const newTimePoint = ref('09:00')
// 计算属性 // 计算属性
const timePointsStr = computed({ const timePointsStr = computed({
@@ -382,18 +390,63 @@ function showTestDialog() {
} }
function showParamsDialog() { function showParamsDialog() {
paramsJson.value = JSON.stringify(form.input_params || {}, null, 2) // 将 input_params 转换为列表格式
const params = form.input_params || {}
paramsList.value = Object.entries(params).map(([key, val]) => {
if (typeof val === 'object' && val !== null && 'value' in val) {
return { key, value: val.value, remark: val.remark || '' }
}
return { key, value: val, remark: '' }
})
if (paramsList.value.length === 0) {
paramsList.value.push({ key: '', value: '', remark: '' })
}
paramsDialogVisible.value = true paramsDialogVisible.value = true
} }
function addParam() {
paramsList.value.push({ key: '', value: '', remark: '' })
}
function removeParam(index) {
paramsList.value.splice(index, 1)
}
function saveParams() { function saveParams() {
try { // 将列表转换为对象
form.input_params = JSON.parse(paramsJson.value) const params = {}
paramsDialogVisible.value = false for (const item of paramsList.value) {
ElMessage.success('参数已保存') if (item.key) {
} catch (e) { params[item.key] = item.value
ElMessage.error('JSON 格式错误') }
} }
form.input_params = params
paramsDialogVisible.value = false
ElMessage.success('参数已保存')
}
// 脚本全屏编辑
function showScriptDialog() {
scriptContent.value = form.script_content
scriptDialogVisible.value = true
}
function saveScript() {
form.script_content = scriptContent.value
scriptDialogVisible.value = false
ElMessage.success('脚本已保存')
}
// 时间点管理
function addTimePoint() {
if (newTimePoint.value && !form.time_points.includes(newTimePoint.value)) {
form.time_points.push(newTimePoint.value)
form.time_points.sort()
}
}
function removeTimePoint(index) {
form.time_points.splice(index, 1)
} }
function getTenantName(tenantId) { function getTenantName(tenantId) {
@@ -547,8 +600,31 @@ onMounted(() => {
<!-- 调度配置 --> <!-- 调度配置 -->
<el-form-item v-if="form.schedule_type === 'simple'" label="执行时间"> <el-form-item v-if="form.schedule_type === 'simple'" label="执行时间">
<el-input v-model="timePointsStr" placeholder="09:00, 12:00, 18:00" /> <div class="time-points-container">
<div class="form-tip">多个时间点用逗号分隔格式: HH:MM</div> <div class="time-points-list">
<el-tag
v-for="(tp, idx) in form.time_points"
:key="idx"
closable
@close="removeTimePoint(idx)"
style="margin-right: 8px; margin-bottom: 8px"
>
{{ tp }}
</el-tag>
</div>
<div class="time-points-add">
<el-time-select
v-model="newTimePoint"
start="00:00"
step="00:30"
end="23:30"
placeholder="选择时间"
style="width: 120px"
/>
<el-button type="primary" size="small" @click="addTimePoint">添加</el-button>
</div>
</div>
<div class="form-tip">点击添加按钮增加执行时间点</div>
</el-form-item> </el-form-item>
<el-form-item v-else label="CRON表达式"> <el-form-item v-else label="CRON表达式">
<el-input v-model="form.cron_expression" placeholder="0 9 * * *" /> <el-input v-model="form.cron_expression" placeholder="0 9 * * *" />
@@ -574,28 +650,35 @@ onMounted(() => {
<div class="script-editor-container"> <div class="script-editor-container">
<div class="script-toolbar"> <div class="script-toolbar">
<el-button size="small" @click="handleShowSdkDocs">SDK 文档</el-button> <el-button size="small" @click="handleShowSdkDocs">SDK 文档</el-button>
<el-button size="small" @click="showScriptDialog">
<el-icon><FullScreen /></el-icon>
全屏编辑
</el-button>
<el-button size="small" type="primary" @click="showTestDialog">测试运行</el-button> <el-button size="small" type="primary" @click="showTestDialog">测试运行</el-button>
</div> </div>
<el-input <el-input
v-model="form.script_content" v-model="form.script_content"
type="textarea" type="textarea"
:rows="15" :rows="12"
placeholder="Python 脚本" placeholder="Python 脚本"
class="script-textarea" class="script-textarea"
/> />
</div> </div>
</el-form-item> </el-form-item>
<el-form-item label="超时时间">
<el-input-number v-model="form.script_timeout" :min="10" :max="3600" />
<span style="margin-left: 8px; color: #999"></span>
</el-form-item>
</template> </template>
<!-- 任务参数 --> <!-- 任务参数 -->
<el-form-item label="任务参数"> <el-form-item label="任务参数">
<div class="params-preview"> <div class="params-preview">
<code>{{ JSON.stringify(form.input_params) }}</code> <div v-if="Object.keys(form.input_params || {}).length === 0" style="color: #999">
<el-button size="small" @click="showParamsDialog">编辑参数</el-button> 暂无参数
</div>
<div v-else class="params-tags">
<el-tag v-for="(val, key) in form.input_params" :key="key" style="margin-right: 8px">
{{ key }}: {{ String(val).substring(0, 20) }}{{ String(val).length > 20 ? '...' : '' }}
</el-tag>
</div>
<el-button size="small" type="primary" @click="showParamsDialog">编辑参数</el-button>
</div> </div>
<div class="form-tip">脚本中使用 get_param('key') 获取</div> <div class="form-tip">脚本中使用 get_param('key') 获取</div>
</el-form-item> </el-form-item>
@@ -800,16 +883,66 @@ onMounted(() => {
</el-dialog> </el-dialog>
<!-- 参数编辑对话框 --> <!-- 参数编辑对话框 -->
<el-dialog v-model="paramsDialogVisible" title="编辑任务参数" width="600px"> <el-dialog v-model="paramsDialogVisible" title="编辑任务参数" width="700px">
<el-input v-model="paramsJson" type="textarea" :rows="15" placeholder='{"prompt": "...", "history_days": 30}' /> <div class="params-table">
<div class="form-tip" style="margin-top: 8px"> <el-table :data="paramsList" style="width: 100%">
JSON 格式脚本中使用 get_param('key') 获取 <el-table-column label="参数名" width="150">
<template #default="{ row }">
<el-input v-model="row.key" placeholder="key" size="small" />
</template>
</el-table-column>
<el-table-column label="参数值" min-width="200">
<template #default="{ row }">
<el-input v-model="row.value" placeholder="value" size="small" />
</template>
</el-table-column>
<el-table-column label="备注" width="150">
<template #default="{ row }">
<el-input v-model="row.remark" placeholder="备注" size="small" />
</template>
</el-table-column>
<el-table-column label="操作" width="70" fixed="right">
<template #default="{ $index }">
<el-button type="danger" link size="small" @click="removeParam($index)">删除</el-button>
</template>
</el-table-column>
</el-table>
<div style="margin-top: 12px">
<el-button size="small" @click="addParam">
<el-icon><Plus /></el-icon>
添加参数
</el-button>
</div>
</div>
<div class="form-tip" style="margin-top: 12px">
脚本中使用 <code>get_param('key')</code> <code>get_param('key', '默认值')</code> 获取参数
</div> </div>
<template #footer> <template #footer>
<el-button @click="paramsDialogVisible = false">取消</el-button> <el-button @click="paramsDialogVisible = false">取消</el-button>
<el-button type="primary" @click="saveParams">保存</el-button> <el-button type="primary" @click="saveParams">保存</el-button>
</template> </template>
</el-dialog> </el-dialog>
<!-- 脚本全屏编辑对话框 -->
<el-dialog v-model="scriptDialogVisible" title="编辑脚本" width="90%" top="3vh" :close-on-click-modal="false">
<div class="script-fullscreen-toolbar">
<el-button size="small" @click="handleShowSdkDocs">SDK 文档</el-button>
<span style="color: #999; font-size: 12px; margin-left: 12px">
提示: 内置模块无需 import直接使用 datetime.now()json.dumps()
</span>
</div>
<el-input
v-model="scriptContent"
type="textarea"
:rows="30"
placeholder="Python 脚本"
class="script-textarea-fullscreen"
/>
<template #footer>
<el-button @click="scriptDialogVisible = false">取消</el-button>
<el-button type="primary" @click="saveScript">保存脚本</el-button>
</template>
</el-dialog>
</div> </div>
</template> </template>
@@ -866,24 +999,49 @@ onMounted(() => {
line-height: 1.5; line-height: 1.5;
} }
.script-textarea-fullscreen :deep(textarea) {
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
font-size: 14px;
line-height: 1.6;
}
.script-fullscreen-toolbar {
display: flex;
align-items: center;
margin-bottom: 12px;
}
.time-points-container {
width: 100%;
}
.time-points-list {
min-height: 32px;
margin-bottom: 8px;
}
.time-points-add {
display: flex;
gap: 8px;
align-items: center;
}
.params-preview { .params-preview {
display: flex; display: flex;
align-items: center; align-items: center;
gap: 12px; gap: 12px;
flex-wrap: wrap;
} }
.params-preview code { .params-tags {
flex: 1; flex: 1;
padding: 8px 12px;
background: #f5f7fa;
border-radius: 4px;
font-size: 12px;
max-width: 400px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
} }
.params-table {
min-height: 200px;
}
.output-preview, .error-preview { .output-preview, .error-preview {
cursor: pointer; cursor: pointer;
font-size: 12px; font-size: 12px;