Doc.tpl
17.8 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
<include file="./Header"/>
<script type="text/javascript">
var apiUrl = '{$apiUrl}';
var paramJson = '';
var wxUser = null;
var cpUser = null;
// 获取domain
function getDomain() {
var domain = $.trim($('#domain').val());
return domain;
}
// 5FC1D7027F00000155735D99E45FFE2F
var FrontLogin = WxLogin.extend({
refreshUserInfo: function (user) {
wxUser = user;
var dpNames = [];
for (var i in user.dpName) {
dpNames.push(user.dpName[i].dpName);
}
var tagNames = [];
for (var i in user.tagName) {
tagNames.push(user.tagName[i].tagName);
}
$('#loginAvatar').attr('src', user.memFace);
$('#loginUsername').html(user.memUsername);
$('#loginUid').html(user.memUid);
$('#loginDepartment').html(dpNames.concat(', '));
$('#loginTag').html(tagNames.concat(', '));
$('#loginMobile').html(user.memMobile);
$('#loginUserid').html(user.memUserid);
$('#uid').val(user.memUid);
},
logout: function (e) {
// 退出前端时, 也退出后台
adminLogin.logout(e);
wxUser = [];
this._super(e);
}
});
// 550071BF7F0000017064C43D0484F00B
var AdminLogin = CpLogin.extend({
refreshUserInfo: function (user) {
cpUser = user;
$('#cpLoginAvatar').attr('src', user.memFace);
$('#cpLoginRealname').html(user.eaRealname);
$('#cpLoginMobile').html(user.eaMobile);
$('#cpLoginEmail').html(user.eaEmail);
$('#cpLoginEaId').html(user.eaId);
$('#cpEaid').val(user.eaId);
},
logout: function (e) {
// 退出后台时, 也退出前端
frontLogin.logout(e);
cpUser = [];
this._super(e);
}
});
// 后台登录
var adminLogin = new AdminLogin();
adminLogin.setDomain(getDomain());
// 前端登录
var frontLogin = new FrontLogin();
frontLogin.setDomain(getDomain());
// 页面加载完成, 开始初始化
$(document).ready(function () {
$('.ui.dropdown').dropdown();
$('.demo .ui.menu .dropdown').dropdown({
on: 'hover'
});
// 获取请求 Json
paramJson = $('#reqParam').val();
// 获取域名(企业标识)
$('#domain').val(enumber);
$('#cpDomain').val(enumber);
// 默认使用通讯录应用标识
$('#identifier').val('Contact');
$('#cpIdentifier').val('Contact');
// 初始化 Api
initApi();
// 获取已登录用户
if (isWxLogin(getCurrentTab())) {
frontLogin.getUser();
} else {
adminLogin.getUser();
}
// 监听请求按钮
$('#sendBtn').click(function () {
if (isLoading) {
return true;
}
isLoading = true;
var params = $('#reqParam').val();
eval('params=' + params);
$.ajax({
url: $('#apiUrl').val(),
type: $('#method').val(),
dataType: "json",
data: params,
success: function (data) {
isLoading = false;
$('#response').val(JSON.stringify(data, null, 4));
if (data.errcode > 0) {
alert("接口错误: " + data.errmsg);
return;
}
},
error: function () {
alert("接口错误, 通讯失败");
isLoading = false;
}
});
});
// 监听初始化按钮
$('#initApiBtn').click(function (e) {
console.log(e);
initApi();
});
// 登录按钮
$('#loginBtn, #cpLoginBtn').click(function (e) {
console.log(e);
var id, identifier;
if ('loginBtn' == $(this).attr('id')) {
identifier = $.trim($('#identifier').val());
id = $.trim($('#uid').val());
} else {
identifier = $.trim($('#cpIdentifier').val());
id = $.trim($('#cpEaid').val());
}
if (id.length != 32) {
alert("请输入正确的id!" + id);
return;
}
if ('loginBtn' == $(this).attr('id')) {
frontLogin.login(id, identifier);
} else {
adminLogin.login(id, identifier);
}
});
// 退出按钮
$("#logoutBtn, #cpLogoutBtn").click(frontLogin.logout);
// tab click 事件
$('#loginTab').on('click', 'a.item', function (e) {
console.log(e);
if (isWxLogin(getCurrentTab())) {
null == wxUser && frontLogin.getUser();
} else {
null == cpUser && adminLogin.getUser();
}
});
});
// 初始化数据
function initApi() {
$('#reqParam').val(paramJson);
$('#apiUrl').val(host + '/' + enumber + '/' + apiUrl);
}
function isWxLogin(tab) {
return 'login_wx' == tab;
}
function getCurrentTab() {
var current = '';
$('#loginTab').children().each(function (e) {
console.log(e);
if ($(this).hasClass('active')) {
current = $(this).data('tab');
return false;
}
});
return current;
}
</script>
<br/>
<div class="ui pointing secondary menu" id="loginTab">
<a class="item active" data-tab="login_wx">微信端登录</a>
<a class="item" data-tab="login_cp">管理后台登录</a>
</div>
<div class="ui tab active segment" data-tab="login_wx">
<div class="ui top attached tabular menu" style="border-bottom: 0;">
<table class="ui striped table" style="border: 0px;">
<tbody>
<tr>
<td style="width: 50%;">
<div class="ui vertical" style="width: 90%;">
<div class="item">
<img id="loginAvatar" class="ui avatar image"/>
<strong>username: </strong><cite id="loginUsername">?</cite>
</div>
<div class="item">
<strong>uid: </strong><cite id="loginUid">?</cite>
</div>
<div class="item">
<strong>department: </strong><cite id="loginDepartment">?</cite>
</div>
<div class="item">
<strong>tag: </strong><cite id="loginTag">?</cite>
</div>
<div class="item">
<strong>mobile: </strong><cite id="loginMobile">?</cite>
</div>
<div class="item">
<strong>userid: </strong><cite id="loginUserid">?</cite>
</div>
</div>
</td>
<td style="width: 50%;">
<div class="ui vertical menu form" style="margin: 0 auto; width: 25rem;">
<a class="active teal item" style="border-color: transparent !important;">微信用户登录</a>
<a class="item">
<input type="text" id="uid" style="width: 16rem;"/>
<div class="ui label" style="margin: .7em auto;">UID</div>
</a>
<div class="item">
<input type="text" id="identifier" style="width: 16rem;"/>
<div class="ui label" style="margin: .7em auto;">Identifier</div>
</div>
<div class="item">
<input type="text" id="domain" style="width: 16rem;" readonly="true"/>
<div class="ui label" style="margin: .7em auto;">Domain</div>
</div>
<div class="ui two bottom attached buttons">
<div id="logoutBtn" class="ui green button">退出</div>
<div id="loginBtn" class="ui blue button">登录</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="ui tab segment" data-tab="login_cp">
<div class="ui top attached tabular menu" style="border-bottom: 0;">
<table class="ui striped table" style="border: 0px;">
<tbody>
<tr>
<td style="width: 50%;">
<div class="ui vertical" style="width: 90%;">
<div class="item">
<img id="cpLoginAvatar" class="ui avatar image"/>
<strong>realname: </strong><cite id="cpLoginRealname">?</cite>
</div>
<div class="item">
<strong>eaId: </strong><cite id="cpLoginEaId">?</cite>
</div>
<div class="item">
<strong>mobile: </strong><cite id="cpLoginMobile">?</cite>
</div>
<div class="item">
<strong>email: </strong><cite id="cpLoginEmail">?</cite>
</div>
</div>
</td>
<td style="width: 50%;">
<div class="ui vertical menu form" style="margin: 0 auto; width: 25rem;">
<a class="active teal item" style="border-color: transparent !important;">管理后台用户登录</a>
<a class="item">
<input type="text" id="cpEaid" style="width: 16rem;"/>
<div class="ui label" style="margin: .7em auto;">EaId</div>
</a>
<div class="item">
<input type="text" id="cpIdentifier" style="width: 16rem;"/>
<div class="ui label" style="margin: .7em auto;">Identifier</div>
</div>
<div class="item">
<input type="text" id="cpDomain" style="width: 16rem;" readonly="true"/>
<div class="ui label" style="margin: .7em auto;">Domain</div>
</div>
<div class="ui two bottom attached buttons">
<div id="cpLogoutBtn" class="ui green button">退出</div>
<div id="cpLoginBtn" class="ui blue button">登录</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="ui horizontal divider" style="margin: 3rem auto;">华丽的分割线</div>
<div class="ui floating message">
<h2 class='ui header'>接口:{$apiUrl}</h2>
<br/>
<span class='ui teal tag label'>
{$comments['description']}
</span>
<div class="ui raised segment">
<span class="ui red ribbon label">接口说明</span>
<div class="ui message">
<p> {$comments['desc']}</p>
</div>
</div>
<script type="text/javascript">
$(function () {
$('.menu .item').tab();
});
</script>
<div class="ui top attached tabular menu">
<a class="active item" data-tab="first"><h4>请求参数</h4></a>
<a class="item" data-tab="second"><h4>返回结果</h4></a>
<a class="item" data-tab="third"><h4>接口测试</h4></a>
<a class="item" data-tab="forth"><h4>O(∩_∩)O哈哈~</h4></a>
</div>
<!-- 请求参数 -->
<div class="ui bottom attached tab active segment" data-tab="first">
<table class="ui red celled striped table">
<thead>
<tr>
<th>参数名字</th>
<th>类型</th>
<th>是否必须</th>
<th>默认值</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<if condition="empty($comments['param'])">
<tr>
<td colspan="5">no param</td>
</tr>
</if>
<foreach name="comments['param']" item="p">
<tr>
<td>{$p['name']}</td>
<td>{$p['type']}</td>
<td>
<if condition="$p['require'] eq 'true'">
<font color="red">必须</font>
<else/>
可选
</if>
</td>
<td style="width:30%;word-wrap:break-word;word-break:break-all;">
<if condition="strlen($p['default']) eq 0&&empty($p['default'])">
无
<else/>
{$p['default']}
</if>
</td>
<td style="width:30%;word-wrap:break-word;word-break:break-all;">{$p['desc']}</td>
</tr>
</foreach>
</tbody>
</table>
<br/>
<h4 class="ui header">
<a href="#">请求数据示例</a>
</h4>
<div class="ui secondary segment">
<pre style="margin: 0;">
<code class="syntax brush-javascript">{$paramExample}</code>
</pre>
</div>
</div>
<!-- 返回参数 -->
<div class="ui bottom attached tab segment" data-tab="second">
<table class="ui green celled striped table">
<thead>
<tr>
<th>返回字段</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<if condition="empty($comments['return'])">
<tr>
<td colspan="3">no return</td>
</tr>
</if>
<foreach name="comments['return']" item="ret">
<tr>
<td>{$ret['name']}</td>
<td>{$ret['type']}</td>
<td style="width:60%;word-wrap:break-word;word-break:break-all;">{$ret['desc']}</td>
</tr>
</foreach>
</tbody>
</table>
<br/>
<h4 class="ui header">
<a href="#">返回数据示例</a>
</h4>
<div class="ui secondary segment">
<pre style="margin: 0;">
<code class="syntax brush-javascript">{$returnExample}</code>
</pre>
</div>
</div>
<!-- 接口测试 -->
<div class="ui bottom attached tab segment" data-tab="third">
<table class="ui striped table" style="border: 0px; width: 90%; margin: 0 auto;">
<tbody>
<tr>
<td>
<div class="ui labeled left input" style="width: 100%;">
<a class="ui label" style="padding: 0;">
<div class="ui selection dropdown" style="min-width: 6em !important;">
<div class="default text">POST</div>
<i class="dropdown icon"></i>
<input id="method" type="hidden" value="POST"/>
<div class="menu">
<div class="item" data-value="POST">POST</div>
<div class="item" data-value="GET">GET</div>
</div>
</div>
</a>
<input type="text" id="apiUrl" placeholder="Api Url..."/>
</div>
</td>
<td style="width: 9em;">
<div id="sendBtn" class="ui blue button">发送请求</div>
</td>
<td style="width: 10em;">
<div id="initApiBtn" class="ui button">初始化数据</div>
</td>
</tr>
</tbody>
</table>
<table class="ui striped table" style="border: 0px;">
<tbody>
<tr>
<td style="width: 33%;">
<div class="ui segment form">
<a class="ui blue ribbon label">请求</a>
<textarea id="reqParam"
style="margin-top: 10px; height: 48em; max-height: 48em;">{$paramJson}</textarea>
</div>
</td>
<td style="width: 33%;">
<div class="ui segment form">
<a class="ui ribbon label">响应</a>
<textarea id="response" style="margin-top: 10px; height: 48em; max-height: 48em;"></textarea>
</div>
</td>
<td style="width: 34%;">
<div class="ui segment form">
<a class="ui green ribbon label">标准响应</a>
<textarea readonly
style="margin-top: 10px; height: 48em; max-height: 48em;">{$returnJson}</textarea>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- 未知参数 -->
<div class="ui bottom attached tab segment" data-tab="forth">你太好奇了, 这样不好......</div>
</div>
<p/>
<include file="./Footer"/>