-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.js
145 lines (145 loc) · 5.9 KB
/
utils.js
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
define(["jquery"],function ($) {
var utils = {
"baseUrl":"http://hd.zjqq.dev/",
"loading" : {
init : function (o) {
var str = '<div class="loading" id="loading"><img style="width: '+o.width+'" src="'+o.gif+'" alt=""></div>'
$(o.target).append(str)
var p = o.target;
if($("#loading").parents(p).css("position")==="static"){
$("#loading").parents(p).css("position","relative")
}
$("#loading").css({
"position":"absolute",
"left":"50%",
"marginLeft":"-66px",
"top":o.top
})
},
show:function () {
$("#loading").show()
},
hide:function () {
$("#loading").hide()
}
},
"alertInfo" : {
init:function () {
var _this = this
var str = '<div id="alertInfo"><div class="cover"></div><div class="cell"><div class="contentCon"></div></div></div>'
$('body').append(str)
var style = '<style>' +
'#alertInfo{position: fixed;width: 100%;height: 100%;left: 0;top: 0;z-index: 9999;display: none;}' +
'#alertInfo .cover{position: absolute;width: 100%;height: 100%;left: 0;top: 0;z-index: -1;background-color: #000;cursor: pointer;opacity: 0.8;filter:alpha(opacity=80);}' +
'#alertInfo .cell{display:table-cell;vertical-align: middle}'+
'#alertInfo .cell .contentCon{width:430px;margin: 0 auto;padding: 35px 0;text-align: center;background-color: #fff;border-radius: 3px}'+
'#alertInfo .cell .contentCon .btn{display: inline-block;margin: 0 10px;min-width: 90px;text-align: center;height: 34px;line-height: 34px;border: 1px solid #fd5b66;border-radius: 3px;color: #fd5b66;cursor: pointer;}'+
'#alertInfo .cell .contentCon .btn:hover{color: #fff;background-color:#fd5b66; }'+
'</style>'
$('body').append(style)
},
show:function (o) {
var _this = this
$("#alertInfo .contentCon").empty()
switch (o.type){//默认图片
case "success":
o.img = o.img?o.img:"/static/backend/utils/images/zy_success.png"
break;
case "error":
o.img = o.img?o.img:"/static/backend/utils/images/zy_error.png"
break;
case "loading":
o.img = o.img?o.img:"/static/backend/utils/images/loading/loading.gif"
break;
default:
break;
}
var str = '';
str += '<img style="margin: 0 auto" src="'+o.img+'"/>';
if(o.title){
str += '<h1 style="font-size: 28px;color: #fd5b66;margin-top: 12px;padding: 0 20px;">'+o.title+'</h1>'
}
if(o.desc){
str += '<p style="color: #878787;margin-top: 10px">'+o.desc+'</p>'
}
if(o.btn&&o.btn.length>0){
str += '<div style="text-align: center;height: 36px;margin-top: 33px">'
for(var i = 0;i<o.btn.length;i++){
str += '<div class="btn">'+o.btn[i].name+'</div>'
}
str += '</div>';
}
$("#alertInfo .contentCon").html(str)
$("#alertInfo .contentCon .btn").on("click",function () {
if(o.btn[$(this).index()].callback){
o.btn[$(this).index()].callback(_this)
}else{
_this.hide()
}
})
$("#alertInfo").css("display","table").fadeIn(200)
$(document).on('click',"#alertInfo .cover",function () {
if(!o.prevent){
_this.hide()
}
})
},
hide:function () {
$("#alertInfo").fadeOut(200)
}
},
"handlerResult":function (data,callback_success) {
console.log(data);
switch (data.code){
case 0:
callback_success()
break;
case -2:
alert("重新登录")
break;
case -1:
var obj = {
"type":"error",
"title":data.msg,
"btn":[
{
"name":"确定"
}
]
}
utils.alertInfo.show(obj);
break;
default:
var obj = {
"type":"error",
"title":"未知错误",
"btn":[
{
"name":"确定"
}
]
}
utils.alertInfo.show(obj);
break;
}
},
"handlerError":function (data) {
var obj = {
"type":"error",
"title":data.msg?data.msg:data.status+' '+data.statusText,
"btn":[
{
"name":"确定"
}
]
}
if(!$("#alertInfo")){
utils.alertInfo.init()
utils.alertInfo.show(obj)
}else{
utils.alertInfo.show(obj)
}
}
}
return utils
})