jufubao-forms 1.0.3 → 1.0.4-beta1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jufubao-forms",
3
- "version": "1.0.3",
3
+ "version": "1.0.4-beta1",
4
4
  "private": false,
5
5
  "description": "聚福宝表单业务插件库",
6
6
  "main": "index.js",
@@ -63,4 +63,14 @@ module.exports = [
63
63
  isConsole: true,
64
64
  disabled: true,
65
65
  },
66
+ {
67
+ mapFnName: "getConOssSign",
68
+ title: "获取上传参数",
69
+ path: "/common-user/v1/h5-oss/sign",
70
+ isRule: false,
71
+ data: {
72
+ },
73
+ isConsole: true,
74
+ disabled: true,
75
+ },
66
76
  ];
@@ -81,6 +81,34 @@
81
81
  @change="e => handleDateTimePicker(e, item)">
82
82
  </uni-datetime-picker>
83
83
  </template>
84
+ <template v-if="item.field_type === 'media'">
85
+ <view v-if="item.validate_type==='image'" class="img_list">
86
+ <view class="img_box" v-for="(img, i) in form[item.field_value]" :key="i">
87
+ <image :src="getServiceUrl(img)" class="img_item" mode="aspectFit" @click="handlePreview(i)"></image>
88
+ <view class="close_box" @click.stop="removeMedia(item, i)">
89
+ <view class="close_box-inner">
90
+ <xd-font-icon icon="iconguanbi" color="#333333" size="28"></xd-font-icon>
91
+ </view>
92
+ </view>
93
+ </view>
94
+ <view v-if="form[item.field_value].length < item.media_count" class="img_box img_add" @click="doAddImage(item)">
95
+ <view class="icon">+</view>
96
+ </view>
97
+ </view>
98
+ <view v-else-if="item.validate_type==='video'" class="img_list">
99
+ <view class="img_box" v-for="(videoSrc, i) in form[item.field_value]" :key="i">
100
+ <video style="width: 100%;height: 100%;" :src="getServiceUrl(videoSrc)"></video>
101
+ <view class="close_box" @click.stop="removeMedia(item, i)">
102
+ <view class="close_box-inner">
103
+ <xd-font-icon icon="iconguanbi" color="#333333" size="28"></xd-font-icon>
104
+ </view>
105
+ </view>
106
+ </view>
107
+ <view v-if="showUploadVideos.length < item.media_count" class="img_box img_add" @click="doAddVideo(item)">
108
+ <view class="icon">+</view>
109
+ </view>
110
+ </view>
111
+ </template>
84
112
  <!-- <xd-form-date v-if="item.field_type === 'calendar'"
85
113
  v-model="form[item.field_value]"
86
114
  :type="item.validate_type"
@@ -199,6 +227,8 @@
199
227
  loaded: false,
200
228
  isPreview: false,
201
229
  emptyImage: getServiceUrl('/common/empty/qa.png'),
230
+ uploadImgList: [],
231
+ uploadVideoList: [],
202
232
 
203
233
  //面板
204
234
  submitPagePath: "",
@@ -222,6 +252,12 @@
222
252
  },
223
253
  bucket(){
224
254
  return this.formBe == 1 ? 'default' : 'saas';
255
+ },
256
+ showUploadImages(){
257
+ return this.uploadImgList.map(item => getServiceUrl(item))
258
+ },
259
+ showUploadVideos(){
260
+ return this.uploadVideoList.map(item => getServiceUrl(item))
225
261
  }
226
262
  },
227
263
  watch: {
@@ -238,6 +274,7 @@
238
274
  //todo
239
275
  },
240
276
  methods: {
277
+ getServiceUrl,
241
278
  onJfbLoad(options) {
242
279
  if (!this.isPreview){
243
280
  if(!options.form_id) {
@@ -302,6 +339,8 @@
302
339
 
303
340
  if(limit.showDefaultValue){
304
341
  this.form[item.field_value] = item.default;
342
+ }else{
343
+ this.form[item.field_value] = "";
305
344
  }
306
345
  }catch(e){}
307
346
  }else if(item.default){
@@ -333,6 +372,12 @@
333
372
  }
334
373
  }catch(e){}
335
374
  }
