21
21
<span style =" font-size : 16px ;color : gray ; margin-right : 5px ;" >当前:</span >
22
22
<path-link :path =" currentPath" :bucket =" bucket" @change =" onChangeDirectory" />
23
23
</div >
24
+ <div class =" filter-item tips" >
25
+ <span >bucket容量:{{ bucketQuota }} </span >
26
+ <span >已用容量:{{ bucketSize }} </span >
27
+ <span >文件数量:{{ bucketObjects }} </span >
28
+ </div >
24
29
</div >
25
30
26
31
<!-- 表格 -->
105
110
:show-file-list =" true"
106
111
:file-list =" uploadFileList"
107
112
:auto-upload =" true"
108
- :http-request =" uploadFile "
113
+ :http-request =" handleUploadFile "
109
114
>
110
115
<i class =" el-icon-upload" />
111
116
<div class =" el-upload__text" >
@@ -122,6 +127,7 @@ import * as oss from '@/api/oss'
122
127
import { assert } from ' @/utils/assert'
123
128
import { showError , showSuccess } from ' @/utils/show'
124
129
import PathLink from ' ./components/path-link.vue'
130
+ import { byte2gb , byte2GbOrMb , gb2byte } from ' @/utils/file'
125
131
126
132
export default {
127
133
name: ' BucketsListPage' ,
@@ -131,16 +137,19 @@ export default {
131
137
bucket: null ,
132
138
bucketDetail: {
133
139
name: ' ' ,
134
- mode: 0 ,
140
+ mode: ' private ' ,
135
141
full_token: ' ' ,
136
142
read_token: ' ' ,
137
- credentials: {}
143
+ credentials: {},
144
+ objects: 0 ,
145
+ size: 0 ,
146
+ quota: 0 ,
138
147
},
139
148
tableKey: 0 ,
140
149
list: null ,
141
150
currentPath: ' /' ,
142
151
total: 0 ,
143
- listLoading: true ,
152
+ listLoading: false ,
144
153
listQuery: {
145
154
page: 1 ,
146
155
limit: 20 ,
@@ -153,9 +162,20 @@ export default {
153
162
},
154
163
downloadLoading: false ,
155
164
uploadCommand: ' uploadFile' ,
156
- uploadFileList: []
165
+ uploadFileList: [],
157
166
}
158
167
},
168
+ computed: {
169
+ bucketQuota () {
170
+ return this .bucketDetail .quota ? byte2GbOrMb (this .bucketDetail .quota ) : 0
171
+ },
172
+ bucketSize () {
173
+ return this .bucketDetail .size ? byte2GbOrMb (this .bucketDetail .size ) : 0
174
+ },
175
+ bucketObjects () {
176
+ return this .bucketDetail .objects
177
+ },
178
+ },
159
179
async created () {
160
180
this .bucket = this .$route .params ? .bucket
161
181
@@ -168,21 +188,25 @@ export default {
168
188
/**
169
189
* 获取数据列表
170
190
*/
171
- async getList () {
191
+ getList (upload = false ) {
192
+ if (this .listLoading ) return
172
193
this .listLoading = true
173
- // 拼装查询条件 by this.listQuery
174
- // const { limit, page } = this.listQuery
175
- // 执行数据查询
176
- const res = await oss .getFilesByBucketName (this .bucket , {
177
- marker: undefined ,
178
- prefix: this .currentPath ,
179
- credentials: this .bucketDetail .credentials
180
- }).finally (() => { this .listLoading = false })
181
194
182
- const files = res .Contents || []
183
- const dirs = res .CommonPrefixes || []
184
- this .list = [... files, ... dirs]
185
- this .listLoading = false
195
+ const getList = async () => {
196
+ const res = await oss .getFilesByBucketName (this .bucket , {
197
+ marker: undefined ,
198
+ prefix: this .currentPath ,
199
+ credentials: this .bucketDetail .credentials
200
+ }).finally (() => { this .listLoading = false })
201
+
202
+ const files = res .Contents || []
203
+ const dirs = res .CommonPrefixes || []
204
+ this .list = [... files, ... dirs]
205
+ this .listLoading = false
206
+ }
207
+
208
+ // 对多文件或文件夹上传做节流处理
209
+ upload ? setTimeout (getList, 1000 ) : getList ()
186
210
},
187
211
// 搜索
188
212
handleFilter () {
@@ -253,19 +277,19 @@ export default {
253
277
},
254
278
handleUploadCommand (command ) {
255
279
this .dialogFormVisible = true
280
+ this .uploadCommand = command
256
281
if (command === ' uploadFolder' ) {
257
- this .uploadCommand = ' uploadFolder'
258
282
this .$nextTick (() => {
259
283
document .getElementsByClassName (' el-upload__input' )[0 ].webkitdirectory = true
260
284
})
261
285
} else {
262
- this .uploadCommand = ' uploadFile'
263
286
this .$nextTick (() => {
264
287
document .getElementsByClassName (' el-upload__input' )[0 ].webkitdirectory = false
265
288
})
266
289
}
267
290
},
268
- async uploadFile (param ) {
291
+ async handleUploadFile (param ) {
292
+ console .log (' upload file' , param)
269
293
const file = param .file
270
294
const key = this .currentPath + (file .webkitRelativePath ? file .webkitRelativePath : file .name )
271
295
const res = await oss .uploadAppFile (this .bucket , key, file, this .bucketDetail .credentials , { contentType: file .type })
@@ -274,7 +298,7 @@ export default {
274
298
}
275
299
276
300
showSuccess (' 文件上传成功: ' + key)
277
- this .getList ()
301
+ this .getList (true )
278
302
},
279
303
// 判断是否为图片类型
280
304
isImage (row ) {
@@ -313,6 +337,12 @@ export default {
313
337
< / script>
314
338
315
339
< style scoped>
340
+ .filter - container .tips {
341
+ font- size: 14px ; color: #333 ;position: absolute;right: 20px ;
342
+ }
343
+ .filter - container .tips span {
344
+ margin- right: 10px ;
345
+ }
316
346
.thumb - image {
317
347
width: 100px ;
318
348
max- height: 60px ;
0 commit comments