diff --git a/docs/zh/guide/change-log.md b/docs/zh/guide/change-log.md index 3dbf2834..672b00d7 100644 --- a/docs/zh/guide/change-log.md +++ b/docs/zh/guide/change-log.md @@ -1,5 +1,9 @@ # 更新日志 +## v1.1.6 + +* [ 新增 ] 新增加了多页控制组件 tab 按钮上的右键操作菜单,现在你可以在 D2Admin 中像使用浏览器一样操作多标签页 + ## v1.1.5 * [ 修改 ] vue-cli3 项目重构,目录调整 diff --git a/src/libs/util.js b/src/libs/util.js index 1e821fed..bac289d6 100644 --- a/src/libs/util.js +++ b/src/libs/util.js @@ -5,7 +5,8 @@ import UaParser from 'ua-parser-js' import { version } from '../../package.json' let util = { - cookies: {} + cookies: {}, + log: {} } /** @@ -73,20 +74,55 @@ util.isOneOf = function (ele, targetArr) { } } +/** + * @description 返回这个样式的颜色值 + * @param {String} type 样式名称 [ primary | success | warning | danger | text ] + */ +util.typeColor = function (type = 'default') { + let color = '' + switch (type) { + case 'default': color = '35495E'; break + case 'primary': color = '#3488ff'; break + case 'success': color = '#43B883'; break + case 'warning': color = '#e6a23c'; break + case 'danger': color = '#f56c6c'; break + default:; break + } + return color +} + /** * @description 打印一个 “胶囊” 样式的信息 * @param {String} title title text * @param {String} info info text + * @param {String} type style */ -util.logCapsule = function (title, info) { +util.log.capsule = function (title, info, type = 'primary') { console.log( `%c ${title} %c ${info} %c`, - 'background:#29384b; padding: 1px; border-radius: 3px 0 0 3px; color: #fff', - 'background:#3488ff; padding: 1px; border-radius: 0 3px 3px 0; color: #fff', + 'background:#35495E; padding: 1px; border-radius: 3px 0 0 3px; color: #fff;', + `background:${util.typeColor(type)}; padding: 1px; border-radius: 0 3px 3px 0; color: #fff;`, 'background:transparent' ) } +/** + * @description 打印彩色文字 + */ +util.log.colorful = function (textArr) { + console.log( + `%c ${textArr.map(t => t.text).join(' %c ')}`, + ...textArr.map(t => `color: ${util.typeColor(t.type)};`) + ) +} + +/** + * @description 打印 danger 样式的文字 + */ +util.log.error = function (text) { + util.log.colorful([{ text, type: 'danger' }]) +} + /** * @description 检查版本更新 * @param {Object} vm vue @@ -100,7 +136,7 @@ util.checkUpdate = function (vm) { let versionGet = res.tag_name const update = semver.lt(version, versionGet) if (update) { - util.logCapsule('D2Admin', `New version ${res.name}`) + util.log.capsule('D2Admin', `New version ${res.name}`) console.log(`版本号: ${res.tag_name} | 详情${res.html_url}`) vm.$store.commit('d2adminReleasesUpdateSet', true) } @@ -115,7 +151,7 @@ util.checkUpdate = function (vm) { * @description 显示版本信息 */ util.showInfo = function showInfo () { - util.logCapsule('D2Admin', `v${version}`) + util.log.capsule('D2Admin', `v${version}`) console.log('Github https://github.com/d2-projects/d2-admin') console.log('Doc http://d2admin.fairyever.com/zh/') } diff --git a/src/main.js b/src/main.js index 57483b5c..adda84f9 100644 --- a/src/main.js +++ b/src/main.js @@ -15,8 +15,9 @@ import util from '@/libs/util.js' import store from '@/store/index' import '@/assets/svg-icons' import '@/components' -import '@/plugin/axios' import '@/mock/register' +import '@/plugin/axios' +import pluginError from '@/plugin/error' import pluginImport from '@/plugin/import' import pluginExport from '@/plugin/export' import pluginOpen from '@/plugin/open' @@ -29,6 +30,7 @@ import { frameInRoutes } from '@/router/routes' Vue.use(ElementUI) Vue.use(VCharts) Vue.use(contentmenu) +Vue.use(pluginError) Vue.use(pluginImport) Vue.use(pluginExport) Vue.use(pluginOpen) @@ -61,6 +63,10 @@ new Vue({ this.$store.commit('d2adminLoginSuccessLoad') // 初始化全屏监听 this.fullscreenListenerInit() + window.onerror = function (message, url, line, column, error) { + console.log('onerror') + console.log(message, url, line, column, error) + } }, watch: { // 监听路由 控制侧边栏显示 diff --git a/src/menu/modules/demo-playground.js b/src/menu/modules/demo-playground.js index b8a8ba02..c94c3d40 100644 --- a/src/menu/modules/demo-playground.js +++ b/src/menu/modules/demo-playground.js @@ -45,6 +45,14 @@ export default { { path: `${pre}db/public`, title: '公用数据', icon: 'users' } ] }, + { + path: `${pre}log`, + title: '日志', + icon: 'bullseye', + children: [ + { path: `${pre}log/error`, title: '错误捕捉', icon: 'bug' } + ] + }, { path: `${pre}env`, title: '环境信息', icon: 'exclamation-circle' } ])('/demo/playground/') } diff --git a/src/pages/demo/playground/log/error/index.vue b/src/pages/demo/playground/log/error/index.vue new file mode 100644 index 00000000..e67b6dc4 --- /dev/null +++ b/src/pages/demo/playground/log/error/index.vue @@ -0,0 +1,17 @@ + + + diff --git a/src/plugin/error/index.js b/src/plugin/error/index.js new file mode 100644 index 00000000..7b6f02b5 --- /dev/null +++ b/src/plugin/error/index.js @@ -0,0 +1,21 @@ +import store from '@/store' +import util from '@/libs/util' + +export default { + install (Vue, options) { + Vue.config.errorHandler = function (err, vm, info) { + Vue.nextTick(() => { + store.commit('d2adminLogAdd', { + err, vm, info + }) + util.log.capsule('D2Admin', 'ErrorHandler', 'danger') + util.log.error('>>>>> err') + console.log(err) + util.log.error('>>>>> vm') + console.log(vm) + util.log.error('>>>>> info') + console.log(info) + }) + } + } +} diff --git a/src/router/routes.js.REMOVED.git-id b/src/router/routes.js.REMOVED.git-id index 1e67b886..1fa7ded1 100644 --- a/src/router/routes.js.REMOVED.git-id +++ b/src/router/routes.js.REMOVED.git-id @@ -1 +1 @@ -0fa9b5a2bdc57841e4f19831dc3e2a913399a280 \ No newline at end of file +51f901f963b0802a69efe93ef5d40b60bcd1a2fd \ No newline at end of file diff --git a/src/store/modules/d2admin.js.REMOVED.git-id b/src/store/modules/d2admin.js.REMOVED.git-id index 2ea59ae8..e1ffd471 100644 --- a/src/store/modules/d2admin.js.REMOVED.git-id +++ b/src/store/modules/d2admin.js.REMOVED.git-id @@ -1 +1 @@ -f6b747b5dbf484da5c8b5876c9d54212c90c3550 \ No newline at end of file +1325e2be4603dde2cf094397e4fca98a542e4ba5 \ No newline at end of file