diff --git a/package.json b/package.json index c9a64425..2701d109 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "lodash.get": "^4.4.2", "lodash.set": "^4.3.2", "lodash.sortby": "^4.7.0", + "lodash.tostring": "^4.1.4", "lodash.uniqueid": "^4.0.1", "lowdb": "^1.0.0", "marked": "^0.3.9", diff --git a/src/plugin/error/index.js b/src/plugin/error/index.js index 7742b380..fd14e375 100644 --- a/src/plugin/error/index.js +++ b/src/plugin/error/index.js @@ -5,6 +5,7 @@ export default { install (Vue, options) { Vue.config.errorHandler = function (err, vm, info) { Vue.nextTick(() => { + // 添加 log store.dispatch('d2admin/log/add', { type: 'error', err, diff --git a/src/plugin/log/index.js b/src/plugin/log/index.js index d5708868..fd34e36c 100644 --- a/src/plugin/log/index.js +++ b/src/plugin/log/index.js @@ -6,11 +6,16 @@ export default { // 快速打印 log Vue.prototype.$log = util.log // 快速记录日志 - Vue.prototype.$logAdd = function (info) { + Vue.prototype.$logAdd = function (info, show = true) { + // store 赋值 store.dispatch('d2admin/log/add', { type: 'log', info }) + // 显示在控制台 + if (show && process.env.NODE_ENV === 'development') { + console.log(info) + } } } } diff --git a/src/store/modules/d2admin/modules/log.js b/src/store/modules/d2admin/modules/log.js index 8f265fe8..8ec421ab 100644 --- a/src/store/modules/d2admin/modules/log.js +++ b/src/store/modules/d2admin/modules/log.js @@ -1,5 +1,6 @@ import dayjs from 'dayjs' import get from 'lodash.get' +import toString from 'lodash.tostring' import util from '@/libs/util.js' export default { @@ -68,7 +69,7 @@ export default { type, err, vm, - info + info: toString(info) })) } }