Revert "Revert "V0.4.0 imporve error response""

This reverts commit 9744f45e86.
This commit is contained in:
yaziming
2019-09-04 20:41:37 +08:00
parent bb4ec17125
commit 6dc687192e
51 changed files with 1373 additions and 416 deletions

View File

@@ -6,6 +6,7 @@
"serve": "vue-cli-service serve --ip=0.0.0.0",
"serve:prod": "vue-cli-service serve --mode=production --ip=0.0.0.0",
"config": "vue ui",
"build:dev": "vue-cli-service build --mode development",
"build:prod": "vue-cli-service build --mode production",
"lint": "vue-cli-service lint",
"test:unit": "vue-cli-service test:unit"

View File

@@ -3,28 +3,51 @@ import router from '../router'
let baseUrl = process.env.VUE_APP_BASE_URL ? process.env.VUE_APP_BASE_URL : 'http://localhost:8000'
const request = (method, path, params, data) => {
return new Promise((resolve, reject) => {
const request = async (method, path, params, data, others = {}) => {
try {
const url = baseUrl + path
const headers = {
'Authorization': window.localStorage.getItem('token')
}
axios({
const response = await axios({
method,
url,
params,
data,
headers
headers,
...others
})
.then(resolve)
.catch(error => {
console.log(error)
if (error.response.status === 401) {
router.push('/login')
}
reject(error)
})
})
// console.log(response)
return response
} catch (e) {
if (e.response.status === 401 && router.currentRoute.path !== '/login') {
router.push('/login')
}
await Promise.reject(e)
}
// return new Promise((resolve, reject) => {
// const url = baseUrl + path
// const headers = {
// 'Authorization': window.localStorage.getItem('token')
// }
// axios({
// method,
// url,
// params,
// data,
// headers,
// ...others
// })
// .then(resolve)
// .catch(error => {
// console.log(error)
// if (error.response.status === 401) {
// router.push('/login')
// }
// reject(error)
// })
// })
}
const get = (path, params) => {

View File

@@ -22,7 +22,7 @@
</el-form>
</el-row>
<el-row class="button-container" v-if="!isView">
<el-button type="success" @click="onSave">{{$t('Save')}}</el-button>
<el-button size="small" type="success" @click="onSave">{{$t('Save')}}</el-button>
</el-row>
</div>
</template>

View File

@@ -44,6 +44,9 @@
<el-option value="customized" :label="$t('Customized')"></el-option>
</el-select>
</el-form-item>
<el-form-item :label="$t('Remark')">
<el-input v-model="spiderForm.remark"/>
</el-form-item>
</el-form>
</el-row>
<el-row class="button-container" v-if="!isView">

View File

@@ -86,15 +86,15 @@ export default {
return dayjs(str).format('YYYY-MM-DD HH:mm:ss')
},
getWaitDuration (row) {
if (row.start_ts.match('^0001')) return 'NA'
if (!row.start_ts || row.start_ts.match('^0001')) return 'NA'
return dayjs(row.start_ts).diff(row.create_ts, 'second')
},
getRuntimeDuration (row) {
if (row.finish_ts.match('^0001')) return 'NA'
if (!row.finish_ts || row.finish_ts.match('^0001')) return 'NA'
return dayjs(row.finish_ts).diff(row.start_ts, 'second')
},
getTotalDuration (row) {
if (row.finish_ts.match('^0001')) return 'NA'
if (!row.finish_ts || row.finish_ts.match('^0001')) return 'NA'
return dayjs(row.finish_ts).diff(row.create_ts, 'second')
}
}

View File

@@ -154,6 +154,8 @@ export default {
'Last Run': '上次运行',
'Action': '操作',
'No command line': '没有执行命令',
'Last Status': '上次运行状态',
'Remark': '备注',
// 任务
'Task Info': '任务信息',
@@ -245,7 +247,7 @@ export default {
'username already exists': '用户名已存在',
'Deleted successfully': '成功删除',
'Saved successfully': '成功保存',
'English': 'English',
// 登录
'Sign in': '登录',
'Sign-in': '登录',
@@ -264,5 +266,20 @@ export default {
'admin': '管理用户',
'Role': '角色',
'Edit User': '更改用户',
'Users': '用户'
'Users': '用户',
tagsView: {
closeOthers: '关闭其他',
close: '关闭',
refresh: '刷新',
closeAll: '关闭所有'
},
nodeList: {
type: '节点类型'
},
schedules: {
cron: 'Cron',
add_cron: '生成Cron',
// Cron Format: [second] [minute] [hour] [day of month] [month] [day of week]
cron_format: 'Cron 格式: [秒] [分] [小时] [日] [月] [周]'
}
}

View File

@@ -46,7 +46,6 @@ export const constantRouterMap = [
]
},
{
name: 'Node',
path: '/nodes',
component: Layout,
meta: {
@@ -76,7 +75,6 @@ export const constantRouterMap = [
]
},
{
name: 'Spider',
path: '/spiders',
component: Layout,
meta: {
@@ -106,7 +104,6 @@ export const constantRouterMap = [
]
},
{
name: 'Task',
path: '/tasks',
component: Layout,
meta: {
@@ -136,7 +133,6 @@ export const constantRouterMap = [
]
},
{
name: 'Schedule',
path: '/schedules',
component: Layout,
meta: {
@@ -157,7 +153,6 @@ export const constantRouterMap = [
]
},
{
name: 'Site',
path: '/sites',
component: Layout,
hidden: true,
@@ -178,7 +173,6 @@ export const constantRouterMap = [
]
},
{
name: 'User',
path: '/users',
component: Layout,
meta: {

View File

@@ -25,15 +25,7 @@ const mutations = {
const { id, systemInfo } = payload
for (let i = 0; i < state.nodeList.length; i++) {
if (state.nodeList[i]._id === id) {
// Vue.set(state.nodeList[i], 'systemInfo', {})
state.nodeList[i].systemInfo = systemInfo
// for (const key in systemInfo) {
// if (systemInfo.hasOwnProperty(key)) {
// console.log(key)
// state.nodeList[i].systemInfo[key] = systemInfo[key]
// // Vue.set(state.nodeList[i].systemInfo, key, systemInfo[key])
// }
// }
break
}
}
@@ -76,10 +68,12 @@ const actions = {
getTaskList ({ state, commit }, id) {
return request.get(`/nodes/${id}/tasks`)
.then(response => {
commit('task/SET_TASK_LIST',
response.data.data.map(d => d)
.sort((a, b) => a.create_ts < b.create_ts ? 1 : -1),
{ root: true })
if (response.data.data) {
commit('task/SET_TASK_LIST',
response.data.data.map(d => d)
.sort((a, b) => a.create_ts < b.create_ts ? 1 : -1),
{ root: true })
}
})
},
getNodeSystemInfo ({ state, commit }, id) {

View File

@@ -120,6 +120,22 @@ const actions = {
commit('SET_TASK_RESULTS_TOTAL_COUNT', response.data.total)
})
},
async getTaskResultExcel ({ state, commit }, id) {
const { data } = await request.request('GET', '/tasks/' + id + '/results/download', {}, {
responseType: 'blob' // important
})
const downloadUrl = window.URL.createObjectURL(new Blob([data]))
const link = document.createElement('a')
link.href = downloadUrl
link.setAttribute('download', 'data.csv') // any other extension
document.body.appendChild(link)
link.click()
link.remove()
},
cancelTask ({ state, dispatch }, id) {
return request.post(`/tasks/${id}/cancel`)
.then(() => {

View File

@@ -32,6 +32,7 @@
<font-awesome-icon :icon="['far', 'question-circle']"/>
<span style="margin-left: 5px;">{{$t('Documentation')}}</span>
</a>
<el-dropdown-menu slot="dropdown"></el-dropdown-menu>
</el-dropdown>
</div>
</template>

View File

@@ -163,7 +163,7 @@ export default {
columns: [
{ name: 'name', label: 'Name', width: '220' },
{ name: 'ip', label: 'IP', width: '160' },
{ name: 'type', label: 'Type', width: '120' },
{ name: 'type', label: 'nodeList.type', width: '120' },
// { name: 'port', label: 'Port', width: '80' },
{ name: 'status', label: 'Status', width: '120' },
{ name: 'description', label: 'Description', width: 'auto' }

View File

@@ -38,21 +38,21 @@
</el-option>
</el-select>
</el-form-item>
<el-form-item :label="$t('Cron')" prop="cron" :rules="cronRules" required>
<el-form-item :label="$t('schedules.cron')" prop="cron" :rules="cronRules" required>
<template slot="label">
<el-tooltip :content="$t('Cron Format: [second] [minute] [hour] [day of month] [month] [day of week]')"
<el-tooltip :content="$t('schedules.cron_format')"
placement="top">
<span>
{{$t('Cron')}}
{{$t('schedules.cron')}}
<i class="fa fa-exclamation-circle"></i>
</span>
</el-tooltip>
</template>
<el-input style="width:calc(100% - 100px);padding-right:10px"
v-model="scheduleForm.cron"
:placeholder="$t('Cron')">
:placeholder="$t('schedules.cron')">
</el-input>
<el-button size="small" style="width:100px" type="primary" @click="onShowCronDialog">{{$t('生成Cron')}}</el-button>
<el-button size="small" style="width:100px" type="primary" @click="onShowCronDialog">{{$t('schedules.add_cron')}}</el-button>
</el-form-item>
<el-form-item :label="$t('Execute Command')" prop="params">
<el-input v-model="spider.cmd"
@@ -156,7 +156,7 @@ export default {
return {
columns: [
{ name: 'name', label: 'Name', width: '180' },
{ name: 'cron', label: 'Cron', width: '120' },
{ name: 'cron', label: 'schedules.cron', width: '120' },
{ name: 'node_name', label: 'Node', width: '150' },
{ name: 'spider_name', label: 'Spider', width: '150' },
{ name: 'description', label: 'Description', width: 'auto' }

View File

@@ -190,6 +190,14 @@
{{getTime(scope.row[col.name])}}
</template>
</el-table-column>
<el-table-column v-else-if="col.name === 'last_status'"
:key="col.name"
:label="$t(col.label)"
align="left" :width="col.width">
<template slot-scope="scope">
<status-tag :status="scope.row.last_status"/>
</template>
</el-table-column>
<el-table-column v-else
:key="col.name"
:property="col.name"
@@ -239,10 +247,14 @@ import {
} from 'vuex'
import dayjs from 'dayjs'
import CrawlConfirmDialog from '../../components/Common/CrawlConfirmDialog'
import StatusTag from '../../components/Status/StatusTag'
export default {
name: 'SpiderList',
components: { CrawlConfirmDialog },
components: {
CrawlConfirmDialog,
StatusTag
},
data () {
return {
pagination: {
@@ -263,14 +275,15 @@ export default {
},
// tableData,
columns: [
{ name: 'name', label: 'Name', width: '180', align: 'left' },
{ name: 'name', label: 'Name', width: '160', align: 'left' },
// { name: 'site_name', label: 'Site', width: '140', align: 'left' },
{ name: 'type', label: 'Spider Type', width: '120' },
// { name: 'cmd', label: 'Command Line', width: '200' },
// { name: 'lang', label: 'Language', width: '120', sortable: true },
{ name: 'last_run_ts', label: 'Last Run', width: '160' },
{ name: 'create_ts', label: 'Create Time', width: '160' },
{ name: 'update_ts', label: 'Update Time', width: '160' }
{ name: 'last_status', label: 'Last Status', width: '120' },
{ name: 'last_run_ts', label: 'Last Run', width: '140' },
{ name: 'create_ts', label: 'Create Time', width: '140' },
{ name: 'update_ts', label: 'Update Time', width: '140' },
{ name: 'remark', label: 'Remark', width: '140' }
// { name: 'last_7d_tasks', label: 'Last 7-Day Tasks', width: '80' },
// { name: 'last_5_errors', label: 'Last 5-Run Errors', width: '80' }
],

View File

@@ -95,16 +95,16 @@ export default {
this.$store.dispatch('task/getTaskResults', this.$route.params.id)
},
downloadCSV () {
window.location.href = this.$request.baseUrl + '/tasks/' + this.$route.params.id + '/results/download'
this.$store.dispatch('task/getTaskResultExcel', this.$route.params.id)
this.$st.sendEv('任务详情-结果', '下载CSV')
}
},
created () {
this.$store.dispatch('task/getTaskData', this.$route.params.id)
async created () {
await this.$store.dispatch('task/getTaskData', this.$route.params.id)
this.$store.dispatch('task/getTaskLog', this.$route.params.id)
this.$store.dispatch('task/getTaskResults', this.$route.params.id)
if (['running'].includes(this.taskForm.status)) {
if (this.taskForm && ['running'].includes(this.taskForm.status)) {
this.handle = setInterval(() => {
this.$store.dispatch('task/getTaskLog', this.$route.params.id)
}, 5000)

View File

@@ -45,7 +45,7 @@
:label="$t(col.label)"
:sortable="col.sortable"
:align="col.align"
:width="col.width">
>
<template slot-scope="scope">
<a href="javascript:" class="a-tag" @click="onClickSpider(scope.row)">{{scope.row[col.name]}}</a>
</template>
@@ -119,7 +119,7 @@
:width="col.width">
</el-table-column>
</template>
<el-table-column :label="$t('Action')" align="left" width="120" fixed="right">
<el-table-column :label="$t('Action')" align="left" 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>