lxf 2 anni fa
parent
commit
4484ff8caf

+ 199 - 0
src/components/webDiskData/treeList.vue

@@ -0,0 +1,199 @@
+<template>
+  <div class="treeList">
+    <div class="title commons-title">
+      {{ title }}
+    </div>
+    <div class="search">
+      <el-input v-model="search" placeholder="请输入搜索内容" clearable @clear="search = ''" @keyup.enter="searchChange"></el-input>
+      <el-button type="primary" plain @click="add({ id: '-1' })">
+        <el-icon :size="20">
+          <Plus />
+        </el-icon>
+      </el-button>
+    </div>
+    <el-tree
+      :data="data"
+      :props="{ children: 'netdiskList' }"
+      ref="tree"
+      node-key="id"
+      @node-click="treeChange"
+      default-expand-all
+      :expand-on-click-node="false"
+      :filter-node-method="filterNode">
+      <template #default="{ node, data }">
+        <div class="custom-tree-node">
+          <div style="flex: 1">{{ data.name }}</div>
+          <div style="float: right">
+            <el-icon :size="17" @click.stop="() => edit(node, data)">
+              <Edit />
+            </el-icon>
+            <el-icon :size="17" style="margin-left: 10px" @click.stop="() => add(data)">
+              <Plus />
+            </el-icon>
+            <el-icon :size="17" style="margin-left: 10px" @click.stop="() => del(data)">
+              <Delete />
+            </el-icon>
+          </div>
+        </div>
+      </template>
+    </el-tree>
+  </div>
+  <el-dialog :title="treeModalType == 'add' ? '添加目录' : '编辑目录'" v-model="treeModal" width="400" v-loading="loading">
+    <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" :rules="rules" ref="submit"> </byForm>
+    <template #footer>
+      <el-button @click="treeModal = false" size="large">取 消</el-button>
+      <el-button type="primary" @click="submitForm()" size="large" :loading="submitLoading"> 确 定 </el-button>
+    </template>
+  </el-dialog>
+</template>
+<script setup>
+import { ElMessage, ElMessageBox } from "element-plus";
+import byForm from "@/components/byForm/index";
+
+const props = defineProps({
+  title: {
+    type: String,
+    default: "目录",
+  },
+  submitType: {
+    type: String,
+    default: "1",
+  },
+  data: {
+    type: Array,
+    default: [],
+  },
+});
+onMounted(() => {});
+const search = ref("");
+const emit = defineEmits(["update:modelValue"]);
+const { proxy } = getCurrentInstance();
+const treeChange = (e) => {
+  if (proxy.type == "radio") {
+    emit("update:modelValue", e.id);
+    emit("change", e);
+  } else {
+    emit("change", e);
+  }
+};
+const filterNode = (value, data) => {
+  if (!value) return true;
+  return data.label.indexOf(value) !== -1;
+};
+const searchChange = () => {
+  proxy.$refs.tree.filter(search.value);
+};
+const submit = ref(null);
+let treeModal = ref(false);
+let submitLoading = ref(false);
+let treeModalType = ref("add");
+let formData = reactive({
+  data: {
+    type: 1,
+    parentFolderId: "-1",
+    name: "",
+  },
+});
+const formOption = reactive({
+  inline: true,
+  labelWidth: 100,
+  itemWidth: 100,
+  rules: [],
+});
+let rules = ref({
+  name: [{ required: true, message: "请输入目录名称", trigger: "blur" }],
+});
+const formConfig = computed(() => {
+  return [
+    {
+      type: "input",
+      prop: "name",
+      label: "目录名称",
+      required: true,
+    },
+  ];
+});
+const add = (data) => {
+  treeModalType.value = "add";
+  formData.data = {
+    type: 1,
+    parentFolderId: data.id,
+    name: "",
+  };
+  submitLoading.value = false;
+  treeModal.value = true;
+};
+const edit = (node, data) => {
+  treeModalType.value = "edit";
+  formData.data = {
+    type: 1,
+    parentFolderId: data.parentFolderId,
+    name: data.name,
+    id: data.id,
+  };
+  submitLoading.value = false;
+  treeModal.value = true;
+};
+const del = (data) => {
+  ElMessageBox.confirm("此操作将永久删除该数据, 是否继续?", "提示", {
+    confirmButtonText: "确定",
+    cancelButtonText: "取消",
+    type: "warning",
+  }).then(() => {
+    proxy.post("/netdisk/delete", [data.id]).then(() => {
+      ElMessage({
+        message: "删除成功",
+        type: "success",
+      });
+      getTreeList();
+    });
+  });
+};
+const submitForm = () => {
+  submit.value.handleSubmit(() => {
+    submitLoading.value = true;
+    proxy.post("/netdisk/" + treeModalType.value, formData.data).then(
+      () => {
+        ElMessage({
+          message: treeModalType.value == "add" ? "添加成功" : "编辑成功",
+          type: "success",
+        });
+        getTreeList();
+        treeModal.value = false;
+      },
+      (err) => {
+        console.log(err);
+        submitLoading.value = false;
+      }
+    );
+  });
+};
+const getTreeList = () => {
+  emit("changeTreeList");
+};
+</script>
+
+<style lang="scss">
+.custom-tree-node {
+  flex: 1;
+  display: flex;
+  align-items: center;
+  justify-content: space-between;
+  font-size: 14px;
+  padding-right: 8px;
+}
+.treeList {
+  display: block;
+  height: 100%;
+  background: #fff;
+  padding: 20px;
+  .search {
+    margin-bottom: 20px;
+    .el-input {
+      width: calc(100% - 70px);
+      margin-right: 10px;
+      text-align: center;
+    }
+  }
+}
+</style>

