Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DiDi
cube-ui
提交
148614fd
C
cube-ui
项目概览
DiDi
/
cube-ui
11 个月 前同步成功
通知
34
Star
9078
Fork
1508
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
cube-ui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
148614fd
编写于
4月 19, 2018
作者:
D
dolymood
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update(doc): upload add custom case
上级
fc590e87
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
320 addition
and
39 deletion
+320
-39
document/components/docs/zh-CN/upload.md
document/components/docs/zh-CN/upload.md
+96
-4
example/pages/upload/compress.vue
example/pages/upload/compress.vue
+63
-0
example/pages/upload/custom.vue
example/pages/upload/custom.vue
+98
-0
example/pages/upload/default.vue
example/pages/upload/default.vue
+10
-33
example/pages/upload/index.vue
example/pages/upload/index.vue
+34
-0
example/router/routes.js
example/router/routes.js
+19
-2
未找到文件。
document/components/docs/zh-CN/upload.md
浏览文件 @
148614fd
...
...
@@ -32,13 +32,20 @@
export
default
{
methods
:
{
filesAdded
(
files
)
{
let
hasIgnore
=
false
const
maxSize
=
1
*
1024
*
1024
// 1M
for
(
let
k
in
files
)
{
const
file
=
files
[
k
]
if
(
file
.
size
>
maxSize
)
{
file
.
ignore
=
true
hasIgnore
=
true
}
}
hasIgnore
&&
this
.
$createToast
({
type
:
'
warn
'
,
time
:
1000
,
txt
:
'
You selected >1M files
'
}).
show
()
}
}
}
...
...
@@ -52,18 +59,18 @@
```
html
<cube-upload
ref=
"upload
2
"
:action=
"action
2
"
ref=
"upload"
:action=
"action"
:simultaneous-uploads=
"1"
:process-file=
"processFile"
@
file-submitted=
"fileSubmitted"
/>
```
```
js
import
compress
from
'
../modules/image
'
import
compress
from
'
../
../
modules/image
'
export
default
{
data
()
{
return
{
action
2
:
{
action
:
{
target
:
'
//jsonplaceholder.typicode.com/photos/
'
,
prop
:
'
base64Value
'
}
...
...
@@ -92,6 +99,91 @@
`file-submitted`
事件则是每个文件处理完后添加到
`upload`
实例的
`files`
数组中后触发,参数就是一个处理后的文件对象。
-
自定义结构样式
使用默认插槽来实现自定义结构,在此基础上自定义样式。
```
html
<cube-upload
ref=
"upload"
v-model=
"files"
:action=
"action"
@
files-added=
"addedHandler"
@
file-error=
"errHandler"
>
<div
class=
"clear-fix"
>
<cube-upload-file
v-for=
"(file, i) in files"
:file=
"file"
:key=
"i"
></cube-upload-file>
<cube-upload-btn
:multiple=
"false"
>
<div>
<i>
+
</i>
<p>
Please click to upload ID card
</p>
</div>
</cube-upload-btn>
</div>
</cube-upload>
```
```
js
export
default
{
data
()
{
return
{
action
:
'
//jsonplaceholder.typicode.com/photos/
'
,
files
:
[]
}
},
methods
:
{
addedHandler
()
{
const
file
=
this
.
files
[
0
]
file
&&
this
.
$refs
.
upload
.
removeFile
(
file
)
},
errHandler
(
file
)
{
// const msg = file.response.message
this
.
$createToast
({
type
:
'
warn
'
,
txt
:
'
Upload fail
'
,
time
:
1000
}).
show
()
}
}
}
```
样式覆盖:
```
stylus
.cube-upload
.cube-upload-file, .cube-upload-btn
margin: 0
height: 200px
.cube-upload-file
margin: 0
+ .cube-upload-btn
margin-top: -200px
opacity: 0
.cube-upload-file-def
width: 100%
height: 100%
.cubeic-wrong
display: none
.cube-upload-btn
display: flex
align-items: center
justify-content: center
> div
text-align: center
i
display: inline-flex
align-items: center
justify-content: center
width: 50px
height: 50px
margin-bottom: 20px
font-size: 32px
line-height: 1
font-style: normal
color: #fff
background-color: #333
border-radius: 50%
```
上述示例实现的效果就是点击上传(一次只能选择一张)一张图片,此图片就会直接展示,而上传按钮本身则是不可见,覆盖在图片预览区域上。再次重新选择图片,就会移除掉上次选择的图片,重新展示新选择的图片。
### Props 配置
| 参数 | 说明 | 类型 | 默认值 | 示例 |
...
...
example/pages/upload/compress.vue
0 → 100644
浏览文件 @
148614fd
<
template
>
<cube-page
type=
"upload-view-compress"
title=
"Upload"
>
<template
slot=
"content"
>
<p>
Compress
&
Base64 upload:
</p>
<div>
<cube-upload
ref=
"upload"
:action=
"action"
:simultaneous-uploads=
"1"
:process-file=
"processFile"
@
file-submitted=
"fileSubmitted"
/>
</div>
</
template
>
</cube-page>
</template>
<
script
type=
"text/ecmascript-6"
>
import
CubePage
from
'
../../components/cube-page.vue
'
import
compress
from
'
../../modules/image
'
export
default
{
data
()
{
return
{
action
:
{
target
:
'
//jsonplaceholder.typicode.com/photos/
'
,
prop
:
'
base64Value
'
,
checkSuccess
(
res
)
{
// success
return
true
}
}
}
},
methods
:
{
processFile
(
file
,
next
)
{
compress
(
file
,
{
compress
:
{
width
:
1600
,
height
:
1600
,
quality
:
0.5
}
},
next
)
},
fileSubmitted
(
file
)
{
file
.
base64Value
=
file
.
file
.
base64
}
},
components
:
{
CubePage
}
}
</
script
>
<
style
lang=
"stylus"
rel=
"stylesheet/stylus"
>
.upload-view-compress
.content
>
p, div
margin: 20px 0
div
.cube-btn, .cube-upload
margin: 10px 0
</
style
>
example/pages/upload/custom.vue
0 → 100644
浏览文件 @
148614fd
<
template
>
<cube-page
type=
"upload-view-custom"
title=
"Upload"
>
<template
slot=
"content"
>
<p>
Use slots:
</p>
<div
class=
"upload-view-custom-main"
>
<cube-upload
ref=
"upload"
v-model=
"files"
:action=
"action"
@
files-added=
"addedHandler"
@
file-error=
"errHandler"
>
<div
class=
"clear-fix"
>
<cube-upload-file
v-for=
"(file, i) in files"
:file=
"file"
:key=
"i"
></cube-upload-file>
<cube-upload-btn
:multiple=
"false"
>
<div>
<i>
+
</i>
<p>
Please click to upload ID card
</p>
</div>
</cube-upload-btn>
</div>
</cube-upload>
</div>
</
template
>
</cube-page>
</template>
<
script
type=
"text/ecmascript-6"
>
import
CubePage
from
'
../../components/cube-page.vue
'
export
default
{
data
()
{
return
{
action
:
'
//jsonplaceholder.typicode.com/photos/
'
,
files
:
[]
}
},
methods
:
{
addedHandler
()
{
const
file
=
this
.
files
[
0
]
file
&&
this
.
$refs
.
upload
.
removeFile
(
file
)
},
errHandler
(
file
)
{
// const msg = file.response.message
this
.
$createToast
({
type
:
'
warn
'
,
txt
:
'
Upload fail
'
,
time
:
1000
}).
show
()
}
},
components
:
{
CubePage
}
}
</
script
>
<
style
lang=
"stylus"
rel=
"stylesheet/stylus"
>
.upload-view-custom
.content
>
p, div
margin: 20px 0
.upload-view-custom-main
background-color: #fff
.cube-upload
.cube-upload-file, .cube-upload-btn
margin: 0
height: 200px
.cube-upload-file
margin: 0
+ .cube-upload-btn
margin-top: -200px
opacity: 0
.cube-upload-file-def
width: 100%
height: 100%
.cubeic-wrong
display: none
.cube-upload-btn
display: flex
align-items: center
justify-content: center
> div
text-align: center
i
display: inline-flex
align-items: center
justify-content: center
width: 50px
height: 50px
margin-bottom: 20px
font-size: 32px
line-height: 1
font-style: normal
color: #fff
background-color: #333
border-radius: 50%
</
style
>
example/pages/upload.vue
→
example/pages/upload
/default
.vue
浏览文件 @
148614fd
<
template
>
<cube-page
type=
"upload-view"
title=
"Upload"
>
<cube-page
type=
"upload-view
-def
"
title=
"Upload"
>
<template
slot=
"content"
>
<p>
Normal upload(File max size 1MB):
</p>
<div>
...
...
@@ -8,35 +8,17 @@
<cube-button
@
click=
"pause"
v-else
>
Pause
</cube-button>
<cube-button
@
click=
"retry"
>
Retry
</cube-button>
</div>
<p>
Compress
&
Base64 upload:
</p>
<div>
<cube-upload
ref=
"upload2"
:action=
"action2"
:simultaneous-uploads=
"1"
:process-file=
"processFile"
@
file-submitted=
"fileSubmitted"
/>
</div>
</
template
>
</cube-page>
</template>
<
script
type=
"text/ecmascript-6"
>
import
CubePage
from
'
../components/cube-page.vue
'
import
compress
from
'
../modules/image
'
import
CubePage
from
'
../../components/cube-page.vue
'
export
default
{
data
()
{
return
{
action
:
'
//jsonplaceholder.typicode.com/photos/
'
,
action2
:
{
target
:
'
//jsonplaceholder.typicode.com/photos/
'
,
prop
:
'
base64Value
'
,
checkSuccess
(
res
)
{
// success
return
true
}
},
isUploading
:
true
}
},
...
...
@@ -53,25 +35,20 @@
this
.
$refs
.
upload
.
retry
()
},
filesAdded
(
files
)
{
let
hasIgnore
=
false
const
maxSize
=
1
*
1024
*
1024
// 1M
for
(
let
k
in
files
)
{
const
file
=
files
[
k
]
if
(
file
.
size
>
maxSize
)
{
file
.
ignore
=
true
hasIgnore
=
true
}
}
},
processFile
(
file
,
next
)
{
compress
(
file
,
{
compress
:
{
width
:
1600
,
height
:
1600
,
quality
:
0.5
}
},
next
)
},
fileSubmitted
(
file
)
{
file
.
base64Value
=
file
.
file
.
base64
hasIgnore
&&
this
.
$createToast
({
type
:
'
warn
'
,
time
:
1000
,
txt
:
'
You selected >1M files
'
}).
show
()
}
},
components
:
{
...
...
@@ -81,7 +58,7 @@
</
script
>
<
style
lang=
"stylus"
rel=
"stylesheet/stylus"
>
.upload-view
.upload-view
-def
.content
>
p, div
...
...
example/pages/upload/index.vue
0 → 100644
浏览文件 @
148614fd
<
template
>
<cube-page
type=
"upload"
title=
"Upload"
>
<div
slot=
"content"
>
<cube-button-group>
<cube-button
@
click=
"goTo('default')"
>
Default
</cube-button>
<cube-button
@
click=
"goTo('compress')"
>
Compress
</cube-button>
<cube-button
@
click=
"goTo('custom')"
>
Custom
</cube-button>
</cube-button-group>
<cube-view></cube-view>
</div>
</cube-page>
</
template
>
<
script
type=
"text/ecmascript-6"
>
import
CubePage
from
'
example/components/cube-page.vue
'
import
CubeButtonGroup
from
'
example/components/cube-button-group.vue
'
import
CubeView
from
'
example/components/cube-view.vue
'
export
default
{
components
:
{
CubePage
,
CubeButtonGroup
,
CubeView
},
methods
:
{
goTo
(
subPath
)
{
this
.
$router
.
push
(
'
/upload/
'
+
subPath
)
}
}
}
</
script
>
<
style
lang=
"stylus"
rel=
"stylesheet/stylus"
>
</
style
>
example/router/routes.js
浏览文件 @
148614fd
...
...
@@ -29,7 +29,10 @@ import IndexListDefault from '../pages/index-list/default.vue'
import
IndexListCustom
from
'
../pages/index-list/custom.vue
'
import
IndexListPullUpLoad
from
'
../pages/index-list/pull-up-load.vue
'
import
IndexListPullDownRefresh
from
'
../pages/index-list/pull-down-refresh.vue
'
import
Upload
from
'
../pages/upload.vue
'
import
Upload
from
'
../pages/upload/index.vue
'
import
UploadDefault
from
'
../pages/upload/default.vue
'
import
UploadCompress
from
'
../pages/upload/compress.vue
'
import
UploadCustom
from
'
../pages/upload/custom.vue
'
import
Validator
from
'
../pages/validator.vue
'
import
Swipe
from
'
../pages/swipe/index.vue
'
import
SwipeDefault
from
'
../pages/swipe/default.vue
'
...
...
@@ -172,7 +175,21 @@ const routes = [
},
{
path
:
'
/upload
'
,
component
:
Upload
component
:
Upload
,
children
:
[
{
path
:
'
default
'
,
component
:
UploadDefault
},
{
path
:
'
compress
'
,
component
:
UploadCompress
},
{
path
:
'
custom
'
,
component
:
UploadCustom
}
]
},
{
path
:
'
/validator
'
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录