| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324 |
- <template>
- <div class="file-details">
- <div class="content">
- <div class="left-box">
- <!-- 左侧树菜单 -->
- <fileSystem
- :selected="selected"
- :list="listArr"
- :draggable="true"
- @delete-node="onDeltet"
- @on-click="onClick"
- @change-name="onChangeName"
- @addNode="onAddNode"
- >
- <template #icon="{ item }">
- <template v-if="item.isFolder">
- <icon v-if="item.expanded" class="iconfont" iconName="icon-24gf-folderOpen" />
- <icon v-else class="iconfont" iconName="icon-bg-folder" />
- </template>
- <treeIcon class="iconfont" :title="item.title" v-else />
- </template>
- <template #operation="{ type }">
- <!-- <i class="iconfont icon-add_file" v-if="type == 'addFolder'"></i> -->
- <i class="iconfont icon-xinzeng" v-if="type == 'addDocument'"></i>
- <i class="iconfont icon-bianji" v-if="type == 'Editable'"></i>
- <i class="iconfont icon-guanbi" v-if="type == 'deleteNode'"></i>
- </template>
- </fileSystem>
- </div>
- <div class="right-box">
- <div class="search">
- <a-input v-model:value="fileName" placeholder="请输入文件名称" />
- <a-button type="primary" preIcon="ant-design:search-outlined" @click="onSearch">查询</a-button>
- <a-button type="primary" style="float: right; margin-right: 20px" @click="openModal(true)">文件上传</a-button>
- <!-- <a-upload :before-upload="beforeUpload" :remove="handleRemove" :multiple="false" :file-list="fileList">
- <a-button type="primary" preIcon="ant-design:cloud-upload-outlined">文件上传</a-button>
- </a-upload> -->
- </div>
- <div class="list">
- <div class="bd-t"></div>
- <NormalTable
- v-if="alive"
- :searchParam="fileName"
- :nodeParam="nodeParam"
- :columns="columns"
- :list="getTree"
- :deleteById="deleteById"
- :downLoad="downLoad"
- designScope="file-detail"
- title="文件详情"
- />
- <div class="bd-b"></div>
- </div>
- </div>
- </div>
- </div>
- </template>
- <script lang="ts" setup name="system-user">
- import { useMessage } from '/@/hooks/web/useMessage';
- import fileSystem from './commen/fileSystem.vue';
- import icon from './commen/Icon/index.vue';
- import treeIcon from './commen/Icon/treeIcon.vue';
- import { ref, onMounted, reactive, nextTick } from 'vue';
- import NormalTable from '../comment/NormalTable.vue';
- import { columns } from './fileDetail.data';
- import { getTree, createFile, editMenu, delMenu, uploadApi, downLoad, deleteById } from './fileDetail.api';
- components: {
- fileSystem;
- }
- const { createMessage } = useMessage();
- let fileName = ref('');
- let fileList = reactive<any[]>([]); //上传文件列表
- // let uploadParam = reactive({}); //上传文件参数
- let nodeParam = reactive({}); //点击树节点时传递的参数
- let alive = ref(true); //点击树节点刷新表格数据
- //lxh tree
- let selected = reactive<any>({
- id: null,
- pid: null,
- title: '',
- isFolder: false,
- });
- //左侧菜单列表
- // const listArr = reactive(list);
- let listArr = reactive<any[]>([]);
- //递归遍历左侧菜单数据
- // let list2tree = (list) => {
- // list.forEach((child) => {
- // const pid = child.parentId;
- // if (pid) {
- // list.forEach((parent) => {
- // if (parent.id === pid) {
- // parent.children = parent.children || [];
- // parent.isFolder = true;
- // parent.title = parent.fileName;
- // parent.pid = parent.parentId;
- // parent.children.push({ id: child.id, isFolder: true, title: child.fileName, pid: child.parentId });
- // }
- // });
- // }
- // });
- // console.log(list, '999999999');
- // return list.filter((n) => n.parentId == 'root');
- // };
- let list2trees = (data) => {
- // 删除 所有 children,以防止多次调用
- data.forEach(function (item) {
- delete item.children;
- });
- // 将数据存储为 以 id 为 KEY 的 map 索引数据列
- let map = {};
- data.forEach(function (item) {
- map[item.id] = item;
- });
- var val = [];
- data.forEach(function (item) {
- item.isFolder = true;
- item.title = item.fileName;
- item.pid = item.parentId;
- // 以当前遍历项,的pid,去map对象中找到索引的id
- var parent = map[item.pid];
- // 好绕啊,如果找到索引,那么说明此项不在顶级当中,那么需要把此项添加到,他对应的父级中
- if (parent) {
- (parent.children || (parent.children = [])).push(item);
- } else {
- //如果没有在map中找到对应的索引ID,那么直接把 当前的item添加到 val结果集中,作为顶级
- val.push(item);
- }
- });
- return val;
- };
- //获取左侧菜单树数据
- let getTreeList = async () => {
- listArr.length = 0;
- let data = await getTree({ parentId: '' });
- let list = list2trees(data.records);
- console.log(list, 'list');
- listArr.push(...list);
- console.log(listArr, '树节点数据');
- };
- //点击目录
- const onClick = (node) => {
- selected = node;
- console.log(node, '点击树节点');
- alive.value = false;
- nextTick(() => {
- alive.value = true;
- nodeParam = node;
- });
- };
- // // 拖拽结束
- // const drop = (node) => {
- // console.log(node);
- // };
- //添加文件
- let onAddNode = async (node) => {
- console.log('新增111', node);
- let data = await createFile({ fileName: node.newName, type: 'FOL', parentId: node.id });
- console.log(data, '新增文件返回');
- getTreeList();
- };
- // 修改名字
- const onChangeName = (node) => {
- console.log(node, '修改菜单名称');
- editMenu({
- id: node.id,
- fileName: node.newName,
- parentId: node.pid,
- }).then((res) => {
- console.log(res, '修改文件返回');
- getTreeList();
- });
- };
- // 删除
- const onDeltet = (node) => {
- console.log(node, '删除菜单');
- if (node.pid == 'root') {
- createMessage.warning('根节点不能被删除!');
- } else {
- delMenu({ id: node.id }).then((res) => {
- console.log(res, '删除文件');
- getTreeList();
- });
- }
- };
- //查询列表
- let onSearch = () => {
- console.log(fileName.value, '查询参数');
- alive.value = false;
- nextTick(() => {
- alive.value = true;
- });
- };
- //上传文件
- let beforeUpload = (file) => {
- console.log(file, '选中文件');
- fileList = [...fileList, file];
- const formData = new FormData();
- formData.append('file', file);
- formData.append('parentId', selected.id);
- formData.append('isApprove', false);
- formData.append('fileType', '');
- uploadApi(formData).then((res) => {
- console.log(res, '上传文件');
- alive.value = false;
- nextTick(() => {
- alive.value = true;
- });
- });
- };
- // 文件移除
- let handleRemove = (file) => {
- const index = fileList.indexOf(file);
- const newFileList = fileList.slice();
- newFileList.splice(index, 1);
- fileList = newFileList;
- };
- onMounted(() => {
- getTreeList();
- });
- </script>
- <style lang="less" scoped>
- .file-details {
- width: 100%;
- height: 100%;
- padding: 15px;
- position: relative;
- background: url(../../../../assets/images/files/homes/bd.png) no-repeat center;
- .content {
- width: 100%;
- height: calc(100% - 30px);
- display: flex;
- flex-direction: row;
- justify-content: space-between;
- align-items: flex-start;
- .left-box {
- width: 15%;
- height: calc(100% - 20px);
- margin-bottom: 20px;
- padding: 20px;
- border: 2px solid #268bc1;
- box-shadow: 0px 0px 20px 7px rgba(30, 119, 186, 0.7) inset;
- -moz-box-shadow: 0px 0px 20px 7px rgba(30, 119, 186, 0.7) inset;
- -webkit-box-shadow: 0px 0px 20px 7px rgba(30, 119, 186, 0.7) inset;
- // lxh
- .iconfont {
- color: #fff;
- font-size: 12px;
- margin-left: 5px;
- }
- }
- .right-box {
- width: 85%;
- height: calc(100% - 20px);
- padding: 0px 0px 0px 15px;
- box-sizing: border-box;
- .search {
- height: 34px;
- line-height: 34px;
- margin-bottom: 15px;
- background: url(../../../../assets/images/files/details/cz-b.png) no-repeat;
- background-size: 100% 100%;
- }
- }
- .list {
- height: calc(100% - 49px);
- position: relative;
- .bd-t {
- height: 4px;
- width: 100%;
- position: absolute;
- top: 0px;
- background: url(../../../../assets/images/files/details/lb-b.png) no-repeat;
- background-size: 100% 100%;
- }
- .bd-b {
- height: 4px;
- width: 100%;
- position: absolute;
- bottom: 0px;
- background: url(../../../../assets/images/files/details/lb-b.png) no-repeat;
- background-size: 100% 100%;
- }
- }
- }
- }
- ::v-deep .jeecg-svg-icon {
- margin-right: 5px;
- }
- ::v-deep .jeecg-basic-table-form-container {
- padding: 0px 0px;
- }
- ::v-deep .zxm-btn-primary {
- background-color: transparent;
- border: none;
- background: url(../../../../assets/images/files/details/btn.png) no-repeat !important;
- background-size: 100% 100% !important;
- }
- ::v-deep .zxm-tree-switcher {
- background: transparent;
- }
- ::v-deep .zxm-input {
- width: 220px;
- height: 28px;
- background: transparent;
- border: 1px solid #31bccc;
- color: #fff;
- margin: 0px 20px;
- border-radius: 5px;
- }
- ::v-deep .zxm-btn-group {
- margin-right: 25px;
- }
- ::v-deep .zxm-upload {
- float: right;
- margin-right: 10px;
- }
- </style>
|