index.vue 12 KB

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