h5样式
This commit is contained in:
216
schoolNewsWeb/src/components/base/MobileNavItem.vue
Normal file
216
schoolNewsWeb/src/components/base/MobileNavItem.vue
Normal file
@@ -0,0 +1,216 @@
|
||||
<template>
|
||||
<div class="mobile-nav-item">
|
||||
<!-- 有子菜单的情况 -->
|
||||
<template v-if="hasChildren">
|
||||
<div
|
||||
class="nav-item-content"
|
||||
:class="{ 'active': isActive }"
|
||||
@click="toggleExpanded"
|
||||
>
|
||||
<div class="nav-item-inner">
|
||||
<span class="nav-title">{{ menu.name }}</span>
|
||||
<el-icon class="expand-icon" :class="{ 'expanded': expanded }">
|
||||
<ArrowRight />
|
||||
</el-icon>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 子菜单 -->
|
||||
<transition name="submenu">
|
||||
<div
|
||||
class="submenu"
|
||||
v-if="expanded"
|
||||
>
|
||||
<MobileNavItem
|
||||
v-for="child in filteredChildren"
|
||||
:key="child.menuID"
|
||||
:menu="child"
|
||||
:level="level + 1"
|
||||
@menu-click="$emit('menu-click', $event)"
|
||||
/>
|
||||
</div>
|
||||
</transition>
|
||||
</template>
|
||||
|
||||
<!-- 没有子菜单的情况 -->
|
||||
<template v-else>
|
||||
<div
|
||||
class="nav-item-content"
|
||||
:class="{ 'active': isActive }"
|
||||
@click="handleClick"
|
||||
>
|
||||
<div class="nav-item-inner">
|
||||
<span class="nav-title">{{ menu.name }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import type { SysMenu } from '@/types';
|
||||
import { MenuType } from '@/types/enums';
|
||||
import { ArrowRight } from '@element-plus/icons-vue';
|
||||
|
||||
// 递归组件需要声明名称
|
||||
defineOptions({
|
||||
name: 'MobileNavItem'
|
||||
});
|
||||
|
||||
// Props
|
||||
interface Props {
|
||||
menu: SysMenu;
|
||||
level?: number;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
level: 0
|
||||
});
|
||||
|
||||
// Emits
|
||||
const emit = defineEmits<{
|
||||
'menu-click': [menu: SysMenu];
|
||||
}>();
|
||||
|
||||
// 状态 - 默认不展开
|
||||
const expanded = ref(false);
|
||||
|
||||
// Composition API
|
||||
const route = useRoute();
|
||||
|
||||
// 计算属性 - 显示NAVIGATION类型的子菜单
|
||||
const hasChildren = computed(() => {
|
||||
return props.menu.children &&
|
||||
props.menu.children.filter((child: SysMenu) => child.type === MenuType.NAVIGATION).length > 0;
|
||||
});
|
||||
|
||||
// 过滤后的子菜单(只显示NAVIGATION类型)
|
||||
const filteredChildren = computed(() => {
|
||||
if (!props.menu.children) return [];
|
||||
return props.menu.children.filter((child: SysMenu) => child.type === MenuType.NAVIGATION);
|
||||
});
|
||||
|
||||
const isActive = computed(() => {
|
||||
// 精确匹配当前路由
|
||||
if (route.path === props.menu.url) return true;
|
||||
|
||||
// 检查是否是子路由激活
|
||||
if (props.menu.children && props.menu.children.length > 0) {
|
||||
return props.menu.children.some(child => route.path === child.url);
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
// 方法
|
||||
function toggleExpanded() {
|
||||
if (hasChildren.value) {
|
||||
expanded.value = !expanded.value;
|
||||
}
|
||||
}
|
||||
|
||||
function handleClick() {
|
||||
if (props.menu.url && props.menu.type === MenuType.NAVIGATION) {
|
||||
emit('menu-click', props.menu);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.mobile-nav-item {
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.nav-item-content {
|
||||
position: relative;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
height: 48px;
|
||||
|
||||
&:hover {
|
||||
background-color: rgba(198, 40, 40, 0.05);
|
||||
}
|
||||
|
||||
&.active {
|
||||
background-color: #C62828;
|
||||
|
||||
.nav-item-inner {
|
||||
color: #FFFFFF;
|
||||
}
|
||||
|
||||
.expand-icon {
|
||||
color: #FFFFFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.nav-item-inner {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
height: 100%;
|
||||
padding: 0 20px;
|
||||
color: #141F38;
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.nav-title {
|
||||
flex: 1;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.expand-icon {
|
||||
font-size: 12px;
|
||||
transition: transform 0.3s ease, color 0.2s;
|
||||
color: #686868;
|
||||
|
||||
&.expanded {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
}
|
||||
|
||||
.submenu {
|
||||
margin: 4px 0;
|
||||
overflow: hidden;
|
||||
|
||||
.mobile-nav-item {
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.nav-item-content {
|
||||
.nav-item-inner {
|
||||
padding-left: 40px;
|
||||
font-size: 14px;
|
||||
font-weight: 400;
|
||||
color: #686868;
|
||||
}
|
||||
|
||||
&.active .nav-item-inner {
|
||||
color: #FFFFFF;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background-color: rgba(198, 40, 40, 0.08);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 动画效果 */
|
||||
.submenu-enter-active,
|
||||
.submenu-leave-active {
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.submenu-enter-from,
|
||||
.submenu-leave-to {
|
||||
opacity: 0;
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
</style>
|
||||
@@ -12,4 +12,5 @@ export { default as GenericSelector } from './GenericSelector.vue';
|
||||
export { default as TreeNode } from './TreeNode.vue';
|
||||
export { default as Notice } from './Notice.vue';
|
||||
export { default as ChangeHome } from './ChangeHome.vue';
|
||||
export { default as DynamicParamForm} from './DynamicParamForm.vue'
|
||||
export { default as DynamicParamForm} from './DynamicParamForm.vue'
|
||||
export { default as MobileNavItem } from './MobileNavItem.vue'
|
||||
Reference in New Issue
Block a user