375
+ if(item.field_type === 'media'){
376
+ let mediaRule = JSON.parse(item.validate_rules);
377
+ item['media_size'] = mediaRule['media_size'];
378
+ item['media_count'] = mediaRule['media_count'];
379
+ this.$set(this.form, item.field_value, [])
380
+ }
336
381
  console.log(item, "item")
337
382
  return item;
338
383
  });
@@ -343,6 +388,16 @@
343
388
  this.$xdHideLoading();
344
389
  })
345
390
  },
391
+ /**
392
+ * @description 监听事件变化
393
+ * @param container {object} 业务组件对象自己
394
+ */
395
+ init(container) {
396
+ this.submitPagePath = getContainerPropsValue(container, 'content.submitPagePath', {value: ""}).value;
397
+ this.formBe = getContainerPropsValue(container, 'content.formBe', '1');
398
+ this.qaListPath = getContainerPropsValue(container, 'content.qaListPath', {value: ""}).value;
399
+ // this.description = getContainerPropsValue(container, 'content.description', "");
400
+ },
346
401
  setFieldItemTop(){
347
402
  const query = uni.createSelectorQuery().in(this);
348
403
  this.dynamicFormList = this.dynamicFormList.map(item => {
@@ -401,15 +456,104 @@
401
456
  let valid_token = this.$xdUniHelper.randomChar(20);
402
457
  this.valid_token = valid_token;
403
458
  },
404
- /**
405
- * @description 监听事件变化
406
- * @param container {object} 业务组件对象自己
407
- */
408
- init(container) {
409
- this.submitPagePath = getContainerPropsValue(container, 'content.submitPagePath', {value: ""}).value;
410
- this.formBe = getContainerPropsValue(container, 'content.formBe', '1');
411
- this.qaListPath = getContainerPropsValue(container, 'content.qaListPath', {value: ""}).value;
412
- // this.description = getContainerPropsValue(container, 'content.description', "");
459
+ removeMedia(item, i){
460
+ this.form[item.field_value].splice(i, 1);
461
+ },
462
+ doAddImage(item){
463
+ uni.chooseImage({
464
+ count: 1,
465
+ sourceType: ['camera'],
466
+ success: async (res) => {
467
+ console.log('chooseImage',res);
468
+ // let filePath = res.tempFilePaths[0];
469
+ let file = res.tempFiles[0];
470
+ //文件file不能大于item.media_size(MB)
471
+ if(file.size > item.media_size * 1024 * 1024){
472
+ uni.showToast({
473
+ title: '图片大小不能超过' + item.media_size + 'MB',
474
+ duration: 2000,
475
+ icon: "none"
476
+ });
477
+ return;
478
+ }
479
+ this.$xdShowLoading({});
480
+ try{
481
+ let image = await this.uploadImage(file);
482
+ this.form[item.field_value].push(image);
483
+ this.handleClearError(item);
484
+ this.$xdHideLoading();
485
+ }catch(err){
486
+ this.$xdHideLoading();
487
+ }
488
+ }
489
+ })
490
+ },
491
+ doAddVideo(item){
492
+ uni.chooseVideo({
493
+ sourceType: ['album', 'camera'],
494
+ success: async (res) => {
495
+ console.log('chooseVideo',res);
496
+ let file = res.tempFile;
497
+ if(file.size > item.media_size * 1024 * 1024){
498
+ uni.showToast({
499
+ title: '视频大小不能超过' + item.media_size + 'MB',
500
+ duration: 2000,
501
+ icon: "none"
502
+ });
503
+ return;
504
+ }
505
+ this.$xdShowLoading({});
506
+ try{
507
+ let video = await this.uploadImage(file);
508
+ this.form[item.field_value].push(video);
509
+ this.handleClearError(item);
510
+ this.$xdHideLoading();
511
+ }catch(err){
512
+ this.$xdHideLoading();
513
+ }
514
+ }
515
+ })
516
+ },
517
+ uploadImage(file){
518
+ let fileName = file.name;
519
+ return new Promise((resolve, reject) => {
520
+ jfbRootExec("getConOssSign", {
521
+ vm: this,
522
+ data: { name: fileName }
523
+ }).then(res => {
524
+ let OSSAccessKeyId = res['id']
525
+ let cdnUrl = res['cdn_url']
526
+ delete res['id']
527
+ delete res['cdn_url']
528
+ uni.uploadFile({
529
+ url: res.action,
530
+ file: file,
531
+ name: 'file',
532
+ formData: {
533
+ ...res,
534
+ OSSAccessKeyId: OSSAccessKeyId,
535
+ name: fileName,
536
+ cdnUrl: cdnUrl,
537
+ success_action_status: 200
538
+ },
539
+ success: (r) => {
540
+ resolve(`/${res.key}`);
541
+ },
542
+ fail:(err)=>{
543
+ resolve('');
544
+ console.error(err)
545
+ }
546
+ });
547
+ }).catch(err => {
548
+ reject(err);
549
+ })
550
+ })
551
+ },
552
+ handlePreview(i){
553
+ uni.previewImage({
554
+ current: i,
555
+ urls: this.showUploadImages
556
+ })
413
557
  },
414
558
  handleClearError(item){
415
559
  this.$set(item, "error", "")
@@ -477,28 +621,23 @@
477
621
  item.error = "";
478
622
  let fieldValue = this.form[item.field_value];
479
623
  console.log(fieldValue, "fieldValue")
480
-
481
- if(item.required && !fieldValue){
482
- let errTip = "";
483
- if(item.field_type === 'text' || item.field_type === 'textarea'){
484
- errTip = "请填写" + item.field_name;
485
- }else{
624
+ let errTip = "";
625
+ if(item.required){
626
+ if(fieldValue === undefined || fieldValue === null || fieldValue === ''){
627
+ if(item.field_type === 'text' || item.field_type === 'textarea'){
628
+ errTip = "请填写" + item.field_name;
629
+ }else{
630
+ errTip = "请选择" + item.field_name;
631
+ }
632
+ } else if(Array.isArray(fieldValue) && fieldValue.length === 0){
486
633
  errTip = "请选择" + item.field_name;
487
634
  }
635
+ } else if(item.field_type === 'text'){
636
+ errTip = this.validFromText(item, fieldValue);
637
+ }
638
+ if(errTip) {
488
639
  item.error = errTip;
489
640
  err_arr.push(item);
490
- }else if(item.required && item.field_type === 'select'){
491
- if(fieldValue === '' || fieldValue.length == 0){
492
- let errTip = "请选择" + item.field_name;
493
- item.error = errTip;
494
- err_arr.push(item);
495
- }
496
- }else if(item.field_type === 'text'){
497
- let errTip = this.validFromText(item, fieldValue);
498
- if(errTip) {
499
- item.error = errTip;
500
- err_arr.push(item);
501
- }
502
641
  }
503
642
  })
504
643
  console.log(this.dynamicForm);
@@ -732,7 +871,56 @@
732
871
  }
733
872
  }
734
873
  }
874
+ .img_list{
875
+ display: flex;
876
+ flex-wrap: wrap;
877
+ .img_box{
878
+ width: 200rpx;
879
+ height: 200rpx;
880
+ border-radius: 16rpx;
881
+ border: 1px solid #E0E0E0;
882
+ margin-right: 20rpx;
883
+ margin-bottom: 20rpx;
884
+ position: relative;
885
+ .close_box{
886
+ position: absolute;
887
+ top: 0;
888
+ right: 0;
889
+ padding: 10rpx;
890
+ .close_box-inner{
891
+ width: 40rpx;
892
+ height: 40rpx;
893
+ border-radius: 50%;
894
+ background-color: #FFFFFF;
895
+ display: flex;
896
+ justify-content: center;
897
+ align-items: center;
898
+ }
899
+ }
900
+ .img_item{
901
+ width: 100%;
902
+ height: 100%;
903
+ }
735
904
 
905
+ &.img_add{
906
+ display: flex;
907
+ align-items: center;
908
+ justify-content: center;
909
+ background-color: #EEEEEE;
910
+ .icon{
911
+ // border: 1px solid #E0E0E0;
912
+ width: 36rpx;
913
+ height: 36rpx;
914
+ border-radius: 6rpx;
915
+ display: flex;
916
+ align-items: center;
917
+ justify-content: center;
918
+ color: #999999;
919
+ font-size: 48rpx;
920
+ }
921
+ }
922
+ }
923
+ }
736
924
  .align-center{
737
925
  display: flex;
738
926
  align-items: center;