隐藏路由

This commit is contained in:
洛洛希雅Lolosia 2023-06-25 17:20:52 +08:00
parent 1710ca21e6
commit 959cf74392
6 changed files with 145 additions and 29 deletions

View File

@ -30,14 +30,24 @@
<!-- <SizeSelect />--> <!-- <SizeSelect />-->
<!-- <LangSelect />--> <!-- <LangSelect />-->
<el-dropdown trigger="click" size="default"> <el-dropdown trigger="click" size="default">
<div class="avatar-wrapper" :title="(userInfo?.realName || userInfo?.username) + ' - 在线'"> <div class="avatar-wrapper" :title="(userInfo?.realName || userInfo?.userName) + ' - 在线'">
<img :src="userInfo.avatar ?? userImage" alt="用户头像" class="user-avatar" /> <img :src="userInfo.avatar ?? userImage" alt="用户头像" class="user-avatar" />
<div class="user-avatar-status" /> <div class="user-avatar-status" :style="{backgroundColor: !online ? 'red' : null}">
<el-popover :visible="!online" :effect="'dark'" :width="170">
<template #reference>
<div />
</template>
<div class="online-status">
<menu-icon icon="exclamation-triangle-fill" />
<span>与服务器连接中断</span>
</div>
</el-popover>
</div>
</div> </div>
<template #dropdown> <template #dropdown>
<el-dropdown-menu class="drop-down"> <el-dropdown-menu class="drop-down">
<el-dropdown-item class="welcome-user"> <el-dropdown-item class="welcome-user">
{{ time }}<b>{{ userInfo.realName || userImage.username || "平台用户" }}</b> {{ time }}<b>{{ userInfo.realName || userImage.userName || "平台用户" }}</b>
</el-dropdown-item> </el-dropdown-item>
<router-link to="/"> <router-link to="/">
<el-dropdown-item divided>{{ langTitle("Home") }}</el-dropdown-item> <el-dropdown-item divided>{{ langTitle("Home") }}</el-dropdown-item>
@ -71,9 +81,12 @@ import { useBasicStore } from "@/store/basic";
import { langTitle } from "@/hooks/use-common"; import { langTitle } from "@/hooks/use-common";
import userImage from "@/assets/layout/user.png"; import userImage from "@/assets/layout/user.png";
import Debugger from "@/layout/default/app-main/component/Debugger.vue"; import Debugger from "@/layout/default/app-main/component/Debugger.vue";
import MenuIcon from "@/components/MenuIcon.vue";
import { useDebuggerStore } from "@/store/debuger";
const basicStore = useBasicStore(); const basicStore = useBasicStore();
const { settings, sidebar, setToggleSideBar, userInfo } = basicStore; const { settings, sidebar, setToggleSideBar, userInfo } = basicStore;
const online = toRef(basicStore, "online");
const toggleSideBar = () => { const toggleSideBar = () => {
setToggleSideBar(); setToggleSideBar();
@ -123,6 +136,21 @@ watch(() => basicStore.navbar.cursor, () => {
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.online-status {
display: flex;
align-items: center;
.menu-icon {
color: gold;
margin-right: 0.5em;
}
span {
color: red;
}
}
.navbar { .navbar {
height: var(--nav-bar-height); height: var(--nav-bar-height);
overflow: hidden; overflow: hidden;

View File

@ -1,34 +1,117 @@
<template> <template>
<div class="debugger" title="调试器"> <div class="debugger" title="调试器">
<el-button class="btn" type="primary" link @click="data.dialog = true"> <el-button v-if="store.enable" class="btn" type="primary" link @click="data.dialog = true">
<menu-icon icon="bug-fill" /> <menu-icon icon="bug-fill" />
</el-button> </el-button>
<el-dialog v-model="data.dialog" :append-to-body="true" title="Debugger" :width="600"> <el-dialog v-if="data.dialog" v-model="data.dialog" :append-to-body="true" title="调试工具" :width="600">
<div> <div class="debugger-items">
显示调试网格 <p>UI</p>
<el-switch v-model="showLayoutGrid" /> <div class="switch-item">
<p>显示页面布局网格</p>
<el-switch v-model="ui.showLayoutGrid" />
</div>
<hr />
<p>消息面板</p>
<div class="switch-item">
<p>始终显示消息面板</p>
<el-switch v-model="messageFrame.alwaysShow" />
</div>
<div class="switch-item">
<p>页面变更时打印间隔消息</p>
<el-switch v-model="messageFrame.showPageSwitchMsg" />
</div>
<hr />
<p>网络</p>
<div class="switch-item">
<p>打印网络请求至消息面板</p>
<el-switch v-model="network.printMsg.enable" />
</div>
<template v-if="network.printMsg.enable">
<div class="switch-item">
<p>> 显示请求时间</p>
<el-switch v-model="network.printMsg.showTime" />
</div>
<div class="switch-item">
<p>> 等待消息面板显示</p>
<el-switch v-model="network.printMsg.waitMessageFrameShow" />
</div>
</template>
</div> </div>
</el-dialog> </el-dialog>
<div v-if="showLayoutGrid" v-html="data.gridHtml" /> <div v-if="ui.showLayoutGrid" v-html="data.gridHtml" />
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import MenuIcon from "@/components/MenuIcon.vue"; import MenuIcon from "@/components/MenuIcon.vue";
import { useDebuggerStore } from "@/store/debuger"; import { useDebuggerStore } from "@/store/debuger";
import bus from "@/utils/bus";
const store = useDebuggerStore() const store = useDebuggerStore();
const {showLayoutGrid} = storeToRefs(store) const { ui, network, messageFrame } = storeToRefs(store);
const data = reactive({ const data = reactive({
dialog: false, dialog: false,
gridHtml: `<style>*{ box-shadow: 0 0 1px 0 blue }</style>` gridHtml: `<style>*{ box-shadow: 0 0 1px 0 blue }</style>`
}); });
function onDebuggerShow() {
data.dialog = true;
}
onMounted(() => {
bus.on("debugger:show", onDebuggerShow);
});
onUnmounted(() => {
bus.off("debugger:show", onDebuggerShow);
});
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.debugger {
margin-left: 0 !important;
.btn { .btn {
margin-left: 1em;
padding: 0.3em !important; padding: 0.3em !important;
} }
}
.debugger-items {
padding: 0 2em 0 2em;
position: relative;
> p {
position: relative;
left: -0.5em;
margin: 0.5em 0 0.5em 0;
color: gray;
}
> hr {
margin: 1em 0 0 0;
}
.switch-item {
display: flex;
align-items: center;
color: black;
> p {
display: block;
flex-grow: 1;
margin: 0;
line-height: 2em;
font-size: 1.1em;
}
.el-switch {
position: relative;
transform: scale(1.4);
right: 2em;
}
}
}
</style> </style>

View File

@ -15,12 +15,12 @@
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts" name="AppMain">
import { computed, watch } from 'vue' import { computed, watch } from 'vue'
import { storeToRefs } from 'pinia/dist/pinia' import { storeToRefs } from 'pinia/dist/pinia'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import type { RouteLocationMatched } from 'vue-router' import type { RouteLocationMatched } from 'vue-router'
import type { rawConfig } from '~/basic' import type { RawConfig, RouteRawConfig } from "~/basic";
import { useBasicStore } from '@/store/basic' import { useBasicStore } from '@/store/basic'
import { cloneDeep } from '@/hooks/use-common' import { cloneDeep } from '@/hooks/use-common'
const { settings, cachedViews } = storeToRefs(useBasicStore()) const { settings, cachedViews } = storeToRefs(useBasicStore())
@ -29,7 +29,7 @@ const key = computed(() => route.path)
/*listen the component name changing, then to keep-alive the page*/ /*listen the component name changing, then to keep-alive the page*/
// cachePage: is true, keep-alive this Page // cachePage: is true, keep-alive this Page
// leaveRmCachePage: is true, keep-alive remote when page leave // leaveRmCachePage: is true, keep-alive remote when page leave
let oldRoute: rawConfig = {} let oldRoute: RouteRawConfig = {} as any
let deepOldRouter: RouteLocationMatched | null = null let deepOldRouter: RouteLocationMatched | null = null
const basicStore = useBasicStore() const basicStore = useBasicStore()
const removeDeepChildren = (deepOldRouter) => { const removeDeepChildren = (deepOldRouter) => {

View File

@ -10,7 +10,7 @@
</div> </div>
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts" name="DefaultLayout">
import { computed } from 'vue' import { computed } from 'vue'
import Sidebar from './sidebar/index.vue' import Sidebar from './sidebar/index.vue'
import AppMain from './app-main/index.vue' import AppMain from './app-main/index.vue'

View File

@ -28,8 +28,8 @@
import { ref } from 'vue' import { ref } from 'vue'
import { resolve } from 'path-browserify' import { resolve } from 'path-browserify'
import Link from './Link.vue' import Link from './Link.vue'
import MenuIcon from '../../../components/MenuIcon.vue' import MenuIcon from '@/components/MenuIcon.vue'
import type { RouteRawConfig } from '~/basic' import type { RouteRawConfig, RouterTypes } from '~/basic'
import { isExternal } from '@/hooks/use-layout' import { isExternal } from '@/hooks/use-layout'
import { langTitle } from '@/hooks/use-common' import { langTitle } from '@/hooks/use-common'
@ -52,13 +52,13 @@ const props = defineProps({
}) })
//sidebarItem //sidebarItem
const onlyOneChild = ref() const onlyOneChild = ref()
const showSidebarItem = (children = [], parent) => { const showSidebarItem = (children: RouterTypes = [], parent: RouteRawConfig) => {
const showingChildren = children.filter((item: RouteRawConfig) => { if (parent.expand === false) {
if (item.hidden) { onlyOneChild.value = { ...parent, path: '', noChildren: true }
return false
} else {
return true return true
} }
const showingChildren = children.filter((item) => {
return !item.hidden
}) })
if (showingChildren.length === 1 && !parent?.alwaysShow) { if (showingChildren.length === 1 && !parent?.alwaysShow) {
onlyOneChild.value = showingChildren[0] onlyOneChild.value = showingChildren[0]
@ -80,3 +80,9 @@ const resolvePath = (routePath) => {
return resolve(props.basePath, routePath) return resolve(props.basePath, routePath)
} }
</script> </script>
<style scoped lang="scss">
:deep(.el-menu-item.is-active) {
text-shadow: 1px 1px 0 #ffffff88;
}
</style>

View File

@ -17,8 +17,7 @@
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts" name="SideBar">
import { computed } from 'vue'
import { storeToRefs } from 'pinia/dist/pinia' import { storeToRefs } from 'pinia/dist/pinia'
import { useRoute } from "vue-router"; import { useRoute } from "vue-router";
import Logo from './Logo.vue' import Logo from './Logo.vue'