diff --git a/src/plugin/log/index.js b/src/plugin/log/index.js index e37bfd6d..46f581fe 100644 --- a/src/plugin/log/index.js +++ b/src/plugin/log/index.js @@ -6,16 +6,9 @@ export default { // 快速打印 log Vue.prototype.$log = util.log // 快速记录日志 - Vue.prototype.$logAdd = function (info, show = true) { + Vue.prototype.$logAdd = function (data) { // store 赋值 - store.dispatch('d2admin/log/add', { - type: 'log', - info - }) - // 显示在控制台 - if (show && process.env.NODE_ENV === 'development') { - util.log.default(info) - } + store.dispatch('d2admin/log/add', data) } } } diff --git a/src/store/modules/d2admin/modules/log.js b/src/store/modules/d2admin/modules/log.js index 22f327ea..8f0a2f84 100644 --- a/src/store/modules/d2admin/modules/log.js +++ b/src/store/modules/d2admin/modules/log.js @@ -1,11 +1,16 @@ import dayjs from 'dayjs' -import { get, toString } from 'lodash' +import { get } from 'lodash' import util from '@/libs/util.js' export default { namespaced: true, state: { // 错误日志 + // + 日志条目的属性 + // - message 必须 日志信息 + // - time 必须 日志记录时间 + // - type 非必须 类型 success | warning | info | error + // - meta 非必须 其它携带信息 list: [] }, getters: { @@ -32,36 +37,35 @@ export default { * @param {Object} param instance {Object} vue 实例 * @param {Object} param info {String} 信息 */ - add ({ state, rootState }, { type, err, instance, info }) { - // store 赋值 - state.list.push(Object.assign({ - // 记录类型 "log" or "error" - type: 'log', - // 信息 - info: '', - // 错误对象 - err: '', - // vue 实例 - instance: '', - // 当前用户信息 - user: rootState.d2admin.user.info, - // 当前用户的 uuid - uuid: util.cookies.get('uuid'), - // 当前的 token - token: util.cookies.get('token'), - // 当前地址 - url: get(window, 'location.href', ''), - // 当前时间 - time: dayjs().format('YYYY-M-D HH:mm:ss') - }, { + add ({ rootState, commit }, { message, type, meta }) { + commit('add', { + message, + time: dayjs().format('YYYY-MM-DD HH:mm:ss'), type, - err, - instance, - info: toString(info) - })) + meta: { + // 当前用户信息 + user: rootState.d2admin.user.info, + // 当前用户的 uuid + uuid: util.cookies.get('uuid'), + // 当前的 token + token: util.cookies.get('token'), + // 当前地址 + url: get(window, 'location.href', ''), + // 用户设置 + ...meta + } + }) } }, mutations: { + /** + * @description 添加日志 + * @param {Object} state vuex state + * @param {Object} log data + */ + add (state, log) { + state.list.push(log) + }, /** * @description 清空日志 * @param {Object} state vuex state diff --git a/src/views/demo/playground/log/log/index.vue b/src/views/demo/playground/log/log/index.vue index 66dca3d8..4153d5dd 100644 --- a/src/views/demo/playground/log/log/index.vue +++ b/src/views/demo/playground/log/log/index.vue @@ -21,7 +21,9 @@ export default { }, methods: { handleAdd () { - this.$logAdd(this.text) + this.$logAdd({ + message: this.text + }) } } }