index.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <div>
  3. <el-container>
  4. <el-header class="el-button--primary" height="40px" style="line-height: 40px;">
  5. {{ title }}
  6. </el-header>
  7. <el-main class="tree-main" style="padding: 15px 0;">
  8. <el-tree
  9. :data="treeData"
  10. node-key="id"
  11. :props="defaultProps"
  12. :default-expanded-keys="defaultExpends"
  13. :style="styleObject"
  14. :highlight-current="false"
  15. @node-click="click"
  16. />
  17. </el-main>
  18. </el-container>
  19. </div>
  20. </template>
  21. <script>
  22. import { addNodesAttr } from '@/utils/tree'
  23. export default {
  24. name: 'Tree',
  25. props: {
  26. title: {
  27. type: String,
  28. default: ''
  29. },
  30. api: {
  31. type: Function,
  32. default: () => {}
  33. },
  34. dataQuery: {
  35. type: Object,
  36. default: () => {}
  37. },
  38. callBack: {
  39. type: Function,
  40. default: () => {}
  41. },
  42. click: {
  43. type: Function,
  44. default: () => {}
  45. },
  46. isShowAll: {
  47. type: Boolean,
  48. default: () => true
  49. },
  50. styleObject: {
  51. type: Object,
  52. default: () => {}
  53. },
  54. defaultExpends: {
  55. type: Array,
  56. default: () => []
  57. },
  58. props: {
  59. type: Object,
  60. default: () => {}
  61. }
  62. },
  63. data: function() {
  64. return {
  65. treeData: [],
  66. defaultProps: {
  67. children: 'nodes',
  68. label: 'name',
  69. value: 'id'
  70. }
  71. }
  72. },
  73. created() {
  74. if (typeof this.props === 'object') {
  75. Object.assign(this.defaultProps, this.props)
  76. }
  77. this.api(this.dataQuery).then(res => {
  78. this.treeData = addNodesAttr(res.data || [], 'opened', false) || []
  79. if (this.isShowAll) {
  80. this.treeData.unshift({ id: '', nodes: null, opened: false, parent: '', tag: { id: '' }, text: 'All' })
  81. }
  82. this.callBack(res.data)
  83. })
  84. }
  85. }
  86. </script>
  87. <style>
  88. .el-tree-node > .el-tree-node__children {
  89. overflow-x: auto
  90. }
  91. .tree-aside .tree-main{
  92. max-height: calc(100vh - 240px);
  93. }
  94. </style>