Browse Source

feat: directory tree refresh

after the directory operation in the upload pop-up dialog
Casper Dai 2 years ago
parent
commit
f8d9fc85ca

+ 8 - 0
src/components/tree/DirectoryTree/index.vue

@@ -244,6 +244,7 @@ export default {
         updateTreeNodeName(this.node).then(() => {
           done()
           this.selectedNode.name = this.node.name
+          this.$emit('refresh')
         })
       } else {
         addTreeNode(this.node).then(({ data }) => {
@@ -252,6 +253,7 @@ export default {
           if (!this.$selectedVNode.expanded) {
             this.$selectedComponent.handleExpandIconClick()
           }
+          this.$emit('refresh')
         })
       }
     },
@@ -278,7 +280,13 @@ export default {
         const { path, name } = this.group
         this.onDirectoryChange({ root: true, id: path, name, group: { path, name } })
         this.$refs.treeRef.setCurrentKey(path)
+        this.$emit('refresh')
       })
+    },
+    refresh () {
+      this.getDirectoryTree()
+      const { path } = this.group
+      this.onDirectoryChange({ root: true, id: path, name: '资源目录' })
     }
   }
 }

+ 4 - 0
src/layout/components/Navbar/UploadDashboard/index.vue

@@ -19,6 +19,7 @@
           :option="directoryOption"
           editable
           @change="onDirectoryChanged"
+          @refresh="onRefresh"
         />
         <div class="l-flex__fill l-flex--col c-sibling-item far">
           <div class="l-flex__none l-flex--row c-sibling-item--v">
@@ -164,6 +165,9 @@ export default {
       this.directoryInfo = root
         ? { org: group.path, directory: `${group.name}-${name}` }
         : { org: group.path, directory: `${group.name}-${name}`, treeId: id }
+    },
+    onRefresh () {
+      EventBus.$emit('directory-refresh', this.directoryOption)
     }
   }
 }

+ 12 - 0
src/views/screen/material/media/index.vue

@@ -7,6 +7,7 @@
     horizontal
   >
     <directory-tree
+      ref="tree"
       class="c-sibling-item c-sidebar u-width--md"
       editable
       remember
@@ -104,7 +105,18 @@ export default {
       }
     }
   },
+  created () {
+    EventBus.$on('directory-refresh', this.onDirectoryRefresh)
+  },
+  beforeDestroy () {
+    EventBus.$off('directory-refresh', this.onDirectoryRefresh)
+  },
   methods: {
+    onDirectoryRefresh (directoryOption) {
+      if (this.$directoryOption?.group?.path && directoryOption.group.path) {
+        this.$refs.tree?.refresh()
+      }
+    },
     canDel ({ status }) {
       return status !== State.DRAFT
     },