forked from N3-components/N3-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
n3PopConfirm.vue
80 lines (76 loc) · 1.56 KB
/
n3PopConfirm.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<template>
<n3-popover
:show.sync="show"
:effect="effect"
:header="false"
:placement="placement"
trigger="click">
<div slot="content">
<p>{{content}}</p>
<div style="float:right; margin:10px;">
<n3-button size="sm" @click="show = false">{{cancelText}}</n3-button>
<n3-button size="sm" type="primary" @click="confirm">{{okText}}</n3-button>
</div>
</div>
<slot></slot>
</n3-popover>
</template>
<script>
import n3Popover from './n3Popover'
import n3Button from './n3Button'
import type from './utils/type'
export default {
props: {
effect: {
type: String,
default: 'scale'
},
content: {
type: String
},
placement: {
type: String,
default: 'top'
},
onConfirm: {
type: Function
},
okText: {
type: String,
default: '确定'
},
cancelText: {
type: String,
default: '取消'
}
},
data () {
return {
show: true
}
},
methods: {
confirm () {
let self = this
if (type.isFunction(this.onConfirm)) {
let promise = this.onConfirm()
if (type.isPromise(promise)) {
promise.then((...args) => {
self.show = false
return args
}).catch((...args) => {
self.show = false
return Promise.reject(args)
})
} else {
self.show = false
}
}
}
},
components: {
n3Popover,
n3Button
}
}
</script>