Skip to content

Commit

Permalink
完善错误日志收集
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Oct 11, 2018
1 parent b7dd9df commit c75381a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
8 changes: 6 additions & 2 deletions src/store/module/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,15 @@ export default {
}
},
actions: {
addErrorLog ({ commit }, info) {
addErrorLog ({ commit, rootState }, info) {
if (!window.location.href.includes('error_logger_page')) commit('setHasReadErrorLoggerStatus', false)
const { user: { token, userId, userName } } = rootState
let data = {
...info,
time: Date.parse(new Date())
time: Date.parse(new Date()),
token,
userId,
userName
}
saveErrorLogger(info).then(() => {
commit('addError', data)
Expand Down
2 changes: 1 addition & 1 deletion src/store/module/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default {
getUserInfo(state.token).then(res => {
const data = res.data
commit('setAvator', data.avator)
commit('setUserName', data.user_name)
commit('setUserName', data.name)
commit('setUserId', data.user_id)
commit('setAccess', data.access)
commit('setHasGetInfo', true)
Expand Down
8 changes: 3 additions & 5 deletions src/view/error-store/error-store.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
</Card>
<Card style="margin-top: 20px;">
<Row>
<i-col span="4">
<Button @click="click">点击测试触发程序错误</Button>
</i-col>
<i-col span="4">
<Button @click="ajaxClick">点击测试触发ajax接口请求错误</Button>
<i-col span="8">
<Button @click="click" style="display: block">点击测试触发程序错误</Button>
<Button @click="ajaxClick" style="margin-top:10px;">点击测试触发ajax接口请求错误</Button>
</i-col>
<i-col span="16">
ajax接口请求是请求easy-mock的一个不存在接口,所以服务端会报404错误,错误收集机制会收集这个错误,测试的时候有一定网络延迟,所以点击按钮之后稍等一会才会收集到错误。
Expand Down
11 changes: 9 additions & 2 deletions src/view/single-page/error-logger.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<template>
<div>
<Table :columns="columns" :data="errorList"></Table>
<Button @click="exportData" type="primary" style="margin: 0 10px 10px 0;">导出日志记录</Button>
<b>注:这里只会显示成功保存到服务端的错误日志,而且页面错误日志不会在浏览器持久化存储,刷新页面即会丢失</b>
<Table ref="table" :columns="columns" :data="errorList"></Table>
</div>
</template>

Expand Down Expand Up @@ -68,7 +70,12 @@ export default {
methods: {
...mapMutations([
'setHasReadErrorLoggerStatus'
])
]),
exportData () {
this.$refs.table.exportCsv({
filename: '错误日志.csv'
})
}
},
activated () {
this.setHasReadErrorLoggerStatus()
Expand Down

0 comments on commit c75381a

Please sign in to comment.