阅行客电子档案
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

156 lines
4.7 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <template>
  2. <div class="app-container">
  3. <!-- 门类列表 -->
  4. <div class="container-main" style="justify-content: flex-start;">
  5. <div class="elect-cont-left">
  6. <div class="container-left">
  7. <span class="right-top-line" />
  8. <span class="left-bottom-line" />
  9. <!--门类树状结构-->
  10. <div class="tree-scroll">
  11. <el-tree
  12. ref="tree"
  13. v-loading="crud.loading"
  14. :data="crud.data"
  15. node-key="id"
  16. :props="defaultProps"
  17. :expand-on-click-node="false"
  18. @node-click="handleNodeClick"
  19. />
  20. </div>
  21. </div>
  22. </div>
  23. <TableList ref="tableList" :selected-category="selectedCategory" />
  24. </div>
  25. </div>
  26. </template>
  27. <script>
  28. import CRUD, { presenter, header, crud } from '@crud/crud'
  29. import TableList from './module/tableList'
  30. import Vue from 'vue'
  31. export default {
  32. name: 'ArchiveScopeManage',
  33. components: { TableList },
  34. cruds() {
  35. return [
  36. CRUD({
  37. title: '归档范围', url: 'api/category/menu',
  38. crudMethod: {}, sort: []
  39. })
  40. ]
  41. },
  42. mixins: [presenter(), header(), crud()],
  43. data() {
  44. return {
  45. selectedCategory: {},
  46. defaultProps: { children: 'children', label: 'cnName' }
  47. }
  48. },
  49. computed: {
  50. },
  51. methods: {
  52. filterData(data) {
  53. return data.filter(node => {
  54. if (node.children && node.children.length > 0) {
  55. node.children = this.filterData(node.children) // 递归处理子节点
  56. }
  57. return node.isType !== 3 // 过滤掉isType为3的节点
  58. })
  59. },
  60. // 逆归实现 获取指定元素
  61. findNode(tree, func) {
  62. for (const node of tree) {
  63. if (func(node)) return node
  64. if (node.children) {
  65. const res = this.findNode(node.children, func)
  66. if (res) return res
  67. }
  68. }
  69. return null
  70. },
  71. // 展开选中的父级
  72. expandParents(node) {
  73. node.expanded = true
  74. if (node.parent) {
  75. this.expandParents(node.parent)
  76. }
  77. },
  78. [CRUD.HOOK.afterRefresh]() {
  79. this.crud.data = this.filterData(this.crud.data)
  80. this.$nextTick(() => {
  81. let currentKey
  82. if (localStorage.getItem('scopeCategoryKey')) {
  83. currentKey = JSON.parse(localStorage.getItem('scopeCategoryKey'))
  84. } else {
  85. if (this.crud.data[0].isType === 1) {
  86. currentKey = this.findNode(this.crud.data[0].children, (node) => {
  87. return node.isType !== 1
  88. })
  89. } else {
  90. currentKey = this.crud.data[0]
  91. }
  92. }
  93. // 设置某个节点的当前选中状态
  94. this.$refs.tree.setCurrentKey(currentKey.id)
  95. this.$nextTick(() => {
  96. // 设置某个节点的父级展开
  97. const selectedKey = this.$refs.tree.getCurrentNode()
  98. if (this.$refs.tree.getNode(selectedKey) && this.$refs.tree.getNode(selectedKey).parent) {
  99. this.expandParents(this.$refs.tree.getNode(selectedKey).parent)
  100. }
  101. // 选中节点的门类详情
  102. this.handleNodeClick(selectedKey)
  103. })
  104. })
  105. },
  106. // 选中门类后,设置门类详情数据
  107. handleNodeClick(val) {
  108. if (val) {
  109. this.selectedCategory = val
  110. if (val.pid !== '0') {
  111. Vue.set(this.selectedCategory, 'parentName', this.$refs.tree.getNode(val.pid).data.cnName)
  112. }
  113. // 缓存当前的选中的
  114. localStorage.setItem('scopeCategoryKey', JSON.stringify(val))
  115. }
  116. },
  117. // 新增 - 判断当前节点类型,卷内/文件不可新建
  118. [CRUD.HOOK.beforeToAdd](crud, form, btn) {
  119. const isCanAddKey = JSON.parse(localStorage.getItem('scopeCategoryKey'))
  120. if (isCanAddKey.isType === 4 || isCanAddKey.isType === 5) {
  121. this.$message({
  122. message: '此门类下不可新建门类',
  123. type: 'error',
  124. duration: 2500
  125. })
  126. return false
  127. }
  128. },
  129. // 新增/编辑后 - 新增后默认选中新增的门类
  130. [CRUD.HOOK.afterSubmit](crud, addedCategory) {
  131. if (addedCategory) {
  132. // 缓存当前的选中的
  133. localStorage.setItem('scopeCategoryKey', JSON.stringify(addedCategory))
  134. }
  135. }
  136. }
  137. }
  138. </script>
  139. <style lang="scss" scoped>
  140. [data-theme=dark] .elect-cont-left .container-left {
  141. min-height: calc(100vh - 160px);
  142. }
  143. [data-theme=dark] .elect-cont-right .container-right {
  144. min-height: calc(100vh - 212px);
  145. }
  146. [data-theme=light] .elect-cont-left .container-left {
  147. min-height: calc(100vh - 200px);
  148. }
  149. .tree-scroll{
  150. font-size: 14px;
  151. }
  152. </style>