File tree Expand file tree Collapse file tree 3 files changed +33
-18
lines changed
uview-ui/components/u-upload Expand file tree Collapse file tree 3 files changed +33
-18
lines changed Original file line number Diff line number Diff line change 2
2
"easycom" : {
3
3
"^u-(.*)" : " @/uview-ui/components/u-$1/u-$1.vue"
4
4
},
5
- "condition" : { //模式配置,仅开发期间生效
6
- "current" : 0 , //当前激活的模式(list 的索引项)
7
- "list" : [{
8
- "name" : " test" , //模式名称
9
- "path" : " pages/componentsA/select/index" , //启动页面,必选
10
- "query" : " id=1&name=2" //启动参数,在页面的onLoad函数里面得到
11
- }]
12
- },
5
+ // "condition": { //模式配置,仅开发期间生效
6
+ // "current": 0, //当前激活的模式(list 的索引项)
7
+ // "list": [{
8
+ // "name": "test", //模式名称
9
+ // "path": "pages/componentsA/select/index", //启动页面,必选
10
+ // "query": "id=1&name=2" //启动参数,在页面的onLoad函数里面得到
11
+ // }]
12
+ // },
13
13
"pages" : [
14
14
// 演示-组件
15
15
{
Original file line number Diff line number Diff line change 14
14
:percent =" item.progress" ></u-line-progress >
15
15
</view >
16
16
</view >
17
- <u-upload ref =" uUpload" :custom-btn =" customBtn" :show-upload-list =" showUploadList" :action =" action" :auto-upload =" autoUpload" :file-list =" fileList"
17
+ <u-upload :beforeUpload = " beforeUpload " ref =" uUpload" :custom-btn =" customBtn" :show-upload-list =" showUploadList" :action =" action" :auto-upload =" autoUpload" :file-list =" fileList"
18
18
:show-progress =" showProgress" :deletable =" deletable" :max-count =" maxCount" @on-list-change =" onListChange" >
19
19
<view v-if =" customBtn" slot =" addBtn" class =" slot-btn" hover-class =" slot-btn__hover" hover-stay-time =" 150" >
20
20
<u-icon name =" photo" size =" 60" :color =" $u.color['lightColor']" ></u-icon >
53
53
export default {
54
54
data () {
55
55
return {
56
- action: ' http://192.168.100.17/index.php/index/index/upload ' ,
56
+ action: ' http://www.tp5.com ' ,
57
57
// 预置上传列表
58
58
fileList: [],
59
59
// fileList: [{
70
70
maxCount: 2 ,
71
71
lists: [], // 组件内部的文件列表
72
72
}
73
+ },
74
+ onLoad () {
75
+
73
76
},
74
77
methods: {
75
78
reUpload () {
136
139
onListChange (lists ) {
137
140
// console.log('onListChange', lists);
138
141
this .lists = lists;
142
+ },
143
+ beforeUpload (index , lists ) {
144
+ return true ;
139
145
}
140
146
}
141
147
}
Original file line number Diff line number Diff line change @@ -334,7 +334,7 @@ export default {
334
334
this .uploadFile (index);
335
335
},
336
336
// 上传图片
337
- uploadFile (index = 0 ) {
337
+ async uploadFile (index = 0 ) {
338
338
if (this .disabled ) return ;
339
339
if (this .uploading ) return ;
340
340
// 全部上传完成
@@ -353,13 +353,22 @@ export default {
353
353
return ;
354
354
}
355
355
// 执行before-upload钩子
356
- // if(this.beforeUpload && typeof(this.beforeUpload) === 'function') {
357
- // let beforeResponse = this.beforeUpload(index, this.lists);
358
- // if (beforeResponse && beforeResponse.then) {
359
-
360
- // }
361
- // }
362
-
356
+ if (this .beforeUpload && typeof (this .beforeUpload ) === ' function' ) {
357
+ // 执行回调,同时传入索引和文件列表当作参数
358
+ let beforeResponse = this .beforeUpload (index, this .lists );
359
+ // 判断是否返回了promise
360
+ if (!! beforeResponse && typeof beforeResponse .then === ' function' ) {
361
+ await beforeResponse .then (res => {
362
+ // promise返回成功,不进行动作,继续上传
363
+ }).catch (err => {
364
+ // 进入catch回调的话,继续下一张
365
+ return this .uploadFile (index + 1 );
366
+ })
367
+ } else if (beforeResponse === false ) {
368
+ // 如果返回false,继续下一张图片的上传
369
+ return this .uploadFile (index + 1 );
370
+ }
371
+ }
363
372
this .lists [index].error = false ;
364
373
this .uploading = true ;
365
374
// 创建上传对象
You can’t perform that action at this time.
0 commit comments