Skip to content

Commit

Permalink
fix: upload onchange not work (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouxinyong authored Mar 30, 2022
1 parent 8fd6ea8 commit df94dce
Showing 1 changed file with 79 additions and 3 deletions.
82 changes: 79 additions & 3 deletions packages/components/src/upload/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,94 @@
import { connect, mapProps } from '@formily/vue'
import { connect, mapProps, h } from '@formily/vue'
import { Upload as AntdUpload } from 'ant-design-vue'
import { composeExport } from '../__builtins__'
import type {
UploadFile,
Upload as AntdUploadProps,
} from 'ant-design-vue/types/upload'
import { defineComponent } from '@vue/composition-api'

export type IUploadOnchange = (fileList: UploadFile[]) => void

export type IUploadProps = Omit<AntdUploadProps, 'onChange'> & {
onChange?: IUploadOnchange
}

export type IDraggerUploadProps = Omit<AntdUploadProps, 'onChange'> & {
onChange?: IUploadOnchange
}

const UploadWrapper = defineComponent<IUploadProps>({
name: 'UploadWrapper',
setup(props, { slots, attrs, listeners, emit }) {
return () => {
const children = {
...slots,
}

return h(
AntdUpload,
{
attrs,
on: {
...listeners,
change: ({ fileList }) => {
;(attrs.onChange as IUploadOnchange)?.(fileList)
emit('change', fileList)
},
},
},
children
)
}
},
})

const UploaDraggerdWrapper = defineComponent<IUploadProps>({
name: 'UploaDraggerdWrapper',
setup(props, { slots, attrs, listeners, emit }) {
return () => {
const children = {
...slots,
}

return h(
'div',
{},
{
default: () =>
h(
AntdUpload.Dragger,
{
attrs,
on: {
...listeners,
change: ({ fileList }) => {
;(attrs.onChange as IUploadOnchange)?.(fileList)
emit('change', fileList)
},
},
},
children
),
}
)
}
},
})

const _Upload = connect(
AntdUpload,
UploadWrapper,
mapProps({
value: 'fileList',
onInput: 'onChange',
})
)

const UploadDragger = connect(
AntdUpload.Dragger,
UploaDraggerdWrapper,
mapProps({
value: 'fileList',
onInput: 'onChange',
})
)

Expand Down

0 comments on commit df94dce

Please sign in to comment.