Newer
Older
KaiFengPC / src / views / document / fileManagement / list / index.vue
@zhangdeliang zhangdeliang on 23 May 6 KB 初始化项目
<template>
  <div class="list">
    <div class="top">
      <el-form ref="ruleForm" inline :model="form">
        <el-form-item label="所属分类:" prop="typeId">
          <el-tree-select
            v-model="form.typeId"
            :data="treeData"
            node-key="id"
            :render-after-expand="false"
            :props="{ label: 'typeName' }"
            check-strictly
            clearable
            style="width: 100%"
          />
        </el-form-item>
        <el-form-item label="文件标签:" prop="fileTag">
          <el-select v-model="form.fileTag" placeholder="请选择文件标签" clearable multiple style="width: 200px">
            <el-option v-for="dict in document_tag" :key="dict.value" :label="dict.label" :value="dict.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="文件名称:" prop="fileName">
          <el-input v-model="form.fileName" placeholder="请输入文件名称" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="Search" @click="search"> 查询</el-button>
          <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-row class="mb8">
        <el-button type="primary" plain icon="Plus" @click="openDialog({}, 'add')">新增</el-button>
      </el-row>
    </div>
    <el-table :data="tableData" v-loading="loading" stripe :max-height="600">
      <el-table-column type="index" width="55" label="序号" />
      <el-table-column label="文件名称" prop="fileName" show-overflow-tooltip width="200">
        <template #default="{ row }">
          <el-button type="primary" link @click="previewFile(row)">{{ row.fileName }}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="文件简述" prop="remark" show-overflow-tooltip />
      <el-table-column label="所属分类" prop="typeName" show-overflow-tooltip />
      <el-table-column label="创建时间" prop="createTime" show-overflow-tooltip width="160" />
      <el-table-column label="文件柜" prop="saveAddressName" show-overflow-tooltip />
      <el-table-column label="文件标签" prop="fileTagNames" show-overflow-tooltip />
      <el-table-column label="电子档名称" prop="sysFileList" show-overflow-tooltip>
        <template #default="{ row }">
          <span>{{ row.originalName || '-' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="电子档大小" prop="sysFileList" show-overflow-tooltip>
        <template #default="{ row }">
          <span>{{ handleFileSize(row.size) || '-' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="电子档格式" prop="sysFileList" show-overflow-tooltip>
        <template #default="{ row }">
          <span>{{ row.extension || '-' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" show-overflow-tooltip width="180">
        <template #default="{ row }">
          <el-button type="primary" link @click="openDialog(row, 'view')">查看</el-button>
          <el-button type="primary" link @click="openDialog(row, 'edit')">修改</el-button>
          <el-button type="danger" link @click="del(row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination :total="total" v-model:page="pageNum" v-model:limit="pageSize" @pagination="getTableList" />

    <el-dialog
      v-model="visible"
      :title="`${opts.text}文件管理`"
      :close-on-click-modal="false"
      width="40%"
      :before-close="close"
      class="dialog"
    >
      <operate v-if="visible" ref="operateRef" :cur-row="curRow" :opts="opts" @close="close"></operate>
      <template #footer v-if="opts.type !== 'view'">
        <div class="dialog-footer">
          <el-button type="primary" @click="submit">保存</el-button>
          <el-button @click="close">取消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import { reactive, ref, onMounted, computed, shallowRef } from 'vue';
import { optTextMap } from '@/utils/map';
import { handleFileSize } from '@/utils';
import { usePagination } from '@/hooks';
import operate from './operate.vue';
import { getDocumentFilePage, documentFileDel } from '@/api/document/fileManagement/list';
import { documentTypeTree } from '@/api/document/dataClassify';
import { documentAccessRecordAdd } from '@/api/document/fileManagement/loanRecord';
const { proxy } = getCurrentInstance();
const { document_tag } = proxy.useDict('document_tag');

const form = reactive({
  typeId: '',
  fileTag: [],
  fileName: '',
});

const params = computed(() => {
  const fileTag = form.fileTag.join();
  return {
    ...form,
    fileTag,
  };
});

const { pageNum, pageSize, tableData, total, loading, getTableList } = usePagination(getDocumentFilePage, params);
const treeData = ref([]);
const visible = ref(false);
const curRow = shallowRef({});
const opts = reactive({
  type: '',
  text: '',
});

const search = () => {
  pageNum.value = 1;
  getTableList();
};

const resetQuery = () => {
  proxy.$refs.ruleForm.resetFields();
  search();
};

const openDialog = (data, type) => {
  visible.value = true;
  opts.type = type;
  opts.text = optTextMap.get(type);
  curRow.value = data;
};

const close = result => {
  if (result?.type === 'add') {
    search();
  } else if (result?.type === 'edit') {
    getTableList();
  }
  visible.value = false;
  opts.type = '';
  opts.text = '';
  curRow.value = {};
};

const del = row => {
  proxy.$modal
    .confirm('是否确认删除?')
    .then(async () => {
      const res = await documentFileDel(row.id);
      if (res?.code !== 200) return;
      getTableList();
    })
    .catch(() => {});
};

const submit = () => {
  proxy.$refs.operateRef.submit();
};

const getTreeData = async () => {
  const res = await documentTypeTree();
  if (res?.code !== 200) return;
  treeData.value = res.data || [];
};

const previewFile = row => {
  const file = row?.sysFileList?.[0] || null;
  if (!file) return;
  window.open(file.url);
  documentAccessRecordAdd({
    fileId: row.id,
  });
};

onMounted(() => {
  getTreeData();
  getTableList();
});
</script>

<style lang="scss" scoped>
.list {
  padding: 20px;
  height: 90vh;
  overflow-y: hidden;
  .top {
    margin-bottom: 15px;
  }
}

:deep(.dialog) {
  .el-dialog__body {
    padding-bottom: 20px !important;
  }
  .el-dialog__footer {
    padding-top: 0 !important;
  }
}
</style>