上传文件夹里面的文件后,按树结构的table表格展示

news2025/2/28 13:36:22

1. 先处理最简单的

原始数据大概是这样:   

        let fileArr = [
                {
                    progress: 100,
                    status: '成功',
                    type: '通号',
                    webkitRelativePath: "六捷数据2023-05-04 163909/G163/Abis口详细信息_(G163)(380BL3544-0)(14984173988)(2018-01-24 174431.0740—2018-01-24 180347.9070).xls"
                },
                {
                    progress: 100,
                    status: '成功',
                    type: '通号',
                    webkitRelativePath: "六捷数据2023-05-04 163909/G163/A口详细信息_(G163)(380BL3544-0)(14984173988)(2018-01-24 174431.4760—2018-01-24 180346.8490).xls"
                },
                {
                    progress: 100,
                    status: '成功',
                    type: '六捷',
                    webkitRelativePath:'六捷数据2023-05-04 163909/DJ5908 (2022-11-16)/PRI接口/PRI 信令(14985174166).xlsx'
                },
                {
                    progress: 100,
                    status: '成功',
                    type: '六捷',
                    webkitRelativePath: '六捷数据2023-05-04 163909/DJ5908 (2022-11-16)/A接口/A 呼叫记录.xlsx'
                },
                {
                    progress: 100,
                    status: '成功',
                    type: '六捷',
                    webkitRelativePath: '六捷数据2023-05-04 163909/DJ5908 (2022-11-16)/Abis接口/Abis 信令(14985174166).xlsx'
                },
                {
                    progress: 100,
                    status: '成功',
                    type: '六捷',
                    webkitRelativePath: '六捷数据2023-05-04 163909/DJ5908 (2022-11-16)/Abis接口/Abis 呼叫记录.xlsx'
                },
                {
                    progress: 100,
                    status: '成功',
                    type: '无',
                    webkitRelativePath: '六捷数据2023-05-04 163909/dahhdahadab.xls'
                }
            ]

处理方法:

let oraginArr = fileArr.map(v => ({ path: v.webkitRelativePath.split("/"), type: v.type, status: v.status, progress: v.progress}))

function genDirTree(arr){
    let result = []
    if(arr.length === 0) return []
   let treeRoots =[...new Set(arr.map(v => v.path[0])) ]
    
    if(treeRoots.length === 0) return
    treeRoots.map((v, i) =>{
        let temp = {
            name: v
        }
        let children = []
        arr.map((value, j) => {
             
            if(value.path && value.path[0] === v){
                 
                let tempV = [...value.path]
                tempV.shift()
                if(tempV.length>0){
                     children.push({ path: tempV, status: value.status, type: value.type, progress:value.progress})
                }
                temp.status = value.status
                temp.type = value.type
                temp.progress = value.progress
               
            }
            
        })
        if(children.length > 0){
            temp.children = genDirTree(children)
        }
       
        result.push(temp)
    } ) 
    return result
}
genDirTree(oraginArr)
console.log('genDirTree:', genDirTree(oraginArr))

打印结果:

效果图展示: 

 全部代码如下:

<template>
	<div>
		<el-table
    :data="tableData"
    style="width: 100%;margin-bottom: 20px;"
    row-key="name"
    border
    default-expand-all
    :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
    <el-table-column prop="name" label="文件名" min-width="500"></el-table-column>
    <el-table-column prop="status" label="状态"></el-table-column>
    <el-table-column prop="type" label="厂家类型"></el-table-column>
    <el-table-column prop="webkitRelativePath" label="原始文件名"></el-table-column>

  </el-table>
	</div>
</template>

