|
@@ -8,394 +8,414 @@ |
|
@@ -8,394 +8,414 @@ |
8
|
*/
|
8
|
*/
|
9
|
|
9
|
|
10
|
layui.define(['laytpl', 'layer'], function(exports){
|
10
|
layui.define(['laytpl', 'layer'], function(exports){
|
11
|
- var $ = layui.jquery
|
|
|
12
|
- ,laytpl = layui.laytpl
|
|
|
13
|
- ,layer = layui.layer
|
|
|
14
|
- ,setter = layui.setter
|
|
|
15
|
- ,hint = layui.hint()
|
|
|
16
|
-
|
|
|
17
|
- //对外接口
|
|
|
18
|
- ,view = function(id){
|
|
|
19
|
- return new Class(id);
|
|
|
20
|
- }
|
|
|
21
|
-
|
|
|
22
|
- ,SHOW = 'layui-show', LAY_BODY = 'LAY_app_body'
|
|
|
23
|
-
|
|
|
24
|
- //构造器
|
|
|
25
|
- ,Class = function(id){
|
|
|
26
|
- this.id = id;
|
|
|
27
|
- this.container = $('#'+(id || LAY_BODY));
|
|
|
28
|
- };
|
|
|
29
|
-
|
|
|
30
|
- //加载中
|
|
|
31
|
- view.loading = function(elem){
|
|
|
32
|
- elem.append(
|
|
|
33
|
- this.elemLoad = $('<i class="layui-anim layui-anim-rotate layui-anim-loop layui-icon layadmin-loading"></i>')
|
|
|
34
|
- );
|
|
|
35
|
- };
|
|
|
36
|
-
|
|
|
37
|
- //移除加载
|
|
|
38
|
- view.removeLoad = function(){
|
|
|
39
|
- this.elemLoad && this.elemLoad.remove();
|
|
|
40
|
- };
|
|
|
41
|
-
|
|
|
42
|
- //清除 token,并跳转到登入页
|
|
|
43
|
- view.exit = function(){
|
|
|
44
|
- layui.use(['sessions','common'], function () {
|
|
|
45
|
- var sessions = layui.sessions;
|
|
|
46
|
- var common = layui.common;
|
|
|
47
|
- layer.closeAll();//关闭所有弹框
|
|
|
48
|
- var accessToken = "";
|
|
|
49
|
- if(sessions.getToken() && sessions.getToken().access_token){
|
|
|
50
|
- accessToken = sessions.getToken().access_token;
|
|
|
51
|
- $.ajax({
|
|
|
52
|
- url: common.domainName + '/api-auth/oauth/remove/token?access_token=' + accessToken,
|
|
|
53
|
- type: 'POST',
|
|
|
54
|
- data: {
|
|
|
55
|
- access_token: accessToken
|
|
|
56
|
- }
|
|
|
57
|
- });
|
11
|
+ var $ = layui.jquery
|
|
|
12
|
+ ,laytpl = layui.laytpl
|
|
|
13
|
+ ,layer = layui.layer
|
|
|
14
|
+ ,setter = layui.setter
|
|
|
15
|
+ ,hint = layui.hint()
|
|
|
16
|
+
|
|
|
17
|
+ //对外接口
|
|
|
18
|
+ ,view = function(id){
|
|
|
19
|
+ return new Class(id);
|
58
|
}
|
20
|
}
|
59
|
- sessions.removeToken();
|
|
|
60
|
- sessionStorage.removeItem("initTips");
|
|
|
61
|
- //清空本地记录的 token
|
|
|
62
|
- layui.data(setter.tableName, {
|
|
|
63
|
- key: setter.request.tokenName
|
|
|
64
|
- ,remove: true
|
|
|
65
|
- });
|
|
|
66
|
- location.reload()
|
|
|
67
|
- });
|
|
|
68
|
- };
|
|
|
69
|
-
|
|
|
70
|
- //Ajax请求
|
|
|
71
|
- view.req = function(options){
|
|
|
72
|
- var that = this
|
|
|
73
|
- ,success = options.success
|
|
|
74
|
- ,error = options.error
|
|
|
75
|
- ,request = setter.request
|
|
|
76
|
- ,response = setter.response
|
|
|
77
|
- ,debug = function(){
|
|
|
78
|
- return setter.debug
|
|
|
79
|
- ? '<br><cite>URL:</cite>' + options.url
|
|
|
80
|
- : '';
|
21
|
+
|
|
|
22
|
+ ,SHOW = 'layui-show', LAY_BODY = 'LAY_app_body'
|
|
|
23
|
+
|
|
|
24
|
+ //构造器
|
|
|
25
|
+ ,Class = function(id){
|
|
|
26
|
+ this.id = id;
|
|
|
27
|
+ this.container = $('#'+(id || LAY_BODY));
|
|
|
28
|
+ };
|
|
|
29
|
+
|
|
|
30
|
+ //加载中
|
|
|
31
|
+ view.loading = function(elem){
|
|
|
32
|
+ elem.append(
|
|
|
33
|
+ this.elemLoad = $('<i class="layui-anim layui-anim-rotate layui-anim-loop layui-icon layadmin-loading"></i>')
|
|
|
34
|
+ );
|
81
|
};
|
35
|
};
|
82
|
|
36
|
|
83
|
- options.data = options.data || {};
|
|
|
84
|
- options.headers = options.headers || {};
|
|
|
85
|
-
|
|
|
86
|
- if(request.tokenName){
|
|
|
87
|
- var sendData = typeof options.data === 'string'
|
|
|
88
|
- ? JSON.parse(options.data)
|
|
|
89
|
- : options.data;
|
|
|
90
|
-
|
|
|
91
|
- //自动给参数传入默认 token
|
|
|
92
|
- options.data[request.tokenName] = request.tokenName in sendData
|
|
|
93
|
- ? options.data[request.tokenName]
|
|
|
94
|
- : (layui.data(setter.tableName)[request.tokenName] || '');
|
|
|
95
|
-
|
|
|
96
|
- // //自动给 Request Headers 传入 token,自动拼接了头部会让浏览器认为是非简单请求,就会导致OPTIONS请求
|
|
|
97
|
- // options.headers[request.tokenName] = request.tokenName in options.headers
|
|
|
98
|
- // ? options.headers[request.tokenName]
|
|
|
99
|
- // : (layui.data(setter.tableName)[request.tokenName] || '');
|
|
|
100
|
- }
|
|
|
101
|
-
|
|
|
102
|
- delete options.success;
|
|
|
103
|
- delete options.error;
|
|
|
104
|
-
|
|
|
105
|
- return $.ajax($.extend({
|
|
|
106
|
- type: 'get'
|
|
|
107
|
- ,dataType: 'json'
|
|
|
108
|
- ,success: function(res){
|
|
|
109
|
- var statusCode = response.statusCode;
|
|
|
110
|
- //只有 response 的 code 一切正常才执行 done
|
|
|
111
|
- if(res[response.statusName] == statusCode.ok) {
|
|
|
112
|
- typeof options.done === 'function' && options.done(res);
|
|
|
113
|
- }
|
|
|
114
|
- //登录状态失效,清除本地 access_token,并强制跳转到登入页
|
|
|
115
|
- else if(res[response.statusName] == statusCode.logout){
|
|
|
116
|
- layer.msg("登录凭证失效,请重新登录验证!", {
|
37
|
+ //移除加载
|
|
|
38
|
+ view.removeLoad = function(){
|
|
|
39
|
+ this.elemLoad && this.elemLoad.remove();
|
|
|
40
|
+ };
|
|
|
41
|
+
|
|
|
42
|
+ //清除 token,并跳转到登入页
|
|
|
43
|
+ view.exit = function(){
|
|
|
44
|
+ debugger
|
|
|
45
|
+ if(window.top.location.hash == '#/bigscreen/daping'){
|
|
|
46
|
+ layui.use(['commonDetail','DPingdex'], function () {
|
|
|
47
|
+ layer.msg("登录凭证失效,无法查看详情页,如需查看详情页面,请重新登录再次进入大屏页面!", {
|
117
|
icon: 7, time: 3000
|
48
|
icon: 7, time: 3000
|
118
|
- },function () {
|
|
|
119
|
- view.exit();
|
|
|
120
|
});
|
49
|
});
|
121
|
- }
|
|
|
122
|
- //其它异常
|
|
|
123
|
- else {
|
|
|
124
|
- var error = [
|
|
|
125
|
- '<cite>Error:</cite> ' + (res[response.msgName] || '返回状态码异常')
|
|
|
126
|
- ,debug()
|
|
|
127
|
- ].join('');
|
|
|
128
|
- view.error(error);
|
|
|
129
|
- }
|
50
|
+ });
|
|
|
51
|
+ } else {
|
|
|
52
|
+ layer.msg("登录凭证失效,请重新登录验证!", {
|
|
|
53
|
+ icon: 7, time: 3000
|
|
|
54
|
+ }, function () {
|
|
|
55
|
+ layui.use(['sessions','common'], function () {
|
|
|
56
|
+ var sessions = layui.sessions;
|
|
|
57
|
+ var common = layui.common;
|
|
|
58
|
+ layer.closeAll();//关闭所有弹框
|
|
|
59
|
+ var accessToken = "";
|
|
|
60
|
+ if(sessions.getToken() && sessions.getToken().access_token){
|
|
|
61
|
+ accessToken = sessions.getToken().access_token;
|
|
|
62
|
+ $.ajax({
|
|
|
63
|
+ url: common.domainName + '/api-auth/oauth/remove/token?access_token=' + accessToken,
|
|
|
64
|
+ type: 'POST',
|
|
|
65
|
+ data: {
|
|
|
66
|
+ access_token: accessToken
|
|
|
67
|
+ }
|
|
|
68
|
+ });
|
|
|
69
|
+ }
|
|
|
70
|
+ sessions.removeToken();
|
|
|
71
|
+ sessionStorage.removeItem("initTips");
|
|
|
72
|
+ //清空本地记录的 token
|
|
|
73
|
+ layui.data(setter.tableName, {
|
|
|
74
|
+ key: setter.request.tokenName
|
|
|
75
|
+ ,remove: true
|
|
|
76
|
+ });
|
|
|
77
|
+ location.reload()
|
|
|
78
|
+ });
|
|
|
79
|
+ });
|
|
|
80
|
+ }
|
|
|
81
|
+
|
|
|
82
|
+ };
|
|
|
83
|
+
|
|
|
84
|
+ //Ajax请求
|
|
|
85
|
+ view.req = function(options){
|
|
|
86
|
+ var that = this
|
|
|
87
|
+ ,success = options.success
|
|
|
88
|
+ ,error = options.error
|
|
|
89
|
+ ,request = setter.request
|
|
|
90
|
+ ,response = setter.response
|
|
|
91
|
+ ,debug = function(){
|
|
|
92
|
+ return setter.debug
|
|
|
93
|
+ ? '<br><cite>URL:</cite>' + options.url
|
|
|
94
|
+ : '';
|
|
|
95
|
+ };
|
|
|
96
|
+
|
|
|
97
|
+ options.data = options.data || {};
|
|
|
98
|
+ options.headers = options.headers || {};
|
130
|
|
99
|
|
131
|
- //只要 http 状态码正常,无论 response 的 code 是否正常都执行 success
|
|
|
132
|
- typeof success === 'function' && success(res);
|
100
|
+ if(request.tokenName){
|
|
|
101
|
+ var sendData = typeof options.data === 'string'
|
|
|
102
|
+ ? JSON.parse(options.data)
|
|
|
103
|
+ : options.data;
|
|
|
104
|
+
|
|
|
105
|
+ //自动给参数传入默认 token
|
|
|
106
|
+ options.data[request.tokenName] = request.tokenName in sendData
|
|
|
107
|
+ ? options.data[request.tokenName]
|
|
|
108
|
+ : (layui.data(setter.tableName)[request.tokenName] || '');
|
|
|
109
|
+
|
|
|
110
|
+ // //自动给 Request Headers 传入 token,自动拼接了头部会让浏览器认为是非简单请求,就会导致OPTIONS请求
|
|
|
111
|
+ // options.headers[request.tokenName] = request.tokenName in options.headers
|
|
|
112
|
+ // ? options.headers[request.tokenName]
|
|
|
113
|
+ // : (layui.data(setter.tableName)[request.tokenName] || '');
|
133
|
}
|
114
|
}
|
134
|
- ,error: function(e, code){
|
|
|
135
|
- if(window.location.hash.indexOf('page/forward') != -1){
|
|
|
136
|
- return;
|
115
|
+
|
|
|
116
|
+ delete options.success;
|
|
|
117
|
+ delete options.error;
|
|
|
118
|
+
|
|
|
119
|
+ return $.ajax($.extend({
|
|
|
120
|
+ type: 'get'
|
|
|
121
|
+ ,dataType: 'json'
|
|
|
122
|
+ ,success: function(res){
|
|
|
123
|
+ var statusCode = response.statusCode;
|
|
|
124
|
+ //只有 response 的 code 一切正常才执行 done
|
|
|
125
|
+ if(res[response.statusName] == statusCode.ok) {
|
|
|
126
|
+ typeof options.done === 'function' && options.done(res);
|
|
|
127
|
+ }
|
|
|
128
|
+ //登录状态失效,清除本地 access_token,并强制跳转到登入页
|
|
|
129
|
+ else if(res[response.statusName] == statusCode.logout){
|
|
|
130
|
+ // layer.msg("登录凭证失效,请重新登录验证!", {
|
|
|
131
|
+ // icon: 7, time: 3000
|
|
|
132
|
+ // },function () {
|
|
|
133
|
+ // view.exit();
|
|
|
134
|
+ // });
|
|
|
135
|
+
|
|
|
136
|
+ view.exit();
|
|
|
137
|
+ }
|
|
|
138
|
+ //其它异常
|
|
|
139
|
+ else {
|
|
|
140
|
+ var error = [
|
|
|
141
|
+ '<cite>Error:</cite> ' + (res[response.msgName] || '返回状态码异常')
|
|
|
142
|
+ ,debug()
|
|
|
143
|
+ ].join('');
|
|
|
144
|
+ view.error(error);
|
|
|
145
|
+ }
|
|
|
146
|
+
|
|
|
147
|
+ //只要 http 状态码正常,无论 response 的 code 是否正常都执行 success
|
|
|
148
|
+ typeof success === 'function' && success(res);
|
137
|
}
|
149
|
}
|
138
|
- if(e.status == '401'){
|
|
|
139
|
- if(localStorage.getItem('access_token')) {
|
|
|
140
|
- layer.msg("登录凭证失效,请重新登录验证!", {
|
|
|
141
|
- icon: 7, time: 3000
|
|
|
142
|
- }, function () {
|
150
|
+ ,error: function(e, code){
|
|
|
151
|
+ if(window.location.hash.indexOf('page/forward') != -1){
|
|
|
152
|
+ return;
|
|
|
153
|
+ }
|
|
|
154
|
+ if(e.status == '401'){
|
|
|
155
|
+ if(localStorage.getItem('access_token')) {
|
|
|
156
|
+ // layer.msg("登录凭证失效,请重新登录验证!", {
|
|
|
157
|
+ // icon: 7, time: 3000
|
|
|
158
|
+ // }, function () {
|
|
|
159
|
+ // view.exit();
|
|
|
160
|
+ // });
|
143
|
view.exit();
|
161
|
view.exit();
|
|
|
162
|
+ }
|
|
|
163
|
+ }else if(e.status == '500'){
|
|
|
164
|
+ // layer.msg("服务异常,请联系管理员!</br>错误信息:"+e.responseJSON["resp_msg"], {
|
|
|
165
|
+ // icon: 7, time: 5000
|
|
|
166
|
+ // });
|
|
|
167
|
+ console.error("服务异常,请联系管理员",e);
|
|
|
168
|
+ }else if(e.status == '403'){
|
|
|
169
|
+ layer.msg("无权限访问,请联系管理员!", {
|
|
|
170
|
+ icon: 7, time: 5000
|
144
|
});
|
171
|
});
|
|
|
172
|
+ } else {
|
|
|
173
|
+ // var errorMsg = [
|
|
|
174
|
+ // '请求异常,请重试<br><cite>错误信息:</cite>' + code
|
|
|
175
|
+ // , debug()
|
|
|
176
|
+ // ].join('');
|
|
|
177
|
+ // view.error(errorMsg);
|
|
|
178
|
+ console.error("'请求异常,请重试",e);
|
145
|
}
|
179
|
}
|
146
|
- }else if(e.status == '500'){
|
|
|
147
|
- // layer.msg("服务异常,请联系管理员!</br>错误信息:"+e.responseJSON["resp_msg"], {
|
|
|
148
|
- // icon: 7, time: 5000
|
|
|
149
|
- // });
|
|
|
150
|
- console.error("服务异常,请联系管理员",e);
|
|
|
151
|
- }else if(e.status == '403'){
|
|
|
152
|
- layer.msg("无权限访问,请联系管理员!", {
|
|
|
153
|
- icon: 7, time: 5000
|
180
|
+ typeof error === 'function' && error(e, code);
|
|
|
181
|
+ }
|
|
|
182
|
+ }, { data: { access_token: request.tokenName } },options));
|
|
|
183
|
+
|
|
|
184
|
+ };
|
|
|
185
|
+
|
|
|
186
|
+ //弹窗
|
|
|
187
|
+ view.popup = function(options){
|
|
|
188
|
+ var success = options.success
|
|
|
189
|
+ ,skin = options.skin;
|
|
|
190
|
+
|
|
|
191
|
+ delete options.success;
|
|
|
192
|
+ delete options.skin;
|
|
|
193
|
+
|
|
|
194
|
+ return layer.open($.extend({
|
|
|
195
|
+ type: 1
|
|
|
196
|
+ ,title: '提示'
|
|
|
197
|
+ ,content: ''
|
|
|
198
|
+ ,id: 'LAY-system-view-popup'
|
|
|
199
|
+ ,skin: 'layui-layer-admin' + (skin ? ' ' + skin : '')
|
|
|
200
|
+ ,shadeClose: true
|
|
|
201
|
+ ,closeBtn: false
|
|
|
202
|
+ ,success: function(layero, index){
|
|
|
203
|
+ var elemClose = $('<i class="layui-icon" close>ဆ</i>');
|
|
|
204
|
+ layero.append(elemClose);
|
|
|
205
|
+ elemClose.on('click', function(){
|
|
|
206
|
+ layer.close(index);
|
154
|
});
|
207
|
});
|
155
|
- } else {
|
|
|
156
|
- // var errorMsg = [
|
|
|
157
|
- // '请求异常,请重试<br><cite>错误信息:</cite>' + code
|
|
|
158
|
- // , debug()
|
|
|
159
|
- // ].join('');
|
|
|
160
|
- // view.error(errorMsg);
|
|
|
161
|
- console.error("'请求异常,请重试",e);
|
208
|
+ typeof success === 'function' && success.apply(this, arguments);
|
162
|
}
|
209
|
}
|
163
|
- typeof error === 'function' && error(e, code);
|
|
|
164
|
- }
|
|
|
165
|
- }, { data: { access_token: request.tokenName } },options));
|
|
|
166
|
-
|
|
|
167
|
- };
|
|
|
168
|
-
|
|
|
169
|
- //弹窗
|
|
|
170
|
- view.popup = function(options){
|
|
|
171
|
- var success = options.success
|
|
|
172
|
- ,skin = options.skin;
|
|
|
173
|
-
|
|
|
174
|
- delete options.success;
|
|
|
175
|
- delete options.skin;
|
|
|
176
|
-
|
|
|
177
|
- return layer.open($.extend({
|
|
|
178
|
- type: 1
|
|
|
179
|
- ,title: '提示'
|
|
|
180
|
- ,content: ''
|
|
|
181
|
- ,id: 'LAY-system-view-popup'
|
|
|
182
|
- ,skin: 'layui-layer-admin' + (skin ? ' ' + skin : '')
|
|
|
183
|
- ,shadeClose: true
|
|
|
184
|
- ,closeBtn: false
|
|
|
185
|
- ,success: function(layero, index){
|
|
|
186
|
- var elemClose = $('<i class="layui-icon" close>ဆ</i>');
|
|
|
187
|
- layero.append(elemClose);
|
|
|
188
|
- elemClose.on('click', function(){
|
|
|
189
|
- layer.close(index);
|
|
|
190
|
- });
|
|
|
191
|
- typeof success === 'function' && success.apply(this, arguments);
|
|
|
192
|
- }
|
|
|
193
|
- }, options))
|
|
|
194
|
- };
|
|
|
195
|
-
|
|
|
196
|
- //异常提示
|
|
|
197
|
- view.error = function(content, options){
|
|
|
198
|
- return view.popup($.extend({
|
|
|
199
|
- content: content
|
|
|
200
|
- ,maxWidth: 300
|
|
|
201
|
- //,shade: 0.01
|
|
|
202
|
- ,offset: 't'
|
|
|
203
|
- ,anim: 6
|
|
|
204
|
- ,id: 'LAY_adminError'
|
|
|
205
|
- }, options))
|
|
|
206
|
- };
|
|
|
207
|
-
|
|
|
208
|
-
|
|
|
209
|
- //请求模板文件渲染
|
|
|
210
|
- Class.prototype.render = function(views, params){
|
|
|
211
|
- var that = this, router = layui.router();
|
|
|
212
|
- views = setter.views + views + setter.engine;
|
|
|
213
|
-
|
|
|
214
|
- $('#'+ LAY_BODY).children('.layadmin-loading').remove();
|
|
|
215
|
- view.loading(that.container); //loading
|
|
|
216
|
-
|
|
|
217
|
- //请求模板
|
|
|
218
|
- $.ajax({
|
|
|
219
|
- url: views
|
|
|
220
|
- ,type: 'get'
|
|
|
221
|
- ,dataType: 'html'
|
|
|
222
|
- ,data: {
|
|
|
223
|
- v: layui.cache.version
|
|
|
224
|
- }
|
|
|
225
|
- ,success: function(html){
|
|
|
226
|
- html = '<div>' + html + '</div>';
|
|
|
227
|
-
|
|
|
228
|
- var elemTitle = $(html).find('title')
|
|
|
229
|
- ,title = elemTitle.text() || (html.match(/\<title\>([\s\S]*)\<\/title>/)||[])[1];
|
|
|
230
|
-
|
|
|
231
|
- var res = {
|
|
|
232
|
- title: title
|
|
|
233
|
- ,body: html
|
|
|
234
|
- };
|
210
|
+ }, options))
|
|
|
211
|
+ };
|
235
|
|
212
|
|
236
|
- elemTitle.remove();
|
|
|
237
|
- that.params = params || {}; //获取参数
|
213
|
+ //异常提示
|
|
|
214
|
+ view.error = function(content, options){
|
|
|
215
|
+ return view.popup($.extend({
|
|
|
216
|
+ content: content
|
|
|
217
|
+ ,maxWidth: 300
|
|
|
218
|
+ //,shade: 0.01
|
|
|
219
|
+ ,offset: 't'
|
|
|
220
|
+ ,anim: 6
|
|
|
221
|
+ ,id: 'LAY_adminError'
|
|
|
222
|
+ }, options))
|
|
|
223
|
+ };
|
238
|
|
224
|
|
239
|
- if(that.then){
|
|
|
240
|
- that.then(res);
|
|
|
241
|
- delete that.then;
|
|
|
242
|
- }
|
|
|
243
|
|
225
|
|
244
|
- that.parse(html);
|
|
|
245
|
- view.removeLoad();
|
226
|
+ //请求模板文件渲染
|
|
|
227
|
+ Class.prototype.render = function(views, params){
|
|
|
228
|
+ var that = this, router = layui.router();
|
|
|
229
|
+ views = setter.views + views + setter.engine;
|
246
|
|
230
|
|
247
|
- // 弹框
|
|
|
248
|
- try{
|
|
|
249
|
- layui.pageTips.init();
|
|
|
250
|
- }catch (e) {
|
|
|
251
|
- console.log(e)
|
|
|
252
|
- }
|
|
|
253
|
- if(that.done){
|
|
|
254
|
- that.done(res);
|
|
|
255
|
- delete that.done;
|
|
|
256
|
- }
|
231
|
+ $('#'+ LAY_BODY).children('.layadmin-loading').remove();
|
|
|
232
|
+ view.loading(that.container); //loading
|
257
|
|
233
|
|
258
|
- }
|
|
|
259
|
- ,error: function(e){
|
|
|
260
|
- view.removeLoad();
|
234
|
+ //请求模板
|
|
|
235
|
+ $.ajax({
|
|
|
236
|
+ url: views
|
|
|
237
|
+ ,type: 'get'
|
|
|
238
|
+ ,dataType: 'html'
|
|
|
239
|
+ ,data: {
|
|
|
240
|
+ v: layui.cache.version
|
|
|
241
|
+ }
|
|
|
242
|
+ ,success: function(html){
|
|
|
243
|
+ html = '<div>' + html + '</div>';
|
261
|
|
244
|
|
262
|
- if(that.render.isError){
|
|
|
263
|
- return view.error('请求视图文件异常,状态:'+ e.status);
|
|
|
264
|
- }
|
245
|
+ var elemTitle = $(html).find('title')
|
|
|
246
|
+ ,title = elemTitle.text() || (html.match(/\<title\>([\s\S]*)\<\/title>/)||[])[1];
|
|
|
247
|
+
|
|
|
248
|
+ var res = {
|
|
|
249
|
+ title: title
|
|
|
250
|
+ ,body: html
|
|
|
251
|
+ };
|
|
|
252
|
+
|
|
|
253
|
+ elemTitle.remove();
|
|
|
254
|
+ that.params = params || {}; //获取参数
|
|
|
255
|
+
|
|
|
256
|
+ if(that.then){
|
|
|
257
|
+ that.then(res);
|
|
|
258
|
+ delete that.then;
|
|
|
259
|
+ }
|
|
|
260
|
+
|
|
|
261
|
+ that.parse(html);
|
|
|
262
|
+ view.removeLoad();
|
|
|
263
|
+
|
|
|
264
|
+ // 弹框
|
|
|
265
|
+ try{
|
|
|
266
|
+ if(window.top.location.hash !== '#/bigscreen/daping'){
|
|
|
267
|
+ layui.pageTips.init();
|
|
|
268
|
+ }
|
|
|
269
|
+ }catch (e) {
|
|
|
270
|
+ console.log(e)
|
|
|
271
|
+ }
|
|
|
272
|
+ if(that.done){
|
|
|
273
|
+ that.done(res);
|
|
|
274
|
+ delete that.done;
|
|
|
275
|
+ }
|
265
|
|
276
|
|
266
|
- if(e.status === 404){
|
|
|
267
|
- if(!localStorage.getItem('access_token')) {
|
|
|
268
|
- layer.msg("登录凭证失效,请重新登录验证!", {
|
|
|
269
|
- icon: 7, time: 3000
|
|
|
270
|
- }, function () {
|
|
|
271
|
- view.exit()
|
|
|
272
|
- });
|
|
|
273
|
- } else {
|
|
|
274
|
- that.render('template/tips/404');
|
|
|
275
|
}
|
277
|
}
|
276
|
- } else {
|
|
|
277
|
- that.render('template/tips/error');
|
|
|
278
|
- }
|
278
|
+ ,error: function(e){
|
|
|
279
|
+ view.removeLoad();
|
279
|
|
280
|
|
280
|
- that.render.isError = true;
|
|
|
281
|
- }
|
|
|
282
|
- });
|
|
|
283
|
- return that;
|
|
|
284
|
- };
|
|
|
285
|
-
|
|
|
286
|
- //解析模板
|
|
|
287
|
- Class.prototype.parse = function(html, refresh, callback){
|
|
|
288
|
- var that = this
|
|
|
289
|
- ,isScriptTpl = typeof html === 'object' //是否模板元素
|
|
|
290
|
- ,elem = isScriptTpl ? html : $(html)
|
|
|
291
|
- ,elemTemp = isScriptTpl ? html : elem.find('*[template]')
|
|
|
292
|
- ,fn = function(options){
|
|
|
293
|
- var tpl = laytpl(options.dataElem.html())
|
|
|
294
|
- ,res = $.extend({
|
|
|
295
|
- params: router.params
|
|
|
296
|
- }, options.res);
|
|
|
297
|
-
|
|
|
298
|
- options.dataElem.after(tpl.render(res));
|
|
|
299
|
- typeof callback === 'function' && callback();
|
|
|
300
|
-
|
|
|
301
|
- try {
|
|
|
302
|
- options.done && new Function('d', options.done)(res);
|
|
|
303
|
- } catch(e){
|
|
|
304
|
- console.error(options.dataElem[0], '\n存在错误回调脚本\n\n', e)
|
|
|
305
|
- }
|
|
|
306
|
- }
|
|
|
307
|
- ,router = layui.router();
|
|
|
308
|
-
|
|
|
309
|
- elem.find('title').remove();
|
|
|
310
|
- that.container[refresh ? 'after' : 'html'](elem.children());
|
|
|
311
|
-
|
|
|
312
|
- router.params = that.params || {};
|
|
|
313
|
-
|
|
|
314
|
- //遍历模板区块
|
|
|
315
|
- for(var i = elemTemp.length; i > 0; i--){
|
|
|
316
|
- (function(){
|
|
|
317
|
- var dataElem = elemTemp.eq(i - 1)
|
|
|
318
|
- ,layDone = dataElem.attr('lay-done') || dataElem.attr('lay-then') //获取回调
|
|
|
319
|
- ,url = laytpl(dataElem.attr('lay-url')|| '').render(router) //接口 url
|
|
|
320
|
- ,data = laytpl(dataElem.attr('lay-data')|| '').render(router) //接口参数
|
|
|
321
|
- ,headers = laytpl(dataElem.attr('lay-headers')|| '').render(router); //接口请求的头信息
|
|
|
322
|
-
|
|
|
323
|
- try {
|
|
|
324
|
- data = new Function('return '+ data + ';')();
|
|
|
325
|
- } catch(e) {
|
|
|
326
|
- hint.error('lay-data: ' + e.message);
|
|
|
327
|
- data = {};
|
|
|
328
|
- };
|
281
|
+ if(that.render.isError){
|
|
|
282
|
+ return view.error('请求视图文件异常,状态:'+ e.status);
|
|
|
283
|
+ }
|
329
|
|
284
|
|
330
|
- try {
|
|
|
331
|
- headers = new Function('return '+ headers + ';')();
|
|
|
332
|
- } catch(e) {
|
|
|
333
|
- hint.error('lay-headers: ' + e.message);
|
|
|
334
|
- headers = headers || {}
|
|
|
335
|
- };
|
285
|
+ if(e.status === 404){
|
|
|
286
|
+ if(!localStorage.getItem('access_token')) {
|
|
|
287
|
+ // layer.msg("登录凭证失效,请重新登录验证!", {
|
|
|
288
|
+ // icon: 7, time: 3000
|
|
|
289
|
+ // }, function () {
|
|
|
290
|
+ // view.exit()
|
|
|
291
|
+ // });
|
|
|
292
|
+ view.exit()
|
|
|
293
|
+ } else {
|
|
|
294
|
+ that.render('template/tips/404');
|
|
|
295
|
+ }
|
|
|
296
|
+ } else {
|
|
|
297
|
+ that.render('template/tips/error');
|
|
|
298
|
+ }
|
336
|
|
299
|
|
337
|
- if(url){
|
|
|
338
|
- view.req({
|
|
|
339
|
- type: dataElem.attr('lay-type') || 'get'
|
|
|
340
|
- ,url: url
|
|
|
341
|
- ,data: data
|
|
|
342
|
- ,dataType: 'json'
|
|
|
343
|
- ,headers: headers
|
|
|
344
|
- ,success: function(res){
|
|
|
345
|
- fn({
|
|
|
346
|
- dataElem: dataElem
|
|
|
347
|
- ,res: res
|
|
|
348
|
- ,done: layDone
|
|
|
349
|
- });
|
300
|
+ that.render.isError = true;
|
350
|
}
|
301
|
}
|
351
|
- });
|
|
|
352
|
- } else {
|
|
|
353
|
- fn({
|
|
|
354
|
- dataElem: dataElem
|
|
|
355
|
- ,done: layDone
|
|
|
356
|
- });
|
302
|
+ });
|
|
|
303
|
+ return that;
|
|
|
304
|
+ };
|
|
|
305
|
+
|
|
|
306
|
+ //解析模板
|
|
|
307
|
+ Class.prototype.parse = function(html, refresh, callback){
|
|
|
308
|
+ var that = this
|
|
|
309
|
+ ,isScriptTpl = typeof html === 'object' //是否模板元素
|
|
|
310
|
+ ,elem = isScriptTpl ? html : $(html)
|
|
|
311
|
+ ,elemTemp = isScriptTpl ? html : elem.find('*[template]')
|
|
|
312
|
+ ,fn = function(options){
|
|
|
313
|
+ var tpl = laytpl(options.dataElem.html())
|
|
|
314
|
+ ,res = $.extend({
|
|
|
315
|
+ params: router.params
|
|
|
316
|
+ }, options.res);
|
|
|
317
|
+
|
|
|
318
|
+ options.dataElem.after(tpl.render(res));
|
|
|
319
|
+ typeof callback === 'function' && callback();
|
|
|
320
|
+
|
|
|
321
|
+ try {
|
|
|
322
|
+ options.done && new Function('d', options.done)(res);
|
|
|
323
|
+ } catch(e){
|
|
|
324
|
+ console.error(options.dataElem[0], '\n存在错误回调脚本\n\n', e)
|
|
|
325
|
+ }
|
|
|
326
|
+ }
|
|
|
327
|
+ ,router = layui.router();
|
|
|
328
|
+
|
|
|
329
|
+ elem.find('title').remove();
|
|
|
330
|
+ that.container[refresh ? 'after' : 'html'](elem.children());
|
|
|
331
|
+
|
|
|
332
|
+ router.params = that.params || {};
|
|
|
333
|
+
|
|
|
334
|
+ //遍历模板区块
|
|
|
335
|
+ for(var i = elemTemp.length; i > 0; i--){
|
|
|
336
|
+ (function(){
|
|
|
337
|
+ var dataElem = elemTemp.eq(i - 1)
|
|
|
338
|
+ ,layDone = dataElem.attr('lay-done') || dataElem.attr('lay-then') //获取回调
|
|
|
339
|
+ ,url = laytpl(dataElem.attr('lay-url')|| '').render(router) //接口 url
|
|
|
340
|
+ ,data = laytpl(dataElem.attr('lay-data')|| '').render(router) //接口参数
|
|
|
341
|
+ ,headers = laytpl(dataElem.attr('lay-headers')|| '').render(router); //接口请求的头信息
|
|
|
342
|
+
|
|
|
343
|
+ try {
|
|
|
344
|
+ data = new Function('return '+ data + ';')();
|
|
|
345
|
+ } catch(e) {
|
|
|
346
|
+ hint.error('lay-data: ' + e.message);
|
|
|
347
|
+ data = {};
|
|
|
348
|
+ };
|
|
|
349
|
+
|
|
|
350
|
+ try {
|
|
|
351
|
+ headers = new Function('return '+ headers + ';')();
|
|
|
352
|
+ } catch(e) {
|
|
|
353
|
+ hint.error('lay-headers: ' + e.message);
|
|
|
354
|
+ headers = headers || {}
|
|
|
355
|
+ };
|
|
|
356
|
+
|
|
|
357
|
+ if(url){
|
|
|
358
|
+ view.req({
|
|
|
359
|
+ type: dataElem.attr('lay-type') || 'get'
|
|
|
360
|
+ ,url: url
|
|
|
361
|
+ ,data: data
|
|
|
362
|
+ ,dataType: 'json'
|
|
|
363
|
+ ,headers: headers
|
|
|
364
|
+ ,success: function(res){
|
|
|
365
|
+ fn({
|
|
|
366
|
+ dataElem: dataElem
|
|
|
367
|
+ ,res: res
|
|
|
368
|
+ ,done: layDone
|
|
|
369
|
+ });
|
|
|
370
|
+ }
|
|
|
371
|
+ });
|
|
|
372
|
+ } else {
|
|
|
373
|
+ fn({
|
|
|
374
|
+ dataElem: dataElem
|
|
|
375
|
+ ,done: layDone
|
|
|
376
|
+ });
|
|
|
377
|
+ }
|
|
|
378
|
+ }());
|
357
|
}
|
379
|
}
|
358
|
- }());
|
|
|
359
|
- }
|
|
|
360
|
-
|
|
|
361
|
- return that;
|
|
|
362
|
- };
|
|
|
363
|
-
|
|
|
364
|
- //直接渲染字符
|
|
|
365
|
- Class.prototype.send = function(views, data){
|
|
|
366
|
- var tpl = laytpl(views || this.container.html()).render(data || {});
|
|
|
367
|
- this.container.html(tpl);
|
|
|
368
|
- return this;
|
|
|
369
|
- };
|
|
|
370
|
-
|
|
|
371
|
- //局部刷新模板
|
|
|
372
|
- Class.prototype.refresh = function(callback){
|
|
|
373
|
- var that = this
|
|
|
374
|
- ,next = that.container.next()
|
|
|
375
|
- ,templateid = next.attr('lay-templateid');
|
|
|
376
|
-
|
|
|
377
|
- if(that.id != templateid) return that;
|
|
|
378
|
-
|
|
|
379
|
- that.parse(that.container, 'refresh', function(){
|
|
|
380
|
- that.container.siblings('[lay-templateid="'+ that.id +'"]:last').remove();
|
|
|
381
|
- typeof callback === 'function' && callback();
|
|
|
382
|
- });
|
|
|
383
|
-
|
|
|
384
|
- return that;
|
|
|
385
|
- };
|
|
|
386
|
-
|
|
|
387
|
- //视图请求成功后的回调
|
|
|
388
|
- Class.prototype.then = function(callback){
|
|
|
389
|
- this.then = callback;
|
|
|
390
|
- return this;
|
|
|
391
|
- };
|
|
|
392
|
-
|
|
|
393
|
- //视图渲染完毕后的回调
|
|
|
394
|
- Class.prototype.done = function(callback){
|
|
|
395
|
- this.done = callback;
|
|
|
396
|
- return this;
|
|
|
397
|
- };
|
|
|
398
|
-
|
|
|
399
|
- //对外接口
|
|
|
400
|
- exports('view', view);
|
380
|
+
|
|
|
381
|
+ return that;
|
|
|
382
|
+ };
|
|
|
383
|
+
|
|
|
384
|
+ //直接渲染字符
|
|
|
385
|
+ Class.prototype.send = function(views, data){
|
|
|
386
|
+ var tpl = laytpl(views || this.container.html()).render(data || {});
|
|
|
387
|
+ this.container.html(tpl);
|
|
|
388
|
+ return this;
|
|
|
389
|
+ };
|
|
|
390
|
+
|
|
|
391
|
+ //局部刷新模板
|
|
|
392
|
+ Class.prototype.refresh = function(callback){
|
|
|
393
|
+ var that = this
|
|
|
394
|
+ ,next = that.container.next()
|
|
|
395
|
+ ,templateid = next.attr('lay-templateid');
|
|
|
396
|
+
|
|
|
397
|
+ if(that.id != templateid) return that;
|
|
|
398
|
+
|
|
|
399
|
+ that.parse(that.container, 'refresh', function(){
|
|
|
400
|
+ that.container.siblings('[lay-templateid="'+ that.id +'"]:last').remove();
|
|
|
401
|
+ typeof callback === 'function' && callback();
|
|
|
402
|
+ });
|
|
|
403
|
+
|
|
|
404
|
+ return that;
|
|
|
405
|
+ };
|
|
|
406
|
+
|
|
|
407
|
+ //视图请求成功后的回调
|
|
|
408
|
+ Class.prototype.then = function(callback){
|
|
|
409
|
+ this.then = callback;
|
|
|
410
|
+ return this;
|
|
|
411
|
+ };
|
|
|
412
|
+
|
|
|
413
|
+ //视图渲染完毕后的回调
|
|
|
414
|
+ Class.prototype.done = function(callback){
|
|
|
415
|
+ this.done = callback;
|
|
|
416
|
+ return this;
|
|
|
417
|
+ };
|
|
|
418
|
+
|
|
|
419
|
+ //对外接口
|
|
|
420
|
+ exports('view', view);
|
401
|
}); |
421
|
}); |