阅行客电子档案
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.

130 lines
3.9 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
  1. <template>
  2. <div class="app-container">
  3. <div class="container-main" style="justify-content: flex-start;">
  4. <!--侧边部门数据-->
  5. <div class="elect-cont-left">
  6. <div class="container-left">
  7. <span class="right-top-line" />
  8. <span class="left-bottom-line" />
  9. <div class="tree-scroll">
  10. <el-tree
  11. ref="tree"
  12. v-loading="crud.loading"
  13. :data="crud.data"
  14. node-key="id"
  15. :props="defaultProps"
  16. :expand-on-click-node="false"
  17. @node-click="handleNodeClick"
  18. />
  19. </div>
  20. </div>
  21. </div>
  22. <!--用户数据-->
  23. <TableList ref="tableList" :selected-category="selectedCategory" />
  24. </div>
  25. </div></template>
  26. <script>
  27. import CRUD, { presenter, header, crud } from '@crud/crud'
  28. import TableList from './module/tableList'
  29. import Vue from 'vue'
  30. export default {
  31. name: 'Classify',
  32. components: { TableList },
  33. cruds() {
  34. return CRUD({ title: '分类', url: 'api/category/menu', crudMethod: {}, sort: [] })
  35. },
  36. mixins: [presenter(), header(), crud()],
  37. data() {
  38. return {
  39. selectedCategory: {},
  40. defaultProps: { children: 'children', label: 'cnName' }
  41. }
  42. },
  43. created() {
  44. },
  45. methods: {
  46. filterData(data) {
  47. return data.filter(node => {
  48. if (node.children && node.children.length > 0) {
  49. node.children = this.filterData(node.children) // 递归处理子节点
  50. }
  51. return node.isType !== 3 // 过滤掉isType为3的节点
  52. })
  53. },
  54. // 逆归实现 获取指定元素
  55. findNode(tree, func) {
  56. for (const node of tree) {
  57. if (func(node)) return node
  58. if (node.children) {
  59. const res = this.findNode(node.children, func)
  60. if (res) return res
  61. }
  62. }
  63. return null
  64. },
  65. // 展开选中的父级
  66. expandParents(node) {
  67. node.expanded = true
  68. if (node.parent) {
  69. this.expandParents(node.parent)
  70. }
  71. },
  72. [CRUD.HOOK.afterRefresh]() {
  73. this.crud.data = this.filterData(this.crud.data)
  74. this.$nextTick(() => {
  75. let currentKey
  76. if (localStorage.getItem('classifyCategoryKey')) {
  77. currentKey = JSON.parse(localStorage.getItem('classifyCategoryKey'))
  78. } else {
  79. if (this.crud.data[0].isType === 1) {
  80. currentKey = this.findNode(this.crud.data[0].children, (node) => {
  81. return node.isType !== 1
  82. })
  83. } else {
  84. currentKey = this.crud.data[0]
  85. }
  86. }
  87. // 设置某个节点的当前选中状态
  88. this.$refs.tree.setCurrentKey(currentKey.id)
  89. this.$nextTick(() => {
  90. // 设置某个节点的父级展开
  91. const selectedKey = this.$refs.tree.getCurrentNode()
  92. if (this.$refs.tree.getNode(selectedKey) && this.$refs.tree.getNode(selectedKey).parent) {
  93. this.expandParents(this.$refs.tree.getNode(selectedKey).parent)
  94. }
  95. // 选中节点的门类详情
  96. this.handleNodeClick(selectedKey)
  97. })
  98. })
  99. },
  100. // 选中门类后,设置门类详情数据
  101. handleNodeClick(val) {
  102. if (val) {
  103. this.selectedCategory = val
  104. if (val.pid !== '0') {
  105. Vue.set(this.selectedCategory, 'parentName', this.$refs.tree.getNode(val.pid).data.cnName)
  106. }
  107. // 缓存当前的选中的
  108. localStorage.setItem('classifyCategoryKey', JSON.stringify(val))
  109. }
  110. }
  111. }
  112. }
  113. </script>
  114. <style lang="scss" scoped>
  115. [data-theme=dark] .elect-cont-left .container-left{
  116. min-height: calc(100vh - 160px);
  117. }
  118. [data-theme=dark] .elect-cont-right .container-right{
  119. min-height: calc(100vh - 212px);
  120. }
  121. [data-theme=light] .elect-cont-right .container-right{
  122. min-height: calc(100vh - 232px);
  123. }
  124. .tree-scroll{
  125. font-size: 14px;
  126. }
  127. </style>