田源
2024-09-29 7d05c69630d066c0992368423f90e440e3638f91
Source/UBCS-WEB/src/components/file/main.vue
@@ -1,72 +1,82 @@
<template>
  <basic-container>
    <avue-crud :option="option"
               :table-loading="loading"
    <avue-crud ref="crud"
               v-model="form"
               :before-open="beforeOpen"
               :data="data"
               :option="option"
               :page.sync="page"
               :permission="permissionList"
               :before-open="beforeOpen"
               v-model="form"
               ref="crud"
               :table-loading="loading"
               @row-del="rowDel"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @row-click="selectedRowClick"
               @current-change="currentChange"
               @size-change="sizeChange"
               @refresh-change="refreshChange"
               @on-load="onLoad">
      <template slot="menuLeft">
        <el-button type="primary"
                   size="small"
        <el-button v-if="hasUpload" icon="el-icon-upload2"
                   plain
                   icon="el-icon-upload2"
                   size="small"
                   type="primary"
                   @click="handleUpload">上 传
        </el-button>
        <el-button type="primary"
                   size="small"
        <el-button v-if="hasEdit" icon="el-icon-edit"
                   plain
                   icon="el-icon-edit"
                   size="small"
                   type="primary"
                   @click="handleEdit">修 改
        </el-button>
        <el-button type="danger"
                   size="small"
                   icon="el-icon-delete"
        <el-button v-if="hasDownload" icon="el-icon-download"
                   plain
                   size="small"
                   type="primary"
                   @click="handleDownload">下 载
        </el-button>
        <el-button v-if="hasDel" icon="el-icon-delete"
                   plain
                   size="small"
                   type="danger"
                   @click="handleDelete">删 除
        </el-button>
      </template>
      <template slot-scope="scope" slot="menu">
        <el-button type="text"
                   icon="el-icon-download"
      <template slot="menu" slot-scope="scope">
        <el-button v-if="hasDownload" icon="el-icon-download"
                   size="small"
                   type="text"
                   @click="handleDownload(scope.row)">下载
        </el-button>
      </template>
    </avue-crud>
    <el-dialog title="上传附件列表"
    <el-dialog :visible.sync="attachBox"
               append-to-body
               :visible.sync="attachBox"
               title="附件管理"
               width="555px">
      <avue-form ref="form" :option="attachOption" v-model="attachForm" :upload-before="uploadBefore" :upload-after="uploadAfter" :upload-error="uploadError">
      <avue-form ref="form" v-model="attachForm" :option="attachOption" :upload-after="uploadAfter"
                 :upload-before="uploadBefore" :upload-error="uploadError">
      </avue-form>
    </el-dialog>
  </basic-container>
