Commit 3ef24d5fe5046ed3ebbfa607d6df20ad4521bbe7
1 parent
dce5a3ea
$Modal support render, fixed #1041
Showing
4 changed files
with
56 additions
and
22 deletions
Show diff stats
examples/routers/modal.vue
| 1 | 1 | <template> |
| 2 | 2 | <div> |
| 3 | + {{ val }} | |
| 3 | 4 | <Button @click="confirm">标准</Button> |
| 4 | 5 | <Button @click="custom">自定义按钮文字</Button> |
| 5 | 6 | <Button @click="async">异步关闭</Button> |
| ... | ... | @@ -19,7 +20,8 @@ |
| 19 | 20 | export default { |
| 20 | 21 | data () { |
| 21 | 22 | return { |
| 22 | - modal1: false | |
| 23 | + modal1: false, | |
| 24 | + val: '' | |
| 23 | 25 | } |
| 24 | 26 | }, |
| 25 | 27 | methods: { |
| ... | ... | @@ -33,6 +35,19 @@ |
| 33 | 35 | this.$Modal.confirm({ |
| 34 | 36 | title: '确认对话框标题', |
| 35 | 37 | content: '<p>一些对话框内容</p><p>一些对话框内容</p>', |
| 38 | + render: (h) => { | |
| 39 | + return h('Input', { | |
| 40 | + props: { | |
| 41 | + value: this.val, | |
| 42 | + autofocus: true | |
| 43 | + }, | |
| 44 | + on: { | |
| 45 | + input: (val) => { | |
| 46 | + this.val = val; | |
| 47 | + } | |
| 48 | + } | |
| 49 | + }, '一个按钮') | |
| 50 | + }, | |
| 36 | 51 | onOk: () => { |
| 37 | 52 | this.$Message.info('点击了确定'); |
| 38 | 53 | }, | ... | ... |
src/components/modal/confirm.js
| ... | ... | @@ -48,6 +48,35 @@ Modal.newInstance = properties => { |
| 48 | 48 | } |
| 49 | 49 | }, this.localeOkText)); |
| 50 | 50 | |
| 51 | + // render content | |
| 52 | + let body_render; | |
| 53 | + if (this.render) { | |
| 54 | + body_render = h('div', { | |
| 55 | + attrs: { | |
| 56 | + class: `${prefixCls}-body ${prefixCls}-body-render` | |
| 57 | + } | |
| 58 | + }, [this.render(h)]); | |
| 59 | + } else { | |
| 60 | + body_render = h('div', { | |
| 61 | + attrs: { | |
| 62 | + class: `${prefixCls}-body` | |
| 63 | + } | |
| 64 | + }, [ | |
| 65 | + h('div', { | |
| 66 | + class: this.iconTypeCls | |
| 67 | + }, [ | |
| 68 | + h('i', { | |
| 69 | + class: this.iconNameCls | |
| 70 | + }) | |
| 71 | + ]), | |
| 72 | + h('div', { | |
| 73 | + domProps: { | |
| 74 | + innerHTML: this.body | |
| 75 | + } | |
| 76 | + }) | |
| 77 | + ]); | |
| 78 | + } | |
| 79 | + | |
| 51 | 80 | return h(Modal, { |
| 52 | 81 | props: Object.assign({}, _props, { |
| 53 | 82 | width: this.width, |
| ... | ... | @@ -81,24 +110,7 @@ Modal.newInstance = properties => { |
| 81 | 110 | } |
| 82 | 111 | }) |
| 83 | 112 | ]), |
| 84 | - h('div', { | |
| 85 | - attrs: { | |
| 86 | - class: `${prefixCls}-body` | |
| 87 | - } | |
| 88 | - }, [ | |
| 89 | - h('div', { | |
| 90 | - class: this.iconTypeCls | |
| 91 | - }, [ | |
| 92 | - h('i', { | |
| 93 | - class: this.iconNameCls | |
| 94 | - }) | |
| 95 | - ]), | |
| 96 | - h('div', { | |
| 97 | - domProps: { | |
| 98 | - innerHTML: this.body | |
| 99 | - } | |
| 100 | - }) | |
| 101 | - ]), | |
| 113 | + body_render, | |
| 102 | 114 | h('div', { |
| 103 | 115 | attrs: { |
| 104 | 116 | class: `${prefixCls}-footer` | ... | ... |
src/components/modal/index.js
| ... | ... | @@ -2,18 +2,20 @@ import Modal from './confirm'; |
| 2 | 2 | |
| 3 | 3 | let modalInstance; |
| 4 | 4 | |
| 5 | -function getModalInstance () { | |
| 5 | +function getModalInstance (render = undefined) { | |
| 6 | 6 | modalInstance = modalInstance || Modal.newInstance({ |
| 7 | 7 | closable: false, |
| 8 | 8 | maskClosable: false, |
| 9 | - footerHide: true | |
| 9 | + footerHide: true, | |
| 10 | + render: render | |
| 10 | 11 | }); |
| 11 | 12 | |
| 12 | 13 | return modalInstance; |
| 13 | 14 | } |
| 14 | 15 | |
| 15 | 16 | function confirm (options) { |
| 16 | - let instance = getModalInstance(); | |
| 17 | + const render = ('render' in options) ? options.render : undefined; | |
| 18 | + let instance = getModalInstance(render); | |
| 17 | 19 | |
| 18 | 20 | options.onRemove = function () { |
| 19 | 21 | modalInstance = null; | ... | ... |
src/styles/components/modal.less