@10yun/cv-mobile-ui 0.5.57 → 0.5.59

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.
@@ -82,21 +82,22 @@
82
82
  </view>
83
83
  <view
84
84
  class="u-upload__deletable"
85
+ :style="iconDelStyle"
85
86
  v-if="item.status !== 'uploading' && (deletable || item.deletable)"
86
87
  @tap.stop="deleteItem(index)"
87
88
  >
88
89
  <view class="u-upload__deletable__icon">
89
- <up-icon name="close" color="#ffffff" size="10"></up-icon>
90
+ <up-icon name="close" color="#ffffff" :size="iconSize"></up-icon>
90
91
  </view>
91
92
  </view>
92
93
  <slot name="success">
93
- <view class="u-upload__success" v-if="item.status === 'success'">
94
+ <view class="u-upload__success" :style="iconSuccStyle1" v-if="item.status === 'success'">
94
95
  <!-- #ifdef APP-NVUE -->
95
96
  <image :src="successIcon" class="u-upload__success__icon"></image>
96
97
  <!-- #endif -->
97
98
  <!-- #ifndef APP-NVUE -->
98
- <view class="u-upload__success__icon">
99
- <up-icon name="checkmark" color="#ffffff" size="12"></up-icon>
99
+ <view class="u-upload__success__icon" :style="iconSuccStyle2">
100
+ <up-icon name="checkmark" color="#ffffff" :size="iconSize"></up-icon>
100
101
  </view>
101
102
  <!-- #endif -->
102
103
  </view>
@@ -158,6 +159,15 @@ import { mixin } from '../../libs/mixin/mixin';
158
159
  import { addStyle, addUnit, toast } from '../../libs/function/index';
159
160
  import test from '../../libs/function/test';
160
161
  import { t } from '../../libs/i18n';
