Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
U
uview-ui
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李晖
uview-ui
Commits
c2f3c8da
Commit
c2f3c8da
authored
Jun 21, 2020
by
wlxuqu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增upload组件的before-upload钩子
parent
4ed03bb8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
18 deletions
+33
-18
pages.json
pages.json
+8
-8
index.vue
pages/componentsB/upload/index.vue
+8
-2
u-upload.vue
uview-ui/components/u-upload/u-upload.vue
+17
-8
No files found.
pages.json
View file @
c2f3c8da
...
@@ -2,14 +2,14 @@
...
@@ -2,14 +2,14 @@
"easycom"
:
{
"easycom"
:
{
"^u-(.*)"
:
"@/uview-ui/components/u-$1/u-$1.vue"
"^u-(.*)"
:
"@/uview-ui/components/u-$1/u-$1.vue"
},
},
"condition"
:
{
//模式配置,仅开发期间生效
//
"condition"
:
{
//模式配置,仅开发期间生效
"current"
:
0
,
//当前激活的模式(list
的索引项)
//
"current"
:
0
,
//当前激活的模式(list
的索引项)
"list"
:
[{
//
"list"
:
[{
"name"
:
"test"
,
//模式名称
//
"name"
:
"test"
,
//模式名称
"path"
:
"pages/componentsA/select/index"
,
//启动页面,必选
//
"path"
:
"pages/componentsA/select/index"
,
//启动页面,必选
"query"
:
"id=1&name=2"
//启动参数,在页面的onLoad函数里面得到
//
"query"
:
"id=1&name=2"
//启动参数,在页面的onLoad函数里面得到
}]
//
}]
},
//
},
"pages"
:
[
"pages"
:
[
//
演示-组件
//
演示-组件
{
{
...
...
pages/componentsB/upload/index.vue
View file @
c2f3c8da
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
:percent=
"item.progress"
></u-line-progress>
:percent=
"item.progress"
></u-line-progress>
</view>
</view>
</view>
</view>
<u-upload
ref=
"uUpload"
:custom-btn=
"customBtn"
:show-upload-list=
"showUploadList"
:action=
"action"
:auto-upload=
"autoUpload"
:file-list=
"fileList"
<u-upload
:beforeUpload=
"beforeUpload"
ref=
"uUpload"
:custom-btn=
"customBtn"
:show-upload-list=
"showUploadList"
:action=
"action"
:auto-upload=
"autoUpload"
:file-list=
"fileList"
:show-progress=
"showProgress"
:deletable=
"deletable"
:max-count=
"maxCount"
@
on-list-change=
"onListChange"
>
:show-progress=
"showProgress"
:deletable=
"deletable"
:max-count=
"maxCount"
@
on-list-change=
"onListChange"
>
<view
v-if=
"customBtn"
slot=
"addBtn"
class=
"slot-btn"
hover-class=
"slot-btn__hover"
hover-stay-time=
"150"
>
<view
v-if=
"customBtn"
slot=
"addBtn"
class=
"slot-btn"
hover-class=
"slot-btn__hover"
hover-stay-time=
"150"
>
<u-icon
name=
"photo"
size=
"60"
:color=
"$u.color['lightColor']"
></u-icon>
<u-icon
name=
"photo"
size=
"60"
:color=
"$u.color['lightColor']"
></u-icon>
...
@@ -53,7 +53,7 @@
...
@@ -53,7 +53,7 @@
export
default
{
export
default
{
data
()
{
data
()
{
return
{
return
{
action
:
'
http://
192.168.100.17/index.php/index/index/upload
'
,
action
:
'
http://
www.tp5.com
'
,
// 预置上传列表
// 预置上传列表
fileList
:
[],
fileList
:
[],
// fileList: [{
// fileList: [{
...
@@ -70,6 +70,9 @@
...
@@ -70,6 +70,9 @@
maxCount
:
2
,
maxCount
:
2
,
lists
:
[],
// 组件内部的文件列表
lists
:
[],
// 组件内部的文件列表
}
}
},
onLoad
()
{
},
},
methods
:
{
methods
:
{
reUpload
()
{
reUpload
()
{
...
@@ -136,6 +139,9 @@
...
@@ -136,6 +139,9 @@
onListChange
(
lists
)
{
onListChange
(
lists
)
{
// console.log('onListChange', lists);
// console.log('onListChange', lists);
this
.
lists
=
lists
;
this
.
lists
=
lists
;
},
beforeUpload
(
index
,
lists
)
{
return
true
;
}
}
}
}
}
}
...
...
uview-ui/components/u-upload/u-upload.vue
View file @
c2f3c8da
...
@@ -334,7 +334,7 @@ export default {
...
@@ -334,7 +334,7 @@ export default {
this
.
uploadFile
(
index
);
this
.
uploadFile
(
index
);
},
},
// 上传图片
// 上传图片
uploadFile
(
index
=
0
)
{
async
uploadFile
(
index
=
0
)
{
if
(
this
.
disabled
)
return
;
if
(
this
.
disabled
)
return
;
if
(
this
.
uploading
)
return
;
if
(
this
.
uploading
)
return
;
// 全部上传完成
// 全部上传完成
...
@@ -353,13 +353,22 @@ export default {
...
@@ -353,13 +353,22 @@ export default {
return
;
return
;
}
}
// 执行before-upload钩子
// 执行before-upload钩子
// if(this.beforeUpload && typeof(this.beforeUpload) === 'function') {
if
(
this
.
beforeUpload
&&
typeof
(
this
.
beforeUpload
)
===
'
function
'
)
{
// let beforeResponse = this.beforeUpload(index, this.lists);
// 执行回调,同时传入索引和文件列表当作参数
// if (beforeResponse && beforeResponse.then) {
let
beforeResponse
=
this
.
beforeUpload
(
index
,
this
.
lists
);
// 判断是否返回了promise
// }
if
(
!!
beforeResponse
&&
typeof
beforeResponse
.
then
===
'
function
'
)
{
// }
await
beforeResponse
.
then
(
res
=>
{
// promise返回成功,不进行动作,继续上传
}).
catch
(
err
=>
{
// 进入catch回调的话,继续下一张
return
this
.
uploadFile
(
index
+
1
);
})
}
else
if
(
beforeResponse
===
false
)
{
// 如果返回false,继续下一张图片的上传
return
this
.
uploadFile
(
index
+
1
);
}
}
this
.
lists
[
index
].
error
=
false
;
this
.
lists
[
index
].
error
=
false
;
this
.
uploading
=
true
;
this
.
uploading
=
true
;
// 创建上传对象
// 创建上传对象
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment