feat: update vc-table vc-upload

pull/398/head
tangjinzhou 2019-01-01 22:30:06 +08:00
parent 639547953c
commit 75e5f04d1e
7 changed files with 48 additions and 13 deletions

View File

@ -1,5 +1,5 @@
import addDOMEventListener from 'add-dom-event-listener' import addDOMEventListener from 'add-dom-event-listener'
export default function addEventListenerWrap (target, eventType, cb) { export default function addEventListenerWrap (target, eventType, cb, option) {
return addDOMEventListener(target, eventType, cb) return addDOMEventListener(target, eventType, cb, option)
} }

View File

@ -14,6 +14,7 @@ import { T, fileToObject, genPercentAdd, getFileItem, removeFileItem } from './u
export { UploadProps } export { UploadProps }
export default { export default {
inheritAttrs: false,
name: 'AUpload', name: 'AUpload',
Dragger: Dragger, Dragger: Dragger,
mixins: [BaseMixin], mixins: [BaseMixin],
@ -231,6 +232,7 @@ export default {
}, },
ref: 'uploadRef', ref: 'uploadRef',
class: `${prefixCls}-btn`, class: `${prefixCls}-btn`,
attrs: this.$attrs,
} }
const uploadList = showUploadList ? ( const uploadList = showUploadList ? (

View File

@ -1,4 +1,4 @@
// base rc-table 6.4.0 // base rc-table 6.4.2
import T from './src/Table' import T from './src/Table'
import Column from './src/Column' import Column from './src/Column'
import ColumnGroup from './src/ColumnGroup' import ColumnGroup from './src/ColumnGroup'

View File

@ -1,6 +1,7 @@
import PropTypes from '../../_util/vue-types' import PropTypes from '../../_util/vue-types'
import BaseMixin from '../../_util/BaseMixin' import BaseMixin from '../../_util/BaseMixin'
import { connect } from '../../_util/store' import { connect } from '../../_util/store'
import shallowEqual from 'shallowequal'
import TableRow from './TableRow' import TableRow from './TableRow'
import { remove } from './utils' import { remove } from './utils'
import { initDefaultProps, getOptionProps } from '../../_util/props-util' import { initDefaultProps, getOptionProps } from '../../_util/props-util'
@ -71,6 +72,12 @@ const ExpandableTable = {
}) })
return {} return {}
}, },
mounted () {
this.handleUpdated()
},
updated () {
this.handleUpdated()
},
watch: { watch: {
expandedRowKeys (val) { expandedRowKeys (val) {
this.$nextTick(() => { this.$nextTick(() => {
@ -81,6 +88,10 @@ const ExpandableTable = {
}, },
}, },
methods: { methods: {
handleUpdated () {
// We should record latest expanded rows to avoid multiple rows remove cause `onExpandedRowsChange` trigger many times
this.latestExpandedRows = null
},
handleExpandChange (expanded, record, event, rowKey, destroy = false) { handleExpandChange (expanded, record, event, rowKey, destroy = false) {
if (event) { if (event) {
event.preventDefault() event.preventDefault()
@ -103,7 +114,12 @@ const ExpandableTable = {
if (!this.expandedRowKeys) { if (!this.expandedRowKeys) {
this.store.setState({ expandedRowKeys }) this.store.setState({ expandedRowKeys })
} }
// De-dup of repeat call
if (!this.latestExpandedRows || !shallowEqual(this.latestExpandedRows, expandedRowKeys)) {
this.latestExpandedRows = expandedRowKeys
this.__emit('expandedRowsChange', expandedRowKeys) this.__emit('expandedRowsChange', expandedRowKeys)
}
if (!destroy) { if (!destroy) {
this.__emit('expand', expanded, record) this.__emit('expand', expanded, record)
} }

View File

@ -1,6 +1,7 @@
import warning from 'warning' import warning from 'warning'
let scrollbarSize let scrollbarVerticalSize
let scrollbarHorizontalSize
// Measure scrollbar width for padding body during modal show/hide // Measure scrollbar width for padding body during modal show/hide
const scrollbarMeasure = { const scrollbarMeasure = {
@ -15,24 +16,34 @@ export function measureScrollbar (direction = 'vertical') {
if (typeof document === 'undefined' || typeof window === 'undefined') { if (typeof document === 'undefined' || typeof window === 'undefined') {
return 0 return 0
} }
if (scrollbarSize) { const isVertical = direction === 'vertical'
return scrollbarSize if (isVertical && scrollbarVerticalSize) {
return scrollbarVerticalSize
} else if (!isVertical && scrollbarHorizontalSize) {
return scrollbarHorizontalSize
} }
const scrollDiv = document.createElement('div') const scrollDiv = document.createElement('div')
Object.keys(scrollbarMeasure).forEach(scrollProp => { Object.keys(scrollbarMeasure).forEach(scrollProp => {
scrollDiv.style[scrollProp] = scrollbarMeasure[scrollProp] scrollDiv.style[scrollProp] = scrollbarMeasure[scrollProp]
}) })
// Append related overflow style
if (isVertical) {
scrollDiv.style.overflowY = 'scroll'
} else {
scrollDiv.style.overflowX = 'scroll'
}
document.body.appendChild(scrollDiv) document.body.appendChild(scrollDiv)
let size = 0 let size = 0
if (direction === 'vertical') { if (isVertical) {
size = scrollDiv.offsetWidth - scrollDiv.clientWidth size = scrollDiv.offsetWidth - scrollDiv.clientWidth
} else if (direction === 'horizontal') { scrollbarVerticalSize = size
} else if (!isVertical) {
size = scrollDiv.offsetHeight - scrollDiv.clientHeight size = scrollDiv.offsetHeight - scrollDiv.clientHeight
scrollbarHorizontalSize = size
} }
document.body.removeChild(scrollDiv) document.body.removeChild(scrollDiv)
scrollbarSize = size return size
return scrollbarSize
} }
export function debounce (func, wait, immediate) { export function debounce (func, wait, immediate) {

View File

@ -35,6 +35,7 @@ const upLoadPropTypes = {
} }
const AjaxUploader = { const AjaxUploader = {
inheritAttrs: false,
name: 'ajaxUploader', name: 'ajaxUploader',
mixins: [BaseMixin], mixins: [BaseMixin],
props: upLoadPropTypes, props: upLoadPropTypes,
@ -184,9 +185,11 @@ const AjaxUploader = {
this.abort() this.abort()
}, },
render () { render () {
const { $props, $attrs } = this
const { const {
componentTag: Tag, prefixCls, disabled, multiple, accept, directory, openFileDialogOnClick, componentTag: Tag, prefixCls, disabled,
} = this.$props multiple, accept, directory, openFileDialogOnClick,
} = $props
const cls = classNames({ const cls = classNames({
[prefixCls]: true, [prefixCls]: true,
[`${prefixCls}-disabled`]: disabled, [`${prefixCls}-disabled`]: disabled,
@ -213,6 +216,7 @@ const AjaxUploader = {
{...tagProps} {...tagProps}
> >
<input <input
id={$attrs.id}
type='file' type='file'
ref='fileInputRef' ref='fileInputRef'
key={this.uid} key={this.uid}

View File

@ -37,6 +37,7 @@ const uploadProps = {
openFileDialogOnClick: PropTypes.bool, openFileDialogOnClick: PropTypes.bool,
} }
export default { export default {
inheritAttrs: false,
name: 'Upload', name: 'Upload',
mixins: [BaseMixin], mixins: [BaseMixin],
props: initDefaultProps(uploadProps, { props: initDefaultProps(uploadProps, {
@ -89,6 +90,7 @@ export default {
}, },
on: this.$listeners, on: this.$listeners,
ref: 'uploaderRef', ref: 'uploaderRef',
attrs: this.$attrs,
} }
if (this.supportServerRender) { if (this.supportServerRender) {
const ComponentUploader = this.Component const ComponentUploader = this.Component