+ 315 - 0
src/views/oa/companyDisk/webDiskData/index.vue

@@ -0,0 +1,315 @@
+<template>
+  <div class="user">
+    <div class="tree">
+      <treeList
+        title="网盘目录"
+        submitType="1"
+        :data="treeListData"
+        v-model="sourceList.pagination.productClassifyId"
+        @change="treeChange"
+        @changeTreeList="getTreeList">
+      </treeList>
+    </div>
+    <div class="content">
+      <byTable
+        :source="sourceList.data"
+        :pagination="sourceList.pagination"
+        :config="config"
+        :loading="loading"
+        highlight-current-row
+        :action-list="[
+          {
+            text: '上传文件',
+            action: () => openModal(),
+            disabled: false,
+          },
+        ]"
+        @get-list="getList">
+        <template #name="{ item }">
+          <div>
+            <a style="color: #409eff; cursor: pointer" @click="clickName(item)">{{ item.name }}</a>
+          </div>
+        </template>
+        <template #fileSize="{ item }">
+          <div>
+            <div v-if="item.type === 2">
+              {{ getSize(item) }}
+            </div>
+          </div>
+        </template>
+      </byTable>
+    </div>
+
+    <el-dialog title="上传文件" v-if="dialogVisible" v-model="dialogVisible" width="500" v-loading="loadingDialog">
+      <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" :rules="rules" ref="submit">
+        <template #productFile>
+          <div style="width: 100%">
+            <el-upload
+              v-model:fileList="fileList"
+              action="https://winfaster.obs.cn-south-1.myhuaweicloud.com"
+              :data="uploadData"
+              multiple
+              :before-upload="uploadFile"
+              :on-preview="onPreviewFile">
+              <el-button>上传文件</el-button>
+            </el-upload>
+          </div>
+        </template>
+      </byForm>
+      <template #footer>
+        <el-button @click="dialogVisible = false" size="large">取 消</el-button>
+        <el-button type="primary" @click="submitForm()" size="large">确 定</el-button>
+      </template>
+    </el-dialog>
+  </div>
+</template>
+
+<script setup>
+import treeList from "@/components/webDiskData/treeList";
+import byTable from "@/components/byTable/index";
+import byForm from "@/components/byForm/index";
+import { computed, ref } from "vue";
+import { ElMessage, ElMessageBox } from "element-plus";
+
+const { proxy } = getCurrentInstance();
+const treeListData = ref([]);
+const sourceList = ref({
+  data: [],
+  pagination: {
+    total: 0,
+    pageNum: 1,
+    pageSize: 10,
+    parentFolderId: "",
+    keyword: "",
+  },
+});
+const treeChange = (e) => {
+  sourceList.value.pagination.parentFolderId = e.id;
+  sourceList.value.pagination.pageNum = 1;
+  getList();
+};
+const getTreeList = () => {
+  proxy.get("/netdisk/tree", {}).then((res) => {
+    treeListData.value = res.data;
+  });
+};
+const loading = ref(false);
+const getList = async (req) => {
+  sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
+  loading.value = true;
+  proxy.post("/netdisk/page", sourceList.value.pagination).then((res) => {
+    sourceList.value.data = res.rows;
+    sourceList.value.pagination.total = res.total;
+    loading.value = false;
+  });
+};
+getTreeList();
+getList();
+const config = computed(() => {
+  return [
+    {
+      attrs: {
+        label: "文件名称",
+        slot: "name",
+      },
+    },
+    {
+      attrs: {
+        label: "类型",
+        prop: "type",
+        width: 120,
+      },
+      render(type) {
+        return type == 1 ? "文件夹" : type == 2 ? "文件" : "";
+      },
+    },
+    {
+      attrs: {
+        label: "大小",
+        slot: "fileSize",
+        width: 160,
+      },
+    },
+    {
+      attrs: {
+        label: "创建人",
+        prop: "createUserName",
+        width: 140,
+      },
+    },
+    {
+      attrs: {
+        label: "创建时间",
+        prop: "createTime",
+        width: 160,
+      },
+    },
+    {
+      attrs: {
+        label: "操作",
+        width: "100",
+        align: "center",
+      },
+      renderHTML(row) {
+        return [
+          {
+            attrs: {
+              label: "删除",
+              type: "primary",
+              text: true,
+            },
+            el: "button",
+            click() {
+              ElMessageBox.confirm("此操作将永久删除该数据, 是否继续?", "提示", {
+                confirmButtonText: "确定",
+                cancelButtonText: "取消",
+                type: "warning",
+              }).then(() => {
+                proxy.post("/netdisk/delete", [row.id]).then(() => {
+                  ElMessage({
+                    message: "删除成功",
+                    type: "success",
+                  });
+                  getList();
+                });
+              });
+            },
+          },
+        ];
+      },
+    },
+  ];
+});
+const dialogVisible = ref(false);
+const loadingDialog = ref(false);
+const submit = ref(null);
+const formOption = reactive({
+  inline: true,
+  labelWidth: 100,
+  itemWidth: 100,
+  rules: [],
+});
+const fileList = ref([]);
+const uploadData = ref({});
+const formData = reactive({
+  data: {
+    type: 2,
+  },
+});
+const formConfig = computed(() => {
+  return [
+    {
+      type: "treeSelect",
+      prop: "parentFolderId",
+      label: "网盘目录",
+      data: treeListData.value,
+      propsTreeLabel: "name",
+      propsTreeChildren: "netdiskList",
+    },
+    {
+      type: "slot",
+      slotName: "productFile",
+      prop: "fileList",
+      label: "文件",
+    },
+  ];
+});
+let rules = ref({
+  parentFolderId: [{ required: true, message: "请选择网盘目录", trigger: "blur" }],
+});
+const openModal = () => {
+  formData.data = {
+    type: 2,
+  };
+  fileList.value = [];
+  loadingDialog.value = false;
+  dialogVisible.value = true;
+};
+const uploadFile = async (file) => {
+  const res = await proxy.post("/fileInfo/getSing", { fileName: file.name });
+  uploadData.value = res.uploadBody;
+  file.id = res.id;
+  file.fileName = res.fileName;
+  file.fileUrl = res.fileUrl;
+  return true;
+};
+const onPreviewFile = (file) => {
+  window.open(file.raw.fileUrl, "_blank");
+};
+const submitForm = () => {
+  submit.value.handleSubmit(() => {
+    if (fileList.value && fileList.value.length > 0) {
+      formData.data.fileList = fileList.value.map((item) => {
+        return {
+          id: item.raw.id,
+          fileName: item.raw.fileName,
+          fileSize: item.raw.size,
+        };
+      });
+      loadingDialog.value = true;
+      proxy.post("/netdisk/add", formData.data).then(
+        () => {
+          ElMessage({
+            message: "上传成功",
+            type: "success",
+          });
+          dialogVisible.value = false;
+          getList();
+        },
+        (err) => {
+          console.log(err);
+          loadingDialog.value = false;
+        }
+      );
+    } else {
+      return ElMessage("请上传文件");
+    }
+  });
+};
+const clickName = (item) => {
+  if (item.type === 2) {
+    proxy.post("/fileInfo/getList", { businessIdList: [item.id] }).then((res) => {
+      window.open(res[item.id][0].fileUrl, "_blank");
+    });
+  } else {
+    sourceList.value.pagination.pageNum = 1;
+    sourceList.value.pagination.parentFolderId = item.id;
+    getList();
+  }
+};
+const getSize = (item) => {
+  let size = "";
+  if (1024 > item.fileSize) {
+    size = item.fileSize + "B";
+  } else if (1024 * 1024 > item.fileSize) {
+    size = parseFloat(Number(item.fileSize) / 1024).toFixed(2) + "KB";
+  } else if (1024 * 1024 * 1024 > item.fileSize) {
+    size = parseFloat(Number(item.fileSize) / 1024 / 1024).toFixed(2) + "MB";
+  } else if (1024 * 1024 * 1024 * 1024 > item.fileSize) {
+    size = parseFloat(Number(item.fileSize) / 1024 / 1024 / 1024).toFixed(2) + "GB";
+  }
+  console.log(size);
+  return size;
+};
+</script>
+
+<style lang="scss" scoped>
+.user {
+  padding: 20px;
+  display: flex;
+  justify-content: space-between;
+  .tree {
+    width: 300px;
+  }
+  .content {
+    width: calc(100% - 320px);
+  }
+}
+.pic {
+  object-fit: contain;
+  width: 50px;
+  height: 50px;
+  cursor: pointer;
+  vertical-align: middle;
+}
+</style>