<script>
export default {
	data () {
		return {
			tableData: [],
			fileArr: [
				{
					progress: 100,
					status: '成功',
					type: '通号',
					webkitRelativePath: "六捷数据2023-05-04 163909/G163/Abis口详细信息_(G163)(380BL3544-0)(14984173988)(2018-01-24 174431.0740—2018-01-24 180347.9070).xls"
        },
        {
					progress: 100,
					status: '成功',
					type: '通号',
					webkitRelativePath: "六捷数据2023-05-04 163909/G163/A口详细信息_(G163)(380BL3544-0)(14984173988)(2018-01-24 174431.4760—2018-01-24 180346.8490).xls"
      	},
        {
					progress: 100,
					status: '成功',
					type: '六捷',
					webkitRelativePath:'六捷数据2023-05-04 163909/DJ5908 (2022-11-16)/PRI接口/PRI 信令(14985174166).xlsx'
        },
        {
					id: 226,
					progress: 100,
					status: '成功',
					type: '六捷',
					webkitRelativePath: '六捷数据2023-05-04 163909/DJ5908 (2022-11-16)/A接口/A 呼叫记录.xlsx'
        },
        {
					progress: 100,
					status: '成功',
					type: '六捷',
					webkitRelativePath: '六捷数据2023-05-04 163909/DJ5908 (2022-11-16)/Abis接口/Abis 信令(14985174166).xlsx'
        },
        {
					progress: 100,
					status: '成功',
					type: '六捷',
					webkitRelativePath: '六捷数据2023-05-04 163909/DJ5908 (2022-11-16)/Abis接口/Abis 呼叫记录.xlsx'
        },
        {
					progress: 100,
					status: '成功',
					type: '无',
					webkitRelativePath: '六捷数据2023-05-04 163909/dahhdahadab.xls'
        }
			]
		}
	},
	methods: {
		genDirTree(arr) {
			let result = []
			if (arr.length === 0) return []
			let treeRoots = [...new Set(arr.map(v => v.path[0]))]
    
    	if (treeRoots.length === 0) return
    	treeRoots.map((v, i) =>{
        let temp = {
          name: v
        }
        let children = []
        arr.map((value, j) => {
					if (value.path && value.path[0] === v) { 
						let tempV = [...value.path]
						tempV.shift()
						if (tempV.length > 0) {
							children.push({ path: tempV, status: value.status, type: value.type, progress: value.progress})
						} else {
							// 最后文件一层 push 其他变量
							temp.status = value.status
							temp.type = value.type
							temp.progress = value.progress
						}
					}
        })
        if (children.length > 0) {
          temp.children = this.genDirTree(children)
        }
        result.push(temp)
    	}) 
    	return result
    }
	},
	created() {
		let oraginArr = this.fileArr.map(v => ({ path: v.webkitRelativePath.split("/"), type: v.type, status: v.status, progress: v.progress}))
    console.log('oraginArr:', oraginArr)
    console.log('genDirTree:', this.genDirTree(oraginArr))
		this.tableData = this.genDirTree(oraginArr)
	},
	mounted() {

	}
}
</script>

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Node.js 正在逐渐被淘汰!Bun 1.0 正在改变 JavaScript 的游戏规则

在深入讨论之前&#xff0c;我们需要解释什么是 JavaScript 运行时以及为什么我们应该关心其速度。 想象一下&#xff0c;你用 JavaScript 写了一个故事&#xff0c;需要有人大声读出来。JavaScript 运行时就像是那个友好的叙述者&#xff0c;为你的故事赋予生命&#xff01;它…

vue实时显示当前年月日时分秒有时间单位的<script setup>写法

在Vue 3中&#xff0c;您可以使用<script setup>语法来编写实时显示当前年月日时分秒并显示时间单位的代码。以下是一个示例&#xff1a; <template> <div> 当前时间&#xff1a;{{ currentDateTime }} </div> </template><script setup>…

el-table 表格里面有tree 层级 进行勾选和反勾选

// 勾选全选反勾选等实现setChecked(data) {for (let i 0; i < data.length; i) {const node data[i];if (node.isCheck) {// 如果当前节点被勾选&#xff0c;将其子节点全部设置为选中状态if(node.children) {for (let j 0; j < node.children.length; j) {const chi…

十三、前端开发知识快速入门

目录 一、HTML概述和基本结构1.1 概述1.2 基本结构1.3 html文档类型1.4 html注释 二、HTML常用标签2.1 块标签2.2 行内标签2.3 字符实体2.4 图片标签2.5 链接标签2.6 列表标签2.7 表单2.8 表格 三、页面布局四、CSS样式4.1 基本语法和页面引用4.2 文本样式设置4.3 颜色表示法4.…

asp.net会议预约管理系统VS开发sqlserver数据库web结构c#编程Microsoft Visual Studio

一、源码特点 asp.net 会议预约管理系统 是一套完善的web设计管理系统&#xff0c;系统具有完整的源代码和数据库&#xff0c;系统主要采用B/S模式开发。开发环境为vs2010&#xff0c;数据库为sqlserver2008&#xff0c;使用c#语 言开发 asp.net 会议预约管理系统 二、…

ES _bulk 批量操作用法

es 的 bulk 操作&#xff0c;是用来批量发送请求&#xff0c;或者理解为批量操作的。 支持4种操作 bulk 支持多种操作&#xff0c;如下create、index、update、delete。 create 如果文档不存在就创建&#xff0c;但如果文档存在就返回错误index 如果文档不存在就创建&#x…

敏捷开发流程图Scrum

敏捷开发中的Scrum流程通常可以用一个简单的流程图来表示&#xff0c;以便更清晰地展示Scrum框架的各个阶段和活动。以下是一个常见的Scrum流程图示例&#xff1a; 转自&#xff1a;Leangoo.com 免费敏捷工具 这个流程图涵盖了Scrum框架的主要阶段和活动&#xff0c;其中包括&…

ABAP 采购组 条目 Z001 不存在T161内-请检查输入

背景&#xff1a;在ALV报表更改PR采购组 做法&#xff1a;ALV报表取出PR相关数据&#xff0c;直接将采购组列设置为可编辑&#xff0c;然后设置按钮更改逻辑。 操作&#xff1a;将采购组值更新&#xff08;从原来500改为600&#xff09;&#xff0c;然后点更改功能按钮&#xf…

