Skip to content

Commit dfa7fca

Browse files
committed
feat: 根目录也支持相应操作
1 parent ba8bfad commit dfa7fca

1 file changed

Lines changed: 29 additions & 7 deletions

File tree

frontend/src/layout/ViewLeft/ViewFolder.vue

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,29 @@
44
<div class="title">目录</div>
55

66
<el-tooltip content="切换目录" placement="bottom">
7-
<el-icon class="icon" @click="openDir()"><Files /></el-icon>
7+
<el-icon class="icon" @click="openDir()"><Switch /></el-icon>
88
</el-tooltip>
9+
10+
<template v-if="treeRef">
11+
<el-tooltip content="刷新目录" placement="top">
12+
<el-icon class="icon" @click.stop="refreshNode(treeRef.root)"><Refresh /></el-icon>
13+
</el-tooltip>
14+
15+
<el-tooltip content="上传文件" placement="top">
16+
<el-icon class="icon" @click.stop="uploadFile(treeRef.root)"><Upload /></el-icon>
17+
</el-tooltip>
18+
19+
<el-tooltip content="创建文件" placement="top">
20+
<el-icon class="icon" @click.stop="addFile(treeRef.root)"><DocumentAdd /></el-icon>
21+
</el-tooltip>
22+
</template>
923
</div>
1024

1125
<div class="content">
1226
<div class="list">
1327
<el-tree
1428
ref="treeRef"
15-
:key="like.cfg.folderActive"
29+
:key="`${like.cfg.folderActive}-${treeNum}`"
1630
:props="{ label: 'label', isLeaf: 'leaf' }"
1731
:load="loadNode"
1832
lazy
@@ -65,7 +79,7 @@
6579
<script lang="ts" setup>
6680
import { nextTick, ref, useTemplateRef } from 'vue'
6781
import { dayjs, ElMessage, ElMessageBox } from 'element-plus'
68-
import { Files, Folder, FolderOpened, Refresh, Upload, DocumentAdd } from '@element-plus/icons-vue'
82+
import { Switch, Folder, FolderOpened, Refresh, Upload, DocumentAdd } from '@element-plus/icons-vue'
6983
7084
import FileView from '@/components/FileView.vue'
7185
@@ -87,21 +101,24 @@ const uploadRef = useTemplateRef('upload')
87101
const uploadInfo = ref<RenderContentContext['node']>()
88102
89103
const treeRef = ref<TreeInstance>()
104+
const treeNum = ref(0)
90105
91106
const openDir = async () => {
92107
open.show = 'dir'
93108
}
94109
95110
const addFile = async (node: RenderContentContext['node']) => {
96111
try {
97-
const { value } = await ElMessageBox.prompt(`${node.data.value}/`, '创建文件', {
112+
const basePath = node.data.value || like.cfg.folderActive
113+
114+
const { value } = await ElMessageBox.prompt(`${basePath}/`, '创建文件', {
98115
inputValidator: (v) => (v ? true : '请输入文件名'),
99116
inputPlaceholder: '文件名+后缀',
100117
confirmButtonText: '确认',
101118
cancelButtonText: '取消',
102119
})
103120
104-
const path = `${node.data.value}/${value}`
121+
const path = `${basePath}/${value}`
105122
106123
await saveFile({ path, force: true, file: new Blob([new TextEncoder().encode(' ')]) })
107124
@@ -143,7 +160,7 @@ const uploadFileChange = async (e: any) => {
143160
}
144161
}
145162
146-
const path = `${uploadInfo.value.data.value}/${file.name}`
163+
const path = `${uploadInfo.value.data.value || like.cfg.folderActive}/${file.name}`
147164
148165
await saveFile({ path, force: true, file })
149166
@@ -162,7 +179,12 @@ const uploadFileChange = async (e: any) => {
162179
}
163180
164181
const refreshNode = (node: RenderContentContext['node']) => {
165-
loadNode(node, (data) => node.key && treeRef.value?.updateKeyChildren(node.key, data))
182+
const key = node.key
183+
if (key) {
184+
loadNode(node, (data) => treeRef.value?.updateKeyChildren(key, data))
185+
} else {
186+
treeNum.value++
187+
}
166188
}
167189
168190
const loadNode = async (node: RenderContentContext['node'], resolve: (v: TreeData) => void) => {

0 commit comments

Comments
 (0)