zip文件树形结构数据组件封装(vue)

zip文件树形结构数据组件封装(vue)

项目中需要实现各种文件的预览,其中包括zip文件的预览。本文主要是针对zip文件在后端解压后返回树形结构的数据给前端展示目录结构。
具体效果如下:

在这里插入图片描述

将后端返回的string数据转为json结构如下:

其中title字段为文件或文件夹名称,treeType为FILE表示为文件夹(可点击打开下一层),treeType为DIR表示为文件(可点击进行查看)。

fileTree = [{
	"title": "哈哈哈test",
	"treeType": "FILE",
	"staticFileUrl": "/app/static/view/20200903/0fc25476-6bcb-4379-a817-c756168cd8e5",
	"isView": null,
	"selectable": null,
	"children": [{
		"title": "鍝堝搱鍝坱est",
		"treeType": "FILE",
		"staticFileUrl": null,
		"isView": null,
		"selectable": null,
		"children": [{
			"title": "kkk",
			"treeType": "FILE",
			"staticFileUrl": null,
			"isView": null,
			"selectable": null,
			"children": [{
				"title": "婊存淮鐢靛瓙鍙戠エB.pdf",
				"treeType": "DIR",
				"staticFileUrl": "/view/2020/09/03/0293765f-ac0c-47bb-b2ce-5a2be8841a4e.pdf",
				"isView": true,
				"selectable": true,
				"children": []
			}]
		}, {
			"title": "婊存淮鍑鸿琛岀▼鎶ラ攢鍗旴.pdf",
			"treeType": "DIR",
			"staticFileUrl": "/view/2020/09/03/ec80331d-0917-4a0d-b4d1-6f56d2ad7d68.pdf",
			"isView": true,
			"selectable": true,
			"children": []
		}, {
			"title": ".DS_Store",
			"treeType": "DIR",
			"staticFileUrl": null,
			"isView": false,
			"selectable": false,
			"children": []
		}, {
			"title": "婊存淮鐢靛瓙鍙戠エA.pdf",
			"treeType": "DIR",
			"staticFileUrl": "/view/2020/09/03/ba01ee46-aeb3-4324-8f3f-3fb2fc69c651.pdf",
			"isView": true,
			"selectable": true,
			"children": []
		}]
	}]
}]

html代码如下

文件目录结构组件代码如下

1.template
<template>
  <div class="file-item">
  <!--文件可点击进行预览操作-->
    <div @click="filePriew(fileTree)" class="file-title file" v-if="fileTree.treeType==='DIR'">
      <img src="@/assets/fkimg/approve/attachmentIcon/files.png" class="file-image"/>
      <span class="file-text">{{fileTree.title}}</span>
      </div>
      <!--文件夹可点击展开-->
    <div @click="isShowChild=!isShowChild"  class="file-title" v-else>
       <img src="@/assets/fkimg/approve/attachmentIcon/fileTree.png" class="file-image"/>
      <span class="file-text">{{fileTree.title}}</span>
       <img v-if="isShowChild" src="@/assets/fkimg/approve/attachmentIcon/up.png" class="file-image-right"/>
       <img v-else src="@/assets/fkimg/approve/attachmentIcon/down.png" class="file-image-right"/>
    </div>
    <div class="padding-left" v-show="fileTree.children&&fileTree.children.length>0&&isShowChild">
    <!--当前组件自己调用自己类似于递归的写法-->
        <file-item
        @filePriew="filePriew"
        v-for="(item,index) in fileTree.children"
        :key="index"
        :fileTree="item"></file-item>
    </div>
  </div>
</template>
2.script
<script>
export default {
  name: 'fileItem',//组件名称一定要写正确,以便自己调用自己
  props: {
    fileTree: {//文件目录结构数据
      type: Object,
      default: null,
    },

  },
  data () {
    return {
      isShowChild: false,//是否显示下一级目录
    }
  },
  methods: {
    clear () {//用于关闭打开的文件,可供父组件调用。
      this.isShowChild = false
    },
    filePriew (item) {//查看文件的方法
    },
  },
}
</script>

3.css样式

<style lang="less" scoped>
.file-item{
  .file-title{
    padding:6px 15px;
      .file-image {
          width: 35px;
          height: 35px;
          margin-right: 15px;
        }
        .file-image-right{
          position:absolute;
           width: 25px;
          height: 25px;
          right:15px;
          top:6px;
        }
        .file-text{
          font-family: PingFangSC-Medium;
          font-size: 14px;
          color: #333333;
          letter-spacing: 0;
          line-height: 35px;
        }
  border-bottom: 1px solid #eeeeee;
  position: relative;
  }
          .file{
    padding:6px 25px;

        }
.padding-left{
  padding-left:10px;
}

}
</style>

调用组件

<file-item ref="fileItemRef" @filePriew="filePriew" :fileTree="fileTree" />
最主要的思路就是利用递归的方式层层展示文件目录结构。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
零件封装是指实际零件焊接到电路板时所指示的外观和焊点的位置。是纯粹的空间概念.因此不同的元件可共用同一零件封装,同种元件也可有不同的零件封装。像电阻,有传统的针插式,这种元件体积较大,电路板必须钻孔才能安置元件,完成钻孔后,插入元件,再过锡炉或喷锡(也可手焊),成本较高,较新的设计都是采用体积小的表面贴片式元件(SMD)这种元件不必钻孔,用钢膜将半熔状锡膏倒入电路板,再把SMD元件放上,即可焊接在电路板上了。 电阻 AXIAL 无极性电容 RAD 电解电容 RB- 电位器 VR 二极管 DIODE 三极管 TO 电源稳压块78和79系列 TO-126H和TO-126V 场效应管 和三极管一样 整流桥 D-44 D-37 D-46 单排多针插座 CON SIP 双列直插元件 DIP 晶振 XTAL1 电阻:RES1,RES2,RES3,RES4;封装属性为axial系列 无极性电容:cap;封装属性为RAD-0.1到rad-0.4 电解电容:electroi;封装属性为rb.2/.4到rb.5/1.0 电位器:pot1,pot2;封装属性为vr-1到vr-5 二极管:封装属性为diode-0.4(小功率)diode-0.7(大功率) 三极管:常见的封装属性为to-18(普通三极管)to-22(大功率三极管)to-3(大功率达林 顿管) 电源稳压块有78和79系列;78系列如7805,7812,7820等 79系列有7905,7912,7920等 常见的封装属性有to126h和to126v 整流桥:BRIDGE1,BRIDGE2: 封装属性为D系列(D-44,D-37,D-46) 电阻: AXIAL0.3-AXIAL0.7  其中0.4-0.7指电阻的长度,一般用AXIAL0.4 瓷片电容:RAD0.1-RAD0.3。  其中0.1-0.3指电容大小,一般用RAD0.1 电解电容:RB.1/.2-RB.4/.8 其中.1/.2-.4/.8指电容大小。一般470uF用RB.3/.6 二极管: DIODE0.4-DIODE0.7 其中0.4-0.7指二极管长短,一般用DIODE0.4 发光二极管:RB.1/.2 集成块: DIP8-DIP40, 其中8-40指有多少脚,8脚的就是DIP8 贴片电阻 0603表示的是封装尺寸 与具体阻值没有关系 但封装尺寸与功率有关 通常来说 0201 1/20W 0402 1/16W 0603 1/10W 0805 1/8W 1206 1/4W 电容电阻外形尺寸与封装的对应关系是: 0402=1.0x0.5 0603=1.6x0.8 0805=2.0x1.2 1206=3.2x1.6 1210=3.2x2.5 1812=4.5x3.2 2225=5.6x6.5
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值