diff --git a/src/plugin/error/index.js b/src/plugin/error/index.js index f07eb7a0..2271b9bc 100644 --- a/src/plugin/error/index.js +++ b/src/plugin/error/index.js @@ -3,14 +3,16 @@ import util from '@/libs/util' export default { install (Vue, options) { - Vue.config.errorHandler = function (err, instance, info) { + Vue.config.errorHandler = function (error, instance, info) { Vue.nextTick(() => { - // 添加 log - store.dispatch('d2admin/log/add', { + // store 追加 log + store.dispatch('d2admin/log/push', { + message: `${info}: ${error.message}`, type: 'error', - err, - instance, - info + meta: { + error, + instance + } }) // 只在开发模式下打印 log if (process.env.NODE_ENV === 'development') { @@ -20,7 +22,7 @@ export default { util.log.danger('>>>>>> Vue 实例 >>>>>>') console.log(instance) util.log.danger('>>>>>> Error >>>>>>') - console.log(err) + console.log(error) } }) } diff --git a/src/plugin/log/index.js b/src/plugin/log/index.js index 182a1456..05e27544 100644 --- a/src/plugin/log/index.js +++ b/src/plugin/log/index.js @@ -12,12 +12,12 @@ export default { // 赋值给 message 字段 // 为了方便使用 // eg: this.$log.push('foo text') - store.dispatch('d2admin/log/add', { + store.dispatch('d2admin/log/push', { message: data }) } else if (typeof data === 'object') { // 如果传递来的数据是对象 - store.dispatch('d2admin/log/add', data) + store.dispatch('d2admin/log/push', data) } } } diff --git a/src/store/modules/d2admin/modules/log.js b/src/store/modules/d2admin/modules/log.js index 57b78652..1e4a3d8a 100644 --- a/src/store/modules/d2admin/modules/log.js +++ b/src/store/modules/d2admin/modules/log.js @@ -11,7 +11,7 @@ export default { // - type 非必须 类型 success | warning | info | error // - time 必须 日志记录时间 // - meta 非必须 其它携带信息 - list: [] + log: [] }, getters: { /** @@ -19,14 +19,14 @@ export default { * @param {*} state vuex state */ length (state) { - return state.list.length + return state.log.length }, /** * @description 返回现存 log (error) 的条数 * @param {*} state vuex state */ lengthError (state) { - return state.list.filter(l => l.type === 'error').length + return state.log.filter(l => l.type === 'error').length } }, actions: { @@ -36,8 +36,8 @@ export default { * @param {String} param type {String} 类型 * @param {Object} param meta {Object} 附带的信息 */ - add ({ rootState, commit }, { message, type, meta }) { - commit('add', { + push ({ rootState, commit }, { message, type, meta }) { + commit('push', { message, type, time: dayjs().format('YYYY-MM-DD HH:mm:ss'), @@ -62,8 +62,8 @@ export default { * @param {Object} state vuex state * @param {Object} log data */ - add (state, log) { - state.list.push(log) + push (state, log) { + state.log.push(log) }, /** * @description 清空日志 @@ -71,7 +71,7 @@ export default { */ clean (state) { // store 赋值 - state.list = [] + state.log = [] } } } diff --git a/src/views/system/log/index.vue b/src/views/system/log/index.vue index 2600ef21..ac302985 100644 --- a/src/views/system/log/index.vue +++ b/src/views/system/log/index.vue @@ -7,13 +7,16 @@ :loading="uploading" @click="handleUpload"> - Upload {{list.length}} log data + Upload {{log.length}} log data
-

- {{log.time}} - {{log.message}} +

+ {{logItem.time}} + {{logItem.message}}

@@ -29,7 +32,7 @@ export default { }, computed: { ...mapState('d2admin/log', [ - 'list' + 'log' ]) }, methods: { @@ -38,7 +41,7 @@ export default { this.$notify({ type: 'info', title: '日志上传', - message: `开始上传${this.list.length}条日志` + message: `开始上传${this.log.length}条日志` }) setTimeout(() => { this.uploading = false