updated frontend to adapt changes of golang version

This commit is contained in:
Marvin Zhang
2019-07-22 12:32:36 +08:00
parent 67c299e5d9
commit c6bd35bd02
11 changed files with 44 additions and 25 deletions

2
.gitignore vendored
View File

@@ -16,8 +16,6 @@ dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/

View File

@@ -56,7 +56,7 @@ export default {
this.$st.sendEv('爬虫详情-环境', '删除')
},
save () {
this.$store.dispatch('spider/updateSpiderEnvs')
this.$store.dispatch('spider/editSpider')
.then(() => {
this.$message.success(this.$t('Spider info has been saved successfully'))
})

View File

@@ -66,7 +66,7 @@ export default {
onRestart () {
},
onStop () {
this.$store.dispatch('task/stopTask', this.$route.params.id)
this.$store.dispatch('task/cancelTask', this.$route.params.id)
.then(() => {
this.$message.success(`Task "${this.$route.params.id}" has been sent signal to stop`)
})

View File

@@ -5,7 +5,7 @@
:header-cell-style="{background:'rgb(48, 65, 86)',color:'white'}"
border>
<template v-for="col in columns">
<el-table-column :key="col" :label="col" :property="col" align="center">
<el-table-column :key="col" :label="col" :property="col" min-width="120">
</el-table-column>
</template>
</el-table>

View File

@@ -75,6 +75,7 @@ export default {
'Node MAC': '节点MAC',
'Node Port': '节点端口',
'Description': '描述',
'All Nodes': '所有节点',
// 节点列表
'IP': 'IP地址',

View File

@@ -110,9 +110,9 @@ const actions = {
return request.get(`/spiders/${id}/tasks`)
.then(response => {
commit('task/SET_TASK_LIST',
response.data.data.map(d => {
response.data.data ? response.data.data.map(d => {
return d
}).sort((a, b) => a.create_ts < b.create_ts ? 1 : -1),
}).sort((a, b) => a.create_ts < b.create_ts ? 1 : -1) : [],
{ root: true })
})
},

View File

@@ -24,7 +24,7 @@ const state = {
const getters = {
taskResultsColumns (state) {
if (!state.taskResultsData.length) {
if (!state.taskResultsData || !state.taskResultsData.length) {
return []
}
const keys = []
@@ -80,7 +80,6 @@ const actions = {
.then(response => {
let data = response.data.data
commit('SET_TASK_FORM', data)
console.log(data)
dispatch('spider/getSpiderData', data.spider_id, { root: true })
dispatch('node/getNodeData', data.node_id, { root: true })
})
@@ -103,13 +102,8 @@ const actions = {
dispatch('getTaskList')
})
},
stopTask ({ state, dispatch }, id) {
return request.post(`/tasks/${id}/stop`)
.then(() => {
dispatch('getTaskList')
})
},
getTaskLog ({ state, commit }, id) {
commit('SET_TASK_LOG', '')
return request.get(`/tasks/${id}/log`)
.then(response => {
commit('SET_TASK_LOG', response.data.data)
@@ -125,6 +119,12 @@ const actions = {
// commit('SET_TASK_RESULTS_COLUMNS', response.data.fields)
commit('SET_TASK_RESULTS_TOTAL_COUNT', response.data.total)
})
},
cancelTask ({ state, dispatch }, id) {
return request.post(`/tasks/${id}/cancel`)
.then(() => {
dispatch('getTaskData')
})
}
}

View File

@@ -104,6 +104,9 @@
:sortable="col.sortable"
:align="col.align"
:width="col.width">
<template slot-scope="scope">
{{$t(scope.row[col.name])}}
</template>
</el-table-column>
</template>
<el-table-column :label="$t('Action')" align="left" width="250" fixed="right">

View File

@@ -179,6 +179,16 @@
<el-input v-model="scope.row[col.name]"></el-input>
</template>
</el-table-column>
<el-table-column v-else-if="col.name.match(/_ts$/)"
:key="col.name"
:label="$t(col.label)"
:sortable="col.sortable"
:align="col.align"
:width="col.width">
<template slot-scope="scope">
{{getTime(scope.row[col.name])}}
</template>
</el-table-column>
<el-table-column v-else
:key="col.name"
:property="col.name"
@@ -188,7 +198,7 @@
:width="col.width">
</el-table-column>
</template>
<el-table-column :label="$t('Action')" align="left" width="150" fixed="right">
<el-table-column :label="$t('Action')" align="left" width="auto" fixed="right">
<template slot-scope="scope">
<el-tooltip :content="$t('View')" placement="top">
<el-button type="primary" icon="el-icon-search" size="mini" @click="onView(scope.row)"></el-button>
@@ -223,6 +233,7 @@
import {
mapState
} from 'vuex'
import dayjs from 'dayjs'
export default {
name: 'SpiderList',
@@ -249,9 +260,9 @@ export default {
{ name: 'type', label: 'Spider Type', width: '120' },
// { name: 'cmd', label: 'Command Line', width: '200' },
// { name: 'lang', label: 'Language', width: '120', sortable: true },
{ name: 'task_ts', label: 'Last Run', width: '160' },
{ name: 'last_7d_tasks', label: 'Last 7-Day Tasks', width: '80' },
{ name: 'last_5_errors', label: 'Last 5-Run Errors', width: '80' }
{ name: 'last_run_ts', label: 'Last Run', width: '160' }
// { name: 'last_7d_tasks', label: 'Last 7-Day Tasks', width: '80' },
// { name: 'last_5_errors', label: 'Last 5-Run Errors', width: '80' }
],
spiderFormRules: {
name: [{ required: true, message: 'Required Field', trigger: 'change' }]
@@ -474,6 +485,10 @@ export default {
// close popup
this.addCustomizedDialogVisible = false
},
getTime (str) {
if (!str || str.match('^0001')) return 'NA'
return dayjs(str).format('YYYY-MM-DD HH:mm:ss')
}
},
created () {

View File

@@ -104,9 +104,11 @@ export default {
this.$store.dispatch('task/getTaskLog', this.$route.params.id)
this.$store.dispatch('task/getTaskResults', this.$route.params.id)
this.handle = setInterval(() => {
this.$store.dispatch('task/getTaskLog', this.$route.params.id)
}, 5000)
if (['running'].includes(this.taskForm.status)) {
this.handle = setInterval(() => {
this.$store.dispatch('task/getTaskLog', this.$route.params.id)
}, 5000)
}
},
destroyed () {
clearInterval(this.handle)

View File

@@ -8,9 +8,9 @@ import os
from pymongo import MongoClient
MONGO_HOST = os.environ['MONGO_HOST']
MONGO_PORT = int(os.environ['MONGO_PORT'])
MONGO_DB = os.environ['MONGO_DB']
MONGO_HOST = os.environ.get('MONGO_HOST') or 'localhost'
MONGO_PORT = int(os.environ.get('MONGO_PORT') or '27017')
MONGO_DB = os.environ.get('MONGO_DB') or 'crawlab_test'
class MongoPipeline(object):