VMware Horizon 8 运维系列(四)云桌面虚拟机被移除网卡

前言 最近发现有一台云桌面虚拟机经常网卡莫名其妙就被删除了,从而造成网络中断,客户端无法连接到该虚拟机桌面,经过分析判断可能是由于用户在使用u盘的时候,误删了虚拟网卡设备造成的。 问题描述: 故障现象:客户机无法访问云桌面虚拟机: 查看桌面池列表,发现该虚拟机…

C++指针解读(1)-- 什么是指针

变量的内存地址叫指针&#xff0c;存放指针的变量叫指针变量。估计不少人会混淆这2个概念&#xff0c;而且有的书籍资料把“指针变量”称为“指针”。 1、数据的存储方式 程序中的数据都会占用一块内存空间&#xff0c;不同数据类型占用的内存大小不同。比如char、bool是1个字…

树上启发式合并:xor1

https://vjudge.net/contest/587311#problem/C 最近没打这个套路&#xff0c;场上忘了 发现和一堆lca什么的有关&#xff0c;然后又是lca下不同的儿子&#xff0c;考虑树上启发式合并。 对于 i ⊕ j i\oplus j i⊕j&#xff0c;我们可以拆位枚举 然后常数大会被卡常。但树上…

AndroidStudio模拟器使用rootAVD ROOT(失败)

下载rootAVD $ git clone https://github.com/newbit1/rootAVD.git 下载Magist Releases topjohnwu/Magisk GitHub 改名为Magist.zip&#xff0c;然后替换 察看设备 > .\rootAVD.bat ListAllAVDsrootAVD.bat system-images\android-31\google_apis_playstore\x86_64…

数据库系统概念学习2

对空值和布尔值的聚集 嵌套子查询 子查询是嵌套在另一个查询中的 select-from-where 表达式 集合成员资格 连接词 in 测试元组是否是集合中的成员&#xff0c;连接词 not in 测试元组是否不是集合中的成员 ↑ 找出在 2009 年球季和 2010 年春季学期同时开课的所有课程 ↓ 找…

docker安装sql-server数据库,使用navicat实现备份数据库导入

docker安装sql-server&#xff0c;使用navicat实现备份数据库导入 1、docker安装sql-server数据库2、使用navicat连接sql-server3、使用navicat导入备份数据库1、第一步&#xff1a;选择需要备份的数据源2、第二步 &#xff08;选择备份计划&#xff0c;设置还原文件位置信息&a…

云计算到底牛x在哪里?

你们好&#xff0c;我的网工朋友。 云计算已经霸屏行业有段时间了&#xff0c;但很多粉丝朋友还是不太明白什么是云计算&#xff0c;为什么要学云计算。 从宏观来说&#xff0c;其实云计算的优点很多。 就和传统模式相比&#xff0c;云计算在六个维度都有显著的提升点。 比…

git主干master分支回滚到历史版本(不会有错误的提交记录)

master版本,“合并错了”的回滚步骤: (这样做不会有“合并错了”的提交记录) 注意&#xff1a;操作前先对master拉一个分支出来&#xff0c;做备份&#xff1b; 1. 在gitLab的上一次合并记录&#xff0c;复制commit-id ​ 2. 在本地执行检出master版本&#xff0c;执行 git re…

阿里云价格计算器入口(一键计算精准报价)

阿里云服务器价格计算器&#xff0c;鼠标选择云服务器ECS实例规格、地域、系统盘、带宽及购买时长即可一键计算出精准报价&#xff0c;阿里云百科aliyunbaike.com分享阿里云服务器价格计算器链接地址&#xff1a; 阿里云服务器价格计算器 先打开阿里云服务器ECS页面 aliyunba…

浅析倾斜摄影三维模型(3D)几何坐标精度偏差的几个因素

浅析倾斜摄影三维模型&#xff08;3D&#xff09;几何坐标精度偏差的几个因素 倾斜摄影是一种通过倾斜角度较大的相机拍摄建筑物、地形等场景&#xff0c;从而生成高精度的三维模型的技术。然而&#xff0c;在进行倾斜摄影操作时&#xff0c;由于多种因素的影响&#xff0c;导致…

Godot自动寻路功能讲解-使用C#语言(2D游戏导航教程)

文章目录 创建导航NavigationAgent2D节点设置目标位置其他文章 创建导航 首先&#xff0c;创建一个基本的场景&#xff0c;下面的文章讲解了如何创建一个基本的导航场景&#xff0c;点击如下链接前往该文章&#xff1a; Godot2D角色导航-自动寻路教程 NavigationAgent2D节点 …

Vue封装组件并发布到npm仓库

前言 使用Vue框架进行开发&#xff0c;组件封装是一个很常规的操作。一个封装好的组件可以在项目的任意地方使用&#xff0c;甚至我们可以直接从npm仓库下载别人封装好的组件来进行使用&#xff0c;比如iview、element-ui这一类的组件库。但是每个公司的业务场景可能不同&…