|
| 1 | +import confirm from '../../components/modals/confirm.vue'; |
| 2 | + |
1 | 3 | var modal = {
|
2 | 4 | install: function (Vue, options) {
|
3 | 5 |
|
4 |
| - var defaultOptions = Object.assgin({ |
5 |
| - name: '$modal' |
6 |
| - },options) |
7 |
| - Vue.prototype[defaultOptions.name] = function () { |
| 6 | + var defaultOptions = Object.assign({ |
| 7 | + name: '$modal', |
| 8 | + id: 'modal' |
| 9 | + }, options) |
| 10 | + |
| 11 | + this.init(defaultOptions.id); |
| 12 | + |
| 13 | + console.log('defaultOptions', defaultOptions, Vue.prototype); |
8 | 14 |
|
| 15 | + var modals = Vue.prototype[defaultOptions.name] = {}; |
| 16 | + |
| 17 | + console.log('confirm', confirm) |
| 18 | + confirm.methods.$ok = function () { |
| 19 | + console.log('osdjcopsjpojcpoj') |
9 | 20 | }
|
| 21 | + modals.confirm = options => { |
| 22 | + return new Promise((res, rej) => { |
| 23 | + console.log('options', options) |
| 24 | + new Vue({ |
| 25 | + render: h => h(confirm, { |
| 26 | + props: options, |
| 27 | + on: { |
| 28 | + abc: function (v) { |
| 29 | + console.log('abc') |
| 30 | + res(v) |
| 31 | + } |
| 32 | + } |
| 33 | + }) |
| 34 | + }).$mount('#' + defaultOptions.id) |
| 35 | + |
| 36 | + this.init(defaultOptions.id) |
| 37 | + }) |
| 38 | + |
| 39 | + |
| 40 | + } |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | + // Object.keys(defaultOptions.modals).forEach(function (v) { |
| 50 | + // modals[v] = function (box) { |
| 51 | + // Vue.component(v, defaultOptions.modals[v]) |
| 52 | + // console.log('box', box.content) |
| 53 | + // console.log(v, defaultOptions.modals[v]) |
| 54 | + |
| 55 | + // // document.getElementsByTagName('body')[0].appendChild('<confirm></confirm>') |
| 56 | + // } |
| 57 | + |
| 58 | + // }) |
| 59 | + }, |
| 60 | + init: name => { |
| 61 | + const div = document.createElement('div'); |
| 62 | + div.setAttribute('id', name || 'modal'); |
| 63 | + document.getElementsByTagName('body')[0].appendChild(div) |
10 | 64 | }
|
11 | 65 | }
|
12 | 66 |
|
|
0 commit comments