iTest.html
8.55 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
<style>
#interface_test_page .result_wrap {
height: calc(100% - 70px);
margin-top: 25px;
}
#interface_test_page .col-md-2 {
padding: 0;
}
#interface_test_page .col-md-2:first-child {
padding-left: 15px;
}
</style>
<div class="container-fluid page" id="interface_test_page">
<div class="card">
<div class="card-body" style="height: 100%">
<div class="top_form_card" style="width: 100%;">
<form>
<div class="row">
<div class="col-md-2">
<div class="form-group">
<label class="bmd-label-floating">接口名称</label>
<select class="form-control" name="interfaceName">
<option>getLineInfoByName</option>
<option>getLine</option>
<option selected>carMonitor</option>
<option>getdispatchScreen</option>
</select>
</div>
</div>
<div class="col-md-2 field" style="margin-top: 5px;">
<div class="form-group">
<label class="bmd-label-floating">线路</label>
<div class="ct_auto_wrap line_autocompleter">
<input type="text" name="lineName" required class="form-control" autocomplete="off">
</div>
</div>
</div>
<div class="col-md-2 field">
<div class="form-group">
<label class="bmd-label-floating">走向</label>
<select class="form-control" name="direction">
<option value=0>上行</option>
<option value=1>下行</option>
</select>
</div>
</div>
<div class="col-md-2 field">
<div class="form-group">
<label class="bmd-label-floating">站点</label>
<select class="form-control" name="stopid"></select>
</div>
</div>
<div class="col-md-2 field" style="margin-top: 5px;">
<div class="form-group">
<label class="bmd-label-floating">时间(t)</label>
<input type="text" name="t" class="form-control" value="">
</div>
</div>
<div class="col-md-1">
<div class="form-group">
<button type="submit" class="btn btn-primary btn-raised" style="margin-top: 22px;">
<i class="material-icons">search</i> 请求接口
</button>
</div>
</div>
</div>
</form>
</div>
<div class="result_wrap">
<div class="form-group">
<label for="get_url_text" class="bmd-label-floating">GET</label>
<textarea class="form-control" id="get_url_text" rows="1" spellcheck="false"></textarea>
</div>
<br>
<div class="form-group" style="height: calc(100% - 120px)">
<label for="result_text" class="bmd-label-floating">RESULT</label>
<textarea class="form-control" id="result_text" style="height: 100% !important;" spellcheck="false"></textarea>
</div>
</div>
</div>
</div>
</div>
<script>
(function () {
var wrap = '#interface_test_page';
//切换接口
$('[name=interfaceName]', wrap).on('change', show_fields);
//线路自动补全
$.get('/basic/lines', function (rs) {
var data = [], item;
for (var i = 0, len = rs.length; i < len; i++) {
item = rs[i];
data.push({
code: item.lineCode,
text: item.name,
others: [item.fullChars, item.camelChars]
});
}
gb_ct_autocompleter.build($('.line_autocompleter', wrap), data);
});
//线路选择事件
$('.line_autocompleter input', wrap).on('auto_change', fullStations);
$('select[name=direction]', wrap).on('change', fullStations);
function fullStations() {
var $stopSelect = $('select[name=stopid]', wrap);
/*if(!$stopSelect.is(':visible'))
return;*/
//填充站点下拉框
var lineCode = $('input[name=lineName]', wrap).data('val')
, upDown = $('select[name=direction]', wrap).val();
$.get('/geo_data/stations/' + lineCode + '/' + upDown, function (rs) {
console.log('stations', rs);
var array = rs.stations;
var opts = '<option value="">请选择...</option>';
for (var i = 0, len = array.length; i < len; i++) {
opts += '<option value="' + array[i].stationCode + '">' + array[i].name + '</option>';
}
$stopSelect.html(opts);
});
}
function show_fields() {
var v = $(this).val()
, ns;
if (v == 'getLineInfoByName' || v == 'getLine')
ns = ['lineName', 't'];
else if (v == 'carMonitor')
ns = ['lineName', 'stopid', 'direction', 't'];
else if (v == 'getdispatchScreen')
ns = ['lineName', 'direction', 't'];
$('form .row>div.field', wrap).hide();
$('form .form-group [name]', wrap).each(function () {
if (ns.indexOf($(this).attr('name')) != -1)
$(this).parents('.field').show();
});
}
$('form', wrap).on('submit', function () {
try {
var params = '';
var data = $(this).serializeJSON();
var lineCode = $('input[name=lineName]', wrap).data('val');
var v = data.interfaceName;
if (v == 'getLineInfoByName')
params = '?linename=' + data.lineName;
else if (v == 'getLine')
params = '?lineid=' + lineCode;
else if (v == 'carMonitor')
params = '?lineid=' + lineCode + '&stopid=' + data.stopid + '&direction=' + data.direction;
else if (v == 'getdispatchScreen')
params = '?lineid=' + lineCode + '&direction=' + data.direction;
params += '&t=' + data.t;
var url = '/xxfb/' + v + params
, fullUrl = window.location.href + 'xxfb/' + v + params;
$('#get_url_text').text(fullUrl);
$.ajax({
url: url,
dataType: 'text',
success: function (data) {
$('#result_text').text(formatXml(data));
}
});
} catch (e) {
console.log(e);
}
return false;
});
function formatXml(xml) {
var formatted = '';
var reg = /(>)(<)(\/*)/g;
xml = xml.replace(reg, '$1\r\n$2$3');
var pad = 0;
jQuery.each(xml.split('\r\n'), function(index, node) {
var indent = 0;
if (node.match( /.+<\/\w[^>]*>$/ )) {
indent = 0;
} else if (node.match( /^<\/\w/ )) {
if (pad != 0) {
pad -= 1;
}
} else if (node.match( /^<\w[^>]*[^\/]>.*$/ )) {
indent = 1;
} else {
indent = 0;
}
var padding = '';
for (var i = 0; i < pad; i++) {
padding += ' ';
}
formatted += padding + node + '\r\n';
pad += indent;
});
return formatted;
}
})();
</script>