162
+ import {
163
+ fileMimeToExtension,
164
+ checkIsObject,
165
+ generateUniqidName,
166
+ parseJsonSafe,
167
+ parseFormData,
168
+ content_to_array,
169
+ getFileInfo
170
+ } from './file.js';
161
171
  /**
162
172
  * upload 上传
163
173
  * @description 该组件用于上传图片场景
@@ -204,10 +214,18 @@ export default {
204
214
  lists: [],
205
215
  isInCount: true,
206
216
  popupShow: false,
207
- currentItemIndex: -1
217
+ currentItemIndex: -1,
218
+ localList: []
208
219
  };
209
220
  },
210
221
  watch: {
222
+ initValue: {
223
+ handler() {
224
+ this._init_parse_list();
225
+ },
226
+ immediate: true,
227
+ deep: true
228
+ },
211
229
  // 监听文件列表的变化,重新整理内部数据
212
230
  fileList: {
213
231
  handler() {
@@ -232,12 +250,60 @@ export default {
232
250
  }
233
251
  },
234
252
  // #ifdef VUE3
235
- emits: ['error', 'beforeRead', 'oversize', 'afterRead', 'delete', 'clickPreview', 'update:fileList', 'afterAutoUpload'],
253
+ emits: [
254
+ 'error',
255
+ 'beforeRead',
256
+ 'oversize',
257
+ 'afterRead',
258
+ 'delete',
259
+ 'clickPreview',
260
+ 'update:modelValue',
261
+ 'update:initValue',
262
+ 'update:fileList',
263
+ 'afterAutoUpload'
264
+ ],
236
265
  // #endif
266
+ computed: {
267
+ // 去除 单位
268
+ iconSizeNum() {
269
+ let size = this.iconSize || 0; // 空值给默认 0
270
+ // if (typeof this.iconSize === 'string' && (this.iconSize.includes('px') || this.iconSize.includes('rpx'))) {
271
+ if (typeof size === 'string') {
272
+ size = size.replace(/[^0-9.]/g, '');
273
+ }
274
+ return parseFloat(size) || 0;
275
+ },
276
+ iconDelStyle() {
277
+ return {
278
+ height: this.iconSizeNum + 4 + 'px',
279
+ width: this.iconSizeNum + 4 + 'px'
280
+ };
281
+ },
282
+ iconSuccStyle1() {
283
+ return {
284
+ 'border-width': this.iconSizeNum - 5 + 'px'
285
+ };
286
+ },
287
+ iconSuccStyle2() {
288
+ return {
289
+ bottom: -(this.iconSizeNum - 3) + 'px',
290
+ right: -(this.iconSizeNum - 3) + 'px'
291
+ };
292
+ }
293
+ },
237
294
  methods: {
238
295
  t,
239
296
  addUnit,
240
297
  addStyle,
298
+ _init_parse_list() {
299
+ if (this.initValue) {
300
+ this.localList = content_to_array(this.initValue);
301
+ } else {
302
+ this.localList = [];
303
+ }
304
+ console.log('---localList--', this.localList);
305
+ this.formatFileList();
306
+ },
241
307
  videoErrorCallback() {},
242
308
  loadedVideoMetadata(e) {
243
309
  if (this.currentItemIndex < 0) {
@@ -297,9 +363,12 @@ export default {
297
363
  })
298
364
  .exec();
299
365
  },
366
+
300
367
  formatFileList() {
301
- const { fileList = [], maxCount } = this;
302
- const lists = fileList.map((item) => {
368
+ const { fileList = [], localList = [], maxCount } = this;
369
+ const fileList2 = localList || fileList || [];
370
+ const lists = fileList2.map((item) => {
371
+ // const lists = fileList.map((item) => {
303
372
  const name = item.name || item.url || item.thumb;
304
373
  return Object.assign(Object.assign({}, item), {
305
374
  // 如果item.url为本地选择的blob文件的话,无法判断其为video还是image,此处优先通过accept做判断处理
@@ -381,6 +450,7 @@ export default {
381
450
  index: index == null ? this.fileList.length : index
382
451
  };
383
452
  },
453
+
384
454
  async onAfterRead(file) {
385
455
  const { maxSize, afterRead } = this;
386
456
  const oversize = Array.isArray(file) ? file.some((item) => item.size > maxSize) : file.size > maxSize;
@@ -426,23 +496,31 @@ export default {
426
496
  case 'upload_oss':
427
497
  // 阿里云前端直传
428
498
  // 获取签名
429
- console.log();
430
499
  let formData = {};
500
+ let save_name = generateUniqidName();
501
+ let extension = fileMimeToExtension(lists[j].type);
502
+ // console.log('---lists[j]--', lists[j]);
431
503
  let ret = await uni.request({
432
504
  url: this.autoUploadAuthUrl,
433
- method: 'get',
505
+ method: 'post',
434
506
  header: this.autoUploadHeader,
435
507
  data: {
436
- filename: lists[j].name
508
+ upload_type: 'aliyun_oss_type2',
509
+ save_sign: 'image',
510
+ filename: lists[j].name,
511
+ save_extension: extension,
512
+ save_name: save_name
437
513
  }
438
514
  });
439
515
  // console.log(ret);
440
516
  let res0 = ret.data;
517
+ let res0Param = {};
441
518
  if (res0.code == 200) {
442
519
  // 路径 + 文件名 + 扩展名
443
520
  // 不传递filename就要拼接key
444
521
  // res0.data.params.key = res0.data.params.dir + res0.data.params.uniqidName + fileExt;
445
- formData = res0.data.params;
522
+ res0Param = res0.data.params || res0.data;
523
+ formData = parseFormData(res0Param);
446
524
  } else {
447
525
  uni.showToast({
448
526
  title: res0.msg,
@@ -451,7 +529,7 @@ export default {
451
529
  return;
452
530
  }
453
531
  var uploadTask = uni.uploadFile({
454
- url: res0.data.params.host,
532
+ url: res0Param.host,
455
533
  filePath: lists[j].url,
456
534
  name: 'file',
457
535
  // fileType: 'video', // 仅支付宝小程序,且必填。
@@ -460,22 +538,33 @@ export default {
460
538
  success: (uploadFileRes) => {
461
539
  let thumb = '';
462
540
  let afterPromise = '';
541
+ let res1 = parseJsonSafe(uploadFileRes?.data || {});
463
542
  if (that.customAfterAutoUpload) {
464
543
  afterPromise = new Promise((resolve, reject) => {
544
+ let res2 = res1?.data || res1 || {};
545
+ // TODO 判断是否多图,
546
+ this.$emit('update:modelValue', res2.filelog_id || '');
547
+ this.localList.push(getFileInfo(res2.cdn_full_path));
548
+ this.formatFileList();
465
549
  that.$emit(
466
550
  'afterAutoUpload',
467
- Object.assign(res0, {
551
+ Object.assign(res2, {
468
552
  callback: (r) => {
469
553
  r.url ? resolve(r) : reject();
470
554
  }
471
555
  })
556
+ // Object.assign(res0, res1, {
557
+ // callback: (r) => {
558
+ // r.url ? resolve(r) : reject();
559
+ // }
560
+ // })
472
561
  );
473
562
  });
474
563
  }
475
564
  if (test.promise(afterPromise)) {
476
565
  afterPromise.then((data) => that.succcessUpload(len + j, data.url, data.thumb));
477
566
  } else {
478
- result = res0.data.params.host + '/' + res0.data.params.key;
567
+ result = res0Param.host + '/' + res0Param.key;
479
568
  if (that.accept === 'video' || test.video(result)) {
480
569
  thumb = result + '?x-oss-process=video/snapshot,t_10000,m_fast';
481
570
  }
@@ -581,6 +670,9 @@ export default {
581
670
  },
582
671
  deleteItem(index) {
583
672
  if (this.autoDelete) {
673
+ this.localList.splice(index, 1);
674
+ this.$emit('update:initValue', this.localList);
675
+
584
676
  this.fileList.splice(index, 1);
585
677
  this.$emit('update:fileList', this.fileList);
586
678
  } else {