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

182 lines
4.9 KiB

2 years ago
2 years ago
2 years ago
  1. <template>
  2. <div class="elect-cont-left">
  3. <div class="container-left">
  4. <span class="right-top-line" />
  5. <span class="left-bottom-line" />
  6. <div class="arc-left-tree">
  7. <h3 class="arc-title arc-title-top">档案门类</h3>
  8. <div class="tree-scroll">
  9. <el-tree ref="tree" v-loading="loading" class="arc-tree" :data="categroyTree" :props="defaultProps" node-key="id" :expand-on-click-node="false" highlight-current @node-click="handleNodeClick">
  10. <span slot-scope="{ node, data }" class="custom-tree-node">
  11. <span v-if="data.isType === 1 " class="iconFolder">
  12. {{ data.cnName }}
  13. </span>
  14. <span v-if="data.isType === 2" class="iconArch">
  15. {{ data.cnName }}
  16. </span>
  17. <span v-if="data.isType === 3" class="iconFile">
  18. {{ data.cnName }}
  19. </span>
  20. </span>
  21. </el-tree>
  22. </div>
  23. </div>
  24. </div>
  25. </div>
  26. </template>
  27. <script>
  28. import { FetchCategoryMenu } from '@/api/system/category/category'
  29. export default {
  30. name: 'CategoryTree',
  31. data() {
  32. return {
  33. categroyTree: [],
  34. loading: false,
  35. defaultProps: {
  36. children: 'children',
  37. label: 'cnName'
  38. },
  39. selectedCategory: {}
  40. }
  41. },
  42. watch: {
  43. },
  44. created() {
  45. this.getCateTree()
  46. },
  47. mounted() {
  48. },
  49. methods: {
  50. filterData(data) {
  51. return data.filter(node => {
  52. if (node.children && node.children.length > 0) {
  53. node.children = this.filterData(node.children) // 递归处理子节点
  54. }
  55. return node.isType !== 3 // 过滤掉isType为3的节点
  56. })
  57. },
  58. // 逆归实现 获取指定元素
  59. findNode(tree, func) {
  60. for (const node of tree) {
  61. if (func(node)) return node
  62. if (node.children) {
  63. const res = this.findNode(node.children, func)
  64. if (res) return res
  65. }
  66. }
  67. return null
  68. },
  69. // 展开选中的父级
  70. expandParents(node) {
  71. node.expanded = true
  72. if (node.parent) {
  73. this.expandParents(node.parent)
  74. }
  75. },
  76. getCateTree() {
  77. this.loading = true
  78. FetchCategoryMenu().then(res => {
  79. this.categroyTree = this.filterData(res)
  80. this.$nextTick(() => {
  81. let currentKey
  82. if (this.categroyTree[0].isType === 1) {
  83. currentKey = this.findNode(this.categroyTree[0].children, (node) => {
  84. return node.isType !== 1
  85. })
  86. } else {
  87. currentKey = this.categroyTree[0]
  88. }
  89. if (currentKey.id) {
  90. // 设置某个节点的当前选中状态
  91. this.$refs.tree.setCurrentKey(currentKey.id)
  92. this.$nextTick(() => {
  93. // 设置某个节点的父级展开
  94. const selectedKey = this.$refs.tree.getCurrentNode()
  95. if (this.$refs.tree.getNode(selectedKey) && this.$refs.tree.getNode(selectedKey).parent) {
  96. this.expandParents(this.$refs.tree.getNode(selectedKey).parent)
  97. }
  98. // 选中节点的门类详情
  99. this.handleNodeClick(selectedKey)
  100. })
  101. }
  102. })
  103. this.loading = false
  104. })
  105. },
  106. handleNodeClick(val) {
  107. this.selectedCategory = val
  108. if (val.cnName) {
  109. this.$emit('nodeClick', val)
  110. }
  111. }
  112. }
  113. }
  114. </script>
  115. <style lang="scss" scoped>
  116. .elect-cont-left{
  117. width: 296px;
  118. padding: 0 !important;
  119. }
  120. [data-theme=light] .elect-cont-left .container-left {
  121. min-height: calc(100vh - 140px);
  122. }
  123. [data-theme=dark] .elect-cont-left .container-left {
  124. min-height: calc(100vh - 160px);
  125. }
  126. .openSidebar .elect-cont-right {
  127. width: calc(100vw - 592px);
  128. }
  129. // [data-theme=light] .elect-cont-right .container-right.tab-content {
  130. // min-height: calc(100vh - 200px) !important;
  131. // }
  132. [data-theme=light] .elect-cont-right {
  133. padding: 20px 0 !important;
  134. }
  135. [data-theme=dark] .elect-cont-right {
  136. margin-top: 0 !important;
  137. }
  138. .arc-title{
  139. position: relative;
  140. height: 48px;
  141. line-height: 48px;
  142. text-align: center;
  143. font-size: 16px;
  144. color: #0C0E1E;
  145. background-color: #F3F5F8;
  146. &::after{
  147. content: "";
  148. position: absolute;
  149. right: 12px;
  150. bottom: 0;
  151. }
  152. }
  153. .arc-title-top{
  154. &::after{
  155. width: 44px;
  156. height: 35px;
  157. background: url("~@/assets/images/collect/daml.png") no-repeat;
  158. background-size: 100% 100%;
  159. }
  160. }
  161. .arc-title-bottom{
  162. &::after{
  163. width: 41px;
  164. height: 40px;
  165. background: url("~@/assets/images/collect/kssx.png") no-repeat;
  166. background-size: 100% 100%;
  167. }
  168. }
  169. .arc-tree{
  170. padding: 0 20px;
  171. overflow: hidden;
  172. overflow-y: scroll;
  173. }
  174. ::v-deep .el-tree-node__children .custom-tree-node{
  175. font-size: 14px;
  176. font-weight: normal;
  177. }
  178. </style>