简体中文
动态首页配置
indexConfig文件夹
这个文件夹里放的是动态首页的综管后台
基本逻辑
index.vue
是一个 Vue 3 组件,主要功能是展示一个标签页界面,允许用户在“系统介绍”和“业务板块”两个标签页之间切换。
applicationLink.vue
此文件主要用于管理应用链接,包含列表展示、新建、编辑和删除应用链接等功能
systemDesc.vue
此文件主要用于管理系统描述,包含列表展示、新建、编辑系统描述等功能。
businessPlate.vue
该文件主要用于管理业务板块,包含列表展示、新建、编辑和删除业务板块等功能。
代码分析
index.vue
html
<template>
<el-card class="indexConfig-container">
<!-- 标签页组件,通过 v-model 绑定当前激活的标签 -->
<el-tabs v-model="activeName" class="demo-tabs">
<!-- 使用 v-for 动态生成标签页 -->
<el-tab-pane
v-for="[key, tab] in Object.entries(TAB_OPTIONS)"
:key="key"
:label="tab.label"
:name="tab.key"
>
<!-- 根据当前激活的标签,动态渲染对应的组件 -->
<component :is="tab.component" v-if="activeName === tab.key" />
</el-tab-pane>
</el-tabs>
</el-card>
</template>html
<script setup>
// 导入 Vue 的 ref 函数
import { ref } from "vue";
// 导入自定义组件
import SystemDesc from "./systemDesc.vue";
import BusinessPlate from "./businessPlate.vue";
// 定义标签页选项配置
const TAB_OPTIONS = {
SYSTEM_DESC: {
label: "系统介绍",
key: "system-desc",
component: SystemDesc,
},
BUSINESS_PLATE: {
label: "业务板块",
key: "business-plate",
component: BusinessPlate,
},
};
// 使用 ref 定义响应式变量,初始激活的标签为“系统介绍”
const activeName = ref(TAB_OPTIONS.SYSTEM_DESC.key);
</script>html
<style scoped lang="scss">
.indexConfig-container {
// 设置左右外边距
margin-left: 20px;
margin-right: 20px;
// 设置容器高度为视口高度减去 200px
height: calc(100vh - 200px);
}
</style>applicationLink.vue
html
<template>
<!-- 应用链接列表对话框 -->
<el-dialog v-model="visibleLink" :title="businessItem.name + ' - 应用链接'" custom-class="application-link-table-dialog">
<div class="appUser_top">
<!-- 新建应用链接按钮 -->
<el-button type="primary" @click="addApplicationLink"> 新 建 </el-button>
</div>
<div class="content el-card" style="margin-top: 20px;">
<!-- 自定义表格组件,用于展示应用链接列表 -->
<TableComponent
ref="tableRef"
:table-list="state.tableData"
:options-button="optionButton"
:table-column-info="ApplicationLinkList"
@defaultPageData="getDefaultPage"
@updateData="setPageInfo"
:options-width="180"
>
</TableComponent>
</div>
<template #footer>
<!-- 关闭列表对话框按钮 -->
<span>
<el-button @click="visibleLink = false">取 消</el-button>
</span>
</template>
</el-dialog>
<!-- 新建或编辑应用链接对话框 -->
<el-dialog v-model="visible" :title="isAdd === 'add' ? '新建': '修改'" custom-class="application-link-dialog">
<el-form
ref="formRef"
:model="form"
:rules="rules"
class="m-auto mt-1"
>
<!-- 关联应用选择框 -->
<el-form-item label="关联应用" prop="applicationID">
<el-select
v-model="form.applicationID"
@change="appIDChange"
clearable
filterable
style="width: 100%">
<el-option
v-for="item in applicationList"
:key="item.ID"
:label="item.name"
:value="item.ID"
></el-option>
</el-select>
</el-form-item>
<!-- 应用名称输入框 -->
<el-form-item label="应用名称" prop="name">
<el-input v-model="form.name"></el-input>
</el-form-item>
<!-- 应用链接输入框 -->
<el-form-item label="应用链接" prop="link">
<el-input type="textarea" :rows="4" v-model="form.link"></el-input>
</el-form-item>
</el-form>
<template #footer>
<!-- 关闭和确认表单操作按钮 -->
<span>
<el-button @click="visible = false">取 消</el-button>
<el-button type="primary" @click="addOrEditBusinessPlate"> 确 定 </el-button>
</span>
</template>
</el-dialog>
</template>html
<script setup>
// 导入所需组件和函数
import TableComponent from "@/components/table/TableComponent.vue";
import {onMounted, onUnmounted, reactive, ref, shallowReactive, watch} from "vue";
import { setObjectValue, xtend} from "@/utils/common";
import {instanceToPlain} from "class-transformer";
import { getApplicationLinkApi, delApplicationLinkApi, addApplicationLinkApi, updateApplicationLinkApi } from "@/api/indexConfig";
import {ApplicationLinkList} from "@/view/superAdmin/defaultConfig";
import { ElMessage, ElMessageBox } from "element-plus";
import {emitter} from "@/utils/bus";
import {get} from "@/api";
import {setHTMLSize} from "../../../utils/rem";
// 定义响应式数据
const state = shallowReactive({
tableData: []
});
let businessItem = {};
// 表格分页相关
const tableRef = ref(null);
const pageInfo = ref(null);
// 表单相关
const isAdd = ref('');
const visibleLink = ref(false);
const visible = ref(false);
const formRef = ref(null);
const form = reactive({
applicationID: null,
name: '',
link: ''
});
// 表单验证规则
let rules = {
name: [{ required: true, message: '应用名称不能为空', trigger: 'blur' }]
};
// 关联应用列表
const applicationList = ref([]);
// 获取应用链接列表
const getApplicationLink = async () => {
const res = await getApplicationLinkApi(businessItem.ID, {});
state.tableData = res.data || [];
tableRef.value.setPageInfo({ total: res.data.length, page: 1, pageSize: 9999 });
}
// 设置分页信息并重新获取数据
const setPageInfo = arg => {
pageInfo.value = arg;
getApplicationLink();
};
// 初始化页数据
const getDefaultPage = page => {
pageInfo.value = page;
};
// 表格操作列按钮配置
const optionButton = [
{
link: true,
type: 'warning',
name: '编辑',
click: arg => {
isAdd.value = 'edit';
visible.value = true;
setObjectValue(form, arg);
form.id = arg.id;
if (!form.applicationID) {
form.applicationID = null;
}
},
},
{
link: true,
type: 'danger',
name: '删除',
click: arg => {
ElMessageBox.confirm(`删除应用链接 【${arg.name}】 ,删除后将不可恢复!`, '删除应用链接', {
confirmButtonText: '删 除',
cancelButtonText: '取 消',
type: 'warning',
center: true,
customClass: 'delMessageBox',
confirmButtonClass: 'delButtonClass',
}).then(async () => {
delApplicationLinkApi(businessItem.ID, arg.id).then(res => {
if (!(res instanceof Error)) {
ElMessage.success(`删除成功!`);
getApplicationLink();
}
});
});
},
},
];
// 新建应用链接
const addApplicationLink = () =>{
isAdd.value = 'add';
visible.value = true;
}
// 关联应用 ID 变化时更新表单数据
const appIDChange = () =>{
if(form.applicationID) {
for(let i = 0;i < applicationList.value.length;i++) {
if (applicationList.value[i].ID === form.applicationID) {
form.name = applicationList.value[i].name;
form.link = applicationList.value[i].callbackAddress;
break;
}
}
} else {
form.name = '';
form.link = '';
}
}
// 确认新建或编辑操作
const addOrEditBusinessPlate = () => {
formRef.value?.validate(async valid => {
if (valid) {
if (isAdd.value === 'add') {
if(!form.applicationID) {
delete form.applicationID;
}
addApplicationLinkApi(businessItem.ID, form).then(res => {
if (!(res instanceof Error)) {
ElMessage.success(`${res.msg}`);
visible.value = false;
getApplicationLink();
}
});
} else {
if(!form.applicationID) {
delete form.applicationID;
}
updateApplicationLinkApi(businessItem.ID, form.id, form).then(res => {
if (!(res instanceof Error)) {
ElMessage.success(`${res.msg}`);
visible.value = false;
getApplicationLink();
}
});
}
}
});
};
// 打开应用链接列表对话框
const openApplicationLinkDialog = (item) =>{
visibleLink.value = true;
businessItem = item;
getApplicationLink();
}
// 监听表单对话框显示状态
watch(
visible,
async () => {
if (!visible.value) {
form.applicationID = '';
form.name = '';
form.link = '';
} else {
let res = await get(
{
page: 1,
pageSize: 9999
},
"/general/app/"
);
applicationList.value = res.data?.list;
}
},
{ immediate: false },
);
// 监听事件总线的消息
emitter.on('application-link', openApplicationLinkDialog);
// 组件挂载时执行
onMounted(() =>{
// 此处无具体逻辑
})
// 组件卸载时移除事件监听
onUnmounted(() =>{
emitter.off('application-link', openApplicationLinkDialog);
})
</script>html
<style lang="scss" scoped>
// 隐藏分页组件
:deep(.paginationclass) {
display: none;
}
// 应用链接列表对话框样式
:deep(.application-link-table-dialog) {
width: 960px;
.content {
height: 460px;
}
}
// 新建或编辑应用链接对话框样式
:deep(.application-link-dialog) {
width: 560px;
.el-form {
max-width: 460px;
.el-form-item__label {
width: 100px;
}
}
}
</style>systemDesc.vue
html
<template>
<div>
<!-- 顶部操作栏,包含新建按钮 -->
<div class="appUser_top">
<el-button type="primary" @click="addSystemDesc"> 新 建 </el-button>
</div>
<!-- 表格展示区域 -->
<div class="mainHeight content el-card el-card__body">
<TableComponent
ref="tableRef"
:table-list="state.tableData"
:options-button="optionButton"
:table-column-info="SystemDescList"
@defaultPageData="getDefaultPage"
@updateData="setPageInfo"
:options-width="180"
>
<!-- 自定义 `isEnabled` 列,使用开关组件 -->
<template #isEnabled="{ data }">
<el-switch v-model="data.isEnabled" @change="isEnabledChange(data)"/>
</template>
<!-- 自定义 `image` 列,展示图片 -->
<template #image="{ data }">
<img :src="data.image ? simulationCover(data.image) :''" alt="" style="width: 192px;">
</template>
</TableComponent>
</div>
<!-- 新建或编辑对话框 -->
<el-dialog v-model="visible" :title="isAdd === 'add' ? '新建': '修改'" custom-class="system-desc-dialog">
<el-form
ref="formRef"
:model="form"
:rules="rules"
class="m-auto mt-1"
>
<!-- 描述输入框 -->
<el-form-item label="描述" prop="description">
<el-input type="textarea" :rows="9" v-model="form.description" :maxlength="186" show-word-limit></el-input>
</el-form-item>
<!-- 轮播图上传组件 -->
<el-form-item label="轮播图" prop="favicon">
<el-upload
action="#"
v-model:file-list="fileList"
ref="uploadRef"
list-type="picture-card"
:auto-upload="false"
:on-change="submitUpload"
>
<el-icon><Plus /></el-icon>
<template #file="{ file }">
<img
class="el-upload-list__item-thumbnail"
:src="file.url"
alt=""
/>
<span class="el-upload-list__item-actions">
<span class="el-upload-list__item-delete" @click="handleRemove">
<el-icon><Delete /></el-icon>
</span>
</span>
</template>
</el-upload>
</el-form-item>
<!-- 跳转链接输入框 -->
<el-form-item label="跳转链接" prop="link">
<el-input type="textarea" :rows="2" v-model="form.link"></el-input>
</el-form-item>
<!-- 是否启用开关 -->
<el-form-item label="是否启用" prop="isEnabled">
<el-switch v-model="form.isEnabled"/>
</el-form-item>
</el-form>
<!-- 对话框底部操作按钮 -->
<template #footer>
<span>
<el-button @click="visible = false">取 消</el-button>
<el-button type="primary" @click="addOrEditSystemDesc"> 确 定 </el-button>
</span>
</template>
</el-dialog>
</div>
</template>html
<script setup>
// 导入组件和函数
import TableComponent from "@/components/table/TableComponent.vue";
import {onMounted, reactive, ref, shallowReactive, watch} from "vue";
import {setObjectValue, xtend} from "@/utils/common";
import {instanceToPlain} from "class-transformer";
import {addSystemDescApi, delSystemDescApi, getSystemDescApi, updateSystemDescApi} from "@/api/indexConfig";
import {simulationCover, SystemDescList} from "@/view/superAdmin/defaultConfig";
import {ElMessage, ElMessageBox} from "element-plus";
import {Delete, Plus} from "@element-plus/icons-vue";
import {uploadFile} from "@/api/user";
// 定义响应式数据
// 表格数据
const state = shallowReactive({
tableData: []
});
// 表格引用和分页信息
const tableRef = ref(null);
const pageInfo = ref(null);
// 表单相关数据
const isAdd = ref('');
const visible = ref(false);
const formRef = ref(null);
const form = reactive({
description: '',
isEnabled: false,
image: '',
link: ''
});
// 表单验证规则
let rules = {
description: [{ required: true, message: '描述不能为空', trigger: 'blur' }]
};
// 文件列表和上传组件引用
const fileList = ref([]);
const uploadRef = ref();
// 处理文件上传
const handleUploadFile = async (file) => {
const data = new FormData();
data.append("file", file);
try {
const res = await uploadFile(data);
form.image = res.data.file_path;
} catch (error) {}
};
// 提交文件上传
const submitUpload = (file) => {
fileList.value = [file];
handleUploadFile(file.raw);
};
// 处理文件移除
const handleRemove = () => {
uploadRef.value.clearFiles();
form.headerImg = "";
};
// 获取系统介绍列表
const getSystemDesc = async () => {
const searchInfo = xtend(instanceToPlain(pageInfo.value));
const {
data: {list, page, pageSize, total},
} = await getSystemDescApi(searchInfo);
state.tableData = list || [];
tableRef.value.setPageInfo({page, pageSize, total});
};
// 设置分页信息并重新获取数据
const setPageInfo = arg => {
pageInfo.value = arg;
getSystemDesc();
};
// 初始化页数据
const getDefaultPage = page => {
pageInfo.value = page;
};
// 表格操作列按钮配置
const optionButton = [
{
link: true,
type: 'warning',
name: '编辑',
click: arg => {
isAdd.value = 'edit';
visible.value = true;
setObjectValue(form, arg);
form.ID = arg.ID;
},
},
{
link: true,
type: 'danger',
name: '删除',
click: arg => {
ElMessageBox.confirm(`删除系统介绍 【${arg.description}】 ,删除后将不可恢复!`, '删除系统介绍', {
confirmButtonText: '删 除',
cancelButtonText: '取 消',
type: 'warning',
center: true,
customClass: 'delMessageBox',
confirmButtonClass: 'delButtonClass',
}).then(async () => {
delSystemDescApi(arg.ID).then(res => {
if (!(res instanceof Error)) {
ElMessage.success(`删除成功!`);
getSystemDesc();
}
});
});
},
},
];
// 新建系统介绍
const addSystemDesc = () =>{
isAdd.value = 'add';
visible.value = true;
};
// 修改启用状态
const isEnabledChange = (arg) =>{
updateSystemDescApi(arg.ID, arg).then(res => {
if (!(res instanceof Error)) {
ElMessage.success(`${res.msg}`);
visible.value = false;
getSystemDesc();
}
});
};
// 确认新建或编辑操作
const addOrEditSystemDesc = () => {
formRef.value?.validate(async valid => {
if (valid) {
if (isAdd.value === 'add') {
addSystemDescApi(form).then(res => {
if (!(res instanceof Error)) {
ElMessage.success(`${res.msg}`);
visible.value = false;
getSystemDesc();
}
});
} else {
updateSystemDescApi(form.ID, form).then(res => {
if (!(res instanceof Error)) {
ElMessage.success(`${res.msg}`);
visible.value = false;
getSystemDesc();
}
});
}
}
});
};
// 监听对话框显示、隐藏,隐藏时重置表单
watch(
visible,
() => {
if (!visible.value) {
form.description = '';
form.isEnabled = false;
fileList.value = [];
}
},
{ immediate: false },
);
// 组件挂载时获取系统介绍列表
onMounted(() =>{
getSystemDesc();
})
</script>html
<style lang="scss" scoped>
:deep(.system-desc-dialog) {
width: 560px;
.el-form {
max-width: 460px;
.el-form-item__label {
width: 100px;
}
}
}
</style>businessPlate.vue
html
<template>
<div>
<!-- 顶部操作栏,新建按钮被注释 -->
<div class="appUser_top">
<!-- <el-button type="primary" @click="addBusinessPlate"> 新 建 </el-button>-->
</div>
<!-- 表格展示区域 -->
<div class="mainHeight content el-card el-card__body">
<TableComponent
ref="tableRef"
:table-list="state.tableData"
:options-button="optionButton"
:table-column-info="BusinessPlateList"
@defaultPageData="getDefaultPage"
@updateData="setPageInfo"
:options-width="240"
>
</TableComponent>
</div>
<!-- 新建或编辑对话框 -->
<el-dialog v-model="visible" :title="isAdd === 'add' ? '新建': '修改'" custom-class="business-plate-dialog">
<el-form
ref="formRef"
:model="form"
:rules="rules"
class="m-auto mt-1"
>
<!-- 业务板块名称输入框 -->
<el-form-item label="业务板块" prop="name">
<el-input v-model="form.name"></el-input>
</el-form-item>
<!-- 简介输入框 -->
<el-form-item label="简介" prop="introduction">
<el-input type="textarea" :rows="2" v-model="form.introduction" :maxlength="15" show-word-limit></el-input>
</el-form-item>
<!-- 描述输入框 -->
<el-form-item label="描述" prop="description">
<el-input type="textarea" :rows="6" v-model="form.description" :maxlength="120" show-word-limit></el-input>
</el-form-item>
</el-form>
<!-- 对话框底部操作按钮 -->
<template #footer>
<span>
<el-button @click="visible = false">取 消</el-button>
<el-button type="primary" @click="addOrEditBusinessPlate"> 确 定 </el-button>
</span>
</template>
</el-dialog>
<!-- 引入应用链接组件 -->
<ApplicationLink></ApplicationLink>
</div>
</template>html
<script setup>
// 导入所需组件和函数
import TableComponent from "@/components/table/TableComponent.vue";
import {onMounted, reactive, ref, shallowReactive, watch} from "vue";
import { setObjectValue, xtend} from "@/utils/common";
import {instanceToPlain} from "class-transformer";
import { getBusinessPlateApi, delBusinessPlateApi, addBusinessPlateApi, updateBusinessPlateApi } from "@/api/indexConfig";
import { BusinessPlateList} from "@/view/superAdmin/defaultConfig";
import { ElMessage, ElMessageBox } from "element-plus";
import ApplicationLink from '@/view/superAdmin/indexConfig/applicationLink.vue';
import {emitter} from "@/utils/bus";
// 定义响应式数据
// 表格数据
const state = shallowReactive({
tableData: []
});
// 表格引用和分页信息
const tableRef = ref(null);
const pageInfo = ref(null);
// 表单相关数据
const isAdd = ref('');
const visible = ref(false);
const formRef = ref(null);
const form = reactive({
name: '',
description: '',
introduction: '',
});
// 表单验证规则
let rules = {
name: [{ required: true, message: '业务板块不能为空', trigger: 'blur' }]
};
// 获取业务板块列表
const getBusinessPlate = async () => {
const searchInfo = xtend(instanceToPlain(pageInfo.value));
const {
data: {list, page, pageSize, total},
} = await getBusinessPlateApi(searchInfo);
state.tableData = list || [];
tableRef.value.setPageInfo({page, pageSize, total});
}
// 设置分页信息并重新获取数据
const setPageInfo = arg => {
pageInfo.value = arg;
getBusinessPlate();
};
// 初始化页数据
const getDefaultPage = page => {
pageInfo.value = page;
};
// 表格操作列按钮配置
const optionButton = [
{
link: true,
type: 'primary',
name: '应用链接',
click: arg => {
emitter.emit('application-link', arg);
},
},
{
link: true,
type: 'warning',
name: '编辑',
click: arg => {
isAdd.value = 'edit';
visible.value = true;
setObjectValue(form, arg);
form.ID = arg.ID;
},
},
// 删除按钮被注释
// {
// link: true,
// type: 'danger',
// name: '删除',
// click: arg => {
// ElMessageBox.confirm(`删除业务板块 【${arg.description}】 ,删除后将不可恢复!`, '删除业务板块', {
// confirmButtonText: '删 除',
// cancelButtonText: '取 消',
// type: 'warning',
// center: true,
// customClass: 'delMessageBox',
// confirmButtonClass: 'delButtonClass',
// }).then(async () => {
// delBusinessPlateApi(arg.ID).then(res => {
// if (!(res instanceof Error)) {
// ElMessage.success(`删除成功!`);
// getBusinessPlate();
// }
// });
// });
// },
// },
];
// 新建业务板块
const addBusinessPlate = () =>{
isAdd.value = 'add';
visible.value = true;
}
// 确认新建或编辑操作
const addOrEditBusinessPlate = () => {
formRef.value?.validate(async valid => {
if (valid) {
if (isAdd.value === 'add') {
addBusinessPlateApi(form).then(res => {
if (!(res instanceof Error)) {
ElMessage.success(`${res.msg}`);
visible.value = false;
getBusinessPlate();
}
});
} else {
updateBusinessPlateApi(form.ID, form).then(res => {
if (!(res instanceof Error)) {
ElMessage.success(`${res.msg}`);
visible.value = false;
getBusinessPlate();
}
});
}
}
});
};
// 监听对话框显示、隐藏,隐藏时重置表单
watch(
visible,
() => {
if (!visible.value) {
form.name = '';
form.description = '';
form.introduction = '';
}
},
{ immediate: false },
);
// 组件挂载时获取业务板块列表
onMounted(() =>{
getBusinessPlate();
})
</script>html
<style lang="scss" scoped>
:deep(.business-plate-dialog) {
width: 560px;
.el-form {
max-width: 460px;
.el-form-item__label {
width: 80px;
}
}
}
</style>zgIndex.vue文件夹
只有一个 index.vue 文件
基本逻辑
从代码来看,这是一个 Vue 3的单文件组件,作为整个系统的首页展示。以下是它的基本逻辑分析:
- 页面结构:
- 顶部有固定导航栏(
zg-index-header) - 中间是轮播图区域(
zg-index-banner) - 下方分为4个主要业务板块:
- 人才培养
- 跨域互联
- 漏洞挖掘
- 安全测试
- 底部有页脚信息
- 顶部有固定导航栏(
- 核心功能逻辑:
- 数据获取:在
onMounted生命周期中,通过API获取系统介绍(getSystemDescFilterApi)和业务板块详情(getBusinessPlateDetailApi) - 权限控制:检查cookie中的
sso_token判断用户登录状态,并根据用户权限(userApps)控制不同功能模块的访问 - 导航交互:
- 顶部导航栏有搜索、用户头像下拉菜单
- 中间区域有锚点导航,点击可平滑滚动到对应板块
- 各业务板块有hover效果和点击跳转
- 数据获取:在
- 主要业务逻辑:
- 人才培养:展示5个子模块(培训教学、竞技实训等),根据权限控制访问
- 跨域互联:展示系统介绍和查看详情入口
- 漏洞挖掘:展示4个安全系统入口
- 安全测试:展示11种安全测试工具入口
这个页面作为系统门户,集成了各主要业务入口,并通过动态数据展示和权限控制提供了良好的用户体验。
代码分析
index.vue
以下只是粗略分析因为这个页面字符太多了
html
<script setup>
// 1. 导入资源部分
// 导入各种图片资源和组件
import talentIcon from '@/assets/datang/banner-talent.png';
import crossIcon from '@/assets/datang/banner-cross.png';
// ...其他图片导入
import { onMounted, onUnmounted, ref } from "vue";
import Search from "@/view/layout/search/search.vue";
// ...其他组件导入
// 2. 路由和状态管理
const router = useRouter();
const userStore = useUserStore()
// 3. 页面数据定义部分
// 顶部导航栏引用
const zgIndexHeaderRef = ref();
// 页面基础信息
const infoData = ref(DATAINFO);
// 轮播图数据
const baseInfoArr = ref([]);
// 4. 业务板块数据定义
// 顶部导航按钮数据
const bannerArr = ref([
{ name: '人才培养', desc: '', href: '#talentId', icon: talentIcon },
// ...其他导航项
]);
// 人才培养模块数据
const trainArr = ref([
{ name: '培训教学', desc: '', href: `#`, icon: trainIcon, iconActive: trainIconActive },
// ...其他子项
])
// 5. 交互逻辑部分
// 人才培养模块hover效果
const talentHover = (index, item) => {
// ...权限判断逻辑
talentCurrentIndex.value = index;
}
// 锚点滚动功能
const scrollToSection = (href) => {
// ...滚动实现
}
// 6. 生命周期钩子
onMounted(() => {
// 初始化逻辑
// 获取用户信息
// 获取系统介绍数据
// 获取业务板块详情
})
// 7. 工具函数
// 数组匹配替换工具
const matchArrItemReplace = (sourceArr, matchField, matchStr, replaceField, replaceStr) => {
// ...实现逻辑
}
</script>
<template>
<!-- 1. 顶部导航栏 -->
<div class="zg-index-header">
<!-- ...导航栏内容 -->
</div>
<!-- 2. 轮播图区域 -->
<div class="zg-index-banner">
<!-- ...轮播图内容 -->
</div>
<!-- 3. 人才培养板块 -->
<div class="zg-index-talent-cultivation" id="talentId">
<!-- ...人才培养内容 -->
</div>
<!-- 4. 跨域互联板块 -->
<div class="zg-index-cross-domain" id="crossId">
<!-- ...跨域互联内容 -->
</div>
<!-- 5. 漏洞挖掘板块 -->
<div class="zg-index-vulnerability-exploration" id="vulnerabilityIId">
<!-- ...漏洞挖掘内容 -->
</div>
<!-- 6. 安全测试板块 -->
<div class="zg-index-security-testing" id="securityId">
<!-- ...安全测试内容 -->
</div>
<!-- 7. 页脚 -->
<div class="zg-index-footer">
<!-- ...页脚内容 -->
</div>
</template>
<style scoped lang="scss">
/* 1. 整体容器样式 */
.zg-index-container {
/* ... */
}
/* 2. 顶部导航栏样式 */
.zg-index-header {
/* ... */
}
/* 3. 轮播图区域样式 */
.zg-index-banner {
/* ... */
}
/* 4. 各业务板块公共样式 */
.zg-index-title-container {
/* 标题统一样式 */
}
/* 5. 人才培养板块特定样式 */
.zg-index-talent-cultivation {
/* ... */
}
/* 6. 其他业务板块样式... */
</style>俩页面数据关联
indexConfig文件夹与zgIndex.vue主要通过API调用关联起来。具体关联方式如下:
API定义部分(
src\api\indexConfig):index.js文件:
jsx// 定义获取业务板块详情的API export const getBusinessPlateDetailApi = () => { return request({ url: '/general/system/businessPlate/detail', method: 'get' }) } // 定义获取系统介绍的API export const getSystemDescFilterApi = () => { return request({ url: '/general/system/desc/filter', method: 'get' }) }组件调用部分(
src\view\zgIndex):index.vue
jsx// 导入API import { getBusinessPlateDetailApi, getSystemDescFilterApi } from "@/api/indexConfig"; // 在onMounted生命周期中调用 onMounted(() => { // 获取系统介绍 getSystemDescFilterApi().then(res => { // 处理返回数据... }); // 获取业务板块详情 getBusinessPlateDetailApi().then(res => { // 处理返回数据... }); })数据流关联:
zgIndex.vue作为首页组件,通过调用indexConfig中定义的API获取配置数据- 获取的数据用于渲染:
- 轮播图内容(baseInfoArr)
- 四大业务板块信息(人才培养/跨域互联/漏洞挖掘/安全测试)
- 各板块下的子模块链接
功能实现:
indexConfig提供后端接口的抽象层zgIndex.vue负责数据获取和界面渲染- 通过Pinia/Vuex管理共享状态(如用户权限信息)
这种设计遵循了前后端分离的原则,使配置数据的获取与界面渲染解耦,便于维护和扩展。
