add modal confirm

This commit is contained in:
tjz 2018-03-06 22:53:32 +08:00
parent e7834f972a
commit fab5c432ca
7 changed files with 120 additions and 33 deletions

View File

@ -111,9 +111,12 @@ export function getClass (ele) {
} else if (ele.$vnode && ele.$vnode.data) { } else if (ele.$vnode && ele.$vnode.data) {
data = ele.$vnode.data data = ele.$vnode.data
} }
let cls = data.class || data.staticClass || {} const tempCls = data.class || data.staticClass
if (typeof cls === 'string') { let cls = {}
cls = cls.split(' ').forEach(c => { cls[c.trim()] = true }) if (typeof tempCls === 'string') {
tempCls.split(' ').forEach(c => { cls[c.trim()] = true })
} else {
cls = tempCls
} }
return cls return cls
} }

View File

@ -72,12 +72,6 @@ import message from './message'
export { default as Spin } from './spin' export { default as Spin } from './spin'
const api = {
notification,
message,
}
export { api }
import Select from './select' import Select from './select'
const SelectOption = Select.Option const SelectOption = Select.Option
const SelectOptGroup = Select.OptGroup const SelectOptGroup = Select.OptGroup
@ -94,4 +88,23 @@ export { default as Affix } from './affix'
export { default as Cascader } from './cascader' export { default as Cascader } from './cascader'
export { default as BackTop } from './back-top' export { default as BackTop } from './back-top'
export { default as Modal } from './modal' export { default as Modal } from './modal'
import {
info,
success,
error,
warning,
warn,
confirm,
} from './modal'
const api = {
notification,
message,
modalInfo: info,
modalSuccess: success,
modalError: error,
modalWarning: warning,
modalWarn: warn,
modalConfirm: confirm,
}
export { api }

View File

