本案例主要是实现数据模型的解析以及实现el-table的动态列加载。

1.数据结构

 公司A\B\C\测试1,是列,功能-url,是行数据,其中功能x是行头。

      this.rawData = [{companyName: "公司A",rpWebShows: [{ "功能1": "https://map.baidu.com/" },{ "功能2": "https://map.baidu.com/" },{ "功能3": "https://map.baidu.com/" }]},{companyName: "公司B",rpWebShows: [{ "功能1": "https://map.baidu.com/" },{ "功能3": "https://map.baidu.com/" },{ "功能4": "https://map.baidu.com/" }]},{companyName: "公司C",rpWebShows: [{ "功能2": "https://map.baidu.com/" },{ "功能3": "https://map.baidu.com/" },{ "功能5": "https://map.baidu.com/" }]},{companyName: "测试1",rpWebShows: [{ "功能1": "https://map.baidu.com/" },{ "功能2": "https://map.baidu.com/" },{ "功能5": "https://map.baidu.com/" }]}]this.companyList = this.rawData.map(item => item.companyName).filter(company => !this.companyList2.includes(company))this.displayCompanyList = [...this.companyList]this.filteredData = this.rawDatathis.loading = false},

2.初始化el-table

 采用v-solt的定义el-table内的结构,并命名为scope,采用v-for语法,实现将companyList2和displayCompanyList内的数据,转换为列。

  <el-table v-loading="loading" border :data="tableData" style="width: 100%" :header-cell-style="{background:'#f5f7fa',color:'#606266'}"><el-table-column prop="functionName" label="功能名称" width="120" fixed/><el-table-column prop="functionName2" label="功能名称2" width="120" fixed/><!-- 动态渲染测试列(companyList2) --><el-table-column v-for="(label, index) in companyList2" :key="index" :label="label" :width="120"><template v-slot="scope"><div class="clickable-cell2" @click="handleCellClick(scope.row.functionName, label, scope.row[`test${index + 1}`])">{{ scope.row[`test${index + 1}`] || '/' }}</div></template></el-table-column><el-table-column v-for="company in displayCompanyList" :key="company" :label="company" :prop="company"><template v-slot="scope"><div v-if="scope.row[company]" class="clickable-cell" @click="openContentWindow(scope.row.functionName, company, scope.row[company])">{{ scope.row[company] }}</div><div v-else>-</div></template></el-table-column></el-table>

3.数据解析

  computed: {tableData() {const data = this.filteredData !== null ? this.filteredData : this.rawDataif (!data || !Array.isArray(data)) return []const allFunctions = new Set()data.forEach(company => {if (company.rpWebShows && Array.isArray(company.rpWebShows)) {company.rpWebShows.forEach(item => {const functionName = Object.keys(item)[0]if (functionName) allFunctions.add(functionName)})}})this.functionList = Array.from(allFunctions)const result = []this.functionList.forEach(func => {const row = { functionName: func, functionName2: `${func}2` }this.companyList2.forEach((label, index) => {const testCompanyData = data.find(item => item.companyName === label)if (testCompanyData && testCompanyData.rpWebShows) {const funcData = testCompanyData.rpWebShows.find(item => Object.keys(item)[0] === func)row[`test${index + 1}`] = funcData ? funcData[func] : null} else {row[`test${index + 1}`] = null}})this.displayCompanyList.forEach(company => {const companyData = data.find(item => item.companyName === company)if (companyData && companyData.rpWebShows) {const funcData = companyData.rpWebShows.find(item => Object.keys(item)[0] === func)row[company] = funcData ? funcData[func] : null} else {row[company] = null}})result.push(row)})return result}}

4.附件1(数据模型)

