完成批量删除Task任务列表

This commit is contained in:
陈景阳
2019-12-08 10:58:02 +08:00
parent 1696081731
commit 0daeb33699
9 changed files with 124 additions and 113 deletions

View File

@@ -63,7 +63,7 @@ const put = (path, data) => {
}
const del = (path, data) => {
return request('DELETE', path)
return request('DELETE', path, {}, data)
}
export default {

View File

@@ -1,5 +1,4 @@
import request from '../../api/request'
const state = {
scheduleList: [],
scheduleForm: {}
@@ -33,18 +32,10 @@ const actions = {
request.delete(`/schedules/${id}`)
},
stopSchedule ({ state, dispatch }, id) {
request.post(`/schedules/${id}/stop`).then((resp) => {
if (resp.data.status === 'ok') {
dispatch(`getScheduleList`)
}
})
return request.post(`/schedules/${id}/stop`)
},
runSchedule ({ state, dispatch }, id) {
return request.post(`/schedules/${id}/run`).then((resp) => {
if (resp.data.status === 'ok') {
dispatch(`getScheduleList`)
}
})
return request.post(`/schedules/${id}/run`)
}
}

View File

@@ -102,6 +102,11 @@ const actions = {
dispatch('getTaskList')
})
},
deleteTaskMultiple ({ state }, ids) {
return request.delete(`/tasks_multiple`, {
ids: ids
})
},
getTaskLog ({ state, commit }, id) {
commit('SET_TASK_LOG', '')
return request.get(`/tasks/${id}/log`)

View File

@@ -249,19 +249,27 @@ export default {
this.$st.sendEv('定时任务', '删除', 'id', row._id)
},
onCrawl (row) {
// 停止定时任务
if (!row.status || row.status === 'running') {
this.$confirm('确定停止定时任务?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
// 停止定时任务
this.$store.dispatch('schedule/stopSchedule', row._id)
.then((resp) => {
this.$store.dispatch('schedule/getScheduleList')
if (resp.data.status === 'ok') {
this.$store.dispatch('schedule/getScheduleList')
return
}
this.$message({
type: 'error',
message: resp.data.error
})
})
}).catch(() => {})
}
// 运行定时任务
if (row.status === 'stop') {
this.$confirm('确定运行定时任务?', '提示', {
confirmButtonText: '确定',
@@ -270,7 +278,14 @@ export default {
}).then(() => {
this.$store.dispatch('schedule/runSchedule', row._id)
.then((resp) => {
this.$store.dispatch('schedule/getScheduleList')
if (resp.data.status === 'ok') {
this.$store.dispatch('schedule/getScheduleList')
return
}
this.$message({
type: 'error',
message: resp.data.error
})
})
}).catch(() => {})
}

View File

@@ -4,31 +4,12 @@
<!--filter-->
<div class="filter">
<div class="left">
<!--<el-select size="small" class="filter-select"-->
<!--v-model="filter.node_id"-->
<!--:placeholder="$t('Node')"-->
<!--filterable-->
<!--clearable-->
<!--@change="onSelectNode">-->
<!--<el-option v-for="op in nodeList" :key="op._id" :value="op._id" :label="op.name"></el-option>-->
<!--</el-select>-->
<!--<el-select size="small" class="filter-select"-->
<!--v-model="filter.spider_id"-->
<!--:placeholder="$t('Spider')"-->
<!--filterable-->
<!--clearable-->
<!--@change="onSelectSpider">-->
<!--<el-option v-for="op in spiderList" :key="op._id" :value="op._id" :label="op.name"></el-option>-->
<!--</el-select>-->
<!--<el-button size="small" type="success"-->
<!--icon="el-icon-search"-->
<!--class="refresh"-->
<!--@click="onRefresh">-->
<!--{{$t('Search')}}-->
<!--</el-button>-->
</div>
<!--<div class="right">-->
<!--</div>-->
<div class="right">
<el-button @click="onRemoveMultipleTask" size="small" type="danger">
删除任务
</el-button>
</div>
</div>
<!--./filter-->
@@ -38,7 +19,9 @@
:header-cell-style="{background:'rgb(48, 65, 86)',color:'white'}"
border
@row-click="onRowClick"
@selection-change="onSelectionChange">
>
<el-table-column type="selection" width="55"/>
<template v-for="col in columns">
<el-table-column v-if="col.name === 'spider_name'"
:key="col.name"
@@ -181,7 +164,9 @@ export default {
{ name: 'total_duration', label: 'Total Duration (sec)', width: '80', align: 'right' },
{ name: 'result_count', label: 'Results Count', width: '80' }
// { name: 'avg_num_results', label: 'Average Results Count per Second', width: '80' }
]
],
multipleSelection: []
}
},
computed: {
@@ -228,12 +213,6 @@ export default {
}
return false
})
// .filter((d, index) => {
// // pagination
// const pageNum = this.pageNum
// const pageSize = this.pageSize
// return (pageSize * (pageNum - 1) <= index) && (index < pageSize * pageNum)
// })
}
},
methods: {
@@ -244,11 +223,34 @@ export default {
this.$store.dispatch('task/getTaskList')
this.$st.sendEv('任务', '搜索')
},
onSelectNode () {
this.$st.sendEv('任务', '选择节点')
},
onSelectSpider () {
this.$st.sendEv('任务', '选择爬虫')
onRemoveMultipleTask () {
if (this.multipleSelection.length === 0) {
this.$message({
type: 'error',
message: '选择要删除的任务'
})
}
this.$confirm('确定删除任务', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
let ids = this.multipleSelection.map(item => item._id)
this.$store.dispatch('task/deleteTaskMultiple', ids).then((resp) => {
if (resp.data.status === 'ok') {
this.$message({
type: 'success',
message: '删除任务成功'
})
this.$store.dispatch('task/getTaskList')
return
}
this.$message({
type: 'error',
message: resp.data.error
})
})
}).catch(() => {})
},
onRemove (row, ev) {
ev.stopPropagation()
@@ -304,6 +306,9 @@ export default {
if (column.label !== this.$t('Action')) {
this.onView(row)
}
},
onSelectionChange (val) {
this.multipleSelection = val
}
},
created () {
@@ -312,10 +317,9 @@ export default {
this.$store.dispatch('node/getNodeList')
},
mounted () {
// request task list every 5 seconds
this.handle = setInterval(() => {
this.$store.dispatch('task/getTaskList')
}, 5000)
// this.handle = setInterval(() => {
// this.$store.dispatch('task/getTaskList')
// }, 5000)
},
destroyed () {
clearInterval(this.handle)