index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <template>
  2. <div class="file-details">
  3. <div class="content">
  4. <div class="left-box">
  5. <!-- 左侧树菜单 -->
  6. <fileSystem
  7. :selected="selected"
  8. :list="listArr"
  9. :draggable="true"
  10. @delete-node="onDeltet"
  11. @on-click="onClick"
  12. @change-name="onChangeName"
  13. @addNode="onAddNode"
  14. >
  15. <template #icon="{ item }">
  16. <template v-if="item.isFolder">
  17. <icon v-if="item.expanded" class="iconfont" iconName="icon-24gf-folderOpen" />
  18. <icon v-else class="iconfont" iconName="icon-bg-folder" />
  19. </template>
  20. <treeIcon class="iconfont" :title="item.title" v-else />
  21. </template>
  22. <template #operation="{ type }">
  23. <!-- <i class="iconfont icon-add_file" v-if="type == 'addFolder'"></i> -->
  24. <i class="iconfont icon-xinzeng" v-if="type == 'addDocument'"></i>
  25. <i class="iconfont icon-bianji" v-if="type == 'Editable'"></i>
  26. <i class="iconfont icon-guanbi" v-if="type == 'deleteNode'"></i>
  27. </template>
  28. </fileSystem>
  29. </div>
  30. <div class="right-box">
  31. <div class="search">
  32. <a-input v-model:value="fileName" placeholder="请输入文件名称" />
  33. <a-button type="primary" preIcon="ant-design:search-outlined" @click="onSearch">查询</a-button>
  34. <a-button type="primary" style="float: right; margin-right: 20px" @click="openModal(true)">文件上传</a-button>
  35. <!-- <a-upload :before-upload="beforeUpload" :remove="handleRemove" :multiple="false" :file-list="fileList">
  36. <a-button type="primary" preIcon="ant-design:cloud-upload-outlined">文件上传</a-button>
  37. </a-upload> -->
  38. </div>
  39. <div class="list">
  40. <div class="bd-t"></div>
  41. <NormalTable
  42. v-if="alive"
  43. :searchParam="fileName"
  44. :nodeParam="nodeParam"
  45. :columns="columns"
  46. :list="getTree"
  47. :deleteById="deleteById"
  48. :downLoad="downLoad"
  49. designScope="file-detail"
  50. title="文件详情"
  51. />
  52. <div class="bd-b"></div>
  53. </div>
  54. </div>
  55. </div>
  56. </div>
  57. </template>
  58. <script lang="ts" setup name="system-user">
  59. import { useMessage } from '/@/hooks/web/useMessage';
  60. import fileSystem from './commen/fileSystem.vue';
  61. import icon from './commen/Icon/index.vue';
  62. import treeIcon from './commen/Icon/treeIcon.vue';
  63. import { ref, onMounted, reactive, nextTick } from 'vue';
  64. import NormalTable from '../comment/NormalTable.vue';
  65. import { columns } from './fileDetail.data';
  66. import { getTree, createFile, editMenu, delMenu, uploadApi, downLoad, deleteById } from './fileDetail.api';
  67. components: {
  68. fileSystem;
  69. }
  70. const { createMessage } = useMessage();
  71. let fileName = ref('');
  72. let fileList = reactive<any[]>([]); //上传文件列表
  73. // let uploadParam = reactive({}); //上传文件参数
  74. let nodeParam = reactive({}); //点击树节点时传递的参数
  75. let alive = ref(true); //点击树节点刷新表格数据
  76. //lxh tree
  77. let selected = reactive<any>({
  78. id: null,
  79. pid: null,
  80. title: '',
  81. isFolder: false,
  82. });
  83. //左侧菜单列表
  84. // const listArr = reactive(list);
  85. let listArr = reactive<any[]>([]);
  86. //递归遍历左侧菜单数据
  87. // let list2tree = (list) => {
  88. // list.forEach((child) => {
  89. // const pid = child.parentId;
  90. // if (pid) {
  91. // list.forEach((parent) => {
  92. // if (parent.id === pid) {
  93. // parent.children = parent.children || [];
  94. // parent.isFolder = true;
  95. // parent.title = parent.fileName;
  96. // parent.pid = parent.parentId;
  97. // parent.children.push({ id: child.id, isFolder: true, title: child.fileName, pid: child.parentId });
  98. // }
  99. // });
  100. // }
  101. // });
  102. // console.log(list, '999999999');
  103. // return list.filter((n) => n.parentId == 'root');
  104. // };
  105. let list2trees = (data) => {
  106. // 删除 所有 children,以防止多次调用
  107. data.forEach(function (item) {
  108. delete item.children;
  109. });
  110. // 将数据存储为 以 id 为 KEY 的 map 索引数据列
  111. let map = {};
  112. data.forEach(function (item) {
  113. map[item.id] = item;
  114. });
  115. var val = [];
  116. data.forEach(function (item) {
  117. item.isFolder = true;
  118. item.title = item.fileName;
  119. item.pid = item.parentId;
  120. // 以当前遍历项,的pid,去map对象中找到索引的id
  121. var parent = map[item.pid];
  122. // 好绕啊,如果找到索引,那么说明此项不在顶级当中,那么需要把此项添加到,他对应的父级中
  123. if (parent) {
  124. (parent.children || (parent.children = [])).push(item);
  125. } else {
  126. //如果没有在map中找到对应的索引ID,那么直接把 当前的item添加到 val结果集中,作为顶级
  127. val.push(item);
  128. }
  129. });
  130. return val;
  131. };
  132. //获取左侧菜单树数据
  133. let getTreeList = async () => {
  134. listArr.length = 0;
  135. let data = await getTree({ parentId: '' });
  136. let list = list2trees(data.records);
  137. console.log(list, 'list');
  138. listArr.push(...list);
  139. console.log(listArr, '树节点数据');
  140. };
  141. //点击目录
  142. const onClick = (node) => {
  143. selected = node;
  144. console.log(node, '点击树节点');
  145. alive.value = false;
  146. nextTick(() => {
  147. alive.value = true;
  148. nodeParam = node;
  149. });
  150. };
  151. // // 拖拽结束
  152. // const drop = (node) => {
  153. // console.log(node);
  154. // };
  155. //添加文件
  156. let onAddNode = async (node) => {
  157. console.log('新增111', node);
  158. let data = await createFile({ fileName: node.newName, type: 'FOL', parentId: node.id });
  159. console.log(data, '新增文件返回');
  160. getTreeList();
  161. };
  162. // 修改名字
  163. const onChangeName = (node) => {
  164. console.log(node, '修改菜单名称');
  165. editMenu({
  166. id: node.id,
  167. fileName: node.newName,
  168. parentId: node.pid,
  169. }).then((res) => {
  170. console.log(res, '修改文件返回');
  171. getTreeList();
  172. });
  173. };
  174. // 删除
  175. const onDeltet = (node) => {
  176. console.log(node, '删除菜单');
  177. if (node.pid == 'root') {
  178. createMessage.warning('根节点不能被删除!');
  179. } else {
  180. delMenu({ id: node.id }).then((res) => {
  181. console.log(res, '删除文件');
  182. getTreeList();
  183. });
  184. }
  185. };
  186. //查询列表
  187. let onSearch = () => {
  188. console.log(fileName.value, '查询参数');
  189. alive.value = false;
  190. nextTick(() => {
  191. alive.value = true;
  192. });
  193. };
  194. //上传文件
  195. let beforeUpload = (file) => {
  196. console.log(file, '选中文件');
  197. fileList = [...fileList, file];
  198. const formData = new FormData();
  199. formData.append('file', file);
  200. formData.append('parentId', selected.id);
  201. formData.append('isApprove', false);
  202. formData.append('fileType', '');
  203. uploadApi(formData).then((res) => {
  204. console.log(res, '上传文件');
  205. alive.value = false;
  206. nextTick(() => {
  207. alive.value = true;
  208. });
  209. });
  210. };
  211. // 文件移除
  212. let handleRemove = (file) => {
  213. const index = fileList.indexOf(file);
  214. const newFileList = fileList.slice();
  215. newFileList.splice(index, 1);
  216. fileList = newFileList;
  217. };
  218. onMounted(() => {
  219. getTreeList();
  220. });
  221. </script>
  222. <style lang="less" scoped>
  223. .file-details {
  224. width: 100%;
  225. height: 100%;
  226. padding: 15px;
  227. position: relative;
  228. background: url(../../../../assets/images/files/homes/bd.png) no-repeat center;
  229. .content {
  230. width: 100%;
  231. height: calc(100% - 30px);
  232. display: flex;
  233. flex-direction: row;
  234. justify-content: space-between;
  235. align-items: flex-start;
  236. .left-box {
  237. width: 15%;
  238. height: calc(100% - 20px);
  239. margin-bottom: 20px;
  240. padding: 20px;
  241. border: 2px solid #268bc1;
  242. box-shadow: 0px 0px 20px 7px rgba(30, 119, 186, 0.7) inset;
  243. -moz-box-shadow: 0px 0px 20px 7px rgba(30, 119, 186, 0.7) inset;
  244. -webkit-box-shadow: 0px 0px 20px 7px rgba(30, 119, 186, 0.7) inset;
  245. // lxh
  246. .iconfont {
  247. color: #fff;
  248. font-size: 12px;
  249. margin-left: 5px;
  250. }
  251. }
  252. .right-box {
  253. width: 85%;
  254. height: calc(100% - 20px);
  255. padding: 0px 0px 0px 15px;
  256. box-sizing: border-box;
  257. .search {
  258. height: 34px;
  259. line-height: 34px;
  260. margin-bottom: 15px;
  261. background: url(../../../../assets/images/files/details/cz-b.png) no-repeat;
  262. background-size: 100% 100%;
  263. }
  264. }
  265. .list {
  266. height: calc(100% - 49px);
  267. position: relative;
  268. .bd-t {
  269. height: 4px;
  270. width: 100%;
  271. position: absolute;
  272. top: 0px;
  273. background: url(../../../../assets/images/files/details/lb-b.png) no-repeat;
  274. background-size: 100% 100%;
  275. }
  276. .bd-b {
  277. height: 4px;
  278. width: 100%;
  279. position: absolute;
  280. bottom: 0px;
  281. background: url(../../../../assets/images/files/details/lb-b.png) no-repeat;
  282. background-size: 100% 100%;
  283. }
  284. }
  285. }
  286. }
  287. ::v-deep .jeecg-svg-icon {
  288. margin-right: 5px;
  289. }
  290. ::v-deep .jeecg-basic-table-form-container {
  291. padding: 0px 0px;
  292. }
  293. ::v-deep .zxm-btn-primary {
  294. background-color: transparent;
  295. border: none;
  296. background: url(../../../../assets/images/files/details/btn.png) no-repeat !important;
  297. background-size: 100% 100% !important;
  298. }
  299. ::v-deep .zxm-tree-switcher {
  300. background: transparent;
  301. }
  302. ::v-deep .zxm-input {
  303. width: 220px;
  304. height: 28px;
  305. background: transparent;
  306. border: 1px solid #31bccc;
  307. color: #fff;
  308. margin: 0px 20px;
  309. border-radius: 5px;
  310. }
  311. ::v-deep .zxm-btn-group {
  312. margin-right: 25px;
  313. }
  314. ::v-deep .zxm-upload {
  315. float: right;
  316. margin-right: 10px;
  317. }
  318. </style>