<template><div class="app-container"><div style="margin-bottom: 16px; display: flex; align-items: center;"><span style="margin-right: 8px;">公司名称</span><el-select v-model="searchCompany" placeholder="请选择" clearable style="width: 200px; margin-right: 8px;"><el-optionv-for="company in companyList":key="company":label="company":value="company"/></el-select><el-button type="primary" @click="handleSearch">搜索</el-button><el-button @click="handleReset" style="margin-left: 8px;">重置</el-button></div><el-table v-loading="loading" :data="tableData" border style="width: 100%":header-cell-style="{background:'#f5f7fa',color:'#606266'}"><el-table-column prop="functionName" label="功能名称" width="120" fixed/><el-table-column v-for="company in displayCompanyList" :key="company" :label="company" :prop="company"><template v-slot="scope"><div v-if="scope.row[company]" class="clickable-cell" @click="openContentWindow(scope.row.functionName, company, scope.row[company])">{{ scope.row[company] }}</div><div v-else></div></template></el-table-column></el-table></div>
</template><script>
export default {name: "FunctionUrlMatrix",data() {return {loading: false,companyList: [],functionList: [],rawData: null,searchCompany: '',filteredData: null,displayCompanyList: []}},computed: {tableData() {const data = this.filteredData !== null ? this.filteredData : this.rawData;if (!data) return [];const result = []; this.functionList.forEach(func => {const row = { functionName: func };this.companyList.forEach(company => {const companyData = data.find(item => item.companyName === company);if (companyData && companyData.rpWebShows) {const funcData = companyData.rpWebShows.find(item => item.requestName === func);row[company] = funcData ? funcData.requestUrl : null;} else {row[company] = null;}});result.push(row);});return result;}},created() {this.loadData();},methods: {loadData() {this.loading = true;// 使用本地模拟数据替代API请求this.rawData = [{companyName: "公司A",rpWebShows: [{ requestName: "功能1", requestUrl: "https://company-a.com/func1" },{ requestName: "功能2", requestUrl: "https://company-a.com/func2" },{ requestName: "功能3", requestUrl: "https://company-a.com/func3" }]},{companyName: "公司B",rpWebShows: [{ requestName: "功能1", requestUrl: "https://company-b.com/func1" },{ requestName: "功能3", requestUrl: "https://company-b.com/func3" },{ requestName: "功能4", requestUrl: "https://company-b.com/func4" }]},{companyName: "公司C",rpWebShows: [{ requestName: "功能2", requestUrl: "https://company-c.com/func2" },{ requestName: "功能3", requestUrl: "https://company-c.com/func3" },{ requestName: "功能5", requestUrl: "https://company-c.com/func5" }]}];this.extractCompanyAndFunctionList();this.loading = false;this.filteredData = this.rawData;},extractCompanyAndFunctionList() {if (!this.rawData || !Array.isArray(this.rawData)) {console.error('无效的数据结构:', this.rawData);return;}this.companyList = this.rawData.map(item => item.companyName).filter(Boolean);this.displayCompanyList = [...this.companyList];const allFunctions = new Set();this.rawData.forEach(company => {if (company.rpWebShows && Array.isArray(company.rpWebShows)) {company.rpWebShows.forEach(func => {if (func && func.requestName) {allFunctions.add(func.requestName);}});console.log(allFunctions);} else {console.warn('公司数据缺少rpWebShows或格式不正确:', company);}});this.functionList = Array.from(allFunctions);console.log("111111111");console.log(this.functionList);},handleSearch() {if (!this.searchCompany) {this.filteredData = this.rawData;this.displayCompanyList = [...this.companyList];return;}this.filteredData = this.rawData.filter(item => item.companyName === this.searchCompany);this.displayCompanyList = [this.searchCompany];},handleReset() {this.searchCompany = '';this.filteredData = this.rawData;this.displayCompanyList = [...this.companyList];},openContentWindow(functionName, company, url) {// 实际环境中使用路由,这里改为直接打开URLwindow.open(url, '_blank');}}
}
</script><style scoped>
.el-table {margin-top: 20px;
}
.el-link {margin-right: 10px;
}.clickable-cell {color: #1890ff;cursor: pointer;text-decoration: underline;
}.clickable-cell:hover {color: #40a9ff;
}
</style>

5.附件2(数据字典)

<template><div class="app-container"><div style="margin-bottom: 16px; display: flex; align-items: center;"><span style="margin-right: 8px;">公司名称</span><el-select v-model="searchCompany" placeholder="请选择" clearable style="width: 200px; margin-right: 8px;"><el-optionv-for="company in companyList":key="company":label="company":value="company"/></el-select><el-button type="primary" @click="handleSearch">搜索</el-button><el-button @click="handleReset" style="margin-left: 8px;">重置</el-button></div><el-table v-loading="loading" :data="tableData" border style="width: 100%":header-cell-style="{background:'#f5f7fa',color:'#606266'}"><el-table-column prop="functionName" label="功能名称" width="120" fixed/><el-table-column v-for="company in displayCompanyList" :key="company" :label="company" :prop="company"><template v-slot="scope"><div v-if="scope.row[company]" class="clickable-cell" @click="openContentWindow(scope.row.functionName, company, scope.row[company])">{{ scope.row[company] }}</div><div v-else></div></template></el-table-column></el-table></div>
</template><script>
export default {name: "FunctionUrlMatrix",data() {return {loading: false,companyList: [],functionList: [],rawData: null,searchCompany: '',filteredData: null,displayCompanyList: []}},computed: {tableData() {const data = this.filteredData !== null ? this.filteredData : this.rawData;if (!data) return [];const result = []; this.functionList.forEach(func => {const row = { functionName: func };this.companyList.forEach(company => {const companyData = data.find(item => item.companyName === company);if (companyData && companyData.rpWebShows) {// 保持原始数据结构不变,从对象中提取功能名称和URLconst funcData = companyData.rpWebShows.find(item => {const key = Object.keys(item)[0];return key === func;});row[company] = funcData ? funcData[func] : null;} else {row[company] = null;}});result.push(row);});return result;}},created() {this.loadData();},methods: {loadData() {this.loading = true;// 使用原始数据结构,不做修改this.rawData = [{companyName: "公司A",rpWebShows: [{ "功能1": "https://company-a.com/func1" },{ "功能2": "https://company-a.com/func2" },{ "功能3": "https://company-a.com/func3" }]},{companyName: "公司B",rpWebShows: [{ "功能1": "https://company-b.com/func1" },{ "功能3": "https://company-b.com/func3" },{ "功能4": "https://company-b.com/func4" }]},{companyName: "公司C",rpWebShows: [{ "功能2": "https://company-c.com/func2" },{ "功能3": "https://company-c.com/func3" },{ "功能5": "https://company-c.com/func5" }]}];this.extractCompanyAndFunctionList();this.loading = false;this.filteredData = this.rawData;},extractCompanyAndFunctionList() {if (!this.rawData || !Array.isArray(this.rawData)) {console.error('无效的数据结构:', this.rawData);return;}this.companyList = this.rawData.map(item => item.companyName).filter(Boolean);this.displayCompanyList = [...this.companyList];const allFunctions = new Set();this.rawData.forEach(company => {if (company.rpWebShows && Array.isArray(company.rpWebShows)) {company.rpWebShows.forEach(func => {// 从对象结构中提取功能名称const functionName = Object.keys(func)[0];if (functionName) {allFunctions.add(functionName);}});} else {console.warn('公司数据缺少rpWebShows或格式不正确:', company);}});this.functionList = Array.from(allFunctions);},handleSearch() {if (!this.searchCompany) {this.filteredData = this.rawData;this.displayCompanyList = [...this.companyList];return;}this.filteredData = this.rawData.filter(item => item.companyName === this.searchCompany);this.displayCompanyList = [this.searchCompany];},handleReset() {this.searchCompany = '';this.filteredData = this.rawData;this.displayCompanyList = [...this.companyList];},openContentWindow(functionName, company, url) {window.open(url, '_blank');}}
}
</script><style scoped>
.el-table {margin-top: 20px;
}
.el-link {margin-right: 10px;
}.clickable-cell {color: #1890ff;cursor: pointer;text-decoration: underline;
}.clickable-cell:hover {color: #40a9ff;
}
</style>    

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/web/82545.shtml
繁体地址,请注明出处:http://hk.pswp.cn/web/82545.shtml
英文地址,请注明出处:http://en.pswp.cn/web/82545.shtml

如若内容造成侵权/违法违规/事实不符,请联系英文站点网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Kerberos面试内容整理-Kerberos 与 LDAP/Active Directory 的集成

Kerberos 通常不会单独存在于企业环境中,而是与目录服务相结合以提供完整的身份管理方案。其中,Active Directory (AD) 是 Kerberos 集成应用的典型代表。Active Directory 是微软的目录服务,实现了 LDAP(轻量级目录访问协议)目录和 Kerberos 认证的融合。在 AD 域控制器上…

Oracle DG库控制文件IO错误导致宕机的应急处理

Oracle DG库控制文件IO错误导致宕机的应急处理 事故现场偷天换日棋差一招事故现场 一套Oracle 19c DG环境的备库宕机。 根据告警时间检查实例宕机时间点附近的alert日志有如下重要信息: 2025-05-25T23:34:10.705385+08:00 KCF: read, write or open error, block=0x3377ee …

《前端面试题:前端盒模型》

前端盒模型完全指南&#xff1a;从原理到面试实战 &#x1f381; 端午快乐&#xff01; 各位前端小伙伴&#xff0c;端午节快乐&#xff01;&#x1f96e; 在这个粽叶飘香的时节&#xff0c;愿你的代码如龙舟般一往无前&#xff0c;bug 如咸蛋黄般被完美包裹&#xff01;今天我…

BERT:让AI真正“读懂”语言的革命

BERT&#xff1a;让AI真正“读懂”语言的革命 ——图解谷歌神作《BERT: Pre-training of Deep Bidirectional Transformers》 2018年&#xff0c;谷歌AI团队扔出一篇核弹级论文&#xff0c;引爆了整个NLP领域。这个叫BERT的模型在11项任务中屠榜&#xff0c;甚至超越人类表现…

爬虫入门:从基础到实战全攻略

&#x1f9e0; 一、爬虫基础概念 1.1 爬虫定义 爬虫&#xff08;Web Crawler&#xff09;是模拟浏览器行为&#xff0c;自动向服务器发送请求并获取响应数据的一种程序。主要用于从网页中提取结构化数据&#xff0c;供后续分析、展示或存储使用。 1.2 爬虫特点 数据碎片化&…

uni-app学习笔记二十一--pages.json中tabBar设置底部菜单项和图标

如果应用是一个多 tab 应用&#xff0c;可以通过 tabBar 配置项指定一级导航栏&#xff0c;以及 tab 切换时显示的对应页。 在 pages.json 中提供 tabBar 配置&#xff0c;不仅仅是为了方便快速开发导航&#xff0c;更重要的是在App和小程序端提升性能。在这两个平台&#xff…

行业分析---小米汽车2025第一季度财报

1 背景 最近几年是新能源汽车的淘汰赛&#xff0c;前短时间比亚迪再次开始了降价&#xff0c;导致一片上市车企的股价大跌&#xff0c;足见车圈现在的敏感度。因此笔者会一直跟踪新势力车企的财报状况&#xff0c;对之前财报分析感兴趣的读者朋友可以参考以下博客&#xff1a;…

Python 解释器安装全攻略(适用于 Linux / Windows / macOS)

目录 一、Windows安装Python解释器1.1 下载并安装Python解释1.2 测试安装是否成功1.3 设置pip的国内镜像------永久配置 二、macOS安装Python解释器三、Linux下安装Python解释器3.1 Rocky8.10/Rocky9.5安装Python解释器3.2 Ubuntu2204/Ubuntu2404安装Python解释器3.3 设置pip的…

考研系列—操作系统:冲刺笔记(1-3章)

目录 第一章 计算机系统概述 1.基本概念 2.内核态和用户态 3.中断(外中断)、异常(内中断-与当前执行的) 4.系统调用 5.操作系统引导程序 2021年真题: 6.操作系统结构 大纲新增 (1)分层结构 (2)模块化 (3)外核 7.虚拟机 第二章 进程管理 1.画作业运行的顺序和甘…

监控 100 台服务器磁盘内存CPU利用率

监控 100 台服务器磁盘,内存&#xff0c;CPU利用率脚本 以下是一个优化后的监控脚本&#xff0c;用于同时监控100台服务器的磁盘、内存和CPU利用率&#xff0c;并支持并发执行以提高效率&#xff1a; #!/bin/bash # 服务器监控脚本 - 支持并发获取100台服务器系统指标 # 功能…

[5-02-04].第01节:Jmeter环境搭建:

JMeter笔记大纲 Jmeter依赖于JDK&#xff0c;所以必须确保当前计算机上已经安装了JDK&#xff0c;并且配置了环境变量 一、JMeter概述&#xff1a; 1.1.JMeter是什么&#xff1a; JMeter是Appache组织使用java开发的一款测试工具 可以用于对服务器、网络或对象模拟巨大的负载…

【兽医处方专用软件】佳易王兽医电子处方软件:高效智能的宠物诊疗管理方案

一、软件概述与核心优势 &#xff08;一&#xff09;试用版获取方式 资源下载路径&#xff1a;进入博主头像主页第一篇文章末尾&#xff0c;点击卡片按钮&#xff1b;或访问左上角博客主页&#xff0c;通过右侧按钮获取详细资料。 说明&#xff1a;下载文件为压缩包&#xff…

MapReduce(期末速成版)

起初在B站看3分钟的速成视频&#xff0c;感觉很多细节没听懂。 具体例子解析(文件内容去重) 对于两个输入文件&#xff0c;即文件A 和文件B&#xff0c;请编写MapReduce 程序&#xff0c;对两个文件进行合并&#xff0c;并剔除 其中重复的内容&#xff0c;得到一个新的输出文件…

Java高级 | 【实验四】Springboot 获取前端数据与返回Json数据

隶属文章&#xff1a; Java高级 | &#xff08;二十二&#xff09;Java常用类库-CSDN博客 系列文章&#xff1a; Java高级 | 【实验一】Spring Boot安装及测试 最新-CSDN博客 Java高级 | 【实验二】Springboot 控制器类相关注解知识-CSDN博客 Java高级 | 【实验三】Springboot …

从零打造AI面试系统全栈开发

&#x1f916; AI面试系统开发完整教程 &#x1f4cb; 项目概述 本教程将带你从零开始构建一个完整的AI面试系统&#xff0c;包含前端、后端、AI集成和部署的全流程。 源码地址 技术栈 前端: React TypeScript Vite Vaadin Components后端: Spring Boot Spring Securi…

【硬件】PCIe协议 | 电脑的高速公路

文章目录 PCIe | 外围设备高速互联通道&#xff08;peripheral component interconnect express&#xff09;的核心概念和应用 基础概念 1.1 电脑内的”高速“&#xff0c;连接CPU、显卡、SSD&#xff08;固态硬盘&#xff09;等核心组件&#xff1b;数据传输速度极快&#xff…

【 Redis | 完结篇 缓存优化 】

前言&#xff1a;本节包含常见redis缓存问题&#xff0c;包含缓存一致性问题&#xff0c;缓存雪崩&#xff0c;缓存穿透&#xff0c;缓存击穿问题及其解决方案 1. 缓存一致性 我们先看下目前企业用的最多的缓存模型。缓存的通用模型有三种&#xff1a; 缓存模型解释Cache Asi…

MySQL访问控制与账号管理:原理、技术与最佳实践

MySQL的安全体系建立在精细的访问控制和账号管理机制上。本文基于MySQL 9.3官方文档,深入解析其核心原理、关键技术、实用技巧和行业最佳实践。 一、访问控制核心原理:双重验证机制 连接验证 (Connection Verification) 客户端发起连接时,MySQL依据user_name@host_name组合进…

Go语言爬虫系列教程4:使用正则表达式解析HTML内容

Go语言爬虫系列教程4&#xff1a;使用正则表达式解析HTML内容 正则表达式&#xff08;Regular Expression&#xff0c;简称RegEx&#xff09;是处理文本数据的利器。在网络爬虫中&#xff0c;我们经常需要从HTML页面中提取特定的信息&#xff0c;正则表达式就像一个智能的&quo…

笔记 | docker构建失败

笔记 | docker构建失败 构建报错LOG1 rootThinkPad-FLY:/mnt/e/02-docker/ubunutu-vm# docker build -t ubuntu16.04:v1 . [] Building 714.5s (6/11) docker:default> [internal] load …