mali-applet-ui 0.2.70 → 0.2.72
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,33 +1,58 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<view class="ml-upload" :class="[className || '']">
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
<!-- 上传图片 -->
|
|
4
|
+
<view v-if="mediatype === 'image'" class="ml-upload-image-list">
|
|
5
|
+
<view class="ml-upload-image-item" v-for="(item, index) in fileList" :key="index">
|
|
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)">
|
|
8
|
+
<ml-icon name="close" />
|
|
7
9
|
</view>
|
|
8
10
|
</view>
|
|
9
|
-
<view v-
|
|
10
|
-
<view class="ml-upload-
|
|
11
|
-
<view class="ml-upload-
|
|
11
|
+
<view v-if="!isFromReadonly" class="ml-upload-image-add">
|
|
12
|
+
<view class="ml-upload-image-add-btn" @tap="chooseEvent">
|
|
13
|
+
<view class="ml-upload-image-add-icon">
|
|
14
|
+
<ml-icon name="add" />
|
|
15
|
+
</view>
|
|
16
|
+
</view>
|
|
17
|
+
</view>
|
|
18
|
+
</view>
|
|
19
|
+
<!-- 上传文件 -->
|
|
20
|
+
<view v-else class="ml-upload-file-list">
|
|
21
|
+
<view v-if="!isFromReadonly" 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>
|
|
29
|
+
<view class="ml-upload-file-item" v-for="(item, index) in fileList" :key="index">
|
|
30
|
+
<view class="ml-upload-file-left">
|
|
31
|
+
<view class="ml-upload-file-icon">
|
|
32
|
+
<ml-icon :name="getFileIcon(item)" />
|
|
33
|
+
</view>
|
|
34
|
+
</view>
|
|
35
|
+
<view class="ml-upload-file-info">
|
|
36
|
+
<view class="ml-upload-file-name">{{ item[nameField] }}</view>
|
|
37
|
+
<view class="ml-upload-file-desc">
|
|
38
|
+
<ml-button v-if="docsTypes.includes(item[typeField])" status="primary" type="text" @click="previewDocs(item)">预览</ml-button>
|
|
39
|
+
<ml-button status="primary" type="text" @click="downloadEvent(item)">下载</ml-button>
|
|
40
|
+
</view>
|
|
41
|
+
</view>
|
|
42
|
+
<view class="ml-upload-file-right">
|
|
43
|
+
<view class="ml-upload-file-del-btn" @click="removeEvent(item)">
|
|
44
|
+
<ml-icon name="close" />
|
|
45
|
+
</view>
|
|
12
46
|
</view>
|
|
13
47
|
</view>
|
|
14
48
|
</view>
|
|
15
|
-
<uni-file-picker
|
|
16
|
-
v-else
|
|
17
|
-
v-model="selectUniFileList"
|
|
18
|
-
:limit="limit"
|
|
19
|
-
file-mediatype="image"
|
|
20
|
-
:image-styles="imageStyles"
|
|
21
|
-
:auto-upload="false"
|
|
22
|
-
@select="selectFile"
|
|
23
|
-
@delete="removeEvent">
|
|
24
|
-
</uni-file-picker>
|
|
25
49
|
</view>
|
|
26
50
|
</template>
|
|
27
51
|
|
|
28
52
|
<script>
|
|
29
53
|
import XEUtils from 'xe-utils'
|
|
30
54
|
import globalStore from '../../config/store'
|
|
55
|
+
import { uploadAllFiles, uploadImageFiles } from './file-handle'
|
|
31
56
|
|
|
32
57
|
export default {
|
|
33
58
|
name: 'MlUpload',
|
|
@@ -82,16 +107,7 @@ export default {
|
|
|
82
107
|
data () {
|
|
83
108
|
return {
|
|
84
109
|
fileList: [],
|
|
85
|
-
|
|
86
|
-
imageStyles: {
|
|
87
|
-
// "height": 60, // 边框高度
|
|
88
|
-
// "width": 60, // 边框宽度
|
|
89
|
-
// "border":{ // 如果为 Boolean 值,可以控制边框显示与否
|
|
90
|
-
// "color":"transparent", // 边框颜色
|
|
91
|
-
// "width":"1px", // 边框宽度
|
|
92
|
-
// "style":"solid", // 边框样式
|
|
93
|
-
// }
|
|
94
|
-
},
|
|
110
|
+
docsTypes: ['doc', 'xls', 'ppt', 'pdf', 'docx', 'xlsx', 'pptx'],
|
|
95
111
|
imgTypes: ['png', 'jpg']
|
|
96
112
|
}
|
|
97
113
|
},
|
|
@@ -119,7 +135,7 @@ export default {
|
|
|
119
135
|
}
|
|
120
136
|
},
|
|
121
137
|
watch: {
|
|
122
|
-
value (
|
|
138
|
+
value () {
|
|
123
139
|
if (!this.isUpdate) {
|
|
124
140
|
this.isUpdate = true
|
|
125
141
|
this.loadList()
|
|
@@ -133,6 +149,25 @@ export default {
|
|
|
133
149
|
this.loadList()
|
|
134
150
|
},
|
|
135
151
|
methods: {
|
|
152
|
+
getFileIcon (item) {
|
|
153
|
+
switch (item[[this.typeField]]) {
|
|
154
|
+
case 'png':
|
|
155
|
+
case 'jpg':
|
|
156
|
+
return 'file-image'
|
|
157
|
+
case 'doc':
|
|
158
|
+
case 'docx':
|
|
159
|
+
return 'file-word'
|
|
160
|
+
case 'xls':
|
|
161
|
+
case 'xlsx':
|
|
162
|
+
return 'file-excel'
|
|
163
|
+
case 'ppt':
|
|
164
|
+
case 'pptx':
|
|
165
|
+
return 'file-ppt'
|
|
166
|
+
case 'pdf':
|
|
167
|
+
return 'file-pdf'
|
|
168
|
+
}
|
|
169
|
+
return 'file-txt'
|
|
170
|
+
},
|
|
136
171
|
loadList () {
|
|
137
172
|
if (this.simpleValue) {
|
|
138
173
|
this.fileList = this.urlList.map(url => {
|
|
@@ -151,21 +186,6 @@ export default {
|
|
|
151
186
|
tempPath: this.getUrl(obj)
|
|
152
187
|
}
|
|
153
188
|
})
|
|
154
|
-
this.selectUniFileList = this.urlList.map(url => {
|
|
155
|
-
const name = this.getUrlName(url)
|
|
156
|
-
const extname = this.getSuffix(name)
|
|
157
|
-
const obj = {
|
|
158
|
-
[this.nameField]: name,
|
|
159
|
-
[this.typeField]: extname,
|
|
160
|
-
[this.urlField]: url
|
|
161
|
-
}
|
|
162
|
-
return {
|
|
163
|
-
...obj,
|
|
164
|
-
name: name,
|
|
165
|
-
extname: extname,
|
|
166
|
-
url: this.getUrl(obj)
|
|
167
|
-
}
|
|
168
|
-
})
|
|
169
189
|
this.isUpdate = true
|
|
170
190
|
this.$emit('input', this.fileList)
|
|
171
191
|
} else {
|
|
@@ -173,14 +193,6 @@ export default {
|
|
|
173
193
|
item.tempPath = this.getUrl(item)
|
|
174
194
|
return item
|
|
175
195
|
})
|
|
176
|
-
this.selectUniFileList = this.value.map(item => {
|
|
177
|
-
return {
|
|
178
|
-
...item,
|
|
179
|
-
name: item[this.nameField],
|
|
180
|
-
extname: item[this.typeField],
|
|
181
|
-
url: this.getUrl(item)
|
|
182
|
-
}
|
|
183
|
-
})
|
|
184
196
|
}
|
|
185
197
|
},
|
|
186
198
|
updateModel () {
|
|
@@ -189,61 +201,8 @@ export default {
|
|
|
189
201
|
this.$emit('input', this.fileList)
|
|
190
202
|
this.$emit('change', { value: this.simpleValue ? urlList : this.fileList })
|
|
191
203
|
},
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
if (this.$loading) {
|
|
195
|
-
this.$loading.show('上传中')
|
|
196
|
-
}
|
|
197
|
-
const uploadMethod = this.uploadFile ? this.uploadFile : (globalStore.upload ? globalStore.upload.uploadFile : null)
|
|
198
|
-
Promise.all(
|
|
199
|
-
tempFiles.map(file => {
|
|
200
|
-
const fileSuffix = this.getSuffix(file.name)
|
|
201
|
-
if (uploadMethod) {
|
|
202
|
-
return Promise.resolve(
|
|
203
|
-
uploadMethod.call(this.currVM, {
|
|
204
|
-
file,
|
|
205
|
-
params: this.params
|
|
206
|
-
})
|
|
207
|
-
).then(res => {
|
|
208
|
-
const item = {
|
|
209
|
-
...res,
|
|
210
|
-
[this.nameField]: res[this.nameField] || file.name,
|
|
211
|
-
[this.typeField]: res[this.typeField] || fileSuffix,
|
|
212
|
-
tempPath: file.path
|
|
213
|
-
}
|
|
214
|
-
this.selectUniFileList.push(file)
|
|
215
|
-
this.fileList.push(item)
|
|
216
|
-
this.isUpdate = true
|
|
217
|
-
this.updateModel()
|
|
218
|
-
})
|
|
219
|
-
} else {
|
|
220
|
-
const item = {
|
|
221
|
-
[this.nameField]: file.name,
|
|
222
|
-
[this.typeField]: file.extname,
|
|
223
|
-
[this.urlField]: file.path,
|
|
224
|
-
tempPath: file.path
|
|
225
|
-
}
|
|
226
|
-
this.selectUniFileList.push(file)
|
|
227
|
-
this.fileList.push(item)
|
|
228
|
-
this.isUpdate = true
|
|
229
|
-
this.updateModel()
|
|
230
|
-
}
|
|
231
|
-
})
|
|
232
|
-
).then(res => {
|
|
233
|
-
if (this.$loading) {
|
|
234
|
-
this.$loading.hide()
|
|
235
|
-
}
|
|
236
|
-
}).catch((e) => {
|
|
237
|
-
if (this.$loading) {
|
|
238
|
-
this.$loading.hide()
|
|
239
|
-
}
|
|
240
|
-
})
|
|
241
|
-
},
|
|
242
|
-
removeEvent (e) {
|
|
243
|
-
const { tempFilePath } = e
|
|
244
|
-
const item = this.fileList.find(item => item.tempPath === tempFilePath)
|
|
245
|
-
this.selectUniFileList = this.selectUniFileList.filter(item => item.url !== tempFilePath)
|
|
246
|
-
this.fileList = this.fileList.filter(item => item.tempPath !== tempFilePath)
|
|
204
|
+
removeEvent (item) {
|
|
205
|
+
this.fileList = this.fileList.filter(obj => obj.tempPath !== item.tempPath)
|
|
247
206
|
const removeMethod = this.removeFile ? this.removeFile : (globalStore.upload ? globalStore.upload.removeFile : null)
|
|
248
207
|
if (!item) {
|
|
249
208
|
console.error('删除出错!!!')
|
|
@@ -281,7 +240,7 @@ export default {
|
|
|
281
240
|
}
|
|
282
241
|
return suffix
|
|
283
242
|
},
|
|
284
|
-
|
|
243
|
+
previewImageEvent (item, index) {
|
|
285
244
|
if (this.previewStatus) {
|
|
286
245
|
return
|
|
287
246
|
}
|
|
@@ -327,40 +286,54 @@ export default {
|
|
|
327
286
|
}
|
|
328
287
|
})
|
|
329
288
|
},
|
|
289
|
+
previewDocs (item) {
|
|
290
|
+
// 仅支持文档和图片
|
|
291
|
+
const supportDocs = this.docsTypes.includes(item[this.typeField])
|
|
292
|
+
const supportImg = this.imgTypes.includes(item[this.typeField])
|
|
293
|
+
if (supportDocs || supportImg) {
|
|
294
|
+
uni.downloadFile({
|
|
295
|
+
url: this.getUrl(item),
|
|
296
|
+
success: (downRes) => {
|
|
297
|
+
if (supportDocs) {
|
|
298
|
+
uni.openDocument({
|
|
299
|
+
filePath: downRes.tempFilePath,
|
|
300
|
+
showMenu: true,
|
|
301
|
+
success () {},
|
|
302
|
+
fail () {
|
|
303
|
+
uni.showModal({
|
|
304
|
+
content: '打开失败',
|
|
305
|
+
showCancel: false
|
|
306
|
+
})
|
|
307
|
+
}
|
|
308
|
+
})
|
|
309
|
+
} else if (supportImg) {
|
|
310
|
+
this.previewImg(item)
|
|
311
|
+
}
|
|
312
|
+
},
|
|
313
|
+
fail () {
|
|
314
|
+
uni.showModal({
|
|
315
|
+
content: '下载失败',
|
|
316
|
+
showCancel: false
|
|
317
|
+
})
|
|
318
|
+
}
|
|
319
|
+
})
|
|
320
|
+
}
|
|
321
|
+
},
|
|
330
322
|
downloadEvent (item) {
|
|
331
323
|
uni.downloadFile({
|
|
332
324
|
url: this.getUrl(item),
|
|
333
325
|
success: (downRes) => {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
})
|
|
348
|
-
} else if (['png', 'jpg'].includes(item[this.typeField])) {
|
|
349
|
-
this.previewImg(item)
|
|
350
|
-
} else {
|
|
351
|
-
uni.saveFile({
|
|
352
|
-
tempFilePath: downRes.tempFilePath,
|
|
353
|
-
success: function(res) {
|
|
354
|
-
uni.showToast({
|
|
355
|
-
icon: 'none',
|
|
356
|
-
mask: true,
|
|
357
|
-
title: '文件已保存:' + res.savedFilePath, //保存路径
|
|
358
|
-
duration: 3000,
|
|
359
|
-
})
|
|
360
|
-
}
|
|
361
|
-
})
|
|
362
|
-
|
|
363
|
-
}
|
|
326
|
+
uni.saveFile({
|
|
327
|
+
tempFilePath: downRes.tempFilePath,
|
|
328
|
+
success: function(res) {
|
|
329
|
+
uni.showToast({
|
|
330
|
+
icon: 'none',
|
|
331
|
+
mask: true,
|
|
332
|
+
title: '文件已保存:' + res.savedFilePath, //保存路径
|
|
333
|
+
duration: 3000,
|
|
334
|
+
})
|
|
335
|
+
}
|
|
336
|
+
})
|
|
364
337
|
},
|
|
365
338
|
fail () {
|
|
366
339
|
uni.showModal({
|
|
@@ -369,6 +342,50 @@ export default {
|
|
|
369
342
|
});
|
|
370
343
|
}
|
|
371
344
|
})
|
|
345
|
+
},
|
|
346
|
+
chooseEvent () {
|
|
347
|
+
let chooseMethod = uploadAllFiles
|
|
348
|
+
if (this.mediatype === 'image') {
|
|
349
|
+
chooseMethod = uploadImageFiles
|
|
350
|
+
}
|
|
351
|
+
const uploadMethod = this.uploadFile ? this.uploadFile : (globalStore.upload ? globalStore.upload.uploadFile : null)
|
|
352
|
+
chooseMethod({
|
|
353
|
+
count: this.limit
|
|
354
|
+
}).then(res => {
|
|
355
|
+
const { tempFiles } = res
|
|
356
|
+
Promise.all(
|
|
357
|
+
tempFiles.map(file => {
|
|
358
|
+
const fileSuffix = this.getSuffix(file.name)
|
|
359
|
+
if (uploadMethod) {
|
|
360
|
+
return Promise.resolve(
|
|
361
|
+
uploadMethod.call(this.currVM, {
|
|
362
|
+
file,
|
|
363
|
+
params: this.params
|
|
364
|
+
})
|
|
365
|
+
).then(res => {
|
|
366
|
+
return {
|
|
367
|
+
...res,
|
|
368
|
+
[this.nameField]: res[this.nameField] || file.name,
|
|
369
|
+
[this.typeField]: res[this.typeField] || fileSuffix,
|
|
370
|
+
tempPath: file.path
|
|
371
|
+
}
|
|
372
|
+
})
|
|
373
|
+
}
|
|
374
|
+
return {
|
|
375
|
+
[this.nameField]: file.name,
|
|
376
|
+
[this.typeField]: file.extname,
|
|
377
|
+
[this.urlField]: file.path,
|
|
378
|
+
tempPath: file.path
|
|
379
|
+
}
|
|
380
|
+
})
|
|
381
|
+
).then(list => {
|
|
382
|
+
this.fileList.push(...list)
|
|
383
|
+
this.isUpdate = true
|
|
384
|
+
this.updateModel()
|
|
385
|
+
}).catch((e) => {
|
|
386
|
+
console.log(e)
|
|
387
|
+
})
|
|
388
|
+
})
|
|
372
389
|
}
|
|
373
390
|
}
|
|
374
391
|
}
|
|
@@ -380,31 +397,105 @@ export default {
|
|
|
380
397
|
background: #fff;
|
|
381
398
|
}
|
|
382
399
|
.ml-upload-image-list {
|
|
383
|
-
|
|
384
|
-
|
|
400
|
+
display: flex;
|
|
401
|
+
flex-direction: row;
|
|
402
|
+
flex-wrap: wrap;
|
|
403
|
+
.ml-upload-image-item,
|
|
404
|
+
.ml-upload-image-add {
|
|
405
|
+
display: flex;
|
|
406
|
+
justify-content: center;
|
|
407
|
+
align-items: center;
|
|
408
|
+
position: relative;
|
|
385
409
|
width: 140rpx;
|
|
386
410
|
height: 140rpx;
|
|
387
|
-
|
|
411
|
+
text-align: center;
|
|
388
412
|
}
|
|
389
|
-
.ml-upload-
|
|
390
|
-
|
|
391
|
-
|
|
413
|
+
.ml-upload-image-del-btn {
|
|
414
|
+
position: absolute;
|
|
415
|
+
right: 0;
|
|
416
|
+
top: 0;
|
|
417
|
+
width: 40rpx;
|
|
418
|
+
height: 40rpx;
|
|
419
|
+
line-height: 40rpx;
|
|
420
|
+
font-size: 28rpx;
|
|
421
|
+
text-align: center;
|
|
422
|
+
border-radius: 50%;
|
|
423
|
+
color: #ffffff;
|
|
424
|
+
background: #c8c8c9;
|
|
425
|
+
}
|
|
426
|
+
.ml-upload-image-add-btn {
|
|
427
|
+
width: 120rpx;
|
|
428
|
+
height: 120rpx;
|
|
429
|
+
line-height: 120rpx;
|
|
430
|
+
font-size: 60rpx;
|
|
431
|
+
color: #c8c8c9;
|
|
432
|
+
border: 1px dashed #c8c8c9;
|
|
433
|
+
border-radius: $ml-border-radius;
|
|
434
|
+
}
|
|
435
|
+
.ml-upload-image-img {
|
|
436
|
+
width: 120rpx;
|
|
437
|
+
height: 120rpx;
|
|
438
|
+
line-height: 120rpx;
|
|
439
|
+
border-radius: $ml-border-radius;
|
|
392
440
|
}
|
|
393
441
|
}
|
|
394
442
|
.ml-upload-file-list {
|
|
395
|
-
|
|
443
|
+
.ml-upload-file-add,
|
|
396
444
|
.ml-upload-file-item {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
445
|
+
margin: 20rpx 0;
|
|
446
|
+
}
|
|
447
|
+
.ml-upload-file-item {
|
|
448
|
+
display: flex;
|
|
449
|
+
flex-direction: row;
|
|
450
|
+
}
|
|
451
|
+
.ml-upload-file-item {
|
|
452
|
+
padding-bottom: 10rpx;
|
|
453
|
+
border-bottom: 1px solid #f1f1f1;
|
|
454
|
+
}
|
|
455
|
+
.ml-upload-file-left,
|
|
456
|
+
.ml-upload-file-right {
|
|
457
|
+
display: flex;
|
|
458
|
+
flex-direction: row;
|
|
459
|
+
align-items: center;
|
|
460
|
+
justify-content: center;
|
|
461
|
+
flex-shrink: 0;
|
|
462
|
+
}
|
|
463
|
+
.ml-upload-file-add-btn {
|
|
464
|
+
height: 70rpx;
|
|
465
|
+
line-height: 70rpx;
|
|
466
|
+
text-align: center;
|
|
467
|
+
color: #8a8686;
|
|
468
|
+
border: 1px dashed #c8c8c9;
|
|
400
469
|
border-radius: $ml-border-radius;
|
|
401
|
-
padding: 20rpx;
|
|
402
470
|
}
|
|
403
|
-
.ml-upload-file-
|
|
404
|
-
width:
|
|
471
|
+
.ml-upload-file-del-btn {
|
|
472
|
+
width: 40rpx;
|
|
473
|
+
height: 40rpx;
|
|
474
|
+
line-height: 40rpx;
|
|
475
|
+
text-align: center;
|
|
476
|
+
font-size: 28rpx;
|
|
477
|
+
color: #ffffff;
|
|
478
|
+
background: #c8c8c9;
|
|
479
|
+
border-radius: 50%;
|
|
480
|
+
}
|
|
481
|
+
.ml-upload-file-left {
|
|
482
|
+
width: 80rpx;
|
|
483
|
+
}
|
|
484
|
+
.ml-upload-file-icon {
|
|
485
|
+
font-size: 60rpx;
|
|
486
|
+
color: #666666;
|
|
487
|
+
}
|
|
488
|
+
.ml-upload-file-info {
|
|
489
|
+
flex-grow: 1;
|
|
405
490
|
overflow: hidden;
|
|
406
|
-
|
|
407
|
-
|
|
491
|
+
.ml-upload-file-name {
|
|
492
|
+
overflow: hidden;
|
|
493
|
+
text-overflow: ellipsis;
|
|
494
|
+
white-space: nowrap;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
.ml-upload-file-right {
|
|
498
|
+
width: 60rpx;
|
|
408
499
|
}
|
|
409
500
|
}
|
|
410
501
|
</style>
|
|
@@ -1,57 +1,33 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<view class="ml-upload" :class="[className || '']">
|
|
3
|
-
<view v-if="
|
|
4
|
-
<view
|
|
5
|
-
<
|
|
6
|
-
|
|
7
|
-
<ml-icon name="close" />
|
|
3
|
+
<view v-if="isFromReadonly">
|
|
4
|
+
<view v-if="mediatype === 'image'" class="ml-upload-image-list">
|
|
5
|
+
<view class="ml-upload-file-item" v-for="(item, index) in value" :key="index">
|
|
6
|
+
<image class="ml-upload-file-img" mode="aspectFill" :src="getUrl(item)" @click="previewEvent(item, index)"></image>
|
|
8
7
|
</view>
|
|
9
8
|
</view>
|
|
10
|
-
<view class="ml-upload-
|
|
11
|
-
<view class="ml-upload-
|
|
12
|
-
<view class="ml-upload-
|
|
13
|
-
<ml-icon name="add" />
|
|
14
|
-
</view>
|
|
15
|
-
</view>
|
|
16
|
-
</view>
|
|
17
|
-
</view>
|
|
18
|
-
|
|
19
|
-
<view v-else class="ml-upload-file-list">
|
|
20
|
-
<view class="ml-upload-file-item" v-for="(item, index) in fileList" :key="index">
|
|
21
|
-
<view class="ml-upload-file-left">
|
|
22
|
-
<view class="ml-upload-file-icon">
|
|
23
|
-
<ml-icon name="file-txt" />
|
|
24
|
-
</view>
|
|
25
|
-
</view>
|
|
26
|
-
<view class="ml-upload-file-info">
|
|
27
|
-
<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>
|
|
31
|
-
</view>
|
|
32
|
-
</view>
|
|
33
|
-
<view class="ml-upload-file-right">
|
|
34
|
-
<view class="ml-upload-file-del-btn">
|
|
35
|
-
<ml-icon name="close" />
|
|
36
|
-
</view>
|
|
37
|
-
</view>
|
|
38
|
-
</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>
|
|
9
|
+
<view v-else class="ml-upload-file-list">
|
|
10
|
+
<view class="ml-upload-file-item" v-for="(item, index) in value" :key="index">
|
|
11
|
+
<view class="ml-upload-file-name" @click="downloadEvent(item)">{{ item[nameField] }}</view>
|
|
45
12
|
</view>
|
|
46
13
|
</view>
|
|
47
14
|
</view>
|
|
15
|
+
<uni-file-picker
|
|
16
|
+
v-else
|
|
17
|
+
v-model="selectUniFileList"
|
|
18
|
+
:limit="limit"
|
|
19
|
+
file-mediatype="image"
|
|
20
|
+
:image-styles="imageStyles"
|
|
21
|
+
:auto-upload="false"
|
|
22
|
+
@select="selectFile"
|
|
23
|
+
@delete="removeEvent">
|
|
24
|
+
</uni-file-picker>
|
|
48
25
|
</view>
|
|
49
26
|
</template>
|
|
50
27
|
|
|
51
28
|
<script>
|
|
52
29
|
import XEUtils from 'xe-utils'
|
|
53
30
|
import globalStore from '../../config/store'
|
|
54
|
-
import { uploadAllFiles, uploadImageFiles } from './file-handle'
|
|
55
31
|
|
|
56
32
|
export default {
|
|
57
33
|
name: 'MlUpload',
|
|
@@ -393,88 +369,6 @@ export default {
|
|
|
393
369
|
});
|
|
394
370
|
}
|
|
395
371
|
})
|
|
396
|
-
},
|
|
397
|
-
chooseImage () {
|
|
398
|
-
const uploadMethod = this.uploadFile ? this.uploadFile : (globalStore.upload ? globalStore.upload.uploadFile : null)
|
|
399
|
-
uploadImageFiles({}).then(res => {
|
|
400
|
-
const { tempFiles } = res
|
|
401
|
-
debugger
|
|
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 () {
|
|
439
|
-
const uploadMethod = this.uploadFile ? this.uploadFile : (globalStore.upload ? globalStore.upload.uploadFile : null)
|
|
440
|
-
uploadAllFiles({}).then(res => {
|
|
441
|
-
const { tempFiles } = res
|
|
442
|
-
debugger
|
|
443
|
-
Promise.all(
|
|
444
|
-
tempFiles.map(file => {
|
|
445
|
-
const fileSuffix = this.getSuffix(file.name)
|
|
446
|
-
if (uploadMethod) {
|
|
447
|
-
return Promise.resolve(
|
|
448
|
-
uploadMethod.call(this.currVM, {
|
|
449
|
-
file,
|
|
450
|
-
params: this.params
|
|
451
|
-
})
|
|
452
|
-
).then(res => {
|
|
453
|
-
return {
|
|
454
|
-
...res,
|
|
455
|
-
[this.nameField]: res[this.nameField] || file.name,
|
|
456
|
-
[this.typeField]: res[this.typeField] || fileSuffix,
|
|
457
|
-
tempPath: file.path
|
|
458
|
-
}
|
|
459
|
-
})
|
|
460
|
-
}
|
|
461
|
-
return {
|
|
462
|
-
[this.nameField]: file.name,
|
|
463
|
-
[this.typeField]: file.extname,
|
|
464
|
-
[this.urlField]: file.path,
|
|
465
|
-
tempPath: file.path
|
|
466
|
-
}
|
|
467
|
-
})
|
|
468
|
-
).then(list => {
|
|
469
|
-
this.selectUniFileList.push(...list)
|
|
470
|
-
this.fileList.push(...list)
|
|
471
|
-
this.isUpdate = true
|
|
472
|
-
this.updateModel()
|
|
473
|
-
debugger
|
|
474
|
-
}).catch((e) => {
|
|
475
|
-
debugger
|
|
476
|
-
})
|
|
477
|
-
})
|
|
478
372
|
}
|
|
479
373
|
}
|
|
480
374
|
}
|
|
@@ -486,80 +380,31 @@ export default {
|
|
|
486
380
|
background: #fff;
|
|
487
381
|
}
|
|
488
382
|
.ml-upload-image-list {
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
flex-wrap: wrap;
|
|
492
|
-
.ml-upload-image-item,
|
|
493
|
-
.ml-upload-image-add {
|
|
494
|
-
display: flex;
|
|
495
|
-
justify-content: center;
|
|
496
|
-
align-items: center;
|
|
497
|
-
position: relative;
|
|
383
|
+
.ml-upload-file-item {
|
|
384
|
+
display: inline-block;
|
|
498
385
|
width: 140rpx;
|
|
499
386
|
height: 140rpx;
|
|
500
|
-
|
|
501
|
-
}
|
|
502
|
-
.ml-upload-image-del-btn {
|
|
503
|
-
position: absolute;
|
|
504
|
-
right: 0;
|
|
505
|
-
top: 0;
|
|
506
|
-
width: 40rpx;
|
|
507
|
-
height: 40rpx;
|
|
508
|
-
line-height: 40rpx;
|
|
509
|
-
text-align: center;
|
|
510
|
-
border-radius: 50%;
|
|
511
|
-
color: #ffffff;
|
|
512
|
-
background: #c8c8c9;
|
|
513
|
-
}
|
|
514
|
-
.ml-upload-image-add-btn {
|
|
515
|
-
width: 100rpx;
|
|
516
|
-
height: 100rpx;
|
|
517
|
-
line-height: 100rpx;
|
|
518
|
-
font-size: 60rpx;
|
|
519
|
-
color: #c8c8c9;
|
|
520
|
-
border: 1px solid #c8c8c9;
|
|
521
|
-
border-radius: 50%;
|
|
387
|
+
padding: 0 10rpx;
|
|
522
388
|
}
|
|
523
|
-
.ml-upload-
|
|
524
|
-
width:
|
|
525
|
-
height:
|
|
526
|
-
line-height: 120rpx;
|
|
527
|
-
border-radius: $ml-border-radius;
|
|
389
|
+
.ml-upload-file-img {
|
|
390
|
+
width: 100%;
|
|
391
|
+
height: 100%;
|
|
528
392
|
}
|
|
529
393
|
}
|
|
530
394
|
.ml-upload-file-list {
|
|
395
|
+
display: block;
|
|
531
396
|
.ml-upload-file-item {
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
display: flex;
|
|
538
|
-
flex-direction: row;
|
|
539
|
-
align-items: center;
|
|
540
|
-
justify-content: center;
|
|
541
|
-
flex-shrink: 0;
|
|
542
|
-
}
|
|
543
|
-
.ml-upload-file-left {
|
|
544
|
-
width: 80rpx;
|
|
545
|
-
}
|
|
546
|
-
.ml-upload-file-icon {
|
|
547
|
-
font-size: 50rpx;
|
|
548
|
-
}
|
|
549
|
-
.ml-upload-file-info {
|
|
550
|
-
flex-grow: 1;
|
|
551
|
-
.ml-upload-file-name {
|
|
552
|
-
overflow: hidden;
|
|
553
|
-
text-overflow: ellipsis;
|
|
554
|
-
white-space: nowrap;
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
.ml-upload-file-right {
|
|
558
|
-
width: 60rpx;
|
|
397
|
+
border: 1rpx solid rgba(39, 42, 48, 0.0200);
|
|
398
|
+
background-color: rgba(39, 42, 48, 0.0200);
|
|
399
|
+
margin: 10rpx 0;
|
|
400
|
+
border-radius: $ml-border-radius;
|
|
401
|
+
padding: 20rpx;
|
|
559
402
|
}
|
|
560
|
-
.ml-upload-file-
|
|
561
|
-
|
|
562
|
-
|
|
403
|
+
.ml-upload-file-name {
|
|
404
|
+
width: 600rpx;
|
|
405
|
+
overflow: hidden;
|
|
406
|
+
text-overflow: ellipsis;
|
|
407
|
+
white-space: nowrap;
|
|
563
408
|
}
|
|
564
409
|
}
|
|
565
410
|
</style>
|
package/package.json
CHANGED
package/utils/date.js
CHANGED
|
@@ -7,7 +7,7 @@ import XEUtils from 'xe-utils'
|
|
|
7
7
|
* @returns
|
|
8
8
|
*/
|
|
9
9
|
export function toDateString (date, format = 'yyyy-MM-dd HH:mm:ss') {
|
|
10
|
-
return XEUtils.toDateString(date, format.replace('YYYY', 'yyyy').replace('DD', 'dd'))
|
|
10
|
+
return XEUtils.toDateString(date, format.replace('YYYY', 'yyyy').replace('DD', 'dd').replace('D', 'd'))
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
/**
|