Merge remote-tracking branch 'origin/develop'
Former-commit-id: 96fd7cde0038cf426d908a227ed4462f6c3ace5c [formerly 96fd7cde0038cf426d908a227ed4462f6c3ace5c [formerly 96fd7cde0038cf426d908a227ed4462f6c3ace5c [formerly 96fd7cde0038cf426d908a227ed4462f6c3ace5c [formerly ad2e6a5eca8a46bf9f2fecefdca7d69d60de41d1 [formerly 71f37f654ea6459d459ec3bc49a14a515bb47227]]]]] Former-commit-id: 31a37b122552fbd26e993102d5ca079d6408a248 Former-commit-id: d8f6ce991e22077cc8cf59160fb24399357bd50c Former-commit-id: f2b7d2832afb45df3c988c607b3f17f383c54c8a [formerly ccfc8d2735de0bdac33eba71342a1db80e1708c2] Former-commit-id: 1ba29ef2d7ef151654053cb36f38701c87d56249 Former-commit-id: d9d88ffbc80f716a3d050b6fbb9796040eba7aac Former-commit-id: dad86160ea27e805f8850629e9223dc647b653dd Former-commit-id: 5cca1791a26a7a18ba97366022c45dee000917f5 Former-commit-id: f7328d97b1a2f75755df37a4ec525bf3f285c1c8
This commit is contained in:
@@ -34,14 +34,6 @@
|
|||||||
.#{$prefix}-fr {
|
.#{$prefix}-fr {
|
||||||
float: right;
|
float: right;
|
||||||
}
|
}
|
||||||
.#{$prefix}-clearfix:before,
|
|
||||||
.#{$prefix}-clearfix:after {
|
|
||||||
display: table;
|
|
||||||
content: "";
|
|
||||||
}
|
|
||||||
.#{$prefix}-clearfix:after {
|
|
||||||
clear: both
|
|
||||||
}
|
|
||||||
|
|
||||||
// 边距相关
|
// 边距相关
|
||||||
$sizes: (0, 5, 10, 15, 20);
|
$sizes: (0, 5, 10, 15, 20);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
class="d2-source"
|
class="d2-source"
|
||||||
:class="{ 'd2-source--active': isActive }"
|
:class="{ 'd2-source--active': isActive }"
|
||||||
@click="handleClick">
|
@click="handleClick">
|
||||||
<d2-icon name="code"/> SourceCode
|
<d2-icon name="code"/> 本页源码
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,12 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
// 相关文档
|
||||||
// https://highlightjs.org/usage/
|
// https://highlightjs.org/usage/
|
||||||
// http://highlightjs.readthedocs.io/en/latest/api.html#configure-options
|
// http://highlightjs.readthedocs.io/en/latest/api.html#configure-options
|
||||||
import './styles/github-gist.css'
|
|
||||||
import htmlFormat from './libs/htmlFormat'
|
|
||||||
import highlight from 'highlight.js'
|
import highlight from 'highlight.js'
|
||||||
|
import '../highlight-styles/github-gist.css'
|
||||||
|
import htmlFormat from './libs/htmlFormat'
|
||||||
export default {
|
export default {
|
||||||
name: 'd2-highlight',
|
name: 'd2-highlight',
|
||||||
props: {
|
props: {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
:placement="placement"
|
:placement="placement"
|
||||||
width="300"
|
width="300"
|
||||||
trigger="click">
|
trigger="click">
|
||||||
<div class="d2-clearfix d2-mb-10" v-if="clearable">
|
<el-row type="flex" justify="end" class="d2-mb-10" v-if="clearable">
|
||||||
<el-button
|
<el-button
|
||||||
type="danger"
|
type="danger"
|
||||||
icon="el-icon-delete"
|
icon="el-icon-delete"
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
@click="selectIcon()">
|
@click="selectIcon()">
|
||||||
清空
|
清空
|
||||||
</el-button>
|
</el-button>
|
||||||
</div>
|
</el-row>
|
||||||
<el-input
|
<el-input
|
||||||
v-model="searchText"
|
v-model="searchText"
|
||||||
:clearable="true"
|
:clearable="true"
|
||||||
|
|||||||
@@ -6,9 +6,7 @@
|
|||||||
:placement="placement"
|
:placement="placement"
|
||||||
width="300"
|
width="300"
|
||||||
trigger="click">
|
trigger="click">
|
||||||
<div
|
<el-row type="flex" justify="end" class="d2-mb-10" v-if="clearable">
|
||||||
class="d2-clearfix d2-mb-10"
|
|
||||||
v-if="clearable">
|
|
||||||
<el-button
|
<el-button
|
||||||
type="danger"
|
type="danger"
|
||||||
icon="el-icon-delete"
|
icon="el-icon-delete"
|
||||||
@@ -17,7 +15,7 @@
|
|||||||
@click="selectIcon()">
|
@click="selectIcon()">
|
||||||
清空
|
清空
|
||||||
</el-button>
|
</el-button>
|
||||||
</div>
|
</el-row>
|
||||||
<el-input
|
<el-input
|
||||||
v-model="searchText"
|
v-model="searchText"
|
||||||
:clearable="true"
|
:clearable="true"
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import marked from 'marked'
|
import marked from 'marked'
|
||||||
import highlight from 'highlight.js'
|
import highlight from 'highlight.js'
|
||||||
|
import '../highlight-styles/github-gist.css'
|
||||||
import bandupan from './plugin/baidupan'
|
import bandupan from './plugin/baidupan'
|
||||||
import 'github-markdown-css'
|
import 'github-markdown-css'
|
||||||
import { ComponentsMarkdownBase } from '@api/components.markdown'
|
import { ComponentsMarkdownBase } from '@api/components.markdown'
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div
|
|
||||||
class="d2-error-log-list__expand"
|
|
||||||
:class="className">
|
|
||||||
<p class="d2-error-log-list__expand-title">{{title}}</p>
|
|
||||||
<p class="d2-error-log-list__expand-value">{{value === '' ? '无数据' : value}}</p>
|
|
||||||
<slot/>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
export default {
|
|
||||||
props: {
|
|
||||||
type: {
|
|
||||||
default: 'log'
|
|
||||||
},
|
|
||||||
title: {
|
|
||||||
default: ''
|
|
||||||
},
|
|
||||||
value: {
|
|
||||||
default: ''
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
className () {
|
|
||||||
return this.type === 'log' ? 'd2-error-log-list__expand--log' : 'd2-error-log-list__expand--error'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,178 +0,0 @@
|
|||||||
<template>
|
|
||||||
<el-table
|
|
||||||
:data="logReversed"
|
|
||||||
border
|
|
||||||
stripe
|
|
||||||
style="width: 100%"
|
|
||||||
size="mini">
|
|
||||||
<el-table-column type="expand">
|
|
||||||
<div slot-scope="{ row = {} }" class="d2-error-log-list__expand-group">
|
|
||||||
<expand-item
|
|
||||||
:type="row.type"
|
|
||||||
title="类型"
|
|
||||||
:value="row.type === 'log' ? '日志' : '异常'"/>
|
|
||||||
<expand-item
|
|
||||||
:type="row.type"
|
|
||||||
title="内容"
|
|
||||||
:value="row.info"/>
|
|
||||||
<expand-item
|
|
||||||
v-if="row.type === 'error'"
|
|
||||||
type="error"
|
|
||||||
title="报错组件"
|
|
||||||
:value="get(row, 'instance.$vnode.tag', '')"/>
|
|
||||||
<expand-item
|
|
||||||
v-if="row.type === 'error'"
|
|
||||||
type="error"
|
|
||||||
title="错误名称"
|
|
||||||
:value="get(row, 'err.name', '')"/>
|
|
||||||
<expand-item
|
|
||||||
v-if="row.type === 'error'"
|
|
||||||
type="error"
|
|
||||||
title="错误信息"
|
|
||||||
:value="get(row, 'err.message', '')"/>
|
|
||||||
<expand-item
|
|
||||||
v-if="row.type === 'error'"
|
|
||||||
type="error"
|
|
||||||
title="错误堆栈"
|
|
||||||
value="见下">
|
|
||||||
<div style="overflow: auto;">
|
|
||||||
<pre>{{stackBeautify(row.err)}}</pre>
|
|
||||||
</div>
|
|
||||||
</expand-item>
|
|
||||||
<expand-item
|
|
||||||
:type="row.type"
|
|
||||||
title="用户名"
|
|
||||||
:value="get(row, 'user.name', '')"/>
|
|
||||||
<expand-item
|
|
||||||
:type="row.type"
|
|
||||||
title="uuid"
|
|
||||||
:value="row.uuid"/>
|
|
||||||
<expand-item
|
|
||||||
:type="row.type"
|
|
||||||
title="token"
|
|
||||||
:value="row.token"/>
|
|
||||||
<expand-item
|
|
||||||
:type="row.type"
|
|
||||||
title="页面地址"
|
|
||||||
:value="row.url"/>
|
|
||||||
<expand-item
|
|
||||||
:type="row.type"
|
|
||||||
title="时间"
|
|
||||||
:value="row.time"/>
|
|
||||||
</div>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column
|
|
||||||
prop="type"
|
|
||||||
label="类型"
|
|
||||||
width="80px"
|
|
||||||
align="center"
|
|
||||||
:filters="[
|
|
||||||
{ text: '日志', value: 'log' },
|
|
||||||
{ text: '异常', value: 'error' }
|
|
||||||
]"
|
|
||||||
:filter-multiple="false"
|
|
||||||
:filter-method="filterType"
|
|
||||||
filter-placement="bottom">
|
|
||||||
<template slot-scope="scope">
|
|
||||||
<el-tag
|
|
||||||
v-if="get(scope, 'row.type') === 'error'"
|
|
||||||
size="mini"
|
|
||||||
type="danger">
|
|
||||||
<d2-icon name="bug"/> Bug
|
|
||||||
</el-tag>
|
|
||||||
<el-tag
|
|
||||||
v-else
|
|
||||||
size="mini"
|
|
||||||
type="info">
|
|
||||||
<d2-icon name="dot-circle-o"/> Log
|
|
||||||
</el-tag>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column
|
|
||||||
label="地址"
|
|
||||||
prop="url"
|
|
||||||
width="140px"
|
|
||||||
:show-overflow-tooltip="true">
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column
|
|
||||||
label="内容"
|
|
||||||
prop="info"
|
|
||||||
:show-overflow-tooltip="true">
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column
|
|
||||||
label="错误类型"
|
|
||||||
width="140px"
|
|
||||||
:show-overflow-tooltip="true">
|
|
||||||
<template
|
|
||||||
slot-scope="scope">
|
|
||||||
{{get(scope, 'row.err.name', '')}}
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column
|
|
||||||
label="错误信息"
|
|
||||||
width="300px">
|
|
||||||
<template
|
|
||||||
slot-scope="scope">
|
|
||||||
{{get(scope, 'row.err.message', '')}}
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
</el-table>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import { mapState } from 'vuex'
|
|
||||||
import { get, cloneDeep } from 'lodash'
|
|
||||||
import ExpandItem from './components/ExpandItem'
|
|
||||||
export default {
|
|
||||||
name: 'd2-error-log-list',
|
|
||||||
components: {
|
|
||||||
ExpandItem
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
...mapState('d2admin', {
|
|
||||||
logList: state => state.log.list
|
|
||||||
}),
|
|
||||||
logReversed () {
|
|
||||||
return cloneDeep(this.logList).reverse()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
get,
|
|
||||||
filterType (value, row) {
|
|
||||||
return row.type === value
|
|
||||||
},
|
|
||||||
stackBeautify (err) {
|
|
||||||
return get(err, 'stack', '')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="scss">
|
|
||||||
.d2-error-log-list__expand-group {
|
|
||||||
.d2-error-log-list__expand {
|
|
||||||
padding-left: 20px;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
&:last-child {
|
|
||||||
margin-bottom: 0px;
|
|
||||||
}
|
|
||||||
.d2-error-log-list__expand-title {
|
|
||||||
font-size: 16px;
|
|
||||||
font-weight: bold;
|
|
||||||
margin-top: 0px;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
}
|
|
||||||
.d2-error-log-list__expand-value {
|
|
||||||
font-size: 12px;
|
|
||||||
margin-top: 0px;
|
|
||||||
margin-bottom: 0px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.d2-error-log-list__expand--log {
|
|
||||||
border-left: 4px solid $color-info;
|
|
||||||
}
|
|
||||||
.d2-error-log-list__expand--error {
|
|
||||||
border-left: 4px solid $color-danger;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div>
|
|
||||||
<el-tooltip
|
|
||||||
effect="dark"
|
|
||||||
:content="tooltipContent"
|
|
||||||
placement="bottom">
|
|
||||||
<el-button
|
|
||||||
class="d2-ml-0 d2-mr btn-text can-hover"
|
|
||||||
type="text"
|
|
||||||
@click="handleClick">
|
|
||||||
<el-badge
|
|
||||||
v-if="logLength > 0"
|
|
||||||
:max="99"
|
|
||||||
:value="logLengthError"
|
|
||||||
:is-dot="logLengthError === 0">
|
|
||||||
<d2-icon
|
|
||||||
:name="logLengthError === 0 ? 'dot-circle-o' : 'bug'"
|
|
||||||
style="font-size: 20px"/>
|
|
||||||
</el-badge>
|
|
||||||
<d2-icon
|
|
||||||
v-else
|
|
||||||
name="dot-circle-o"
|
|
||||||
style="font-size: 20px"/>
|
|
||||||
</el-button>
|
|
||||||
</el-tooltip>
|
|
||||||
<el-dialog
|
|
||||||
:title="tooltipContent"
|
|
||||||
:fullscreen="true"
|
|
||||||
:visible.sync="dialogVisible"
|
|
||||||
:append-to-body="true">
|
|
||||||
<div class="d2-mb-10">
|
|
||||||
<el-button type="danger" size="mini" @click="handleLogClean">
|
|
||||||
<d2-icon name="trash-o"/>
|
|
||||||
清空
|
|
||||||
</el-button>
|
|
||||||
</div>
|
|
||||||
<d2-error-log-list/>
|
|
||||||
</el-dialog>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import { mapGetters, mapMutations } from 'vuex'
|
|
||||||
import D2ErrorLogList from './components/list'
|
|
||||||
export default {
|
|
||||||
components: {
|
|
||||||
D2ErrorLogList
|
|
||||||
},
|
|
||||||
data () {
|
|
||||||
return {
|
|
||||||
dialogVisible: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
...mapGetters('d2admin', {
|
|
||||||
logLength: 'log/length',
|
|
||||||
logLengthError: 'log/lengthError'
|
|
||||||
}),
|
|
||||||
tooltipContent () {
|
|
||||||
return this.logLength === 0
|
|
||||||
? '没有日志或异常'
|
|
||||||
: `${this.logLength} 条日志${this.logLengthError > 0
|
|
||||||
? ` | 包含 ${this.logLengthError} 个异常`
|
|
||||||
: ''}`
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
...mapMutations('d2admin/log', [
|
|
||||||
'clean'
|
|
||||||
]),
|
|
||||||
handleClick () {
|
|
||||||
if (this.logLength > 0) {
|
|
||||||
this.dialogVisible = true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
handleLogClean () {
|
|
||||||
this.dialogVisible = false
|
|
||||||
this.clean()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
54
src/layout/header-aside/components/header-log/index.vue
Normal file
54
src/layout/header-aside/components/header-log/index.vue
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<template>
|
||||||
|
<el-tooltip
|
||||||
|
effect="dark"
|
||||||
|
:content="tooltipContent"
|
||||||
|
placement="bottom">
|
||||||
|
<el-button
|
||||||
|
class="d2-ml-0 d2-mr btn-text can-hover"
|
||||||
|
type="text"
|
||||||
|
@click="handleClick">
|
||||||
|
<el-badge
|
||||||
|
v-if="logLength > 0"
|
||||||
|
:max="99"
|
||||||
|
:value="logLengthError"
|
||||||
|
:is-dot="logLengthError === 0">
|
||||||
|
<d2-icon
|
||||||
|
:name="logLengthError === 0 ? 'dot-circle-o' : 'bug'"
|
||||||
|
style="font-size: 20px"/>
|
||||||
|
</el-badge>
|
||||||
|
<d2-icon
|
||||||
|
v-else
|
||||||
|
name="dot-circle-o"
|
||||||
|
style="font-size: 20px"/>
|
||||||
|
</el-button>
|
||||||
|
</el-tooltip>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { mapGetters, mapMutations } from 'vuex'
|
||||||
|
export default {
|
||||||
|
computed: {
|
||||||
|
...mapGetters('d2admin', {
|
||||||
|
logLength: 'log/length',
|
||||||
|
logLengthError: 'log/lengthError'
|
||||||
|
}),
|
||||||
|
tooltipContent () {
|
||||||
|
return this.logLength === 0
|
||||||
|
? '没有日志或异常'
|
||||||
|
: `${this.logLength} 条日志${this.logLengthError > 0
|
||||||
|
? ` | 包含 ${this.logLengthError} 个异常`
|
||||||
|
: ''}`
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
...mapMutations('d2admin/log', [
|
||||||
|
'clean'
|
||||||
|
]),
|
||||||
|
handleClick () {
|
||||||
|
this.$router.push({
|
||||||
|
name: 'log'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
<div class="d2-header-right" flex-box="0">
|
<div class="d2-header-right" flex-box="0">
|
||||||
<!-- 如果你只想在开发环境显示这个按钮请添加 v-if="$env === 'development'" -->
|
<!-- 如果你只想在开发环境显示这个按钮请添加 v-if="$env === 'development'" -->
|
||||||
<d2-header-search @click="handleSearchClick"/>
|
<d2-header-search @click="handleSearchClick"/>
|
||||||
<d2-header-error-log/>
|
<d2-header-log/>
|
||||||
<d2-header-fullscreen/>
|
<d2-header-fullscreen/>
|
||||||
<d2-header-theme/>
|
<d2-header-theme/>
|
||||||
<d2-header-size/>
|
<d2-header-size/>
|
||||||
@@ -89,7 +89,7 @@ import d2HeaderSearch from './components/header-search'
|
|||||||
import d2HeaderSize from './components/header-size'
|
import d2HeaderSize from './components/header-size'
|
||||||
import d2HeaderTheme from './components/header-theme'
|
import d2HeaderTheme from './components/header-theme'
|
||||||
import d2HeaderUser from './components/header-user'
|
import d2HeaderUser from './components/header-user'
|
||||||
import d2HeaderErrorLog from './components/header-error-log'
|
import d2HeaderLog from './components/header-log'
|
||||||
import { mapState, mapGetters, mapActions } from 'vuex'
|
import { mapState, mapGetters, mapActions } from 'vuex'
|
||||||
import mixinSearch from './mixins/search'
|
import mixinSearch from './mixins/search'
|
||||||
export default {
|
export default {
|
||||||
@@ -106,7 +106,7 @@ export default {
|
|||||||
d2HeaderSize,
|
d2HeaderSize,
|
||||||
d2HeaderTheme,
|
d2HeaderTheme,
|
||||||
d2HeaderUser,
|
d2HeaderUser,
|
||||||
d2HeaderErrorLog
|
d2HeaderLog
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
module.exports = file => require('@/pages/' + file).default
|
module.exports = file => require('@/views/' + file).default
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
module.exports = file => () => import('@/pages/' + file)
|
module.exports = file => () => import('@/views/' + file)
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
import page from './page'
|
|
||||||
|
|
||||||
export default page
|
|
||||||
@@ -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', {
|
||||||
type: 'error',
|
message: `${info}: ${error.message}`,
|
||||||
err,
|
type: 'danger',
|
||||||
instance,
|
meta: {
|
||||||
info
|
error,
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,17 +4,21 @@ import util from '@/libs/util'
|
|||||||
export default {
|
export default {
|
||||||
install (Vue, options) {
|
install (Vue, options) {
|
||||||
// 快速打印 log
|
// 快速打印 log
|
||||||
Vue.prototype.$log = util.log
|
Vue.prototype.$log = {
|
||||||
// 快速记录日志
|
...util.log,
|
||||||
Vue.prototype.$logAdd = function (info, show = true) {
|
push (data) {
|
||||||
// store 赋值
|
if (typeof data === 'string') {
|
||||||
store.dispatch('d2admin/log/add', {
|
// 如果传递来的数据是字符串
|
||||||
type: 'log',
|
// 赋值给 message 字段
|
||||||
info
|
// 为了方便使用
|
||||||
})
|
// eg: this.$log.push('foo text')
|
||||||
// 显示在控制台
|
store.dispatch('d2admin/log/push', {
|
||||||
if (show && process.env.NODE_ENV === 'development') {
|
message: data
|
||||||
util.log.default(info)
|
})
|
||||||
|
} else if (typeof data === 'object') {
|
||||||
|
// 如果传递来的数据是对象
|
||||||
|
store.dispatch('d2admin/log/push', data)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,38 +22,38 @@ const frameIn = [
|
|||||||
redirect: { name: 'index' },
|
redirect: { name: 'index' },
|
||||||
component: layoutHeaderAside,
|
component: layoutHeaderAside,
|
||||||
children: [
|
children: [
|
||||||
// 首页 必须 name:index
|
// 首页
|
||||||
{
|
{
|
||||||
path: 'index',
|
path: 'index',
|
||||||
name: 'index',
|
name: 'index',
|
||||||
meta: {
|
meta: {
|
||||||
auth: true
|
auth: true
|
||||||
},
|
},
|
||||||
component: _import('index')
|
component: _import('system/index')
|
||||||
|
},
|
||||||
|
// 系统 前端日志
|
||||||
|
{
|
||||||
|
path: 'log',
|
||||||
|
name: 'log',
|
||||||
|
meta: {
|
||||||
|
title: '前端日志',
|
||||||
|
auth: true
|
||||||
|
},
|
||||||
|
component: _import('system/log')
|
||||||
},
|
},
|
||||||
// 刷新页面 必须保留
|
// 刷新页面 必须保留
|
||||||
{
|
{
|
||||||
path: 'refresh',
|
path: 'refresh',
|
||||||
name: 'refresh',
|
name: 'refresh',
|
||||||
hidden: true,
|
hidden: true,
|
||||||
component: {
|
component: _import('system/function/refresh')
|
||||||
beforeRouteEnter (to, from, next) {
|
|
||||||
next(instance => instance.$router.replace(from.fullPath))
|
|
||||||
},
|
|
||||||
render: h => h()
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
// 页面重定向 必须保留
|
// 页面重定向 必须保留
|
||||||
{
|
{
|
||||||
path: 'redirect/:route*',
|
path: 'redirect/:route*',
|
||||||
name: 'redirect',
|
name: 'redirect',
|
||||||
hidden: true,
|
hidden: true,
|
||||||
component: {
|
component: _import('system/function/redirect')
|
||||||
beforeRouteEnter (to, from, next) {
|
|
||||||
next(instance => instance.$router.replace(JSON.parse(from.params.route)))
|
|
||||||
},
|
|
||||||
render: h => h()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -76,7 +76,7 @@ const frameOut = [
|
|||||||
{
|
{
|
||||||
path: '/login',
|
path: '/login',
|
||||||
name: 'login',
|
name: 'login',
|
||||||
component: _import('login')
|
component: _import('system/login')
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -84,11 +84,10 @@ const frameOut = [
|
|||||||
* 错误页面
|
* 错误页面
|
||||||
*/
|
*/
|
||||||
const errorPage = [
|
const errorPage = [
|
||||||
// 404
|
|
||||||
{
|
{
|
||||||
path: '*',
|
path: '*',
|
||||||
name: '404',
|
name: '404',
|
||||||
component: _import('error-page-404')
|
component: _import('system/error/404')
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import { get, toString } from 'lodash'
|
import { get } from 'lodash'
|
||||||
import util from '@/libs/util.js'
|
import util from '@/libs/util.js'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
namespaced: true,
|
namespaced: true,
|
||||||
state: {
|
state: {
|
||||||
// 错误日志
|
// 错误日志
|
||||||
list: []
|
// + 日志条目的属性
|
||||||
|
// - message 必须 日志信息
|
||||||
|
// - type 非必须 类型 success | warning | info(默认) | error
|
||||||
|
// - time 必须 日志记录时间
|
||||||
|
// - meta 非必须 其它携带信息
|
||||||
|
log: []
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
/**
|
/**
|
||||||
@@ -14,61 +19,59 @@ 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: {
|
||||||
/**
|
/**
|
||||||
* @description 添加一个日志
|
* @description 添加一个日志
|
||||||
* @param {Object} param type {String} 类型
|
* @param {String} param message {String} 信息
|
||||||
* @param {Object} param err {Error} 错误对象
|
* @param {String} param type {String} 类型
|
||||||
* @param {Object} param instance {Object} vue 实例
|
* @param {Object} param meta {Object} 附带的信息
|
||||||
* @param {Object} param info {String} 信息
|
|
||||||
*/
|
*/
|
||||||
add ({ state, rootState }, { type, err, instance, info }) {
|
push ({ rootState, commit }, { message, type = 'info', meta }) {
|
||||||
// store 赋值
|
commit('push', {
|
||||||
state.list.push(Object.assign({
|
message,
|
||||||
// 记录类型 "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')
|
|
||||||
}, {
|
|
||||||
type,
|
type,
|
||||||
err,
|
time: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
||||||
instance,
|
meta: {
|
||||||
info: toString(info)
|
// 当前用户信息
|
||||||
}))
|
user: rootState.d2admin.user.info,
|
||||||
|
// 当前用户的 uuid
|
||||||
|
uuid: util.cookies.get('uuid'),
|
||||||
|
// 当前的 token
|
||||||
|
token: util.cookies.get('token'),
|
||||||
|
// 当前地址
|
||||||
|
url: get(window, 'location.href', ''),
|
||||||
|
// 用户设置
|
||||||
|
...meta
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
|
/**
|
||||||
|
* @description 添加日志
|
||||||
|
* @param {Object} state vuex state
|
||||||
|
* @param {Object} log data
|
||||||
|
*/
|
||||||
|
push (state, log) {
|
||||||
|
state.log.push(log)
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* @description 清空日志
|
* @description 清空日志
|
||||||
* @param {Object} state vuex state
|
* @param {Object} state vuex state
|
||||||
*/
|
*/
|
||||||
clean (state) {
|
clean (state) {
|
||||||
// store 赋值
|
// store 赋值
|
||||||
state.list = []
|
state.log = []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user