简体中文
主要页面逻辑
这个 Vue 文件是一个企业级首页组件,包含头部导航、轮播横幅、多个业务板块展示和页脚。以下是核心部分的详细解析:
1. 头部区域 (zg-index-header)
html
<div class="zg-index-header" ref="zgIndexHeaderRef">
<!-- 企业Logo -->
<img :src="infoData.logo" v-show="!imgLoading">
<!-- 右侧功能区 -->
<div class="right-box">
<!-- 大屏跳转按钮(仅管理员可见) -->
<el-tooltip v-if="getCookieValue('sso_token') ? isSuper : false">
<img @click="toScreen" src="bigscreen.png">
</el-tooltip>
<!-- 搜索组件 -->
<Search />
<!-- 用户下拉菜单 -->
<el-dropdown>
<span class="header-avatar">
<CustomPic /> <!-- 自定义头像组件 -->
<span>{{ userStore.userInfo.nickName }}</span>
<el-icon><arrow-down /></el-icon>
</span>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item @click="loginIn" v-if="!getCookieValue('sso_token')">登入</el-dropdown-item>
<el-dropdown-item @click="userStore.LoginOut" v-else>登出</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
</div>- 功能:
- 显示企业 Logo(
infoData.logo) - 管理员可见的大屏跳转入口(
toScreen) - 集成搜索功能(
Search组件) - 用户登录/登出控制(依赖
sso_token和userStore)
- 显示企业 Logo(
- 技术点:
ref="zgIndexHeaderRef"可用于获取头部 DOM(如计算高度)- 条件渲染(
v-if、v-show)控制元素显隐
2. 横幅区域 (zg-index-banner)
html
<div class="zg-index-banner" ref="zgIndexBanner">
<!-- 主标题 -->
<div class="zg-index-main-title">{{ infoData.indexTitle }}</div>
<!-- 文字轮播(ElCarousel) -->
<el-carousel @change="carouselChange">
<el-carousel-item v-for="item in baseInfoArr">
<pre v-if="item.desc.includes('\n')">{{ item.desc }}</pre>
<span v-else>{{ item.desc }}</span>
<a @click="baseInfoJump(item)">查看详情 ></a>
</el-carousel-item>
</el-carousel>
<!-- 快速导航入口 -->
<div class="zg-index-banner-target">
<a
v-for="item in bannerArr"
@click.prevent="scrollToSection(item.href)"
>
<img :src="item.icon">
<div>
<div class="name">{{ item.name }}</div>
<div class="desc">{{ item.desc }}</div>
</div>
</a>
</div>
</div>- 功能:
- 展示企业主标题(
infoData.indexTitle) - 文字轮播(
baseInfoArr数据驱动,支持换行显示) - 四个快捷入口(
bannerArr),点击平滑滚动到对应板块
- 展示企业主标题(
- 技术点:
@click.prevent阻止默认跳转,改用scrollToSection实现锚点滚动el-carousel的@change事件监听轮播切换
3. 业务板块(人才培养/跨域互联/漏洞挖掘/安全测试)
通用结构
html
<div class="zg-index-talent-cultivation" id="talentId">
<!-- 标题+下划线 -->
<div class="zg-index-title-container">
<div class="zg-index-title">
<span>人才培养</span>
<div class="zg-index-title-underLine"></div>
</div>
</div>
<!-- 描述文本 -->
<div class="zg-index-desc">{{ businessPlateObj['人才培养'].description }}</div>
<!-- 子功能入口 -->
<div class="zg-index-talent-target">
<div
v-for="(item, index) in trainArr"
@mouseenter="talentHover(index, item)"
@click="zgIndexJump(item)"
:class="{ 'active': talentCurrentIndex === index }"
:style="{ cursor: item.disabled ? 'not-allowed' : 'pointer' }"
>
<img :src="item.iconActive">
<div class="name">{{ item.name }}</div>
<div class="desc">{{ item.desc }}</div>
</div>
</div>
</div>- 功能:
- 每个板块有统一标题样式(下划线动画)
- 显示业务描述(从
businessPlateObj动态获取) - 多个子功能入口(如
trainArr、vulnerabilityArr等),支持:- 悬停高亮(
@mouseenter) - 点击跳转(
zgIndexJump) - 权限控制(如
userApps.includes(item.appKey))
- 悬停高亮(
- 技术点:
id="talentId"用于锚点定位(被scrollToSection使用)- 动态样式(
:class、:style)控制交互状态
4. 页脚 (zg-index-footer)
html
<div class="zg-index-footer">
<span>{{ infoData.footer }}</span>
</div>- 简单显示版权信息(从
infoData.footer获取)
核心交互逻辑
权限控制
- 通过
getCookieValue('sso_token')判断登录状态 userApps控制用户能访问的子功能(如item.appKey校验)
- 通过
滚动定位
jsxfunction scrollToSection(href) { // 示例:滚动到 #talentId document.querySelector(href)?.scrollIntoView({ behavior: 'smooth' }); }数据驱动
- 所有内容通过
infoData、businessPlateObj、bannerArr等响应式数据渲染
- 所有内容通过
总结
这是一个典型的企业门户首页,包含:
- 响应式布局(适应不同屏幕)
- 模块化设计(头部、横幅、业务板块、页脚)
- 丰富的交互(轮播、悬停、权限跳转、平滑滚动)
- Vue 3 特性:Composition API、
ref操作 DOM、条件渲染等
如果需要优化或扩展(如 SEO 适配、移动端响应),可以进一步讨论!
