FileList.vue 15 KB
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 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
<template>
  <el-container style="height: 100%; border: 1px solid #eee">
    <!-- 分类树 -->
    <ht-tree
      class="file-type-tree"
      :data="treeData"
      :props="defaultProps"
      default-expand-all
      :expand-on-click-node="false"
      @node-click="handleNodeClick"
      ref="htTypeTree"
    >
      <span class="custom-tree-node" slot-scope="{ node, data }">
        <span class="show-ellipsis" :title="node.label">{{ node.label }}</span>
        <el-dropdown @command="handleCommand">
          <span>
            <i class="icon-more" title="更多操作" />
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item
              icon="el-icon-plus"
              :command="{ node: node, data, action: 'add' }"
              >添加</el-dropdown-item
            >
            <el-dropdown-item
              icon="el-icon-edit"
              v-if="data.id != '-1'"
              :command="{ node: node, data, action: 'edit' }"
              >编辑</el-dropdown-item
            >
            <el-dropdown-item
              icon="el-icon-s-unfold"
              v-if="data.id != '-1'"
              :command="{ node: node, data, action: 'delete' }"
              >删除</el-dropdown-item
            >
          </el-dropdown-menu>
        </el-dropdown>
      </span>
    </ht-tree>
    <el-container>
      <el-main>
        <!-- 附件数据 -->
        <ht-table
          @load="loadData"
          :data="data"
          :pageResult="pageResult"
          quick-search-props="fileName,extensionName"
          :show-export="false"
          ref="htTable"
          @row-click="rowClick"
          :header-cell-class-name="headerCellClassName"
          @selection-change="handleSelectionChange"
        >
          <template v-slot:toolbar>
            <el-button
              size="small"
              @click="selectTypeDialog"
              icon="el-icon-plus"
              :disabled="isDisabled"
              >设置分类</el-button
            >
          </template>
          <template>
            <ht-table-column
              type="index"
              width="50"
              align="center"
              label="序号"
            />
            <ht-table-column
              label="文件名"
              prop="fileName"
              :show-overflow-tooltip="true"
            >
              <template v-slot="{ row }">
                <el-link @click="searchFile(row)" type="primary">{{
                  row.fileName
                }}</el-link>
              </template>
            </ht-table-column>
            <ht-table-column prop="extensionName" width="90" label="扩展名" />
            <ht-table-column prop="type" width="110" label="所属分类" />
            <ht-table-column
              prop="storeType"
              label="存储类型"
              width="110"
              :render-header="renderHeaderMethod"
              :filters="[
                { text: '磁盘', value: 'folder' },
                { text: '数据库', value: 'database' },
                { text: 'FTP服务器', value: 'ftp' },
                { text: '阿里云OSS', value: 'aliyunOss' }
              ]"
            >
              <template v-slot="{ row }">
                <el-tag type="info" v-if="row.storeType == 'folder'"
                  >磁盘</el-tag
                >
                <el-tag type="success" v-if="row.storeType == 'database'"
                  >数据库</el-tag
                >
                <el-tag type="warning" v-if="row.storeType == 'ftp'"
                  >FTP服务器</el-tag
                >
                <el-tag type="warning" v-if="row.storeType == 'aliyunOss'">阿里云OSS</el-tag>
              </template>
            </ht-table-column>
            <ht-table-column
              prop="creatorName"
              label="上传人"
              width="110"
              :sortable="true"
            />
            <ht-table-column
              label="创建时间"
              width="150"
              prop="createTime"
              :sortable="true"
            >
              <template v-slot="scope">
                <span>{{
                  scope.row.createTime
                }}</span>
              </template>
            </ht-table-column>
            <ht-table-column width="100" label="操作" align="left">
              <template v-slot="{ row }">
                <el-button
                  size="mini"
                  type="text"
                  @click="download(row)"
                  >下载</el-button
                >
                <!-- <el-button size="mini" type="primary" icon="el-icon-picture-outline" @click="searchFile(row.id)">预览</el-button> -->
              </template>
            </ht-table-column>
          </template>
        </ht-table>
        <!-- 添加编辑分类 -->
        <ht-sidebar-dialog
          width="380px"
          :title="title"
          :visible="dialogVisible"
          :before-close="handleClose"
          class="add_edit_type"
        >
          <el-form :model="treeSidebarData" data-vv-scope="editSysTypeForm">
            <ht-form-item
              label="父节点"
              label-width="80px"
              v-if="parentSysType.name != ''"
            >
              <ht-input
                v-model="parentSysType.name"
                autocomplete="off"
                validate="required"
                disabled
              ></ht-input>
            </ht-form-item>
            <ht-form-item label="目录名" label-width="80px">
              <ht-input
                v-model="treeSidebarData.name"
                placeholder="请输入目录名"
                autocomplete="off"
                validate="required"
              ></ht-input>
            </ht-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="handleClose">取 消</el-button>
            <ht-submit-button
              :url="saveSysTypeUrl"
              :model="treeSidebarData"
              scope-name="editSysTypeForm"
              @after-save-data="afterSaveData"
              >保存</ht-submit-button>
          </div>
        </ht-sidebar-dialog>
        <!-- 设置分类 -->
        <eip-url-tree-dialog
          :url="urlTree"
          title="选择分类"
          ref="eipUrlTreeDialog"
          @handle-save="handleSave"
        ></eip-url-tree-dialog>
        <!-- 预览压缩文件-->
        <file-tree
          ref="fileTreeSearch"
          :fileTree="fileTree"
          :fileRow="fileRow"
        />
        <!-- 预览pdf.word等文件格式 -->
        <Pdf ref="pdfSearch" :src="src" :fileRow="fileRow" @changeSrc="changeSrc"/>
        <!-- 预览excel.jpg.png.txt等文件格式 -->
        <iframe-src
          ref="iframeSrcSearch"
          :iframeSrc="iframeSrc"
          :fileRow="fileRow"
        />
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import { Message } from "element-ui";
import req from "@/request.js";
const EipUrlTreeDialog = () =>
  import("@/components/dialog/EipUrlTreeDialog.vue");
