Skip to content

Commit d2c3aba

Browse files
committed
dialog add delay param
1 parent 9f289c4 commit d2c3aba

File tree

4 files changed

+45
-10
lines changed

4 files changed

+45
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-dialog-loading",
3-
"version": "0.4.7",
3+
"version": "0.5.0",
44
"description": "A light vue dialog plugin with loading animation and image preview",
55
"private": false,
66
"main": "./dist/index.js",

src/App.vue

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<button @click="openDialog">Dialog</button>
44
<button @click="openDialog1">Dialog1</button>
55
<button @click="openBusyDialog">Loading</button>
6+
<button @click="openDelayDialog">DelayDialog</button>
67
<img class="img" :src="imgUrl" @click="preview(imgUrl)"/>
78
<LoadingCom/>
89
</div>
@@ -70,6 +71,19 @@
7071
],
7172
})
7273
},
74+
openDelayDialog () {
75+
this.$dialog({
76+
content: 'dialog with delay 3s',
77+
// background: '#00f',
78+
delay: 3000,
79+
btns: [
80+
{
81+
label: 'OK',
82+
color: '#09f',
83+
}
84+
],
85+
})
86+
},
7387
openBusyDialog () {
7488
this.$loading.show({delay: 0}) //delay default is 300ms
7589
// this.$loading.show({delay: 0, background: 'rgba(0,0,0,0.5)'}) //delay default is 300ms

src/component/Dialog.vue

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
onOk: null,
2929
onCancel: null,
3030
background: null,
31+
delay: 0,
3132
btns: []
3233
}
3334
},
@@ -46,22 +47,32 @@
4647
this.visible = false
4748
setTimeout(() => {
4849
this.$destroy(true)
49-
this.$el.parentNode.removeChild(this.$el)
50+
if (this.$el.parentNode) {
51+
this.$el.parentNode.removeChild(this.$el)
52+
}
5053
}, 330)
5154
},
52-
handleBgClose (e) {
55+
handleBgClose(e) {
5356
if (this.visible && this.bgClose && !document.querySelector('.dialog').contains(e.target)) {
5457
this.close()
5558
}
5659
}
5760
},
58-
created () {
61+
created() {
5962
},
60-
mounted () {
63+
mounted() {
64+
65+
},
66+
updated() {
67+
if (this.delay > 0) {
68+
window.setTimeout(() => {
69+
this.close()
70+
}, this.delay)
71+
}
6172
},
62-
beforeDestroy () {
73+
beforeDestroy() {
6374
},
64-
destroyed () {
75+
destroyed() {
6576
}
6677
6778
}

src/component/index.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const dialog = (params) => {
2525
// instance.id = id
2626
instance.vm = instance.$mount()
2727

28-
let {title, content, btns, bgClose, background} = params || {}
28+
let {title, content, btns, bgClose, background, delay} = params || {}
2929
if (!background) {
3030
background = options.background;
3131
}
@@ -52,8 +52,18 @@ const dialog = (params) => {
5252
})
5353
}
5454

55+
if (Number.isInteger(delay)) {
56+
if (delay > 30000) {
57+
delay = 30000
58+
}
59+
if (delay < 20) {
60+
delay = 20
61+
}
62+
instance.delay = delay
63+
}
64+
5565
document.body.appendChild(instance.$el)
56-
return instance.el
66+
return instance.$el
5767
}
5868

5969
export {Dialog, Loading, ImagePreview}
@@ -79,7 +89,7 @@ if (typeof window !== 'undefined' && window.Vue) {
7989
}
8090

8191
export default {
82-
version: '0.4.7',
92+
version: '0.5.0',
8393
install,
8494
Dialog,
8595
Loading,

0 commit comments

Comments
 (0)