index.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <template>
  2. <view class="tree-main">
  3. <ly-tree v-if="isReady" :props="props" :node-key="props.value" :load="loadNode" lazy :tree-data="treeData"
  4. show-node-icon :defaultExpandAll='false' />
  5. </view>
  6. </template>
  7. <script>
  8. import LyTree from './subordinateTree/ly-tree.vue'
  9. import {
  10. getSubordinate
  11. } from '@/api/common.js'
  12. let _self;
  13. export default {
  14. components: {
  15. LyTree
  16. },
  17. data() {
  18. return {
  19. isReady: false,
  20. props: {
  21. label: 'userName',
  22. isLeaf: 'isLeaf',
  23. value: "id",
  24. icon: 'avatar'
  25. },
  26. treeData: []
  27. }
  28. },
  29. onLoad() {
  30. _self = this
  31. this.isReady = true;
  32. },
  33. computed: {
  34. baseURL() {
  35. return this.define.baseURL
  36. }
  37. },
  38. methods: {
  39. loadNode(node, resolve) {
  40. if (node.level === 0) {
  41. getSubordinate(node.level).then(res => {
  42. let data = JSON.parse(JSON.stringify(res.data))
  43. data.map((o) => {
  44. o.avatar = _self.baseURL + o.avatar
  45. return data
  46. })
  47. resolve(data)
  48. })
  49. } else {
  50. getSubordinate(node.key).then(res => {
  51. let data = JSON.parse(JSON.stringify(res.data))
  52. data.map((o) => {
  53. o.avatar = _self.baseURL + o.avatar
  54. return data
  55. })
  56. resolve(data)
  57. })
  58. }
  59. }
  60. }
  61. }
  62. </script>
  63. <style>
  64. </style>