index.vue 11 KB

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