Skip to content

Commit 66e21ba

Browse files
committed
Java: MultiDataSource 更新内置 APIAuto
1 parent 8966025 commit 66e21ba

File tree

5 files changed

+48
-20
lines changed

5 files changed

+48
-20
lines changed

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/apijson/CodeUtil.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,8 @@ var CodeUtil = {
294294

295295

296296
getOperation: function (method, json) {
297-
var method = StringUtil.toLowerCase(method)
297+
var ind = method == null ? -1 : method.indexOf('?');
298+
var method = StringUtil.toLowerCase(ind < 0 ? method : method.substring(0, ind));
298299
if (method.startsWith('insert') || method.startsWith('post') || method.startsWith('add')
299300
|| method.startsWith('pub') || method.startsWith('write')) {
300301
return 'INSERT'
@@ -5791,10 +5792,17 @@ var CodeUtil = {
57915792
* @param depth
57925793
* @return {string}
57935794
*/
5794-
getBlank: function(depth) {
5795+
getBlank: function(depth, unit) {
57955796
var s = '';
5797+
var one = ' ';
5798+
if (unit != null && unit > 0 && unit != 4) {
5799+
one = ''
5800+
for (var i = 0; i < unit; i ++) {
5801+
one += ' ';
5802+
}
5803+
}
57965804
for (var i = 0; i < depth; i ++) {
5797-
s += ' ';
5805+
s += one;
57985806
}
57995807
return s;
58005808
},
@@ -6724,6 +6732,8 @@ var CodeUtil = {
67246732
}
67256733
else {
67266734
//功能符 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
6735+
var ind = method == null ? -1 : method.indexOf('?');
6736+
method = ind < 0 ? method : method.substring(0, ind);
67276737

67286738
if (columnName.endsWith("()")) {//方法,查询完后处理,先用一个Map<key,function>保存?
67296739
if (['GET', 'HEAD'].indexOf(method) < 0) {

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/apijson/JSONObject.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ var JSONObject = {
7878
method = method || 'get';
7979
var isRestful = true;
8080

81+
var ind = method.indexOf('?');
82+
if (ind >= 0) {
83+
method = method.substring(0, ind);
84+
}
85+
8186
if (method.startsWith("/")) {
8287
method = method.substring(1);
8388
}

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/apijson/StringUtil.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,11 @@ var StringUtil = {
175175

176176
join: function (arr, separator) {
177177
return arr == null ? '' : arr.join(separator)
178-
}
178+
},
179179

180+
length: function (s) {
181+
return s == null ? 0 : s.length
182+
}
180183
};
181184

182185
if (typeof module == 'object') {

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/index.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@
144144
<button v-show="isShowMethod()" class="transfer" style="width: 60px" id="vMethod" :disabled="isEditResponse" @click="changeMethod()">{{ getMethodName(method, type) }}</button>
145145
<button v-show="isShowType()" class="transfer" id="vType" :disabled="isEditResponse" @click="changeType()">{{ getTypeName(type, method) }}</button>
146146
<div style="height: 100%;display: flex;flex-grow: 1">
147-
<input class="url" id="vUrlComment" :disabled="isEditResponse" type="text" style="width: 100%; position: absolute; z-index: -100; color: darkseagreen;background: #0000;" />
148-
<input class="url" id="vUrl" :disabled="isEditResponse" type="text" @copy="doOnCopy" @paste="doOnPaste" @keyup="doOnKeyUp(event)" placeholder="请输入请求的接口地址,可粘贴浏览器/抓包工具/接口工具 的 Network/Header/Content 等请求信息,自动填充到界面,格式为 key: value" style="z-index: 0; background: #0000;" />
147+
<input class="url" id="vUrlComment" :disabled="isEditResponse" type="text" style="width: 100%; position: absolute; z-index: -100; color: darkseagreen;background: #0000;" ></input>
148+
<textarea class="url" id="vUrl" :disabled="isEditResponse" type="text" @copy="doOnCopy" @paste="doOnPaste" @keyup="doOnKeyUp(event)"
149+
placeholder="请输入请求的接口地址,可粘贴浏览器/抓包工具/接口工具 的 Network/Header/Content 等请求信息,自动填充到界面,格式为 key: value"
150+
style="z-index: 0; background: #0000; padding-left: 2px; padding-right: 1px; scrollbar-width: none; " ></textarea>
149151
</div>
150152
<button class="send" id="vSend" @click="onClickSend()">{{ isEditResponse ? '模拟返回' : '发送请求' }}</button>
151153
</div>

APIJSON-Java-Server/APIJSONBoot-MultiDataSource/src/main/resources/static/js/main.js

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,7 @@ https://github.com/Tencent/APIJSON/issues
12971297
}
12981298

12991299
vUrlComment.value = isSingle || StringUtil.isEmpty(this.urlComment, true)
1300-
? '' : vUrl.value + CodeUtil.getComment(this.urlComment, false, ' ')
1300+
? '' : CodeUtil.getBlank(StringUtil.length(vUrl.value), 1) + CodeUtil.getComment(this.urlComment, false, ' ')
13011301
+ ' - ' + (this.requestVersion > 0 ? 'V' + this.requestVersion : 'V*');
13021302
},
13031303

@@ -1352,11 +1352,11 @@ https://github.com/Tencent/APIJSON/issues
13521352
return ind < 0 ? url.length : index + 3 + ind
13531353
},
13541354
//获取操作方法
1355-
getMethod: function (url) {
1355+
getMethod: function (url, noQuery) {
13561356
var url = new String(url == null ? vUrl.value : url).trim()
13571357
var index = this.getBaseUrlLength(url)
13581358
url = index <= 0 ? url : url.substring(index)
1359-
index = url.indexOf("?")
1359+
index = noQuery ? url.indexOf("?") : -1
13601360
if (index >= 0) {
13611361
url = url.substring(0, index)
13621362
}
@@ -2429,7 +2429,7 @@ https://github.com/Tencent/APIJSON/issues
24292429
const isEditResponse = this.isEditResponse
24302430
const isReleaseRESTful = isExportRandom && btnIndex == 1 && ! isEditResponse
24312431

2432-
const path = App.getMethod();
2432+
const path = this.getMethod();
24332433
const methodInfo = isReleaseRESTful ? (JSONObject.parseUri(path, true) || {}) : {};
24342434
if (isReleaseRESTful) {
24352435
var isRestful = methodInfo.isRestful;
@@ -2471,7 +2471,6 @@ https://github.com/Tencent/APIJSON/issues
24712471

24722472
var commentObj = null;
24732473
if (isExportRandom != true) {
2474-
var m = this.getMethod();
24752474
var commentStddObj = null
24762475
try {
24772476
commentStddObj = JSON.parse(isEditResponse ? tr.standard : doc.standard);
@@ -2483,7 +2482,7 @@ https://github.com/Tencent/APIJSON/issues
24832482
inputObj.code = null // delete inputObj.code
24842483

24852484
commentObj = JSONResponse.updateStandard(commentStddObj, inputObj);
2486-
CodeUtil.parseComment(after, docObj == null ? null : docObj['[]'], m, this.database, this.language, isEditResponse != true, commentObj, true);
2485+
CodeUtil.parseComment(after, docObj == null ? null : docObj['[]'], path, this.database, this.language, isEditResponse != true, commentObj, true);
24872486

24882487
inputObj.code = code_
24892488
}
@@ -5049,7 +5048,7 @@ https://github.com/Tencent/APIJSON/issues
50495048
+ ' \n'; //解决遮挡
50505049

50515050
vUrlComment.value = isSingle || StringUtil.isEmpty(this.urlComment, true)
5052-
? '' : vUrl.value + CodeUtil.getComment(this.urlComment, false, ' ')
5051+
? '' : CodeUtil.getBlank(StringUtil.length(vUrl.value), 1) + CodeUtil.getComment(this.urlComment, false, ' ')
50535052
+ ' - ' + (this.requestVersion > 0 ? 'V' + this.requestVersion : 'V*');
50545053

50555054
if (! isSingle) {
@@ -5063,7 +5062,7 @@ https://github.com/Tencent/APIJSON/issues
50635062
var name = api == null ? null : api.name;
50645063
if (StringUtil.isEmpty(name, true) == false) {
50655064
this.urlComment = name;
5066-
vUrlComment.value = vUrl.value + CodeUtil.getComment(this.urlComment, false, ' ')
5065+
vUrlComment.value = CodeUtil.getBlank(StringUtil.length(vUrl.value), 1) + CodeUtil.getComment(this.urlComment, false, ' ')
50675066
}
50685067
}
50695068

@@ -5478,15 +5477,15 @@ https://github.com/Tencent/APIJSON/issues
54785477
}
54795478

54805479
if (req != null && JSONResponse.getType(req) == 'object') { // 支持 URL 里有 Path Variable,例如 http://apijson.cn:8080/{method}/{table}
5481-
var ind = url.indexOf('?')
5480+
var ind = -1 // 支持 ?id={id} 这种动态参数 url.indexOf('?')
54825481
var uri = ind < 0 ? url : url.substring(0, ind)
54835482

54845483
var newReq = {}
54855484
for (var k in req) {
54865485
var v = k == null ? null : req[k]
54875486
var kind = uri.indexOf('{' + k + '}')
54885487
if (kind >= 0) {
5489-
uri = uri.replaceAll('{' + k + '}', v)
5488+
uri = uri.replaceAll('${' + k + '}', v).replaceAll('{{' + k + '}}', v).replaceAll('{' + k + '}', v)
54905489
continue
54915490
}
54925491

@@ -5501,9 +5500,9 @@ https://github.com/Tencent/APIJSON/issues
55015500
axios({
55025501
method: method != null ? method : (HTTP_METHODS.indexOf(type) >= 0 ? type.toLowerCase() : (type == REQUEST_TYPE_PARAM ? 'get' : 'post')),
55035502
url: (isDelegate ? (
5504-
App.server + '/delegate?' + (type == REQUEST_TYPE_GRPC ? '$_type=GRPC&' : '')
5505-
+ (StringUtil.isEmpty(App.delegateId, true) ? '' : '$_delegate_id=' + App.delegateId + '&')
5506-
+ '$_delegate_url=' + encodeURIComponent(url)
5503+
App.server + '/delegate?$_type=' + (type || REQUEST_TYPE_JSON)
5504+
+ (StringUtil.isEmpty(App.delegateId, true) ? '' : '&$_delegate_id=' + App.delegateId)
5505+
+ '&$_delegate_url=' + encodeURIComponent(url)
55075506
+ (StringUtil.isEmpty(hs, true) ? '' : '&$_headers=' + encodeURIComponent(hs.trim()))
55085507
) : (
55095508
App.isEncodeEnabled ? encodeURI(url) : url
@@ -6137,6 +6136,9 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea
61376136
}
61386137

61396138
if (type == null) {
6139+
// 无效,这时已经换行了 if (event.target == vUrl) {
6140+
// event.preventDefault();
6141+
// }
61406142
this.send(false);
61416143
return
61426144
}
@@ -8497,7 +8499,7 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea
84978499
randomId, line
84988500
, (fun == ORDER_INT || args == null ? 0 : args.length)
84998501
+ (fun == ORDER_BAD_BOOL ? BAD_BOOLS.length : (fun == ORDER_BAD_NUM ? BAD_NUMS.length : (fun == ORDER_BAD_STR
8500-
? BAD_STRS.length : (fun == ORDER_BAD_ARR ? BAD_ARRS.length : (fun == ORDER_BAD_OBJ ? BAD_OBJS.length : BADS.length)))))
8502+
? BAD_STRS.length : (fun == ORDER_BAD_ARR ? BAD_ARRS.length : (fun == ORDER_BAD_OBJ ? BAD_OBJS.length : (fun == ORDER_BAD ? BADS.length : 0))))))
85018503
, step
85028504
) + ', ' + value.substring(start + 1);
85038505
}
@@ -10916,6 +10918,12 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea
1091610918

1091710919
var keyCode = event.keyCode;
1091810920
var isEnter = keyCode === 13;
10921+
if (isEnter && target == vUrl) {
10922+
App.send(false);
10923+
event.preventDefault();
10924+
return
10925+
}
10926+
1091910927
var isDel = keyCode === 8 || keyCode === 46; // backspace 和 del
1092010928
var isChar = (keyCode >= 48 && keyCode <= 90) || (keyCode >= 106 && keyCode <= 111) || (keyCode >= 186 && keyCode <= 222);
1092110929

0 commit comments

Comments
 (0)