• 图床项目进度(三)——文件展示页


    前言

    该项目作为一个类网盘项目,主要包括上传下载,引用,预览等功能。
    在这里插入图片描述

    大致功能:

    1. 图片预览
      在这里插入图片描述

    这里的图片预览我使用的一个插件
    const state: any = reactive({

      image: 'https://pic35.photophoto.cn/20150511/0034034892281415_b.jpg',
      index: 0
    });
    
    const previewEvent = () => {
      preview({
        images: state.image
      });
    };
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    1. 上传图片
      在这里插入图片描述
    <el-button type="primary" size="small" @click="dialogVisible = true" :icon=Upload>上传图片</el-button>
    
    • 1
    1. 几个自定义标签
      在这里插入图片描述
    <el-table-column>
    <!--        几个自定义图标-->
            <template v-slot="{row}">
              <div v-if="isPicture(row)" >
                <el-button  type="primary" round size="small" style="margin-right: 50px" @click="previewEvent">预览</el-button>
                <el-tooltip class="item" effect="dark" content="引用" placement="bottom-start">
                <el-button type="text">
                  <el-icon>
                    <Link/>
                  </el-icon>
                </el-button>
               </el-tooltip>
              <el-tooltip class="item" effect="dark" content="下载" placement="bottom-start">
                <el-button type="text">
                  <el-icon>
                    <Download/>
                  </el-icon>
                </el-button>
              </el-tooltip>
              <el-tooltip class="item" effect="dark" content="删除" placement="bottom-start" >
                <el-button type="text"><el-button type="text">
                  <el-icon>
                    <Delete/>
                  </el-icon>
                </el-button></el-button>
              </el-tooltip>
              </div>
            </template>
          </el-table-column>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    1. 文件展示
      在这里插入图片描述

    vue组件源码:

    <template>
      <div>
        <div class="bt">
          <el-button type="text" size="medium" @click="back" v-if="path.length >= 1">
            <el-icon>
              <ArrowLeft/>
            </el-icon>
            返回上一级
          </el-button>
          <el-button type="primary" size="small" @click="dialogVisible = true" :icon=Upload>上传图片</el-button>
          <el-button size="small"  @click="addFolder = true">
            新建文件夹
          </el-button>
          <el-dialog
              title="输入文件名字"
              v-model="addFolder"
              width="20%"
          >
            <el-input v-model="input" placeholder="请输入内容" :input-style="{}"></el-input>
            <span slot="footer" class="dialog-footer">
                <el-button @click="addFolder = false">取 消</el-button>
                <el-button type="primary" @click="newfolder">确 定</el-button>
            </span>
          </el-dialog>
          <el-dialog
              title="上传"
              v-model="dialogVisible"
              width="30%"
              :before-close="handleClose">
            <el-upload
                class="upload-demo"
                drag
                action="upload"
                :before-upload="beforeUpload"
                multiple
    
                v-loading="loading"
                element-loading-text="正在上传"
            >
              <el-icon :size="20">
                <Upload />
              </el-icon>
              <div class="el-upload__text">将图片拖到此处,或<em>点击上传</em></div>
              <div class="el-upload__tip" slot="tip"></div>
            </el-upload>
            <span slot="footer" class="dialog-footer">
      </span>
          </el-dialog>
          <div id="search">
            <input placeholder="请输入内容" class="search" v-model="keywords" />
            <el-icon v-if="keywords > 0" style="margin-right: 10px">
              <Close @click="backSearch" />
            </el-icon>
    
            <el-icon >
              <Search/>
            </el-icon>
    
          </div>
        </div>
        <el-table :data="filteredTableData" :height="height">
          <el-table-column prop="name" label="文件名" width="600px">
            <template v-slot="{row}">
              <img :src="thumbnail(row)" class="img-mini"/>
              <a href="javascript:void(0)" class="fileName" @click="next(row)">{{ row.name }}</a>
            </template>
          </el-table-column>
          <el-table-column>
    <!--        几个自定义图标-->
            <template v-slot="{row}">
              <div v-if="isPicture(row)" >
                <el-button  type="primary" round size="small" style="margin-right: 50px" @click="previewEvent">预览</el-button>
                <el-tooltip class="item" effect="dark" content="引用" placement="bottom-start">
                <el-button type="text">
                  <el-icon>
                    <Link/>
                  </el-icon>
                </el-button>
               </el-tooltip>
              <el-tooltip class="item" effect="dark" content="下载" placement="bottom-start">
                <el-button type="text">
                  <el-icon>
                    <Download/>
                  </el-icon>
                </el-button>
              </el-tooltip>
              <el-tooltip class="item" effect="dark" content="删除" placement="bottom-start" >
                <el-button type="text"><el-button type="text">
                  <el-icon>
                    <Delete/>
                  </el-icon>
                </el-button></el-button>
              </el-tooltip>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="size" label="大小" width="270"></el-table-column>
          <el-table-column prop="time" label="修改日期" width="220"></el-table-column>
        </el-table>
      </div>
    </template>
    
    <script lang="ts" setup>
    import {Upload, Search, Download, Delete, Link, ArrowLeft, Close} from "@element-plus/icons-vue";
    import {computed, reactive, ref} from "vue";
    import {preview, vPreview, Vue3ImagePreview} from 'vue3-image-preview';
    const  height =  window.innerHeight - 62 - 80 - 40;
    let keywords = ref('');
    //当前文件夹目录
    let path =  ref([]);
    const next = (row) => {
      tableData.value = newTableData;
      path.value.push(row.name);
      console.log(path)
    
    }
    const back = () => {
      tableData.value.unshift(
          { name: '文件夹', img: 'image2.jpg', size: '-', time: '2023-08-20' },
      )
      path.value.pop();
      console.log(path);
    }
    function search(){
      return [];
    }
    const backSearch = () =>{
      console.log("执行了backSearch")
      keywords.value = '';
    }
    
    const filteredTableData = computed(() => {
      if (!keywords.value) {
        return tableData.value;
      }
      const lowerKeywords = keywords.value.toLowerCase();
      return tableData.value.filter(item => item.name.toLowerCase().includes(lowerKeywords));
    });
    const addFolder = ref(false);
    const input = ref();
    const  dialogVisible = ref(false);
    
    //核心图片数据区
    const tableData = ref([
      { name: '文件夹', img: 'image2.jpg', size: '-', time: '2023-08-20' },
      { name: "文件1", img: 'image1.jpg', size: '1MB', time: '2023-08-21' },
      { name: '文件2', img: 'image2.jpg', size: '500KB', time: '2023-08-20' },
    
      // ...
    ]);
    const newTableData = [
      { name: "文件1", img: 'image1.jpg', size: '1MB', time: '2023-08-21' },
      { name: '文件2', img: 'image2.jpg', size: '500KB', time: '2023-08-20' },
    ]
    //是否是图片
    const isPicture = (row: { size: string | any[]; }) => {
      return row.size.length > 1;
    }
    //获取缩略图
    const thumbnail = (row: { size: string | any[]; }) => {
      if(row.size.length > 1){
        return  "../src/static/img/picture.svg";
      }else{
        return "../src/static/img/folder.svg";
      }
    }
    //打开预览框
    const state: any = reactive<any>({
      image: 'https://pic35.photophoto.cn/20150511/0034034892281415_b.jpg',
      index: 0
    });
    
    const previewEvent = () => {
      preview({
        images: state.image
      });
    };
    
    </script>
    
    
    
    <style lang="less" scoped>
    
    .bt {
      max-width: 100%;
      background-color: white;
      height: 40px;
      font: 12px/1.5 "Microsoft YaHei", arial, SimSun, "宋体";
      line-height: 30px;
    }
    .nav{
      max-width: 100%;
      background-color: white;
      height: 20px;
      /*font: 12px/1.5 "Microsoft YaHei", arial, SimSun, "宋体";*/
      font-size: 8px;
      line-height: 20px;
    }
    
    .el-table-column {
      max-height: 48px;
      line-height: 48px;
    }
    
    .el-table {
      max-width: 100%;
      font: 12px/1.5 "Microsoft YaHei", arial, SimSun, "宋体";
    }
    
    #search {
      width: 315px;
      border-radius: 33px;
      background-color: #f7f7f7;
      float: right;
      text-align: center;
      height: 32px;
      line-height: 32px;
      input{
         outline: none;
    
      }
    
    }
    
    .search {
      border: none;
      background-color: #f7f7f7;
      height: 30px;
      width: 248px;
    }
    
    img {
      width: 30px;
      height: 30px;
    }
    
    a {
      color: #424e67;
      text-decoration: none;
    }
    
    a:hover {
      color: #09AAFF;
    }
    .el-icon-delete{
      color:#F56C6C;
    }
    .dialog-footer{
      display: flex;
      justify-content: space-between;
    
    }
    span{
      margin-top: 5%;
    }
    .img-mini{
      display: inline-block;
      vertical-align: middle
    }
    .fileName{
      margin-left: 5px;
    }
    .custom-icon{
    
    }
    
    </style>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
  • 相关阅读:
    如何用selenium库自动登录校园网网址?
    java计算机毕业设计智能道路交通管理系统源代码+系统+数据库+lw文档
    连续时间随机游走(Continuous-time random walk, CTRW)
    使用jackson将xml和对象、List相互转换
    单例模式:饿汉式
    CAD如何自定义快捷键
    Godot4.1 GDExtension 配置VisualStudio方法梳理以及快捷配置工具
    杭州动环监控系统供应商,动环监控设备
    箭头函数总结
    根据当年节假日和非工作时间计算请假时间-获取每个月的节假日,计算每个月的工作日时间进度,节假日每年更新
  • 原文地址:https://blog.csdn.net/faker1234546/article/details/132788004