index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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" ref="formState" labelAlign="right" :label-col="{ span: 6 }"
  42. :wrapper-col="{ span: 16 }" >
  43. <a-form-item label="是否审批" name="isApprove" >
  44. <a-radio-group v-model:value="formState.isApprove" name="radioGroup">
  45. <a-radio value="true">是</a-radio>
  46. <a-radio value="false">否</a-radio>
  47. </a-radio-group>
  48. </a-form-item>
  49. <a-form-item label="文件类型" >
  50. <JDictSelectTag v-model:value="formState.fileType" placeholder="请选择文件类型" dictCode="file_type" 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. //左侧菜单列表
  92. let listArr = reactive<any[]>([]);
  93. //上传文件
  94. let openModal = (val) => {
  95. formState.isApprove=false
  96. formState.fileType=''
  97. fileList.length=0
  98. visible.value = val
  99. }
  100. //开始上传
  101. let handleOk = () => {
  102. uploadApi(startUpload.value).then((res) => {
  103. console.log(res, '上传文件');
  104. alive.value = false;
  105. nextTick(() => {
  106. alive.value = true;
  107. visible.value=false
  108. });
  109. });
  110. }
  111. //取消上传
  112. let handleCancel=()=>{
  113. visible.value = false
  114. }
  115. let list2trees = (data) => {
  116. // 删除 所有 children,以防止多次调用
  117. data.forEach(function (item) {
  118. delete item.children;
  119. });
  120. // 将数据存储为 以 id 为 KEY 的 map 索引数据列
  121. let map = {};
  122. data.forEach(function (item) {
  123. map[item.id] = item;
  124. });
  125. var val = [];
  126. data.forEach(function (item) {
  127. item.isFolder = true;
  128. item.title = item.fileName;
  129. item.pid = item.parentId;
  130. // 以当前遍历项,的pid,去map对象中找到索引的id
  131. var parent = map[item.pid];
  132. // 好绕啊,如果找到索引,那么说明此项不在顶级当中,那么需要把此项添加到,他对应的父级中
  133. if (parent) {
  134. (parent.children || (parent.children = [])).push(item);
  135. } else {
  136. //如果没有在map中找到对应的索引ID,那么直接把 当前的item添加到 val结果集中,作为顶级
  137. val.push(item);
  138. }
  139. });
  140. return val;
  141. };
  142. //获取左侧菜单树数据
  143. let getTreeList = async () => {
  144. listArr.length = 0;
  145. let data = await getTree({ parentId: '' });
  146. let list = list2trees(data.records);
  147. console.log(list, 'list');
  148. listArr.push(...list);
  149. console.log(listArr, '树节点数据');
  150. selected.id=listArr[0].id
  151. selected.pid=listArr[0].pid
  152. selected.title=listArr[0].title
  153. selected.isFolder=listArr[0].isFolder
  154. };
  155. //点击目录
  156. const onClick = (node) => {
  157. selected = node;
  158. console.log(node, '点击树节点');
  159. alive.value = false;
  160. nextTick(() => {
  161. alive.value = true;
  162. nodeParam = node;
  163. });
  164. };
  165. // // 拖拽结束
  166. // const drop = (node) => {
  167. // console.log(node);
  168. // };
  169. //添加文件
  170. let onAddNode = async (node) => {
  171. console.log('新增111', node);
  172. let data = await createFile({ fileName: node.newName, type: 'FOL', parentId: node.id });
  173. console.log(data, '新增文件返回');
  174. getTreeList();
  175. };
  176. // 修改名字
  177. const onChangeName = (node) => {
  178. console.log(node, '修改菜单名称');
  179. editMenu({
  180. id: node.id,
  181. fileName: node.newName,
  182. parentId: node.pid,
  183. }).then((res) => {
  184. console.log(res, '修改文件返回');
  185. getTreeList();
  186. });
  187. };
  188. // 删除
  189. const onDeltet = (node) => {
  190. console.log(node, '删除菜单');
  191. if (node.pid == 'root') {
  192. createMessage.warning('根节点不能被删除!');
  193. } else {
  194. delMenu({ id: node.id }).then((res) => {
  195. console.log(res, '删除文件');
  196. getTreeList();
  197. });
  198. }
  199. };
  200. //查询列表
  201. let onSearch = () => {
  202. console.log(fileName.value, '查询参数');
  203. alive.value = false;
  204. nextTick(() => {
  205. alive.value = true;
  206. });
  207. };
  208. //上传文件
  209. let beforeUpload = (file) => {
  210. console.log(file, '选中文件');
  211. fileList.length=0;
  212. fileList.push(file)
  213. const formData = new FormData();
  214. formData.append('file', file);
  215. formData.append('parentId', selected.id);
  216. formData.append('isApprove', formState.isApprove);
  217. formData.append('fileType', formState.fileType);
  218. startUpload.value=formData
  219. };
  220. // 文件移除
  221. let handleRemove = (file) => {
  222. const index = fileList.indexOf(file);
  223. const newFileList = fileList.slice();
  224. newFileList.splice(index, 1);
  225. fileList = newFileList;
  226. };
  227. onMounted(() => {
  228. getTreeList();
  229. });
  230. </script>
  231. <style lang="less" scoped>
  232. .file-details {
  233. width: 100%;
  234. height: 100%;
  235. padding: 15px;
  236. position: relative;
  237. // background: url(../../../../assets/images/files/homes/bd.png) no-repeat center;
  238. .content {
  239. width: 100%;
  240. height: calc(100% - 30px);
  241. display: flex;
  242. flex-direction: row;
  243. justify-content: space-between;
  244. align-items: flex-start;
  245. .left-box {
  246. // width: 15%;
  247. // height: calc(100% - 20px);
  248. // margin-bottom: 20px;
  249. // padding: 20px;
  250. // border: 1px solid #91e9fe;
  251. // box-shadow: 0px 0px 20px 7px rgba(145, 233, 254, 0.7) inset;
  252. // -moz-box-shadow: 0px 0px 20px 7px rgba(145, 233, 254, 0.7) inset;
  253. // -webkit-box-shadow: 0px 0px 20px 7px rgba(145, 233, 254, 0.7) inset;
  254. width: 15%;
  255. height: calc(100% - 20px);
  256. margin-bottom: 20px;
  257. padding: 20px;
  258. border: 1px solid #99e8ff66;
  259. background: #27546e4a;
  260. box-shadow: 0px 0px 20px 7px rgba(145, 233, 254, 0.7) inset;
  261. -moz-box-shadow: 0px 0px 20px 7px rgba(145, 233, 254, 0.7) inset;
  262. -webkit-box-shadow: 0px 0px 50px 1px rgb(149 235 255 / 5%) inset;
  263. // border: 2px solid #268bc1;
  264. // box-shadow: 0px 0px 20px 7px rgba(30, 119, 186, 0.7) inset;
  265. // -moz-box-shadow: 0px 0px 20px 7px rgba(30, 119, 186, 0.7) inset;
  266. // -webkit-box-shadow: 0px 0px 20px 7px rgba(30, 119, 186, 0.7) inset;
  267. // lxh
  268. .iconfont {
  269. color: #fff;
  270. font-size: 12px;
  271. margin-left: 5px;
  272. }
  273. }
  274. .right-box {
  275. width: 85%;
  276. height: calc(100% - 20px);
  277. padding: 0px 0px 0px 15px;
  278. box-sizing: border-box;
  279. .search {
  280. height: 34px;
  281. line-height: 34px;
  282. margin-bottom: 15px;
  283. // background: url(../../../../assets/images/files/details/cz-b.png) no-repeat;
  284. // background-size: 100% 100%;
  285. }
  286. }
  287. .list {
  288. height: calc(100% - 49px);
  289. position: relative;
  290. .bd-t {
  291. height: 4px;
  292. width: 100%;
  293. position: absolute;
  294. top: 0px;
  295. background: url(../../../../assets/images/files/details/lb-b.png) no-repeat;
  296. background-size: 100% 100%;
  297. }
  298. .bd-b {
  299. height: 4px;
  300. width: 100%;
  301. position: absolute;
  302. bottom: 0px;
  303. background: url(../../../../assets/images/files/details/lb-b.png) no-repeat;
  304. background-size: 100% 100%;
  305. }
  306. }
  307. }
  308. .zxm-form {
  309. padding: 10px !important;
  310. }
  311. }
  312. ::v-deep .jeecg-svg-icon {
  313. margin-right: 5px;
  314. }
  315. ::v-deep .jeecg-basic-table-form-container {
  316. padding: 0px 0px;
  317. }
  318. ::v-deep .zxm-btn-primary {
  319. background-color: transparent;
  320. border: none;
  321. background: url(../../../../assets/images/files/details/btn.png) no-repeat !important;
  322. background-size: 100% 100% !important;
  323. }
  324. ::v-deep .zxm-tree-switcher {
  325. background: transparent;
  326. }
  327. ::v-deep .zxm-input {
  328. width: 220px;
  329. height: 28px;
  330. background: transparent;
  331. border: 1px solid #31bccc;
  332. color: #fff;
  333. margin: 0px 20px;
  334. border-radius: 5px;
  335. }
  336. ::v-deep .zxm-btn-group {
  337. margin-right: 25px;
  338. }
  339. ::v-deep .zxm-upload-list-item-name{
  340. color: #fff;
  341. }
  342. ::v-deep .zxm-upload-list-item-name:hover{
  343. color: #000;
  344. }
  345. </style>