1
1
<script setup lang="ts">
2
2
import { baseUrlApi } from " @/api/utils" ;
3
3
import { http } from " @/utils/http" ;
4
- import data from " @iconify-icons/ri/fullscreen-fill" ;
5
4
import PureTable from " @pureadmin/table" ;
6
5
import qs from " qs" ;
7
6
import { onMounted , ref } from " vue" ;
@@ -25,7 +24,11 @@ const tableData = ref([]);
25
24
// 在 'onMounted' 钩子中发起 HTTP 请求
26
25
onMounted (async () => {
27
26
try {
28
- const response = await http .request <FilesResult >(" get" , baseUrlApi (" /api/list/" ));
27
+ const response = await http .request <FilesResult >(" get" , baseUrlApi (" /api/list/" ));
28
+ const items = response .items ;
29
+ items .forEach (item => {
30
+ item .type = item .type === 0 ? ' 文件夹' : ' 文件' ;
31
+ });
29
32
tableData .value = response .items ;
30
33
} catch (error ) {
31
34
console .error (' There was an error fetching the data:' , error );
@@ -47,6 +50,22 @@ const toggleSelection = (rows?: any) => {
47
50
const handleSelectionChange = val => {
48
51
multipleSelection .value = val ;
49
52
};
53
+ const handleRowClick = async row => {
54
+ if (row .type === ' 文件夹' ) {
55
+ try {
56
+ const response = await http .request <FilesResult >(" get" , baseUrlApi (" /api/list/" ) + row .name );
57
+ const items = response .items ;
58
+ items .forEach (item => {
59
+ item .type = item .type === 0 ? ' 文件夹' : ' 文件' ;
60
+ });
61
+ tableData .value = response .items ;
62
+ } catch (error ) {
63
+ console .error (' There was an error fetching the data:' , error );
64
+ }
65
+ } else {
66
+ alert (' 这是一个文件,无法打开!' );
67
+ }
68
+ };
50
69
const handleDownload = async () => {
51
70
if (multipleSelection .value .length === 0 ) {
52
71
alert (' 请至少选择一项进行下载!' );
@@ -101,7 +120,7 @@ const handleDownload = async () => {
101
120
}
102
121
103
122
};
104
- const handleUpload = async (uploadPath ) => {
123
+ const handleUpload = async () => {
105
124
// 创建一个文件输入控件
106
125
const input = document .createElement (' input' );
107
126
input .type = ' file' ;
@@ -125,6 +144,8 @@ const handleUpload = async (uploadPath) => {
125
144
126
145
if (response .success === true ) {
127
146
alert (' 上传成功!' );
147
+ // 刷新页面
148
+ window .location .reload ();
128
149
} else {
129
150
console .error (' 上传失败:' , response );
130
151
}
@@ -134,6 +155,27 @@ const handleUpload = async (uploadPath) => {
134
155
};
135
156
};
136
157
158
+ const handleNewFolder = async () => {
159
+ const folderName = prompt (' 请输入文件夹名称:' );
160
+ if (! folderName ) {
161
+ return ;
162
+ }
163
+
164
+ try {
165
+ const response = await http .request <FilesResult >(" post" ,baseUrlApi (" api/mkdir/" + folderName ) , {
166
+ });
167
+
168
+ if (response .success === true ) {
169
+ alert (' 创建成功!' );
170
+ // 刷新页面
171
+ window .location .reload ();
172
+ } else {
173
+ console .error (' 创建失败:' , response );
174
+ }
175
+ } catch (error ) {
176
+ console .error (' 创建文件夹时出错:' , error );
177
+ }
178
+ };
137
179
138
180
const columns: TableColumnList = [
139
181
{
@@ -148,22 +190,25 @@ const columns: TableColumnList = [
148
190
label: " 大小" ,
149
191
prop: " size"
150
192
},
151
- {
152
- label: " 日期 " ,
153
- prop: " date "
193
+ {
194
+ label: " 类型 " ,
195
+ prop: " type "
154
196
}
155
197
];
156
198
</script >
157
199
158
200
<template >
159
- <pure-table ref =" tableRef" :data =" tableData" :columns =" columns"
160
- @selection-change =" handleSelectionChange" height =" 360" />
201
+ <pure-table ref =" tableRef" :data =" tableData" :columns =" columns"
202
+ @selection-change =" handleSelectionChange"
203
+ @row-click =" handleRowClick" height =" 360" > </pure-table >
161
204
<div style =" display : flex ; justify-content : space-between ; align-items : center ; margin-top : 20px ;" >
162
205
<div >
163
206
<el-button @click =" toggleSelection(tableData)" >全选</el-button >
164
207
<el-button @click =" toggleSelection()" >清除</el-button >
165
208
</div >
166
209
<div >
210
+
211
+ <el-button type =" primary" icon =" el-icon-download" @click =" handleNewFolder" >新建文件夹</el-button >
167
212
<el-button type =" primary" icon =" el-icon-download" @click =" handleDownload" >下载</el-button >
168
213
<el-button type =" primary" icon =" el-icon-download" @click =" handleUpload" >上传</el-button >
169
214
</div >
0 commit comments