main.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. <template>
  2. <div class="ele-body">
  3. <el-card shadow="never" v-loading="loading">
  4. <ele-split-layout
  5. width="210px"
  6. allow-collapse
  7. :right-style="{ overflow: 'hidden' }"
  8. >
  9. <div>
  10. <!-- 操作按钮 -->
  11. <ele-toolbar class="ele-toolbar-actions">
  12. <div style="margin: 5px 0">
  13. <!-- <el-button
  14. size="small"
  15. type="primary"
  16. icon="el-icon-plus"
  17. class="ele-btn-icon"
  18. @click="openEdit()"
  19. >
  20. 添加
  21. </el-button>
  22. <el-button
  23. size="small"
  24. type="warning"
  25. icon="el-icon-edit"
  26. class="ele-btn-icon"
  27. :disabled="!current"
  28. @click="openEdit(current)"
  29. >
  30. 修改
  31. </el-button>
  32. <el-button
  33. size="small"
  34. type="danger"
  35. icon="el-icon-delete"
  36. class="ele-btn-icon"
  37. :disabled="!current"
  38. @click="remove"
  39. >
  40. 删除
  41. </el-button> -->
  42. </div>
  43. </ele-toolbar>
  44. <div class="ele-border-lighter sys-organization-list">
  45. <el-tree
  46. ref="tree"
  47. :data="data"
  48. highlight-current
  49. :draggable="true"
  50. node-key="id"
  51. :props="{ label: 'name', children: 'sonDirectoryList' }"
  52. :expand-on-click-node="false"
  53. :default-expand-all="true"
  54. @node-click="onNodeClick"
  55. @node-drop="nodeDrop"
  56. :allow-drop="allowDrop"
  57. >
  58. <span
  59. class="custom-tree-node"
  60. slot-scope="{ node, data }"
  61. @contextmenu.prevent="onRightClick(data,$event)"
  62. @click.prevent="clicka"
  63. ref="trueNodeRef"
  64. >
  65. <el-popover
  66. style="position: fixed; z-index: 2000"
  67. width="130"
  68. ref="popoverRef"
  69. v-model="visible"
  70. @click.native="visible = false"
  71. v-if="data.id == rightData.id && fileType === 0 && !isPop"
  72. >
  73. <div>
  74. <el-link
  75. v-if="lcyStatus == 1 && isPower(current)"
  76. :underline="false"
  77. @click.native="setPower(data)"
  78. >更改权限
  79. </el-link></div
  80. >
  81. <div>
  82. <el-link
  83. v-if="lcyStatus != 1"
  84. :underline="false"
  85. @click.native="goTo('文档工作区', data)"
  86. >转到文档工作区
  87. </el-link></div
  88. >
  89. <div>
  90. <el-link
  91. v-if="lcyStatus != '2'"
  92. :underline="false"
  93. @click.native="goTo('文档归档区', data)"
  94. >转到文档归档区
  95. </el-link></div
  96. >
  97. <div>
  98. <el-link
  99. v-if="lcyStatus != '3'"
  100. :underline="false"
  101. @click.native="goTo('文档发布区', data)"
  102. >转到文档发布区
  103. </el-link></div
  104. >
  105. </el-popover>
  106. <ElementTreeLine
  107. :node="node"
  108. :showLabelLine="true"
  109. :indent="20"
  110. >
  111. <img src="../../../assets/wjj.png" />
  112. <span>{{ node.label }}</span>
  113. </ElementTreeLine>
  114. </span>
  115. </el-tree>
  116. </div>
  117. </div>
  118. <template v-slot:content>
  119. <FileTableList
  120. ref="tableRef"
  121. :parentData="current"
  122. :folderList="data"
  123. @parenOpen="openEdit"
  124. :fileType="fileType"
  125. :lcyStatus="lcyStatus"
  126. :isPop="isPop"
  127. :disabledTableList="disabledTableList"
  128. />
  129. </template>
  130. </ele-split-layout>
  131. </el-card>
  132. <!-- 编辑弹窗 -->
  133. <folder-edit @done="query" ref="editRef" :fileType="fileType" />
  134. <!-- 文件夹权限 -->
  135. <ele-modal
  136. width="50vw"
  137. :visible="powerVisible"
  138. @close="powerVisible = false"
  139. :close-on-click-modal="false"
  140. append-to-body
  141. >
  142. <Power @powerSave="powerSave" ref="PowerRef" :powerArr="powerArr" />
  143. </ele-modal>
  144. <!-- {{current?.id}} -->
  145. </div>
  146. </template>
  147. <script>
  148. //
  149. import FileTableList from '@/views/doc/components/file-table-list.vue';
  150. import folderEdit from '@/views/doc/components/folder-edit.vue';
  151. import {
  152. directoryDeleteAPI,
  153. getDocTreeListAPI,
  154. directoryUpdateAPi,
  155. validationPersonal,
  156. moveDirectory
  157. } from '@/api/doc-manage';
  158. import { mapGetters } from 'vuex';
  159. import Power from './power/index.vue';
  160. import { isPower } from '../util.js';
  161. import ElementTreeLine from 'element-tree-line';
  162. // css
  163. import 'element-tree-line/dist/style.scss';
  164. export default {
  165. components: { FileTableList, folderEdit, ElementTreeLine, Power },
  166. props: {
  167. fileType: '', //0:公共文档 1:个人文档 2:文档模板
  168. lcyStatus: '', //1:文档工作区 2:文档归档区 3:文档发布区 4:文档废止区
  169. isPop: {
  170. //是否弹出
  171. default: false
  172. },
  173. disabledTableList: {
  174. //已选择列表
  175. default: () => []
  176. }
  177. },
  178. data() {
  179. return {
  180. isPower,
  181. powerArr: [
  182. { name: 'add', label: '新建' },
  183. { name: 'revise', label: '修改' },
  184. { name: 'del', label: '删除' }
  185. ],
  186. visible: false,
  187. powerVisible: false,
  188. rightData: {},
  189. // 加载状态
  190. loading: true,
  191. // 列表数据
  192. data: [],
  193. institutionList: [],
  194. // 选中数据
  195. current: {},
  196. // 是否显示表单弹窗
  197. showFolderEditFlag: false,
  198. // 编辑回显数据
  199. editData: null,
  200. // 上级id
  201. parentId: null
  202. };
  203. },
  204. computed: {
  205. ...mapGetters(['user'])
  206. },
  207. created() {
  208. this.query();
  209. },
  210. mounted() {
  211. document.addEventListener('click', this.clicka);
  212. },
  213. destroyed() {
  214. document.removeEventListener('click', this.clicka);
  215. },
  216. methods: {
  217. /* 查询 */
  218. async query(row) {
  219. this.loading = true;
  220. let query = {
  221. type: this.fileType,
  222. currentUserId: this.user.info.userId
  223. };
  224. this.data = await getDocTreeListAPI(query);
  225. if (this.fileType == 1 && this.data.length == 0) {
  226. await validationPersonal();
  227. await this.query();
  228. }
  229. this.$nextTick(() => {
  230. if (this.$route.params.row) {
  231. this.$refs.tree.setCurrentKey(this.$route.params.row.id);
  232. this.onNodeClick(this.$route.params.row);
  233. }else if (row&&row.id) {
  234. this.$refs.tree.setCurrentKey(row.id);
  235. this.onNodeClick(row);
  236. }else {
  237. this.$refs.tree.setCurrentKey(this.data[0].id);
  238. this.onNodeClick(this.data[0]);
  239. }
  240. });
  241. this.loading = false;
  242. },
  243. /* 选择数据 */
  244. onNodeClick(row, node, list) {
  245. console.log('row',row, node, list)
  246. if (row) {
  247. // 构建完整路径
  248. const fullPath = this.buildFullPath(row, this.data);
  249. // 将完整路径添加到current对象中
  250. this.current = {
  251. ...row,
  252. fullPath: fullPath
  253. };
  254. this.$nextTick(() => {
  255. this.$refs.tableRef.reload();
  256. });
  257. } else {
  258. this.current = null;
  259. }
  260. },
  261. /* 构建完整路径 */
  262. buildFullPath(currentNode, folderList) {
  263. // 如果节点没有parentId,直接返回节点名称
  264. if (!currentNode.parentId || currentNode.parentId === 0) {
  265. return currentNode.name;
  266. }
  267. // 递归查找上级节点
  268. function findParent(node, list) {
  269. let path = [node.name];
  270. let parentId = node.parentId;
  271. // 递归查找所有父节点
  272. function searchParent(id) {
  273. for (const item of list) {
  274. if (item.id === id) {
  275. path.unshift(item.name); // 将父节点名称添加到路径开头
  276. if (item.parentId && item.parentId !== 0) {
  277. searchParent(item.parentId); // 继续查找上一级
  278. }
  279. return;
  280. }
  281. // 如果当前节点有子节点,继续在子节点中查找
  282. if (item.sonDirectoryList && item.sonDirectoryList.length > 0) {
  283. searchParentInChildren(item.sonDirectoryList, id);
  284. }
  285. }
  286. }
  287. // 在子节点列表中查找父节点
  288. function searchParentInChildren(children, id) {
  289. for (const child of children) {
  290. if (child.id === id) {
  291. path.unshift(child.name);
  292. if (child.parentId && child.parentId !== 0) {
  293. searchParent(child.parentId);
  294. }
  295. return;
  296. }
  297. if (child.sonDirectoryList && child.sonDirectoryList.length > 0) {
  298. searchParentInChildren(child.sonDirectoryList, id);
  299. }
  300. }
  301. }
  302. if (parentId) {
  303. searchParent(parentId);
  304. }
  305. return path.join(' / ');
  306. }
  307. return findParent(currentNode, folderList);
  308. },
  309. allowDrop(draggingNode, dropNode, type) {
  310. //拖拽限制
  311. return dropNode.parent.id == draggingNode.parent.id && type != 'inner';
  312. },
  313. clicka() {
  314. this.visible = false;
  315. },
  316. onRightClick(data,PointerEvent) {
  317. this.rightData = data;
  318. this.visible = true;
  319. this.$nextTick(() => {
  320. let y = PointerEvent.pageY;
  321. let x = PointerEvent.pageX+10;
  322. if (PointerEvent.screenY >= PointerEvent.view.innerHeight) {
  323. y -= 80;
  324. }
  325. this.$refs.popoverRef.$el.style.top = y+'px'
  326. this.$refs.popoverRef.$el.style.left = x+'px'
  327. });
  328. },
  329. setPower(data) {
  330. this.powerVisible = true;
  331. this.$nextTick(() => {
  332. this.$refs.PowerRef &&
  333. this.$refs.PowerRef.setTableList(data.userAuthority || []);
  334. });
  335. },
  336. //权限保存
  337. powerSave(tableList) {
  338. directoryUpdateAPi({
  339. id: this.current.id,
  340. userAuthority: tableList,
  341. authority: 1
  342. }).then((msg) => {
  343. this.powerVisible = false;
  344. this.query();
  345. });
  346. },
  347. goTo(name, row) {
  348. this.$router.push({
  349. name,
  350. params: {
  351. row
  352. }
  353. });
  354. },
  355. /* 显示编辑 */
  356. openEdit(type) {
  357. if (type == 'del') {
  358. this.remove();
  359. return;
  360. }
  361. this.$refs.editRef.open(
  362. type,
  363. JSON.parse(JSON.stringify(this.current)),
  364. this.data
  365. );
  366. },
  367. /* 删除 */
  368. remove() {
  369. this.$confirm('确定要删除选中文件夹吗?', '提示', {
  370. type: 'warning'
  371. })
  372. .then(() => {
  373. const loading = this.$loading({ lock: true });
  374. directoryDeleteAPI([this.current.id])
  375. .then((msg) => {
  376. loading.close();
  377. this.$message.success('操作成功');
  378. this.query();
  379. })
  380. .catch((e) => {
  381. loading.close();
  382. });
  383. })
  384. .catch(() => {});
  385. },
  386. nodeDrop(to, form) {
  387. moveDirectory({
  388. targetId: form.data.id,
  389. replaceId: to.data.id
  390. });
  391. },
  392. getTableList() {
  393. return this.$refs.tableRef.getTableList();
  394. }
  395. }
  396. };
  397. </script>
  398. <style lang="scss" scoped>
  399. .sys-organization-list {
  400. height: calc(100vh - 180px);
  401. box-sizing: border-box;
  402. border-width: 1px;
  403. border-style: solid;
  404. overflow: auto;
  405. }
  406. .sys-organization-list :deep(.el-tree-node__content) {
  407. height: 25px;
  408. & > .el-tree-node__expand-icon {
  409. margin-left: 10px;
  410. }
  411. }
  412. .custom-tree-node {
  413. display: flex;
  414. align-items: center;
  415. }
  416. :deep(.el-popover) {
  417. min-width: 50px;
  418. position: fixed;
  419. background: #409EFF;
  420. }
  421. :deep(.el-link--inner) {
  422. padding: 3px 0;
  423. }
  424. :deep(.el-link.el-link--default) {
  425. color:#fff
  426. }
  427. // :deep(.element-tree-node-line-hor) {
  428. // border-bottom: 1px solid #dcdfe6;
  429. // }
  430. // :deep(.element-tree-node-line-ver) {
  431. // border-left: 1px solid #dcdfe6;
  432. // }
  433. </style>
  434. <style lang="scss">
  435. .el-tree
  436. > .el-tree-node
  437. > .el-tree-node__content:nth-of-type(1)
  438. .element-tree-node-line-hor {
  439. border: none;
  440. }
  441. .el-tree
  442. > .el-tree-node
  443. > .el-tree-node__content:nth-of-type(1)
  444. .element-tree-node-line-ver {
  445. border: none;
  446. }
  447. </style>