@ -7,9 +7,9 @@ import { getConfirmLocale } from './locale'
export default { export default {
functional: true, functional: true,
render () { render (h, context) {
const { onCancel, onOk, close, zIndex, afterClose, visible } = this.$props const { data: props } = context
const props = this.$props const { onCancel, onOk, close, zIndex, afterClose, visible } = props
const iconType = props.iconType || 'question-circle' const iconType = props.iconType || 'question-circle'
const okType = props.okType || 'primary' const okType = props.okType || 'primary'
const prefixCls = props.prefixCls || 'ant-confirm' const prefixCls = props.prefixCls || 'ant-confirm'

View File

@ -7,7 +7,7 @@ import buttonTypes from '../button/buttonTypes'
const ButtonType = buttonTypes().type const ButtonType = buttonTypes().type
import LocaleReceiver from '../locale-provider/LocaleReceiver' import LocaleReceiver from '../locale-provider/LocaleReceiver'
import { getConfirmLocale } from './locale' import { getConfirmLocale } from './locale'
import { initDefaultProps, getComponentFromProp } from '../_util/props-util' import { initDefaultProps, getComponentFromProp, getClass, getStyle } from '../_util/props-util'
let mousePosition = null let mousePosition = null
let mousePositionEventBinded = false let mousePositionEventBinded = false
@ -125,11 +125,13 @@ export default {
children={this.renderFooter} children={this.renderFooter}
/> />
) )
const footer = getComponentFromProp(this, 'footer')
const title = getComponentFromProp(this, 'title')
const dialogProps = { const dialogProps = {
props: { props: {
...this.$props, ...this.$props,
title: getComponentFromProp(this, 'title'), title,
footer: getComponentFromProp(this, 'footer') || defaultFooter, footer: typeof footer === undefined ? defaultFooter : footer,
visible: visible, visible: visible,
mousePosition, mousePosition,
}, },
@ -137,6 +139,8 @@ export default {
...$listeners, ...$listeners,
close: this.handleCancel, close: this.handleCancel,
}, },
class: getClass(this),
style: getStyle(this),
} }
return ( return (
<Dialog {...dialogProps}> <Dialog {...dialogProps}>

View File

@ -0,0 +1,58 @@
<cn>
#### 确认对话框
使用 `confirm()` 可以快捷地弹出确认框。
</cn>
<us>
#### Confirmation modal dialog
To use `confirm()` to popup a confirmation modal dialog.
</us>
```html
<template>
<div>
<a-button @click="showConfirm">
Confirm
</a-button>
<a-button @click="showDeleteConfirm" type="dashed">
Delete
</a-button>
</div>
</template>
<script>
export default {
methods: {
showConfirm() {
this.$modalConfirm({
title: 'Do you Want to delete these items?',
content: 'Some descriptions',
onOk() {
console.log('OK');
},
onCancel() {
console.log('Cancel');
},
});
},
showDeleteConfirm() {
this.$modalConfirm({
title: 'Are you sure delete this task?',
content: 'Some descriptions',
okText: 'Yes',
okType: 'danger',
cancelText: 'No',
onOk() {
console.log('OK');
},
onCancel() {
console.log('Cancel');
},
});
},
}
}
</script>
```

View File

@ -1,56 +1,66 @@
import Modal from './Modal' import Modal from './Modal'
import confirm from './confirm' import modalConfirm from './confirm'
// export { ActionButtonProps } from './ActionButton' // export { ActionButtonProps } from './ActionButton'
// export { ModalProps, ModalFuncProps } from './Modal' // export { ModalProps, ModalFuncProps } from './Modal'
Modal.info = function (props) { const info = function (props) {
const config = { const config = {
type: 'info', type: 'info',
iconType: 'info-circle', iconType: 'info-circle',
okCancel: false, okCancel: false,
...props, ...props,
} }
return confirm(config) return modalConfirm(config)
} }
Modal.success = function (props) { const success = function (props) {
const config = { const config = {
type: 'success', type: 'success',
iconType: 'check-circle', iconType: 'check-circle',
okCancel: false, okCancel: false,
...props, ...props,
} }
return confirm(config) return modalConfirm(config)
} }
Modal.error = function (props) { const error = function (props) {
const config = { const config = {
type: 'error', type: 'error',
iconType: 'cross-circle', iconType: 'cross-circle',
okCancel: false, okCancel: false,
...props, ...props,
} }
return confirm(config) return modalConfirm(config)
} }
Modal.warning = Modal.warn = function (props) { const warning = function (props) {
const config = { const config = {
type: 'warning', type: 'warning',
iconType: 'exclamation-circle', iconType: 'exclamation-circle',
okCancel: false, okCancel: false,
...props, ...props,
} }
return confirm(config) return modalConfirm(config)
} }
const warn = warning
Modal.confirm = function (props) { const confirm = function (props) {
const config = { const config = {
type: 'confirm', type: 'confirm',
okCancel: true, okCancel: true,
...props, ...props,
} }
return confirm(config) return modalConfirm(config)
}
export {
info,
success,
error,
warning,
warn,
confirm,
} }
export default Modal export default Modal

View File

@ -11,7 +11,7 @@ let uuid = 0
let openCount = 0 let openCount = 0
/* eslint react/no-is-mounted:0 */ /* eslint react/no-is-mounted:0 */
function noop () {}
function getScroll (w, top) { function getScroll (w, top) {
let ret = w[`page${top ? 'Y' : 'X'}Offset`] let ret = w[`page${top ? 'Y' : 'X'}Offset`]
const method = `scroll${top ? 'Top' : 'Left'}` const method = `scroll${top ? 'Top' : 'Left'}`
@ -90,12 +90,12 @@ export default {
watch: { watch: {
visible (val) { visible (val) {
this.$nextTick(() => {
this.updatedCallback(val)
})
if (val) { if (val) {
this.destroyPopup = false this.destroyPopup = false
} }
this.$nextTick(() => {
this.updatedCallback(!val)
})
}, },
}, },
beforeDestroy () { beforeDestroy () {
@ -160,7 +160,6 @@ export default {
} }
}, },
onKeydown (e) { onKeydown (e) {
console.log('keydown')
const props = this.$props const props = this.$props
if (props.keyboard && e.keyCode === KeyCode.ESC) { if (props.keyboard && e.keyCode === KeyCode.ESC) {
this.close(e) this.close(e)
@ -216,7 +215,7 @@ export default {
closer = ( closer = (
<button <button
key='close' key='close'
onClick={this.close} onClick={this.close || noop}
aria-label='Close' aria-label='Close'
class={`${prefixCls}-close`} class={`${prefixCls}-close`}
> >
@ -402,7 +401,7 @@ export default {
onKeydown={this.onKeydown} onKeydown={this.onKeydown}
class={`${prefixCls}-wrap ${wrapClassName || ''}`} class={`${prefixCls}-wrap ${wrapClassName || ''}`}
ref='wrap' ref='wrap'
onClick={maskClosable ? this.onMaskClick : undefined} onClick={maskClosable ? this.onMaskClick : noop}
role='dialog' role='dialog'
aria-labelledby={title ? this.titleId : null} aria-labelledby={title ? this.titleId : null}
style={style} style={style}