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 | <template> | 1 | <template> |
| 2 | <div> | 2 | <div> |
| 3 | + {{ val }} | ||
| 3 | <Button @click="confirm">标准</Button> | 4 | <Button @click="confirm">标准</Button> |
| 4 | <Button @click="custom">自定义按钮文字</Button> | 5 | <Button @click="custom">自定义按钮文字</Button> |
| 5 | <Button @click="async">异步关闭</Button> | 6 | <Button @click="async">异步关闭</Button> |
| @@ -19,7 +20,8 @@ | @@ -19,7 +20,8 @@ | ||
| 19 | export default { | 20 | export default { |
| 20 | data () { | 21 | data () { |
| 21 | return { | 22 | return { |
| 22 | - modal1: false | 23 | + modal1: false, |
| 24 | + val: '' | ||
| 23 | } | 25 | } |
| 24 | }, | 26 | }, |
| 25 | methods: { | 27 | methods: { |
| @@ -33,6 +35,19 @@ | @@ -33,6 +35,19 @@ | ||
| 33 | this.$Modal.confirm({ | 35 | this.$Modal.confirm({ |
| 34 | title: '确认对话框标题', | 36 | title: '确认对话框标题', |
| 35 | content: '<p>一些对话框内容</p><p>一些对话框内容</p>', | 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 | onOk: () => { | 51 | onOk: () => { |
| 37 | this.$Message.info('点击了确定'); | 52 | this.$Message.info('点击了确定'); |
| 38 | }, | 53 | }, |
src/components/modal/confirm.js
| @@ -48,6 +48,35 @@ Modal.newInstance = properties => { | @@ -48,6 +48,35 @@ Modal.newInstance = properties => { | ||
| 48 | } | 48 | } |
| 49 | }, this.localeOkText)); | 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 | return h(Modal, { | 80 | return h(Modal, { |
| 52 | props: Object.assign({}, _props, { | 81 | props: Object.assign({}, _props, { |
| 53 | width: this.width, | 82 | width: this.width, |
| @@ -81,24 +110,7 @@ Modal.newInstance = properties => { | @@ -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 | h('div', { | 114 | h('div', { |
| 103 | attrs: { | 115 | attrs: { |
| 104 | class: `${prefixCls}-footer` | 116 | class: `${prefixCls}-footer` |
src/components/modal/index.js
| @@ -2,18 +2,20 @@ import Modal from './confirm'; | @@ -2,18 +2,20 @@ import Modal from './confirm'; | ||
| 2 | 2 | ||
| 3 | let modalInstance; | 3 | let modalInstance; |
| 4 | 4 | ||
| 5 | -function getModalInstance () { | 5 | +function getModalInstance (render = undefined) { |
| 6 | modalInstance = modalInstance || Modal.newInstance({ | 6 | modalInstance = modalInstance || Modal.newInstance({ |
| 7 | closable: false, | 7 | closable: false, |
| 8 | maskClosable: false, | 8 | maskClosable: false, |
| 9 | - footerHide: true | 9 | + footerHide: true, |
| 10 | + render: render | ||
| 10 | }); | 11 | }); |
| 11 | 12 | ||
| 12 | return modalInstance; | 13 | return modalInstance; |
| 13 | } | 14 | } |
| 14 | 15 | ||
| 15 | function confirm (options) { | 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 | options.onRemove = function () { | 20 | options.onRemove = function () { |
| 19 | modalInstance = null; | 21 | modalInstance = null; |
src/styles/components/modal.less
| @@ -98,6 +98,11 @@ | @@ -98,6 +98,11 @@ | ||
| 98 | color: @text-color; | 98 | color: @text-color; |
| 99 | position: relative; | 99 | position: relative; |
| 100 | 100 | ||
| 101 | + &-render{ | ||
| 102 | + margin: 0; | ||
| 103 | + padding: 0; | ||
| 104 | + } | ||
| 105 | + | ||
| 101 | &-icon { | 106 | &-icon { |
| 102 | font-size: 36px; | 107 | font-size: 36px; |
| 103 | position: absolute; | 108 | position: absolute; |