TreeLevel.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template lang="pug">
  2. ul.treeview-level
  3. //- ROOT NODE
  4. li.treeview-node(v-if='!props.parentId')
  5. .treeview-label(@click='setRoot', :class='{ "active": !selection }')
  6. q-icon(name='img:/_assets/icons/fluent-ftp.svg', size='sm')
  7. .treeview-label-text(:class='$q.dark.isActive ? `text-purple-4` : `text-purple`') root
  8. q-menu(
  9. v-if='rootContextActionList.length > 0'
  10. touch-position
  11. context-menu
  12. auto-close
  13. transition-show='jump-down'
  14. transition-hide='jump-up'
  15. )
  16. q-card.q-pa-sm
  17. q-list(dense, style='min-width: 150px;')
  18. q-item(
  19. v-for='action of rootContextActionList'
  20. :key='action.key'
  21. clickable
  22. @click='action.handler(null)'
  23. )
  24. q-item-section(side)
  25. q-icon(:name='action.icon', :color='action.iconColor')
  26. q-item-section(:class='action.labelColor && (`text-` + action.labelColor)') {{action.label}}
  27. q-icon(
  28. v-if='!selection'
  29. name='las la-angle-right'
  30. :color='$q.dark.isActive ? `purple-4` : `purple`'
  31. )
  32. //- NORMAL NODES
  33. tree-node(
  34. v-for='node of level'
  35. :key='node.id'
  36. :node='node'
  37. :depth='props.depth'
  38. :parent-id='props.parentId'
  39. )
  40. </template>
  41. <script setup>
  42. import { computed, inject } from 'vue'
  43. import { useQuasar } from 'quasar'
  44. import TreeNode from './TreeNode.vue'
  45. // PROPS
  46. const props = defineProps({
  47. depth: {
  48. required: true,
  49. type: Number
  50. },
  51. parentId: {
  52. type: String,
  53. default: null
  54. }
  55. })
  56. // QUASAR
  57. const $q = useQuasar()
  58. // INJECT
  59. const roots = inject('roots')
  60. const nodes = inject('nodes')
  61. const selection = inject('selection')
  62. const contextActionList = inject('contextActionList')
  63. // COMPUTED
  64. const rootContextActionList = computed(() => {
  65. if (props.parentId) { return [] }
  66. return contextActionList.filter(c => c.key === 'newFolder')
  67. })
  68. const level = computed(() => {
  69. const items = []
  70. if (!props.parentId) {
  71. for (const root of roots.value) {
  72. items.push({
  73. id: root,
  74. ...nodes[root]
  75. })
  76. }
  77. } else {
  78. for (const node of nodes[props.parentId].children) {
  79. items.push({
  80. id: node,
  81. ...nodes[node]
  82. })
  83. }
  84. }
  85. return items
  86. })
  87. // METHODS
  88. function setRoot () {
  89. selection.value = null
  90. }
  91. </script>