mali-applet-ui 0.2.71 → 0.2.73

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,480 +0,0 @@
1
- <template>
2
- <view class="ml-upload" :class="[className || '']">
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" />
9
- </view>
10
- </view>
11
- <view 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 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="file-txt" />
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 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>
46
- </view>
47
- </view>
48
- </view>
49
- </view>
50
- </template>
51
-
52
- <script>
53
- import XEUtils from 'xe-utils'
54
- import globalStore from '../../config/store'
55
- import mlButton from '../ml-button/ml-button.vue'
56
- import { uploadAllFiles, uploadImageFiles } from './file-handle'
57
-
58
- export default {
59
- components: { mlButton },
60
- name: 'MlUpload',
61
- props: {
62
- value: {
63
- type: Array,
64
- default: () => ([])
65
- },
66
- urlList: {
67
- type: Array,
68
- default: () => ([])
69
- },
70
- simpleValue: {
71
- type: Boolean,
72
- default: false
73
- },
74
- readonly: {
75
- type: Boolean,
76
- default: false
77
- },
78
- limit: {
79
- type: Number,
80
- default: 9
81
- },
82
- className: String,
83
- mediatype: {
84
- type: String,
85
- default: 'all'
86
- },
87
- params: {
88
- type: Object,
89
- default: () => ({})
90
- },
91
- fileProps: {
92
- type: Object,
93
- default: () => ({})
94
- },
95
- getFileUrl: Function,
96
- uploadFile: Function,
97
- removeFile: Function
98
- },
99
- inject: {
100
- currVM: {
101
- from: '$pageVM',
102
- default: null
103
- },
104
- form: {
105
- from: 'mlForm',
106
- default: null
107
- }
108
- },
109
- data () {
110
- return {
111
- fileList: [],
112
- docsTypes: ['doc', 'xls', 'ppt', 'pdf', 'docx', 'xlsx', 'pptx'],
113
- imgTypes: ['png', 'jpg']
114
- }
115
- },
116
- computed: {
117
- isFromReadonly () {
118
- if (this.readonly) {
119
- return true
120
- }
121
- return this.form ? this.form.readonly : false
122
- },
123
- imageList () {
124
- return this.value ? this.value.filter(item => this.imgTypes.includes(item[this.typeField])) : []
125
- },
126
- fieldMaps () {
127
- return { ...globalStore.upload.fileProps, ...this.fileProps }
128
- },
129
- urlField () {
130
- return this.fieldMaps.fileUrl || 'fileUrl'
131
- },
132
- typeField () {
133
- return this.fieldMaps.fileType || 'fileType'
134
- },
135
- nameField () {
136
- return this.fieldMaps.fileName || 'fileName'
137
- }
138
- },
139
- watch: {
140
- value () {
141
- if (!this.isUpdate) {
142
- this.isUpdate = true
143
- this.loadList()
144
- }
145
- },
146
- urlList () {
147
- this.loadList()
148
- }
149
- },
150
- created () {
151
- this.loadList()
152
- },
153
- methods: {
154
- loadList () {
155
- if (this.simpleValue) {
156
- this.fileList = this.urlList.map(url => {
157
- const name = this.getUrlName(url)
158
- const obj = {
159
- id: null,
160
- [this.nameField]: name,
161
- [this.typeField]: this.getSuffix(name),
162
- [this.urlField]: url
163
- }
164
- return {
165
- id: null,
166
- [this.nameField]: name,
167
- [this.typeField]: this.getSuffix(name),
168
- [this.urlField]: url,
169
- tempPath: this.getUrl(obj)
170
- }
171
- })
172
- this.isUpdate = true
173
- this.$emit('input', this.fileList)
174
- } else {
175
- this.fileList = this.value.map(item => {
176
- item.tempPath = this.getUrl(item)
177
- return item
178
- })
179
- }
180
- },
181
- updateModel () {
182
- const urlList = this.fileList.map(item => item[this.urlField])
183
- this.$emit('update:urlList', urlList)
184
- this.$emit('input', this.fileList)
185
- this.$emit('change', { value: this.simpleValue ? urlList : this.fileList })
186
- },
187
- removeEvent (item) {
188
- this.fileList = this.fileList.filter(obj => obj.tempPath !== item.tempPath)
189
- const removeMethod = this.removeFile ? this.removeFile : (globalStore.upload ? globalStore.upload.removeFile : null)
190
- if (!item) {
191
- console.error('删除出错!!!')
192
- }
193
- if (item && !item.id) {
194
- if (removeMethod) {
195
- removeMethod.call(this.currVM, {
196
- item,
197
- params: this.params
198
- })
199
- }
200
- }
201
- this.isUpdate = true
202
- this.updateModel()
203
- },
204
- getUrl (item) {
205
- const getFileMethod = this.getFileUrl ? this.getFileUrl : (globalStore.upload ? globalStore.upload.getFileUrl : null)
206
- if (getFileMethod) {
207
- return getFileMethod.call(this.currVM, {
208
- item,
209
- params: this.params
210
- })
211
- }
212
- return item[this.urlField]
213
- },
214
- getUrlName (url) {
215
- const urlRest = XEUtils.parseUrl(url)
216
- return urlRest.pathname.split('/').slice(-1)[0] || ''
217
- },
218
- getSuffix (filename) {
219
- const pos = filename.lastIndexOf('.')
220
- let suffix = ''
221
- if (pos !== -1) {
222
- suffix = filename.substring(pos + 1)
223
- }
224
- return suffix
225
- },
226
- previewImageEvent (item, index) {
227
- if (this.previewStatus) {
228
- return
229
- }
230
- this.previewStatus = true
231
- Promise.all(
232
- this.value.map(item => {
233
- return new Promise((resolve) => {
234
- uni.downloadFile({
235
- url: this.getUrl(item),
236
- success: (downRes) => {
237
- resolve({
238
- url: downRes.tempFilePath
239
- })
240
- },
241
- fail () {
242
- resolve({
243
- url: ''
244
- })
245
- }
246
- })
247
- })
248
- })
249
- ).then(res => {
250
- uni.previewImage({
251
- current: index,
252
- urls: res.map(item => item.url)
253
- })
254
- this.previewStatus = false
255
- })
256
- },
257
- previewImg (item) {
258
- uni.downloadFile({
259
- url: this.getUrl(item),
260
- success: (downRes) => {
261
- uni.previewImage({
262
- urls: [
263
- downRes.tempFilePath
264
- ],
265
- longPressActions: {
266
- itemList: ['保存图片']
267
- }
268
- })
269
- }
270
- })
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
- },
305
- downloadEvent (item) {
306
- uni.downloadFile({
307
- url: this.getUrl(item),
308
- success: (downRes) => {
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
- })
320
- },
321
- fail () {
322
- uni.showModal({
323
- content: '下载失败',
324
- showCancel: false
325
- });
326
- }
327
- })
328
- },
329
- chooseEvent () {
330
- let chooseMethod = uploadAllFiles
331
- if (this.mediatype === 'image') {
332
- chooseMethod = uploadImageFiles
333
- }
334
- const uploadMethod = this.uploadFile ? this.uploadFile : (globalStore.upload ? globalStore.upload.uploadFile : null)
335
- chooseMethod({}).then(res => {
336
- const { tempFiles } = res
337
- Promise.all(
338
- tempFiles.map(file => {
339
- const fileSuffix = this.getSuffix(file.name)
340
- if (uploadMethod) {
341
- return Promise.resolve(
342
- uploadMethod.call(this.currVM, {
343
- file,
344
- params: this.params
345
- })
346
- ).then(res => {
347
- return {
348
- ...res,
349
- [this.nameField]: res[this.nameField] || file.name,
350
- [this.typeField]: res[this.typeField] || fileSuffix,
351
- tempPath: file.path
352
- }
353
- })
354
- }
355
- return {
356
- [this.nameField]: file.name,
357
- [this.typeField]: file.extname,
358
- [this.urlField]: file.path,
359
- tempPath: file.path
360
- }
361
- })
362
- ).then(list => {
363
- this.fileList.push(...list)
364
- this.isUpdate = true
365
- this.updateModel()
366
- }).catch((e) => {
367
- console.log(e)
368
- })
369
- })
370
- }
371
- }
372
- }
373
- </script>
374
-
375
- <style lang="scss">
376
- .ml-upload{
377
- margin: 20rpx 0;
378
- background: #fff;
379
- }
380
- .ml-upload-image-list {
381
- display: flex;
382
- flex-direction: row;
383
- flex-wrap: wrap;
384
- .ml-upload-image-item,
385
- .ml-upload-image-add {
386
- display: flex;
387
- justify-content: center;
388
- align-items: center;
389
- position: relative;
390
- width: 140rpx;
391
- height: 140rpx;
392
- text-align: center;
393
- }
394
- .ml-upload-image-del-btn {
395
- position: absolute;
396
- right: 0;
397
- top: 0;
398
- width: 40rpx;
399
- height: 40rpx;
400
- line-height: 40rpx;
401
- font-size: 28rpx;
402
- text-align: center;
403
- border-radius: 50%;
404
- color: #ffffff;
405
- background: #c8c8c9;
406
- }
407
- .ml-upload-image-add-btn {
408
- width: 100rpx;
409
- height: 100rpx;
410
- line-height: 100rpx;
411
- font-size: 60rpx;
412
- color: #c8c8c9;
413
- border: 1px solid #c8c8c9;
414
- border-radius: 50%;
415
- }
416
- .ml-upload-image-img {
417
- width: 120rpx;
418
- height: 120rpx;
419
- line-height: 120rpx;
420
- border-radius: $ml-border-radius;
421
- }
422
- }
423
- .ml-upload-file-list {
424
- .ml-upload-file-add,
425
- .ml-upload-file-item {
426
- margin: 20rpx 0;
427
- }
428
- .ml-upload-file-item {
429
- display: flex;
430
- flex-direction: row;
431
- }
432
- .ml-upload-file-item {
433
- padding-bottom: 10rpx;
434
- border-bottom: 1px solid #f1f1f1;
435
- }
436
- .ml-upload-file-left,
437
- .ml-upload-file-right {
438
- display: flex;
439
- flex-direction: row;
440
- align-items: center;
441
- justify-content: center;
442
- flex-shrink: 0;
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
- }
462
- .ml-upload-file-left {
463
- width: 80rpx;
464
- }
465
- .ml-upload-file-icon {
466
- font-size: 60rpx;
467
- }
468
- .ml-upload-file-info {
469
- flex-grow: 1;
470
- .ml-upload-file-name {
471
- overflow: hidden;
472
- text-overflow: ellipsis;
473
- white-space: nowrap;
474
- }
475
- }
476
- .ml-upload-file-right {
477
- width: 60rpx;
478
- }
479
- }
480
- </style>