Commit b2c3e73d by cwq0219

去掉日志

1 parent c4565dc7
...@@ -15,7 +15,6 @@ import '@/filters' ...@@ -15,7 +15,6 @@ import '@/filters'
// 功能插件 // 功能插件
import pluginError from '@/plugin/error' import pluginError from '@/plugin/error'
import pluginLog from '@/plugin/log'
import pluginOpen from '@/plugin/open' import pluginOpen from '@/plugin/open'
export default { export default {
...@@ -37,7 +36,6 @@ export default { ...@@ -37,7 +36,6 @@ export default {
Vue.use(ElementUI, { size: 'medium', zIndex: 3000 }) Vue.use(ElementUI, { size: 'medium', zIndex: 3000 })
// 插件 // 插件
Vue.use(pluginError) Vue.use(pluginError)
Vue.use(pluginLog)
Vue.use(pluginOpen) Vue.use(pluginOpen)
} }
} }
import store from '@/store'
import util from '@/libs/util'
export default {
install(Vue, options) {
// 快速打印 log
Vue.prototype.$log = {
...util.log,
push(data) {
if (typeof data === 'string') {
// 如果传递来的数据是字符串
// 赋值给 message 字段
// 为了方便使用
// eg: this.$log.push('foo text')
store.dispatch('d2admin/log/push', {
message: data
})
} else if (typeof data === 'object') {
// 如果传递来的数据是对象
store.dispatch('d2admin/log/push', data)
}
}
}
}
}
...@@ -31,15 +31,6 @@ export const home = { ...@@ -31,15 +31,6 @@ export const home = {
component: _import('index') component: _import('index')
} }
export const sys = [ export const sys = [
// 系统 前端日志
// {
// path: '/log',
// name: 'log',
// meta: {
// title: '前端日志',
// },
// component: _import('system/log')
// },
// 刷新页面 必须保留 // 刷新页面 必须保留
{ {
path: '/refresh', path: '/refresh',
......
import dayjs from 'dayjs'
import util from '@/libs/util.js'
export default {
namespaced: true,
state: {
// 错误日志
// + 日志条目的属性
// - message 必须 日志信息
// - type 非必须 类型 success | warning | info(默认) | danger
// - time 必须 日志记录时间
// - meta 非必须 其它携带信息
log: []
},
getters: {
/**
* @description 返回现存 log (all) 的条数
* @param {*} state vuex state
*/
length(state) {
return state.log.length
},
/**
* @description 返回现存 log (error) 的条数
* @param {*} state vuex state
*/
lengthError(state) {
return state.log.filter(log => log.type === 'danger').length
}
},
actions: {
/**
* @description 添加一个日志
* @param {Object} context
* @param {String} param message {String} 信息
* @param {String} param type {String} 类型
* @param {Object} payload meta {Object} 附带的信息
*/
push({ rootState, commit }, { message, type = 'info', meta }) {
commit('push', {
message,
type,
time: dayjs().format('YYYY-MM-DD HH:mm:ss'),
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 state
* @param {Object} log data
*/
push(state, log) {
state.log.push(log)
},
/**
* @description 清空日志
* @param {Object} state state
*/
clean(state) {
// store 赋值
state.log = []
}
}
}
<template>
<d2-container>
<el-table
:data="log"
size="mini"
style="width: 100%"
empty-text="暂无日志信息"
stripe>
<!-- 时间 -->
<el-table-column
prop="time"
label="Time"
width="140">
</el-table-column>
<!-- 信息 -->
<el-table-column
prop="message"
label="Message">
</el-table-column>
<!-- 触发页面 -->
<el-table-column
label="Url"
align="center"
min-width="200">
<template slot-scope="scope">
<p v-text="get(scope.row, 'meta.url')"></p>
</template>
</el-table-column>
<!-- 触发组件 -->
<el-table-column
label="Tag"
align="center"
min-width="120">
<template slot-scope="scope">
<el-tag
v-if="get(scope.row, 'meta.instance.$vnode.componentOptions.tag')"
type="info"
size="mini"
v-text="get(scope.row, 'meta.instance.$vnode.componentOptions.tag')">
</el-tag>
</template>
</el-table-column>
<!-- 查看详情 -->
<el-table-column
fixed="right"
align="center"
label="More"
width="100">
<template slot-scope="scope">
<el-button
type="primary"
size="mini"
@click="handleShowMore(scope.row)">
<d2-icon name="eye"/>
</el-button>
</template>
</el-table-column>
</el-table>
<template slot="footer">
<el-button
type="primary"
size="mini"
:loading="uploading"
@click="handleUpload">
<d2-icon name="cloud-upload"/>
Upload log data
</el-button>
</template>
</d2-container>
</template>
<script>
import { mapState } from 'vuex'
export default {
data() {
return {
uploading: false
}
},
computed: {
...mapState('d2admin/log', [
'log'
])
},
methods: {
get: _.get,
handleShowMore(log) {
// 打印一条日志的所有信息到控制台
this.$notify({
type: 'info',
title: '日志详情',
message: '完整的日志内容已经打印到控制台'
})
this.$log.capsule('D2Admin', 'handleShowMore', 'primary')
console.group(log.message)
console.log('time: ', log.time)
console.log('type: ', log.type)
console.log(log.meta)
console.groupEnd()
},
// 日志上传
handleUpload() {
this.uploading = true
this.$notify({
type: 'info',
title: '日志上传',
message: `开始上传${this.log.length}条日志`
})
setTimeout(() => {
this.uploading = false
this.$notify({
type: 'success',
title: '日志上传',
message: '上传成功'
})
}, 3000)
}
}
}
</script>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!