From 18f34f1703ff76ee2752544c1532749911cdddf5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=99=88=E6=99=AF=E9=98=B3?= <1656488874@qq.com>
Date: Sat, 7 Dec 2019 14:03:23 +0800
Subject: [PATCH] =?UTF-8?q?Feature=20=E6=96=B0=E5=A2=9E=E5=AE=9A=E6=97=B6?=
=?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=8F=AF=E6=9A=82=E5=81=9C/=E8=BF=90?=
=?UTF-8?q?=E8=A1=8C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
frontend/src/i18n/zh.js | 2 +
frontend/src/store/modules/schedule.js | 14 ++++++
frontend/src/views/schedule/ScheduleList.vue | 49 +++++++++++++++++---
3 files changed, 59 insertions(+), 6 deletions(-)
diff --git a/frontend/src/i18n/zh.js b/frontend/src/i18n/zh.js
index 65170117..c9e24806 100644
--- a/frontend/src/i18n/zh.js
+++ b/frontend/src/i18n/zh.js
@@ -212,6 +212,8 @@ export default {
'Schedule Description': '定时任务描述',
'Parameters': '参数',
'Add Schedule': '添加定时任务',
+ 'stop': '暂停',
+ 'running': '运行',
// 网站
'Site': '网站',
diff --git a/frontend/src/store/modules/schedule.js b/frontend/src/store/modules/schedule.js
index 44ab7218..caa1857d 100644
--- a/frontend/src/store/modules/schedule.js
+++ b/frontend/src/store/modules/schedule.js
@@ -31,6 +31,20 @@ const actions = {
},
removeSchedule ({ state }, id) {
request.delete(`/schedules/${id}`)
+ },
+ stopSchedule ({ state, dispatch }, id) {
+ request.post(`/schedules/${id}/stop`).then((resp) => {
+ if (resp.data.status === 'ok') {
+ dispatch(`getScheduleList`)
+ }
+ })
+ },
+ runSchedule ({ state, dispatch }, id) {
+ return request.post(`/schedules/${id}/run`).then((resp) => {
+ if (resp.data.status === 'ok') {
+ dispatch(`getScheduleList`)
+ }
+ })
}
}
diff --git a/frontend/src/views/schedule/ScheduleList.vue b/frontend/src/views/schedule/ScheduleList.vue
index 44a52517..e8ed5cd5 100644
--- a/frontend/src/views/schedule/ScheduleList.vue
+++ b/frontend/src/views/schedule/ScheduleList.vue
@@ -102,18 +102,29 @@
:header-cell-style="{background:'rgb(48, 65, 86)',color:'white'}"
border>
-
- {{$t(scope.row[col.name])}}
+ {{ scope.row[col.name] ? $t(scope.row[col.name]) : $t('NA') }}
+
+
+
+
+ {{scope.row[col.name]}}
-
+
@@ -123,7 +134,7 @@
-
+
@@ -151,7 +162,8 @@ export default {
{ name: 'node_name', label: 'Node', width: '150' },
{ name: 'spider_name', label: 'Spider', width: '150' },
{ name: 'param', label: 'Parameters', width: '150' },
- { name: 'description', label: 'Description', width: 'auto' }
+ { name: 'description', label: 'Description', width: 'auto' },
+ { name: 'status', label: 'Status', width: 'auto' }
],
isEdit: false,
dialogTitle: '',
@@ -236,7 +248,32 @@ export default {
})
this.$st.sendEv('定时任务', '删除', 'id', row._id)
},
- onCrawl () {
+ 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')
+ })
+ }).catch(() => {})
+ }
+ if (row.status === 'stop') {
+ this.$confirm('确定运行定时任务?', '提示', {
+ confirmButtonText: '确定',
+ cancelButtonText: '取消',
+ type: 'warning'
+ }).then(() => {
+ this.$store.dispatch('schedule/runSchedule', row._id)
+ .then((resp) => {
+ this.$store.dispatch('schedule/getScheduleList')
+ })
+ }).catch(() => {})
+ }
},
onCrontabFill (value) {
value = value.replace(/[?]/g, '*')