-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
397 lines (341 loc) · 17.3 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="author" content="https://github.com/cbcfrank" />
<title>ApiBox - A Simple Api Sandbox for any App/Service based on the http</title>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="static/libs/jquery-1.11.1.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="static/libs/bootstrap.min.js"></script>
<!-- Bootstrap -->
<link rel="stylesheet" href="static/css/bootstrap.min.css">
<link rel="stylesheet" href="static/css/jquery.json-viewer.css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="static/libs/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="static/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<script src="static/libs/vue.js"></script>
<script src="static/libs/axios.min.js"></script>
<script src="static/libs/des.js"></script>
<script src="static/libs/jquery.json-viewer.js"></script>
<script src="static/libs/md5.js"></script>
<script src="static/libs/utils.js"></script>
</head>
<body>
<div id="app">
<!-- header -->
<nav class="navbar navbar-default" role="navigation">
<div class="navbar-header"><a class="navbar-brand" href="#">ApiBox - 基于http的微服务沙箱</a></div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li v-bind:class="{ active: current_proj=='demo2' }" v-on:click="change_proj('demo2')"><a href="#">DEMO</a></li>
<li v-bind:class="{ active: current_proj=='sample2' }" v-on:click="change_proj('sample2')"><a href="#">SAMPLE</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-md-4">
<!-- main -->
<div class="form-group">
<label>版本</label>
<select v-model="version" class="form-control">
<option v-for="ver in versionlist" v-bind:value="ver">
{{ ver }}
</option>
</select>
</div>
<div class="form-group">
<label>资源对象</label>
<select v-model="object" class="form-control">
<option v-for="obj in objectlist" v-bind:value="obj.value">
{{ obj.text }}
</option>
</select>
</div>
<div class="form-group">
<label>对象方法</label>
<select v-model="method" class="form-control">
<option v-for="vo in methodlist" v-bind:value="vo.name">
{{ vo.text }}
</option>
</select>
</div>
<!--{{intfName.desc}}-->
<div class="form-group">
<label>HTTP Method</label>
<input type="text" class="form-control" v-model="http_method" readonly />
</div>
<div class="form-group" v-show="custom_headers.length!=0" v-on:click="custom_headers_show = !custom_headers_show">
<label>---------HTTP HEADERS---------(点击展示)</label>
</div>
<div v-if="custom_headers_show">
<div class="form-group" v-for="header in custom_headers">
{{ header.name }}:<input type="text" v-model="header.value" class="form-control" >
</div>
</div>
<div class="form-group" v-show="current_proj!=='apigateway'">
<label>---------ENCRYPTION KEY---------</label>
</div>
<div v-show="current_proj!=='apigateway'">
<div class="form-group">
<input type="text" v-model="encryption_key" class="form-control" >
</div>
</div>
<div class="form-group" v-show="api_public_params.length!=0" v-on:click="api_public_params_show = !api_public_params_show">
<label>---------公用参数---------(点击展示)</label>
</div>
<div v-if="api_public_params_show">
<div class="form-group" v-for="param in api_public_params">
{{ param.name }}:<input type="text" v-model="param.value" class="form-control" >
</div>
</div>
<div class="form-group"><label>---------参数---------</label></div>
<div class="form-group" v-for="param in paramlist">
{{ param.name }}:<input type="text" v-model="param.sample" class="form-control" />
</div>
<!-- <form action="{{intfName.url}}" method="{{intfName.method}}"> -->
<!--<div class="form-group" ng-repeat="param in intfName.param">-->
<!--{{param.name}}-<label>{{param.optional===true?'':'[必填]'}}</label>-->
<!--<pre>{{param.desc}}</pre>-->
<!--<textarea ng-model="param.value" class="form-control" rows="10" ng-if="param.ui=='textarea'"></textarea>-->
<!--<input type="text" class="form-control" ng-model="param.value" ng-if="param.ui!=='textarea'"/>-->
<!--</div>-->
<!--<div class="form-group">cid<input type="text"/>uid<input type="text"/>webkey<input type="text"/></div>-->
<button type="submit" class="btn btn-primary" v-on:click="callApi();">提交</button>
<br/><br/><br/><br/><br/>
<!-- </form> -->
<!-- -- -->
</div>
<!-- 结果 -->
<div class="col-md-6">
<label>URL: {{ url }}/{{ version }}/{{ object }}/{{ method }}</label>
<table class="table table-bordered table-striped table-hover">
<thead>
<tr><th>公用参数</th><th>类型</th><th>是否必填</th><th>最大长度</th>
<th>描述 <button type="button" class="btn btn-info" v-on:click="custom_headers_table_show = !custom_headers_table_show"> 点击(隐藏/展示)公用参数</button></th>
<th>示例值</th>
</tr>
</thead>
<tbody v-if="custom_headers_table_show">
<tr v-for="param in api_public_params"><td>{{ param.name }}</td><td>{{ param.datatype }}</td><td>{{ param.require | bool2str('是', '否') }}</td><td>{{ param.maxlen }}</td><td>{{ param.remark }}</td><td>{{ param.sample }}</td></tr>
</tbody>
</table>
<table class="table table-bordered table-striped table-hover">
<thead>
<tr><th>参数</th><th>类型</th><th>是否必填</th><th>最大长度</th><th>描述</th><th>示例值</th></tr>
</thead>
<tbody>
<tr v-for="param in paramlist"><td>{{ param.name }}</td><td>{{ param.datatype }}</td><td>{{ param.require | bool2str('是', '否') }}</td><td>{{ param.maxlen }}</td><td>{{ param.remark }}</td><td>{{ param.sample }}</td></tr>
</tbody>
</table>
<div class="form-group">
<label>结果返回</label>
<pre id="json-renderer"></pre>
</div>
</div>
</div>
<!-- footer -->
<br/><br/><br/>
<nav class="navbar navbar-default navbar-fixed-bottom" role="navigation" style="text-align:center; display:table-cell; vertical-align:middle;"> apibox </nav>
</div>
</div>
</body>
</html>
<script>
(function(){
Vue.filter('bool2str', function(bool, yes_str, no_str) {
//console.log(bool)
if (bool===true) {
return yes_str
}
return no_str
});
var app = new Vue({
el: '#app',
data: {
domain: '',
url: '',
version: '',
versionlist: [],
http_method: 'GET',
custom_headers: [],
custom_headers_show: false,
custom_headers_table_show: true,
object: '',
objects: {},
objectlist: [],
apilist: [],
api_public_params: [],
api_public_params_show: false,
method: '',
methodlist: [],
paramlist: [],
// resp_data:'',
// resp_data_dec:'',
encryption_key:'',
current_proj:'demo',
},
computed:{},
watch: {
version: function(version){
if (this.objects[version] === undefined) return;
//console.log(this.objects)
//console.log(this.objects[version][0])
this.object = this.objects[version][0]['value']
this.objectlist = this.objects[version]
},
object: function(object){
for(vo in this.objectlist) {
if (this.objectlist[vo]['value']==object) {
this.method = this.apilist[this.version][object][0]['name']
this.methodlist = this.apilist[this.version][object]
}
}
},
method: function (method) {
for(vo in this.methodlist) {
if (this.methodlist[vo]['name']==method) {
this.paramlist = this.methodlist[vo]['params']
if (this.methodlist[vo]['http_method'] != undefined) {
this.http_method = this.methodlist[vo]['http_method']
} else {
this.http_method = 'GET'
}
}
}
}
},
methods: {
change_proj: function (proj_name) {
//console.log(proj_name)
app.version = ''
loadJson(proj_name);
},
callApi: function () {
var apiurl = this.url+ '/' + this.version + '/' + this.object + '/' + this.method
console.log(apiurl)
// console.log(this.custom_headers, this.api_public_params, this.paramlist)
var headers = {}
for (i in this.custom_headers) {
headers[this.custom_headers[i].name] = this.custom_headers[i].value
}
var params = {}
for (i in this.api_public_params) {
params[this.api_public_params[i].name] = this.api_public_params[i].value
}
// 网关涉及到加密,单独处理
if (this.current_proj=='apigateway') {
params['sn'] = (new Date()).valueOf() //new Date().getTime()
params['params'] = {}
for (i in this.paramlist) {
//params['params'][this.paramlist[i].name] = this.paramlist[i].value
params['params'][this.paramlist[i].name] = this.paramlist[i].sample
}
console.log(headers, params)
var req_obj = {
params: {
data: encrypt(headers['X-Dola-Code'], JSON.stringify(params), 'kkk')
},
headers: headers
}
if (this.http_method=='POST') {
axios.post(apiurl, null, req_obj).then(process_resp).catch(process_resp_error);
} else {
axios.get(apiurl, req_obj).then(process_resp).catch(process_resp_error);
}
/*
axios.get(apiurl, {
params: {
data: encrypt(headers['X-Dola-Code'], JSON.stringify(params), 'kkk')
},
headers: headers
}).then(function (response) {
console.log(response)
if ((typeof response.data) == 'object') {
$('#json-renderer').jsonViewer(response.data)
}
//console.log(decrypt(response.headers['x-andy-edoc'], response.data, 'kkk'));
//console.log(JSON.parse(decrypt(response.headers['x-andy-edoc'], response.data, 'kkk')));
//console.log(JSON.parse(JSON.parse(decrypt(response.headers['x-andy-edoc'], response.data, 'kkk'))));
//$('#json-renderer').jsonViewer(decrypt(response.headers['x-andy-edoc'], response.data, 'kkk'));
$('#json-renderer').jsonViewer(JSON.parse(decrypt(response.headers['x-andy-edoc'], response.data, 'kkk')));
//$('#json-renderer').jsonViewer(JSON.parse(JSON.parse(decrypt(response.headers['x-andy-edoc'], response.data, 'kkk'))));
}).catch(function (error) {
console.log(error);
}) */
} else { //内部项目交互
var param_str = ''
for (i in this.paramlist) {
params[this.paramlist[i].name] = this.paramlist[i].sample
}
//console.log(this.encryption_key, params)
//for (var i in params) console.log(i, params[i])
var new_params = ksort(params)
//console.log(this.encryption_key, new_params)
//for (var i in new_params) console.log(i, new_params[i])
delete new_params['_sign']
param_str = http_build_query(new_params)
//console.log(param_str)
//new_params['_sign'] = hex_md5(param_str)
new_params['_sign'] = hex_hmac_md5(this.encryption_key, param_str)
param_str = http_build_query(new_params)
//console.log(param_str)
apiurl = apiurl + '?' + param_str
console.log(apiurl)
axios.get(apiurl, {
headers: headers
}).then(function (response) {
console.log(response)
$('#json-renderer').jsonViewer(response.data)
}).catch(function (error) {
console.log(error);
})
}
}
},
beforeCreate:function(){
//loadJson(app.current_proj);
loadJson('demo2');
}
});
//处理正确响应
function process_resp(response) {
console.log(response);
if ((typeof response.data) == 'object') {
$('#json-renderer').jsonViewer(response.data)
}
$('#json-renderer').jsonViewer(JSON.parse(decrypt(response.headers['x-andy-edoc'], response.data, 'kkk')));
}
//处理错误响应
function process_resp_error(error) {
console.log(error);
}
function loadJson(proj_name){
axios.get('json/'+proj_name+'.json').then(function(response){
// 响应成功回调
//console.log(response)
//console.log(response.data.domain)
//console.log(app.current_proj)
app.current_proj = response.data.name
app.domain = response.data.domain.slice(0, response.data.domain.indexOf('.')) + '.' + window.location.hostname.slice(4);
app.url = response.data.url.replace(response.data.domain, app.domain)
app.version = response.data.version
//app.version = response.data.version_list[0]
app.versionlist = response.data.version_list
app.custom_headers = response.data.custom_headers
app.object = {}
app.objects = response.data.object
app.objectlist = []
app.apilist = response.data.apilist
app.api_public_params = response.data.api_public_params
}).catch(function (error) {
//console.log(error);
});
}
})();
</script>