mali-applet-ui 0.2.70 → 0.2.71
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.
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
function normalizeChooseAndUploadFileRes(res, fileType) {
|
|
2
|
-
debugger
|
|
3
2
|
res.tempFiles.forEach((item) => {
|
|
4
3
|
if (!item.name) {
|
|
5
4
|
item.name = item.path.substring(item.path.lastIndexOf('/') + 1)
|
|
@@ -34,7 +33,7 @@ export function uploadAllFiles(opts) {
|
|
|
34
33
|
if (typeof wx !== 'undefined' && typeof wx.chooseMessageFile === 'function') {
|
|
35
34
|
chooseFile = wx.chooseMessageFile
|
|
36
35
|
}
|
|
37
|
-
if (typeof chooseFile
|
|
36
|
+
if (typeof chooseFile !== 'function') {
|
|
38
37
|
return reject({})
|
|
39
38
|
}
|
|
40
39
|
chooseFile({
|
|
@@ -1,22 +1,31 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<view class="ml-upload" :class="[className || '']">
|
|
3
|
+
<!-- 上传图片 -->
|
|
3
4
|
<view v-if="mediatype === 'image'" class="ml-upload-image-list">
|
|
4
5
|
<view class="ml-upload-image-item" v-for="(item, index) in fileList" :key="index">
|
|
5
|
-
<image class="ml-upload-image-img" mode="
|
|
6
|
-
<view class="ml-upload-image-del-btn">
|
|
6
|
+
<image class="ml-upload-image-img" mode="aspectFit" :src="getUrl(item)" @click="previewImageEvent(item, index)"></image>
|
|
7
|
+
<view class="ml-upload-image-del-btn" @click="removeEvent(item)">
|
|
7
8
|
<ml-icon name="close" />
|
|
8
9
|
</view>
|
|
9
10
|
</view>
|
|
10
11
|
<view class="ml-upload-image-add">
|
|
11
|
-
<view class="ml-upload-image-add-btn" @tap="
|
|
12
|
+
<view class="ml-upload-image-add-btn" @tap="chooseEvent">
|
|
12
13
|
<view class="ml-upload-image-add-icon">
|
|
13
14
|
<ml-icon name="add" />
|
|
14
15
|
</view>
|
|
15
16
|
</view>
|
|
16
17
|
</view>
|
|
17
18
|
</view>
|
|
18
|
-
|
|
19
|
+
<!-- 上传文件 -->
|
|
19
20
|
<view v-else class="ml-upload-file-list">
|
|
21
|
+
<view class="ml-upload-file-add">
|
|
22
|
+
<view class="ml-upload-file-add-btn" @tap="chooseEvent">
|
|
23
|
+
<text class="ml-upload-file-add-icon">
|
|
24
|
+
<ml-icon name="add" />
|
|
25
|
+
</text>
|
|
26
|
+
<text>添加文件</text>
|
|
27
|
+
</view>
|
|
28
|
+
</view>
|
|
20
29
|
<view class="ml-upload-file-item" v-for="(item, index) in fileList" :key="index">
|
|
21
30
|
<view class="ml-upload-file-left">
|
|
22
31
|
<view class="ml-upload-file-icon">
|
|
@@ -25,25 +34,17 @@
|
|
|
25
34
|
</view>
|
|
26
35
|
<view class="ml-upload-file-info">
|
|
27
36
|
<view class="ml-upload-file-name">{{ item[nameField] }}</view>
|
|
28
|
-
<view>
|
|
29
|
-
<ml-button status="primary" type="text">预览</ml-button>
|
|
30
|
-
<ml-button status="primary" type="text">下载</ml-button>
|
|
37
|
+
<view class="ml-upload-file-desc">
|
|
38
|
+
<ml-button status="primary" type="text" @click="previewDocs(item)">预览</ml-button>
|
|
39
|
+
<ml-button status="primary" type="text" @click="downloadEvent(item)">下载</ml-button>
|
|
31
40
|
</view>
|
|
32
41
|
</view>
|
|
33
42
|
<view class="ml-upload-file-right">
|
|
34
|
-
<view class="ml-upload-file-del-btn">
|
|
43
|
+
<view class="ml-upload-file-del-btn" @click="removeEvent(item)">
|
|
35
44
|
<ml-icon name="close" />
|
|
36
45
|
</view>
|
|
37
46
|
</view>
|
|
38
47
|
</view>
|
|
39
|
-
<view class="ml-upload-file-add">
|
|
40
|
-
<view class="ml-upload-file-add-btn" @tap="chooseFile">
|
|
41
|
-
<view class="ml-upload-file-add-icon">
|
|
42
|
-
<ml-icon name="add" />
|
|
43
|
-
</view>
|
|
44
|
-
<view class="ml-upload-file-add-text">添加附件</view>
|
|
45
|
-
</view>
|
|
46
|
-
</view>
|
|
47
48
|
</view>
|
|
48
49
|
</view>
|
|
49
50
|
</template>
|
|
@@ -51,9 +52,11 @@
|
|
|
51
52
|
<script>
|
|
52
53
|
import XEUtils from 'xe-utils'
|
|
53
54
|
import globalStore from '../../config/store'
|
|
55
|
+
import mlButton from '../ml-button/ml-button.vue'
|
|
54
56
|
import { uploadAllFiles, uploadImageFiles } from './file-handle'
|
|
55
57
|
|
|
56
58
|
export default {
|
|
59
|
+
components: { mlButton },
|
|
57
60
|
name: 'MlUpload',
|
|
58
61
|
props: {
|
|
59
62
|
value: {
|
|
@@ -106,16 +109,7 @@ export default {
|
|
|
106
109
|
data () {
|
|
107
110
|
return {
|
|
108
111
|
fileList: [],
|
|
109
|
-
|
|
110
|
-
imageStyles: {
|
|
111
|
-
// "height": 60, // 边框高度
|
|
112
|
-
// "width": 60, // 边框宽度
|
|
113
|
-
// "border":{ // 如果为 Boolean 值,可以控制边框显示与否
|
|
114
|
-
// "color":"transparent", // 边框颜色
|
|
115
|
-
// "width":"1px", // 边框宽度
|
|
116
|
-
// "style":"solid", // 边框样式
|
|
117
|
-
// }
|
|
118
|
-
},
|
|
112
|
+
docsTypes: ['doc', 'xls', 'ppt', 'pdf', 'docx', 'xlsx', 'pptx'],
|
|
119
113
|
imgTypes: ['png', 'jpg']
|
|
120
114
|
}
|
|
121
115
|
},
|
|
@@ -143,7 +137,7 @@ export default {
|
|
|
143
137
|
}
|
|
144
138
|
},
|
|
145
139
|
watch: {
|
|
146
|
-
value (
|
|
140
|
+
value () {
|
|
147
141
|
if (!this.isUpdate) {
|
|
148
142
|
this.isUpdate = true
|
|
149
143
|
this.loadList()
|
|
@@ -175,21 +169,6 @@ export default {
|
|
|
175
169
|
tempPath: this.getUrl(obj)
|
|
176
170
|
}
|
|
177
171
|
})
|
|
178
|
-
this.selectUniFileList = this.urlList.map(url => {
|
|
179
|
-
const name = this.getUrlName(url)
|
|
180
|
-
const extname = this.getSuffix(name)
|
|
181
|
-
const obj = {
|
|
182
|
-
[this.nameField]: name,
|
|
183
|
-
[this.typeField]: extname,
|
|
184
|
-
[this.urlField]: url
|
|
185
|
-
}
|
|
186
|
-
return {
|
|
187
|
-
...obj,
|
|
188
|
-
name: name,
|
|
189
|
-
extname: extname,
|
|
190
|
-
url: this.getUrl(obj)
|
|
191
|
-
}
|
|
192
|
-
})
|
|
193
172
|
this.isUpdate = true
|
|
194
173
|
this.$emit('input', this.fileList)
|
|
195
174
|
} else {
|
|
@@ -197,14 +176,6 @@ export default {
|
|
|
197
176
|
item.tempPath = this.getUrl(item)
|
|
198
177
|
return item
|
|
199
178
|
})
|
|
200
|
-
this.selectUniFileList = this.value.map(item => {
|
|
201
|
-
return {
|
|
202
|
-
...item,
|
|
203
|
-
name: item[this.nameField],
|
|
204
|
-
extname: item[this.typeField],
|
|
205
|
-
url: this.getUrl(item)
|
|
206
|
-
}
|
|
207
|
-
})
|
|
208
179
|
}
|
|
209
180
|
},
|
|
210
181
|
updateModel () {
|
|
@@ -213,61 +184,8 @@ export default {
|
|
|
213
184
|
this.$emit('input', this.fileList)
|
|
214
185
|
this.$emit('change', { value: this.simpleValue ? urlList : this.fileList })
|
|
215
186
|
},
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
if (this.$loading) {
|
|
219
|
-
this.$loading.show('上传中')
|
|
220
|
-
}
|
|
221
|
-
const uploadMethod = this.uploadFile ? this.uploadFile : (globalStore.upload ? globalStore.upload.uploadFile : null)
|
|
222
|
-
Promise.all(
|
|
223
|
-
tempFiles.map(file => {
|
|
224
|
-
const fileSuffix = this.getSuffix(file.name)
|
|
225
|
-
if (uploadMethod) {
|
|
226
|
-
return Promise.resolve(
|
|
227
|
-
uploadMethod.call(this.currVM, {
|
|
228
|
-
file,
|
|
229
|
-
params: this.params
|
|
230
|
-
})
|
|
231
|
-
).then(res => {
|
|
232
|
-
const item = {
|
|
233
|
-
...res,
|
|
234
|
-
[this.nameField]: res[this.nameField] || file.name,
|
|
235
|
-
[this.typeField]: res[this.typeField] || fileSuffix,
|
|
236
|
-
tempPath: file.path
|
|
237
|
-
}
|
|
238
|
-
this.selectUniFileList.push(file)
|
|
239
|
-
this.fileList.push(item)
|
|
240
|
-
this.isUpdate = true
|
|
241
|
-
this.updateModel()
|
|
242
|
-
})
|
|
243
|
-
} else {
|
|
244
|
-
const item = {
|
|
245
|
-
[this.nameField]: file.name,
|
|
246
|
-
[this.typeField]: file.extname,
|
|
247
|
-
[this.urlField]: file.path,
|
|
248
|
-
tempPath: file.path
|
|
249
|
-
}
|
|
250
|
-
this.selectUniFileList.push(file)
|
|
251
|
-
this.fileList.push(item)
|
|
252
|
-
this.isUpdate = true
|
|
253
|
-
this.updateModel()
|
|
254
|
-
}
|
|
255
|
-
})
|
|
256
|
-
).then(res => {
|
|
257
|
-
if (this.$loading) {
|
|
258
|
-
this.$loading.hide()
|
|
259
|
-
}
|
|
260
|
-
}).catch((e) => {
|
|
261
|
-
if (this.$loading) {
|
|
262
|
-
this.$loading.hide()
|
|
263
|
-
}
|
|
264
|
-
})
|
|
265
|
-
},
|
|
266
|
-
removeEvent (e) {
|
|
267
|
-
const { tempFilePath } = e
|
|
268
|
-
const item = this.fileList.find(item => item.tempPath === tempFilePath)
|
|
269
|
-
this.selectUniFileList = this.selectUniFileList.filter(item => item.url !== tempFilePath)
|
|
270
|
-
this.fileList = this.fileList.filter(item => item.tempPath !== tempFilePath)
|
|
187
|
+
removeEvent (item) {
|
|
188
|
+
this.fileList = this.fileList.filter(obj => obj.tempPath !== item.tempPath)
|
|
271
189
|
const removeMethod = this.removeFile ? this.removeFile : (globalStore.upload ? globalStore.upload.removeFile : null)
|
|
272
190
|
if (!item) {
|
|
273
191
|
console.error('删除出错!!!')
|
|
@@ -305,7 +223,7 @@ export default {
|
|
|
305
223
|
}
|
|
306
224
|
return suffix
|
|
307
225
|
},
|
|
308
|
-
|
|
226
|
+
previewImageEvent (item, index) {
|
|
309
227
|
if (this.previewStatus) {
|
|
310
228
|
return
|
|
311
229
|
}
|
|
@@ -351,40 +269,54 @@ export default {
|
|
|
351
269
|
}
|
|
352
270
|
})
|
|
353
271
|
},
|
|
272
|
+
previewDocs (item) {
|
|
273
|
+
// 仅支持文档和图片
|
|
274
|
+
const supportDocs = this.docsTypes.includes(item[this.typeField])
|
|
275
|
+
const supportImg = this.imgTypes.includes(item[this.typeField])
|
|
276
|
+
if (supportDocs || supportImg) {
|
|
277
|
+
uni.downloadFile({
|
|
278
|
+
url: this.getUrl(item),
|
|
279
|
+
success: (downRes) => {
|
|
280
|
+
if (supportDocs) {
|
|
281
|
+
uni.openDocument({
|
|
282
|
+
filePath: downRes.tempFilePath,
|
|
283
|
+
showMenu: true,
|
|
284
|
+
success () {},
|
|
285
|
+
fail () {
|
|
286
|
+
uni.showModal({
|
|
287
|
+
content: '打开失败',
|
|
288
|
+
showCancel: false
|
|
289
|
+
})
|
|
290
|
+
}
|
|
291
|
+
})
|
|
292
|
+
} else if (supportImg) {
|
|
293
|
+
this.previewImg(item)
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
fail () {
|
|
297
|
+
uni.showModal({
|
|
298
|
+
content: '下载失败',
|
|
299
|
+
showCancel: false
|
|
300
|
+
})
|
|
301
|
+
}
|
|
302
|
+
})
|
|
303
|
+
}
|
|
304
|
+
},
|
|
354
305
|
downloadEvent (item) {
|
|
355
306
|
uni.downloadFile({
|
|
356
307
|
url: this.getUrl(item),
|
|
357
308
|
success: (downRes) => {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
})
|
|
372
|
-
} else if (['png', 'jpg'].includes(item[this.typeField])) {
|
|
373
|
-
this.previewImg(item)
|
|
374
|
-
} else {
|
|
375
|
-
uni.saveFile({
|
|
376
|
-
tempFilePath: downRes.tempFilePath,
|
|
377
|
-
success: function(res) {
|
|
378
|
-
uni.showToast({
|
|
379
|
-
icon: 'none',
|
|
380
|
-
mask: true,
|
|
381
|
-
title: '文件已保存:' + res.savedFilePath, //保存路径
|
|
382
|
-
duration: 3000,
|
|
383
|
-
})
|
|
384
|
-
}
|
|
385
|
-
})
|
|
386
|
-
|
|
387
|
-
}
|
|
309
|
+
uni.saveFile({
|
|
310
|
+
tempFilePath: downRes.tempFilePath,
|
|
311
|
+
success: function(res) {
|
|
312
|
+
uni.showToast({
|
|
313
|
+
icon: 'none',
|
|
314
|
+
mask: true,
|
|
315
|
+
title: '文件已保存:' + res.savedFilePath, //保存路径
|
|
316
|
+
duration: 3000,
|
|
317
|
+
})
|
|
318
|
+
}
|
|
319
|
+
})
|
|
388
320
|
},
|
|
389
321
|
fail () {
|
|
390
322
|
uni.showModal({
|
|
@@ -394,52 +326,14 @@ export default {
|
|
|
394
326
|
}
|
|
395
327
|
})
|
|
396
328
|
},
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
Promise.all(
|
|
403
|
-
tempFiles.map(file => {
|
|
404
|
-
const fileSuffix = this.getSuffix(file.name)
|
|
405
|
-
if (uploadMethod) {
|
|
406
|
-
return Promise.resolve(
|
|
407
|
-
uploadMethod.call(this.currVM, {
|
|
408
|
-
file,
|
|
409
|
-
params: this.params
|
|
410
|
-
})
|
|
411
|
-
).then(res => {
|
|
412
|
-
return {
|
|
413
|
-
...res,
|
|
414
|
-
[this.nameField]: res[this.nameField] || file.name,
|
|
415
|
-
[this.typeField]: res[this.typeField] || fileSuffix,
|
|
416
|
-
tempPath: file.path
|
|
417
|
-
}
|
|
418
|
-
})
|
|
419
|
-
}
|
|
420
|
-
return {
|
|
421
|
-
[this.nameField]: file.name,
|
|
422
|
-
[this.typeField]: file.extname,
|
|
423
|
-
[this.urlField]: file.path,
|
|
424
|
-
tempPath: file.path
|
|
425
|
-
}
|
|
426
|
-
})
|
|
427
|
-
).then(list => {
|
|
428
|
-
this.selectUniFileList.push(...list)
|
|
429
|
-
this.fileList.push(...list)
|
|
430
|
-
this.isUpdate = true
|
|
431
|
-
this.updateModel()
|
|
432
|
-
debugger
|
|
433
|
-
}).catch((e) => {
|
|
434
|
-
debugger
|
|
435
|
-
})
|
|
436
|
-
})
|
|
437
|
-
},
|
|
438
|
-
chooseFile () {
|
|
329
|
+
chooseEvent () {
|
|
330
|
+
let chooseMethod = uploadAllFiles
|
|
331
|
+
if (this.mediatype === 'image') {
|
|
332
|
+
chooseMethod = uploadImageFiles
|
|
333
|
+
}
|
|
439
334
|
const uploadMethod = this.uploadFile ? this.uploadFile : (globalStore.upload ? globalStore.upload.uploadFile : null)
|
|
440
|
-
|
|
335
|
+
chooseMethod({}).then(res => {
|
|
441
336
|
const { tempFiles } = res
|
|
442
|
-
debugger
|
|
443
337
|
Promise.all(
|
|
444
338
|
tempFiles.map(file => {
|
|
445
339
|
const fileSuffix = this.getSuffix(file.name)
|
|
@@ -466,13 +360,11 @@ export default {
|
|
|
466
360
|
}
|
|
467
361
|
})
|
|
468
362
|
).then(list => {
|
|
469
|
-
this.selectUniFileList.push(...list)
|
|
470
363
|
this.fileList.push(...list)
|
|
471
364
|
this.isUpdate = true
|
|
472
365
|
this.updateModel()
|
|
473
|
-
debugger
|
|
474
366
|
}).catch((e) => {
|
|
475
|
-
|
|
367
|
+
console.log(e)
|
|
476
368
|
})
|
|
477
369
|
})
|
|
478
370
|
}
|
|
@@ -506,6 +398,7 @@ export default {
|
|
|
506
398
|
width: 40rpx;
|
|
507
399
|
height: 40rpx;
|
|
508
400
|
line-height: 40rpx;
|
|
401
|
+
font-size: 28rpx;
|
|
509
402
|
text-align: center;
|
|
510
403
|
border-radius: 50%;
|
|
511
404
|
color: #ffffff;
|
|
@@ -528,10 +421,18 @@ export default {
|
|
|
528
421
|
}
|
|
529
422
|
}
|
|
530
423
|
.ml-upload-file-list {
|
|
424
|
+
.ml-upload-file-add,
|
|
425
|
+
.ml-upload-file-item {
|
|
426
|
+
margin: 20rpx 0;
|
|
427
|
+
}
|
|
531
428
|
.ml-upload-file-item {
|
|
532
429
|
display: flex;
|
|
533
430
|
flex-direction: row;
|
|
534
431
|
}
|
|
432
|
+
.ml-upload-file-item {
|
|
433
|
+
padding-bottom: 10rpx;
|
|
434
|
+
border-bottom: 1px solid #f1f1f1;
|
|
435
|
+
}
|
|
535
436
|
.ml-upload-file-left,
|
|
536
437
|
.ml-upload-file-right {
|
|
537
438
|
display: flex;
|
|
@@ -540,11 +441,29 @@ export default {
|
|
|
540
441
|
justify-content: center;
|
|
541
442
|
flex-shrink: 0;
|
|
542
443
|
}
|
|
444
|
+
.ml-upload-file-add-btn {
|
|
445
|
+
height: 70rpx;
|
|
446
|
+
line-height: 70rpx;
|
|
447
|
+
text-align: center;
|
|
448
|
+
color: #8a8686;
|
|
449
|
+
border: 1px solid #c8c8c9;
|
|
450
|
+
border-radius: $ml-border-radius;
|
|
451
|
+
}
|
|
452
|
+
.ml-upload-file-del-btn {
|
|
453
|
+
width: 40rpx;
|
|
454
|
+
height: 40rpx;
|
|
455
|
+
line-height: 40rpx;
|
|
456
|
+
text-align: center;
|
|
457
|
+
font-size: 28rpx;
|
|
458
|
+
color: #ffffff;
|
|
459
|
+
background: #c8c8c9;
|
|
460
|
+
border-radius: 50%;
|
|
461
|
+
}
|
|
543
462
|
.ml-upload-file-left {
|
|
544
463
|
width: 80rpx;
|
|
545
464
|
}
|
|
546
465
|
.ml-upload-file-icon {
|
|
547
|
-
font-size:
|
|
466
|
+
font-size: 60rpx;
|
|
548
467
|
}
|
|
549
468
|
.ml-upload-file-info {
|
|
550
469
|
flex-grow: 1;
|
|
@@ -557,9 +476,5 @@ export default {
|
|
|
557
476
|
.ml-upload-file-right {
|
|
558
477
|
width: 60rpx;
|
|
559
478
|
}
|
|
560
|
-
.ml-upload-file-add-btn {
|
|
561
|
-
display: flex;
|
|
562
|
-
flex-direction: row;
|
|
563
|
-
}
|
|
564
479
|
}
|
|
565
480
|
</style>
|