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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
| import { Injectable } from '@angular/core';
| import { AlertController, AlertOptions, ToastController } from 'ionic-angular';
|
| @Injectable()
| export class MessageBox {
|
| constructor(private alertCtrl: AlertController, private toastCtrl: ToastController) { }
|
| /**
| * Toast提示框
| */
| toast(msg: string, css: string = '') {
| let toast = this.toastCtrl.create({
| message: msg,
| duration: 3000,
| cssClass: css
| });
|
| toast.present();
| }
|
| /** 提示框 */
| alert(msg: string) {
| let options: AlertOptions = {
| title: '',
| subTitle: msg,
| buttons: [
| {
| text: '',
| },
| {
| text: '确定',
| }
| ]
| };
| this._present(options);
| }
|
| /**
| * 确认框
| */
| confirm(
| msg: string,
| onOk: () => void,
| onCancel = () => { },
| okText = '确定',
| cancelText = ''
| ) {
| let options: AlertOptions = {
| title: '',
| message: msg,
| buttons: [
| {
| text: cancelText,
| role: 'cancel',
| handler: onCancel
| },
| {
| text: okText,
| role: 'ok',
| handler: onOk
| }
| ]
| };
| this._present(options);
| }
|
| /**
| * 输入框
| */
| prompt(
| msg: string,
| inputName: string,
| inputPlaceholer: string,
| onOk: (data: any) => void,
| onCancel = (data: any) => { },
| okText = '确定',
| cancelText = ''
| ) {
| this._present({
| title: '请输入',
| subTitle: msg,
| inputs: [
| {
| name: inputName,
| placeholder: inputPlaceholer
| }
| ],
| buttons: [
| {
| text: cancelText,
| role: 'cancel',
| handler: onCancel
| },
| {
| text: okText,
| role: 'ok',
| handler: onOk
| }
| ]
| });
| }
|
| private _present(options: AlertOptions) {
| options.cssClass = 'messagebox';
| let alert = this.alertCtrl.create(options);
| alert.present();
| }
| }
|
|