add vc-upload demo
parent
c1cd8f46f0
commit
25631cf541
|
@ -0,0 +1,44 @@
|
||||||
|
import Upload from '../index'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
render () {
|
||||||
|
const uploaderProps = {
|
||||||
|
props: {
|
||||||
|
action: '/upload.do',
|
||||||
|
multiple: true,
|
||||||
|
beforeUpload (file, fileList) {
|
||||||
|
console.log(file, fileList)
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
console.log('start check')
|
||||||
|
setTimeout(() => {
|
||||||
|
console.log('check finshed')
|
||||||
|
resolve(file)
|
||||||
|
}, 3000)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
on: {
|
||||||
|
start: (file) => {
|
||||||
|
console.log('onStart', file.name)
|
||||||
|
},
|
||||||
|
success (file) {
|
||||||
|
console.log('onSuccess', file)
|
||||||
|
},
|
||||||
|
error (err) {
|
||||||
|
console.log('onError', err)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
margin: '100px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<Upload {...uploaderProps}><a>开始上传</a></Upload>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
import Upload from '../index'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
render () {
|
||||||
|
const uploaderProps = {
|
||||||
|
props: {
|
||||||
|
action: '/upload.do',
|
||||||
|
type: 'drag',
|
||||||
|
accept: '.png',
|
||||||
|
beforeUpload (file) {
|
||||||
|
console.log('beforeUpload', file.name)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
on: {
|
||||||
|
start: (file) => {
|
||||||
|
console.log('onStart', file.name)
|
||||||
|
},
|
||||||
|
success (file) {
|
||||||
|
console.log('onSuccess', file)
|
||||||
|
},
|
||||||
|
progress (step, file) {
|
||||||
|
console.log('onProgress', Math.round(step.percent), file.name)
|
||||||
|
},
|
||||||
|
error (err) {
|
||||||
|
console.log('onError', err)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
style: { display: 'inline-block', width: '200px', height: '200px', background: '#eee' },
|
||||||
|
}
|
||||||
|
return <Upload {...uploaderProps}></Upload>
|
||||||
|
},
|
||||||
|
}
|
|
@ -0,0 +1,105 @@
|
||||||
|
import Upload from '../index'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
destroyed: false,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
destroy () {
|
||||||
|
this.destroyed = true
|
||||||
|
},
|
||||||
|
},
|
||||||
|
render () {
|
||||||
|
if (this.destroyed) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
const propsObj = {
|
||||||
|
action: '/upload.do',
|
||||||
|
data: { a: 1, b: 2 },
|
||||||
|
headers: {
|
||||||
|
Authorization: 'xxxxxxx',
|
||||||
|
},
|
||||||
|
multiple: true,
|
||||||
|
beforeUpload (file) {
|
||||||
|
console.log('beforeUpload', file.name)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
const propsEvent = {
|
||||||
|
start: (file) => {
|
||||||
|
console.log('onStart', file.name)
|
||||||
|
// this.refs.inner.abort(file);
|
||||||
|
},
|
||||||
|
success (file) {
|
||||||
|
console.log('onSuccess', file)
|
||||||
|
},
|
||||||
|
progress (step, file) {
|
||||||
|
console.log('onProgress', Math.round(step.percent), file.name)
|
||||||
|
},
|
||||||
|
error (err) {
|
||||||
|
console.log('onError', err)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
const uploaderProps = {
|
||||||
|
props: {
|
||||||
|
...propsObj,
|
||||||
|
},
|
||||||
|
on: {
|
||||||
|
...propsEvent,
|
||||||
|
},
|
||||||
|
ref: 'inner',
|
||||||
|
}
|
||||||
|
const uploaderProps1 = {
|
||||||
|
props: {
|
||||||
|
...propsObj,
|
||||||
|
componentTag: 'div',
|
||||||
|
},
|
||||||
|
on: {
|
||||||
|
...propsEvent,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
const style = `
|
||||||
|
.rc-upload-disabled {
|
||||||
|
opacity:0.5;
|
||||||
|
`
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
margin: '100px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<h2>固定位置</h2>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
{style}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<Upload {...uploaderProps}><a>开始上传</a></Upload>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h2>滚动</h2>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
height: '200px',
|
||||||
|
overflow: 'auto',
|
||||||
|
border: '1px solid red',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
height: '500px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Upload {...uploaderProps1} style={{ display: 'inline-block' }}>
|
||||||
|
<a>开始上传2</a></Upload>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button onClick={this.destroy}>destroy</button>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
|
}
|
|
@ -6,9 +6,10 @@ import getUid from './uid'
|
||||||
import attrAccept from './attr-accept'
|
import attrAccept from './attr-accept'
|
||||||
|
|
||||||
const upLoadPropTypes = {
|
const upLoadPropTypes = {
|
||||||
component: PropTypes.string,
|
componentTag: PropTypes.string,
|
||||||
// style: PropTypes.object,
|
// style: PropTypes.object,
|
||||||
prefixCls: PropTypes.string,
|
prefixCls: PropTypes.string,
|
||||||
|
action: PropTypes.string,
|
||||||
// className: PropTypes.string,
|
// className: PropTypes.string,
|
||||||
multiple: PropTypes.bool,
|
multiple: PropTypes.bool,
|
||||||
disabled: PropTypes.bool,
|
disabled: PropTypes.bool,
|
||||||
|
@ -163,24 +164,32 @@ const AjaxUploader = {
|
||||||
},
|
},
|
||||||
render () {
|
render () {
|
||||||
const {
|
const {
|
||||||
component: Tag, prefixCls, disabled, multiple, accept,
|
componentTag: Tag, prefixCls, disabled, multiple, accept,
|
||||||
} = this.$props
|
} = this.$props
|
||||||
const cls = classNames({
|
const cls = classNames({
|
||||||
[prefixCls]: true,
|
[prefixCls]: true,
|
||||||
[`${prefixCls}-disabled`]: disabled,
|
[`${prefixCls}-disabled`]: disabled,
|
||||||
})
|
})
|
||||||
const events = disabled ? {} : {
|
const events = disabled ? {} : {
|
||||||
onClick: this.onClick,
|
click: this.onClick,
|
||||||
onKeydown: this.onKeyDown,
|
keydown: this.onKeyDown,
|
||||||
onDrop: this.onFileDrop,
|
drop: this.onFileDrop,
|
||||||
onDragover: this.onFileDrop,
|
dragover: this.onFileDrop,
|
||||||
tabIndex: '0',
|
}
|
||||||
|
const tagProps = {
|
||||||
|
on: {
|
||||||
|
...events,
|
||||||
|
...this.$listeners,
|
||||||
|
},
|
||||||
|
attrs: {
|
||||||
|
role: 'button',
|
||||||
|
tabIndex: disabled ? null : '0',
|
||||||
|
},
|
||||||
|
class: cls,
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<Tag
|
<Tag
|
||||||
{...events}
|
{...tagProps}
|
||||||
class={cls}
|
|
||||||
role='button'
|
|
||||||
>
|
>
|
||||||
<input
|
<input
|
||||||
type='file'
|
type='file'
|
||||||
|
|
|
@ -17,7 +17,7 @@ const IFRAME_STYLE = {
|
||||||
const IframeUploader = {
|
const IframeUploader = {
|
||||||
mixins: [BaseMixin],
|
mixins: [BaseMixin],
|
||||||
props: {
|
props: {
|
||||||
component: PropTypes.string,
|
componentTag: PropTypes.string,
|
||||||
// style: PropTypes.object,
|
// style: PropTypes.object,
|
||||||
disabled: PropTypes.bool,
|
disabled: PropTypes.bool,
|
||||||
prefixCls: PropTypes.string,
|
prefixCls: PropTypes.string,
|
||||||
|
@ -242,7 +242,7 @@ const IframeUploader = {
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const {
|
const {
|
||||||
component: Tag, disabled,
|
componentTag: Tag, disabled,
|
||||||
prefixCls,
|
prefixCls,
|
||||||
} = this.$props
|
} = this.$props
|
||||||
const iframeStyle = {
|
const iframeStyle = {
|
||||||
|
@ -253,6 +253,7 @@ const IframeUploader = {
|
||||||
[prefixCls]: true,
|
[prefixCls]: true,
|
||||||
[`${prefixCls}-disabled`]: disabled,
|
[`${prefixCls}-disabled`]: disabled,
|
||||||
})
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Tag
|
<Tag
|
||||||
className={cls}
|
className={cls}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import IframeUpload from './IframeUploader'
|
||||||
// }
|
// }
|
||||||
|
|
||||||
const uploadProps = {
|
const uploadProps = {
|
||||||
component: PropTypes.string,
|
componentTag: PropTypes.string,
|
||||||
prefixCls: PropTypes.string,
|
prefixCls: PropTypes.string,
|
||||||
action: PropTypes.string,
|
action: PropTypes.string,
|
||||||
name: PropTypes.string,
|
name: PropTypes.string,
|
||||||
|
@ -35,7 +35,7 @@ export default {
|
||||||
name: 'Upload',
|
name: 'Upload',
|
||||||
mixins: [BaseMixin],
|
mixins: [BaseMixin],
|
||||||
props: initDefaultProps(uploadProps, {
|
props: initDefaultProps(uploadProps, {
|
||||||
component: 'span',
|
componentTag: 'span',
|
||||||
prefixCls: 'rc-upload',
|
prefixCls: 'rc-upload',
|
||||||
data: {},
|
data: {},
|
||||||
headers: {},
|
headers: {},
|
||||||
|
@ -78,14 +78,21 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
|
const componentProps = {
|
||||||
|
props: {
|
||||||
|
...this.$props,
|
||||||
|
},
|
||||||
|
on: this.$listeners,
|
||||||
|
ref: 'uploaderRef',
|
||||||
|
}
|
||||||
if (this.supportServerRender) {
|
if (this.supportServerRender) {
|
||||||
const ComponentUploader = this.Component
|
const ComponentUploader = this.Component
|
||||||
if (ComponentUploader) {
|
if (ComponentUploader) {
|
||||||
return <ComponentUploader {...this.$props} ref='uploaderRef' />
|
return <ComponentUploader {...componentProps} >{this.$slots.default}</ComponentUploader>
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
const ComponentUploader = this.getComponent()
|
const ComponentUploader = this.getComponent()
|
||||||
return <ComponentUploader {...this.$props} ref='uploaderRef' />
|
return <ComponentUploader {...componentProps} >{this.$slots.default}</ComponentUploader>
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,5 +2,5 @@ const now = +(new Date())
|
||||||
let index = 0
|
let index = 0
|
||||||
|
|
||||||
export default function uid () {
|
export default function uid () {
|
||||||
return `rc-upload-${now}-${++index}`
|
return `vc-upload-${now}-${++index}`
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import Layout from './components/layout.vue'
|
||||||
const AsyncTestComp = () => {
|
const AsyncTestComp = () => {
|
||||||
const d = window.location.hash.replace('#', '')
|
const d = window.location.hash.replace('#', '')
|
||||||
return {
|
return {
|
||||||
component: import(`../components/vc-tree/demo/${d}`),
|
component: import(`../components/vc-upload/demo/${d}`),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue