@@ -54,13 +54,14 @@ import SvgIcon from "@/components/SvgIcon";
54
54
import {isImgExt } from " @/util/validate" ;
55
55
import {randomUUID } from " @/util/uuid" ;
56
56
import {copy } from " @/util/copy" ;
57
- import cos from " @/api/ cos" ;
57
+ import COS from ' cos-js-sdk-v5 ' ;
58
58
59
59
export default {
60
60
name: " TxyunManage" ,
61
61
components: {SvgIcon},
62
62
data () {
63
63
return {
64
+ cos: {},
64
65
txyunConfig: {
65
66
secretId: ' ' ,
66
67
secretKey: ' ' ,
@@ -111,34 +112,36 @@ export default {
111
112
created () {
112
113
this .hintShow1 = localStorage .getItem (' txyunHintShow1' ) ? false : true
113
114
this .hintShow2 = localStorage .getItem (' txyunHintShow2' ) ? false : true
115
+
114
116
const txyunConfig = localStorage .getItem (' txyunConfig' )
115
117
if (txyunConfig) {
116
118
this .txyunConfig = JSON .parse (txyunConfig)
117
119
this .txyunConfig .domain = this .txyunConfig .domain .endsWith (' /' ) ? this .txyunConfig .domain : ` ${ this .txyunConfig .domain } /`
120
+
121
+ this .cos = new COS ({
122
+ SecretId: this .txyunConfig .secretId ,
123
+ SecretKey: this .txyunConfig .secretKey ,
124
+ })
118
125
} else {
119
126
this .msgError (' 请先配置腾讯云' )
120
127
this .$router .push (' /pictureHosting/setting' )
121
128
}
122
-
123
129
},
124
130
methods: {
125
131
// 换成懒加载
126
132
async getReposContents (arr , path ) {
127
133
const {txyunConfig } = this
128
- await cos .getBucket ({
134
+ await this . cos .getBucket ({
129
135
Bucket: txyunConfig .bucketName , /* 必须 */
130
136
Region: txyunConfig .region , /* 存储桶所在地域,必须字段 */
131
137
Prefix: path, /* 非必须 */
132
138
Delimiter: ' /'
133
139
}).then (data => {
134
- console .log (' 查询成功' ,data);
135
140
data .CommonPrefixes .forEach ((item ) => {
136
- item .name = item .Prefix .replace (path, ' ' ).slice (0 ,- 1 )
141
+ item .name = item .Prefix .replace (path, ' ' ).slice (0 , - 1 )
137
142
// 让所有节点都是非叶子节点
138
143
arr .push ({value: item .name , label: item .name , leaf: false })
139
144
});
140
- }).catch (err => {
141
- console .log (' 查询失败' ,err);
142
145
})
143
146
},
144
147
// 获取存储空间下指定目录的文件列表
@@ -150,21 +153,18 @@ export default {
150
153
if (path != ' ' ) {
151
154
path = path .endsWith (' /' ) ? path : ` ${ path} /`
152
155
}
153
- cos .getBucket ({
156
+ this . cos .getBucket ({
154
157
Bucket: txyunConfig .bucketName , /* 必须 */
155
158
Region: txyunConfig .region , /* 存储桶所在地域,必须字段 */
156
159
Prefix: path, /* 非必须 */
157
160
Delimiter: ' /'
158
161
}).then (data => {
159
- console .log (' 查询成功' ,data);
160
162
data .Contents .filter ((item ) => ! item .Key .endsWith (' /' ) && isImgExt (item .Key )).forEach (item => {
161
163
item .path = item .Key
162
164
item .cdn_url = ` ${ txyunConfig .domain }${ item .path } `
163
165
item .name = item .Key .replace (path, ' ' )
164
166
fileList .push (item)
165
167
})
166
- }).catch (err => {
167
- console .log (' 查询失败' ,err);
168
168
})
169
169
this .fileList = fileList
170
170
},
@@ -185,22 +185,19 @@ export default {
185
185
// 删除文件
186
186
delFile (file ) {
187
187
const {txyunConfig } = this
188
- console .log (" 删除路径:" , file .path )
189
188
this .$confirm (" 此操作将永久删除该文件, 是否删除?" , " 提示" , {
190
189
confirmButtonText: ' 确定' ,
191
190
cancelButtonText: ' 取消' ,
192
191
type: ' warning' ,
193
192
}).then (() => {
194
- cos .deleteObject ({
193
+ this . cos .deleteObject ({
195
194
Bucket: txyunConfig .bucketName , /* 填写自己的bucket,必须字段 */
196
195
Region: txyunConfig .region , /* 存储桶所在地域,必须字段 */
197
196
Key: file .path , /* 存储在桶里的对象键(例如1.jpg,a/b/test.txt),必须字段 */
198
- }).then (data => {
199
- console .log (' 删除成功' ,data);
197
+ }).then (() => {
200
198
this .msgSuccess (' 删除成功' )
201
199
this .search ()
202
- }).catch (err => {
203
- console .log (' 删除失败' ,err);
200
+ }).catch (() => {
204
201
this .msgError (' 删除失败' )
205
202
})
206
203
}).catch (() => {
@@ -229,22 +226,18 @@ export default {
229
226
let path = this .realPath ;
230
227
path = path .startsWith (' /' ) ? path .slice (1 ) : path
231
228
path = path .endsWith (' /' ) ? path : ` ${ path} /`
232
- console .log (" 上传路径:" , path)
233
- cos .uploadFile ({
229
+ this .cos .uploadFile ({
234
230
Bucket: txyunConfig .bucketName , /* 必须 */
235
231
Region: txyunConfig .region , /* 存储桶所在地域,必须字段 */
236
232
Key: ` ${ path}${ fileName} ` , /* 存储在桶里的对象键(例如:1.jpg,a/b/test.txt,图片.jpg)支持中文,必须字段 */
237
233
Body: data .file , // 上传文件对象
238
234
SliceSize: 1024 * 1024 * 5 , /* 触发分块上传的阈值,超过5MB使用分块上传,小于5MB使用简单上传。可自行设置,非必须 */
239
- onProgress : function (progressData ) {
235
+ onProgress : function (progressData ) {
240
236
console .log (JSON .stringify (progressData));
241
237
}
242
238
}).then (() => {
243
- console .log (' 上传成功' );
244
239
this .msgSuccess (' 上传成功' )
245
240
data .onSuccess ()
246
- }).catch (err => {
247
- console .log (' 上传失败' , err);
248
241
})
249
242
},
250
243
},
@@ -388,4 +381,4 @@ export default {
388
381
.image-container :hover .image-content ::before {
389
382
height : 80px ;
390
383
}
391
- </style >
384
+ </style >
0 commit comments