log 模块优化

Former-commit-id: 46dd58602044e544021e6dac3750f8063dd8f630 [formerly 46dd58602044e544021e6dac3750f8063dd8f630 [formerly 46dd58602044e544021e6dac3750f8063dd8f630 [formerly 46dd58602044e544021e6dac3750f8063dd8f630 [formerly 02da1cf89a30a31b7ada6753276bf8d7db49c7c2 [formerly 8732cbe9dc0937266a143b0cb94061cc6458c22f]]]]]
Former-commit-id: 9bb0587d2bf29ae030c34e973b2968898c409efa
Former-commit-id: 4573b85856d998f1e0e1fc745aa84c116374b757
Former-commit-id: 499c55cf76d4187c091b3780fc492b863b20160a [formerly 522496547f9dcaeb7cceff1c71ca90d19fa853ce]
Former-commit-id: 76cf33d5c5abb90f90715e0678987996286b8e7a
Former-commit-id: c5601273186197e17715589beec00fa4b0d93c8f
Former-commit-id: 2057049057822377d125e273d901e9e0b01d3d99
Former-commit-id: 4a45cde995408c9e2de7028e9335c72a57f93530
Former-commit-id: b8a74a0c8dca434b6dd43606d97cebb396bc36c0
This commit is contained in:
liyang
2019-03-21 22:42:03 +08:00
parent f0d9674ed2
commit 20c30520f0
4 changed files with 28 additions and 23 deletions

View File

@@ -3,14 +3,16 @@ import util from '@/libs/util'
export default { export default {
install (Vue, options) { install (Vue, options) {
Vue.config.errorHandler = function (err, instance, info) { Vue.config.errorHandler = function (error, instance, info) {
Vue.nextTick(() => { Vue.nextTick(() => {
// 加 log // store 追加 log
store.dispatch('d2admin/log/add', { store.dispatch('d2admin/log/push', {
message: `${info}: ${error.message}`,
type: 'error', type: 'error',
err, meta: {
instance, error,
info instance
}
}) })
// 只在开发模式下打印 log // 只在开发模式下打印 log
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
@@ -20,7 +22,7 @@ export default {
util.log.danger('>>>>>> Vue 实例 >>>>>>') util.log.danger('>>>>>> Vue 实例 >>>>>>')
console.log(instance) console.log(instance)
util.log.danger('>>>>>> Error >>>>>>') util.log.danger('>>>>>> Error >>>>>>')
console.log(err) console.log(error)
} }
}) })
} }

View File

@@ -12,12 +12,12 @@ export default {
// 赋值给 message 字段 // 赋值给 message 字段
// 为了方便使用 // 为了方便使用
// eg: this.$log.push('foo text') // eg: this.$log.push('foo text')
store.dispatch('d2admin/log/add', { store.dispatch('d2admin/log/push', {
message: data message: data
}) })
} else if (typeof data === 'object') { } else if (typeof data === 'object') {
// 如果传递来的数据是对象 // 如果传递来的数据是对象
store.dispatch('d2admin/log/add', data) store.dispatch('d2admin/log/push', data)
} }
} }
} }

View File

@@ -11,7 +11,7 @@ export default {
// - type 非必须 类型 success | warning | info | error // - type 非必须 类型 success | warning | info | error
// - time 必须 日志记录时间 // - time 必须 日志记录时间
// - meta 非必须 其它携带信息 // - meta 非必须 其它携带信息
list: [] log: []
}, },
getters: { getters: {
/** /**
@@ -19,14 +19,14 @@ export default {
* @param {*} state vuex state * @param {*} state vuex state
*/ */
length (state) { length (state) {
return state.list.length return state.log.length
}, },
/** /**
* @description 返回现存 log (error) 的条数 * @description 返回现存 log (error) 的条数
* @param {*} state vuex state * @param {*} state vuex state
*/ */
lengthError (state) { lengthError (state) {
return state.list.filter(l => l.type === 'error').length return state.log.filter(l => l.type === 'error').length
} }
}, },
actions: { actions: {
@@ -36,8 +36,8 @@ export default {
* @param {String} param type {String} 类型 * @param {String} param type {String} 类型
* @param {Object} param meta {Object} 附带的信息 * @param {Object} param meta {Object} 附带的信息
*/ */
add ({ rootState, commit }, { message, type, meta }) { push ({ rootState, commit }, { message, type, meta }) {
commit('add', { commit('push', {
message, message,
type, type,
time: dayjs().format('YYYY-MM-DD HH:mm:ss'), time: dayjs().format('YYYY-MM-DD HH:mm:ss'),
@@ -62,8 +62,8 @@ export default {
* @param {Object} state vuex state * @param {Object} state vuex state
* @param {Object} log data * @param {Object} log data
*/ */
add (state, log) { push (state, log) {
state.list.push(log) state.log.push(log)
}, },
/** /**
* @description 清空日志 * @description 清空日志
@@ -71,7 +71,7 @@ export default {
*/ */
clean (state) { clean (state) {
// store 赋值 // store 赋值
state.list = [] state.log = []
} }
} }
} }

View File

@@ -7,13 +7,16 @@
:loading="uploading" :loading="uploading"
@click="handleUpload"> @click="handleUpload">
<d2-icon name="cloud-upload"/> <d2-icon name="cloud-upload"/>
Upload {{list.length}} log data Upload {{log.length}} log data
</el-button> </el-button>
</template> </template>
<section class="page"> <section class="page">
<p class="log" v-for="(log, logIndex) in list" :key="logIndex"> <p
<span class="log-time">{{log.time}}</span> class="log"
<span class="log-message">{{log.message}}</span> v-for="(logItem, logIndex) in log"
:key="logIndex">
<span class="log-time">{{logItem.time}}</span>
<span class="log-message">{{logItem.message}}</span>
</p> </p>
</section> </section>
</d2-container> </d2-container>
@@ -29,7 +32,7 @@ export default {
}, },
computed: { computed: {
...mapState('d2admin/log', [ ...mapState('d2admin/log', [
'list' 'log'
]) ])
}, },
methods: { methods: {
@@ -38,7 +41,7 @@ export default {
this.$notify({ this.$notify({
type: 'info', type: 'info',
title: '日志上传', title: '日志上传',
message: `开始上传${this.list.length}条日志` message: `开始上传${this.log.length}条日志`
}) })
setTimeout(() => { setTimeout(() => {
this.uploading = false this.uploading = false