xianniu-ui 0.8.53 → 0.8.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/xianniu-ui.common.js +136 -127
- package/lib/xianniu-ui.umd.js +136 -127
- package/lib/xianniu-ui.umd.min.js +2 -2
- package/package.json +1 -1
- package/packages/upload/main.vue +5 -4
- package/src/oss/index.js +56 -40
package/package.json
CHANGED
package/packages/upload/main.vue
CHANGED
|
@@ -367,10 +367,11 @@ export default {
|
|
|
367
367
|
.then((res) => {
|
|
368
368
|
this.successFiles.push(res);
|
|
369
369
|
|
|
370
|
-
this.realFileList.forEach((item
|
|
370
|
+
this.realFileList.forEach((item) => {
|
|
371
371
|
if (item.uid === res.file.uid) {
|
|
372
|
-
|
|
373
|
-
|
|
372
|
+
const obj = JSON.parse(JSON.stringify(res));
|
|
373
|
+
delete obj.file;
|
|
374
|
+
item = Object.assign(item, obj);
|
|
374
375
|
}
|
|
375
376
|
});
|
|
376
377
|
|
|
@@ -380,7 +381,7 @@ export default {
|
|
|
380
381
|
this.$emit("on-uploaded", true);
|
|
381
382
|
this.isUploading = false;
|
|
382
383
|
})
|
|
383
|
-
.catch(({
|
|
384
|
+
.catch(({fileName}) => {
|
|
384
385
|
this.$notify.error({
|
|
385
386
|
title: "上传失败",
|
|
386
387
|
dangerouslyUseHTMLString: true,
|
package/src/oss/index.js
CHANGED
|
@@ -11,12 +11,19 @@ class Client {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
getToken() {
|
|
14
|
+
const _token = localStorage.getItem('xnToken');
|
|
15
|
+
if (!_token) return '';
|
|
16
|
+
|
|
17
|
+
const isQuotedString = /^".*"$/.test(_token);
|
|
14
18
|
try {
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
if (isQuotedString) {
|
|
20
|
+
return _token.slice(1, -1);
|
|
21
|
+
} else {
|
|
22
|
+
return JSON.parse(_token);
|
|
23
|
+
}
|
|
17
24
|
} catch (error) {
|
|
18
25
|
console.error('Failed to parse token:', error);
|
|
19
|
-
return
|
|
26
|
+
return _token;
|
|
20
27
|
}
|
|
21
28
|
}
|
|
22
29
|
|
|
@@ -40,7 +47,7 @@ class Client {
|
|
|
40
47
|
if (!this.stsUrl) {
|
|
41
48
|
console.error('获取临时凭证地址不能为空');
|
|
42
49
|
file.onError();
|
|
43
|
-
return;
|
|
50
|
+
return Promise.reject('获取临时凭证地址不能为空');
|
|
44
51
|
}
|
|
45
52
|
|
|
46
53
|
try {
|
|
@@ -55,9 +62,11 @@ class Client {
|
|
|
55
62
|
bucket,
|
|
56
63
|
region
|
|
57
64
|
});
|
|
65
|
+
return this;
|
|
58
66
|
} catch (err) {
|
|
59
67
|
console.error('获取临时凭证失败:', err);
|
|
60
|
-
|
|
68
|
+
file.onError();
|
|
69
|
+
return Promise.reject(err);
|
|
61
70
|
}
|
|
62
71
|
}
|
|
63
72
|
|
|
@@ -71,50 +80,57 @@ class Client {
|
|
|
71
80
|
},
|
|
72
81
|
body: JSON.stringify(params)
|
|
73
82
|
});
|
|
83
|
+
|
|
84
|
+
if (!response.ok) {
|
|
85
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
86
|
+
}
|
|
87
|
+
|
|
74
88
|
const { data } = await response.json();
|
|
75
89
|
return data;
|
|
76
90
|
} catch (err) {
|
|
77
91
|
console.error('设置文件ID失败:', err);
|
|
78
|
-
|
|
92
|
+
return Promise.reject(err);
|
|
79
93
|
}
|
|
80
94
|
}
|
|
81
95
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
96
|
+
upload(file, headers = {}) {
|
|
97
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
98
|
+
return new Promise(async (resolve, reject) => {
|
|
99
|
+
const currentFile = file.file;
|
|
100
|
+
const fileName = currentFile.name;
|
|
101
|
+
const newFileName = this.getFileNameUUID() + '.' + this.getExt(currentFile);
|
|
102
|
+
const path = `accessory/${$dayjs().format('YYYY/MM/DD')}/`;
|
|
87
103
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
});
|
|
104
|
+
try {
|
|
105
|
+
await this.getStsToken(file);
|
|
106
|
+
const res = await this.oss.multipartUpload(path + newFileName, currentFile, {
|
|
107
|
+
...headers,
|
|
108
|
+
progress: (p) => {
|
|
109
|
+
const _progress = parseFloat(p * 100);
|
|
110
|
+
file.onProgress({ percent: _progress });
|
|
111
|
+
}
|
|
112
|
+
});
|
|
98
113
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
114
|
+
const fileObj = {
|
|
115
|
+
name: fileName,
|
|
116
|
+
size: currentFile.size,
|
|
117
|
+
ext: this.getExt(currentFile),
|
|
118
|
+
imgFlag: Number(this.isImg(currentFile)),
|
|
119
|
+
isAV: Number(this.isAV(currentFile)),
|
|
120
|
+
url: this.uploadHost + res.name,
|
|
121
|
+
accessoryName: fileName,
|
|
122
|
+
accessorySize: currentFile.size
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const fileIdResponse = await this.setFileId(fileObj);
|
|
126
|
+
file.onSuccess();
|
|
127
|
+
resolve({ ...fileObj, fileId: fileIdResponse.fileId, file: currentFile });
|
|
128
|
+
} catch (err) {
|
|
129
|
+
console.error('上传文件失败:', err);
|
|
130
|
+
file.onError();
|
|
131
|
+
reject({ file, fileName, err });
|
|
132
|
+
}
|
|
133
|
+
});
|
|
118
134
|
}
|
|
119
135
|
}
|
|
120
136
|
|