const FileTree = () => import("@/views/file/FileTree.vue");
const IframeSrc = () => import("@/views/file/IframeSrc.vue");
const Pdf = () => import("@/views/file/Pdf.vue");
import tableHeaderFilter from '@/mixins/tableHeaderFilter.js'
import { mapState } from 'vuex';

export default {
  components: { EipUrlTreeDialog, FileTree, IframeSrc, Pdf },
  
  mixins: [tableHeaderFilter],
  data() {
    return {
      src: "",
      iframeSrc: "",
      fileRow: "",
      fileTree: "",
      title: "添加分类",
      treeSidebarData: {}, //树的新增修改数据
      treeData: [], //树数据
      defaultProps: {
        children: "children",
        label: "name"
      },
      data: [], //列表数据
      pageResult: {
        page: 1,
        pageSize: 20,
        total: 0
      },
      urlTree: window.context.portal + "/file/catalog/v1/getTree", //加载树的URL地址
      dialogVisible: false, //侧边栏是否显示
      parentSysType: {
        name: ""
      }, // 树数据新增时显示父节点
      ids: [], //设置分类时的附件ID集合
      isDisabled:true,  //按钮的禁用
      selectedList:[]
    };
  },
  computed: {
    ...mapState('login',['currentUser']),
    //保存树数据的URL (树新增修改时)
    saveSysTypeUrl: function() {
      return window.context.portal + "/file/catalog/v1/save";
    }
  },
  watch: {
    // 监听选中下
     selectedList:{
      handler(val){
        this.isDisabled = val.length < 1 ? true : false
      },
      deep:true
    }
  },
  methods: {
    handleSelectionChange(selection){
      this.selectedList = selection
    },
    //鼠标选中行改变复选框
    rowClick(row, column, event){
      this.$refs.htTable.$refs.htTable.toggleRowSelection(row);
    },
    //查看附件
    searchFile(row) {
      window.open(`${window.context.portal}/onlinePreview?fileId=${row.id}&token=${this.currentUser.token}`)
    },
    changeSrc(){
      this.src = '';
    },
    //下载附件
    download(row) {
      req.download("${portal}/system/file/v1/downloadFile?fileId=" + row.id);
    },
    //设置分类
    selectTypeDialog() {
      if (
        this.$refs.htTable.$refs.htTable &&
        this.$refs.htTable.$refs.htTable.selection.length == 0
      ) {
        Message.warning("请选择要分类的附件数据");
        return;
      }
      let val = this.$refs.htTable.$refs.htTable.selection;
      this.ids = [];
      for (let i = 0; i < val.length; i++) {
        this.ids.push(val[i].id);
      }
      this.$refs.eipUrlTreeDialog.showDialog();
    },
    //关闭侧边栏
    handleClose() {
      this.loadTreeData(); //刷新树
      this.treeSidebarData = {}; //清除保存过的数据
      this.dialogVisible = false;
    },
    //树新增修改保存后提示
    afterSaveData() {
      this.loadTreeData(); //刷新树
      //如果是编辑不弹出提示信息
      if (this.parentSysType.name == "") {
        this.dialogVisible = false;
        return;
      }
      let parentId = this.treeSidebarData.parentId;
      this.treeSidebarData = {}; //清除保存过的数据
      this.treeSidebarData.parentId = parentId;
      this.$confirm("是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "success"
      })
        .then(() => {})
        .catch(() => {
          this.dialogVisible = false;
        });
    },
    //树的按钮事件
    handleCommand(command) {
      let node = command.node;
      let data = command.data;
      let action = command.action;
      switch (action) {
        case "add":
          this.showDialog(data, action);
          break;
        case "edit":
          this.showDialog(data, action);
          break;
        case "delete":
          this.delSysType(data);
          break;
      }
    },
    //点击按钮打开侧边栏
    showDialog(data, action) {
      this.dialogVisible = true;
      if (data) {
        if (action == "add") {
          this.title = "添加分类";
          this.treeSidebarData = {};
          this.parentSysType = data;
          this.treeSidebarData.parentId = data.id;
        } else if (action == "edit") {
          this.title = "编辑分类";
          this.parentSysType.name = "";
          this.treeSidebarData = data;
        }
      }
    },
    //删除树数据
    delSysType(data) {
      this.$confirm("是否确定删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        req
          .remove(
            window.context.portal + "/file/catalog/v1/remove?id=" + data.id
          )
          .then(
            res => {
              if (res.data.state) {
                this.$message({
                  type: "success",
                  message: res.data.message || "删除成功"
                });
                this.loadTreeData();
              } else {
                this.$message.error(res.data.message || "删除成功");
              }
            },
            error => {
              reject(error);
            }
          );
      });
    },
    //树鼠标左点击时间查询数据
    handleNodeClick(node) {
      if (node.id == "-1") {
        let param = { pageBean: { page: 1, pageSize: 20, showTotal: true } };
        this.loadData(param);
        return;
      }
      let param = {
        pageBean: { page: 1, pageSize: 20, showTotal: true },
        querys: [
          {
            property: "xbTypeId",
            value: node.id,
            group: "main",
            operation: "EQUAL",
            relation: "AND"
          }
        ]
      };
      this.loadData(param);
    },
    //页面加载显示数据
    loadData(param, cb) {
      if (!param.sorter || param.sorter.length == 0) {
        param.sorter = [{ property: "createTime", direction: "DESC" }]; //排序字段
      }
      req
        .post(window.context.portal + "/system/file/v1/list", param)
        .then(response => {
          this.data = response.data.rows;
          this.pageResult = {
            page: response.data.page,
            pageSize: response.data.pageSize,
            total: response.data.total
          };
        })
        .finally(() => cb());
    },
    //加载树
    loadTreeData() {
      req.get(this.urlTree).then(response => {
        this.treeData = response.data;
      });
    },
    //监听对话框确认事件
    handleSave(data) {
      const this_ = this;
      req
        .post(
          window.context.portal +
            "/system/file/v1/setXbTypeId?xbTypeId=" +
            data.id +
            "&type=" +
            data.name,
          this_.ids
        )
        .then(response => {
          if (response.data && response.data.state) {
            Message.success({
              duration: 1500,
              message: response.data.message,
              onClose: function() {
                let param = {
                  pageBean: { page: 1, pageSize: 20, showTotal: true }
                };
                this_.loadData(param);
              }
            });
          } else {
            Message.error(response.data.message || "设置分类失败");
          }
        });
    }
  },
  mounted() {
    this.loadTreeData();
  }
};
</script>

<style lang="scss" scoped>
@import "@/assets/css/element-variables.scss";

::v-deep{
  .cell>.el-table__column-filter-trigger{
    display: none;
  }
  .el-form-item__content{
    .ht-form-inputs__inline {
      width: 270px;
    }
  }
}

.file-type-tree {
  border-right: 1px solid #eee;
  width: $--aside-width;
}

.todo-subject {
  cursor: pointer;
}

.todo-subject:hover {
  color: #2761ff;
}

>>> .custom-tree-node {
  width: calc(100% - 40px);
  // flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  padding-right: 8px;
}

.custom-tree-node i {
  visibility: hidden;
  font-weight: bold;
}

.custom-tree-node:hover i {
  visibility: visible;
}

//侧边弹窗
.add_edit_type {
  ::v-deep {
    .el-dialog__body {
      padding: 0;
      padding-top: 10px;
    }
  }
}
</style>