1
0

refactor: 重构任务执行

This commit is contained in:
2025-09-24 22:34:16 +08:00
parent 8011a4f2cb
commit 01690bbcd6
35 changed files with 610 additions and 1137 deletions

View File

@@ -9,7 +9,6 @@ import StockList from './pages/stock/StockList.tsx'
import StockDetail from './pages/stock/StockDetail.tsx'
import TaskList from './pages/task/TaskList.tsx'
import TaskTemplateList from './pages/task/TaskTemplateList.tsx'
import TaskTemplateSave from './pages/task/TaskTemplateSave.tsx'
import TaskScheduleList from './pages/task/TaskScheduleList.tsx'
import TaskScheduleSave from './pages/task/TaskScheduleSave.tsx'
import StockCollectionList from './pages/stock/StockCollectionList.tsx'
@@ -73,10 +72,6 @@ const routes: RouteObject[] = [
path: 'list',
Component: TaskTemplateList,
},
{
path: 'save/:id',
Component: TaskTemplateSave,
},
],
},
{

View File

@@ -1,5 +1,14 @@
import React from 'react'
import {amisRender, commonInfo, crudCommonOptions, paginationTemplate, remoteMappings, time} from '../../util/amis.tsx'
import {
amisRender,
commonInfo,
crudCommonOptions,
horizontalFormOptions,
paginationTemplate,
remoteMappings,
remoteOptions,
time,
} from '../../util/amis.tsx'
import {useNavigate} from 'react-router'
function TaskList() {
@@ -25,7 +34,41 @@ function TaskList() {
},
interval: 30000,
...crudCommonOptions(),
...paginationTemplate(15),
...paginationTemplate(
15,
undefined,
[
{
type: 'action',
label: '',
icon: 'fa fa-plus',
actionType: 'dialog',
dialog: {
title: '创建任务',
body: {
type: 'form',
api: {
method: 'post',
url: `${commonInfo.baseUrl}/task/execute`,
data: {
templateId: '${templateId|default:undefined}',
},
},
...horizontalFormOptions(),
body: [
{
name: 'templateId',
label: '名称',
required: true,
selectFirst: true,
...remoteOptions('select', 'task_template_id'),
},
],
},
},
},
],
),
columns: [
{
name: 'name',
@@ -44,10 +87,10 @@ function TaskList() {
...remoteMappings('task_status', 'status'),
},
{
name: 'step',
label: '进度',
type: 'progress',
width: 200,
value: '${ROUND(step * 100, 0)}',
},
{
label: '耗时',

View File

@@ -1,9 +1,7 @@
import React from 'react'
import {amisRender, commonInfo, crudCommonOptions, paginationTemplate} from '../../util/amis.tsx'
import {useNavigate} from 'react-router'
function TaskTemplateList() {
const navigate = useNavigate()
return (
<div className="task-template-list">
{amisRender(
@@ -13,43 +11,10 @@ function TaskTemplateList() {
body: [
{
type: 'crud',
api: {
method: 'post',
url: `${commonInfo.baseUrl}/task_template/list`,
data: {
page: {
index: '${page}',
size: '${perPage}',
},
},
},
api: `get:${commonInfo.baseUrl}/task/template/list`,
...crudCommonOptions(),
...paginationTemplate(
15,
undefined,
[
{
type: 'action',
label: '',
icon: 'fa fa-plus',
tooltip: '添加模板',
tooltipPlacement: 'top',
onEvent: {
click: {
actions: [
{
actionType: 'custom',
// @ts-ignore
script: (context, action, event) => {
navigate('/task/template/save/-1')
},
},
],
},
},
},
],
),
...paginationTemplate(15),
loadOnce: true,
columns: [
{
name: 'name',
@@ -63,7 +28,7 @@ function TaskTemplateList() {
{
type: 'operation',
label: '操作',
width: 150,
width: 100,
buttons: [
{
type: 'action',
@@ -78,35 +43,7 @@ function TaskTemplateList() {
},
},
confirmText: '确认执行模板<span class="text-lg font-bold mx-2">${name}</span>',
confirmTitle: '删除',
},
{
type: 'action',
label: '详情',
level: 'link',
onEvent: {
click: {
actions: [
{
actionType: 'custom',
// @ts-ignore
script: (context, action, event) => {
navigate(`/task/template/save/${context.props.data['id']}`)
},
},
],
},
},
},
{
className: 'text-danger btn-deleted',
type: 'action',
label: '删除',
level: 'link',
actionType: 'ajax',
api: `get:${commonInfo.baseUrl}/task_template/remove/\${id}`,
confirmText: '确认删除模板<span class="text-lg font-bold mx-2">${name}</span>',
confirmTitle: '删除',
confirmTitle: '执行',
},
],
},

View File

@@ -1,105 +0,0 @@
import React from 'react'
import {amisRender, commonInfo} from '../../util/amis.tsx'
import {useNavigate, useParams} from 'react-router'
function TaskTemplateSave() {
const navigate = useNavigate()
const {id} = useParams()
return (
<div className="task-template-save">
{amisRender(
{
type: 'page',
title: '任务模板添加',
body: [
{
debug: commonInfo.debug,
type: 'form',
api: `post:${commonInfo.baseUrl}/task_template/save`,
initApi: `get:${commonInfo.baseUrl}/task_template/detail/${id}`,
initFetchOn: `${id} !== -1`,
wrapWithPanel: false,
mode: 'horizontal',
labelAlign: 'left',
onEvent: {
submitSucc: {
actions: [
{
actionType: 'custom',
// @ts-ignore
script: (context, action, event) => {
navigate(-1)
},
},
],
},
},
body: [
{
type: 'hidden',
name: 'id',
},
{
type: 'input-text',
name: 'name',
label: '名称',
required: true,
clearable: true,
},
{
type: 'textarea',
name: 'description',
label: '描述',
required: true,
clearable: true,
},
{
type: 'input-text',
name: 'expression',
label: 'EL表达式',
required: true,
clearable: true,
},
{
type: 'button-toolbar',
buttons: [
{
type: 'action',
label: '提交',
actionType: 'submit',
level: 'primary',
},
{
type: 'action',
label: '重置',
actionType: 'reset',
},
{
type: 'action',
label: '返回',
onEvent: {
click: {
actions: [
{
actionType: 'custom',
// @ts-ignore
script: (context, action, event) => {
navigate(-1)
},
},
],
},
},
},
],
},
],
},
],
},
)}
</div>
)
}
export default React.memo(TaskTemplateSave)