mali-applet-ui 0.2.67 → 0.2.69

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.
@@ -7,7 +7,7 @@
7
7
  <script>
8
8
  import XEUtils from 'xe-utils'
9
9
  import WxCanvas from './wx-canvas';
10
- import * as echarts from './echarts';
10
+ import * as echarts from './echarts.simple.min.js';
11
11
 
12
12
  function wrapTouch(event) {
13
13
  for (let i = 0; i < event.touches.length; ++i) {
@@ -0,0 +1,52 @@
1
+ function normalizeChooseAndUploadFileRes(res, fileType) {
2
+ debugger
3
+ res.tempFiles.forEach((item) => {
4
+ if (!item.name) {
5
+ item.name = item.path.substring(item.path.lastIndexOf('/') + 1)
6
+ }
7
+ if (fileType) {
8
+ item.fileType = fileType
9
+ }
10
+ })
11
+ return res
12
+ }
13
+
14
+ export function uploadImageFiles(opts) {
15
+ return new Promise((resolve, reject) => {
16
+ uni.chooseImage({
17
+ count: opts.count || 9,
18
+ sizeType: opts.sizeType || ['original', 'compressed'],
19
+ sourceType: opts.sourceType || ['album', 'camera'],
20
+ extension: opts.extension,
21
+ success(res) {
22
+ resolve(normalizeChooseAndUploadFileRes(res, 'image'));
23
+ },
24
+ fail(res) {
25
+ reject(res)
26
+ }
27
+ })
28
+ })
29
+ }
30
+
31
+ export function uploadAllFiles(opts) {
32
+ return new Promise((resolve, reject) => {
33
+ let chooseFile = uni.chooseFile;
34
+ if (typeof wx !== 'undefined' && typeof wx.chooseMessageFile === 'function') {
35
+ chooseFile = wx.chooseMessageFile
36
+ }
37
+ if (typeof chooseFile == 'function') {
38
+ return reject({})
39
+ }
40
+ chooseFile({
41
+ type: 'all',
42
+ count: opts.count || 9,
43
+ extension: opts.extension,
44
+ success(res) {
45
+ resolve(normalizeChooseAndUploadFileRes(res));
46
+ },
47
+ fail(res) {
48
+ reject(res)
49
+ }
50
+ })
51
+ })
52
+ }
@@ -0,0 +1,519 @@
1
+ <template>
2
+ <view class="ml-upload" :class="[className || '']">
3
+ <view v-if="mediatype === 'image'" class="ml-upload-image-list">
4
+ <view class="ml-upload-image-item" v-for="(item, index) in fileList" :key="index">
5
+ <image class="ml-upload-image-img" mode="aspectFill" :src="getUrl(item)" @click="previewEvent(item, index)"></image>
6
+ <view class="ml-upload-image-del-btn">
7
+ <ml-icon name="close" />
8
+ </view>
9
+ </view>
10
+ <view class="ml-upload-image-add">
11
+ <view class="ml-upload-image-add-btn" @tap="chooseImage">
12
+ <view class="ml-upload-image-add-icon">
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">
21
+ <view class="ml-upload-file-icon">
22
+ <ml-icon name="file-txt" />
23
+ </view>
24
+ <view class="ml-upload-file-info">
25
+ <view class="ml-upload-file-name"></view>
26
+ <view></view>
27
+ </view>
28
+ </view>
29
+ <view class="ml-upload-file-add">
30
+ <view class="ml-upload-file-add-btn" @tap="chooseFile">
31
+ <view class="ml-upload-file-add-icon">
32
+ <ml-icon name="add" />
33
+ </view>
34
+ <view class="ml-upload-file-add-text">添加附件</view>
35
+ </view>
36
+ </view>
37
+ </view>
38
+ </view>
39
+ </template>
40
+
41
+ <script>
42
+ import XEUtils from 'xe-utils'
43
+ import globalStore from '../../config/store'
44
+ import { uploadImageFiles } from './file-handle'
45
+
46
+ export default {
47
+ name: 'MlUpload',
48
+ props: {
49
+ value: {
50
+ type: Array,
51
+ default: () => ([])
52
+ },
53
+ urlList: {
54
+ type: Array,
55
+ default: () => ([])
56
+ },
57
+ simpleValue: {
58
+ type: Boolean,
59
+ default: false
60
+ },
61
+ readonly: {
62
+ type: Boolean,
63
+ default: false
64
+ },
65
+ limit: {
66
+ type: Number,
67
+ default: 9
68
+ },
69
+ className: String,
70
+ mediatype: {
71
+ type: String,
72
+ default: 'all'
73
+ },
74
+ params: {
75
+ type: Object,
76
+ default: () => ({})
77
+ },
78
+ fileProps: {
79
+ type: Object,
80
+ default: () => ({})
81
+ },
82
+ getFileUrl: Function,
83
+ uploadFile: Function,
84
+ removeFile: Function
85
+ },
86
+ inject: {
87
+ currVM: {
88
+ from: '$pageVM',
89
+ default: null
90
+ },
91
+ form: {
92
+ from: 'mlForm',
93
+ default: null
94
+ }
95
+ },
96
+ data () {
97
+ return {
98
+ fileList: [],
99
+ selectUniFileList: [],
100
+ imageStyles: {
101
+ // "height": 60, // 边框高度
102
+ // "width": 60, // 边框宽度
103
+ // "border":{ // 如果为 Boolean 值,可以控制边框显示与否
104
+ // "color":"transparent", // 边框颜色
105
+ // "width":"1px", // 边框宽度
106
+ // "style":"solid", // 边框样式
107
+ // }
108
+ },
109
+ imgTypes: ['png', 'jpg']
110
+ }
111
+ },
112
+ computed: {
113
+ isFromReadonly () {
114
+ if (this.readonly) {
115
+ return true
116
+ }
117
+ return this.form ? this.form.readonly : false
118
+ },
119
+ imageList () {
120
+ return this.value ? this.value.filter(item => this.imgTypes.includes(item[this.typeField])) : []
121
+ },
122
+ fieldMaps () {
123
+ return { ...globalStore.upload.fileProps, ...this.fileProps }
124
+ },
125
+ urlField () {
126
+ return this.fieldMaps.fileUrl || 'fileUrl'
127
+ },
128
+ typeField () {
129
+ return this.fieldMaps.fileType || 'fileType'
130
+ },
131
+ nameField () {
132
+ return this.fieldMaps.fileName || 'fileName'
133
+ }
134
+ },
135
+ watch: {
136
+ value (val) {
137
+ if (!this.isUpdate) {
138
+ this.isUpdate = true
139
+ this.loadList()
140
+ }
141
+ },
142
+ urlList () {
143
+ this.loadList()
144
+ }
145
+ },
146
+ created () {
147
+ this.loadList()
148
+ },
149
+ methods: {
150
+ loadList () {
151
+ if (this.simpleValue) {
152
+ this.fileList = this.urlList.map(url => {
153
+ const name = this.getUrlName(url)
154
+ const obj = {
155
+ id: null,
156
+ [this.nameField]: name,
157
+ [this.typeField]: this.getSuffix(name),
158
+ [this.urlField]: url
159
+ }
160
+ return {
161
+ id: null,
162
+ [this.nameField]: name,
163
+ [this.typeField]: this.getSuffix(name),
164
+ [this.urlField]: url,
165
+ tempPath: this.getUrl(obj)
166
+ }
167
+ })
168
+ this.selectUniFileList = this.urlList.map(url => {
169
+ const name = this.getUrlName(url)
170
+ const extname = this.getSuffix(name)
171
+ const obj = {
172
+ [this.nameField]: name,
173
+ [this.typeField]: extname,
174
+ [this.urlField]: url
175
+ }
176
+ return {
177
+ ...obj,
178
+ name: name,
179
+ extname: extname,
180
+ url: this.getUrl(obj)
181
+ }
182
+ })
183
+ this.isUpdate = true
184
+ this.$emit('input', this.fileList)
185
+ } else {
186
+ this.fileList = this.value.map(item => {
187
+ item.tempPath = this.getUrl(item)
188
+ return item
189
+ })
190
+ this.selectUniFileList = this.value.map(item => {
191
+ return {
192
+ ...item,
193
+ name: item[this.nameField],
194
+ extname: item[this.typeField],
195
+ url: this.getUrl(item)
196
+ }
197
+ })
198
+ }
199
+ },
200
+ updateModel () {
201
+ const urlList = this.fileList.map(item => item[this.urlField])
202
+ this.$emit('update:urlList', urlList)
203
+ this.$emit('input', this.fileList)
204
+ this.$emit('change', { value: this.simpleValue ? urlList : this.fileList })
205
+ },
206
+ async selectFile (e) {
207
+ const { tempFiles } = e
208
+ if (this.$loading) {
209
+ this.$loading.show('上传中')
210
+ }
211
+ const uploadMethod = this.uploadFile ? this.uploadFile : (globalStore.upload ? globalStore.upload.uploadFile : null)
212
+ Promise.all(
213
+ tempFiles.map(file => {
214
+ const fileSuffix = this.getSuffix(file.name)
215
+ if (uploadMethod) {
216
+ return Promise.resolve(
217
+ uploadMethod.call(this.currVM, {
218
+ file,
219
+ params: this.params
220
+ })
221
+ ).then(res => {
222
+ const item = {
223
+ ...res,
224
+ [this.nameField]: res[this.nameField] || file.name,
225
+ [this.typeField]: res[this.typeField] || fileSuffix,
226
+ tempPath: file.path
227
+ }
228
+ this.selectUniFileList.push(file)
229
+ this.fileList.push(item)
230
+ this.isUpdate = true
231
+ this.updateModel()
232
+ })
233
+ } else {
234
+ const item = {
235
+ [this.nameField]: file.name,
236
+ [this.typeField]: file.extname,
237
+ [this.urlField]: file.path,
238
+ tempPath: file.path
239
+ }
240
+ this.selectUniFileList.push(file)
241
+ this.fileList.push(item)
242
+ this.isUpdate = true
243
+ this.updateModel()
244
+ }
245
+ })
246
+ ).then(res => {
247
+ if (this.$loading) {
248
+ this.$loading.hide()
249
+ }
250
+ }).catch((e) => {
251
+ if (this.$loading) {
252
+ this.$loading.hide()
253
+ }
254
+ })
255
+ },
256
+ removeEvent (e) {
257
+ const { tempFilePath } = e
258
+ const item = this.fileList.find(item => item.tempPath === tempFilePath)
259
+ this.selectUniFileList = this.selectUniFileList.filter(item => item.url !== tempFilePath)
260
+ this.fileList = this.fileList.filter(item => item.tempPath !== tempFilePath)
261
+ const removeMethod = this.removeFile ? this.removeFile : (globalStore.upload ? globalStore.upload.removeFile : null)
262
+ if (!item) {
263
+ console.error('删除出错!!!')
264
+ }
265
+ if (item && !item.id) {
266
+ if (removeMethod) {
267
+ removeMethod.call(this.currVM, {
268
+ item,
269
+ params: this.params
270
+ })
271
+ }
272
+ }
273
+ this.isUpdate = true
274
+ this.updateModel()
275
+ },
276
+ getUrl (item) {
277
+ const getFileMethod = this.getFileUrl ? this.getFileUrl : (globalStore.upload ? globalStore.upload.getFileUrl : null)
278
+ if (getFileMethod) {
279
+ return getFileMethod.call(this.currVM, {
280
+ item,
281
+ params: this.params
282
+ })
283
+ }
284
+ return item[this.urlField]
285
+ },
286
+ getUrlName (url) {
287
+ const urlRest = XEUtils.parseUrl(url)
288
+ return urlRest.pathname.split('/').slice(-1)[0] || ''
289
+ },
290
+ getSuffix (filename) {
291
+ const pos = filename.lastIndexOf('.')
292
+ let suffix = ''
293
+ if (pos !== -1) {
294
+ suffix = filename.substring(pos + 1)
295
+ }
296
+ return suffix
297
+ },
298
+ previewEvent (item, index) {
299
+ if (this.previewStatus) {
300
+ return
301
+ }
302
+ this.previewStatus = true
303
+ Promise.all(
304
+ this.value.map(item => {
305
+ return new Promise((resolve) => {
306
+ uni.downloadFile({
307
+ url: this.getUrl(item),
308
+ success: (downRes) => {
309
+ resolve({
310
+ url: downRes.tempFilePath
311
+ })
312
+ },
313
+ fail () {
314
+ resolve({
315
+ url: ''
316
+ })
317
+ }
318
+ })
319
+ })
320
+ })
321
+ ).then(res => {
322
+ uni.previewImage({
323
+ current: index,
324
+ urls: res.map(item => item.url)
325
+ })
326
+ this.previewStatus = false
327
+ })
328
+ },
329
+ previewImg (item) {
330
+ uni.downloadFile({
331
+ url: this.getUrl(item),
332
+ success: (downRes) => {
333
+ uni.previewImage({
334
+ urls: [
335
+ downRes.tempFilePath
336
+ ],
337
+ longPressActions: {
338
+ itemList: ['保存图片']
339
+ }
340
+ })
341
+ }
342
+ })
343
+ },
344
+ downloadEvent (item) {
345
+ uni.downloadFile({
346
+ url: this.getUrl(item),
347
+ success: (downRes) => {
348
+ // 仅支持类型
349
+ if (['doc', 'xls', 'ppt', 'pdf', 'docx', 'xlsx', 'pptx'].includes(item[this.typeField])) {
350
+ uni.openDocument({
351
+ filePath: downRes.tempFilePath,
352
+ showMenu: true,
353
+ success (saveRes) {
354
+ },
355
+ fail () {
356
+ uni.showModal({
357
+ content: '打开失败',
358
+ showCancel: false
359
+ });
360
+ }
361
+ })
362
+ } else if (['png', 'jpg'].includes(item[this.typeField])) {
363
+ this.previewImg(item)
364
+ } else {
365
+ uni.saveFile({
366
+ tempFilePath: downRes.tempFilePath,
367
+ success: function(res) {
368
+ uni.showToast({
369
+ icon: 'none',
370
+ mask: true,
371
+ title: '文件已保存:' + res.savedFilePath, //保存路径
372
+ duration: 3000,
373
+ })
374
+ }
375
+ })
376
+
377
+ }
378
+ },
379
+ fail () {
380
+ uni.showModal({
381
+ content: '下载失败',
382
+ showCancel: false
383
+ });
384
+ }
385
+ })
386
+ },
387
+ chooseImage () {
388
+ const uploadMethod = this.uploadFile ? this.uploadFile : (globalStore.upload ? globalStore.upload.uploadFile : null)
389
+ uploadImageFiles({}).then(res => {
390
+ const { tempFiles } = res
391
+ debugger
392
+ Promise.all(
393
+ tempFiles.map(file => {
394
+ const fileSuffix = this.getSuffix(file.name)
395
+ if (uploadMethod) {
396
+ return Promise.resolve(
397
+ uploadMethod.call(this.currVM, {
398
+ file,
399
+ params: this.params
400
+ })
401
+ ).then(res => {
402
+ return {
403
+ ...res,
404
+ [this.nameField]: res[this.nameField] || file.name,
405
+ [this.typeField]: res[this.typeField] || fileSuffix,
406
+ tempPath: file.path
407
+ }
408
+ })
409
+ }
410
+ return {
411
+ [this.nameField]: file.name,
412
+ [this.typeField]: file.extname,
413
+ [this.urlField]: file.path,
414
+ tempPath: file.path
415
+ }
416
+ })
417
+ ).then(list => {
418
+ this.selectUniFileList.push(...list)
419
+ this.fileList.push(...list)
420
+ this.isUpdate = true
421
+ this.updateModel()
422
+ debugger
423
+ }).catch((e) => {
424
+ debugger
425
+ })
426
+ })
427
+ },
428
+ chooseFile () {
429
+ const uploadMethod = this.uploadFile ? this.uploadFile : (globalStore.upload ? globalStore.upload.uploadFile : null)
430
+ uploadImageFiles({}).then(res => {
431
+ const { tempFiles } = res
432
+ debugger
433
+ Promise.all(
434
+ tempFiles.map(file => {
435
+ const fileSuffix = this.getSuffix(file.name)
436
+ if (uploadMethod) {
437
+ return Promise.resolve(
438
+ uploadMethod.call(this.currVM, {
439
+ file,
440
+ params: this.params
441
+ })
442
+ ).then(res => {
443
+ return {
444
+ ...res,
445
+ [this.nameField]: res[this.nameField] || file.name,
446
+ [this.typeField]: res[this.typeField] || fileSuffix,
447
+ tempPath: file.path
448
+ }
449
+ })
450
+ }
451
+ return {
452
+ [this.nameField]: file.name,
453
+ [this.typeField]: file.extname,
454
+ [this.urlField]: file.path,
455
+ tempPath: file.path
456
+ }
457
+ })
458
+ ).then(list => {
459
+ this.selectUniFileList.push(...list)
460
+ this.fileList.push(...list)
461
+ this.isUpdate = true
462
+ this.updateModel()
463
+ debugger
464
+ }).catch((e) => {
465
+ debugger
466
+ })
467
+ })
468
+ }
469
+ }
470
+ }
471
+ </script>
472
+
473
+ <style lang="scss">
474
+ .ml-upload{
475
+ margin: 20rpx 0;
476
+ background: #fff;
477
+ }
478
+ .ml-upload-image-list {
479
+ display: flex;
480
+ flex-direction: row;
481
+ flex-wrap: wrap;
482
+ .ml-upload-image-item,
483
+ .ml-upload-image-add {
484
+ position: relative;
485
+ width: 100rpx;
486
+ height: 100rpx;
487
+ margin: 20rpx;
488
+ }
489
+ .ml-upload-image-del-btn {
490
+ position: absolute;
491
+ right: 0;
492
+ top: 0;
493
+ border-radius: 50%;
494
+ }
495
+ .ml-upload-image-img {
496
+ border-radius: $ml-border-radius;
497
+ }
498
+ }
499
+ .ml-upload-file-list {
500
+ .ml-upload-file-item {
501
+ display: block;
502
+ }
503
+ .ml-upload-file-icon {
504
+ flex-shrink: 0;
505
+ }
506
+ .ml-upload-file-info {
507
+ flex-grow: 1;
508
+ .ml-upload-file-name {
509
+ overflow: hidden;
510
+ text-overflow: ellipsis;
511
+ white-space: nowrap;
512
+ }
513
+ }
514
+ .ml-upload-file-add-btn {
515
+ display: flex;
516
+ flex-direction: row;
517
+ }
518
+ }
519
+ </style>
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <view class="ml-list-item" :class="[className || '', itemType ? `type-${itemType}` : '', {'is-padding': padding, 'is-vertical': itemVertical}]" :style="styles" @click="clickEvent" @tap="tapEvent">
2
+ <view class="ml-list-item" :class="[className || '', itemType ? `type-${itemType}` : '', {'is-padding': padding, 'is-vertical': itemVertical, 'is-disabled': disabled}]" :style="styles" @click="clickEvent" @tap="tapEvent">
3
3
  <view v-if="itemType === 'checkbox'" class="ml-list-checkbox-icon">
4
4
  <ml-checkbox :value="hasCheckedChecked" :disabled="disabled"></ml-checkbox>
5
5
  </view>
@@ -155,6 +155,12 @@ export default {
155
155
  padding: 20rpx;
156
156
  border-radius: $ml-border-radius;
157
157
  background: #ffffff;
158
+ &.is-disabled {
159
+ opacity: 0.5;
160
+ // #ifdef H5
161
+ cursor: no-drop;
162
+ // #endif
163
+ }
158
164
  &.is-padding {
159
165
  margin-bottom: 20rpx;
160
166
  }
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <view class="ml-list-menu-item" :class="[className || '', itemType ? `type-${itemType}` : '', {'is-vertical': itemVertical}]" @click="clickEvent" @tap="tapEvent">
2
+ <view class="ml-list-menu-item" :class="[className || '', itemType ? `type-${itemType}` : '', {'is-vertical': itemVertical, 'is-disabled': disabled}]" @click="clickEvent" @tap="tapEvent">
3
3
  <view v-if="itemType === 'checkbox'" class="ml-list-menu-checkbox-icon">
4
4
  <ml-checkbox :value="hasCheckedChecked" :disabled="disabled"></ml-checkbox>
5
5
  </view>
@@ -157,6 +157,12 @@ export default {
157
157
  font-size: 30rpx;
158
158
  padding: 10rpx 20rpx;
159
159
  background: #ffffff;
160
+ &.is-disabled {
161
+ opacity: 0.5;
162
+ // #ifdef H5
163
+ cursor: no-drop;
164
+ // #endif
165
+ }
160
166
  &:first-child {
161
167
  border-top: 1px solid #e5e5e5;
162
168
  }