</template>
<script>
import {getList, getFile,upload,update, remove,download} from "@/api/resource/file";
import {getList, getFile, upload, update, remove, download} from "@/api/resource/file";
import {mapGetters} from "vuex";
import {dateFormat} from "@/util/date";
import {validatenull} from "@/util/validate";
import func from "@/util/func";
export default {
  props: ["options","visible"],
  props: ["options", "visible", "ownbizOid"],
  data() {
    return {
      form: {},
      query: {},
      params:{},
      params: {},
      loading: false,
      hasPage: this.options.hasPage || false,
      page: {
        pageSize: 10,
        currentPage: 1,
@@ -74,15 +84,21 @@
      },
      attachBox: false,
      selectionList: [],
      //默认为null全部是true
      hasUpload: validatenull(this.options.hasUpload) ? true : this.options.hasUpload,
      hasEdit: validatenull(this.options.hasEdit) ? true : this.options.hasEdit,
      hasDel: validatenull(this.options.hasDel) ? true : this.options.hasDel,
      hasDownload: validatenull(this.options.hasDownload) ? true : this.options.hasDownload,
      option: {
        height: 'auto',
        height: (this.options.tableHeight ? this.options.tableHeight : '300'),
        calcHeight: 30,
        tip: false,
        searchShow: true,
        searchShow: false,
        searchMenuSpan: 6,
        border: true,
        index: true,
        viewBtn: true,
        refreshBtn: false,
        selection: true,
        dialogClickModal: false,
        column: [
@@ -102,34 +118,26 @@
          {
            label: "文件大小",
            prop: "fileSize",
            formatter:function(d){
              if(!d.fileSize || d.fileSize == null || d.fileSize*1 == 0 || isNaN(d.fileSize*1) ){
            formatter: function (d) {
              if (!d.fileSize || d.fileSize == null || d.fileSize * 1 == 0 || isNaN(d.fileSize * 1)) {
                return "未知大小";
              }else{
              } else {
                //原始大小是B
                var filesize = d.fileSize*1;
                if(filesize>1024*1024*1024*1024){
                  return parseInt(filesize/(1024*1024*1024*1024)) + "TB";
                }else if(filesize> 1024*1024*1024){
                  return parseInt(filesize/(1024*1024*1024)) + "GB";
                }else if(filesize> 1024*1024){
                  return parseInt(filesize/(1024*1024)) + "MB";
                }else if(filesize> 1024){
                  return parseInt(filesize/1024) + "KB";
                }else {
                var filesize = d.fileSize * 1;
                if (filesize > 1024 * 1024 * 1024 * 1024) {
                  return parseInt(filesize / (1024 * 1024 * 1024 * 1024)) + "TB";
                } else if (filesize > 1024 * 1024 * 1024) {
                  return parseInt(filesize / (1024 * 1024 * 1024)) + "GB";
                } else if (filesize > 1024 * 1024) {
                  return parseInt(filesize / (1024 * 1024)) + "MB";
                } else if (filesize > 1024) {
                  return parseInt(filesize / 1024) + "KB";
                } else {
                  return filesize + "B";
                }
              }
            }
          },
          /*{
            label: "密级",
            prop: "secretGradeText"
          },
          {
            label: "文档类别",
            prop: "fileDocClassifyName"
          },*/
          {
            label: "创建者",
            prop: "creator"
@@ -140,42 +148,58 @@
          },
        ]
      },
      data: [{
        btmname: "fileobject",
        createTime: "2023-06-14 16:08:50.002",
        creator: "1",
        fileDocClassify: "undefined",
        fileDocClassifyName: null,
        fileExtension: "png",
        filePath: "VolumnFactoryService:/f87a4c92-ce6e-458b-aad0-0c76bd5eeb35\\54120082-76aa-4092-abbf-b13cb40606c5",
        fileSize: 858,
        id: "assignRole",
        name: "assignRole",
        nameOid: "9FF4C05D-4EFA-F00B-0080-5ABB50257D4E",
        oid: "54120082-76aa-4092-abbf-b13cb40606c5",
        ownBtmname: "wupin",
        ownbizOid: "6EF696C3-CD87-0E7C-1EA1-8DE3913A95C9",
        owner: "1",
        secretGrade: null,
        secretGradeText: null
      }],
      columnType: {
        text: "input",
        combox: "select",
        truefalse: "switch",
        number: "number",
        textarea: "textarea",
        datetime: "datetime",
        date: "date",
        refer: "refer",
      },
      data: [],
      attachForm: {},
      attachOption: {
        submitBtn: true,
        emptyBtn: true,
        column: [
          {
            label: '附件上传',
            prop: 'attachFile',
            type: 'upload',
            dragFile: true,
            loadText: '文件上传中,请稍等',
            span: 24,
            propsHttp: {
              res: 'data'
            },
            action: "/api/ubcs-resource/fileController/uploadFile"
          }
        submitBtn: false,
        emptyBtn: false,
        column: [{
          prop: 'fileDocClassify',
          label: '文件类型',
          props: {
            label: 'value',
            value: 'key'
          },
          change: () => {
            (!!this.options.fileDocClassifyCombox) && this.changeFun('fileDocClassify');
          },
          blur: () => {
            (!this.options.fileDocClassifyCombox) && this.changeFun('fileDocClassify');
          },
          value: this.options.fileDocClassify || "ADMIN_SHARE",
          type: (!this.options.fileDocClassifyCombox) ? 'input' : 'select',
          dicData: (this.options.fileDocClassifyCombox || []),//[{key: 'text', value: '文本框'}]
          display: (!!this.options.fileDocClassifyCombox)
        }, {
          label: '附件上传',
          prop: 'attachFile',
          type: 'upload',
          dragFile: true,
          showFileList: false,
          accept: this.options.uploadAccept || 'file',
          loadText: '文件上传中,请稍等',
          span: 24,
          propsHttp: {
            res: 'data'
          },
          data: {
            ownbizOid: this.options.ownbizOid || "share",
            ownBtmName: this.options.ownbizBtm || "share",
            fileDocClassify: this.options.fileDocClassify || "ADMIN_SHARE",
            fileDocClassifyName: this.options.fileDocClassifyName || "管理员共享文件"
          },
          action: "/api/ubcs-resource/fileController/uploadFile"
        }
        ]
      }
    };
@@ -185,53 +209,190 @@
    permissionList() {
      return {
        addBtn: false,
        editBtn: false,
        viewBtn: false,
        delBtn: this.vaildData(this.permission.attach_delete, false)
        delBtn: this.vaildData(this.permission.attach_delete, false),
        editBtn: false
      };
    },
    ids() {
      let ids = [];
    oids() {
      let oids = [];
      this.selectionList.forEach(ele => {
        ids.push(ele.id);
        oids.push(ele.oid);
      });
      return ids.join(",");
      return oids.join(",");
    }
  },
  created() {
    this.setFormItem();
    this.setParams()
  },
  mounted() {
  },
  watch: {
    ownbizOid(val) {
      this.setParams()
      this.refreshChange()
    },
  },
  methods: {
    setParams(){
      var params={
        ownbizOid:options.ownbizOid || '6EF696C3-CD87-0E7C-1EA1-8DE3913A95C9',
        ownbizBtm:options.ownbizBtm || 'wupin',
        fileDocClassify:options.fileDocClassify || '!=processAuditSuggest'
    setFormItem() {
      /*this.options.formItems=[{
        field: 'fileDocClassify11',
        title: '文件类型',
        type:  'combox',
        data: [{key: 'text', value: '文本框'},{key: 'number', value: '数字框'}]
      }]*/
      if (this.options && this.options.formItems) {
        this.options.formItems.forEach(item => {
          // 设置表单校验的规则,文本
          let message = "请选择";
          let trigger = "change";
          if (item.type === "text") {
            message = "请输入";
            trigger = "blur";
          }
          this.attachOption.column.push({
            ...item,
            label: item.title,
            prop: item.field,
            display: !item.hidden,
            value: item.defaultValue,
            disabled: item.readOnly,
            type: this.columnType[item.type],
            dicData: this.getDataList(item.type, item.data),
            change: () => {
              if (item.type !== "text" && item.type !== "number" && item.type !== "textarea") {
                this.changeFun(item.field);
              }
            },
            blur: () => {
              if (item.type == "text" || item.type == "number" || item.type == "textarea") {
                this.changeFun(item.field);
              }
            },
            rules: [
              {
                required: item.required,
                message: `请${message}${item.title}`,
                trigger,
              },
              {
                // 如果没有正则则匹配任何字符
                pattern: item.verify ? item.verify : /[\s\S.]*/g,
                message: item.tooltips,
                trigger,
              },
            ],
            props: {
              label: 'value',
              value: 'key'
            }
          })
        })
      }
      this.params=params;
    },
    changeFun(prop) {
      this.attachOption.column[1].data[prop] = this.attachForm[prop]
    },
    getDataList(type, dicData) {
      if (type === "truefalse") {
        return [
          {
            key: false,
            value: "否",
          },
          {
            key: true,
            value: "是",
          },
        ];
      } else if (type === "combox") {
        return dicData;
      }
      return [];
    },
    setParams() {
      var queryMap = {
        currentButtonKey: 'VIEW',
        ownbizOid: this.options.ownbizOid || "share",
        ownBtmName: this.options.ownbizBtm || "share",
        fileDocClassify: this.options.fileDocClassify || "ADMIN_SHARE",
        fileDocClassifyName: this.options.fileDocClassifyName || "管理员共享文件"
      };
      if (this.options.where) {
        Object.assign(queryMap, this.options.where);
      }
      this.params = queryMap;
      if (!this.options.pageObject) {
        this.options.pageObject = {
          limit: 10,
          page: 1
        };
      }
      this.page.pageSize = this.options.pageObject.limit;
      this.page.currentPage = this.options.pageObject.page;
      this.attachOption.column[1].data.ownbizOid = this.options.ownbizOid || "share";
      this.attachOption.column[1].data.ownBtmName = this.options.ownbizBtm || "share";
      this.attachOption.column[1].data.fileDocClassify = this.options.fileDocClassify || "ADMIN_SHARE";
      this.attachOption.column[1].data.fileDocClassifyName = this.options.fileDocClassifyName || "管理员共享文件"
    },
    handleUpload() {
      this.attachOption.column[1].data.fileOid = '';
      delete this.attachOption.column[1].data.oid;
      delete this.attachOption.column[1].data.updateFileFlag;
      this.attachBox = true;
    },
    handleEdit() {
      if (this.selectionList.length == 0) {
        this.$message.warning('请选择需要修改的文件')
        return false;
      } else if (this.selectionList.length > 1) {
        this.$message.warning('请选择一条数据')
        return false;
      }
      this.attachOption.column[1].data.fileOid = this.oids;
      this.attachOption.column[1].data.oid = this.oids;
      this.attachOption.column[1].data.updateFileFlag = true
      this.attachBox = true;
    },
    uploadBefore(file, done, loading,column) {
      console.log(file,column)
      //如果你想修改file文件,由于上传的file是只读文件,必须复制新的file才可以修改名字,完后赋值到done函数里,如果不修改的话直接写done()即可
      var newFile = new File([file], '1234', { type: file.type });
      done(newFile)
      this.$message.success('上传前的方法')
    uploadBefore(file, done, loading, column) {
      done();
    },
    uploadAfter(res, done, loading, column) {
      window.console.log(column);
      this.attachBox = false;
      this.$message.success('文件上传成功')
      this.refreshChange();
      done();
    },
    uploadError(error, column) {
      this.$message.success('上传失败回调')
      console.log(error, column)
      this.$message.error(error || '上传文件出现了异常')
    },
    handleDownload(row) {
      window.open(`${row.link}`);
      //window.open(`${row.link}`);
      let data = new FormData();
      if (row && row.oid) {
        data.append('fileOids', row.oid)
        this.downloadFile(data);
      } else {
        if (this.selectionList.length === 0) {
          this.$message.warning("请选择至少一条数据");
          return;
        }
        data.append('fileOids', this.oids)
        this.downloadFile(data);
      }
    },
    downloadFile(data) {
      download(data).then(res => {
        console.log(res);
        if (res) {
          func.downloadFileByBlobHandler(res);
        }
      });
    },
    rowDel(row) {
      this.$confirm("确定将选择文件删除?", {
@@ -240,7 +401,7 @@
        type: "warning"
      })
        .then(() => {
          return remove(row.id);
          return remove([row.oid]);
        })
        .then(() => {
          this.onLoad(this.page);
@@ -261,7 +422,7 @@
        type: "warning"
      })
        .then(() => {
          return remove(this.ids);
          return remove(this.oids.split(','));
        })
        .then(() => {
          this.onLoad(this.page);
@@ -287,11 +448,18 @@
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      this.onLoad(this.page);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
      this.$refs.crud.setCurrentRow(this.selectionList[list.length - 1]);
    },
    selectedRowClick(row) {
      this.selectionList = row;
      this.$refs.crud.toggleSelection();
      this.$refs.crud.setCurrentRow(row);
      this.$refs.crud.toggleRowSelection(row); //选中当前行
    },
    selectionClear() {
      this.selectionList = [];
@@ -304,18 +472,38 @@
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
      this.onLoad(this.page);
    },
    onLoad(page, params) {
      //this.loading = true;
      params=this.params || {}
      /*getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
    onLoad(page, params = {}) {
      this.loading = true;
      var query = {}
      if (this.query) {
        for (var key in this.query) {
          query['conditionMap["' + key + '"]'] = this.query[key];
        }
      }
      getList(page.currentPage, page.pageSize, Object.assign(params, this.params, query, this.query)).then(res => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        if (this.options.fileDocClassifyCombox) {
          this.data = data.records.map(item => {
            if (validatenull(item.fileDocClassifyName) && !validatenull(item.fileDocClassify)) {
              item.fileDocClassifyName = this.options.fileDocClassifyCombox[item.fileDocClassify] || '';
            }
            return {
              ...item
            }
          })
        } else {
          this.data = data.records;
        }
        this.loading = false;
        this.selectionClear();
      });*/
      }).catch(error => {
        this.$message.error(error);
        this.loading = false;
      });
    }
  }
};