Skip to content

Commit

Permalink
feat: 调整代码结构,新增了调试数据可视化面板
Browse files Browse the repository at this point in the history
  • Loading branch information
pumelotea committed Mar 20, 2022
1 parent 427f0f5 commit 565d70b
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 28 deletions.
15 changes: 11 additions & 4 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
<script setup>
import {
NMessageProvider
NMessageProvider, NConfigProvider, zhCN, dateZhCN
} from 'naive-ui'
import HbAdminDevTool from "./components/dev/HbAdminDevTool.vue";
import {theme} from "./global/config";
</script>
<template>
<n-message-provider>
<router-view/>
</n-message-provider>
<n-config-provider :theme="theme" :locale="zhCN" :date-locale="dateZhCN">
<n-message-provider>
<router-view/>
<hb-admin-dev-tool/>
</n-message-provider>
</n-config-provider>
</template>
175 changes: 175 additions & 0 deletions src/components/dev/HbAdminDevTool.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
<script setup>
import {NCard, NSpace, NButton, NTag, NCode, NTable, useMessage} from "naive-ui";
import framework from "../../global/framework";
import security from "../../global/security";
import hljs from 'highlight.js/lib/core'
import javascript from 'highlight.js/lib/languages/javascript'
import {onMounted, ref, watch} from "vue";
hljs.registerLanguage('javascript', javascript)
const clientId = ref(framework.getTracker().clientId)
const message = useMessage()
function consoleMenu() {
console.log(framework.getMenuTree())
message.info('请打开控制台查看菜单数据结构')
}
const navList = framework.getNavList()
function consoleNav() {
console.log(navList)
message.info('请打开控制台查看导航数据结构')
}
const token = ref(security.getToken())
const user = ref(JSON.stringify(security.getUser().value, null, 2))
const cacheTitleList = ref([])
function getNavTitleCache() {
cacheTitleList.value = []
for (let i = 0; i < localStorage.length; i++) {
let key = localStorage.key(i); //获取本地存储的Key
if (key.indexOf('HAPPYKIT_STORAGE/NAV_TITLE') > -1) {
const title = localStorage.getItem(key)
const pageId = key.replace('HAPPYKIT_STORAGE/NAV_TITLE/', '')
let isExist = false
navList.value.forEach(e => {
if (e.pageId === pageId) {
isExist = true
}
})
cacheTitleList.value.push({
title,
isExist,
pageId,
})
}
}
}
const showPanel = ref(false)
function handleClose() {
showPanel.value = false
}
function handleOpen() {
showPanel.value = true
}
function cleanCache() {
let keys = []
for (let i = 0; i < localStorage.length; i++) {
let key = localStorage.key(i); //获取本地存储的Key
if (key.indexOf('HAPPYKIT_STORAGE/NAV_TITLE') > -1) {
keys.push(key)
}
}
keys.forEach(k => localStorage.removeItem(k))
getNavTitleCache()
message.info('清空标题缓存完成')
}
function refreshList() {
getNavTitleCache()
message.info('重新获取标题缓存列表完成')
}
const current = framework.getCurrentMenuRoute()
watch(current, () => {
getNavTitleCache()
})
function refresh(){
clientId.value = framework.getTracker().clientId
token.value = security.getToken()
user.value = JSON.stringify(security.getUser().value, null, 2)
getNavTitleCache()
message.info('刷新完成')
}
onMounted(refresh)
watch(showPanel,()=>{
if (showPanel.value){
refresh()
}
})
</script>
<template>
<div class="hb-admin-dev-tool">
<div style="position: fixed;right: 10px;bottom: 10px;opacity: 0.6">
<n-button @click="handleOpen" type="info" size="small">DEV TOOL</n-button>
</div>
<div class="hb-dev-panel animate__animated animate__slideInUp" v-if="showPanel">
<n-card closable @close="handleClose" hoverable style="height: 100%" content-style="overflow:auto"
title="HAPPYBOOT DEV TOOL">
<n-space vertical>
<n-button @click="refresh">刷新全部数据</n-button>
<n-space vertical>
<n-tag>ClientId</n-tag>
<n-code :code="clientId" :hljs="hljs"></n-code>
<n-tag>Token</n-tag>
<n-code :code="token" :hljs="hljs"></n-code>
<n-tag>User Data</n-tag>
<div style="width: 100%;overflow: auto">
<n-code :code="user" :hljs="hljs" language="JavaScript"></n-code>
</div>
</n-space>
<n-tag>导航标题缓存&菜单</n-tag>
<n-space align="center">
<n-button type="info" @click="consoleMenu">输出菜单数据</n-button>
<n-button type="info" @click="consoleNav">输出导航数据</n-button>
<n-button type="info" @click="refreshList">重新获取标题缓存列表</n-button>
<n-button type="warning" @click="cleanCache">清空标题缓存</n-button>
</n-space>
<n-table :bordered="false" :single-line="false">
<thead>
<tr>
<th>页面ID</th>
<th>标题</th>
<th>游离态</th>
</tr>
</thead>
<tbody>
<tr v-for="e in cacheTitleList">
<td>{{ e.pageId }}</td>
<td>{{ e.title }}</td>
<td>
<n-tag type="success" v-if="e.isExist">
{{ e.isExist ? '否' : '是' }}
</n-tag>
<n-tag type="warning" v-else>
{{ e.isExist ? '否' : '是' }}
</n-tag>
</td>
</tr>
</tbody>
</n-table>
</n-space>
</n-card>
</div>
</div>
</template>


