From 7c4ddd2824474832ea4ea3701d53a1136dab35a1 Mon Sep 17 00:00:00 2001 From: marvzhang Date: Thu, 13 Feb 2020 11:15:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=97=A5=E5=BF=97=EF=BC=8C?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E6=A0=87=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/InfoView/TaskInfoView.vue | 25 +- .../src/components/Overview/TaskOverview.vue | 2 +- .../src/components/ScrollView/LogItem.vue | 50 ++-- .../src/components/ScrollView/LogView.vue | 250 ++++++++++++++---- frontend/src/i18n/zh.js | 2 + frontend/src/store/modules/task.js | 31 +++ frontend/src/utils/index.js | 4 +- frontend/src/utils/log.js | 5 + frontend/src/views/task/TaskDetail.vue | 14 +- 9 files changed, 298 insertions(+), 85 deletions(-) create mode 100644 frontend/src/utils/log.js diff --git a/frontend/src/components/InfoView/TaskInfoView.vue b/frontend/src/components/InfoView/TaskInfoView.vue index 34318d84..d55945b0 100644 --- a/frontend/src/components/InfoView/TaskInfoView.vue +++ b/frontend/src/components/InfoView/TaskInfoView.vue @@ -11,6 +11,15 @@ + + + {{$t('Log with errors')}} + + @@ -28,7 +37,7 @@ - + @@ -37,7 +46,7 @@ - + @@ -59,7 +68,8 @@ diff --git a/frontend/src/i18n/zh.js b/frontend/src/i18n/zh.js index 2dcb46d2..5dbf2919 100644 --- a/frontend/src/i18n/zh.js +++ b/frontend/src/i18n/zh.js @@ -211,6 +211,8 @@ export default { 'Search Log': '搜索日志', 'Auto-Scroll': '自动滚动', 'Updating log...': '正在更新日志...', + 'Error Count': '错误数', + 'Log with errors': '日志错误', // 任务列表 'Node': '节点', diff --git a/frontend/src/store/modules/task.js b/frontend/src/store/modules/task.js index 95153be5..563fc907 100644 --- a/frontend/src/store/modules/task.js +++ b/frontend/src/store/modules/task.js @@ -1,4 +1,5 @@ import request from '../../api/request' +import utils from '../../utils' const state = { // TaskList @@ -6,6 +7,7 @@ const state = { taskListTotalCount: 0, taskForm: {}, taskLog: '', + currentLogIndex: 0, taskResultsData: [], taskResultsColumns: [], taskResultsTotalCount: 0, @@ -36,6 +38,32 @@ const getters = { } } return keys + }, + logData (state) { + const data = state.taskLog.split('\n') + .map((d, i) => { + return { + index: i + 1, + data: d, + active: state.currentLogIndex === i + 1 + } + }) + if (state.taskForm && state.taskForm.status === 'running') { + data.push({ + index: data.length + 1, + data: '###LOG_END###' + }) + data.push({ + index: data.length + 1, + data: '' + }) + } + return data + }, + errorLogData (state, getters) { + return getters.logData.filter(d => { + return d.data.match(utils.log.errorRegex) + }) } } @@ -49,6 +77,9 @@ const mutations = { SET_TASK_LOG (state, value) { state.taskLog = value }, + SET_CURRENT_LOG_INDEX (state, value) { + state.currentLogIndex = value + }, SET_TASK_RESULTS_DATA (state, value) { state.taskResultsData = value }, diff --git a/frontend/src/utils/index.js b/frontend/src/utils/index.js index ab33114f..9867c812 100644 --- a/frontend/src/utils/index.js +++ b/frontend/src/utils/index.js @@ -1,9 +1,11 @@ import stats from './stats' import encrypt from './encrypt' import tour from './tour' +import log from './log' export default { stats, encrypt, - tour + tour, + log } diff --git a/frontend/src/utils/log.js b/frontend/src/utils/log.js new file mode 100644 index 00000000..8b1ea0ab --- /dev/null +++ b/frontend/src/utils/log.js @@ -0,0 +1,5 @@ +const regexToken = ' :,.' + +export default { + errorRegex: new RegExp(`(?:[${regexToken}]|^)((?:error|exception|traceback)s?)(?:[${regexToken}]|$)`, 'gi') +} diff --git a/frontend/src/views/task/TaskDetail.vue b/frontend/src/views/task/TaskDetail.vue index d5d1fd04..8af32049 100644 --- a/frontend/src/views/task/TaskDetail.vue +++ b/frontend/src/views/task/TaskDetail.vue @@ -12,10 +12,10 @@ - + - +
@@ -55,7 +55,6 @@ export default { return { activeTabName: 'overview', handle: undefined, - taskLog: '', // tutorial tourSteps: [ @@ -137,7 +136,8 @@ export default { ...mapState('task', [ 'taskForm', 'taskResultsData', - 'taskResultsTotalCount' + 'taskResultsTotalCount', + 'taskLog' ]), ...mapGetters('task', [ 'taskResultsColumns' @@ -186,11 +186,7 @@ export default { this.$st.sendEv('任务详情', '结果', '下载CSV') }, getTaskLog () { - if (this.$route.params.id) { - request.get(`/tasks/${this.$route.params.id}/log`).then(response => { - this.taskLog = response.data.data - }) - } + this.$store.dispatch('task/getTaskLog', this.$route.params.id) } }, created () {