From dd6bcfd94b0c8eff8b2a1c59df1c591f1a0021af Mon Sep 17 00:00:00 2001
From: liyang <1711467488@qq.com>
Date: Thu, 9 Aug 2018 01:03:20 +0800
Subject: [PATCH] log
Former-commit-id: 067af1ad15588da779f6fdb52d8dd5e4d5337a83 [formerly 067af1ad15588da779f6fdb52d8dd5e4d5337a83 [formerly 067af1ad15588da779f6fdb52d8dd5e4d5337a83 [formerly 067af1ad15588da779f6fdb52d8dd5e4d5337a83 [formerly 26bff908e7e98cdecb3942975cb8dac912d22760 [formerly 5394d813fcdce16e699ff3d54fca956c87f1b56b]]]]]
Former-commit-id: 4d70ea535fa6b135fd63ef83fc090e9a9d851e39
Former-commit-id: faec9e738fabb0225ec9ed61b86c30f269c02486
Former-commit-id: 9b54c495f13d810d67fa85e2129c05eec4a99324 [formerly 46471134b136a5df475c7787b5694052aca6b8ae]
Former-commit-id: 0eb56ebbfa256ce1c2d3c1d99994ec7236c7ad5f
Former-commit-id: 68c0847f64453808a6afc906ffc110654ccf84a4
Former-commit-id: 93c3b439339c575b5d7a085262817b295a852058
Former-commit-id: 32ccde3e80c1ec1a1dc8bc335082eb6ac80ea3e1
Former-commit-id: b8e2a549af61ff83b566fd961085ad7414d21b2d
---
src/components/d2-error-log-list/index.vue | 12 +--
.../components/header-error-log/index.vue | 24 +++---
.../components/header-user/index.vue | 8 +-
src/layout/header-aside/layout.vue | 8 +-
src/pages/demo/playground/store/sys/index.vue | 8 +-
src/plugin/error/index.js | 2 +-
src/plugin/log/index.js | 2 +-
.../modules/d2admin/index.js.REMOVED.git-id | 2 +-
src/store/modules/d2admin/modules/log.js | 75 +++++++++++++++++++
9 files changed, 106 insertions(+), 35 deletions(-)
create mode 100644 src/store/modules/d2admin/modules/log.js
diff --git a/src/components/d2-error-log-list/index.vue b/src/components/d2-error-log-list/index.vue
index 666fac97..737153f4 100644
--- a/src/components/d2-error-log-list/index.vue
+++ b/src/components/d2-error-log-list/index.vue
@@ -136,15 +136,15 @@ export default {
ExpandItem
},
computed: {
- ...mapState('d2admin', [
- 'log'
- ]),
+ ...mapState('d2admin', {
+ logList: state => state.log.list
+ }),
logReverse () {
// 直接 reverse 的话有点问题
const res = []
- const loglength = this.log.length
- this.log.forEach((log, index) => {
- res.push(this.log[loglength - 1 - index])
+ const loglength = this.logList.length
+ this.logList.forEach((log, index) => {
+ res.push(this.logList[loglength - 1 - index])
})
return res
}
diff --git a/src/layout/header-aside/components/header-error-log/index.vue b/src/layout/header-aside/components/header-error-log/index.vue
index b031d8c5..c326860a 100644
--- a/src/layout/header-aside/components/header-error-log/index.vue
+++ b/src/layout/header-aside/components/header-error-log/index.vue
@@ -11,10 +11,10 @@
+ :value="logLengthError"
+ :is-dot="logLengthError === 0">
0
- ? ` | 包含 ${this.logErrorLength} 个异常`
+ : `${this.logLength} 条日志${this.logLengthError > 0
+ ? ` | 包含 ${this.logLengthError} 个异常`
: ''}`
}
},
methods: {
- ...mapMutations('d2admin', [
- 'logClean'
+ ...mapMutations('d2admin/log', [
+ 'clean'
]),
handleClick () {
if (this.logLength > 0) {
@@ -72,7 +72,7 @@ export default {
},
handleLogClean () {
this.dialogVisible = false
- this.logClean()
+ this.clean()
}
}
}
diff --git a/src/layout/header-aside/components/header-user/index.vue b/src/layout/header-aside/components/header-user/index.vue
index 44f81b14..e5d25609 100644
--- a/src/layout/header-aside/components/header-user/index.vue
+++ b/src/layout/header-aside/components/header-user/index.vue
@@ -1,6 +1,6 @@
- 你好 {{userInfo.name}}
+ 你好 {{info.name}}
@@ -14,9 +14,9 @@
import { mapState, mapActions } from 'vuex'
export default {
computed: {
- ...mapState('d2admin', {
- userInfo: state => state.user.info
- })
+ ...mapState('d2admin/user', [
+ 'info'
+ ])
},
methods: {
...mapActions('d2admin', [
diff --git a/src/layout/header-aside/layout.vue b/src/layout/header-aside/layout.vue
index c867125b..53af6d3d 100644
--- a/src/layout/header-aside/layout.vue
+++ b/src/layout/header-aside/layout.vue
@@ -85,11 +85,9 @@ export default {
...mapState('d2admin/menu', [
'asideCollapse'
]),
- ...mapGetters('d2admin', [
- 'keepAliveInclude'
- ]),
- ...mapGetters('d2admin/theme', {
- themeActiveSetting: 'activeSetting'
+ ...mapGetters('d2admin', {
+ keepAliveInclude: 'keepAliveInclude',
+ themeActiveSetting: 'theme/activeSetting'
}),
/**
* @description 最外层容器的背景图片样式
diff --git a/src/pages/demo/playground/store/sys/index.vue b/src/pages/demo/playground/store/sys/index.vue
index 26f9b725..a82bf6cc 100644
--- a/src/pages/demo/playground/store/sys/index.vue
+++ b/src/pages/demo/playground/store/sys/index.vue
@@ -155,11 +155,9 @@ export default {
'pageCurrent',
'ua'
]),
- ...mapGetters('d2admin', [
- 'keepAliveInclude'
- ]),
- ...mapGetters('d2admin/theme', {
- themeActiveSetting: 'activeSetting'
+ ...mapGetters('d2admin', {
+ keepAliveInclude: 'keepAliveInclude',
+ themeActiveSetting: 'theme/activeSetting'
})
}
}
diff --git a/src/plugin/error/index.js b/src/plugin/error/index.js
index 64e07424..7742b380 100644
--- a/src/plugin/error/index.js
+++ b/src/plugin/error/index.js
@@ -5,7 +5,7 @@ export default {
install (Vue, options) {
Vue.config.errorHandler = function (err, vm, info) {
Vue.nextTick(() => {
- store.commit('d2admin/logAdd', {
+ store.dispatch('d2admin/log/add', {
type: 'error',
err,
vm,
diff --git a/src/plugin/log/index.js b/src/plugin/log/index.js
index 668c85c4..d5708868 100644
--- a/src/plugin/log/index.js
+++ b/src/plugin/log/index.js
@@ -7,7 +7,7 @@ export default {
Vue.prototype.$log = util.log
// 快速记录日志
Vue.prototype.$logAdd = function (info) {
- store.commit('d2admin/logAdd', {
+ store.dispatch('d2admin/log/add', {
type: 'log',
info
})
diff --git a/src/store/modules/d2admin/index.js.REMOVED.git-id b/src/store/modules/d2admin/index.js.REMOVED.git-id
index 174d508a..fb0aad66 100644
--- a/src/store/modules/d2admin/index.js.REMOVED.git-id
+++ b/src/store/modules/d2admin/index.js.REMOVED.git-id
@@ -1 +1 @@
-e2e9f9e3f236b74d6b87a1b9a3865b19b4afc9fb
\ No newline at end of file
+2eb4adc620a4ffb94292cc6c574b7290fccf8356
\ No newline at end of file
diff --git a/src/store/modules/d2admin/modules/log.js b/src/store/modules/d2admin/modules/log.js
new file mode 100644
index 00000000..8f265fe8
--- /dev/null
+++ b/src/store/modules/d2admin/modules/log.js
@@ -0,0 +1,75 @@
+import dayjs from 'dayjs'
+import get from 'lodash.get'
+import util from '@/libs/util.js'
+
+export default {
+ namespaced: true,
+ state: {
+ // 错误日志
+ list: []
+ },
+ getters: {
+ /**
+ * @description 返回现存 log (all) 的条数
+ * @param {*} state vuex state
+ */
+ length (state) {
+ return state.list.length
+ },
+ /**
+ * @description 返回现存 log (error) 的条数
+ * @param {*} state vuex state
+ */
+ lengthError (state) {
+ return state.list.filter(l => l.type === 'error').length
+ }
+ },
+ mutations: {
+ /**
+ * @description 清空日志
+ * @param {Object} state vuex state
+ */
+ clean (state) {
+ // store 赋值
+ state.list = []
+ }
+ },
+ actions: {
+ /**
+ * @description 添加一个日志
+ * @param {Object} state vuex state
+ * @param {Object} param type {String}: 类型
+ * @param {Object} param err {Error}: 错误对象
+ * @param {Object} param vm {Object}: vue 实例
+ * @param {Object} param info {String}: 信息
+ */
+ add ({ state, rootState }, { type, err, vm, info }) {
+ // store 赋值
+ state.list.push(Object.assign({
+ // 记录类型
+ type: 'log', // or error
+ // 信息
+ info: '',
+ // 错误对象
+ err: '',
+ // vue 实例
+ vm: '',
+ // 当前用户信息
+ 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,
+ err,
+ vm,
+ info
+ }))
+ }
+ }
+}