commit | author | age
|
a5a648
|
1 |
import { Injectable } from '@angular/core'; |
W |
2 |
import { AlertController, AlertOptions, ToastController } from 'ionic-angular'; |
|
3 |
|
|
4 |
@Injectable() |
|
5 |
export class MessageBox { |
|
6 |
|
|
7 |
constructor(private alertCtrl: AlertController, private toastCtrl: ToastController) { } |
|
8 |
|
|
9 |
/** |
|
10 |
* Toast提示框 |
|
11 |
*/ |
|
12 |
toast(msg: string, css: string = '') { |
|
13 |
let toast = this.toastCtrl.create({ |
|
14 |
message: msg, |
|
15 |
duration: 3000, |
|
16 |
cssClass: css |
|
17 |
}); |
|
18 |
|
|
19 |
toast.present(); |
|
20 |
} |
|
21 |
|
|
22 |
/** 提示框 */ |
|
23 |
alert(msg: string) { |
|
24 |
let options: AlertOptions = { |
|
25 |
title: '', |
|
26 |
subTitle: msg, |
|
27 |
buttons: [ |
|
28 |
{ |
|
29 |
text: '', |
|
30 |
}, |
|
31 |
{ |
|
32 |
text: '确定', |
|
33 |
} |
|
34 |
] |
|
35 |
}; |
|
36 |
this._present(options); |
|
37 |
} |
|
38 |
|
|
39 |
/** |
|
40 |
* 确认框 |
|
41 |
*/ |
|
42 |
confirm( |
|
43 |
msg: string, |
|
44 |
onOk: () => void, |
|
45 |
onCancel = () => { }, |
|
46 |
okText = '确定', |
|
47 |
cancelText = '' |
|
48 |
) { |
|
49 |
let options: AlertOptions = { |
|
50 |
title: '', |
|
51 |
message: msg, |
|
52 |
buttons: [ |
|
53 |
{ |
|
54 |
text: cancelText, |
|
55 |
role: 'cancel', |
|
56 |
handler: onCancel |
|
57 |
}, |
|
58 |
{ |
|
59 |
text: okText, |
|
60 |
role: 'ok', |
|
61 |
handler: onOk |
|
62 |
} |
|
63 |
] |
|
64 |
}; |
|
65 |
this._present(options); |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* 输入框 |
|
70 |
*/ |
|
71 |
prompt( |
|
72 |
msg: string, |
|
73 |
inputName: string, |
|
74 |
inputPlaceholer: string, |
|
75 |
onOk: (data: any) => void, |
|
76 |
onCancel = (data: any) => { }, |
|
77 |
okText = '确定', |
|
78 |
cancelText = '' |
|
79 |
) { |
|
80 |
this._present({ |
|
81 |
title: '请输入', |
|
82 |
subTitle: msg, |
|
83 |
inputs: [ |
|
84 |
{ |
|
85 |
name: inputName, |
|
86 |
placeholder: inputPlaceholer |
|
87 |
} |
|
88 |
], |
|
89 |
buttons: [ |
|
90 |
{ |
|
91 |
text: cancelText, |
|
92 |
role: 'cancel', |
|
93 |
handler: onCancel |
|
94 |
}, |
|
95 |
{ |
|
96 |
text: okText, |
|
97 |
role: 'ok', |
|
98 |
handler: onOk |
|
99 |
} |
|
100 |
] |
|
101 |
}); |
|
102 |
} |
|
103 |
|
|
104 |
private _present(options: AlertOptions) { |
|
105 |
options.cssClass = 'messagebox'; |
|
106 |
let alert = this.alertCtrl.create(options); |
|
107 |
alert.present(); |
|
108 |
} |
|
109 |
} |