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
commonModule.factory('messagebox', ['$q', '$translate', 'SweetAlert', function ($q, $translate, SweetAlert) {
'use strict';
var getMsg = function (resultMsg, hasTranslated) {
hasTranslated = hasTranslated || false;
var msg = resultMsg;
if (!hasTranslated) {
msg = $translate.instant(resultMsg);
}
return msg;
};
var success = function (resultMsg, hasTranslated) {
var msg = this.getMsg(resultMsg, hasTranslated)
SweetAlert.success(msg);
};
var warning = function (resultMsg, hasTranslated) {
var msg = this.getMsg(resultMsg, hasTranslated)
SweetAlert.warning(msg);
};
//有确认和取消按钮
var confirm = function (title, text, customClass) {
var deferred = $q.defer();
SweetAlert.swal({
title: title,
text: text,
html: true,
type: "warning",
customClass: customClass || '',
showCancelButton: true,
confirmButtonColor: "#DD6B55",
allowOutsideClick: false,
confirmButtonText: $translate.instant('Confirm'),
cancelButtonText: $translate.instant('Cancel'),
closeOnConfirm: true,
closeOnCancel: true
},
function (isConfirm) {
deferred.resolve(isConfirm);
});
return deferred.promise;
};
//没有取消按钮
var info = function (title, text, customClass) {
var deferred = $q.defer();
SweetAlert.swal({
title: title,
text: text,
html: true,
type: "warning",
customClass: customClass || '',
showCancelButton: false,
confirmButtonColor: "#DD6B55",
allowOutsideClick: false,
confirmButtonText: $translate.instant('Confirm'),
cancelButtonText: $translate.instant('Cancel'),
closeOnConfirm: true,
closeOnCancel: false
},
function (isConfirm) {
deferred.resolve(isConfirm);
});
return deferred.promise;
};
return {
getMsg: getMsg,
success: success,
warning: warning,
confirm: confirm,
info: info
}
}]);