refactor[errorLog]: save the logs in vuex
This commit is contained in:
parent
f9aaaa9091
commit
a68413cb8f
|
@ -1,15 +1,17 @@
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import errLog from '@/store/errorLog'
|
import store from './store'
|
||||||
|
|
||||||
// you can set only in production env show the error-log
|
// you can set only in production env show the error-log
|
||||||
// if (process.env.NODE_ENV === 'production') {
|
// if (process.env.NODE_ENV === 'production') {
|
||||||
Vue.config.errorHandler = function(err, vm, info) {
|
Vue.config.errorHandler = function(err, vm, info, a) {
|
||||||
errLog.pushLog({
|
Vue.nextTick(() => {
|
||||||
|
store.dispatch('addErrorLog', {
|
||||||
err,
|
err,
|
||||||
vm,
|
vm,
|
||||||
info,
|
info,
|
||||||
url: window.location.href
|
url: window.location.href
|
||||||
})
|
})
|
||||||
console.error(err, info)
|
console.error(err, info)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
// }
|
// }
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
const errLog = {
|
|
||||||
state: {
|
|
||||||
errLog: []
|
|
||||||
},
|
|
||||||
pushLog(log) {
|
|
||||||
this.state.errLog.unshift(log)
|
|
||||||
},
|
|
||||||
clearLog() {
|
|
||||||
this.state.errLog = []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default errLog
|
|
|
@ -11,6 +11,7 @@ const getters = {
|
||||||
roles: state => state.user.roles,
|
roles: state => state.user.roles,
|
||||||
setting: state => state.user.setting,
|
setting: state => state.user.setting,
|
||||||
permission_routers: state => state.permission.routers,
|
permission_routers: state => state.permission.routers,
|
||||||
addRouters: state => state.permission.addRouters
|
addRouters: state => state.permission.addRouters,
|
||||||
|
errorLogs: state => state.errorLog.logs
|
||||||
}
|
}
|
||||||
export default getters
|
export default getters
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import Vuex from 'vuex'
|
import Vuex from 'vuex'
|
||||||
import app from './modules/app'
|
import app from './modules/app'
|
||||||
|
import errorLog from './modules/errorLog'
|
||||||
import permission from './modules/permission'
|
import permission from './modules/permission'
|
||||||
import tagsView from './modules/tagsView'
|
import tagsView from './modules/tagsView'
|
||||||
import user from './modules/user'
|
import user from './modules/user'
|
||||||
|
@ -11,6 +12,7 @@ Vue.use(Vuex)
|
||||||
const store = new Vuex.Store({
|
const store = new Vuex.Store({
|
||||||
modules: {
|
modules: {
|
||||||
app,
|
app,
|
||||||
|
errorLog,
|
||||||
permission,
|
permission,
|
||||||
tagsView,
|
tagsView,
|
||||||
user
|
user
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
const errorLog = {
|
||||||
|
state: {
|
||||||
|
logs: []
|
||||||
|
},
|
||||||
|
mutations: {
|
||||||
|
ADD_ERROR_LOG: (state, log) => {
|
||||||
|
state.logs.push(log)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
addErrorLog({ commit }, log) {
|
||||||
|
commit('ADD_ERROR_LOG', log)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default errorLog
|
|
@ -5,8 +5,7 @@
|
||||||
<breadcrumb class="breadcrumb-container"></breadcrumb>
|
<breadcrumb class="breadcrumb-container"></breadcrumb>
|
||||||
|
|
||||||
<div class="right-menu">
|
<div class="right-menu">
|
||||||
|
<error-log v-if="errorLogs.length>0" class="errLog-container right-menu-item" :logsList="errorLogs"></error-log>
|
||||||
<error-log v-if="log.length>0" class="errLog-container right-menu-item" :logsList="log"></error-log>
|
|
||||||
|
|
||||||
<el-tooltip effect="dark" content="全屏" placement="bottom">
|
<el-tooltip effect="dark" content="全屏" placement="bottom">
|
||||||
<screenfull class="screenfull right-menu-item"></screenfull>
|
<screenfull class="screenfull right-menu-item"></screenfull>
|
||||||
|
@ -58,7 +57,6 @@ import Hamburger from '@/components/Hamburger'
|
||||||
import ThemePicker from '@/components/ThemePicker'
|
import ThemePicker from '@/components/ThemePicker'
|
||||||
import Screenfull from '@/components/Screenfull'
|
import Screenfull from '@/components/Screenfull'
|
||||||
import ErrorLog from '@/components/ErrorLog'
|
import ErrorLog from '@/components/ErrorLog'
|
||||||
import errLogStore from '@/store/errorLog'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
|
@ -68,17 +66,13 @@ export default {
|
||||||
ErrorLog,
|
ErrorLog,
|
||||||
Screenfull
|
Screenfull
|
||||||
},
|
},
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
log: errLogStore.state.errLog
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
computed: {
|
||||||
...mapGetters([
|
...mapGetters([
|
||||||
'sidebar',
|
'sidebar',
|
||||||
'name',
|
'name',
|
||||||
'avatar',
|
'avatar',
|
||||||
'language'
|
'language',
|
||||||
|
'errorLogs'
|
||||||
])
|
])
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
Loading…
Reference in New Issue