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> - + @@ -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, '*')