diff --git a/frontend/src/i18n/zh.js b/frontend/src/i18n/zh.js
index 852e79be..ecb0bd82 100644
--- a/frontend/src/i18n/zh.js
+++ b/frontend/src/i18n/zh.js
@@ -223,6 +223,8 @@ export default {
'error': '错误',
'Not Found Node': '节点配置错误',
'Not Found Spider': '爬虫配置错误',
+ '[minute] [hour] [day] [month] [day of week]': '[分] [时] [天] [月] [星期几]',
+ 'Enable/Disable': '启用/禁用',
// 网站
'Site': '网站',
@@ -313,6 +315,13 @@ export default {
'Installing language failed': '安装语言失败',
'You have successfully installed a language: ': '您已成功安装语言: ',
'The language installation is unsuccessful: ': '安装语言失败: ',
+ 'Enabling the schedule successful': '启用定时任务成功',
+ 'Disabling the schedule successful': '禁用定时任务成功',
+ 'Enabling the schedule unsuccessful': '启用定时任务失败',
+ 'Disabling the schedule unsuccessful': '禁用定时任务失败',
+ 'The schedule has been removed': '已删除定时任务',
+ 'The schedule has been added': '已添加定时任务',
+ 'The schedule has been saved': '已保存定时任务',
// 登录
'Sign in': '登录',
diff --git a/frontend/src/store/modules/schedule.js b/frontend/src/store/modules/schedule.js
index e71d5f03..9fde4e84 100644
--- a/frontend/src/store/modules/schedule.js
+++ b/frontend/src/store/modules/schedule.js
@@ -21,7 +21,12 @@ const actions = {
getScheduleList ({ state, commit }) {
request.get('/schedules')
.then(response => {
- commit('SET_SCHEDULE_LIST', response.data.data)
+ commit('SET_SCHEDULE_LIST', response.data.data.map(d => {
+ const arr = d.cron.split(' ')
+ arr.splice(0, 1)
+ d.cron = arr.join(' ')
+ return d
+ }))
})
},
addSchedule ({ state }) {
@@ -33,11 +38,11 @@ const actions = {
removeSchedule ({ state }, id) {
request.delete(`/schedules/${id}`)
},
- stopSchedule ({ state, dispatch }, id) {
- return request.post(`/schedules/${id}/stop`)
+ enableSchedule ({ state, dispatch }, id) {
+ return request.post(`/schedules/${id}/enable`)
},
- runSchedule ({ state, dispatch }, id) {
- return request.post(`/schedules/${id}/run`)
+ disableSchedule ({ state, dispatch }, id) {
+ return request.post(`/schedules/${id}/disable`)
}
}
diff --git a/frontend/src/views/schedule/ScheduleList.vue b/frontend/src/views/schedule/ScheduleList.vue
index 0cfbb6d2..ab9e7636 100644
--- a/frontend/src/views/schedule/ScheduleList.vue
+++ b/frontend/src/views/schedule/ScheduleList.vue
@@ -67,8 +67,10 @@
-
+
@@ -137,13 +139,28 @@
-
+
{{$t('All Nodes')}}
{{$t('Selected Nodes')}}
{{$t('Random')}}
+
+
+ {{scope.row.nodes.map(d => d.name).join(', ')}}
+
+
+
+
+
+
+
-
+
@@ -188,14 +205,15 @@ export default {
data () {
return {
columns: [
- { name: 'name', label: 'Name', width: '180' },
- { name: 'cron', label: 'Cron', width: '120' },
- { name: 'run_type', label: 'Run Type', width: '150' },
- { 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: 'status', label: 'Status', width: 'auto' }
+ { name: 'name', label: 'Name', width: '150px' },
+ { name: 'cron', label: 'Cron', width: '120px' },
+ { name: 'run_type', label: 'Run Type', width: '120px' },
+ { name: 'node_names', label: 'Node', width: '150px' },
+ { name: 'spider_name', label: 'Spider', width: '150px' },
+ { name: 'param', label: 'Parameters', width: '150px' },
+ { name: 'description', label: 'Description', width: '200px' },
+ { name: 'enable', label: 'Enable/Disable', width: '120px' }
+ // { name: 'status', label: 'Status', width: '100px' }
],
isEdit: false,
dialogTitle: '',
@@ -242,23 +260,27 @@ export default {
onAddSubmit () {
this.$refs.scheduleForm.validate(res => {
if (res) {
+ const form = JSON.parse(JSON.stringify(this.scheduleForm))
+ form.cron = '0 ' + this.scheduleForm.cron
if (this.isEdit) {
- request.post(`/schedules/${this.scheduleForm._id}`, this.scheduleForm).then(response => {
+ request.post(`/schedules/${this.scheduleForm._id}`, form).then(response => {
if (response.data.error) {
this.$message.error(response.data.error)
return
}
this.dialogVisible = false
this.$store.dispatch('schedule/getScheduleList')
+ this.$message.success(this.$t('The schedule has been saved'))
})
} else {
- request.put('/schedules', this.scheduleForm).then(response => {
+ request.put('/schedules', form).then(response => {
if (response.data.error) {
this.$message.error(response.data.error)
return
}
this.dialogVisible = false
this.$store.dispatch('schedule/getScheduleList')
+ this.$message.success(this.$t('The schedule has been added'))
})
}
}
@@ -283,57 +305,13 @@ export default {
.then(() => {
setTimeout(() => {
this.$store.dispatch('schedule/getScheduleList')
- this.$message.success(`Schedule "${row.name}" has been removed`)
+ this.$message.success(this.$t('The schedule has been removed'))
}, 100)
})
}).catch(() => {
})
this.$st.sendEv('定时任务', '删除定时任务')
},
- onCrawl (row) {
- // 停止定时任务
- if (!row.status || row.status === 'running') {
- this.$confirm(this.$t('Are you sure to delete the schedule task?'), this.$t('Notification'), {
- confirmButtonText: this.$t('Confirm'),
- cancelButtonText: this.$t('Cancel'),
- type: 'warning'
- }).then(() => {
- this.$store.dispatch('schedule/stopSchedule', row._id)
- .then((resp) => {
- 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(this.$t('Are you sure to delete the schedule task?'), this.$t('Notification'), {
- confirmButtonText: this.$t('Confirm'),
- cancelButtonText: this.$t('Cancel'),
- type: 'warning'
- }).then(() => {
- this.$store.dispatch('schedule/runSchedule', row._id)
- .then((resp) => {
- if (resp.data.status === 'ok') {
- this.$store.dispatch('schedule/getScheduleList')
- return
- }
- this.$message({
- type: 'error',
- message: resp.data.error
- })
- })
- }).catch(() => {
- })
- }
- },
isDisabledSpider (spider) {
if (spider.type === 'customized') {
return !spider.cmd
@@ -349,6 +327,19 @@ export default {
} else if (row.status === 'error') {
return 'Start'
}
+ },
+ async onEnabledChange (row) {
+ let res
+ if (row.enabled) {
+ res = await this.$store.dispatch('schedule/enableSchedule', row._id)
+ } else {
+ res = await this.$store.dispatch('schedule/disableSchedule', row._id)
+ }
+ if (!res || res.data.error) {
+ this.$message.error(this.$t(`${row.enabled ? 'Enabling' : 'Disabling'} the schedule unsuccessful`))
+ } else {
+ this.$message.success(this.$t(`${row.enabled ? 'Enabling' : 'Disabling'} the schedule successful`))
+ }
}
},
created () {
diff --git a/frontend/src/views/task/TaskList.vue b/frontend/src/views/task/TaskList.vue
index 6cfab747..543a1ac1 100644
--- a/frontend/src/views/task/TaskList.vue
+++ b/frontend/src/views/task/TaskList.vue
@@ -345,9 +345,9 @@ export default {
this.$store.dispatch('node/getNodeList')
},
mounted () {
- // this.handle = setInterval(() => {
- // this.$store.dispatch('task/getTaskList')
- // }, 5000)
+ this.handle = setInterval(() => {
+ this.$store.dispatch('task/getTaskList')
+ }, 5000)
},
destroyed () {
clearInterval(this.handle)