Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
bdc
/
bdcjg-web
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
7668d9bc
authored
2023-02-13 08:59:34 +0800
by
赵千
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
定时任务前端编写
1 parent
3b051109
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
127 additions
and
159 deletions
src/api/sjsbTask.js
src/utils/filter.js
src/views/system/components/addTask.vue
src/views/system/timedTask/data/index.js
src/views/system/timedTask/index.vue
src/api/sjsbTask.js
View file @
7668d9b
...
...
@@ -6,15 +6,19 @@ class sjsbTask {
// 定时任务查询接口
async
getTaskListByName
(
data
)
{
return
request
({
url
:
SERVER
.
SERVERAPI
+
'/sjsbTask/getTaskListByName'
,
method
:
'post'
,
data
url
:
SERVER
.
SERVERAPI
+
'/rest/schedule/getScheduleList'
,
method
:
'get'
,
params
:
{
jobName
:
data
.
jobName
,
pageNo
:
data
.
currentPage
,
pageSize
:
data
.
pageSize
}
})
}
// 定时任务新增接口
async
sjsbTaskSave
(
data
)
{
return
request
({
url
:
SERVER
.
SERVERAPI
+
'/
sjsbTask/save
'
,
url
:
SERVER
.
SERVERAPI
+
'/
rest/schedule/add
'
,
method
:
'post'
,
data
})
...
...
@@ -22,7 +26,7 @@ class sjsbTask {
// 修改定时任务执行时间接口
async
updateCron
(
data
)
{
return
request
({
url
:
SERVER
.
SERVERAPI
+
'/
sjsbTask/updateCron
'
,
url
:
SERVER
.
SERVERAPI
+
'/
rest/schedule/update
'
,
method
:
'post'
,
data
})
...
...
@@ -30,50 +34,30 @@ class sjsbTask {
// 定时任务删除接口
async
sjsbTaskRemove
(
id
)
{
return
request
({
url
:
SERVER
.
SERVERAPI
+
'/
sjsbTask/remov
e'
,
url
:
SERVER
.
SERVERAPI
+
'/
rest/schedule/delet
e'
,
method
:
'get'
,
params
:
{
id
:
id
}
})
}
// 暂停任务接口
async
pauseJob
(
id
)
{
return
request
({
url
:
SERVER
.
SERVERAPI
+
'/sjsbTask/pauseJob'
,
method
:
'get'
,
params
:
{
id
:
id
jobId
:
id
}
})
}
// 恢复任务接口
async
re
sumeJob
(
id
)
{
async
re
cover
(
id
)
{
return
request
({
url
:
SERVER
.
SERVERAPI
+
'/
sjsbTask/resumeJob
'
,
url
:
SERVER
.
SERVERAPI
+
'/
rest/schedule/recover
'
,
method
:
'get'
,
params
:
{
i
d
:
id
jobI
d
:
id
}
})
}
// 激活任务接口
async
activateJob
(
id
)
{
return
request
({
url
:
SERVER
.
SERVERAPI
+
'/sjsbTask/activateJob'
,
method
:
'get'
,
params
:
{
id
:
id
}
})
}
// 手动测试
async
sjsbTaskRun
(
id
)
{
async
active
(
id
)
{
return
request
({
url
:
SERVER
.
SERVERAPI
+
'/
sjsbTask/run
'
,
url
:
SERVER
.
SERVERAPI
+
'/
rest/schedule/active
'
,
method
:
'get'
,
params
:
{
i
d
:
id
jobI
d
:
id
}
})
}
...
...
src/utils/filter.js
View file @
7668d9b
...
...
@@ -25,4 +25,10 @@ export default class filter {
return
name
}
}
stateStatus
(
val
)
{
let
index
=
val
+
1
;
// -1 : 不存在 ,0 : 待激活,1:正常,2:暂停,3 : 出错, 4:阻塞
let
status
=
{
0
:
'不存在'
,
1
:
'待激活'
,
2
:
'正常'
,
3
:
'暂停'
,
4
:
'出错'
,
5
:
'阻塞'
}
return
status
[
index
]
}
}
...
...
src/views/system/components/addTask.vue
View file @
7668d9b
<
template
>
<!-- 编辑 -->
<dialogBox
ref=
"addTask"
width=
"60%"
@
submitForm=
"handleSubmit"
:closed=
"true"
@
closeDialog=
"handleClos
e"
customClass=
"editValidRule"
multiple
title=
"新增定时任务"
>
<dialogBox
ref=
"addTask"
width=
"60%"
@
submitForm=
"handleSubmit"
@
closeDialog=
"handleClose"
v-model=
"myValu
e"
customClass=
"editValidRule"
title=
"新增定时任务"
>
<el-form
:model=
"ruleForm"
:rules=
"rules"
ref=
"ruleForm"
label-width=
"100px"
>
<el-row
:gutter=
"20"
>
<el-col
:span=
"12"
>
<el-form-item
label=
"任务名"
prop=
"job
_n
ame"
>
<el-input
v-model=
"ruleForm.job
_n
ame"
placeholder=
"任务名"
></el-input>
<el-form-item
label=
"任务名"
prop=
"job
N
ame"
>
<el-input
v-model=
"ruleForm.job
N
ame"
placeholder=
"任务名"
></el-input>
</el-form-item>
</el-col>
<el-col
:span=
"12"
>
<el-form-item
label=
"
任务分组"
prop=
"job_group
"
>
<el-input
v-model=
"ruleForm.
job_group"
placeholder=
"任务分组
"
></el-input>
<el-form-item
label=
"
类名"
prop=
"beanName
"
>
<el-input
v-model=
"ruleForm.
beanName"
placeholder=
"类名
"
></el-input>
</el-form-item>
</el-col>
</el-row>
<el-row
:gutter=
"20"
>
<el-col
:span=
"12"
>
<el-form-item
label=
"cron表达式"
prop=
"cron
_e
xpression"
>
<el-input
v-model=
"ruleForm.cron
_e
xpression"
placeholder=
"cron表达式"
></el-input>
<el-form-item
label=
"cron表达式"
prop=
"cron
E
xpression"
>
<el-input
v-model=
"ruleForm.cron
E
xpression"
placeholder=
"cron表达式"
></el-input>
</el-form-item>
</el-col>
<el-col
:span=
"12"
>
<el-form-item
label=
"
任务类名"
prop=
"bean_class
"
>
<el-input
v-model=
"ruleForm.
bean_class"
placeholder=
"任务执行时调用哪个类的方法 包名+类
名"
></el-input>
<el-form-item
label=
"
方法名"
prop=
"methodName
"
>
<el-input
v-model=
"ruleForm.
methodName"
placeholder=
"方法
名"
></el-input>
</el-form-item>
</el-col>
</el-row>
<el-row
:gutter=
"20"
>
<el-col
:span=
"24"
>
<el-form-item
label=
"任务描述"
prop=
"
description
"
>
<el-input
v-model=
"ruleForm.
description
"
placeholder=
"任务描述"
></el-input>
<el-form-item
label=
"任务描述"
prop=
"
remark
"
>
<el-input
v-model=
"ruleForm.
remark
"
placeholder=
"任务描述"
></el-input>
</el-form-item>
</el-col>
</el-row>
...
...
@@ -43,6 +43,7 @@
import
sjsbTask
from
'@/api/sjsbTask.js'
export
default
{
props
:
{
value
:
{
type
:
Boolean
,
default
:
false
},
taskData
:
{
type
:
Object
,
default
:
null
...
...
@@ -50,42 +51,33 @@ export default {
},
data
()
{
return
{
myValue
:
this
.
value
,
ruleForm
:
{
job_name
:
''
,
job_group
:
''
,
cron_expression
:
''
,
bean_class
:
''
,
description
:
''
jobName
:
''
,
cronExpression
:
''
,
beanName
:
''
,
methodName
:
''
,
methodParams
:
''
,
remark
:
''
},
rules
:
{
job
_n
ame
:
[
job
N
ame
:
[
{
required
:
true
,
message
:
'任务名'
,
trigger
:
'blur'
}
],
job_group
:
[
{
required
:
true
,
message
:
'分组'
,
trigger
:
'blur'
}
],
cron_expression
:
[
cronExpression
:
[
{
required
:
true
,
message
:
'cron表达式'
,
trigger
:
'blur'
}
],
bean
_class
:
[
bean
Name
:
[
{
required
:
true
,
message
:
'任务类名'
,
trigger
:
'blur'
}
],
description
:
[
{
required
:
true
,
message
:
'任务
描述
'
,
trigger
:
'blur'
}
]
,
methodName
:
[
{
required
:
true
,
message
:
'任务
方法名
'
,
trigger
:
'blur'
}
]
},
message
:
''
}
},
methods
:
{
isShow
()
{
this
.
$refs
.
addTask
.
isShow
()
setTimeout
(()
=>
{
if
(
this
.
taskData
)
{
this
.
ruleForm
=
_
.
cloneDeep
(
this
.
taskData
)
}
},
0
)
},
handleSubmit
()
{
let
_this
=
this
this
.
$refs
[
'ruleForm'
].
validate
(
async
(
valid
)
=>
{
...
...
@@ -129,13 +121,49 @@ export default {
})
},
handleClose
()
{
this
.
$refs
.
addTask
.
isHide
()
this
.
$refs
[
'ruleForm'
].
resetFields
()
this
.
$emit
(
"input"
,
false
);
}
},
watch
:
{
value
(
val
)
{
this
.
myValue
=
val
},
taskData
(
val
)
{
if
(
val
!=
null
)
{
this
.
ruleForm
=
val
}
else
{
this
.
ruleForm
=
{
jobName
:
''
,
cronExpression
:
''
,
beanName
:
''
,
methodName
:
''
,
methodParams
:
''
,
remark
:
''
}
}
}
}
}
</
script
>
<
style
rel=
"stylesheet/less"
lang=
"less"
scoped
>
<
style
rel=
"stylesheet/scss"
lang=
"scss"
scoped
>
@import
"~@/styles/public.scss"
;
.editDialogBox-box
{
margin
:
14px
18px
30px
18px
!important
}
/
deep
/
.el-form-item__label
{
color
:
#fff
;
}
/
deep
/
.el-form-item
{
color
:
#fff
;
margin-bottom
:
10px
;
}
/
deep
/
.el-input__inner
{
background-color
:
transparent
;
border
:
1px
solid
#458ACF
;
}
</
style
>
...
...
src/views/system/timedTask/data/index.js
View file @
7668d9b
...
...
@@ -6,34 +6,35 @@ class data extends filter {
columns
()
{
return
[
{
prop
:
"job
_n
ame"
,
prop
:
"job
N
ame"
,
label
:
"任务名称"
,
width
:
130
},
{
prop
:
"
description
"
,
prop
:
"
remark
"
,
label
:
"任务描述"
,
width
:
300
},
{
prop
:
"cron
_e
xpression"
,
prop
:
"cron
E
xpression"
,
label
:
"cron表达式"
},
{
prop
:
"bean
_class
"
,
prop
:
"bean
Name
"
,
width
:
260
,
label
:
"任务类"
},
{
prop
:
"
job_group
"
,
label
:
"
任务分组
"
prop
:
"
methodName
"
,
label
:
"
方法名称
"
},
{
label
:
"状态"
,
prop
:
"jobStatus"
,
render
:
(
h
,
scope
)
=>
{
return
(
<
div
>
{
this
.
stateStatus
(
scope
.
row
.
job
_s
tatus
)
}
{
this
.
stateStatus
(
scope
.
row
.
job
S
tatus
)
}
<
/div
>
)
},
...
...
src/views/system/timedTask/index.vue
View file @
7668d9b
...
...
@@ -8,11 +8,12 @@
<el-row>
<el-col
:span=
"6"
>
<el-form-item
label=
"搜索标题"
>
<el-input
v-model=
"form.job
_n
ame"
placeholder=
"标题"
></el-input>
<el-input
v-model=
"form.job
N
ame"
placeholder=
"标题"
></el-input>
</el-form-item>
</el-col>
<el-col
:span=
"18"
class=
"btnColRight"
>
<btn
nativeType=
"cx"
@
click=
"handleSearch"
>
查询
</btn>
<btn
nativeType=
"cx"
@
click=
"handleSubmit"
>
搜索
</btn>
<btn
nativeType=
"cx"
@
click=
"resetSe"
>
重置
</btn>
<btn
nativeType=
"cx"
@
click=
"handleAdd"
>
新增
</btn>
</el-col>
</el-row>
...
...
@@ -23,7 +24,7 @@
@
size-change=
"handleSizeChange"
@
p-current-change=
"handleCurrentChange"
:column=
"tableData.columns"
:data=
"tableData.data"
>
</lb-table>
<add-task
ref=
"task"
:taskData=
"taskData"
/>
<add-task
ref=
"task"
:taskData=
"taskData"
v-model=
"isDialog"
/>
</div>
</div>
</
template
>
...
...
@@ -42,8 +43,9 @@ export default {
data
()
{
return
{
taskData
:
null
,
isDialog
:
false
,
form
:
{
job
_n
ame
:
''
,
job
N
ame
:
''
,
currentPage
:
1
},
selectionList
:
[],
...
...
@@ -60,37 +62,23 @@ export default {
render
:
(
h
,
scope
)
=>
{
return
(
<
div
>
<
el
-
button
type
=
"text"
size
=
"mini"
style
=
"color: #67C23A"
v
-
show
=
{
scope
.
row
.
job_status
!==
'1'
&&
scope
.
row
.
job_status
!==
'2'
}
icon
=
"el-icon-magic-stick"
onClick
=
{()
=>
{
this
.
handleRecovery
(
scope
.
row
)
}}
>
激活
<
/el-button
>
<
el
-
button
type
=
"text"
size
=
"mini"
style
=
"color: #67C23A;margin-left:0"
icon
=
"el-icon-refresh-right"
v
-
show
=
{
scope
.
row
.
job_status
===
'2'
}
onClick
=
{()
=>
{
this
.
handleActivation
(
scope
.
row
)
}}
>
恢复
<
/el-button
>
<
el
-
button
type
=
"text"
size
=
"mini"
v
-
show
=
{
scope
.
row
.
job
_status
!==
'1'
}
icon
=
"el-icon-
stopwatch
"
onClick
=
{()
=>
{
this
.
handle
test
(
scope
.
row
)
}}
>
手动测试
v
-
show
=
{
scope
.
row
.
job
Status
===
0
}
icon
=
"el-icon-
video-pause
"
onClick
=
{()
=>
{
this
.
handle
Active
(
scope
.
row
)
}}
>
激活
<
/el-button
>
<
el
-
button
type
=
"text"
size
=
"mini"
v
-
show
=
{
scope
.
row
.
job_status
===
'1'
}
v
-
show
=
{
scope
.
row
.
jobStatus
===
-
1
}
icon
=
"el-icon-video-pause"
onClick
=
{()
=>
{
this
.
handleSuspend
(
scope
.
row
)
}}
>
暂停
onClick
=
{()
=>
{
this
.
recover
(
scope
.
row
)
}}
>
恢复
<
/el-button
>
<
el
-
button
type
=
"text"
size
=
"mini"
icon
=
"el-icon-edit"
v
-
show
=
{
scope
.
row
.
job_status
===
'2'
||
scope
.
row
.
job_status
===
'-1'
||
scope
.
row
.
job_status
===
'0'
}
onClick
=
{()
=>
{
this
.
handleEdit
(
scope
.
row
)
}}
>
编辑
<
/el-button
>
<
el
-
button
type
=
"text"
size
=
"mini"
icon
=
"el-icon-delete"
style
=
"color:#F56C6C"
v
-
show
=
{
scope
.
row
.
job
_status
!==
'1'
}
v
-
show
=
{
scope
.
row
.
job
Status
!==
-
1
}
onClick
=
{()
=>
{
this
.
handleDel
(
scope
.
row
)
}}
>
删除
<
/el-button
>
<
/div
>
...
...
@@ -110,37 +98,30 @@ export default {
methods
:
{
handleAdd
()
{
this
.
taskData
=
null
this
.
$refs
.
task
.
isShow
()
this
.
isDialog
=
true
},
handleSearch
()
{
this
.
form
.
currentPage
=
1
this
.
tableData
.
data
=
[]
this
.
queryClick
()
resetSe
()
{
this
.
form
.
jobName
=
''
this
.
featchData
()
},
async
featchData
()
{
try
{
this
.
form
=
Object
.
assign
(
this
.
form
,
this
.
formData
)
let
{
result
:
{
list
,
total
,
pages
:
pageSize
,
pageNum
:
current
}
}
=
await
sjsbTask
.
getTaskListByName
(
this
.
form
)
this
.
tableData
.
data
=
list
this
.
pageData
=
{
pageSize
,
current
,
total
}
let
{
result
}
=
await
sjsbTask
.
getTaskListByName
(
this
.
form
)
this
.
tableData
.
data
=
result
.
list
console
.
log
(
this
.
tableData
.
data
,
'fffffffffffffffffff'
)
}
catch
(
error
)
{
this
.
message
=
error
}
},
// 暂停
handleSuspend
(
row
)
{
this
.
$confirm
(
'此操将进行暂停操作, 是否继续?'
,
'提示'
,
{
recover
(
row
)
{
this
.
$confirm
(
'此操将进行恢复操作, 是否继续?'
,
'提示'
,
{
confirmButtonText
:
'确定'
,
cancelButtonText
:
'取消'
,
type
:
'warning'
,
})
.
then
(()
=>
{
sjsbTask
.
pauseJob
(
row
.
i
d
)
sjsbTask
.
recover
(
row
.
jobI
d
)
.
then
((
res
)
=>
{
if
((
res
.
code
=
200
))
{
this
.
$message
({
...
...
@@ -164,15 +145,15 @@ export default {
})
})
},
// 激活
handle
Recovery
(
row
)
{
handle
Active
(
row
)
{
this
.
$confirm
(
'此操将进行激活操作, 是否继续?'
,
'提示'
,
{
confirmButtonText
:
'确定'
,
cancelButtonText
:
'取消'
,
type
:
'warning'
,
})
.
then
(()
=>
{
sjsbTask
.
activ
ateJob
(
row
.
i
d
)
sjsbTask
.
activ
e
(
row
.
jobI
d
)
.
then
((
res
)
=>
{
if
((
res
.
code
=
200
))
{
this
.
$message
({
...
...
@@ -196,15 +177,15 @@ export default {
})
})
},
//
恢复
handle
Activation
(
row
)
{
this
.
$confirm
(
'此操将进行
恢复
操作, 是否继续?'
,
'提示'
,
{
//
暂停
handle
Suspend
(
row
)
{
this
.
$confirm
(
'此操将进行
暂停
操作, 是否继续?'
,
'提示'
,
{
confirmButtonText
:
'确定'
,
cancelButtonText
:
'取消'
,
type
:
'warning'
,
})
.
then
(()
=>
{
sjsbTask
.
resum
eJob
(
row
.
id
)
sjsbTask
.
paus
eJob
(
row
.
id
)
.
then
((
res
)
=>
{
if
((
res
.
code
=
200
))
{
this
.
$message
({
...
...
@@ -228,41 +209,9 @@ export default {
})
})
},
// 手动测试
handletest
(
row
)
{
this
.
$confirm
(
'此操将进行手动测试, 是否继续?'
,
'提示'
,
{
confirmButtonText
:
'确定'
,
cancelButtonText
:
'取消'
,
type
:
'warning'
,
})
.
then
(()
=>
{
sjsbTask
.
sjsbTaskRun
(
row
.
id
)
.
then
((
res
)
=>
{
if
((
res
.
code
=
200
))
{
this
.
$alert
(
res
.
message
,
'提示'
,
{
confirmButtonText
:
'确定'
,
type
:
'success'
});
this
.
featchData
()
}
})
.
catch
((
error
)
=>
{
this
.
$alert
(
error
,
'提示'
,
{
confirmButtonText
:
'确定'
,
type
:
'error'
})
})
})
.
catch
(()
=>
{
this
.
$message
({
type
:
'info'
,
message
:
'已取消'
,
})
})
},
handleEdit
(
row
)
{
this
.
taskData
=
row
this
.
$refs
.
task
.
isShow
()
this
.
isDialog
=
true
},
handleDel
(
row
)
{
this
.
$confirm
(
'此操将进行删除操作, 是否继续?'
,
'提示'
,
{
...
...
@@ -271,7 +220,7 @@ export default {
type
:
'warning'
,
})
.
then
(()
=>
{
sjsbTask
.
sjsbTaskRemove
(
row
.
i
d
)
sjsbTask
.
sjsbTaskRemove
(
row
.
jobI
d
)
.
then
((
res
)
=>
{
if
((
res
.
code
=
200
))
{
this
.
$message
({
...
...
Please
register
or
sign in
to post a comment