@lambo-design/upload-file 1.0.0-beta.15 → 1.0.0-beta.17
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/CHANGELOG.md +19 -5
- package/package.json +3 -3
- package/src/index.vue +100 -53
package/CHANGELOG.md
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
# Changelog
|
|
2
|
-
## [1.0.0-beta.
|
|
2
|
+
## [1.0.0-beta.17](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@lambo-design/upload-file@1.0.0-beta.16...@lambo-design/upload-file@1.0.0-beta.17) (2024-06-04)
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
### ✨ Features | 新功能
|
|
6
6
|
|
|
7
|
-
*
|
|
7
|
+
* **upload-file:** 增加文件编码列表fileIdList、限制文件上传数量limitFileNum属性 ([9c0b631](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/commit/9c0b6310b797503c574a7f32e90768e9912a5c4e))
|
|
8
8
|
|
|
9
|
-
## [1.0.0-beta.
|
|
9
|
+
## [1.0.0-beta.16](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@lambo-design/upload-file@1.0.0-beta.15...@lambo-design/upload-file@1.0.0-beta.16) (2024-05-31)
|
|
10
10
|
|
|
11
|
-
## [1.0.0-beta.13](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@lambo-design/upload-file@1.0.0-beta.12...@lambo-design/upload-file@1.0.0-beta.13) (2024-04-12)
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
### ✨ Features | 新功能
|
|
13
|
+
|
|
14
|
+
* **upload-file:** 上传文件优化 ([0b71962](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/commit/0b71962bba818f01c573f19eed57bd81e758e1ac))
|
|
15
|
+
|
|
16
|
+
## [1.0.0-beta.15](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@lambo-design/upload-file@1.0.0-beta.14...@lambo-design/upload-file@1.0.0-beta.15) (2024-04-18)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### ✨ Features | 新功能
|
|
20
|
+
|
|
21
|
+
* **@lambo-design/upload-file:** 修改工具类方法引用路径 ([d48b381](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/commit/d48b38109bbdb96b0e21128bf93e5ba85b8248bb))
|
|
22
|
+
|
|
23
|
+
## [1.0.0-beta.14](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@lambo-design/upload-file@1.0.0-beta.13...@lambo-design/upload-file@1.0.0-beta.14) (2024-04-13)
|
|
24
|
+
|
|
25
|
+
## [1.0.0-beta.13](http://git.inspur.com/ecbh/lambo-design/lambo-design/-/compare/@lambo-design/upload-file@1.0.0-beta.12...@lambo-design/upload-file@1.0.0-beta.13) (2024-04-12)
|
|
26
|
+
|
|
27
|
+
## 1.0.0-beta.12 (2024-04-12)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lambo-design/upload-file",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.17",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "lambo",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"axios": "^0.24.0",
|
|
14
14
|
"axios-cache-plugin": "^0.1.0",
|
|
15
|
-
"@lambo-design/
|
|
16
|
-
"@lambo-design/
|
|
15
|
+
"@lambo-design/shared": "^1.0.0-beta.183",
|
|
16
|
+
"@lambo-design/core": "^4.7.1-beta.139"
|
|
17
17
|
},
|
|
18
18
|
"scripts": {
|
|
19
19
|
"release": "pnpm release-beta && git push --follow-tags && pnpm re-publish",
|
package/src/index.vue
CHANGED
|
@@ -15,13 +15,13 @@
|
|
|
15
15
|
:multiple="multiple"
|
|
16
16
|
:accept="accept"
|
|
17
17
|
@change="readFile($event, 1)"/>
|
|
18
|
-
|
|
18
|
+
<div class="upload-file-list" v-if="showFileList && resultList.length > 0">
|
|
19
19
|
<List border size="small">
|
|
20
20
|
<ListItem v-for="item in resultList" :key="item.fileCode">
|
|
21
21
|
<div span="21">
|
|
22
22
|
<a :href="item.fileUrl ? item.fileUrl : downloadUrl + item.fileCode">
|
|
23
|
-
{{item.fileName}}
|
|
24
|
-
<span class="size" style="margin-left: 5px" v-if="item.showSize">({{item.showSize}})</span>
|
|
23
|
+
{{ item.fileName }}
|
|
24
|
+
<span class="size" style="margin-left: 5px" v-if="item.showSize">({{ item.showSize }})</span>
|
|
25
25
|
</a>
|
|
26
26
|
</div>
|
|
27
27
|
<div span="3" style="text-align: right">
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
</template>
|
|
36
36
|
|
|
37
37
|
<script>
|
|
38
|
-
import
|
|
38
|
+
import ajax from "@lambo-design/shared/utils/ajax";
|
|
39
39
|
import config from "@lambo-design/shared/config/config";
|
|
40
40
|
import {formatterSizeUnit} from "@lambo-design/shared/utils/file";
|
|
41
41
|
|
|
@@ -64,6 +64,12 @@ export default {
|
|
|
64
64
|
type: Boolean,
|
|
65
65
|
default: false
|
|
66
66
|
},
|
|
67
|
+
//限制上传数量
|
|
68
|
+
limitFileNum: {
|
|
69
|
+
type: Number,
|
|
70
|
+
required: false,
|
|
71
|
+
default: 0
|
|
72
|
+
},
|
|
67
73
|
//是否按钮形式
|
|
68
74
|
uploadBtn: {
|
|
69
75
|
type: Boolean,
|
|
@@ -88,6 +94,14 @@ export default {
|
|
|
88
94
|
required: false,
|
|
89
95
|
default: ""
|
|
90
96
|
},
|
|
97
|
+
//文件编码列表
|
|
98
|
+
fileIdList: {
|
|
99
|
+
type: Array,
|
|
100
|
+
required: false,
|
|
101
|
+
default: () => {
|
|
102
|
+
return []
|
|
103
|
+
}
|
|
104
|
+
},
|
|
91
105
|
//文件列表
|
|
92
106
|
fileList: {
|
|
93
107
|
type: Array,
|
|
@@ -102,24 +116,24 @@ export default {
|
|
|
102
116
|
default: ''
|
|
103
117
|
},
|
|
104
118
|
//上传文件Url
|
|
105
|
-
ossFilePutUrl:{
|
|
119
|
+
ossFilePutUrl: {
|
|
106
120
|
type: String,
|
|
107
121
|
default: "/oss/file/put"
|
|
108
122
|
},
|
|
109
123
|
//获取文件url
|
|
110
|
-
ossFileGetUrl:{
|
|
111
|
-
type:String,
|
|
112
|
-
default:"/oss/file/get/"
|
|
124
|
+
ossFileGetUrl: {
|
|
125
|
+
type: String,
|
|
126
|
+
default: "/oss/file/get/"
|
|
113
127
|
},
|
|
114
128
|
//文件预览所需文件流服务host
|
|
115
|
-
fileOnlinePreviewHost:{
|
|
129
|
+
fileOnlinePreviewHost: {
|
|
116
130
|
type: String,
|
|
117
131
|
default: "http://pub-manage-server:8080"
|
|
118
132
|
},
|
|
119
133
|
//预览文件url
|
|
120
|
-
ossFilePreviewUrl:{
|
|
121
|
-
type:String,
|
|
122
|
-
default:"/anon/oss/file/getObjToOutputStream/"
|
|
134
|
+
ossFilePreviewUrl: {
|
|
135
|
+
type: String,
|
|
136
|
+
default: "/anon/oss/file/getObjToOutputStream/"
|
|
123
137
|
}
|
|
124
138
|
},
|
|
125
139
|
|
|
@@ -145,18 +159,21 @@ export default {
|
|
|
145
159
|
},
|
|
146
160
|
methods: {
|
|
147
161
|
UploadFile: function () {
|
|
148
|
-
this
|
|
149
|
-
|
|
162
|
+
if (this.limitFileNum !== 0 && this.resultList.length > this.limitFileNum) {
|
|
163
|
+
alert('最多只能上传' + this.limitFileNum + '个文件');
|
|
164
|
+
} else {
|
|
165
|
+
this.$refs.uploadInput.click();
|
|
166
|
+
}
|
|
150
167
|
},
|
|
151
168
|
readFile: function (e, num) {
|
|
152
169
|
let self = this;
|
|
153
170
|
//读取文件
|
|
154
|
-
|
|
171
|
+
self.loading = true;
|
|
155
172
|
for (let file of e.target.files) {
|
|
156
|
-
|
|
157
|
-
var reg = new RegExp("\.(" + this.fileSuffix + ")$", "i");
|
|
173
|
+
const reg = new RegExp("\.(" + this.fileSuffix + ")$", "i");
|
|
158
174
|
if (!reg.test(file.name)) {
|
|
159
175
|
alert('文件类型必须是doc,docx,txt,xls,xlsx,jpg,jpeg,png中的一种');
|
|
176
|
+
self.loading = false;
|
|
160
177
|
return false;
|
|
161
178
|
} else {
|
|
162
179
|
self.attachmentFile.fileName = file;
|
|
@@ -168,33 +185,31 @@ export default {
|
|
|
168
185
|
}
|
|
169
186
|
}
|
|
170
187
|
self.attachmentFile.fileType = self.attachmentFile.fileName.name.substring(self.attachmentFile.fileName.name.lastIndexOf(".") + 1);
|
|
171
|
-
|
|
172
188
|
}
|
|
173
|
-
|
|
174
|
-
self.loadtoServer();
|
|
189
|
+
self.doUpload();
|
|
175
190
|
},
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
if (afile.size == 0) {
|
|
191
|
+
doUpload: function () {
|
|
192
|
+
let self = this;
|
|
193
|
+
const allFile = this.$refs.uploadInput.files;
|
|
194
|
+
if (allFile.size === 0) {
|
|
181
195
|
alert("不能传入空文件");
|
|
196
|
+
self.loading = false;
|
|
182
197
|
return false;
|
|
183
198
|
}
|
|
184
199
|
let formData = new FormData();
|
|
185
|
-
for (let file of
|
|
200
|
+
for (let file of allFile) {
|
|
186
201
|
formData.append('file', file);
|
|
187
202
|
}
|
|
188
203
|
let resultList = [];
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
if (response.data.code
|
|
193
|
-
|
|
204
|
+
const uploadUrl = self.ossServerContext + self.ossFilePutUrl;
|
|
205
|
+
const downloadUrl = self.ossServerContext + self.ossFileGetUrl;
|
|
206
|
+
ajax.post(uploadUrl, formData, { payload: true }).then(response => {
|
|
207
|
+
if (response.data.code === 1) {
|
|
208
|
+
const result = response.data.data;
|
|
194
209
|
self.loading = false;
|
|
195
210
|
if (result.length >= 1) {
|
|
196
211
|
result.forEach(item => {
|
|
197
|
-
|
|
212
|
+
const tmp = {
|
|
198
213
|
fileUrl: downloadUrl + item.fileId,
|
|
199
214
|
fileCode: item.fileId,
|
|
200
215
|
fileName: item.fileName,
|
|
@@ -203,7 +218,6 @@ export default {
|
|
|
203
218
|
showSize: formatterSizeUnit(item.length),
|
|
204
219
|
otherParam: self.otherParam
|
|
205
220
|
};
|
|
206
|
-
|
|
207
221
|
resultList.push(tmp);
|
|
208
222
|
self.resultList.push(tmp);
|
|
209
223
|
});
|
|
@@ -226,34 +240,29 @@ export default {
|
|
|
226
240
|
|
|
227
241
|
encode64(value) {
|
|
228
242
|
let typeValue = typeof value;
|
|
229
|
-
if (typeValue
|
|
243
|
+
if (typeValue === 'string' || typeValue === 'number') {
|
|
230
244
|
return window.btoa(
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
)
|
|
237
|
-
);
|
|
245
|
+
window.encodeURIComponent(value)
|
|
246
|
+
.replace(/%([0-9A-F]{2})/g,
|
|
247
|
+
function toSolidBytes(match, p1) {
|
|
248
|
+
return String.fromCharCode('0x' + p1);
|
|
249
|
+
}));
|
|
238
250
|
} else {
|
|
239
251
|
return value;
|
|
240
252
|
}
|
|
241
253
|
},
|
|
242
254
|
previewFile: function (item) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
if(fileCode) {
|
|
247
|
-
let url = this.fileOnlinePreviewHost + this.ossServerContext + this.ossFilePreviewUrl + fileCode + "?fullfilename=" + fileName + "." + fileType;
|
|
248
|
-
window.open(config.fileOnlinePreviewContext + '/onlinePreview?url='+encodeURIComponent(this.encode64(url)));
|
|
255
|
+
if (item.fileCode) {
|
|
256
|
+
const url = this.fileOnlinePreviewHost + this.ossServerContext + this.ossFilePreviewUrl + item.fileCode + "?fullfilename=" + item.fileName + "." + item.fileType;
|
|
257
|
+
window.open(config.fileOnlinePreviewContext + '/onlinePreview?url=' + encodeURIComponent(this.encode64(url)));
|
|
249
258
|
}
|
|
250
259
|
},
|
|
251
260
|
deleteFile: function (fileCode) {
|
|
252
261
|
if (fileCode) {
|
|
253
|
-
|
|
254
|
-
|
|
262
|
+
let result = [];
|
|
263
|
+
let deletes = []
|
|
255
264
|
this.resultList.forEach(item => {
|
|
256
|
-
if (item.fileCode
|
|
265
|
+
if (item.fileCode !== fileCode) {
|
|
257
266
|
result.push(item);
|
|
258
267
|
} else {
|
|
259
268
|
deletes.push(item)
|
|
@@ -266,12 +275,50 @@ export default {
|
|
|
266
275
|
this.$emit("upload-result", this.resultList, deletes);
|
|
267
276
|
}
|
|
268
277
|
}
|
|
278
|
+
},
|
|
279
|
+
initFileList: function (value) {
|
|
280
|
+
if (this.resultList.length === 0) {
|
|
281
|
+
let requests = []
|
|
282
|
+
for (const fileId of value) {
|
|
283
|
+
requests.push(ajax.get(config.upmsServerContext + "/oss/file/getMetaData/" + fileId))
|
|
284
|
+
}
|
|
285
|
+
Promise.all(requests).then((response) => {
|
|
286
|
+
response.forEach(item => {
|
|
287
|
+
this.resultList.push({
|
|
288
|
+
fileCode: item.data.data.fileId,
|
|
289
|
+
fileUrl: this.ossServerContext + this.ossFileGetUrl + item.data.data.fileId,
|
|
290
|
+
fileName: item.data.data.fileName,
|
|
291
|
+
fileType: item.data.data.fileName.substring(item.data.data.fileName.lastIndexOf(".") + 1),
|
|
292
|
+
size: item.data.data.length,
|
|
293
|
+
showSize: formatterSizeUnit(item.data.data.length),
|
|
294
|
+
otherParam: this.otherParam
|
|
295
|
+
})
|
|
296
|
+
})
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
arraysEqual(arr1, arr2) {
|
|
301
|
+
if (arr1.length !== arr2.length) return false;
|
|
302
|
+
for (let i = 0; i < arr1.length; i++) {
|
|
303
|
+
if (arr1[i] !== arr2[i]) return false;
|
|
304
|
+
}
|
|
305
|
+
return true;
|
|
269
306
|
}
|
|
270
307
|
},
|
|
271
308
|
watch: {
|
|
272
|
-
fileList:
|
|
273
|
-
|
|
274
|
-
|
|
309
|
+
fileList: {
|
|
310
|
+
handler: function (value) {
|
|
311
|
+
this.resultList = this.fileList
|
|
312
|
+
},
|
|
313
|
+
deep: true
|
|
314
|
+
},
|
|
315
|
+
fileIdList: {
|
|
316
|
+
handler: function (newValue, oldValue) {
|
|
317
|
+
if (newValue.length > 0 && !this.arraysEqual(newValue, oldValue)) {
|
|
318
|
+
this.initFileList(newValue)
|
|
319
|
+
}
|
|
320
|
+
},
|
|
321
|
+
deep: true
|
|
275
322
|
}
|
|
276
323
|
}
|
|
277
324
|
}
|