<style scoped>
.hb-admin-dev-tool {
z-index: 9999;
}
.hb-dev-panel {
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: 600px;
padding: 10px;
box-sizing: border-box;
}
</style>
10 changes: 4 additions & 6 deletions src/views/login/index.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<script setup>
import {theme} from "../../global/config";
import {
NConfigProvider,
NCard, NSpace, NInput, NForm, NFormItem, zhCN,
dateZhCN, NLayout, NButton, NIcon, useMessage
NCard, NSpace, NInput, NForm, NFormItem,
NLayout, NButton, NIcon, useMessage
} from 'naive-ui'
import {
LockOpenOutline, Person,LogoGithub,LogoWechat,LogoApple,QrCodeOutline
Expand Down Expand Up @@ -79,7 +77,7 @@ function onVideoBgError(){
</script>
<template>
<n-config-provider :theme="theme" :locale="zhCN" :date-locale="dateZhCN">
<div>
<img class="image-bg" v-if="!loadedVideoBg" src="/src/assets/bg-2.png"/>
<video @loadeddata="onVideoBgLoad" @error="onVideoBgError" class="bg-video" loop muted autoplay src="https://prod-streaming-video-msn-com.akamaized.net/2787cb8a-1de3-455d-82db-1b2ebfc6a2ba/53af17b5-5d5d-4a5d-bdb5-7fe03aaaeb79.mp4"></video>
<n-layout class="hb-admin-login" content-style="width:100%;opacity:0.8;">
Expand Down Expand Up @@ -132,7 +130,7 @@ function onVideoBgError(){
</n-card>
</n-space>
</n-layout>
</n-config-provider>
</div>
</template>
Expand Down
10 changes: 4 additions & 6 deletions src/views/quick-login/index.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<script setup>
import {theme} from "../../global/config";
import {
NConfigProvider,
NCard, NSpace, NAvatar, zhCN,
dateZhCN, NLayout, NButton, useMessage
NCard, NSpace, NAvatar,
NLayout, NButton, useMessage
} from 'naive-ui'
import {useRouter} from "vue-router";
Expand Down Expand Up @@ -34,7 +32,7 @@ function login() {
</script>
<template>
<n-config-provider :theme="theme" :locale="zhCN" :date-locale="dateZhCN">
<div>
<n-layout class="hb-admin-login" content-style="width:100%;backdrop-filter: blur(5px);opacity:0.8;">
<n-space vertical justify="center" align="center" style="height: 100%;width: 100%;">
<n-card hoverable class="hb-card animate__animated animate__fadeIn animate__slow">
Expand Down Expand Up @@ -64,7 +62,7 @@ function login() {
</n-card>
</n-space>
</n-layout>
</n-config-provider>
</div>
</template>
Expand Down
10 changes: 4 additions & 6 deletions src/views/recover/index.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<script setup>
import {theme} from "../../global/config";
import {
NConfigProvider,
NCard,NSpace,NInput,NForm,NFormItem, zhCN,
dateZhCN,NLayout,NButton,NIcon
NCard,NSpace,NInput,NForm,NFormItem,
NLayout,NButton,NIcon
} from 'naive-ui'
import {
MailOutline
} from "@vicons/ionicons5"
</script>
<template>
<n-config-provider :theme="theme" :locale="zhCN" :date-locale="dateZhCN">
<div>
<n-layout class="hb-admin-recover" content-style="width:100%;backdrop-filter: blur(5px);opacity:0.8;">
<n-space vertical justify="center" align="center" style="height: 100%;width: 100%">
<n-card title="通过邮箱地址重置密码" hoverable class="hb-card animate__animated animate__fadeIn animate__slow">
Expand All @@ -34,7 +32,7 @@ import {
</n-card>
</n-space>
</n-layout>
</n-config-provider>
</div>
</template>


Expand Down
9 changes: 3 additions & 6 deletions src/views/signup/index.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<script setup>
import {theme} from "../../global/config";
import {
NConfigProvider,
NCard,NSpace,NInput,NForm,NFormItem, zhCN,
dateZhCN,NLayout,NButton,NIcon
NCard,NSpace,NInput,NForm,NFormItem,NLayout,NButton,NIcon
} from 'naive-ui'
import {
LockOpenOutline,Person,MailOutline
Expand All @@ -13,7 +10,7 @@ import {useRouter} from "vue-router";
const router = useRouter()
</script>
<template>
<n-config-provider :theme="theme" :locale="zhCN" :date-locale="dateZhCN">
<div>
<n-layout class="hb-admin-signup" content-style="width:100%;backdrop-filter: blur(5px);opacity:0.8;">
<n-space vertical justify="center" align="center" style="height: 100%;width: 100%">
<n-card title="使用邮箱地址注册" hoverable class="hb-card animate__animated animate__fadeIn animate__slow">
Expand Down Expand Up @@ -54,7 +51,7 @@ const router = useRouter()
</n-card>
</n-space>
</n-layout>
</n-config-provider>
</div>
</template>


Expand Down

0 comments on commit 565d70b

Please sign in to comment.