+
+
+
+
+
退出
From 905fdd3c4c3728751f557d37260c2c4bcd27977a Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sat, 26 Jan 2019 23:07:42 +0800
Subject: [PATCH 021/818] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90?=
=?UTF-8?q?=E6=96=87=E6=A1=A3:=E6=9D=83=E9=99=90Access=E6=96=B0=E5=A2=9Esc?=
=?UTF-8?q?hema=E6=98=BE=E7=A4=BA=E5=B9=B6=E5=9C=A8=E5=8F=B3=E4=BE=A7?=
=?UTF-8?q?=E5=AF=B9=E7=A7=B0=E6=96=B0=E5=A2=9E=20=E8=A1=A8=E5=90=8D(Schem?=
=?UTF-8?q?a)=20=E6=96=B9=E4=BE=BF=E9=98=85=E8=AF=BB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/js/main.js b/js/main.js
index bb2f18e..9885e6f 100755
--- a/js/main.js
+++ b/js/main.js
@@ -1422,7 +1422,7 @@
'Access[]': {
'count': 0,
'Access': {
- '@column': 'name,alias,get,head,gets,heads,post,put,delete',
+ '@column': 'schema,name,alias,get,head,gets,heads,post,put,delete',
'@order': 'date-,name+',
'name()': 'getWithDefault(alias,name)',
'r0()': 'removeKey(alias)'
@@ -1523,8 +1523,8 @@
log('getDoc Access[] = \n' + format(JSON.stringify(list)));
doc += '\n\n\n\n\n\n\n\n\n### 访问权限'
- + ' \n 表名 | 允许 get 的角色 | 允许 head 的角色 | 允许 gets 的角色 | 允许 heads 的角色 | 允许 post 的角色 | 允许 put 的角色 | 允许 delete 的角色'
- + ' \n -------- | -------------- | -------------- | -------------- | -------------- | -------------- | -------------- | -------------- ';
+ + ' \n 表名(Schema) | 允许 get 的角色 | 允许 head 的角色 | 允许 gets 的角色 | 允许 heads 的角色 | 允许 post 的角色 | 允许 put 的角色 | 允许 delete 的角色 | 表名(Schema)'
+ + ' \n -------- | --------- | --------- | --------- | --------- | --------- | --------- | --------- | -------- ';
for (var i = 0; i < list.length; i++) {
item = list[i];
@@ -1534,14 +1534,15 @@
log('getDoc Access[] for i=' + i + ': item = \n' + format(JSON.stringify(item)));
- doc += '\n' + item.name
+ doc += '\n' + (item.name + '(' + item.schema + ')')
+ ' | ' + JSONResponse.getShowString(JSON.parse(item.get))
+ ' | ' + JSONResponse.getShowString(JSON.parse(item.head))
+ ' | ' + JSONResponse.getShowString(JSON.parse(item.gets))
+ ' | ' + JSONResponse.getShowString(JSON.parse(item.heads))
+ ' | ' + JSONResponse.getShowString(JSON.parse(item.post))
+ ' | ' + JSONResponse.getShowString(JSON.parse(item.put))
- + ' | ' + JSONResponse.getShowString(JSON.parse(item.delete));
+ + ' | ' + JSONResponse.getShowString(JSON.parse(item.delete))
+ + ' | ' + (item.name + '(' + item.schema + ')');
}
doc += '\n' //避免没数据时表格显示没有网格
From 00622b5a8acee4a545e2bb9c66c3db63eddcbdae Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sun, 27 Jan 2019 00:28:07 +0800
Subject: [PATCH 022/818] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90?=
=?UTF-8?q?=E6=B3=A8=E9=87=8A:=E6=96=B0=E5=A2=9E=E5=AD=90=E6=9F=A5?=
=?UTF-8?q?=E8=AF=A2=E7=9A=84=E6=B3=A8=E9=87=8A=EF=BC=9B=E5=8A=A0=E5=BC=BA?=
=?UTF-8?q?@role=EF=BC=8C@database=E5=80=BC=E7=9A=84=E6=A0=A1=E9=AA=8C?=
=?UTF-8?q?=EF=BC=8C=E5=A4=A7=E5=B0=8F=E5=86=99=E6=95=8F=E6=84=9F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
apijson/CodeUtil.js | 51 +++++++++++++++++++++++++++++++++++++--------
1 file changed, 42 insertions(+), 9 deletions(-)
diff --git a/apijson/CodeUtil.js b/apijson/CodeUtil.js
index 344e4ff..a172304 100644
--- a/apijson/CodeUtil.js
+++ b/apijson/CodeUtil.js
@@ -36,6 +36,7 @@ var CodeUtil = {
var depth = 0;
var names = [];
+ var isInSubquery = false;
var index;
var key;
@@ -55,14 +56,19 @@ var CodeUtil = {
line = line.trim();
if (line.endsWith('{')) { //对象,判断是不是Table,再加对应的注释
+ isInSubquery = key.endsWith('@');
+
depth ++;
names[depth] = key;
- comment = CodeUtil.getComment4Request(tableList, null, key, null, method);
+
+ comment = CodeUtil.getComment4Request(tableList, names[depth - 1], key, null, method, false);
}
else {
if (line.endsWith('}')) {
+ isInSubquery = false;
+
if (line.endsWith('{}')) { //对象,判断是不是Table,再加对应的注释
- comment = CodeUtil.getComment4Request(tableList, null, key, null, method);
+ comment = CodeUtil.getComment4Request(tableList, names[depth], key, null, method, false);
}
else {
depth --;
@@ -76,7 +82,7 @@ var CodeUtil = {
var isArray = line.endsWith('['); // [] 不影响
// alert('depth = ' + depth + '; line = ' + line + '; isArray = ' + isArray);
comment = value == 'null' ? ' ! null无效' : CodeUtil.getComment4Request(tableList, names[depth], key
- , isArray ? '' : line.substring(index + 2).trim(), method);
+ , isArray ? '' : line.substring(index + 2).trim(), method, isInSubquery);
}
}
@@ -830,6 +836,7 @@ var CodeUtil = {
QUERY_TYPES: ['数据', '数量', '全部'],
+ SUBQUERY_RANGES: ['ANY', 'ALL'],
QUERY_TYPE_KEYS: [0, 1, 2],
QUERY_TYPE_CONSTS: ["JSONRequest.QUERY_TABLE", "JSONRequest.QUERY_TOTAL", "JSONRequest.QUERY_ALL"],
REQUEST_ROLE_KEYS: ['UNKNOWN', 'LOGIN', 'CONTACT', 'CIRCLE', 'OWNER', 'ADMIN'],
@@ -848,16 +855,29 @@ var CodeUtil = {
* @param name
* @param key
* @param value
+ * @param isInSubquery
*/
- getComment4Request: function (tableList, name, key, value, method) {
+ getComment4Request: function (tableList, name, key, value, method, isInSubquery) {
// alert('name = ' + name + '; key = ' + key + '; value = ' + value + '; method = ' + method);
if (key == null) {
return '';
}
+ // if (value == null) {
+ // return ' ! key:value 中 key 或 value 任何一个为 null 时,该 key:value 都无效!'
+ // }
if (value == null || value instanceof Object) {
+ if (key.endsWith('@')) {
+ var aliaIndex = name == null ? -1 : name.indexOf(':');
+ var objName = aliaIndex < 0 ? name : name.substring(0, aliaIndex);
+ // if (JSONObject.isTableKey(objName)) {
+ return CodeUtil.getComment('子查询 < ' + CodeUtil.getCommentFromDoc(tableList, objName, key.substring(0, key.length - 1), method), false, ' ');
+ // }
+ // return CodeUtil.getComment('子查询 ' + StringUtil.get(name), false, ' ');
+ }
+
if (JSONObject.isArrayKey(key)) {
if (method != 'GET') {
return ' ! key[]:{}只支持GET方法!';
@@ -887,7 +907,7 @@ var CodeUtil = {
return '';
}
- if (JSONObject.isArrayKey(name)) {
+ if (isInSubquery || JSONObject.isArrayKey(name)) {
switch (key) {
case 'count':
return CodeUtil.getType4Request(value) != 'number' ? ' ! value必须是Number类型!' : CodeUtil.getComment('最多数量: 例如 5 10 20 ...', false, ' ');
@@ -901,6 +921,19 @@ var CodeUtil = {
return StringUtil.isEmpty(query) ? ' ! value必须是[' + CodeUtil.QUERY_TYPE_KEYS.join() + ']中的一种!' : CodeUtil.getComment('查询内容:0-数据 1-总数 2-全部', false, ' ');
case 'join':
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('多表连接:例如 &/User/id@,
Date: Sun, 27 Jan 2019 00:31:54 +0800
Subject: [PATCH 023/818] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90?=
=?UTF-8?q?=E6=B3=A8=E9=87=8A:=E6=96=B0=E5=A2=9E=E6=98=AF=E5=90=A6?=
=?UTF-8?q?=E5=AD=98=E5=9C=A8=E5=88=A4=E6=96=AD=20key}{=20=E7=9A=84?=
=?UTF-8?q?=E6=B3=A8=E9=87=8A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
apijson/CodeUtil.js | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/apijson/CodeUtil.js b/apijson/CodeUtil.js
index a172304..52dd856 100644
--- a/apijson/CodeUtil.js
+++ b/apijson/CodeUtil.js
@@ -1081,6 +1081,10 @@ var CodeUtil = {
fun = '包含选项';
key = columnName.substring(0, columnName.length - 2);
}
+ else if (columnName.endsWith("}{")) {//存在,EXISTS。查询时处理
+ fun = '是否存在';
+ key = columnName.substring(0, columnName.length - 2);
+ }
else if (columnName.endsWith("+")) {//延长,PUT查询时处理
if (method != 'PUT') {//不为PUT就抛异常
return ' ! 功能符 + - 只能用于PUT请求!';
From 5c580f30fcac064090536fcd77daca04e78b4a21 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sun, 27 Jan 2019 00:37:53 +0800
Subject: [PATCH 024/818] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90?=
=?UTF-8?q?=E4=BB=A3=E7=A0=81:=E5=AD=90=E6=9F=A5=E8=AF=A2=20"key@":{}=20?=
=?UTF-8?q?=E7=94=9F=E6=88=90=E7=9A=84=E5=8F=98=E9=87=8F=E5=90=8D=E5=8E=BB?=
=?UTF-8?q?=E6=8E=89=E5=90=8E=E9=9D=A2=E7=9A=84@,=20=E7=94=B1=20key@=20?=
=?UTF-8?q?=E6=94=B9=E4=B8=BA=20key?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
apijson/JSONResponse.js | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/apijson/JSONResponse.js b/apijson/JSONResponse.js
index 8621488..33b8162 100644
--- a/apijson/JSONResponse.js
+++ b/apijson/JSONResponse.js
@@ -221,7 +221,8 @@ var JSONResponse = {
* @return
*/
formatAt(key) {
- return key.startsWith("@") ? key.substring(1) : key;
+ var k = key.startsWith("@") ? key.substring(1) : key;
+ return k.endsWith("@") ? k.substring(0, k.length - 1) : k;
},
/**key:alias => alias
* @param key
From 30539083370ce5f8937194d9e624ee116109734f Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sun, 27 Jan 2019 01:08:29 +0800
Subject: [PATCH 025/818] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90?=
=?UTF-8?q?=E6=B3=A8=E9=87=8A:=E6=96=B0=E5=A2=9E=E6=95=B0=E6=8D=AE?=
=?UTF-8?q?=E6=9D=A5=E6=BA=90=E7=9A=84=E6=B3=A8=E9=87=8A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
apijson/CodeUtil.js | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/apijson/CodeUtil.js b/apijson/CodeUtil.js
index 52dd856..96c1395 100644
--- a/apijson/CodeUtil.js
+++ b/apijson/CodeUtil.js
@@ -60,7 +60,7 @@ var CodeUtil = {
depth ++;
names[depth] = key;
-
+
comment = CodeUtil.getComment4Request(tableList, names[depth - 1], key, null, method, false);
}
else {
@@ -870,12 +870,16 @@ var CodeUtil = {
if (value == null || value instanceof Object) {
if (key.endsWith('@')) {
+ if (key == '@from@') {
+ return CodeUtil.getComment('数据来源:匿名子查询,例如 {"from":"Table", "Table":{}}', false, ' ');
+ }
+
var aliaIndex = name == null ? -1 : name.indexOf(':');
var objName = aliaIndex < 0 ? name : name.substring(0, aliaIndex);
- // if (JSONObject.isTableKey(objName)) {
+ if (JSONObject.isTableKey(objName)) {
return CodeUtil.getComment('子查询 < ' + CodeUtil.getCommentFromDoc(tableList, objName, key.substring(0, key.length - 1), method), false, ' ');
- // }
- // return CodeUtil.getComment('子查询 ' + StringUtil.get(name), false, ' ');
+ }
+ return CodeUtil.getComment('子查询 ' + StringUtil.get(name) + ",需要被下面的表字段相关 key 引用赋值", false, ' ');
}
if (JSONObject.isArrayKey(key)) {
@@ -945,6 +949,8 @@ var CodeUtil = {
switch (key) {
case '@column':
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('返回字段:例如 id,name;json_length(contactIdList):contactCount;...', false, ' ');
+ case '@from@': //value 类型为 Object 时 到不了这里,已在上方处理
+ return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String或Object类型!' : CodeUtil.getComment('数据来源:引用赋值 子查询 "' + value.substring(1, value.length - 1) + '@":{...} ', false, ' ');
case '@group':
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('分组方式:例如 userId,momentId,...', false, ' ');
case '@having':
From 00a9efc04c9579030158cd009add19546209d4c1 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sun, 27 Jan 2019 01:14:19 +0800
Subject: [PATCH 026/818] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90?=
=?UTF-8?q?=E6=B3=A8=E9=87=8A:=E4=BC=98=E5=8C=96=E5=AD=90=E6=9F=A5?=
=?UTF-8?q?=E8=AF=A2=E5=85=B3=E9=94=AE=E8=AF=8D=20from=20=E7=9A=84?=
=?UTF-8?q?=E6=B3=A8=E9=87=8A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
apijson/CodeUtil.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/apijson/CodeUtil.js b/apijson/CodeUtil.js
index 96c1395..147b812 100644
--- a/apijson/CodeUtil.js
+++ b/apijson/CodeUtil.js
@@ -934,7 +934,7 @@ var CodeUtil = {
}
return CodeUtil.SUBQUERY_RANGES.indexOf(value.substring(1, value.length - 1)) <= 0 ? ' ! value必须是[' + CodeUtil.SUBQUERY_RANGES.join() + ']中的一种!' : CodeUtil.getComment('比较范围:ANY-任意 ALL-全部', false, ' ');
case 'from':
- return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('主表名称:例如 User Comment:to,同一层级必须有对应的 "User": {...}, "Comment:to": {...}', false, ' ');
+ return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('数据来源:例如 User,同一层级必须有对应的 "User": {...}', false, ' ');
}
}
break;
From 04b4ff58dec59c8bbc5a3d017d73736e21d0ebce Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sat, 2 Feb 2019 18:11:51 +0800
Subject: [PATCH 027/818] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90?=
=?UTF-8?q?=E6=B3=A8=E9=87=8A:=E8=A7=A3=E5=86=B3=E5=AF=B9=E5=AD=90?=
=?UTF-8?q?=E6=9F=A5=E8=AF=A2range=E6=A0=A1=E9=AA=8CANY=E5=87=BA=E9=94=99?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
apijson/CodeUtil.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/apijson/CodeUtil.js b/apijson/CodeUtil.js
index 147b812..faf27b1 100644
--- a/apijson/CodeUtil.js
+++ b/apijson/CodeUtil.js
@@ -932,7 +932,7 @@ var CodeUtil = {
if (CodeUtil.getType4Request(value) != 'string') {
return ' ! value必须是String类型!';
}
- return CodeUtil.SUBQUERY_RANGES.indexOf(value.substring(1, value.length - 1)) <= 0 ? ' ! value必须是[' + CodeUtil.SUBQUERY_RANGES.join() + ']中的一种!' : CodeUtil.getComment('比较范围:ANY-任意 ALL-全部', false, ' ');
+ return CodeUtil.SUBQUERY_RANGES.indexOf(value.substring(1, value.length - 1)) < 0 ? ' ! value必须是[' + CodeUtil.SUBQUERY_RANGES.join() + ']中的一种!' : CodeUtil.getComment('比较范围:ANY-任意 ALL-全部', false, ' ');
case 'from':
return CodeUtil.getType4Request(value) != 'string' ? ' ! value必须是String类型!' : CodeUtil.getComment('数据来源:例如 User,同一层级必须有对应的 "User": {...}', false, ' ');
}
From b55636e1b5e3458cfb7aa0b9153378224e2f86fe Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Mon, 11 Feb 2019 18:35:14 +0800
Subject: [PATCH 028/818] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=94=AF=E6=8C=81?=
=?UTF-8?q?=E5=AF=B9=E8=AF=B7=E6=B1=82=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89?=
=?UTF-8?q?=E6=B3=A8=E9=87=8A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 80 ++++++++++++++++++++++++++++++++++--------------------
1 file changed, 50 insertions(+), 30 deletions(-)
diff --git a/js/main.js b/js/main.js
index 9885e6f..bf99163 100755
--- a/js/main.js
+++ b/js/main.js
@@ -323,15 +323,27 @@
},
//获取请求的tag
getTag: function () {
- var req = null
+ var req = null;
try {
- req = JSON.parse(new String(vInput.value))
+ req = this.getRequest(vInput.value);
} catch (e) {
- log('main.getTag', 'try { req = JSON.parse(new String(vInput.value)) \n } catch (e) {\n' + e.message)
+ log('main.getTag', 'try { req = this.getRequest(vInput.value); \n } catch (e) {\n' + e.message)
}
return req == null ? null : req.tag
},
+ getRequest: function (json) {
+ var s = App.toDoubleJSON(json);
+ try {
+ return jsonlint.parse(s);
+ }
+ catch (e) {
+ log('main.getRequest', 'try { return jsonlint.parse(s); \n } catch (e) {\n' + e.message)
+ log('main.getRequest', 'return jsonlint.parse(App.removeComment(s));')
+ return jsonlint.parse(App.removeComment(s));
+ }
+ },
+
// 显示保存弹窗
showSave: function (show) {
if (show) {
@@ -1134,14 +1146,21 @@
before = App.toDoubleJSON(before);
log('onHandle before = \n' + before);
- before = jsonlint.parse(before);
-
- before = JSON.stringify(before, null, " "); //用format不能catch!
+ var after;
+ try {
+ after = JSON.stringify(jsonlint.parse(before), null, " ");
+ before = after;
+ }
+ catch (e) {
+ log('main.onHandle', 'try { return jsonlint.parse(before); \n } catch (e) {\n' + e.message)
+ log('main.onHandle', 'return jsonlint.parse(App.removeComment(before));')
+ after = JSON.stringify(jsonlint.parse(App.removeComment(before)), null, " ");
+ }
//关键词let在IE和Safari上不兼容
var code = '';
try {
- code = this.getCode(before); //必须在before还是用 " 时使用,后面用会因为解析 ' 导致失败
+ code = this.getCode(after); //必须在before还是用 " 时使用,后面用会因为解析 ' 导致失败
} catch(e) {
code = '\n\n\n建议:\n使用其它浏览器,例如 谷歌Chrome、火狐FireFox 或者 微软Edge, 因为这样能自动生成请求代码.'
+ '\nError:\n' + e.message + '\n\n\n';
@@ -1166,7 +1185,7 @@
App.showDoc()
try {
- vComment.value = isSingle ? '' : CodeUtil.parseComment(before, docObj == null ? null : docObj['[]'], App.getMethod())
+ vComment.value = isSingle ? '' : CodeUtil.parseComment(after, docObj == null ? null : docObj['[]'], App.getMethod())
onScrollChanged()
} catch (e) {
@@ -1209,25 +1228,30 @@
// 删除注释 <<<<<<<<<<<<<<<<<<<<<
- var input = new String(vInput.value);
+ var input = this.removeComment(vInput.value);
+ if (vInput.value != input) {
+ vInput.value = input
+ }
+ // 删除注释 >>>>>>>>>>>>>>>>>>>>>
+
+
+ this.onChange();
+ },
+
+ /**
+ * 删除注释
+ */
+ removeComment: function (json) {
var reg = /("([^\\\"]*(\\.)?)*")|('([^\\\']*(\\.)?)*')|(\/{2,}.*?(\r|\n))|(\/\*(\n|.)*?\*\/)/g // 正则表达式
try {
- input = input.replace(reg, function(word) { // 去除注释后的文本
+ return new String(json).replace(reg, function(word) { // 去除注释后的文本
return /^\/{2,}/.test(word) || /^\/\*/.test(word) ? "" : word;
})
-
- if (vInput.value != input) {
- vInput.value = input
- }
} catch (e) {
- log('transfer delete comment in json >> catch \n' + e.message)
+ log('transfer delete comment in json >> catch \n' + e.message);
}
-
- // 删除注释 >>>>>>>>>>>>>>>>>>>>>
-
-
- this.onChange();
+ return json;
},
showAndSend: function (url, req, isAdminOperation, callback) {
@@ -1249,11 +1273,7 @@
clearTimeout(handler);
- var real = new String(vInput.value);
- if (real.indexOf("'") >= 0) {
- real = real.replace(/'/g, "\"");
- }
- var req = JSON.parse(real);
+ var req = this.getRequest(vInput.value);
var url = new String(vUrl.value)
url = url.replace(/ /g, '')
@@ -1274,7 +1294,7 @@
'userId': App.User.id,
'name': App.formatDateTime() + (StringUtil.isEmpty(req.tag, true) ? '' : ' ' + req.tag),
'url': '/' + method,
- 'request': real
+ 'request': JSON.stringify(req, null, ' ')
}
})
App.saveCache('', 'locals', this.locals)
@@ -1746,7 +1766,7 @@
continue
}
doc += '\n\n#### ' + (item.version > 0 ? 'V' + item.version : 'V*') + ' ' + item.name + ' ' + item.url
- doc += '\n```json\n' + JSON.stringify(JSON.parse(item.request), null, ' ') + '\n```\n'
+ doc += '\n```json\n' + item.request + '\n```\n'
}
return doc
},
@@ -1815,7 +1835,7 @@
// App.restore(item)
// App.onChange(false)
- App.request(false, baseUrl + document.url, JSON.parse(document.request), function (url, res, err) {
+ App.request(false, baseUrl + document.url, App.getRequest(document.request), function (url, res, err) {
try {
App.onResponse(url, res, err)
@@ -2000,7 +2020,7 @@
else {
url = App.server + '/post/testrecord/ml'
req = {
- documentId: document.id
+ documentId: document.id
}
}
@@ -2032,7 +2052,7 @@
setRequestHint(index, item) {
var d = item == null ? null : item.Document;
var r = d == null ? null : d.request;
- this.$refs.testCaseTexts[index].setAttribute('data-hint', r == null ? '' : JSON.stringify(JSON.parse(r), null, ' '));
+ this.$refs.testCaseTexts[index].setAttribute('data-hint', r == null ? '' : JSON.stringify(this.getRequest(r), null, ' '));
},
//显示详细信息, :data-hint :data, :hint 都报错,只能这样
setTestHint(index, item) {
From 2e187c6140da0fd21b05738c7870eab5d096c4a0 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sun, 17 Feb 2019 10:56:17 +0800
Subject: [PATCH 029/818] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E4=BB=8E=E6=B5=8B?=
=?UTF-8?q?=E8=AF=95=E7=94=A8=E4=BE=8B=E5=88=87=E6=8D=A2=E4=B8=BA=E8=BE=93?=
=?UTF-8?q?=E5=85=A5=E6=A1=86=E5=90=8E=E6=9C=AA=E6=98=BE=E7=A4=BA=E8=87=AA?=
=?UTF-8?q?=E5=8A=A8=E7=94=9F=E6=88=90=E7=9A=84=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/js/main.js b/js/main.js
index bf99163..993ef54 100755
--- a/js/main.js
+++ b/js/main.js
@@ -1179,7 +1179,7 @@
vInput.value = before;
vSend.disabled = false;
- vOutput.value = 'OK,请点击 [发送请求] 按钮来测试。[点击这里查看视频教程](http://i.youku.com/apijson)' + code;
+ vOutput.value = output = 'OK,请点击 [发送请求] 按钮来测试。[点击这里查看视频教程](http://i.youku.com/apijson)' + code;
App.showDoc()
From 05c864cceb8efcbf8e64993ef3d91c3b132b721e Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sun, 17 Feb 2019 18:30:43 +0800
Subject: [PATCH 030/818] =?UTF-8?q?=E8=A1=A8=E5=92=8C=E5=AD=97=E6=AE=B5?=
=?UTF-8?q?=E5=B1=9E=E6=80=A7key=E5=85=A8=E5=B0=8F=E5=86=99=EF=BC=8C?=
=?UTF-8?q?=E5=87=86=E5=A4=87=E5=85=BC=E5=AE=B9PostgreSQL=EF=BC=9B?=
=?UTF-8?q?=E5=8A=A0=E5=AE=BD=E6=9C=AC=E5=9C=B0=E4=BF=9D=E5=AD=98=E6=B5=8B?=
=?UTF-8?q?=E8=AF=95=E7=9A=84=E9=80=89=E9=A1=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
apijson/CodeUtil.js | 22 +++++++++++-----------
index.html | 2 +-
js/main.js | 26 +++++++++++++-------------
3 files changed, 25 insertions(+), 25 deletions(-)
diff --git a/apijson/CodeUtil.js b/apijson/CodeUtil.js
index faf27b1..294b810 100644
--- a/apijson/CodeUtil.js
+++ b/apijson/CodeUtil.js
@@ -502,7 +502,7 @@ var CodeUtil = {
//Table
table = item == null ? null : item.Table;
- model = CodeUtil.getModelName(table == null ? null : table.TABLE_NAME);
+ model = CodeUtil.getModelName(table == null ? null : table.table_name);
if (model != clazz) {
continue;
}
@@ -515,7 +515,7 @@ var CodeUtil = {
+ '\n\n使用方法\n1.修改包名package \n2.import需要引入的类,可使用快捷键Ctrl+Shift+O '
+ '\n*/\n'
+ '\npackage apijson.demo.server.model;\n\n\n'
- + CodeUtil.getComment(table.TABLE_COMMENT, true)
+ + CodeUtil.getComment(table.table_comment, true)
+ '\n@MethodAccess'
+ '\npublic class ' + model + ' implements Serializable {'
+ '\n private static final long serialVersionUID = 1L;\n';
@@ -532,16 +532,16 @@ var CodeUtil = {
for (var j = 0; j < columnList.length; j++) {
column = columnList[j];
- name = CodeUtil.getFieldName(column == null ? null : column.COLUMN_NAME);
+ name = CodeUtil.getFieldName(column == null ? null : column.column_name);
if (name == '') {
continue;
}
- type = name == 'id' ? 'Long' : CodeUtil.getJavaType(column.COLUMN_TYPE, false);
+ type = name == 'id' ? 'Long' : CodeUtil.getJavaType(column.column_type, false);
console.log('parseJavaBean [] for j=' + j + ': column = \n' + format(JSON.stringify(column)));
- doc += '\n private ' + type + ' ' + name + '; ' + CodeUtil.getComment(column.COLUMN_COMMENT, false);
+ doc += '\n private ' + type + ' ' + name + '; ' + CodeUtil.getComment(column.column_comment, false);
}
@@ -559,11 +559,11 @@ var CodeUtil = {
for (var j = 0; j < columnList.length; j++) {
column = columnList[j];
- name = CodeUtil.getFieldName(column == null ? null : column.COLUMN_NAME);
+ name = CodeUtil.getFieldName(column == null ? null : column.column_name);
if (name == '') {
continue;
}
- type = name == 'id' ? 'Long' : CodeUtil.getJavaType(column.COLUMN_TYPE);
+ type = name == 'id' ? 'Long' : CodeUtil.getJavaType(column.column_type);
console.log('parseJavaBean [] for j=' + j + ': column = \n' + format(JSON.stringify(column)));
@@ -1038,13 +1038,13 @@ var CodeUtil = {
//Table
table = item == null ? null : item.Table;
- if (table == null || tableName != CodeUtil.getModelName(table.TABLE_NAME)) {
+ if (table == null || tableName != CodeUtil.getModelName(table.table_name)) {
continue;
}
log('getDoc [] for i=' + i + ': table = \n' + format(JSON.stringify(table)));
if (StringUtil.isEmpty(columnName)) {
- return table.TABLE_COMMENT;
+ return table.table_comment;
}
@@ -1155,7 +1155,7 @@ var CodeUtil = {
var name;
for (var j = 0; j < columnList.length; j++) {
column = columnList[j];
- name = column == null ? null : column.COLUMN_NAME;
+ name = column == null ? null : column.column_name;
if (name == null || key != name) {
continue;
}
@@ -1163,7 +1163,7 @@ var CodeUtil = {
var p = (at.length <= 0 ? '' : at + ' < ')
+ (fun.length <= 0 ? '' : fun + ' < ')
+ (logic.length <= 0 ? '' : logic + ' < ');
- return (p.length <= 0 ? '' : p + key + ': ') + CodeUtil.getJavaType(column.COLUMN_TYPE, true) + ', ' + column.COLUMN_COMMENT;
+ return (p.length <= 0 ? '' : p + key + ': ') + CodeUtil.getJavaType(column.column_type, true) + ', ' + column.column_comment;
}
break;
diff --git a/index.html b/index.html
index e6c160a..32ce1dd 100755
--- a/index.html
+++ b/index.html
@@ -207,7 +207,7 @@
-
+
-
{{his.name}}
diff --git a/js/main.js b/js/main.js
index 993ef54..7f281c1 100755
--- a/js/main.js
+++ b/js/main.js
@@ -1424,18 +1424,18 @@
'[]': {
'count': 0,
'Table': {
- 'TABLE_SCHEMA': App.schema,
- 'TABLE_TYPE': 'BASE TABLE',
- 'TABLE_NAME!$': ['\\_%', 'sys\\_%', 'system\\_%'],
- '@order': 'TABLE_NAME+',
- '@column': 'TABLE_NAME,TABLE_COMMENT'
+ 'table_schema': App.schema,
+ 'table_type': 'BASE TABLE',
+ 'table_name!$': ['\\_%', 'sys\\_%', 'system\\_%'],
+ '@order': 'table_name+',
+ '@column': 'table_name,table_comment'
},
'Column[]': {
'count': 0,
'Column': {
- 'TABLE_SCHEMA': App.schema,
- 'TABLE_NAME@': '[]/Table/TABLE_NAME',
- '@column': 'COLUMN_NAME,COLUMN_TYPE,COLUMN_COMMENT'
+ 'table_schema': App.schema,
+ 'table_name@': '[]/Table/table_name',
+ '@column': 'column_name,column_type,column_comment'
}
}
},
@@ -1497,7 +1497,7 @@
log('getDoc [] for i=' + i + ': table = \n' + format(JSON.stringify(table)));
- doc += '### ' + (i + 1) + '. ' + CodeUtil.getModelName(table.TABLE_NAME) + '\n#### 说明: \n' + App.toMD(table.TABLE_COMMENT);
+ doc += '### ' + (i + 1) + '. ' + CodeUtil.getModelName(table.table_name) + '\n#### 说明: \n' + App.toMD(table.table_comment);
//Column[]
doc += '\n\n#### 字段: \n 名称 | 类型 | 最大长度 | 详细说明' +
@@ -1514,16 +1514,16 @@
var length;
for (var j = 0; j < columnList.length; j++) {
column = columnList[j];
- name = column == null ? null : column.COLUMN_NAME;
+ name = column == null ? null : column.column_name;
if (name == null) {
continue;
}
- type = CodeUtil.getJavaType(column.COLUMN_TYPE, false);
- length = CodeUtil.getMaxLength(column.COLUMN_TYPE);
+ type = CodeUtil.getJavaType(column.column_type, false);
+ length = CodeUtil.getMaxLength(column.column_type);
log('getDoc [] for j=' + j + ': column = \n' + format(JSON.stringify(column)));
- doc += '\n' + name + ' | ' + type + ' | ' + length + ' | ' + App.toMD(column.COLUMN_COMMENT);
+ doc += '\n' + name + ' | ' + type + ' | ' + length + ' | ' + App.toMD(column.column_comment);
}
From 9a84528b9cae246e7c0fc9f32cdbfc9aff0258ad Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sun, 17 Feb 2019 18:44:19 +0800
Subject: [PATCH 031/818] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=AD=97=E5=85=B8?=
=?UTF-8?q?=E6=96=87=E6=A1=A3=E5=85=BC=E5=AE=B9PostgreSQL?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/js/main.js b/js/main.js
index 7f281c1..f5b1c1d 100755
--- a/js/main.js
+++ b/js/main.js
@@ -175,6 +175,7 @@
id: 0,
balance: null //点击更新提示需要判空 0.00
},
+ database: 'MYSQL',// 'POSTGRESQL',
schema: 'sys',
server: 'http://vip.apijson.org/'
},
@@ -1428,14 +1429,14 @@
'table_type': 'BASE TABLE',
'table_name!$': ['\\_%', 'sys\\_%', 'system\\_%'],
'@order': 'table_name+',
- '@column': 'table_name,table_comment'
+ '@column': App.database == 'POSTGRESQL' ? 'table_name' : 'table_name,table_comment'
},
'Column[]': {
'count': 0,
'Column': {
'table_schema': App.schema,
'table_name@': '[]/Table/table_name',
- '@column': 'column_name,column_type,column_comment'
+ '@column': App.database == 'POSTGRESQL' ? 'column_name,data_type:column_type' : 'column_name,column_type,column_comment'
}
}
},
From 2482d1ff6882300029d62a1c9c71ffbe632efd94 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sun, 17 Feb 2019 21:39:58 +0800
Subject: [PATCH 032/818] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=95=B0=E6=8D=AE?=
=?UTF-8?q?=E5=BA=93=E7=B1=BB=E5=9E=8B=E7=9A=84=E8=AE=BE=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
index.html | 9 +++++----
js/main.js | 20 ++++++++++++++------
2 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/index.html b/index.html
index 32ce1dd..cf7195f 100755
--- a/index.html
+++ b/index.html
@@ -90,10 +90,11 @@
{{ User.id != null && User.id > 0 ? User.name : '设置' }}
- 数据库Schema: {{ schema || '点击设置' }}
- 托管服务器URL: {{ server || '点击设置' }}
- 当前账号: {{ Privacy.phone || '点击更新' }}
可用余额: {{ Privacy.balance == null ? '点击更新' : Privacy.balance + ' 元' }}
- 付费功能:
接口用例托管、机器学习测试 等
+ 数据库类型: {{ database || '点击设置' }}
+ 数据库模式: {{ schema || '点击设置' }}
+ 托管服务器URL: {{ server || '点击设置' }}
+ 当前账号: {{ Privacy.phone || '点击更新' }}
可用余额: {{ Privacy.balance == null ? '点击更新' : Privacy.balance + ' 元' }}
+ 付费功能:
接口用例托管、机器学习测试 等
-
微信扫码充值
没有账号会帮你创建
diff --git a/js/main.js b/js/main.js
index f5b1c1d..b850a45 100755
--- a/js/main.js
+++ b/js/main.js
@@ -398,13 +398,14 @@
switch (index) {
case 0:
case 1:
- App.exTxt.name = index == 0 ? App.schema : App.server
+ case 2:
+ App.exTxt.name = index == 0 ? App.database : (index == 1 ? App.schema : App.server)
App.isConfigShow = true
break
- case 2:
+ case 3:
App.getCurrentUser(true)
break
- case 3:
+ case 4:
App.showAndSend(App.server + '/get', {
'Goods[]': {
'count': 0,
@@ -588,9 +589,16 @@
saveConfig: function () {
App.isConfigShow = false
- if (App.exTxt.index == 0) {
- App.schema = App.exTxt.name
- App.saveCache('', 'schema', App.schema)
+
+ if (App.exTxt.index <= 1) {
+ if (App.exTxt.index == 0) {
+ App.database = App.exTxt.name
+ App.saveCache('', 'database', App.database)
+ }
+ else {
+ App.schema = App.exTxt.name
+ App.saveCache('', 'schema', App.schema)
+ }
doc = null
App.onChange(false)
From ebe0b111ef25cfc18cde343348925addc4096e1d Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sun, 17 Feb 2019 21:42:47 +0800
Subject: [PATCH 033/818] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=89=93=E5=BC=80?=
=?UTF-8?q?=E6=88=96=E7=BD=91=E9=A1=B5=E5=90=8E=E6=95=B0=E6=8D=AE=E5=BA=93?=
=?UTF-8?q?=E7=B1=BB=E5=9E=8B=E4=B8=8D=E6=98=AF=E4=B8=8A=E6=AC=A1=E7=BC=93?=
=?UTF-8?q?=E5=AD=98=E7=9A=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/js/main.js b/js/main.js
index b850a45..0ef0069 100755
--- a/js/main.js
+++ b/js/main.js
@@ -2095,6 +2095,10 @@
if (StringUtil.isEmpty(url, true) == false) {
URL_BASE = url
}
+ var database = this.getCache('', 'database')
+ if (StringUtil.isEmpty(database, true) == false) {
+ this.database = database
+ }
var schema = this.getCache('', 'schema')
if (StringUtil.isEmpty(schema, true) == false) {
this.schema = schema
From 1e8cc1e796bd76859da39be56f49441bc8a88a71 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sun, 17 Feb 2019 21:52:02 +0800
Subject: [PATCH 034/818] =?UTF-8?q?=E6=9F=A5=E6=96=87=E6=A1=A3=E8=AF=B7?=
=?UTF-8?q?=E6=B1=82JSON=E6=96=B0=E5=A2=9E=E9=BB=98=E8=AE=A4=E6=95=B0?=
=?UTF-8?q?=E6=8D=AE=E5=BA=93=20@database?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 1 +
1 file changed, 1 insertion(+)
diff --git a/js/main.js b/js/main.js
index 0ef0069..0df0987 100755
--- a/js/main.js
+++ b/js/main.js
@@ -1430,6 +1430,7 @@
*/
getDoc: function (callback) {
App.request(false, this.getBaseUrl() + '/get', {
+ '@database': App.database,
'[]': {
'count': 0,
'Table': {
From 7c0cb5e82be8e7a7ed5acd437c0a042f9306af12 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sun, 17 Feb 2019 22:49:07 +0800
Subject: [PATCH 035/818] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90?=
=?UTF-8?q?=E4=BB=A3=E7=A0=81:=E7=94=A8{}=E5=8C=85=E6=8B=AC=E5=8F=98?=
=?UTF-8?q?=E9=87=8F=EF=BC=8C=E4=BB=A5=E5=8F=8A=E4=B8=BAitem=E5=8F=98?=
=?UTF-8?q?=E9=87=8F=E5=8A=A0=E5=B1=82=E7=BA=A7=E5=90=8E=E7=BC=80=EF=BC=8C?=
=?UTF-8?q?=E8=A7=A3=E5=86=B3=E9=87=8D=E5=90=8D=E5=86=B2=E7=AA=81=EF=BC=8C?=
=?UTF-8?q?=E9=A1=BA=E4=BE=BF=E8=AE=A9=E5=B1=82=E6=AC=A1=E6=9B=B4=E6=B8=85?=
=?UTF-8?q?=E6=99=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
apijson/CodeUtil.js | 49 ++++++++++++++++++++++++---------------------
1 file changed, 26 insertions(+), 23 deletions(-)
diff --git a/apijson/CodeUtil.js b/apijson/CodeUtil.js
index 294b810..c93198c 100644
--- a/apijson/CodeUtil.js
+++ b/apijson/CodeUtil.js
@@ -165,13 +165,15 @@ var CodeUtil = {
depth = 0;
}
- const parentKey = JSONObject.isArrayKey(name) ? JSONResponse.getVariableName(CodeUtil.getItemKey(name)) : CodeUtil.getTableKey(JSONResponse.getVariableName(name));
+ const parentKey = JSONObject.isArrayKey(name) ? JSONResponse.getVariableName(CodeUtil.getItemKey(name)) + (depth <= 1 ? '' : depth) : CodeUtil.getTableKey(JSONResponse.getVariableName(name));
+ const prefix = CodeUtil.getBlank(depth);
+ const nextPrefix = CodeUtil.getBlank(depth + 1);
return CodeUtil.parseCode(name, reqObj, {
onParseParentStart: function () {
- return '\n' + (isSmart ? 'JSONRequest' : 'Map') + ' ' + parentKey + ' = new ' + (isSmart ? 'JSONRequest' : 'LinkedHashMap<>') + '();';
+ return '\n' + prefix + (isSmart ? 'JSONRequest' : 'Map') + ' ' + parentKey + ' = new ' + (isSmart ? 'JSONRequest' : 'LinkedHashMap<>') + '();';
},
onParseParentEnd: function () {
@@ -180,7 +182,7 @@ var CodeUtil = {
onParseChildArray: function (key, value, index) {
- var s = '\n\n//' + key + '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<';
+ var s = '\n\n' + prefix + '{ ' + '//' + key + '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<';
const count = isSmart ? (value.count || 0) : 0;
const page = isSmart ? (value.page || 0) : 0;
@@ -200,32 +202,33 @@ var CodeUtil = {
log(CodeUtil.TAG, 'parseJava for delete >> count = ' + count + '; page = ' + page);
- var name = JSONResponse.getVariableName(CodeUtil.getItemKey(key));
+ var name = JSONResponse.getVariableName(CodeUtil.getItemKey(key)) + (depth <= 0 ? '' : depth + 1);
if (isSmart) {
- var prefix = key.substring(0, key.length - 2);
+ var alias = key.substring(0, key.length - 2);
s += '\n\n';
if (query != null) {
- s += name + '.setQuery(' + (CodeUtil.QUERY_TYPE_CONSTS[query] || CodeUtil.QUERY_TYPE_CONSTS[0]) + ');\n';
+ s += nextPrefix + name + '.setQuery(' + (CodeUtil.QUERY_TYPE_CONSTS[query] || CodeUtil.QUERY_TYPE_CONSTS[0]) + ');\n';
}
if (StringUtil.isEmpty(join, true) == false) {
- s += name + '.setJoin("' + join + '");\n';
+ s += nextPrefix + name + '.setJoin("' + join + '");\n';
}
- s += parentKey + '.putAll(' + name + '.toArray('
- + count + ', ' + page + (prefix.length <= 0 ? '' : ', "' + prefix + '"') + '));';
+
+ s += nextPrefix + parentKey + '.putAll(' + name + '.toArray('
+ + count + ', ' + page + (alias.length <= 0 ? '' : ', "' + alias + '"') + '));';
}
else {
- s += '\n\n' + parentKey + '.put("' + key + '", ' + name + ');';
+ s += '\n\n' + CodeUtil.getBlank(depth + 1) + parentKey + '.put("' + key + '", ' + name + ');';
}
- s += '\n//' + key + '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n';
+ s += '\n' + prefix + '} ' + '//' + key + '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n';
return s;
},
onParseChildObject: function (key, value, index) {
- var s = '\n\n//' + key + '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<';
+ var s = '\n\n' + prefix + '{ ' + '//' + key + '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<';
const isTable = isSmart && JSONObject.isTableKey(JSONResponse.getTableName(key));
@@ -253,19 +256,19 @@ var CodeUtil = {
const name = CodeUtil.getTableKey(JSONResponse.getVariableName(key));
if (isTable) {
- s = column == null ? s : s + '\n' + name + '.setColumn(' + CodeUtil.getJavaValue(name, key, column) + ');';
- s = group == null ? s : s + '\n' + name + '.setGroup(' + CodeUtil.getJavaValue(name, key, group) + ');';
- s = having == null ? s : s + '\n' + name + '.setHaving(' + CodeUtil.getJavaValue(name, key, having) + ');';
- s = order == null ? s : s + '\n' + name + '.setOrder(' + CodeUtil.getJavaValue(name, key, order) + ');';
- s = combine == null ? s : s + '\n' + name + '.setCombine(' + CodeUtil.getJavaValue(name, key, combine) + ');';
- s = schema == null ? s : s + '\n' + name + '.setSchema(' + CodeUtil.getJavaValue(name, key, schema) + ');';
- s = database == null ? s : s + '\n' + name + '.setDatabase(' + CodeUtil.getJavaValue(name, key, database) + ');';
- s = role == null ? s : s + '\n' + name + '.setRole(' + CodeUtil.getJavaValue(name, key, role) + ');';
+ s = column == null ? s : s + '\n' + nextPrefix + name + '.setColumn(' + CodeUtil.getJavaValue(name, key, column) + ');';
+ s = group == null ? s : s + '\n' + nextPrefix + name + '.setGroup(' + CodeUtil.getJavaValue(name, key, group) + ');';
+ s = having == null ? s : s + '\n' + nextPrefix + name + '.setHaving(' + CodeUtil.getJavaValue(name, key, having) + ');';
+ s = order == null ? s : s + '\n' + nextPrefix + name + '.setOrder(' + CodeUtil.getJavaValue(name, key, order) + ');';
+ s = combine == null ? s : s + '\n' + nextPrefix + name + '.setCombine(' + CodeUtil.getJavaValue(name, key, combine) + ');';
+ s = schema == null ? s : s + '\n' + nextPrefix + name + '.setSchema(' + CodeUtil.getJavaValue(name, key, schema) + ');';
+ s = database == null ? s : s + '\n' + nextPrefix + name + '.setDatabase(' + CodeUtil.getJavaValue(name, key, database) + ');';
+ s = role == null ? s : s + '\n' + nextPrefix + name + '.setRole(' + CodeUtil.getJavaValue(name, key, role) + ');';
}
- s += '\n\n' + parentKey + '.put("' + key + '", ' + name + ');';
+ s += '\n\n' + nextPrefix + parentKey + '.put("' + key + '", ' + name + ');';
- s += '\n//' + key + '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n';
+ s += '\n' + prefix + '} ' + '//' + key + '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n';
return s;
},
@@ -291,7 +294,7 @@ var CodeUtil = {
return '\n' + parentKey + '.setRole(' + CodeUtil.getJavaValue(name, key, value) + ');';
}
}
- return '\n' + parentKey + '.put("' + key + '", ' + CodeUtil.getJavaValue(name, key, value) + ');';
+ return '\n' + prefix + parentKey + '.put("' + key + '", ' + CodeUtil.getJavaValue(name, key, value) + ');';
}
})
From f2086ec2b90dd5c7a74e8c25d6dadbf6c1710c0a Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sun, 17 Mar 2019 15:08:30 +0800
Subject: [PATCH 036/818] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90?=
=?UTF-8?q?=E6=A3=80=E6=9F=A5:=E6=96=B0=E5=A2=9E=E5=AF=B9=E7=BC=BA?=
=?UTF-8?q?=E5=B0=91tag=E7=9A=84=E6=8F=90=E7=A4=BA=EF=BC=9B=E8=87=AA?=
=?UTF-8?q?=E5=8A=A8=E7=94=9F=E6=88=90=E4=BB=A3=E7=A0=81:=E8=A7=A3?=
=?UTF-8?q?=E5=86=B3=E6=9F=90=E4=BA=9B=E5=B5=8C=E5=A5=97=E5=AF=B9=E8=B1=A1?=
=?UTF-8?q?=E5=86=85=E9=83=A8=E4=B8=8D=E9=9A=8FisSingle=E6=A8=A1=E5=BC=8F?=
=?UTF-8?q?=E7=94=9F=E6=95=88?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
apijson/CodeUtil.js | 2 +-
js/main.js | 11 ++++++++++-
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/apijson/CodeUtil.js b/apijson/CodeUtil.js
index c93198c..7093224 100644
--- a/apijson/CodeUtil.js
+++ b/apijson/CodeUtil.js
@@ -252,7 +252,7 @@ var CodeUtil = {
delete value['@role'];
}
- s += CodeUtil.parseJava(key, value, depth + 1, isTable);
+ s += CodeUtil.parseJava(key, value, depth + 1, isSmart);
const name = CodeUtil.getTableKey(JSONResponse.getVariableName(key));
if (isTable) {
diff --git a/js/main.js b/js/main.js
index 0df0987..3c8e372 100755
--- a/js/main.js
+++ b/js/main.js
@@ -1194,7 +1194,16 @@
App.showDoc()
try {
- vComment.value = isSingle ? '' : CodeUtil.parseComment(after, docObj == null ? null : docObj['[]'], App.getMethod())
+ var m = App.getMethod();
+ var c = isSingle ? '' : CodeUtil.parseComment(after, docObj == null ? null : docObj['[]'], m)
+
+ if (isSingle != true) {
+ m = m == null ? 'GET' : m.toUpperCase()
+ if (m != 'GET' && m != 'HEAD' && c.tag == null) {
+ c += ' ! 非开放请求必须设置 tag !例如 "tag": "User"'
+ }
+ }
+ vComment.value = c
onScrollChanged()
} catch (e) {
From f26a5a37549536f19b478bf894d747276d2ed4b4 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sun, 17 Mar 2019 15:16:44 +0800
Subject: [PATCH 037/818] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90?=
=?UTF-8?q?=E6=B3=A8=E9=87=8A:=E6=96=B0=E5=A2=9E=E6=AF=94=E8=BE=83?=
=?UTF-8?q?=E7=AC=A6=E5=8F=B7>,<,>=3D,<=3D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
apijson/CodeUtil.js | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/apijson/CodeUtil.js b/apijson/CodeUtil.js
index 7093224..a1ff99d 100644
--- a/apijson/CodeUtil.js
+++ b/apijson/CodeUtil.js
@@ -1108,6 +1108,22 @@ var CodeUtil = {
fun = '减少/去除';
key = columnName.substring(0, columnName.length - 1);
}
+ else if (columnName.endsWith(">=")) {//大于或等于
+ fun = '大于或等于';
+ key = columnName.substring(0, columnName.length - 2);
+ }
+ else if (columnName.endsWith("<=")) {//小于或等于
+ fun = '小于或等于';
+ key = columnName.substring(0, columnName.length - 2);
+ }
+ else if (columnName.endsWith(">")) {//大于
+ fun = '大于';
+ key = columnName.substring(0, columnName.length - 1);
+ }
+ else if (columnName.endsWith("<")) {//小于
+ fun = '小于';
+ key = columnName.substring(0, columnName.length - 1);
+ }
else {
fun = '';
key = new String(columnName);
From 1310b199a33524289897fb98f23e439acd6726f2 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sun, 17 Mar 2019 20:53:33 +0800
Subject: [PATCH 038/818] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90?=
=?UTF-8?q?=E6=B3=A8=E9=87=8A:=E8=87=AA=E5=AE=9A=E4=B9=89API=E4=B8=8D?=
=?UTF-8?q?=E6=A0=A1=E9=AA=8Ctag?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/js/main.js b/js/main.js
index 3c8e372..a1d476c 100755
--- a/js/main.js
+++ b/js/main.js
@@ -1155,15 +1155,18 @@
before = App.toDoubleJSON(before);
log('onHandle before = \n' + before);
+ var afterObj;
var after;
try {
- after = JSON.stringify(jsonlint.parse(before), null, " ");
+ afterObj = jsonlint.parse(before);
+ after = JSON.stringify(afterObj, null, " ");
before = after;
}
catch (e) {
log('main.onHandle', 'try { return jsonlint.parse(before); \n } catch (e) {\n' + e.message)
log('main.onHandle', 'return jsonlint.parse(App.removeComment(before));')
- after = JSON.stringify(jsonlint.parse(App.removeComment(before)), null, " ");
+ afterObj = jsonlint.parse(App.removeComment(before));
+ after = JSON.stringify(afterObj, null, " ");
}
//关键词let在IE和Safari上不兼容
@@ -1197,9 +1200,9 @@
var m = App.getMethod();
var c = isSingle ? '' : CodeUtil.parseComment(after, docObj == null ? null : docObj['[]'], m)
- if (isSingle != true) {
+ if (isSingle != true && afterObj.tag == null) {
m = m == null ? 'GET' : m.toUpperCase()
- if (m != 'GET' && m != 'HEAD' && c.tag == null) {
+ if (['GETS', 'HEADS', 'POST', 'PUT', 'DELETE'].indexOf(m) >= 0) {
c += ' ! 非开放请求必须设置 tag !例如 "tag": "User"'
}
}
From 0708eebce222d32d41b72a7c4623b129c6985d58 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sun, 31 Mar 2019 17:03:42 +0800
Subject: [PATCH 039/818] =?UTF-8?q?=E5=AF=BC=E8=88=AA=E9=93=BE=E6=8E=A5?=
=?UTF-8?q?=EF=BC=9A=E5=8A=A0=E4=B8=8Aapijson-php?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 1 +
1 file changed, 1 insertion(+)
diff --git a/js/main.js b/js/main.js
index a1d476c..6efd216 100755
--- a/js/main.js
+++ b/js/main.js
@@ -1413,6 +1413,7 @@
+ '\nAPIJSON 接口工具: [https://github.com/TommyLemon/APIJSONAuto](https://github.com/TommyLemon/APIJSONAuto) '
+ '\nAPIJSON -Java版: [https://github.com/TommyLemon/APIJSON](https://github.com/TommyLemon/APIJSON) '
+ '\nAPIJSON - C# 版: [https://github.com/liaozb/APIJSON.NET](https://github.com/liaozb/APIJSON.NET) '
+ + '\nAPIJSON - PHP版: [https://github.com/qq547057827/apijson-php](https://github.com/qq547057827/apijson-php) '
+ '\nAPIJSON - PHP版: [https://github.com/orchie/apijson](https://github.com/orchie/apijson) '
+ '\nAPIJSON -Node版: [https://github.com/TEsTsLA/apijson](https://github.com/TEsTsLA/apijson) '
+ '\nAPIJSON -Python: [https://github.com/zhangchunlin/uliweb-apijson](https://github.com/zhangchunlin/uliweb-apijson) ';
From d8eebbbc5ebde44246479e6fd0683ab4f6f4b384 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sun, 31 Mar 2019 18:35:21 +0800
Subject: [PATCH 040/818] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90?=
=?UTF-8?q?=E6=96=87=E6=A1=A3:=E6=96=B0=E5=A2=9EPostgreSQL=E7=9A=84?=
=?UTF-8?q?=E5=AD=97=E6=AE=B5=E6=B3=A8=E9=87=8A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/js/main.js b/js/main.js
index 6efd216..bfef8b3 100755
--- a/js/main.js
+++ b/js/main.js
@@ -1442,6 +1442,8 @@
* 获取文档
*/
getDoc: function (callback) {
+
+
App.request(false, this.getBaseUrl() + '/get', {
'@database': App.database,
'[]': {
@@ -1453,12 +1455,22 @@
'@order': 'table_name+',
'@column': App.database == 'POSTGRESQL' ? 'table_name' : 'table_name,table_comment'
},
- 'Column[]': {
+ 'PgClass': App.database != 'POSTGRESQL' ? null : {
+ 'relname@': '/Table/table_name',
+ '@column': 'oid' //,relname,attnum;col_description(oid,attnum)'
+ },
+ '[]': {
'count': 0,
'Column': {
'table_schema': App.schema,
'table_name@': '[]/Table/table_name',
'@column': App.database == 'POSTGRESQL' ? 'column_name,data_type:column_type' : 'column_name,column_type,column_comment'
+ },
+ 'PgAttribute': App.database != 'POSTGRESQL' ? null : {
+ 'attrelid@': '[]/PgClass/oid',
+ 'attname@': '/Column/column_name',
+ 'attnum>': 0,
+ '@column': 'col_description(attrelid,attnum):column_comment'
}
}
},
@@ -1526,7 +1538,7 @@
doc += '\n\n#### 字段: \n 名称 | 类型 | 最大长度 | 详细说明' +
' \n -------- | ------------ | ------------ | ------------ ';
- columnList = item['Column[]'];
+ columnList = item['[]'];
if (columnList == null) {
continue;
}
@@ -1536,7 +1548,7 @@
var type;
var length;
for (var j = 0; j < columnList.length; j++) {
- column = columnList[j];
+ column = (columnList[j] || {}).Column;
name = column == null ? null : column.column_name;
if (name == null) {
continue;
@@ -1546,7 +1558,9 @@
log('getDoc [] for j=' + j + ': column = \n' + format(JSON.stringify(column)));
- doc += '\n' + name + ' | ' + type + ' | ' + length + ' | ' + App.toMD(column.column_comment);
+ var o = App.database != 'POSTGRESQL' ? column : (columnList[j] || {}).PgAttribute
+
+ doc += '\n' + name + ' | ' + type + ' | ' + length + ' | ' + App.toMD((o || {}).column_comment);
}
From 6703a606b65658d89302f9b70dd810a8792b28d4 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sun, 31 Mar 2019 18:49:59 +0800
Subject: [PATCH 041/818] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90?=
=?UTF-8?q?=E6=96=87=E6=A1=A3:=E6=96=B0=E5=A2=9EPostgreSQL=E7=9A=84?=
=?UTF-8?q?=E8=A1=A8=E6=B3=A8=E9=87=8A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/js/main.js b/js/main.js
index bfef8b3..be3d1bb 100755
--- a/js/main.js
+++ b/js/main.js
@@ -1457,7 +1457,8 @@
},
'PgClass': App.database != 'POSTGRESQL' ? null : {
'relname@': '/Table/table_name',
- '@column': 'oid' //,relname,attnum;col_description(oid,attnum)'
+ //FIXME 多个 schema 有同名表时数据总是取前面的 不属于 pg_class 表 'nspname': App.schema,
+ '@column': 'oid;obj_description(oid):table_comment'
},
'[]': {
'count': 0,
@@ -1532,7 +1533,8 @@
log('getDoc [] for i=' + i + ': table = \n' + format(JSON.stringify(table)));
- doc += '### ' + (i + 1) + '. ' + CodeUtil.getModelName(table.table_name) + '\n#### 说明: \n' + App.toMD(table.table_comment);
+ doc += '### ' + (i + 1) + '. ' + CodeUtil.getModelName(table.table_name) + '\n#### 说明: \n'
+ + App.toMD(App.database != 'POSTGRESQL' ? table.table_comment : (item.PgClass || {}).table_comment);
//Column[]
doc += '\n\n#### 字段: \n 名称 | 类型 | 最大长度 | 详细说明' +
From 876398075aa729c9d76bfb1666bf630d34cd861f Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Mon, 1 Apr 2019 00:50:41 +0800
Subject: [PATCH 042/818] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90?=
=?UTF-8?q?=E4=BB=A3=E7=A0=81:=E8=A7=A3=E5=86=B3=E7=B1=BB=E6=96=87?=
=?UTF-8?q?=E4=BB=B6=E6=B2=A1=E6=9C=89=E6=88=90=E5=91=98=E5=8F=98=E9=87=8F?=
=?UTF-8?q?=EF=BC=9B=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90=E6=B3=A8=E9=87=8A?=
=?UTF-8?q?:=E8=A7=A3=E5=86=B3=E8=A1=A8=E6=B3=A8=E9=87=8A=E5=92=8C?=
=?UTF-8?q?=E5=AD=97=E6=AE=B5=E6=B3=A8=E9=87=8A=E4=B8=A2=E5=A4=B1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
apijson/CodeUtil.js | 43 ++++++++++++++++++++++++-------------------
js/main.js | 4 ++--
2 files changed, 26 insertions(+), 21 deletions(-)
diff --git a/apijson/CodeUtil.js b/apijson/CodeUtil.js
index a1ff99d..1a50bbe 100644
--- a/apijson/CodeUtil.js
+++ b/apijson/CodeUtil.js
@@ -24,7 +24,7 @@ var CodeUtil = {
* @param tableList
* @return parseComment
*/
- parseComment: function (reqStr, tableList, method) { //怎么都获取不到真正的长度,cols不行,默认20不变,maxLineLength不行,默认undefined不变 , maxLineLength) {
+ parseComment: function (reqStr, tableList, method, database) { //怎么都获取不到真正的长度,cols不行,默认20不变,maxLineLength不行,默认undefined不变 , maxLineLength) {
if (StringUtil.isEmpty(reqStr)) {
return '';
}
@@ -61,14 +61,14 @@ var CodeUtil = {
depth ++;
names[depth] = key;
- comment = CodeUtil.getComment4Request(tableList, names[depth - 1], key, null, method, false);
+ comment = CodeUtil.getComment4Request(tableList, names[depth - 1], key, null, method, false, database);
}
else {
if (line.endsWith('}')) {
isInSubquery = false;
if (line.endsWith('{}')) { //对象,判断是不是Table,再加对应的注释
- comment = CodeUtil.getComment4Request(tableList, names[depth], key, null, method, false);
+ comment = CodeUtil.getComment4Request(tableList, names[depth], key, null, method, false, database);
}
else {
depth --;
@@ -82,7 +82,7 @@ var CodeUtil = {
var isArray = line.endsWith('['); // [] 不影响
// alert('depth = ' + depth + '; line = ' + line + '; isArray = ' + isArray);
comment = value == 'null' ? ' ! null无效' : CodeUtil.getComment4Request(tableList, names[depth], key
- , isArray ? '' : line.substring(index + 2).trim(), method, isInSubquery);
+ , isArray ? '' : line.substring(index + 2).trim(), method, isInSubquery, database);
}
}
@@ -485,7 +485,7 @@ var CodeUtil = {
/**用数据字典转为JavaBean
* @param docObj
*/
- parseJavaBean: function(docObj, clazz) {
+ parseJavaBean: function(docObj, clazz, database) {
//转为Java代码格式
var doc = '';
@@ -518,13 +518,13 @@ var CodeUtil = {
+ '\n\n使用方法\n1.修改包名package \n2.import需要引入的类,可使用快捷键Ctrl+Shift+O '
+ '\n*/\n'
+ '\npackage apijson.demo.server.model;\n\n\n'
- + CodeUtil.getComment(table.table_comment, true)
+ + CodeUtil.getComment(database != 'POSTGRESQL' ? table.table_comment : (item.PgClass || {}).table_comment, true)
+ '\n@MethodAccess'
+ '\npublic class ' + model + ' implements Serializable {'
+ '\n private static final long serialVersionUID = 1L;\n';
//Column[]
- columnList = item['Column[]'];
+ columnList = item['[]'];
if (columnList != null) {
console.log('parseJavaBean [] for ' + i + ': columnList = \n' + format(JSON.stringify(columnList)));
@@ -533,7 +533,7 @@ var CodeUtil = {
var type;
for (var j = 0; j < columnList.length; j++) {
- column = columnList[j];
+ column = (columnList[j] || {}).Column;
name = CodeUtil.getFieldName(column == null ? null : column.column_name);
if (name == '') {
@@ -544,7 +544,8 @@ var CodeUtil = {
console.log('parseJavaBean [] for j=' + j + ': column = \n' + format(JSON.stringify(column)));
- doc += '\n private ' + type + ' ' + name + '; ' + CodeUtil.getComment(column.column_comment, false);
+ var o = database != 'POSTGRESQL' ? column : (columnList[j] || {}).PgAttribute
+ doc += '\n private ' + type + ' ' + name + '; ' + CodeUtil.getComment((o || {}).column_comment, false);
}
@@ -859,8 +860,9 @@ var CodeUtil = {
* @param key
* @param value
* @param isInSubquery
+ * @param database
*/
- getComment4Request: function (tableList, name, key, value, method, isInSubquery) {
+ getComment4Request: function (tableList, name, key, value, method, isInSubquery, database) {
// alert('name = ' + name + '; key = ' + key + '; value = ' + value + '; method = ' + method);
if (key == null) {
@@ -880,7 +882,7 @@ var CodeUtil = {
var aliaIndex = name == null ? -1 : name.indexOf(':');
var objName = aliaIndex < 0 ? name : name.substring(0, aliaIndex);
if (JSONObject.isTableKey(objName)) {
- return CodeUtil.getComment('子查询 < ' + CodeUtil.getCommentFromDoc(tableList, objName, key.substring(0, key.length - 1), method), false, ' ');
+ return CodeUtil.getComment('子查询 < ' + CodeUtil.getCommentFromDoc(tableList, objName, key.substring(0, key.length - 1), method, database), false, ' ');
}
return CodeUtil.getComment('子查询 ' + StringUtil.get(name) + ",需要被下面的表字段相关 key 引用赋值", false, ' ');
}
@@ -906,7 +908,7 @@ var CodeUtil = {
var objName = aliaIndex < 0 ? key : key.substring(0, aliaIndex);
if (JSONObject.isTableKey(objName)) {
- var c = CodeUtil.getCommentFromDoc(tableList, objName, null, method);
+ var c = CodeUtil.getCommentFromDoc(tableList, objName, null, method, database);
return StringUtil.isEmpty(c) ? ' ! 表不存在!' : CodeUtil.getComment(
(aliaIndex < 0 ? '' : '新建别名: ' + key.substring(aliaIndex + 1, key.length) + ' < ' + objName + ': ') + c, false, ' ');
}
@@ -979,7 +981,7 @@ var CodeUtil = {
if (key.startsWith('@')) {
return '';
}
- var c = CodeUtil.getCommentFromDoc(tableList, objName, key, method);
+ var c = CodeUtil.getCommentFromDoc(tableList, objName, key, method, database);
return StringUtil.isEmpty(c) ? ' ! 字段不存在!' : CodeUtil.getComment(c, false, ' ');
}
@@ -1024,8 +1026,8 @@ var CodeUtil = {
* @param method
* @return {*}
*/
- getCommentFromDoc: function (tableList, tableName, columnName, method) {
- log('getCommentFromDoc tableName = ' + tableName + '; columnName = ' + columnName + '; method = ' + method + '; tableList = \n' + JSON.stringify(tableList));
+ getCommentFromDoc: function (tableList, tableName, columnName, method, database) {
+ log('getCommentFromDoc tableName = ' + tableName + '; columnName = ' + columnName + '; method = ' + method + '; database = ' + database + '; tableList = \n' + JSON.stringify(tableList));
if (tableList == null || tableList.length <= 0) {
return '...';
@@ -1047,7 +1049,7 @@ var CodeUtil = {
log('getDoc [] for i=' + i + ': table = \n' + format(JSON.stringify(table)));
if (StringUtil.isEmpty(columnName)) {
- return table.table_comment;
+ return database != 'POSTGRESQL' ? table.table_comment : (item.PgClass || {}).table_comment;
}
@@ -1165,7 +1167,7 @@ var CodeUtil = {
//功能符 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- columnList = item['Column[]'];
+ columnList = item['[]'];
if (columnList == null) {
continue;
}
@@ -1173,7 +1175,7 @@ var CodeUtil = {
var name;
for (var j = 0; j < columnList.length; j++) {
- column = columnList[j];
+ column = (columnList[j] || {}).Column;
name = column == null ? null : column.column_name;
if (name == null || key != name) {
continue;
@@ -1182,7 +1184,10 @@ var CodeUtil = {
var p = (at.length <= 0 ? '' : at + ' < ')
+ (fun.length <= 0 ? '' : fun + ' < ')
+ (logic.length <= 0 ? '' : logic + ' < ');
- return (p.length <= 0 ? '' : p + key + ': ') + CodeUtil.getJavaType(column.column_type, true) + ', ' + column.column_comment;
+
+ var o = database != 'POSTGRESQL' ? column : (columnList[j] || {}).PgAttribute
+
+ return (p.length <= 0 ? '' : p + key + ': ') + CodeUtil.getJavaType(column.column_type, true) + ', ' + (o || {}).column_comment;
}
break;
diff --git a/js/main.js b/js/main.js
index be3d1bb..3b6e935 100755
--- a/js/main.js
+++ b/js/main.js
@@ -533,7 +533,7 @@
var clazz = App.exTxt.name
- var txt = CodeUtil.parseJavaBean(docObj, clazz)
+ var txt = CodeUtil.parseJavaBean(docObj, clazz, App.database)
if (StringUtil.isEmpty(txt, true)) {
alert('找不到 ' + clazz + ' 对应的表!请检查数据库中是否存在!\n如果不存在,请重新输入存在的表;\n如果存在,请刷新网页后重试。')
return
@@ -1198,7 +1198,7 @@
try {
var m = App.getMethod();
- var c = isSingle ? '' : CodeUtil.parseComment(after, docObj == null ? null : docObj['[]'], m)
+ var c = isSingle ? '' : CodeUtil.parseComment(after, docObj == null ? null : docObj['[]'], m, App.database)
if (isSingle != true && afterObj.tag == null) {
m = m == null ? 'GET' : m.toUpperCase()
From 5b66a97bf45ea19a7434eaa07fac74f8048d6bc2 Mon Sep 17 00:00:00 2001
From: TommyLemon
Date: Sun, 7 Apr 2019 22:23:07 +0800
Subject: [PATCH 043/818] Update README.md
---
README.md | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 3277aed..fa9c156 100755
--- a/README.md
+++ b/README.md
@@ -50,10 +50,12 @@ QQ技术交流群:739316921(群2) 607020115(群1)
### 其它项目
-[APIJSON](https://github.com/TommyLemon/APIJSON) 后端接口和文档自动化,前端(客户端) 定制返回JSON的数据和结构
+[APIJSON](https://github.com/TommyLemon/APIJSON) 码云最有价值项目:后端接口和文档自动化,前端(客户端) 定制返回JSON的数据和结构!
[APIJSON.NET](https://github.com/liaozb/APIJSON.NET) C# 版 APIJSON ,支持 MySQL, PostgreSQL, MS SQL Server, Oracle, SQLite
+[apijson-php](https://github.com/qq547057827/apijson-php) PHP 版 APIJSON,基于 ThinkPHP,支持 MySQL, PostgreSQL, MS SQL Server, Oracle 等
+
[apijson](https://github.com/orchie/apijson) PHP 版 APIJSON,支持 MySQL, PostgreSQL, MS SQL Server, Oracle, SQLite 等
[apijson](https://github.com/TEsTsLA/apijson) Node.ts 版 APIJSON,支持 MySQL, PostgreSQL, MS SQL Server, Oracle, SQLite, MariaDB, WebSQL
@@ -62,6 +64,8 @@ QQ技术交流群:739316921(群2) 607020115(群1)
[APIJSONParser](https://github.com/Zerounary/APIJSONParser) 参考 APIJSON 设计标准开发的一款 SQL 编译器框架
+[ApiJsonByJFinal](https://gitee.com/zhiyuexin/ApiJsonByJFinal) 整合 JFinal 和 APIJSON 的 Demo
+
[SpringServer1.2-APIJSON](https://github.com/Airforce-1/SpringServer1.2-APIJSON) 智慧党建服务器端,提供 上传 和 下载 文件的接口
感谢热心的作者们的贡献,点 ⭐Star 支持下他们吧。
From df8291d1b31051d9ba7c0e1dd4c524471dcf07a0 Mon Sep 17 00:00:00 2001
From: TommyLemon
Date: Sun, 7 Apr 2019 22:24:16 +0800
Subject: [PATCH 044/818] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index fa9c156..7e4d836 100755
--- a/README.md
+++ b/README.md
@@ -62,7 +62,7 @@ QQ技术交流群:739316921(群2) 607020115(群1)
[uliweb-apijson](https://github.com/zhangchunlin/uliweb-apijson) Python 版 APIJSON,支持 MySQL, PostgreSQL, MS SQL Server, Oracle, SQLite 等
-[APIJSONParser](https://github.com/Zerounary/APIJSONParser) 参考 APIJSON 设计标准开发的一款 SQL 编译器框架
+[APIJSONParser](https://github.com/Zerounary/APIJSONParser) Complate JSON to SQL,APIJSON编译器,将JSON动态编译成SQL
[ApiJsonByJFinal](https://gitee.com/zhiyuexin/ApiJsonByJFinal) 整合 JFinal 和 APIJSON 的 Demo
From 2d6d2cb16433add309605fb6745cdc1096174e39 Mon Sep 17 00:00:00 2001
From: TommyLemon
Date: Sun, 7 Apr 2019 22:24:45 +0800
Subject: [PATCH 045/818] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 7e4d836..26a9c96 100755
--- a/README.md
+++ b/README.md
@@ -50,7 +50,7 @@ QQ技术交流群:739316921(群2) 607020115(群1)
### 其它项目
-[APIJSON](https://github.com/TommyLemon/APIJSON) 码云最有价值项目:后端接口和文档自动化,前端(客户端) 定制返回JSON的数据和结构!
+[APIJSON](https://github.com/TommyLemon/APIJSON) 码云最有价值项目:后端接口和文档自动化,前端(客户端) 定制返回JSON的数据和结构
[APIJSON.NET](https://github.com/liaozb/APIJSON.NET) C# 版 APIJSON ,支持 MySQL, PostgreSQL, MS SQL Server, Oracle, SQLite
From b1f4293d616c3f29ea9957588b73bb26d2cd08ca Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sat, 13 Apr 2019 15:19:15 +0800
Subject: [PATCH 046/818] =?UTF-8?q?=E6=81=A2=E5=A4=8D=E6=94=AF=E6=8C=81?=
=?UTF-8?q?=E7=A9=BA=E6=A0=BC=E9=9A=94=E6=96=AD=20base=5Furl=20=E5=92=8C?=
=?UTF-8?q?=20branch=5Furl?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/js/main.js b/js/main.js
index 3b6e935..c959cd0 100755
--- a/js/main.js
+++ b/js/main.js
@@ -311,8 +311,13 @@
},
//获取基地址长度,以://后的第一个/分割baseUrl和method
getBaseUrlLength: function (url_) {
- var url = url_ == null ? '' : '' + url_
- var index = url.indexOf('://')
+ var url = StringUtil.trim(url_)
+ var index = url.indexOf(' ')
+ if (index >= 0) {
+ return index + 1
+ }
+
+ index = url.indexOf('://')
return index < 0 ? 0 : index + 3 + url.substring(index + 3).indexOf('/')
},
//获取操作方法
From d03318e7c8a99f6dca54bf9b13a397928e1ccc08 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sat, 13 Apr 2019 15:28:22 +0800
Subject: [PATCH 047/818] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E8=87=AA=E5=8A=A8?=
=?UTF-8?q?=E5=8C=96=E6=B5=8B=E8=AF=95=20URL=20=E5=8F=AF=E8=83=BD=E5=A4=9A?=
=?UTF-8?q?=E7=A9=BA=E6=A0=BC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/js/main.js b/js/main.js
index c959cd0..b43394a 100755
--- a/js/main.js
+++ b/js/main.js
@@ -1837,7 +1837,7 @@
4-code/值类型 改变,红色;
*/
test: function () {
- var baseUrl = App.getBaseUrl() || ''
+ var baseUrl = StringUtil.trim(App.getBaseUrl())
if (baseUrl == '') {
alert('请先输入有效的URL!')
return
From 153cbec913066e2ba0c7afd7465d270e817cfdf8 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sat, 13 Apr 2019 16:12:44 +0800
Subject: [PATCH 048/818] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E8=BE=93=E5=85=A5=20?=
=?UTF-8?q?URL=20=E5=B8=A6=E7=A9=BA=E6=A0=BC=E5=AF=BC=E8=87=B4=E4=B8=8D?=
=?UTF-8?q?=E8=83=BD=E8=8E=B7=E5=8F=96=E6=96=87=E6=A1=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/js/main.js b/js/main.js
index b43394a..fa8b600 100755
--- a/js/main.js
+++ b/js/main.js
@@ -1331,7 +1331,7 @@
// axios.defaults.withcredentials = true
axios({
method: 'post',
- url: url,
+ url: StringUtil.noBlank(url),
data: req,
withCredentials: true
})
From 733141215fca5bc80aed3253360e8047e7a7be6b Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sat, 13 Apr 2019 17:33:22 +0800
Subject: [PATCH 049/818] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=85=89=E6=A0=87?=
=?UTF-8?q?=E6=82=AC=E5=81=9C=E5=9C=A8=E6=B5=8B=E8=AF=95=E7=BB=93=E6=9E=9C?=
=?UTF-8?q?=20Reseponse=20JSON=20=E7=9A=84=20key=20=E4=B8=8A=E6=97=B6?=
=?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=B3=A8=E9=87=8A=20hint?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
index.html | 6 +++---
js/main.js | 43 +++++++++++++++++++++++++++++++++++++++++--
2 files changed, 44 insertions(+), 5 deletions(-)
diff --git a/index.html b/index.html
index cf7195f..79535b1 100755
--- a/index.html
+++ b/index.html
@@ -427,7 +427,7 @@
@@ -435,7 +435,7 @@
@@ -435,7 +437,9 @@
@@ -470,7 +470,7 @@
"{{field}}":
-
+
{{formatVal(val)}}
{{formatVal(val)}}
,
diff --git a/js/main.js b/js/main.js
index ed702b5..c895980 100755
--- a/js/main.js
+++ b/js/main.js
@@ -6,7 +6,7 @@
})
Vue.component('vue-outer', {
- props: ['jsondata', 'isend', 'theme'],
+ props: ['jsondata', 'isend', 'path', 'theme'],
template: '#outer-template'
})
@@ -16,7 +16,7 @@
})
Vue.component('vue-val', {
- props: ['field', 'val', 'isend', 'theme'],
+ props: ['field', 'val', 'isend', 'path', 'theme'],
template: '#val-template'
})
@@ -65,15 +65,10 @@
switch(Vue.prototype.getTyp(val)) {
case 'String':
return '"' + val + '"'
- break
-
case 'Null':
return 'null'
- break
-
default:
return val
-
}
}
@@ -93,50 +88,81 @@
* @param key
* @return {boolean}
*/
- Vue.prototype.onRenderJSONItem = function (val, key) {
- if (key == null) {
+ Vue.prototype.onRenderJSONItem = function (val, key, path) {
+ if (isSingle || key == null) {
return true
}
- if (key == '_$_table_$_') {
+ if (key == '_$_this_$_') {
// return true
return false
}
try {
- if (val instanceof Array == false) {
+ if (val instanceof Array) {
+ if (val[0] instanceof Object && (val[0] instanceof Array == false) && JSONObject.isArrayKey(key)) {
+ // alert('onRenderJSONItem key = ' + key + '; val = ' + JSON.stringify(val))
- var aliaIndex = key.indexOf(':');
- var objName = aliaIndex < 0 ? key : key.substring(0, aliaIndex);
+ var ckey = key.substring(0, key.lastIndexOf('[]'));
- if (JSONObject.isTableKey(objName)) {
- val._$_table_$_ = objName
- // val = Object.assign({ _$_table_$_: objName }, val) //解决多显示一个逗号 ,
+ var aliaIndex = ckey.indexOf(':');
+ var objName = aliaIndex < 0 ? ckey : ckey.substring(0, aliaIndex);
- // this._$_table_$_ = key TODO 不影响 JSON 的方式,直接在组件读写属性
- // alert('this._$_table_$_ = ' + this._$_table_$_)
- }
- }
- else if (val[0] instanceof Object && (val[0] instanceof Array == false) && JSONObject.isArrayKey(key)) {
- // alert('onRenderJSONItem key = ' + key + '; val = ' + JSON.stringify(val))
+ var firstIndex = objName.indexOf('-');
+ var firstKey = firstIndex < 0 ? objName : objName.substring(0, firstIndex);
+
+ for (var i = 0; i < val.length; i++) {
+ var cPath = (StringUtil.isEmpty(path, false) ? '' : path + '/') + key;
- key = key.substring(0, key.lastIndexOf('[]'));
+ if (JSONObject.isTableKey(firstKey)) {
+ var newVal = JSON.parse(JSON.stringify(val[i]))
+ for (var k in val[i]) {
+ delete val[i][k]
+ }
+
+ val[i]._$_this_$_ = JSON.stringify({
+ path: cPath + '/' + i,
+ table: firstKey
+ })
+
+ for (var k in newVal) {
+ val[i][k] = newVal[k]
+ }
+ }
+ else {
+ this.onRenderJSONItem(val[i], '' + i, cPath);
+ }
+
+ // this.$children[i]._$_this_$_ = key
+ // alert('this.$children[i]._$_this_$_ = ' + this.$children[i]._$_this_$_)
+ }
+ }
+ }
+ else if (val instanceof Object) {
var aliaIndex = key.indexOf(':');
var objName = aliaIndex < 0 ? key : key.substring(0, aliaIndex);
- var firstIndex = objName.indexOf('-');
- var firstKey = firstIndex < 0 ? objName : objName.substring(0, firstIndex);
+ var newVal = JSON.parse(JSON.stringify(val))
+ for (var k in val) {
+ delete val[k]
+ }
- if (JSONObject.isTableKey(firstKey)) {
- for (var i = 0; i < val.length; i++) {
- val[i]._$_table_$_ = firstKey
+ val._$_this_$_ = JSON.stringify({
+ path: (StringUtil.isEmpty(path, false) ? '' : path + '/') + key,
+ table: JSONObject.isTableKey(objName) ? objName : null
+ })
- // this.$children[i]._$_table_$_ = key
- // alert('this.$children[i]._$_table_$_ = ' + this.$children[i]._$_table_$_)
- }
+ for (var k in newVal) {
+ val[k] = newVal[k]
}
+
+ // val = Object.assign({ _$_this_$_: objName }, val) //解决多显示一个逗号 ,
+
+ // this._$_this_$_ = key TODO 不影响 JSON 的方式,直接在组件读写属性
+ // alert('this._$_this_$_ = ' + this._$_this_$_)
}
+
} catch (e) {
alert('onRenderJSONItem try { ... } catch (e) {\n' + e.message)
}
@@ -181,90 +207,109 @@
try {
+ var path = null
var table = null
var column = null
if (val instanceof Object && (val instanceof Array == false)) {
- var aliaIndex = key.indexOf(':');
- var objName = aliaIndex < 0 ? key : key.substring(0, aliaIndex);
- if (JSONObject.isTableKey(objName)) {
- table = objName
- // table = this._$_table_$_
- }
- else {
- var parent = $event.currentTarget.parentElement.parentElement
- var valString = parent.textContent
+ var parent = $event.currentTarget.parentElement.parentElement
+ var valString = parent.textContent
- // alert('valString = ' + valString)
+ // alert('valString = ' + valString)
- var i = valString.indexOf('"_$_table_$_": "')
+ var i = valString.indexOf('"_$_this_$_": "')
+ if (i >= 0) {
+ valString = valString.substring(i + '"_$_this_$_": "'.length)
+ i = valString.indexOf('}"')
if (i >= 0) {
- valString = valString.substring(i + '"_$_table_$_": "'.length)
+ valString = valString.substring(0, i + 1)
// alert('valString = ' + valString)
- i = valString.indexOf('"')
- if (i >= 0) {
- table = valString.substring(0, i)
- }
+ var _$_this_$_ = JSON.parse(valString) || {}
+ path = _$_this_$_.path
+ table = _$_this_$_.table
}
- column = key
+
+ var aliaIndex = key == null ? -1 : key.indexOf(':');
+ var objName = aliaIndex < 0 ? key : key.substring(0, aliaIndex);
+
+ if (JSONObject.isTableKey(objName)) {
+ table = objName
+ }
+ else if (JSONObject.isTableKey(table)) {
+ column = key
+ }
+
+ // alert('path = ' + path + '; table = ' + table + '; column = ' + column)
}
}
else {
+ var parent = $event.currentTarget.parentElement.parentElement
+ var valString = parent.textContent
+
+ // alert('valString = ' + valString)
+
+ var i = valString.indexOf('"_$_this_$_": "')
+ if (i >= 0) {
+ valString = valString.substring(i + '"_$_this_$_": "'.length)
+ i = valString.indexOf('}"')
+ if (i >= 0) {
+ valString = valString.substring(0, i + 1)
+ // alert('valString = ' + valString)
+ var _$_this_$_ = JSON.parse(valString) || {}
+ path = _$_this_$_.path
+ table = _$_this_$_.table
+ }
+ }
+
if (val instanceof Array && JSONObject.isArrayKey(key)) {
- key = key.substring(0, key.lastIndexOf('[]'));
+ var key2 = key == null ? null : key.substring(0, key.lastIndexOf('[]'));
- var aliaIndex = key.indexOf(':');
- var objName = aliaIndex < 0 ? key : key.substring(0, aliaIndex);
+ var aliaIndex = key2 == null ? -1 : key2.indexOf(':');
+ var objName = aliaIndex < 0 ? key2 : key2.substring(0, aliaIndex);
- var firstIndex = objName.indexOf('-');
+ var firstIndex = objName == null ? -1 : objName.indexOf('-');
var firstKey = firstIndex < 0 ? objName : objName.substring(0, firstIndex);
+ // alert('key = ' + key + '; firstKey = ' + firstKey + '; firstIndex = ' + firstIndex)
if (JSONObject.isTableKey(firstKey)) {
table = firstKey
+ var s0 = '';
if (firstIndex > 0) {
objName = objName.substring(firstIndex + 1);
firstIndex = objName.indexOf('-');
column = firstIndex < 0 ? objName : objName.substring(0, firstIndex)
- var s0 = this.getResponseHint({}, table, $event)
- if (StringUtil.isEmpty(s0, true) == false) {
- s = s0 + ' - '
- }
+ var c = CodeUtil.getCommentFromDoc(docObj == null ? null : docObj['[]'], table, column, App.getMethod(), App.database, true); // this.getResponseHint({}, table, $event
+ s0 = column + (StringUtil.isEmpty(c, true) ? '' : ': ' + c)
}
- }
+ var c = CodeUtil.getCommentFromDoc(docObj == null ? null : docObj['[]'], table, null, App.getMethod(), App.database, true);
+ s = (StringUtil.isEmpty(path) ? '' : path + '/') + key + ' 中 '
+ + (
+ StringUtil.isEmpty(c, true) ? '' : table + ': '
+ + c + ((StringUtil.isEmpty(s0, true) ? '' : ' - ' + s0) )
+ );
+
+ return s;
+ }
+ //导致 key[] 的 hint 显示为 key[]key[] else {
+ // s = (StringUtil.isEmpty(path) ? '' : path + '/') + key
+ // }
}
else {
-
- var parent = $event.currentTarget.parentElement.parentElement
- var valString = parent.textContent
-
- // alert('valString = ' + valString)
-
- var i = valString.indexOf('"_$_table_$_": "')
- if (i >= 0) {
- valString = valString.substring(i + '"_$_table_$_": "'.length)
- // alert('valString = ' + valString)
- i = valString.indexOf('"')
- if (i >= 0) {
- table = valString.substring(0, i)
- }
+ if (JSONObject.isTableKey(table)) {
+ column = key
}
-
- // table = parent._$_table_$_
-
- column = key
+ // alert('path = ' + path + '; table = ' + table + '; column = ' + column)
}
}
// alert('setResponseHint table = ' + table + '; column = ' + column)
var c = CodeUtil.getCommentFromDoc(docObj == null ? null : docObj['[]'], table, column, App.getMethod(), App.database, true);
- if (StringUtil.isEmpty(c, true) == false) {
- s += (StringUtil.isEmpty(column) ? table : column) + ': ' + c
- }
+ s += (StringUtil.isEmpty(path) ? '' : path + '/') + (StringUtil.isEmpty(column) ? (StringUtil.isEmpty(table) ? key : table) : column) + (StringUtil.isEmpty(c, true) ? '' : ': ' + c)
}
catch (e) {
s += '\n' + e.message
@@ -280,7 +325,7 @@
var initJson = {}
- // 主题 [key, String, Number, Boolean, Null, link-link, link-hover]
+// 主题 [key, String, Number, Boolean, Null, link-link, link-hover]
var themes = [
['#92278f', '#3ab54a', '#25aae2', '#f3934e', '#f34e5c', '#717171'],
['rgb(19, 158, 170)', '#cf9f19', '#ec4040', '#7cc500', 'rgb(211, 118, 126)', 'rgb(15, 189, 170)'],
@@ -291,8 +336,8 @@
- // APIJSON <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- //这些全局变量不能放在data中,否则会报undefined错误
+// APIJSON <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+//这些全局变量不能放在data中,否则会报undefined错误
var baseUrl
var inputted
@@ -305,7 +350,7 @@
var doneCount
- // APIJSON >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
+// APIJSON >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
var App = new Vue({
el: '#app',
@@ -468,7 +513,19 @@
App.view = 'empty'
} else {
App.view = 'code'
- App.jsonhtml = jsonlint.parse(this.jsoncon)
+
+ if (isSingle) {
+ App.jsonhtml = jsonlint.parse(this.jsoncon)
+ }
+ else {
+ App.jsonhtml = Object.assign({
+ _$_this_$_: JSON.stringify({
+ path: null,
+ table: null
+ })
+ }, jsonlint.parse(this.jsoncon))
+ }
+
}
} catch (ex) {
App.view = 'error'
@@ -1949,7 +2006,7 @@
+ '\nAPIJSON -Java版: https://github.com/TommyLemon/APIJSON '
+ '\nAPIJSON - C# 版: https://github.com/liaozb/APIJSON.NET '
+ '\nAPIJSON - PHP版: https://github.com/qq547057827/apijson-php '
- + '\nAPIJSON -Node版: https://github.com/TEsTsLA/apijson '
+ + '\nAPIJSON -Node版: https://github.com/kevinaskin/apijson-node '
+ '\nAPIJSON - Go 版: https://github.com/crazytaxi824/APIJSON '
+ '\nAPIJSON -Python: https://github.com/zhangchunlin/uliweb-apijson ';
From e77095150336c4a805ff4440f5ae0bd35583aa85 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sun, 8 Sep 2019 02:51:02 +0800
Subject: [PATCH 147/818] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90?=
=?UTF-8?q?=E6=B3=A8=E9=87=8A=EF=BC=9A=E6=8F=90=E5=8D=87=E5=A4=84=E7=90=86?=
=?UTF-8?q?=20hint=20=E7=9A=84=E6=80=A7=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/js/main.js b/js/main.js
index c895980..c6f2602 100755
--- a/js/main.js
+++ b/js/main.js
@@ -114,9 +114,11 @@
var cPath = (StringUtil.isEmpty(path, false) ? '' : path + '/') + key;
if (JSONObject.isTableKey(firstKey)) {
- var newVal = JSON.parse(JSON.stringify(val[i]))
+ // var newVal = JSON.parse(JSON.stringify(val[i]))
+ var newVal = {}
for (var k in val[i]) {
+ newVal[k] = val[i][k] //提升性能
delete val[i][k]
}
@@ -142,8 +144,11 @@
var aliaIndex = key.indexOf(':');
var objName = aliaIndex < 0 ? key : key.substring(0, aliaIndex);
- var newVal = JSON.parse(JSON.stringify(val))
+ // var newVal = JSON.parse(JSON.stringify(val))
+
+ var newVal = {}
for (var k in val) {
+ newVal[k] = val[k] //提升性能
delete val[k]
}
From 5b2b2d7add49db8e842ee43ffb66cd9ddfee13c4 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Sun, 8 Sep 2019 15:45:39 +0800
Subject: [PATCH 148/818] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=8C=96=E6=8E=A5?=
=?UTF-8?q?=E5=8F=A3=E5=9B=9E=E5=BD=92=E6=B5=8B=E8=AF=95=EF=BC=9A=E8=A7=A3?=
=?UTF-8?q?=E5=86=B3=E4=B8=8B=E8=BD=BD=E5=BD=93=E5=89=8D=E6=B5=8B=E8=AF=95?=
=?UTF-8?q?=E7=BB=93=E6=9E=9C=E6=8A=A5=E9=94=99=EF=BC=9B=E8=87=AA=E5=8A=A8?=
=?UTF-8?q?=E7=94=9F=E6=88=90=E6=B3=A8=E9=87=8A=EF=BC=9A=E9=81=BF=E5=85=8D?=
=?UTF-8?q?=E5=A4=9A=E4=BD=99=E7=9A=84=E8=AE=A1=E7=AE=97=E6=9D=A5=E6=8F=90?=
=?UTF-8?q?=E9=AB=98=20UI=20=E6=B8=B2=E6=9F=93=E6=80=A7=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
index.html | 2 +-
js/main.js | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/index.html b/index.html
index 81febb8..2544aa6 100755
--- a/index.html
+++ b/index.html
@@ -457,7 +457,7 @@
diff --git a/js/main.js b/js/main.js
index dc63fe0..ca8bbe7 100755
--- a/js/main.js
+++ b/js/main.js
@@ -5636,11 +5636,25 @@
this.listHistory()
this.transfer()
- if (this.User != null && this.User.id != null && this.User.id > 0) {
- setTimeout(function () {
+ setTimeout(function () {
+ var rawReq = getRequest()
+ if (rawReq != null && StringUtil.isEmpty(rawReq.json, true) == false) {
+ vType.value = StringUtil.toUpperCase(rawReq.type || App.type, true)
+ vUrl.value = StringUtil.trim(rawReq.url || App.url)
+ vUrlComment.value = ""
+ vComment.value = ""
+ vInput.value = StringUtil.trim(rawReq.json)
+ App.onChange(false)
+ App.send(false)
+
+ setTimeout(function () {
+ window.open(vUrl.value + "/" + encodeURIComponent(vInput.value))
+ }, 1000)
+ }
+ else if (App.User != null && App.User.id != null && App.User.id > 0) {
App.showTestCase(true, false) // 本地历史仍然要求登录 App.User == null || App.User.id == null)
- }, 1000)
- }
+ }
+ }, 1000)
}
})
})()
From 45518c12f0745f53afb717c62b88dfd8d6c29c40 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Mon, 27 Sep 2021 18:13:32 +0800
Subject: [PATCH 487/818] =?UTF-8?q?=E8=B0=83=E8=AF=95=EF=BC=9A=E7=BD=91?=
=?UTF-8?q?=E9=A1=B5=20URL=20=E6=96=B0=E5=A2=9E=E6=94=AF=E6=8C=81=E8=B7=B3?=
=?UTF-8?q?=E8=BD=AC=E5=85=B3=E9=94=AE=E8=AF=8D=20jump=20=E5=8F=AF?=
=?UTF-8?q?=E5=BC=BA=E5=88=B6=E8=B7=B3=E8=BD=AC=E6=88=96=E4=B8=8D=E8=B7=B3?=
=?UTF-8?q?=E8=BD=AC=EF=BC=8C=E6=B2=A1=E4=BC=A0=20jump=20=E5=88=99?=
=?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=A4=84=E7=90=86=EF=BC=9B=E7=BD=91=E9=A1=B5?=
=?UTF-8?q?=20URL=20=E5=8F=AF=E7=BC=BA=E7=9C=81=E5=8F=82=E6=95=B0=20url?=
=?UTF-8?q?=EF=BC=9B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/js/main.js b/js/main.js
index ca8bbe7..3044e1f 100755
--- a/js/main.js
+++ b/js/main.js
@@ -5639,17 +5639,28 @@
setTimeout(function () {
var rawReq = getRequest()
if (rawReq != null && StringUtil.isEmpty(rawReq.json, true) == false) {
- vType.value = StringUtil.toUpperCase(rawReq.type || App.type, true)
- vUrl.value = StringUtil.trim(rawReq.url || App.url)
vUrlComment.value = ""
vComment.value = ""
+
+ if (StringUtil.isEmpty(rawReq.url, true) == false) {
+ vType.value = StringUtil.toUpperCase(rawReq.type, true)
+ }
+
+ if (StringUtil.isEmpty(rawReq.url, true) == false) {
+ vUrl.value = StringUtil.trim(rawReq.url)
+ }
+
vInput.value = StringUtil.trim(rawReq.json)
+
App.onChange(false)
App.send(false)
- setTimeout(function () {
- window.open(vUrl.value + "/" + encodeURIComponent(vInput.value))
- }, 1000)
+ var url = vUrl.value
+ if (rawReq.jump == "true" || (rawReq.jump != "false" && (url.endsWith("/get") || url.endsWith("/head")) ) ) {
+ setTimeout(function () {
+ window.open(vUrl.value + "/" + encodeURIComponent(vInput.value))
+ }, 1000)
+ }
}
else if (App.User != null && App.User.id != null && App.User.id > 0) {
App.showTestCase(true, false) // 本地历史仍然要求登录 App.User == null || App.User.id == null)
From c2e84e8c4384b60d6d7a9b1ccb4ecfdc2eb277cc Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Mon, 27 Sep 2021 21:47:28 +0800
Subject: [PATCH 488/818] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=8C=96=E6=B3=A8?=
=?UTF-8?q?=E9=87=8A=EF=BC=9A=E6=96=B0=E5=A2=9E=E6=94=AF=E6=8C=81=20/get/U?=
=?UTF-8?q?ser=20=E7=AD=89=20APIJSON=20=E7=AE=80=E7=89=88=E6=8E=A5?=
=?UTF-8?q?=E5=8F=A3=20/{method}/{tag}?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
apijson/CodeUtil.js | 46 ++++++++++++++++++++++++++++++++++--------
apijson/JSONObject.js | 26 ++++++++++++++++++++++++
apijson/JSONRequest.js | 1 +
js/main.js | 13 ++++++------
4 files changed, 72 insertions(+), 14 deletions(-)
diff --git a/apijson/CodeUtil.js b/apijson/CodeUtil.js
index 372531b..70a3331 100644
--- a/apijson/CodeUtil.js
+++ b/apijson/CodeUtil.js
@@ -55,9 +55,39 @@ var CodeUtil = {
if (StringUtil.isEmpty(reqStr)) {
return '';
}
- method = method == null ? 'GET' : method;
+ method = method || 'get';
+ var isRestful = true;
+
+ if (method.startsWith("/")) {
+ method = method.substring(1);
+ }
+
+ if (method.endsWith("/")) {
+ method = method.substring(0, method.length - 1);
+ }
+
+ var startName = null;
+
var mIndex = method.indexOf('/');
- var isRestful = mIndex > 0 && mIndex < method.length - 1;
+ if (mIndex < 0) {
+ isRestful = false;
+ }
+ else if (APIJSON_METHODS.indexOf(method.substring(0, mIndex)) >= 0) {
+ var suffix = method.substring(mIndex + 1);
+ method = method.substring(0, mIndex);
+
+ mIndex = suffix.indexOf("/");
+ isRestful = mIndex >= 0;
+
+ if (isReq && ! isRestful) {
+ var tag = suffix.substring(mIndex + 1)
+ var tbl = tag.endsWith("[]") ? tag.substring(0, tag.length - 2) : tag;
+ if (JSONObject.isTableKey(tbl)) {
+ startName = method == 'put' || method == 'delete' ? tbl : tag;
+ }
+ }
+ }
+
if (isRestful != true) {
method = method.toUpperCase();
}
@@ -65,8 +95,8 @@ var CodeUtil = {
var lines = reqStr.split('\n');
var line;
- var depth = 0;
- var names = [];
+ var depth = startName == null ? 0 : 1;
+ var names = startName == null ? [] : [startName];
var isInSubquery = false;
var index;
@@ -76,12 +106,12 @@ var CodeUtil = {
var hintComment;
for (var i = 0; i < lines.length; i ++) {
- line = lines[i].trim();
+ line = lines[i].trim() || '';
//每一种都要提取:左边的key
- index = line == null ? -1 : line.indexOf(': '); //可能是 ' 或 ",所以不好用 ': , ": 判断
- key = index < 0 ? '' : line.substring(1, index - 1);
- var cIndex = line == null ? -1 : line.indexOf(' //');
+ index = line.indexOf(': '); //可能是 ' 或 ",所以不好用 ': , ": 判断
+ key = index < 0 ? (depth <= 1 && startName != null ? startName : '') : line.substring(1, index - 1);
+ var cIndex = line.indexOf(' //');
comment = '';
if (cIndex >= 0) {
diff --git a/apijson/JSONObject.js b/apijson/JSONObject.js
index 62a534d..448d479 100644
--- a/apijson/JSONObject.js
+++ b/apijson/JSONObject.js
@@ -59,6 +59,32 @@ var JSONObject = {
}
return key.endsWith('[]');
+ },
+
+ isAPIJSONPath: function (method) {
+ if (method == null) {
+ return false;
+ }
+
+ if (method.startsWith("/")) {
+ method = method.substring(1);
+ }
+
+ if (method.endsWith("/")) {
+ method = method.substring(0, method.length - 1);
+ }
+
+ var mIndex = method.indexOf('/');
+ if (mIndex < 0) {
+ return true;
+ }
+
+ if (APIJSON_METHODS.indexOf(method.substring(0, mIndex)) >= 0) {
+ mIndex = method.substring(mIndex + 1).indexOf("/");
+ return mIndex < 0;
+ }
+
+ return false;
}
}
diff --git a/apijson/JSONRequest.js b/apijson/JSONRequest.js
index 5d97f51..13aad57 100644
--- a/apijson/JSONRequest.js
+++ b/apijson/JSONRequest.js
@@ -28,6 +28,7 @@ var URL_HEADS = URL_BASE + "/heads"; // 通过POST来HEAD数据,不显示请
var URL_POST = URL_BASE + "/post"; // 新增(或者说插入)数据
var URL_PUT = URL_BASE + "/put"; // 修改数据,只修改传入字段对应的值
var URL_DELETE = URL_BASE + "/delete"; // 删除数据
+var APIJSON_METHODS = ["get", "head", "gets", "heads", "post", "put", "delete"]
/**请求,全走HTTP POST
diff --git a/js/main.js b/js/main.js
index 3044e1f..4819192 100755
--- a/js/main.js
+++ b/js/main.js
@@ -98,8 +98,7 @@
}
var method = App.getMethod();
- var mIndex = method == null ? -1 : method.indexOf('/');
- var isRestful = mIndex > 0 && mIndex < method.length - 1;
+ var isRestful = ! JSONObject.isAPIJSONPath(method);
try {
if (val instanceof Array) {
@@ -228,8 +227,7 @@
var column = null
var method = App.isTestCaseShow ? ((App.currentRemoteItem || {}).Document || {}).url : App.getMethod();
- var mIndex = method == null ? -1 : method.indexOf('/');
- var isRestful = mIndex > 0 && mIndex < method.length - 1;
+ var isRestful = ! JSONObject.isAPIJSONPath(method);
if (val instanceof Object && (val instanceof Array == false)) {
@@ -802,6 +800,10 @@
var url = new String(vUrl.value).trim()
var index = this.getBaseUrlLength(url)
url = index <= 0 ? url : url.substring(index)
+ index = url.indexOf("?")
+ if (index >= 0) {
+ url = url.substring(0, index)
+ }
return url.startsWith('/') ? url.substring(1) : url
},
//获取请求的tag
@@ -3156,8 +3158,7 @@
if (! isSingle) {
var method = App.getMethod(); // m 已经 toUpperCase 了
- var mIndex = method.indexOf('/');
- var isRestful = mIndex > 0 && mIndex < method.length - 1;
+ var isRestful = ! JSONObject.isAPIJSONPath(method);
if (isRestful != true) {
method = method.toUpperCase();
}
From ddf386c7cbb1048d35d4806615bf90bee4b16285 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Mon, 27 Sep 2021 22:28:22 +0800
Subject: [PATCH 489/818] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=8C=96=E6=B3=A8?=
=?UTF-8?q?=E9=87=8A=EF=BC=9A=E6=96=B0=E5=A2=9E=E6=94=AF=E6=8C=81=20APIJSO?=
=?UTF-8?q?N=20=E5=85=B3=E9=94=AE=E8=AF=8D=20@datasource?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
apijson/CodeUtil.js | 20 +++++++++++++++-----
index.html | 2 +-
2 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/apijson/CodeUtil.js b/apijson/CodeUtil.js
index 70a3331..7547aad 100644
--- a/apijson/CodeUtil.js
+++ b/apijson/CodeUtil.js
@@ -1202,6 +1202,7 @@ var CodeUtil = {
var combine = isTable ? value['@combine'] : null;
var schema = isTable ? value['@schema'] : null;
var database = isTable ? value['@database'] : null;
+ var datasource = isTable ? value['@datasource'] : null;
var raw = isTable ? value['@raw'] : null;
var role = isTable ? value['@role'] : null;
var explain = isTable ? value['@explain'] : null;
@@ -1216,6 +1217,7 @@ var CodeUtil = {
delete value['@combine'];
delete value['@schema'];
delete value['@database'];
+ delete value['@datasource'];
delete value['@raw'];
delete value['@role'];
delete value['@explain'];
@@ -1234,6 +1236,7 @@ var CodeUtil = {
s = combine == null ? s : s + '\n' + nextPrefix + name + '.setCombine(' + CodeUtil.getCode4Value(CodeUtil.LANGUAGE_JAVA, combine) + ');';
s = schema == null ? s : s + '\n' + nextPrefix + name + '.setSchema(' + CodeUtil.getCode4Value(CodeUtil.LANGUAGE_JAVA, schema) + ');';
s = database == null ? s : s + '\n' + nextPrefix + name + '.setDatabase(' + CodeUtil.getCode4Value(CodeUtil.LANGUAGE_JAVA, database) + ');';
+ s = datasource == null ? s : s + '\n' + nextPrefix + name + '.setDatasource(' + CodeUtil.getCode4Value(CodeUtil.LANGUAGE_JAVA, datasource) + ');';
s = raw == null ? s : s + '\n' + nextPrefix + name + '.setRaw(' + CodeUtil.getCode4Value(CodeUtil.LANGUAGE_JAVA, raw) + ');';
s = role == null ? s : s + '\n' + nextPrefix + name + '.setRole(' + CodeUtil.getCode4Value(CodeUtil.LANGUAGE_JAVA, role) + ');';
s = explain == null ? s : s + '\n' + nextPrefix + name + '.setExplain(' + CodeUtil.getCode4Value(CodeUtil.LANGUAGE_JAVA, explain) + ');';
@@ -1338,6 +1341,9 @@ var CodeUtil = {
if (key == '@database') {
return '\n' + parentKey + '.setDatabase(' + valStr + ');';
}
+ if (key == '@datasource') {
+ return '\n' + parentKey + '.setDatasource(' + valStr + ');';
+ }
if (key == '@role') {
return '\n' + parentKey + '.setRole(' + valStr + ');';
}
@@ -5838,7 +5844,7 @@ var CodeUtil = {
OWNER: '拥有者',
ADMIN: '管理员'
},
- DATABASE_KEYS: ['MYSQL', 'POSTGRESQL', 'SQLSERVER', 'ORACLE', 'DB2', 'SQLITE'],
+ DATABASE_KEYS: ['MYSQL', 'POSTGRESQL', 'SQLSERVER', 'ORACLE', 'DB2', 'CLICKHOUSE', 'SQLITE'],
/**获取请求JSON的注释
* @param tableList
@@ -5910,7 +5916,7 @@ var CodeUtil = {
}
else if (value instanceof Object) {
if (isRestful != true && StringUtil.isEmpty(key, true)) {
- return ' ' + CodeUtil.getComment('根对象,可在内部加 format,tag,version,@role,@database,@schema,@explain,@cache 等全局关键词键值对', false, ' ');
+ return ' ' + CodeUtil.getComment('根对象,可在内部加 format,tag,version,@role,@database,@schema,@datasource,@explain,@cache 等全局关键词键值对', false, ' ');
}
if (isRestful != true && key.endsWith('@')) {
@@ -6052,13 +6058,15 @@ var CodeUtil = {
case '@combine':
return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('条件组合' + (isValueNotEmpty ? '' : ',例如 "name$,tag$" "!userId<,!toId" 等'), false, ' ');
case '@schema':
- return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('集合空间' + (isValueNotEmpty ? '' : ',例如 "sys" "apijson" 等'), false, ' ');
+ return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('集合空间(数据库名/模式)' + (isValueNotEmpty ? '' : ',例如 "sys" "apijson" "postgres" "dbo" 等'), false, ' ');
+ case '@datasource':
+ return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('跨数据源' + (isValueNotEmpty ? '' : ',例如 "DRUID" "HIKARICP" 等'), false, ' ');
case '@raw':
return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('原始SQL' + (isValueNotEmpty ? '' : ',例如 "@column" "id{},@having" 等'), false, ' ');
case '@json':
return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('转为JSON' + (isValueNotEmpty ? '' : ',例如 "request" "gets,heads" 等'), false, ' ');
case '@database':
- return CodeUtil.DATABASE_KEYS.indexOf(value) < 0 ? ' ! value必须是[' + CodeUtil.DATABASE_KEYS.join() + ']中的一种!' : CodeUtil.getComment('数据库:例如 "MYSQL" "POSTGRESQL" "SQLSERVER" "ORACLE" 等', false, ' ');
+ return CodeUtil.DATABASE_KEYS.indexOf(value) < 0 ? ' ! value必须是[' + CodeUtil.DATABASE_KEYS.join() + ']中的一种!' : CodeUtil.getComment('数据库类型:例如 "MYSQL" "POSTGRESQL" "SQLSERVER" "ORACLE" "DB2" "CLICKHOUSE" 等', false, ' ');
case '@role':
var role = CodeUtil.ROLES[value];
return StringUtil.isEmpty(role) ? ' ! value必须是[' + CodeUtil.ROLE_KEYS.join() + ']中的一种!' : CodeUtil.getComment('来访角色:' + role, false, ' ');
@@ -6094,7 +6102,9 @@ var CodeUtil = {
case 'format':
return valuesIsNotBoolean ? ' ! value必须是Boolean类型!' : CodeUtil.getComment('格式化: true-是 false-否', false, ' ');
case '@schema':
- return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('集合空间' + (isValueNotEmpty ? '' : ',例如 "sys" "apijson" 等'), false, ' ');
+ return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('集合空间(数据库名/模式)' + (isValueNotEmpty ? '' : ',例如 "sys" "apijson" "postgres" "dbo" 等'), false, ' ');
+ case '@datasource':
+ return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('跨数据源' + (isValueNotEmpty ? '' : ',例如 "DRUID" "HIKARICP" 等'), false, ' ');
case '@database':
return CodeUtil.DATABASE_KEYS.indexOf(value) < 0 ? ' ! value必须是[' + CodeUtil.DATABASE_KEYS.join() + ']中的一种!' : CodeUtil.getComment('数据库' + (isValueNotEmpty ? '' : ',例如 "MYSQL" "POSTGRESQL" "SQLSERVER" "ORACLE" 等'), false, ' ');
case '@role':
diff --git a/index.html b/index.html
index ff466df..87ac6f7 100755
--- a/index.html
+++ b/index.html
@@ -115,7 +115,7 @@
{{ (isHeaderShow ? '隐藏(固定)' : '显示(编辑)') + (isEditResponse ? '响应头 Response Header' : '请求头 Request Header' ) }}
生成代码(封装,解析) : {{ language || '例如 Java' }}
数据库类型 Database: {{ database || '例如 MYSQL' }}
- 数据库模式 Schema: {{ schema || '例如 sys' }}
+ 数据库名/模式 Schema: {{ schema || '例如 sys' }}
使用的请求类型: {{ types == null || types.length <= 0 ? '点击设置' : types.join() }}
托管服务器地址 URL: {{ server || '点击设置' }}
导入第三方文档(平台名 URL):
{{ thirdParty || '点击设置' }}
From 6a2a35c29bdc4c3d8eaa31abc719af79a72d8eaf Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Tue, 28 Sep 2021 02:07:12 +0800
Subject: [PATCH 490/818] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E9=9D=99=E6=80=81?=
=?UTF-8?q?=E6=A3=80=E6=9F=A5=EF=BC=9A=E5=AE=8C=E5=96=84=20APIJSON=20?=
=?UTF-8?q?=E5=AD=97=E6=AE=B5=E7=B1=BB=E5=9E=8B=E5=8F=8A=E5=90=84=E7=A7=8D?=
=?UTF-8?q?=E5=8A=9F=E8=83=BD=E7=9A=84=E6=A0=A1=E9=AA=8C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
apijson/CodeUtil.js | 168 +++++++++++++++++++++++++++++++++-----------
1 file changed, 126 insertions(+), 42 deletions(-)
diff --git a/apijson/CodeUtil.js b/apijson/CodeUtil.js
index 7547aad..2c17424 100644
--- a/apijson/CodeUtil.js
+++ b/apijson/CodeUtil.js
@@ -5612,6 +5612,7 @@ var CodeUtil = {
return 'time_t' + length;
case CodeUtil.LANGUAGE_JAVA_SCRIPT:
+ return 'string';
case CodeUtil.LANGUAGE_TYPE_SCRIPT:
break;
@@ -5921,13 +5922,13 @@ var CodeUtil = {
if (isRestful != true && key.endsWith('@')) {
if (key == '@from@') {
- return CodeUtil.getComment('数据来源:子查询' + (isValueNotEmpty ? ',里面必须有 from 键值对和 表对象 Table:{}' : ',例如 { "from":"User", "User":{} }'), false, ' ');
+ return CodeUtil.getComment('数据来源:子查询' + (isValueNotEmpty ? ',里面必须有 "from":Table, Table:{}' : ',例如 { "from":"User", "User":{} }'), false, ' ');
}
var aliaIndex = name == null ? -1 : name.indexOf(':');
var objName = aliaIndex < 0 ? name : name.substring(0, aliaIndex);
if (JSONObject.isTableKey(objName)) {
- return CodeUtil.getComment('子查询 < ' + CodeUtil.getCommentFromDoc(tableList, objName, key.substring(0, key.length - 1), method, database, language, false, isReq, pathKeys, isRestful, value), false, ' ');
+ return CodeUtil.getComment('子查询,里面必须有 "from":Table, Table:{} < ' + CodeUtil.getCommentFromDoc(tableList, objName, key.substring(0, key.length - 1), method, database, language, false, isReq, pathKeys, isRestful, value, null, null, true), false, ' ');
}
return CodeUtil.getComment('子查询,可在内部加 from,range 或 数组关键词 等键值对,需要被下面的表字段相关 key 引用赋值', false, ' ');
}
@@ -5977,13 +5978,14 @@ var CodeUtil = {
return value != null && value < 0 ? ' ! 必须 >= 0 !' : CodeUtil.getComment('分页页码' + (isValueNotEmpty ? '' : ': 例如 0 1 2 ...'), false, ' ');
case 'query':
var query = CodeUtil.QUERY_TYPES[value];
- return StringUtil.isEmpty(query) ? ' ! value必须是[' + CodeUtil.QUERY_TYPE_KEYS.join() + ']中的一种!' : CodeUtil.getComment('查询内容:0-数据 1-总数 2-全部', false, ' ');
+ return StringUtil.isEmpty(query) ? ' ! value必须是[' + CodeUtil.QUERY_TYPE_KEYS.join() + ']中的一种!' : CodeUtil.getComment('查询内容:0-对象 1-总数和分页详情 2-数据、总数和分页详情', false, ' ');
case 'join':
if (valuesIsNotString) {
return ' ! value必须是String类型!';
}
var s = '';
+ var must = '';
var items = value.length < 1 ? null : StringUtil.split(value);
if (items != null && items.length > 0) {
@@ -6017,11 +6019,12 @@ var CodeUtil = {
return ' ! 表名 ' + t + ' 不合法 ! 必须是 Table 这种大驼峰格式' + (isValueNotEmpty ? '' : ',例如 "User" "Comment" "ViewTable" 等 !');
}
- s += CodeUtil.JOIN_TYPES[c] + ' JOIN ' + t + (a.length <= 0 ? '' : ' AS ' + a) + ' ';
+ s += CodeUtil.JOIN_TYPES[c] + ' JOIN ' + t + (a.length <= 0 ? '' : ' AS ' + a);
+ must += (i > 0 ? ', ' : ',同一层级必须有 "') + t + '":{ "' + item.substring(lastIndex + 1) + '":"/../.." }';
}
}
- return CodeUtil.getComment('多表连接:' + (s || '例如 &/User/id@, RIGHT, * CROSS, & INNER, | FULL, ! OUTER, ^ SIDE, ( ANTI, ) FOREIGN'), false, ' ');
default:
if (isInSubquery) {
@@ -6032,7 +6035,7 @@ var CodeUtil = {
}
return CodeUtil.SUBQUERY_RANGES.indexOf(value) < 0 ? ' ! value必须是[' + CodeUtil.SUBQUERY_RANGES.join() + ']中的一种!' : CodeUtil.getComment('比较范围:ANY-任意 ALL-全部', false, ' ');
case 'from':
- return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('数据来源' + (isValueNotEmpty ? ',同一层级必须有对应的 "' + value + '":{...}' : ',例如 "User",同一层级必须有对应的 "User":{...}'), false, ' ');
+ return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('数据来源' + (isValueNotEmpty ? ',同一层级必须有 "' + value + '":{...}' : ',例如 "User",同一层级必须有 "User":{...}'), false, ' ');
}
}
break;
@@ -6046,39 +6049,39 @@ var CodeUtil = {
if (isRestful != true && JSONObject.isTableKey(objName)) {
switch (key) {
case '@column':
- return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('返回字段' + (isValueNotEmpty ? '' : ':例如 "name" "toId:parentId" "id,userId;json_length(praiseUserIdList):praiseCount" 等'), false, ' ');
+ return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('返回字段' + (isValueNotEmpty ? ',可传 字段(:别名)、SQL 函数(:别名,用分号 ; 隔开)、表达式,以及部分 SQL 关键词' : ':例如 "name" "toId:parentId" "id,userId;json_length(praiseUserIdList):praiseCount" 等'), false, ' ');
case '@from@': //value 类型为 Object 时 到不了这里,已在上方处理
return valuesIsNotString && typeOfValue != 'object' ? ' ! value必须是String或Object类型!' : CodeUtil.getComment('数据来源:引用赋值 子查询 "' + value + '@":{...} ', false, ' ');
case '@group':
return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('分组方式' + (isValueNotEmpty ? '' : ',例如 "userId" "momentId,toId" 等'), false, ' ');
case '@having':
- return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('SQL函数' + (isValueNotEmpty ? '' : ',例如 "max(id)>100" "length(phone)>0;sum(balance)<=10000" 等'), false, ' ');
+ return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('聚合函数' + (isValueNotEmpty ? ',可传 SQL 函数(用分号 ; 隔开)、表达式,以及部分 SQL 关键词' : ',例如 "max(id)>100" "length(phone)>0;sum(balance)<=10000" 等'), false, ' ');
case '@order':
return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('排序方式:+升序,-降序' + (isValueNotEmpty ? '' : ',例如 "date-" "name+,id-" 等'), false, ' ');
- case '@combine':
- return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('条件组合' + (isValueNotEmpty ? '' : ',例如 "name$,tag$" "!userId<,!toId" 等'), false, ' ');
+ case '@combine': //TODO 解析 value 并直接给出条件组合结果
+ return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('条件组合' + (isValueNotEmpty ? ',| 可省略。合并同类,外层按照 & | ! 顺序,内层按传参顺序组合成 (key0 & key1 & key6 & 其它key) & (key2 | key3 | key7) & !(key4 | key5)' : ',例如 "name$,tag$" "!userId<,!toId" 等'), false, ' ');
case '@schema':
return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('集合空间(数据库名/模式)' + (isValueNotEmpty ? '' : ',例如 "sys" "apijson" "postgres" "dbo" 等'), false, ' ');
case '@datasource':
return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('跨数据源' + (isValueNotEmpty ? '' : ',例如 "DRUID" "HIKARICP" 等'), false, ' ');
case '@raw':
- return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('原始SQL' + (isValueNotEmpty ? '' : ',例如 "@column" "id{},@having" 等'), false, ' ');
+ return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('原始SQL片段' + (isValueNotEmpty ? ',由后端 RAW_MAP 代码配置指定 "key0,key1.." 中每个 key 对应 key:"SQL片段" 中的 SQL片段' : ',例如 "@column" "id{},@having" 等'), false, ' ');
case '@json':
return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('转为JSON' + (isValueNotEmpty ? '' : ',例如 "request" "gets,heads" 等'), false, ' ');
case '@database':
return CodeUtil.DATABASE_KEYS.indexOf(value) < 0 ? ' ! value必须是[' + CodeUtil.DATABASE_KEYS.join() + ']中的一种!' : CodeUtil.getComment('数据库类型:例如 "MYSQL" "POSTGRESQL" "SQLSERVER" "ORACLE" "DB2" "CLICKHOUSE" 等', false, ' ');
case '@role':
var role = CodeUtil.ROLES[value];
- return StringUtil.isEmpty(role) ? ' ! value必须是[' + CodeUtil.ROLE_KEYS.join() + ']中的一种!' : CodeUtil.getComment('来访角色:' + role, false, ' ');
+ return StringUtil.isEmpty(role) ? ' ! value必须是[' + CodeUtil.ROLE_KEYS.join() + ']中的一种!' : CodeUtil.getComment('来访角色:' + role + ',限制可操作的数据,假定真实强制匹配', false, ' ');
case '@cache':
var cache = CodeUtil.CACHE_TYPES[value];
return StringUtil.isEmpty(cache) ? ' ! value必须是[' + CodeUtil.CACHE_TYPE_KEYS.join() + ']中的一种!' : CodeUtil.getComment('缓存方式:0-全部 1-磁盘 2-内存', false, ' ');
case '@explain':
- return valuesIsNotBoolean ? ' ! value必须是Boolean类型!' : CodeUtil.getComment('性能分析:true-开启 false-关闭', false, ' ');
+ return valuesIsNotBoolean ? ' ! value必须是Boolean类型!' : CodeUtil.getComment('性能分析:true-开启 false-关闭,返回执行的 SQL 及查询计划', false, ' ');
}
if (key.startsWith('@')) {
if (key.endsWith('()')) {
- return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('存储过程' + (isValueNotEmpty ? '' : ':例如 "getCommentByUserId(id,@limit,@offset)"'), false, ' ');
+ return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('存储过程' + (isValueNotEmpty ? ',触发调用数据库存储过程' : ':例如 "getCommentByUserId(id,@limit,@offset)"'), false, ' ');
}
return '';
}
@@ -6090,17 +6093,11 @@ var CodeUtil = {
if (isRestful != true && StringUtil.isEmpty(name)) {
switch (key) {
case 'tag':
- // if (method == 'GET' || method == 'HEAD') {
- // return '';
- // }
- return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('请求标识' + (method == 'GET' || method == 'HEAD' ? ',GET,HEAD 请求不会自动解析,仅为后续迭代可能的手动优化而预留' : (isValueNotEmpty ? '' : ',例如 "User" "Comment[]" "Privacy-CIRCLE" 等')), false, ' ');
+ return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('请求标识' + (method == 'GET' || method == 'HEAD' ? ',GET,HEAD 请求不会自动解析,仅为后续迭代可能的手动优化而预留' : (isValueNotEmpty ? ',用来区分不同请求并校验,由后端 Request 表中指定' : ',例如 "User" "Comment[]" "Privacy-CIRCLE" 等')), false, ' ');
case 'version':
- if (method == 'GET' || method == 'HEAD') {
- return '';
- }
- return value != null && valuesIsNotInteger ? ' ! value必须是Integer类型!' : CodeUtil.getComment('版本号' + (isValueNotEmpty ? '' : ',例如 1 2 3 等'), false, ' ');
+ return valuesIsNotInteger ? ' ! value必须是Integer类型!' : CodeUtil.getComment('版本号' + (method == 'GET' || method == 'HEAD' ? ',GET,HEAD 请求不会自动解析,仅为后续迭代可能的手动优化而预留' : (isValueNotEmpty ? ',用来使用特定版本的校验规则,由后端 Request 表中指定' : ',例如 1 2 3 等')), false, ' ');
case 'format':
- return valuesIsNotBoolean ? ' ! value必须是Boolean类型!' : CodeUtil.getComment('格式化: true-是 false-否', false, ' ');
+ return valuesIsNotBoolean ? ' ! value必须是Boolean类型!' : CodeUtil.getComment('格式化: true-是 false-否,将 TableName 转为 tableName, TableName[] 转为 tableNameList, Table:alias 转为 alias 等小驼峰格式', false, ' ');
case '@schema':
return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('集合空间(数据库名/模式)' + (isValueNotEmpty ? '' : ',例如 "sys" "apijson" "postgres" "dbo" 等'), false, ' ');
case '@datasource':
@@ -6114,7 +6111,7 @@ var CodeUtil = {
var cache = CodeUtil.CACHE_TYPES[value];
return StringUtil.isEmpty(cache) ? ' ! value必须是[' + CodeUtil.CACHE_TYPE_KEYS.join() + ']中的一种!' : CodeUtil.getComment('缓存方式:0-全部 1-磁盘 2-内存', false, ' ');
case '@explain':
- return valuesIsNotBoolean ? ' ! value必须是Boolean类型!' : CodeUtil.getComment('性能分析:true-开启 false-关闭', false, ' ');
+ return valuesIsNotBoolean ? ' ! value必须是Boolean类型!' : CodeUtil.getComment('性能分析:true-开启 false-关闭,返回执行的 SQL 及查询计划', false, ' ');
}
}
@@ -6131,7 +6128,7 @@ var CodeUtil = {
* @param onlyTableAndColumn
* @return {*}
*/
- getCommentFromDoc: function (tableList, tableName, columnName, method, database, language, onlyTableAndColumn, isReq, pathKeys, isRestful, value, ignoreError, standardObj) {
+ getCommentFromDoc: function (tableList, tableName, columnName, method, database, language, onlyTableAndColumn, isReq, pathKeys, isRestful, value, ignoreError, standardObj, isSubquery) {
log('getCommentFromDoc tableName = ' + tableName + '; columnName = ' + columnName
+ '; method = ' + method + '; database = ' + database + '; language = ' + language
+ '; onlyTableAndColumn = ' + onlyTableAndColumn + '; tableList = \n' + JSON.stringify(tableList));
@@ -6155,10 +6152,14 @@ var CodeUtil = {
var typeOfValue = CodeUtil.getType4Request(value);
var valuesIsNotString = typeOfValue != 'string';
- // var valuesIsNotInteger = typeOfValue != 'integer';
- // var valuesIsNotNumber = valuesIsNotInteger && typeOfValue != 'number';
+ var valuesIsNotInteger = typeOfValue != 'integer';
+ var valuesIsNotNumber = valuesIsNotInteger && typeOfValue != 'number';
var valuesIsNotArray = typeOfValue != 'array';
var valuesIsNotObject = typeOfValue != 'object';
+ var valuesIsNotStringOrObject = valuesIsNotString && valuesIsNotObject;
+ var valuesIsNotStringOrArray = valuesIsNotString && valuesIsNotArray;
+ var valuesIsNotStringOrNumber = valuesIsNotString && valuesIsNotNumber;
+ var valuesIsNotStringOrNumberOrObject = valuesIsNotStringOrNumber && valuesIsNotObject;
var valuesIsNotStringOrArrayOrObject = valuesIsNotString && valuesIsNotArray && valuesIsNotObject;
var isValueNotEmpty = valuesIsNotString ? (typeOfValue != 'array' ? value != null : value.length > 0) : StringUtil.isEmpty(value, true) != true;
@@ -6276,6 +6277,8 @@ var CodeUtil = {
var key;
var logic = '';
+ var verifyType = isSubquery != true && value != null;
+
if (onlyTableAndColumn) {
key = new String(columnName);
}
@@ -6284,29 +6287,69 @@ var CodeUtil = {
//功能符 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
if (columnName.endsWith("()")) {//方法,查询完后处理,先用一个Map保存?
- return '远程函数' + (isValueNotEmpty ? '' : ',例如 "isContain(praiseUserIdList,userId)"');
- }
+ if (['GET', 'HEAD'].indexOf(method) < 0) {
+ return ' ! 远程函数只能用于 GET,HEAD 请求!!';
+ }
+ if (value != null && valuesIsNotString) {
+ return ' ! value必须是String类型!';
+ }
+ if (value != null) {
+ var startIndex = value.indexOf("(");
+ if (startIndex <= 0 || value.endsWith(")") == false) {
+ return ' ! value必须符合 fun(arg0,arg1..) 这种格式!且不要有任何多余的空格!';
+ }
+ var fun = value.substring(0, startIndex);
+ if (StringUtil.isName(fun) != true) {
+ return '! 函数名' + fun + '不合法!value必须符合 fun(arg0,arg1..) 这种格式!且不要有任何多余的空格!';
+ }
+ }
+ var priority = '';
+ if (columnName.endsWith("-()")) {
+ priority = ' < 在解析所在对象前优先执行';
+ }
+ else if (columnName.endsWith("+()")) {
+ priority = ' < 在解析所在对象后滞后执行';
+ }
+ else {
+ priority = ',执行时机在解析所在对象后,解析子对象前,可以在 () 前用 + - 设置优先级,例如 key-() 优先执行';
+ }
+
+ return '远程函数' + (isValueNotEmpty ? ',触发调用后端对应的方法/函数' + priority : ',例如 "isContain(praiseUserIdList,userId)"');
+ }
+
+ var hasAt = false;
if (columnName.endsWith("@")) {//引用,引用对象查询完后处理。fillTarget中暂时不用处理,因为非GET请求都是由给定的id确定,不需要引用
// 没传 value 进来,不好解析,而且太长导致后面的字段属性被遮住
// var lastIndex = value.lastIndexOf('/');
// var refLastPath =
// at = '引用赋值: ' + tableName + '.' + columnName + '=' + ;
+ hasAt = true;
- at = '引用赋值' + (isValueNotEmpty ? '' : ',例如 "User/id" "[]/Moment/id" 等');
+ at = '引用赋值' + (isValueNotEmpty ? (value.startsWith('/') ? ',从对象父级开始的相对(缺省)路径' : ',从最外层开始的绝对(完整)路径') : ',例如 "User/id" "[]/Moment/id" 等');
columnName = columnName.substring(0, columnName.length - 1);
+
+ if (value != null && valuesIsNotStringOrObject) {
+ return ' ! value必须是String或Object类型!';
+ }
+
+ verifyType = false;
}
if (columnName.endsWith("$")) {//搜索,查询时处理
- if (value != null && valuesIsNotStringOrArrayOrObject) {
- return ' ! value必须是String,Array或Object类型!';
- }
+ if (verifyType && hasAt != true && valuesIsNotStringOrArray) {
+ return ' ! value必须是String或Array类型!';
+ }
fun = '模糊搜索' + (isValueNotEmpty ? '' : ',例如 "%c%" "S%" "%end" 等');
key = columnName.substring(0, columnName.length - 1);
}
else if (columnName.endsWith("~")) {//匹配正则表达式,查询时处理
+ if (verifyType && hasAt != true && valuesIsNotStringOrArray) {
+ return ' ! value必须是String或Array类型!';
+ }
+
fun = '正则匹配' + (isValueNotEmpty ? '' : ',例如 "C" "^[0-9]+$" "^[a-zA-Z]+$" 等');
key = columnName.substring(0, columnName.length - 1);
if (key.endsWith("*")) {
@@ -6315,26 +6358,41 @@ var CodeUtil = {
}
}
else if (columnName.endsWith("%")) {//连续范围 BETWEEN AND,查询时处理
- if (value != null && valuesIsNotStringOrArrayOrObject) {
- return ' ! value必须是String,Array或Object类型!';
+ if (verifyType && hasAt != true && valuesIsNotStringOrArray) {
+ return ' ! value必须是String或Array类型!';
}
+
fun = '连续范围' + (isValueNotEmpty ? '' : ',例如 "82001,82020" "2018-01-01,2020-01-01" ["1-10", "90-100"] 等');
key = columnName.substring(0, columnName.length - 1);
}
else if (columnName.endsWith("{}")) {//被包含,或者说key对应值处于value的范围内。查询时处理
- if (value != null && valuesIsNotStringOrArrayOrObject) {
- return ' ! value必须是String,Array或Object类型!';
+ if (verifyType && hasAt != true && valuesIsNotStringOrArray) {
+ return ' ! value必须是String或Array类型!';
}
+
fun = '匹配 选项/条件' + (isValueNotEmpty ? '' : ',例如 ' + (valuesIsNotString ? '[1, 2, 3] ["%c%", "S%", "%end"] 等' : '">100" "%2=0;<=100000" 等'));
key = columnName.substring(0, columnName.length - 2);
+
+ verifyType = false;
}
else if (columnName.endsWith("<>")) {//包含,或者说value处于key对应值的范围内。查询时处理
fun = '包含选项' + (isValueNotEmpty ? '' : ',例如 1 "Test" [82001, 82002] 等');
key = columnName.substring(0, columnName.length - 2);
+
+ verifyType = false;
}
else if (columnName.endsWith("}{")) {//存在,EXISTS。查询时处理
+ if (verifyType && hasAt != true && isSubquery != true) {
+ return ' ! key}{ 后面必须接 @,写成 key}{@:{} 格式!';
+ }
+ if (verifyType && valuesIsNotObject) {
+ return ' ! value必须是Object类型!';
+ }
+
fun = '是否存在' + (isValueNotEmpty ? '' : ',例如 { "from":"Comment", "Comment":{ "@column":"userId" } }');
key = columnName.substring(0, columnName.length - 2);
+
+ verifyType = false;
}
else if (columnName.endsWith("+")) {//延长,PUT查询时处理
if (method != 'PUT') {//不为PUT就抛异常
@@ -6351,18 +6409,34 @@ var CodeUtil = {
key = columnName.substring(0, columnName.length - 1);
}
else if (columnName.endsWith(">=")) {//大于或等于
+ if (verifyType && hasAt != true && valuesIsNotStringOrNumber) {
+ return ' ! value必须是String或Number类型!';
+ }
+
fun = '大于或等于' + (isValueNotEmpty ? '' : ',例如 1 9.9 "2020-01-01" 等');
key = columnName.substring(0, columnName.length - 2);
}
else if (columnName.endsWith("<=")) {//小于或等于
+ if (verifyType && hasAt != true && valuesIsNotStringOrNumber) {
+ return ' ! value必须是String或Number类型!';
+ }
+
fun = '小于或等于' + (isValueNotEmpty ? '' : ',例如 1 9.9 "2020-01-01" 等');
key = columnName.substring(0, columnName.length - 2);
}
else if (columnName.endsWith(">")) {//大于
+ if (verifyType && hasAt != true && valuesIsNotStringOrNumber) {
+ return ' ! value必须是String或Number类型!';
+ }
+
fun = '大于' + (isValueNotEmpty ? '' : ',例如 1 9.9 "2020-01-01" 等');
key = columnName.substring(0, columnName.length - 1);
}
else if (columnName.endsWith("<")) {//小于
+ if (verifyType && hasAt != true && valuesIsNotStringOrNumber) {
+ return ' ! value必须是String或Number类型!';
+ }
+
fun = '小于' + (isValueNotEmpty ? '' : ',例如 1 9.9 "2020-01-01" 等');
key = columnName.substring(0, columnName.length - 1);
}
@@ -6391,10 +6465,9 @@ var CodeUtil = {
logic = '';
}
-
if (logic.length > 0) {
- if (method != 'GET' && method != 'HEAD' && method != 'GETS' && method != 'HEADS') {//逻辑运算符仅供GET,HEAD方法使用
- return ' ! 逻辑运算符 & | ! 只能用于查询(GET,HEAD,GETS,HEADS)请求!';
+ if (['GET', 'HEAD', 'GETS', 'HEADS', 'PUT', 'DELETE'].indexOf(method) < 0) {//逻辑运算符仅供GET,HEAD方法使用
+ return ' ! 逻辑运算符 & | ! 只能用于 GET,HEAD,GETS,HEADS,PUT,DELETE 请求!';
}
key = key.substring(0, key.length - 1);
}
@@ -6404,7 +6477,6 @@ var CodeUtil = {
}
//功能符 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-
}
columnList = item['[]'];
@@ -6437,7 +6509,19 @@ var CodeUtil = {
);
column.column_type = CodeUtil.getColumnType(column, database);
- return (p.length <= 0 ? '' : p + key + ': ') + CodeUtil.getType4Language(language, column.column_type, true) + (column.is_nullable == 'YES' ? '? ' : ', ') + (o || {}).column_comment;
+ var t = CodeUtil.getType4Language(language, column.column_type, true);
+ var c = (p.length <= 0 ? '' : p + key + ': ') + t + (column.is_nullable == 'YES' ? '? ' : ', ') + (o || {}).column_comment;
+
+ var ct = CodeUtil.getType4Language(CodeUtil.LANGUAGE_JAVA_SCRIPT, column.column_type, false);
+ if (verifyType && t != null && CodeUtil.isTypeMatch(ct, CodeUtil.getType4Language(CodeUtil.LANGUAGE_JAVA_SCRIPT, typeOfValue))) {
+ // c = ' ! value必须是' + t + '类型!' + CodeUtil.getComment(c, false, ' ')
+ // if (ignoreError != true) {
+ // throw new Error(c);
+ // }
+ return ' ! value必须是' + t + '类型!' + CodeUtil.getComment(c, false, ' ')
+ }
+
+ return c;
}
return onlyTableAndColumn ? '' : ' ! 字段 ' + key + ' 不存在!只能是 [' + columnNames.join() + '] 中的一个!';
From cf78c9d9faedaf8232659d6651a112f1b4211141 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Tue, 28 Sep 2021 03:10:08 +0800
Subject: [PATCH 491/818] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E8=A7=86=E9=A2=91?=
=?UTF-8?q?=E6=95=99=E7=A8=8B=E9=93=BE=E6=8E=A5=EF=BC=9B=E6=96=B0=E5=A2=9E?=
=?UTF-8?q?=20apijson-go=20=E9=93=BE=E6=8E=A5=EF=BC=8C=E6=9B=BF=E6=8D=A2?=
=?UTF-8?q?=20APIJSON=20PHP=20=E9=93=BE=E6=8E=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
index.html | 2 +-
js/main.js | 5 +++--
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/index.html b/index.html
index 87ac6f7..7975706 100755
--- a/index.html
+++ b/index.html
@@ -79,7 +79,7 @@
diff --git a/js/main.js b/js/main.js
index 4819192..ae6c1b9 100755
--- a/js/main.js
+++ b/js/main.js
@@ -3126,7 +3126,7 @@
vSend.disabled = false;
if (App.isEditResponse != true) {
- vOutput.value = output = 'OK,请点击 [发送请求] 按钮来测试。[点击这里查看视频教程](http://i.youku.com/apijson)' + code;
+ vOutput.value = output = 'OK,请点击 [发送请求] 按钮来测试。[点击这里查看视频教程](https://i.youku.com/i/UNTg1NzI1MjQ4MA==/videos?spm=a2hzp.8244740.0.0)' + code;
App.showDoc()
}
@@ -3762,8 +3762,9 @@
+ '\nAPIJSON 英文文档: https://github.com/ruoranw/APIJSONdocs '
+ '\nAPIJSON 官方网站: https://github.com/APIJSON/apijson.org '
+ '\nAPIJSON -Java版: https://github.com/Tencent/APIJSON '
+ + '\nAPIJSON - Go 版: https://gitee.com/tiangao/apijson-go '
+ '\nAPIJSON - C# 版: https://github.com/liaozb/APIJSON.NET '
- + '\nAPIJSON - PHP版: https://github.com/qq547057827/apijson-php '
+ + '\nAPIJSON - PHP版: https://github.com/xianglong111/APIJSON-php '
+ '\nAPIJSON -Node版: https://github.com/kevinaskin/apijson-node '
+ '\nAPIJSON -Python: https://github.com/zhangchunlin/uliweb-apijson '
+ '\n感谢热心的作者们的贡献,GitHub 右上角点 ⭐Star 支持下他们吧 ^_^';
From fe6d475405d88af8ac378519bda657f371703efe Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Tue, 28 Sep 2021 03:22:38 +0800
Subject: [PATCH 492/818] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E5=A4=B1=E6=95=88?=
=?UTF-8?q?=E7=9A=84=20apijson.org=20=E4=B8=BA=20apijson.cn?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 2 +-
index.html | 6 +++---
js/main.js | 26 +++++++++++++-------------
3 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/README.md b/README.md
index 5d8a75d..1088acd 100755
--- a/README.md
+++ b/README.md
@@ -97,7 +97,7 @@ https://www.bilibili.com/video/BV1yv411p7Y4
### 部署方法
可以直接下载源码解压后用浏览器打开 index.html,建议用 Chrome 或 火狐 (Safari、Edge、IE 等可能有兼容问题)。
-也可以直接访问官网的线上环境 http://apijson.cn/api 或开发环境 http://apijson.org:8000/api 。
+也可以直接访问官方网站 http://apijson.cn/api
把左侧 URL 输入框内基地址改为你主机的地址(例如 http://localhost:8080 ),
然后在右上角 设置 下拉菜单内修改 数据库类型Database、数据库模式Schema。
diff --git a/index.html b/index.html
index 7975706..4e0aba5 100755
--- a/index.html
+++ b/index.html
@@ -68,8 +68,8 @@

-
- APIJSON.org
+
+ APIJSON.cn
2s
@@ -86,7 +86,7 @@
-
+
diff --git a/js/main.js b/js/main.js
index ae6c1b9..1d37789 100755
--- a/js/main.js
+++ b/js/main.js
@@ -592,13 +592,13 @@
balance: null //点击更新提示需要判空 0.00
},
type: REQUEST_TYPE_JSON,
- types: [ REQUEST_TYPE_PARAM, REQUEST_TYPE_JSON, REQUEST_TYPE_FORM, REQUEST_TYPE_DATA, REQUEST_TYPE_GRPC ], //默认展示
+ types: [ REQUEST_TYPE_PARAM, REQUEST_TYPE_JSON], // 很多人喜欢用 GET 接口测试,默认的 JSON 看不懂 , REQUEST_TYPE_FORM, REQUEST_TYPE_DATA, REQUEST_TYPE_GRPC ], //默认展示
host: '',
database: 'MYSQL', // 查文档必须,除非后端提供默认配置接口 // 用后端默认的,避免用户总是没有配置就问为什么没有生成文档和注释 'MYSQL',// 'POSTGRESQL',
schema: 'sys', // 查文档必须,除非后端提供默认配置接口 // 用后端默认的,避免用户总是没有配置就问为什么没有生成文档和注释 'sys',
- server: 'http://apijson.cn:9090/', // Chrome 90+ 跨域问题非常难搞,开发模式启动都不行了 'http://apijson.org:9090/', //apijson.org:8000
+ server: 'http://apijson.cn:9090/', // Chrome 90+ 跨域问题非常难搞,开发模式启动都不行了 'http://apijson.org:9090/', //apijson.cn
// server: 'http://47.74.39.68:9090/', // apijson.org
- thirdParty: 'SWAGGER /v2/api-docs', //apijson.org:8000
+ thirdParty: 'SWAGGER /v2/api-docs', //apijson.cn
// thirdParty: 'RAP /repository/joined /repository/get',
// thirdParty: 'YAPI /api/interface/list_menu /api/interface/get',
language: CodeUtil.LANGUAGE_KOTLIN,
@@ -1052,7 +1052,7 @@
response: api.res_body == null ? null : JSON.parse(api.res_body),
detail: name
+ '\n' + (api.up_time == null ? '' : (typeof api.up_time != 'number' ? api.up_time : new Date(1000*api.up_time).toLocaleString()))
- + '\nhttp://apijson.org/yapi/project/1/interface/api/' + api._id
+ + '\nhttp://apijson.cn/yapi/project/1/interface/api/' + api._id
+ '\n\n' + (StringUtil.isEmpty(api.markdown, true) ? StringUtil.trim(api.description) : api.markdown.trim().replace(/\\_/g, '_'))
}
}
@@ -2230,7 +2230,7 @@
typeAndParam.type, api.title, api.path, typeAndParam.param, header
, (StringUtil.trim(api.username) + ': ' + StringUtil.trim(api.title)
+ '\n' + (api.up_time == null ? '' : (typeof api.up_time != 'number' ? api.up_time : new Date(1000*api.up_time).toLocaleString()))
- + '\nhttp://apijson.org/yapi/project/1/interface/api/' + api._id
+ + '\nhttp://apijson.cn/yapi/project/1/interface/api/' + api._id
+ '\n\n' + (StringUtil.isEmpty(api.markdown, true) ? StringUtil.trim(api.description) : api.markdown.trim().replace(/\\_/g, '_')))
, api.username
)
@@ -4317,10 +4317,10 @@
// alert('请把URL改成你自己的!\n例如 http://localhost:8080')
// return
// }
- if (baseUrl.indexOf('/apijson.org') >= 0) {
- alert('请把URL改成 http://apijson.cn:8080 或 你自己的!\n例如 http://localhost:8080')
- return
- }
+ // if (baseUrl.indexOf('/apijson.org') >= 0) {
+ // alert('请把URL改成 http://apijson.cn:8080 或 你自己的!\n例如 http://localhost:8080')
+ // return
+ // }
const list = (testSubList ? this.randomSubs : this.randoms) || []
var allCount = list.length
@@ -4865,10 +4865,10 @@
// alert('请把URL改成你自己的!\n例如 http://localhost:8080')
// return
// }
- if (baseUrl.indexOf('/apijson.org') >= 0) {
- alert('请把URL改成 http://apijson.cn:8080 或 你自己的!\n例如 http://localhost:8080')
- return
- }
+ // if (baseUrl.indexOf('/apijson.org') >= 0) {
+ // alert('请把URL改成 http://apijson.cn:8080 或 你自己的!\n例如 http://localhost:8080')
+ // return
+ // }
const list = App.remotes || []
const allCount = list.length
From dfaa8c56af0fcb497f9e8864d84c55b5a48a8d9c Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Wed, 29 Sep 2021 18:57:10 +0800
Subject: [PATCH 493/818] =?UTF-8?q?=E8=B0=83=E8=AF=95=EF=BC=9A=E4=BC=98?=
=?UTF-8?q?=E5=8C=96=E7=BD=91=E9=A1=B5=20URL=20=E4=BC=A0=E5=8F=82=E8=BD=AC?=
=?UTF-8?q?=E5=8F=91=E5=88=B0=E6=B5=8F=E8=A7=88=E5=99=A8=E6=96=B0=E6=A0=87?=
=?UTF-8?q?=E7=AD=BE=E7=9A=84=E8=A7=A3=E7=A0=81=EF=BC=8C=E5=85=BC=E5=AE=B9?=
=?UTF-8?q?=E6=9B=B4=E5=A4=9A=E5=9C=BA=E6=99=AF=E4=B8=94=E6=9B=B4=E6=B8=85?=
=?UTF-8?q?=E6=99=B0=E5=8F=AF=E8=AF=BB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
index.html | 2 +-
js/main.js | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/index.html b/index.html
index 4e0aba5..6ef4aeb 100755
--- a/index.html
+++ b/index.html
@@ -806,7 +806,7 @@
}
- function getRequest() {
+ function getRequestFromURL() {
var url = window.location.search;
var index = url == null ? -1 : url.indexOf("?")
diff --git a/js/main.js b/js/main.js
index 1d37789..99aa174 100755
--- a/js/main.js
+++ b/js/main.js
@@ -5639,7 +5639,7 @@
this.transfer()
setTimeout(function () {
- var rawReq = getRequest()
+ var rawReq = getRequestFromURL()
if (rawReq != null && StringUtil.isEmpty(rawReq.json, true) == false) {
vUrlComment.value = ""
vComment.value = ""
@@ -5660,7 +5660,7 @@
var url = vUrl.value
if (rawReq.jump == "true" || (rawReq.jump != "false" && (url.endsWith("/get") || url.endsWith("/head")) ) ) {
setTimeout(function () {
- window.open(vUrl.value + "/" + encodeURIComponent(vInput.value))
+ window.open(vUrl.value + "/" + encodeURIComponent(JSON.stringify(encode(JSON.parse(vInput.value)))))
}, 1000)
}
}
From 0e441f4f4bfd6fe8e708e4827fbd938e51e2e24a Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Wed, 29 Sep 2021 20:04:21 +0800
Subject: [PATCH 494/818] =?UTF-8?q?=E5=88=86=E4=BA=AB=EF=BC=9A=E6=96=B0?=
=?UTF-8?q?=E5=A2=9E=E6=94=AF=E6=8C=81=E5=88=86=E4=BA=AB=20APIAuto=20?=
=?UTF-8?q?=E9=93=BE=E6=8E=A5=EF=BC=8C=E6=96=B9=E4=BE=BF=E5=BC=80=E5=8F=91?=
=?UTF-8?q?=E5=8D=8F=E4=BD=9C=E5=92=8C=E5=AE=8C=E5=96=84=E6=96=87=E6=A1=A3?=
=?UTF-8?q?=E7=9A=84=20APIAuto=20=E9=93=BE=E6=8E=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 39 ++++++++++++++++++++++++++++++++++++---
1 file changed, 36 insertions(+), 3 deletions(-)
diff --git a/js/main.js b/js/main.js
index 99aa174..823f37c 100755
--- a/js/main.js
+++ b/js/main.js
@@ -895,6 +895,25 @@
alert('请先输入请求内容!')
return
}
+
+ setTimeout(function () {
+ var href = window.location.href || 'http://apijson.cn/api'
+ var ind = href == null ? -1 : href.indexOf('?') // url 后带参数只能 encodeURIComponent
+ var reqStr
+ try {
+ reqStr = JSON.stringify(encode(JSON.parse(vInput.value)))
+ } catch (e){ // 可能包含注释
+ reqStr = encode(StringUtil.trim(vInput.value))
+ }
+
+ window.open((ind < 0 ? href : href.substring(0, ind))
+ + "?type=" + StringUtil.trim(App.type)
+ + "&url=" + encodeURIComponent(StringUtil.trim(vUrl.value))
+ + (StringUtil.isEmpty(vHeader.value, true) ? '' : "&header=" + encodeURIComponent(StringUtil.trim(vHeader.value)))
+ + "&json=" + reqStr
+ + (StringUtil.isEmpty(vRandom.value, true) ? '' : "&random=" + encodeURIComponent(StringUtil.trim(vRandom.value))))
+ }, 1000)
+
if (App.view == 'error') { // App.view != 'code') {
alert('发现错误,请输入正确的内容!') // alert('请先测试请求,确保是正确可用的!')
return
@@ -5644,20 +5663,34 @@
vUrlComment.value = ""
vComment.value = ""
- if (StringUtil.isEmpty(rawReq.url, true) == false) {
- vType.value = StringUtil.toUpperCase(rawReq.type, true)
+ if (StringUtil.isEmpty(rawReq.type, true) == false) {
+ App.type = StringUtil.toUpperCase(rawReq.type, true)
+ if (App.types != null && App.types.indexOf(App.type) < 0) {
+ App.types.push(App.type)
+ }
}
if (StringUtil.isEmpty(rawReq.url, true) == false) {
vUrl.value = StringUtil.trim(rawReq.url)
}
+ if (StringUtil.isEmpty(rawReq.header, true) == false) {
+ vHeader.value = StringUtil.trim(rawReq.header, true)
+ App.isHeaderShow = true
+ }
+
+ if (StringUtil.isEmpty(rawReq.random, true) == false) {
+ vRandom.value = StringUtil.trim(rawReq.random, true)
+ App.isRandomShow = true
+ App.isRandomListShow = false
+ }
+
vInput.value = StringUtil.trim(rawReq.json)
App.onChange(false)
App.send(false)
- var url = vUrl.value
+ var url = vUrl.value || ''
if (rawReq.jump == "true" || (rawReq.jump != "false" && (url.endsWith("/get") || url.endsWith("/head")) ) ) {
setTimeout(function () {
window.open(vUrl.value + "/" + encodeURIComponent(JSON.stringify(encode(JSON.parse(vInput.value)))))
From a61edfaeb90778818db0d8eb06bc190982329134 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Thu, 30 Sep 2021 01:06:42 +0800
Subject: [PATCH 495/818] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=EF=BC=9A=E6=96=B0?=
=?UTF-8?q?=E5=A2=9E=E6=94=AF=E6=8C=81=E5=88=86=E4=BA=AB=E8=AE=BE=E7=BD=AE?=
=?UTF-8?q?(=E9=85=8D=E7=BD=AE)=E5=B9=B6=E9=80=9A=E8=BF=87=E7=BD=91?=
=?UTF-8?q?=E9=A1=B5=20URL=20=E5=8F=82=E6=95=B0=20save=3Dtrue=20=E8=87=AA?=
=?UTF-8?q?=E5=8A=A8=E4=BF=9D=E5=AD=98=E8=AE=BE=E7=BD=AE(=E9=85=8D?=
=?UTF-8?q?=E7=BD=AE)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
apijson/JSONRequest.js | 29 +++++++++
index.html | 2 +-
js/main.js | 129 +++++++++++++++++++++++++++++++----------
3 files changed, 128 insertions(+), 32 deletions(-)
diff --git a/apijson/JSONRequest.js b/apijson/JSONRequest.js
index 13aad57..eac0474 100644
--- a/apijson/JSONRequest.js
+++ b/apijson/JSONRequest.js
@@ -151,6 +151,35 @@ function encode(json) {
return json;
}
+/**解码JSON,反转义所有String
+ * @param json 任意类型
+ */
+function decode(json) {
+ // alertOfDebug("decode before:\n" + format(JSON.stringify(json)));
+
+ if (typeof json == "string") { //json instanceof String) {
+ json = decodeURIComponent(json);
+ }
+ else if (json instanceof Array) {
+ // alertOfDebug("decode json instanceof Array");
+
+ for (var i = 0; i < json.length; i ++) {
+ // alertOfDebug("json[" + i + "] = " + format(JSON.stringify(json[i])));
+ json[i] = decode(json[i]);
+ }
+ }
+ else if (json instanceof Object) {
+ // alertOfDebug("decode json instanceof Object");
+ for (var key in json) {
+ // alertOfDebug("decode json[" + key + "] = " + format(JSON.stringify(json[key])));
+ json[key] = decode(json[key]);
+ }
+ }
+ // alertOfDebug("decode after:\n" + format(JSON.stringify(json)));
+
+ return json;
+}
+
/**编码JSON,转义所有String
* @param data 任意类型
*/
diff --git a/index.html b/index.html
index 6ef4aeb..82c18f5 100755
--- a/index.html
+++ b/index.html
@@ -116,7 +116,7 @@
生成代码(封装,解析) : {{ language || '例如 Java' }}
数据库类型 Database: {{ database || '例如 MYSQL' }}
数据库名/模式 Schema: {{ schema || '例如 sys' }}
-
使用的请求类型: {{ types == null || types.length <= 0 ? '点击设置' : types.join() }}
+
使用的请求类型: {{ types == null || types.length <= 0 ? '点击设置' : (types instanceof Array ? types.join() : types) }}
托管服务器地址 URL: {{ server || '点击设置' }}
导入第三方文档(平台名 URL):
{{ thirdParty || '点击设置' }}
diff --git a/js/main.js b/js/main.js
index 823f37c..1e13482 100755
--- a/js/main.js
+++ b/js/main.js
@@ -903,15 +903,57 @@
try {
reqStr = JSON.stringify(encode(JSON.parse(vInput.value)))
} catch (e){ // 可能包含注释
+ log(e)
reqStr = encode(StringUtil.trim(vInput.value))
}
+ // URL 太长导致打不开标签
+ var settingStr = null
+ try {
+ settingStr = JSON.stringify({
+ requestVersion: App.requestVersion,
+ requestCount: App.requestCount,
+ isTestCaseShow: App.isTestCaseShow,
+ // isHeaderShow: App.isHeaderShow,
+ // isRandomShow: App.isRandomShow,
+ isRandomListShow: App.isRandomShow ? App.isRandomListShow : undefined,
+ isRandomSubListShow: App.isRandomListShow ? App.isRandomSubListShow : undefined,
+ // isRandomEditable: App.isRandomEditable,
+ isCrossEnabled: App.isCrossEnabled,
+ isMLEnabled: App.isMLEnabled,
+ isDelegateEnabled: App.isDelegateEnabled,
+ isPreviewEnabled: App.isPreviewEnabled,
+ isEncodeEnabled: App.isEncodeEnabled,
+ isEditResponse: App.isEditResponse,
+ isLocalShow: App.isTestCaseShow ? App.isLocalShow : undefined,
+ page: App.page,
+ count: App.count,
+ testCasePage: App.testCasePage,
+ testCaseCount: App.testCaseCount,
+ randomPage: App.randomPage,
+ randomCount: App.randomCount,
+ randomSubPage: App.randomSubPage,
+ randomSubCount: App.randomSubCount,
+ host: StringUtil.isEmpty(App.host, true) ? undefined : encodeURIComponent(App.host),
+ search: StringUtil.isEmpty(App.search, true) ? undefined : encodeURIComponent(App.search),
+ testCaseSearch: StringUtil.isEmpty(App.testCaseSearch, true) ? undefined : App.testCaseSearch,
+ randomSearch: StringUtil.isEmpty(App.randomSearch, true) ? undefined : encodeURIComponent(App.randomSearch),
+ randomSubSearch: StringUtil.isEmpty(App.randomSubSearch, true) ? undefined : encodeURIComponent(App.randomSubSearch)
+ })
+ } catch (e){
+ log(e)
+ }
+
+ // 实测 561059 长度的 URL 都支持,只是输入框显示长度约为 2000
window.open((ind < 0 ? href : href.substring(0, ind))
- + "?type=" + StringUtil.trim(App.type)
+ + (App.view == 'code' ? "?send=true" : "?send=false")
+ + "&type=" + StringUtil.trim(App.type)
+ "&url=" + encodeURIComponent(StringUtil.trim(vUrl.value))
- + (StringUtil.isEmpty(vHeader.value, true) ? '' : "&header=" + encodeURIComponent(StringUtil.trim(vHeader.value)))
+ "&json=" + reqStr
- + (StringUtil.isEmpty(vRandom.value, true) ? '' : "&random=" + encodeURIComponent(StringUtil.trim(vRandom.value))))
+ + (StringUtil.isEmpty(vHeader.value, true) ? '' : "&header=" + encodeURIComponent(StringUtil.trim(vHeader.value)))
+ + (StringUtil.isEmpty(vRandom.value, true) ? '' : "&random=" + encodeURIComponent(StringUtil.trim(vRandom.value)))
+ + (StringUtil.isEmpty(settingStr, true) ? '' : "&setting=" + settingStr)
+ )
}, 1000)
if (App.view == 'error') { // App.view != 'code') {
@@ -2760,7 +2802,7 @@
cache[key] = value
localStorage.setItem('APIAuto:' + url, JSON.stringify(cache))
},
- getCache: function (url, key) {
+ getCache: function (url, key, defaultValue) {
var cache = localStorage.getItem('APIAuto:' + url)
try {
cache = JSON.parse(cache)
@@ -2768,7 +2810,8 @@
App.log('login App.send >> try { cache = JSON.parse(cache) } catch(e) {\n' + e.message)
}
cache = cache || {}
- return key == null ? cache : cache[key]
+ var val = key == null ? cache : cache[key]
+ return val == null && defaultValue != null ? defaultValue : val
},
/**登录确认
@@ -5483,7 +5526,7 @@
item.TestRecord = testRecord
- //
+
// if (! isNewRandom) {
// if (isRandom) {
// App.showRandomList(true, App.currentRemoteItem)
@@ -5594,7 +5637,7 @@
}
var types = this.getCache('', 'types')
if (types != null && types.length > 0) {
- this.types = types
+ this.types = types instanceof Array ? types : StringUtil.split(types)
}
var server = this.getCache('', 'server')
if (StringUtil.isEmpty(server, true) == false) {
@@ -5605,13 +5648,13 @@
this.thirdParty = thirdParty
}
- this.locals = this.getCache('', 'locals') || []
+ this.locals = this.getCache('', 'locals', [])
- this.isDelegateEnabled = this.getCache('', 'isDelegateEnabled') || this.isDelegateEnabled
- this.isEncodeEnabled = this.getCache('', 'isEncodeEnabled') || this.isEncodeEnabled
- //预览了就不能编辑了,点开看会懵 this.isPreviewEnabled = this.getCache('', 'isPreviewEnabled') || this.isPreviewEnabled
- this.isHeaderShow = this.getCache('', 'isHeaderShow') || this.isHeaderShow
- this.isRandomShow = this.getCache('', 'isRandomShow') || this.isRandomShow
+ this.isDelegateEnabled = this.getCache('', 'isDelegateEnabled', this.isDelegateEnabled)
+ this.isEncodeEnabled = this.getCache('', 'isEncodeEnabled', this.isEncodeEnabled)
+ //预览了就不能编辑了,点开看会懵 this.isPreviewEnabled = this.getCache('', 'isPreviewEnabled', this.isPreviewEnabled)
+ this.isHeaderShow = this.getCache('', 'isHeaderShow', this.isHeaderShow)
+ this.isRandomShow = this.getCache('', 'isRandomShow', this.isRandomShow)
} catch (e) {
console.log('created try { ' +
'\nvar url = this.getCache(, url) ...' +
@@ -5630,25 +5673,25 @@
}
try { //可能URL_BASE是const类型,不允许改,这里是初始化,不能出错
- this.User = this.getCache(this.server, 'User') || {}
- this.isCrossEnabled = this.getCache(this.server, 'isCrossEnabled') || this.isCrossEnabled
- this.isMLEnabled = this.getCache(this.server, 'isMLEnabled') || this.isMLEnabled
+ this.User = this.getCache(this.server, 'User', {})
+ this.isCrossEnabled = this.getCache(this.server, 'isCrossEnabled', this.isCrossEnabled)
+ this.isMLEnabled = this.getCache(this.server, 'isMLEnabled', this.isMLEnabled)
this.crossProcess = this.isCrossEnabled ? '交叉账号:已开启' : '交叉账号:已关闭'
this.testProcess = this.isMLEnabled ? '机器学习:已开启' : '机器学习:已关闭'
// this.host = this.getBaseUrl()
- this.page = this.getCache(this.server, 'page') || this.page
- this.count = this.getCache(this.server, 'count') || this.count
- this.testCasePage = this.getCache(this.server, 'testCasePage') || this.testCasePage
- this.testCaseCount = this.getCache(this.server, 'testCaseCount') || this.testCaseCount
- this.randomPage = this.getCache(this.server, 'randomPage') || this.randomPage
- this.randomCount = this.getCache(this.server, 'randomCount') || this.randomCount
- this.randomSubPage = this.getCache(this.server, 'randomSubPage') || this.randomSubPage
- this.randomSubCount = this.getCache(this.server, 'randomSubCount') || this.randomSubCount
+ this.page = this.getCache(this.server, 'page', this.page)
+ this.count = this.getCache(this.server, 'count', this.count)
+ this.testCasePage = this.getCache(this.server, 'testCasePage', this.testCasePage)
+ this.testCaseCount = this.getCache(this.server, 'testCaseCount', this.testCaseCount)
+ this.randomPage = this.getCache(this.server, 'randomPage', this.randomPage)
+ this.randomCount = this.getCache(this.server, 'randomCount', this.randomCount)
+ this.randomSubPage = this.getCache(this.server, 'randomSubPage', this.randomSubPage)
+ this.randomSubCount = this.getCache(this.server, 'randomSubCount', this.randomSubCount)
CodeUtil.thirdPartyApiMap = this.getCache(this.thirdParty, 'thirdPartyApiMap')
} catch (e) {
console.log('created try { ' +
- '\nthis.User = this.getCache(this.server, User) || {}' +
+ '\nthis.User = this.getCache(this.server, User, {})' +
'\n} catch (e) {\n' + e.message)
}
@@ -5687,14 +5730,38 @@
vInput.value = StringUtil.trim(rawReq.json)
+
+ // URL 太长导致截断和乱码
+ if (StringUtil.isEmpty(rawReq.setting, true) == false) {
+ var save = rawReq.save == 'true'
+ try {
+ var setting = JSON.parse(StringUtil.trim(rawReq.setting, true))
+ for (var k in setting) {
+ var v = k == null ? null : setting[k]
+ if (v == null) {
+ continue
+ }
+ App[k] = v // App.$data[k] = app[k]
+
+ if (save) {
+ App.saveCache('', k, v)
+ }
+ }
+ } catch (e) {
+ log(e)
+ }
+ }
+
App.onChange(false)
- App.send(false)
+ if (rawReq.send != "false") {
+ App.send(false)
- var url = vUrl.value || ''
- if (rawReq.jump == "true" || (rawReq.jump != "false" && (url.endsWith("/get") || url.endsWith("/head")) ) ) {
- setTimeout(function () {
- window.open(vUrl.value + "/" + encodeURIComponent(JSON.stringify(encode(JSON.parse(vInput.value)))))
- }, 1000)
+ var url = vUrl.value || ''
+ if (rawReq.jump == "true" || (rawReq.jump != "false" && (url.endsWith("/get") || url.endsWith("/head")) )) {
+ setTimeout(function () {
+ window.open(vUrl.value + "/" + encodeURIComponent(JSON.stringify(encode(JSON.parse(vInput.value)))))
+ }, 1000)
+ }
}
}
else if (App.User != null && App.User.id != null && App.User.id > 0) {
From 10daf627c3ad341c280c79ce7433bc8123948133 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Thu, 30 Sep 2021 02:38:47 +0800
Subject: [PATCH 496/818] =?UTF-8?q?=E5=88=86=E4=BA=AB=EF=BC=9A=E9=93=BE?=
=?UTF-8?q?=E6=8E=A5=E4=B8=AD=E5=87=86=E7=A1=AE=E5=8C=BA=E5=88=86=E6=98=AF?=
=?UTF-8?q?=E5=90=A6=E4=B8=BA=E9=9A=8F=E6=9C=BA=E6=B5=8B=E8=AF=95=EF=BC=9B?=
=?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
index.html | 9 ++-
js/main.js | 166 ++++++++++++++++++++++++++++++++---------------------
2 files changed, 105 insertions(+), 70 deletions(-)
diff --git a/index.html b/index.html
index 82c18f5..86f5628 100755
--- a/index.html
+++ b/index.html
@@ -139,7 +139,7 @@
-
+
@@ -150,7 +150,7 @@
{{ crossProcess }}
{{ testProcess }}
-
+
@@ -814,7 +814,7 @@
return null;
}
- var theRequest = {};
+ var theRequest = null;
var str = url.substring(index + 1); //从第一个字符开始 因为第0个是?号 获取所有除问号的所有符串
var arr = str.split("&"); //截除“&”生成一个数组
@@ -826,6 +826,9 @@
continue
}
+ if (theRequest == null) {
+ theRequest = {};
+ }
theRequest[part.substring(0, ind)] = decodeURIComponent(part.substring(ind+1));
}
diff --git a/js/main.js b/js/main.js
index 1e13482..001ace1 100755
--- a/js/main.js
+++ b/js/main.js
@@ -528,6 +528,7 @@
testRandomCount: 1,
testRandomProcess: '',
compareColor: '#0000',
+ isRandomTest: false,
isDelayShow: false,
isSaveShow: false,
isExportShow: false,
@@ -872,6 +873,73 @@
return header
},
+ // 分享 APIAuto 特有链接,打开即可还原分享人的 JSON 参数、设置项、搜索关键词、分页数量及页码等配置
+ shareLink: function (isRandom) {
+ var jsonStr = null
+ if (App.isTestCaseShow != true) {
+ try {
+ jsonStr = JSON.stringify(encode(JSON.parse(vInput.value)))
+ } catch (e) { // 可能包含注释
+ log(e)
+ jsonStr = encode(StringUtil.trim(vInput.value))
+ }
+ }
+
+ // URL 太长导致打不开标签
+ var settingStr = null
+ try {
+ settingStr = JSON.stringify({
+ requestVersion: App.requestVersion,
+ requestCount: App.requestCount,
+ isTestCaseShow: App.isTestCaseShow,
+ // isHeaderShow: App.isHeaderShow,
+ // isRandomShow: App.isRandomShow,
+ isRandomListShow: App.isRandomShow ? App.isRandomListShow : undefined,
+ isRandomSubListShow: App.isRandomListShow ? App.isRandomSubListShow : undefined,
+ // isRandomEditable: App.isRandomEditable,
+ isCrossEnabled: App.isCrossEnabled,
+ isMLEnabled: App.isMLEnabled,
+ isDelegateEnabled: App.isDelegateEnabled,
+ isPreviewEnabled: App.isPreviewEnabled,
+ isEncodeEnabled: App.isEncodeEnabled,
+ isEditResponse: App.isEditResponse,
+ isLocalShow: App.isTestCaseShow ? App.isLocalShow : undefined,
+ page: App.page,
+ count: App.count,
+ testCasePage: App.testCasePage,
+ testCaseCount: App.testCaseCount,
+ randomPage: App.randomPage,
+ randomCount: App.randomCount,
+ randomSubPage: App.randomSubPage,
+ randomSubCount: App.randomSubCount,
+ host: StringUtil.isEmpty(App.host, true) ? undefined : encodeURIComponent(App.host),
+ search: StringUtil.isEmpty(App.search, true) ? undefined : encodeURIComponent(App.search),
+ testCaseSearch: StringUtil.isEmpty(App.testCaseSearch, true) ? undefined : App.testCaseSearch,
+ randomSearch: StringUtil.isEmpty(App.randomSearch, true) ? undefined : encodeURIComponent(App.randomSearch),
+ randomSubSearch: StringUtil.isEmpty(App.randomSubSearch, true) ? undefined : encodeURIComponent(App.randomSubSearch)
+ })
+ } catch (e){
+ log(e)
+ }
+
+ var headerStr = App.isTestCaseShow || StringUtil.isEmpty(vHeader.value, true) ? null : encodeURIComponent(StringUtil.trim(vHeader.value))
+ var randomStr = App.isTestCaseShow || StringUtil.isEmpty(vRandom.value, true) ? null : encodeURIComponent(StringUtil.trim(vRandom.value))
+
+ var href = window.location.href || 'http://apijson.cn/api'
+ var ind = href == null ? -1 : href.indexOf('?') // url 后带参数只能 encodeURIComponent
+
+ // 实测 561059 长度的 URL 都支持,只是输入框显示长度约为 2000
+ window.open((ind < 0 ? href : href.substring(0, ind))
+ + (App.view != 'code' ? "?send=false" : (isRandom ? "?send=random" : "?send=true"))
+ + "&type=" + StringUtil.trim(App.type)
+ + "&url=" + encodeURIComponent(StringUtil.trim(vUrl.value))
+ + (StringUtil.isEmpty(jsonStr, true) ? '' : "&json=" + jsonStr)
+ + (StringUtil.isEmpty(headerStr, true) ? '' : "&header=" + headerStr)
+ + (StringUtil.isEmpty(randomStr, true) ? '' : "&random=" + randomStr)
+ + (StringUtil.isEmpty(settingStr, true) ? '' : "&setting=" + settingStr)
+ )
+ },
+
// 显示保存弹窗
showSave: function (show) {
if (show) {
@@ -891,71 +959,18 @@
if (show) {
if (isRemote) { //共享测试用例
App.isExportRandom = isRandom
+
+ if (isRandom != true) {
+ setTimeout(function () {
+ App.shareLink(App.isRandomTest)
+ }, 1000)
+ }
+
if (App.isTestCaseShow) {
alert('请先输入请求内容!')
return
}
- setTimeout(function () {
- var href = window.location.href || 'http://apijson.cn/api'
- var ind = href == null ? -1 : href.indexOf('?') // url 后带参数只能 encodeURIComponent
- var reqStr
- try {
- reqStr = JSON.stringify(encode(JSON.parse(vInput.value)))
- } catch (e){ // 可能包含注释
- log(e)
- reqStr = encode(StringUtil.trim(vInput.value))
- }
-
- // URL 太长导致打不开标签
- var settingStr = null
- try {
- settingStr = JSON.stringify({
- requestVersion: App.requestVersion,
- requestCount: App.requestCount,
- isTestCaseShow: App.isTestCaseShow,
- // isHeaderShow: App.isHeaderShow,
- // isRandomShow: App.isRandomShow,
- isRandomListShow: App.isRandomShow ? App.isRandomListShow : undefined,
- isRandomSubListShow: App.isRandomListShow ? App.isRandomSubListShow : undefined,
- // isRandomEditable: App.isRandomEditable,
- isCrossEnabled: App.isCrossEnabled,
- isMLEnabled: App.isMLEnabled,
- isDelegateEnabled: App.isDelegateEnabled,
- isPreviewEnabled: App.isPreviewEnabled,
- isEncodeEnabled: App.isEncodeEnabled,
- isEditResponse: App.isEditResponse,
- isLocalShow: App.isTestCaseShow ? App.isLocalShow : undefined,
- page: App.page,
- count: App.count,
- testCasePage: App.testCasePage,
- testCaseCount: App.testCaseCount,
- randomPage: App.randomPage,
- randomCount: App.randomCount,
- randomSubPage: App.randomSubPage,
- randomSubCount: App.randomSubCount,
- host: StringUtil.isEmpty(App.host, true) ? undefined : encodeURIComponent(App.host),
- search: StringUtil.isEmpty(App.search, true) ? undefined : encodeURIComponent(App.search),
- testCaseSearch: StringUtil.isEmpty(App.testCaseSearch, true) ? undefined : App.testCaseSearch,
- randomSearch: StringUtil.isEmpty(App.randomSearch, true) ? undefined : encodeURIComponent(App.randomSearch),
- randomSubSearch: StringUtil.isEmpty(App.randomSubSearch, true) ? undefined : encodeURIComponent(App.randomSubSearch)
- })
- } catch (e){
- log(e)
- }
-
- // 实测 561059 长度的 URL 都支持,只是输入框显示长度约为 2000
- window.open((ind < 0 ? href : href.substring(0, ind))
- + (App.view == 'code' ? "?send=true" : "?send=false")
- + "&type=" + StringUtil.trim(App.type)
- + "&url=" + encodeURIComponent(StringUtil.trim(vUrl.value))
- + "&json=" + reqStr
- + (StringUtil.isEmpty(vHeader.value, true) ? '' : "&header=" + encodeURIComponent(StringUtil.trim(vHeader.value)))
- + (StringUtil.isEmpty(vRandom.value, true) ? '' : "&random=" + encodeURIComponent(StringUtil.trim(vRandom.value)))
- + (StringUtil.isEmpty(settingStr, true) ? '' : "&setting=" + settingStr)
- )
- }, 1000)
-
if (App.view == 'error') { // App.view != 'code') {
alert('发现错误,请输入正确的内容!') // alert('请先测试请求,确保是正确可用的!')
return
@@ -4360,6 +4375,7 @@
* @param show
*/
onClickTestRandom: function () {
+ this.isRandomTest = true
this.testRandom(! this.isRandomListShow && ! this.isRandomSubListShow, this.isRandomListShow, this.isRandomSubListShow)
},
testRandom: function (show, testList, testSubList, limit) {
@@ -4886,7 +4902,14 @@
},
-
+ onClickSend: function () {
+ this.isRandomTest = false
+ this.send(false)
+ },
+ onClickTest: function () {
+ this.isRandomTest = false
+ this.test(false, this.isCrossEnabled ? -1 : currentAccountIndex)
+ },
/**回归测试
* 原理:
1.遍历所有上传过的测试用例(URL+请求JSON)
@@ -5702,7 +5725,7 @@
setTimeout(function () {
var rawReq = getRequestFromURL()
- if (rawReq != null && StringUtil.isEmpty(rawReq.json, true) == false) {
+ if (rawReq != null) {
vUrlComment.value = ""
vComment.value = ""
@@ -5717,6 +5740,10 @@
vUrl.value = StringUtil.trim(rawReq.url)
}
+ if (StringUtil.isEmpty(rawReq.json, true) == false) {
+ vInput.value = StringUtil.trim(rawReq.json)
+ }
+
if (StringUtil.isEmpty(rawReq.header, true) == false) {
vHeader.value = StringUtil.trim(rawReq.header, true)
App.isHeaderShow = true
@@ -5728,8 +5755,6 @@
App.isRandomListShow = false
}
- vInput.value = StringUtil.trim(rawReq.json)
-
// URL 太长导致截断和乱码
if (StringUtil.isEmpty(rawReq.setting, true) == false) {
@@ -5753,11 +5778,18 @@
}
App.onChange(false)
- if (rawReq.send != "false") {
- App.send(false)
+
+ if (rawReq.send != "false" && rawReq.send != "null") {
+ if (rawReq.send == 'random') {
+ App.onClickTestRandom()
+ } else if (App.isTestCaseShow) {
+ App.onClickTest()
+ } else {
+ App.send(false)
+ }
var url = vUrl.value || ''
- if (rawReq.jump == "true" || (rawReq.jump != "false" && (url.endsWith("/get") || url.endsWith("/head")) )) {
+ if (rawReq.jump == "true" || rawReq.jump == "null" || (rawReq.jump != "false" && (url.endsWith("/get") || url.endsWith("/head")) )) {
setTimeout(function () {
window.open(vUrl.value + "/" + encodeURIComponent(JSON.stringify(encode(JSON.parse(vInput.value)))))
}, 1000)
From a1a92c3b94b161a1915be609e1aafef2a32e54e4 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Thu, 30 Sep 2021 02:53:34 +0800
Subject: [PATCH 497/818] =?UTF-8?q?=E5=88=86=E4=BA=AB=EF=BC=9A=E8=A7=A3?=
=?UTF-8?q?=E5=86=B3=E5=88=86=E4=BA=AB=E9=93=BE=E6=8E=A5=E6=9C=AA=E5=B8=A6?=
=?UTF-8?q?=E4=B8=8A=E9=9A=8F=E6=9C=BA=E6=B5=8B=E8=AF=95=E6=AC=A1=E6=95=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 1 +
1 file changed, 1 insertion(+)
diff --git a/js/main.js b/js/main.js
index 001ace1..4353956 100755
--- a/js/main.js
+++ b/js/main.js
@@ -908,6 +908,7 @@
count: App.count,
testCasePage: App.testCasePage,
testCaseCount: App.testCaseCount,
+ testRandomCount: App.testRandomCount,
randomPage: App.randomPage,
randomCount: App.randomCount,
randomSubPage: App.randomSubPage,
From 41af903bf3812c6d92fc015cfe144a77a48fba60 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Thu, 30 Sep 2021 03:22:32 +0800
Subject: [PATCH 498/818] =?UTF-8?q?=E5=88=86=E4=BA=AB=EF=BC=9A=E8=A7=A3?=
=?UTF-8?q?=E5=86=B3=E5=88=86=E4=BA=AB=E9=93=BE=E6=8E=A5=E4=B8=AD=20WebSto?=
=?UTF-8?q?rm=20=E5=8A=A0=E7=9A=84=E9=9D=9E=20APIAuto=20=E5=8F=82=E6=95=B0?=
=?UTF-8?q?=E5=AF=BC=E8=87=B4=20APIAuto=20=E8=87=AA=E5=8A=A8=E8=BF=98?=
=?UTF-8?q?=E5=8E=9F=E5=92=8C=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/js/main.js b/js/main.js
index 4353956..bfe09a4 100755
--- a/js/main.js
+++ b/js/main.js
@@ -961,7 +961,7 @@
if (isRemote) { //共享测试用例
App.isExportRandom = isRandom
- if (isRandom != true) {
+ if (isRandom != true) { // 分享搜索关键词和分页信息也挺好 } && App.isTestCaseShow != true) { // 没有拿到列表,没用
setTimeout(function () {
App.shareLink(App.isRandomTest)
}, 1000)
@@ -4909,7 +4909,7 @@
},
onClickTest: function () {
this.isRandomTest = false
- this.test(false, this.isCrossEnabled ? -1 : currentAccountIndex)
+ this.test(false, this.isCrossEnabled ? -1 : this.currentAccountIndex)
},
/**回归测试
* 原理:
@@ -5727,10 +5727,10 @@
setTimeout(function () {
var rawReq = getRequestFromURL()
if (rawReq != null) {
- vUrlComment.value = ""
- vComment.value = ""
+ var hasTestArg = false // 避免 http://localhost:63342/APIAuto/index.html?_ijt=fh8di51h7qip2d1s3r3bqn73nt 这种无意义参数
if (StringUtil.isEmpty(rawReq.type, true) == false) {
+ hasTestArg = true
App.type = StringUtil.toUpperCase(rawReq.type, true)
if (App.types != null && App.types.indexOf(App.type) < 0) {
App.types.push(App.type)
@@ -5738,19 +5738,23 @@
}
if (StringUtil.isEmpty(rawReq.url, true) == false) {
+ hasTestArg = true
vUrl.value = StringUtil.trim(rawReq.url)
}
if (StringUtil.isEmpty(rawReq.json, true) == false) {
+ hasTestArg = true
vInput.value = StringUtil.trim(rawReq.json)
}
if (StringUtil.isEmpty(rawReq.header, true) == false) {
+ hasTestArg = true
vHeader.value = StringUtil.trim(rawReq.header, true)
App.isHeaderShow = true
}
if (StringUtil.isEmpty(rawReq.random, true) == false) {
+ hasTestArg = true
vRandom.value = StringUtil.trim(rawReq.random, true)
App.isRandomShow = true
App.isRandomListShow = false
@@ -5778,9 +5782,14 @@
}
}
+ if (hasTestArg) {
+ vUrlComment.value = ""
+ vComment.value = ""
+ }
+
App.onChange(false)
- if (rawReq.send != "false" && rawReq.send != "null") {
+ if (hasTestArg && rawReq.send != "false" && rawReq.send != "null") {
if (rawReq.send == 'random') {
App.onClickTestRandom()
} else if (App.isTestCaseShow) {
@@ -5793,7 +5802,7 @@
if (rawReq.jump == "true" || rawReq.jump == "null" || (rawReq.jump != "false" && (url.endsWith("/get") || url.endsWith("/head")) )) {
setTimeout(function () {
window.open(vUrl.value + "/" + encodeURIComponent(JSON.stringify(encode(JSON.parse(vInput.value)))))
- }, 1000)
+ }, App.isTestCaseShow || rawReq.send == 'random' ? 5000 : 2000)
}
}
}
From 823ca0e04ffdbf7c62db2fe92079fbba80f30b6e Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Thu, 30 Sep 2021 05:04:55 +0800
Subject: [PATCH 499/818] =?UTF-8?q?=E5=88=86=E4=BA=AB=EF=BC=9A=E8=A7=A3?=
=?UTF-8?q?=E5=86=B3=E4=B8=8D=E8=83=BD=E6=88=90=E5=8A=9F=E8=87=AA=E5=8A=A8?=
=?UTF-8?q?=E6=89=A7=E8=A1=8C=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=E5=88=97?=
=?UTF-8?q?=E8=A1=A8=E5=9B=9E=E5=BD=92=E6=B5=8B=E8=AF=95=E5=92=8C=E9=9A=8F?=
=?UTF-8?q?=E6=9C=BA=E5=88=97=E8=A1=A8=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
index.html | 29 --------------
js/main.js | 112 ++++++++++++++++++++++++++++++++++++++++-------------
2 files changed, 86 insertions(+), 55 deletions(-)
diff --git a/index.html b/index.html
index 86f5628..72bcb61 100755
--- a/index.html
+++ b/index.html
@@ -806,35 +806,6 @@
}
- function getRequestFromURL() {
- var url = window.location.search;
-
- var index = url == null ? -1 : url.indexOf("?")
- if(index < 0) { //判断是否有参数
- return null;
- }
-
- var theRequest = null;
- var str = url.substring(index + 1); //从第一个字符开始 因为第0个是?号 获取所有除问号的所有符串
- var arr = str.split("&"); //截除“&”生成一个数组
-
- var len = arr == null ? 0 : arr.length;
- for(var i = 0; i < len; i++) {
- var part = arr[i];
- var ind = part == null ? -1 : part.indexOf("=");
- if (ind <= 0) {
- continue
- }
-
- if (theRequest == null) {
- theRequest = {};
- }
- theRequest[part.substring(0, ind)] = decodeURIComponent(part.substring(ind+1));
- }
-
- return theRequest;
- }
-
diff --git a/js/main.js b/js/main.js
index bfe09a4..373c171 100755
--- a/js/main.js
+++ b/js/main.js
@@ -363,6 +363,36 @@
// APIJSON <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
+
+ function getRequestFromURL() {
+ var url = window.location.search;
+
+ var index = url == null ? -1 : url.indexOf("?")
+ if(index < 0) { //判断是否有参数
+ return null;
+ }
+
+ var theRequest = null;
+ var str = url.substring(index + 1); //从第一个字符开始 因为第0个是?号 获取所有除问号的所有符串
+ var arr = str.split("&"); //截除“&”生成一个数组
+
+ var len = arr == null ? 0 : arr.length;
+ for(var i = 0; i < len; i++) {
+ var part = arr[i];
+ var ind = part == null ? -1 : part.indexOf("=");
+ if (ind <= 0) {
+ continue
+ }
+
+ if (theRequest == null) {
+ theRequest = {};
+ }
+ theRequest[part.substring(0, ind)] = decodeURIComponent(part.substring(ind+1));
+ }
+
+ return theRequest;
+ }
+
var PLATFORM_POSTMAN = 'POSTMAN'
var PLATFORM_SWAGGER = 'SWAGGER'
var PLATFORM_YAPI = 'YAPI'
@@ -3887,7 +3917,7 @@
var page = this.page || 0
var search = StringUtil.isEmpty(this.search, true) ? null : '%' + StringUtil.trim(this.search) + '%'
- App.request(false, REQUEST_TYPE_JSON, this.getBaseUrl() + '/get', {
+ this.request(false, REQUEST_TYPE_JSON, this.getBaseUrl() + '/get', {
format: false,
'@database': StringUtil.isEmpty(App.database, true) ? undefined : App.database,
// '@schema': StringUtil.isEmpty(App.schema, true) ? undefined : App.schema,
@@ -5719,14 +5749,21 @@
'\n} catch (e) {\n' + e.message)
}
-
//无效,只能在index里设置 vUrl.value = this.getCache('', 'URL_BASE')
+
this.listHistory()
- this.transfer()
- setTimeout(function () {
- var rawReq = getRequestFromURL()
- if (rawReq != null) {
+ var rawReq = getRequestFromURL()
+ if (rawReq == null || StringUtil.isEmpty(rawReq.type, true)) {
+ this.transfer()
+
+ if (this.User != null && this.User.id != null && this.User.id > 0) {
+ this.showTestCase(true, false) // 本地历史仍然要求登录 App.User == null || App.User.id == null)
+ }
+ }
+ else {
+ setTimeout(function () {
+ isSingle = ! isSingle
var hasTestArg = false // 避免 http://localhost:63342/APIAuto/index.html?_ijt=fh8di51h7qip2d1s3r3bqn73nt 这种无意义参数
if (StringUtil.isEmpty(rawReq.type, true) == false) {
@@ -5760,12 +5797,30 @@
App.isRandomListShow = false
}
-
// URL 太长导致截断和乱码
if (StringUtil.isEmpty(rawReq.setting, true) == false) {
var save = rawReq.save == 'true'
try {
- var setting = JSON.parse(StringUtil.trim(rawReq.setting, true))
+ var setting = JSON.parse(StringUtil.trim(rawReq.setting, true)) || {}
+
+ var delayTime = 0
+ if (setting.count != App.count || setting.page != App.page || setting.search != App.search) {
+ delayTime += 2000
+ App.getDoc(function (d) {
+ App.setDoc(d);
+ })
+ }
+
+ if (setting.isRandomShow && setting.isRandomListShow) {
+ delayTime += 2000
+ App.showRandomList(true, setting.isRandomSubListShow ? App.currentRandomItem : null, setting.isRandomSubListShow)
+ }
+
+ if (setting.isTestCaseShow) {
+ delayTime += 2000
+ App.showTestCase(true, setting.isLocalShow)
+ }
+
for (var k in setting) {
var v = k == null ? null : setting[k]
if (v == null) {
@@ -5790,26 +5845,31 @@
App.onChange(false)
if (hasTestArg && rawReq.send != "false" && rawReq.send != "null") {
- if (rawReq.send == 'random') {
- App.onClickTestRandom()
- } else if (App.isTestCaseShow) {
- App.onClickTest()
- } else {
- App.send(false)
- }
+ setTimeout(function () {
+ if (rawReq.send == 'random') {
+ App.onClickTestRandom()
+ } else if (App.isTestCaseShow) {
+ App.onClickTest()
+ } else {
+ App.send(false)
+ }
- var url = vUrl.value || ''
- if (rawReq.jump == "true" || rawReq.jump == "null" || (rawReq.jump != "false" && (url.endsWith("/get") || url.endsWith("/head")) )) {
- setTimeout(function () {
- window.open(vUrl.value + "/" + encodeURIComponent(JSON.stringify(encode(JSON.parse(vInput.value)))))
- }, App.isTestCaseShow || rawReq.send == 'random' ? 5000 : 2000)
- }
+ var url = vUrl.value || ''
+ if (rawReq.jump == "true" || rawReq.jump == "null"
+ || (rawReq.jump != "false" && App.isTestCaseShow != true && rawReq.send != 'random'
+ && (url.endsWith("/get") || url.endsWith("/head"))
+ )
+ ) {
+ setTimeout(function () {
+ window.open(vUrl.value + "/" + encodeURIComponent(JSON.stringify(encode(JSON.parse(vInput.value)))))
+ }, 2000)
+ }
+ }, delayTime)
}
- }
- else if (App.User != null && App.User.id != null && App.User.id > 0) {
- App.showTestCase(true, false) // 本地历史仍然要求登录 App.User == null || App.User.id == null)
- }
- }, 1000)
+ }, 1000)
+
+ }
+
}
})
})()
From 49b6764d2487d8de7ed44e226e16655cfa7feb72 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Thu, 30 Sep 2021 05:15:26 +0800
Subject: [PATCH 500/818] =?UTF-8?q?=E5=88=86=E4=BA=AB=EF=BC=9A=E8=A7=A3?=
=?UTF-8?q?=E5=86=B3=E8=87=AA=E5=8A=A8=E6=9F=A5=E6=B5=8B=E8=AF=95=E7=94=A8?=
=?UTF-8?q?=E4=BE=8B=E5=88=97=E8=A1=A8=E6=9C=AA=E4=BD=BF=E7=94=A8=20URL=20?=
=?UTF-8?q?=E6=8F=90=E4=BE=9B=E7=9A=84=E5=8F=82=E6=95=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/js/main.js b/js/main.js
index 373c171..df4f5e0 100755
--- a/js/main.js
+++ b/js/main.js
@@ -5811,16 +5811,6 @@
})
}
- if (setting.isRandomShow && setting.isRandomListShow) {
- delayTime += 2000
- App.showRandomList(true, setting.isRandomSubListShow ? App.currentRandomItem : null, setting.isRandomSubListShow)
- }
-
- if (setting.isTestCaseShow) {
- delayTime += 2000
- App.showTestCase(true, setting.isLocalShow)
- }
-
for (var k in setting) {
var v = k == null ? null : setting[k]
if (v == null) {
@@ -5832,6 +5822,16 @@
App.saveCache('', k, v)
}
}
+
+ if (setting.isRandomShow && setting.isRandomListShow) {
+ delayTime += 2000
+ App.showRandomList(true, setting.isRandomSubListShow ? App.currentRandomItem : null, setting.isRandomSubListShow)
+ }
+
+ if (setting.isTestCaseShow) {
+ delayTime += 2000
+ App.showTestCase(true, setting.isLocalShow)
+ }
} catch (e) {
log(e)
}
From 8f11feec60abc016ef86e76babf217096f968806 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Thu, 7 Oct 2021 01:20:09 +0800
Subject: [PATCH 501/818] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=9F=90=E4=BA=9B?=
=?UTF-8?q?=E6=83=85=E5=86=B5=E4=B8=8B=E6=89=93=E5=BC=80=E6=8A=A5=E9=94=99?=
=?UTF-8?q?=EF=BC=9B=E5=88=86=E4=BA=AB=EF=BC=9A=E8=A7=A3=E5=86=B3=E5=9C=A8?=
=?UTF-8?q?=20APIJSON=20GitHub=20=E6=96=87=E6=A1=A3=E4=B8=AD=E8=B7=B3?=
=?UTF-8?q?=E8=BD=AC=E8=BF=87=E6=9D=A5=E5=8F=AF=E8=83=BD=E5=9C=A8=E8=AF=B7?=
=?UTF-8?q?=E6=B1=82=E6=88=90=E5=8A=9F=E5=90=8E=E5=86=8D=E6=81=A2=E5=A4=8D?=
=?UTF-8?q?=E6=98=BE=E7=A4=BA=E4=B8=BA=E6=96=87=E6=A1=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/js/main.js b/js/main.js
index df4f5e0..68f0534 100755
--- a/js/main.js
+++ b/js/main.js
@@ -3919,8 +3919,8 @@
var search = StringUtil.isEmpty(this.search, true) ? null : '%' + StringUtil.trim(this.search) + '%'
this.request(false, REQUEST_TYPE_JSON, this.getBaseUrl() + '/get', {
format: false,
- '@database': StringUtil.isEmpty(App.database, true) ? undefined : App.database,
- // '@schema': StringUtil.isEmpty(App.schema, true) ? undefined : App.schema,
+ '@database': StringUtil.isEmpty(this.database, true) ? undefined : this.database,
+ // '@schema': StringUtil.isEmpty(this.schema, true) ? undefined : this.schema,
'sql@': {
'from': 'Access',
'Access': {
@@ -5866,7 +5866,7 @@
}
}, delayTime)
}
- }, 1000)
+ }, 2000)
}
From 0faa92a2d18afe07c1cb5941c17a876e58ed56a2 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Thu, 7 Oct 2021 03:24:57 +0800
Subject: [PATCH 502/818] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=9C=89=E6=97=B6?=
=?UTF-8?q?=E5=90=AF=E5=8A=A8=E6=8A=A5=E9=94=99?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 232 +++++++++++++++++++++++++++--------------------------
1 file changed, 119 insertions(+), 113 deletions(-)
diff --git a/js/main.js b/js/main.js
index 68f0534..12252af 100755
--- a/js/main.js
+++ b/js/main.js
@@ -989,44 +989,44 @@
showExport: function (show, isRemote, isRandom) {
if (show) {
if (isRemote) { //共享测试用例
- App.isExportRandom = isRandom
+ this.isExportRandom = isRandom
if (isRandom != true) { // 分享搜索关键词和分页信息也挺好 } && App.isTestCaseShow != true) { // 没有拿到列表,没用
setTimeout(function () {
App.shareLink(App.isRandomTest)
}, 1000)
}
-
- if (App.isTestCaseShow) {
+
+ if (this.isTestCaseShow) {
alert('请先输入请求内容!')
return
}
- if (App.view == 'error') { // App.view != 'code') {
+ if (this.view == 'error') { // this.view != 'code') {
alert('发现错误,请输入正确的内容!') // alert('请先测试请求,确保是正确可用的!')
return
}
if (isRandom) {
- App.exTxt.name = '随机配置 ' + App.formatDateTime()
+ this.exTxt.name = '随机配置 ' + this.formatDateTime()
}
else {
- if (App.isEditResponse) {
- App.isExportRemote = isRemote
- App.exportTxt()
+ if (this.isEditResponse) {
+ this.isExportRemote = isRemote
+ this.exportTxt()
return
}
// var tag = App.getTag()
- App.exTxt.name = App.urlComment || '' // 避免偷懒不输入名称 App.getMethod() + (StringUtil.isEmpty(tag, true) ? '' : ' ' + tag)
+ this.exTxt.name = this.urlComment || '' // 避免偷懒不输入名称 App.getMethod() + (StringUtil.isEmpty(tag, true) ? '' : ' ' + tag)
}
}
else { //下载到本地
- if (App.isTestCaseShow) { //文档
- App.exTxt.name = 'APIJSON自动化文档 ' + App.formatDateTime()
+ if (this.isTestCaseShow) { //文档
+ this.exTxt.name = 'APIJSON自动化文档 ' + App.formatDateTime()
}
- else if (App.view == 'markdown' || App.view == 'output') {
+ else if (this.view == 'markdown' || this.view == 'output') {
var suffix
- switch (App.language) {
+ switch (this.language) {
case CodeUtil.LANGUAGE_KOTLIN:
suffix = '.kt';
break;
@@ -1069,32 +1069,32 @@
break;
}
- App.exTxt.name = 'User' + suffix
+ this.exTxt.name = 'User' + suffix
alert('自动生成模型代码,可填类名后缀:\n'
+ 'Kotlin.kt, Java.java, Swift.swift, Objective-C.m, C#.cs, Go.go,'
+ '\nTypeScript.ts, JavaScript.js, PHP.php, Python.py, C++.cpp');
}
else {
- App.exTxt.name = 'APIJSON测试 ' + App.getMethod() + ' ' + App.formatDateTime()
+ this.exTxt.name = 'APIJSON测试 ' + this.getMethod() + ' ' + this.formatDateTime()
}
}
}
- App.isExportShow = show
- App.isExportRemote = isRemote
+ this.isExportShow = show
+ this.isExportRemote = isRemote
},
// 显示配置弹窗
showConfig: function (show, index) {
- App.isConfigShow = false
- if (App.isTestCaseShow) {
+ this.isConfigShow = false
+ if (this.isTestCaseShow) {
if (index == 3 || index == 4 || index == 5 || index == 10) {
- App.showTestCase(false, false)
+ this.showTestCase(false, false)
}
}
if (show) {
- App.exTxt.button = index == 8 ? '上传' : '切换'
- App.exTxt.index = index
+ this.exTxt.button = index == 8 ? '上传' : '切换'
+ this.exTxt.index = index
switch (index) {
case 0:
case 1:
@@ -1102,9 +1102,9 @@
case 6:
case 7:
case 8:
- App.exTxt.name = index == 0 ? App.database : (index == 1 ? App.schema : (index == 2
- ? App.language : (index == 6 ? App.server : (index == 8 ? App.thirdParty : (App.types || []).join()))))
- App.isConfigShow = true
+ this.exTxt.name = index == 0 ? this.database : (index == 1 ? this.schema : (index == 2
+ ? this.language : (index == 6 ? this.server : (index == 8 ? this.thirdParty : (this.types || []).join()))))
+ this.isConfigShow = true
if (index == 0) {
alert('可填数据库:\nMYSQL,POSTGRESQL,SQLSERVER,ORACLE,DB2,SQLITE')
@@ -1116,12 +1116,12 @@
alert('多个类型用 , 隔开,可填类型:\nPARAM(GET ?a=1&b=c&key=value),\nJSON(POST application/json),\nFORM(POST x-www-form-urlencoded),\nDATA(POST form-data),\nGRPC(POST application/json 需要 GRPC 服务开启反射)')
}
else if (index == 8) {
- App.isHeaderShow = true
+ this.isHeaderShow = true
alert('例如:\nSWAGGER http://apijson.cn:8080/v2/api-docs\nSWAGGER /v2/api-docs // 省略 Host\nSWAGGER / // 省略 Host 和 分支 URL\nRAP /repository/joined /repository/get\nYAPI /api/interface/list_menu /api/interface/get')
try {
- App.getThirdPartyApiList(this.thirdParty, function (platform, docUrl, listUrl, itemUrl, url_, res, err) {
+ this.getThirdPartyApiList(this.thirdParty, function (platform, docUrl, listUrl, itemUrl, url_, res, err) {
CodeUtil.thirdParty = platform
if (err != null || ((res || {}).data || {}).errCode != 0) {
App.isHeaderShow = true
@@ -1182,89 +1182,89 @@
}
break
case 3:
- App.host = App.getBaseUrl()
- App.showUrl(false, new String(vUrl.value).substring(App.host.length)) //没必要导致必须重新获取 Response,App.onChange(false)
+ this.host = this.getBaseUrl()
+ this.showUrl(false, new String(vUrl.value).substring(this.host.length)) //没必要导致必须重新获取 Response,App.onChange(false)
break
case 4:
- App.isHeaderShow = show
- App.saveCache('', 'isHeaderShow', show)
+ this.isHeaderShow = show
+ this.saveCache('', 'isHeaderShow', show)
break
case 5:
- App.isRandomShow = show
- App.saveCache('', 'isRandomShow', show)
+ this.isRandomShow = show
+ this.saveCache('', 'isRandomShow', show)
break
case 9:
- App.isDelegateEnabled = show
- App.saveCache('', 'isDelegateEnabled', show)
+ this.isDelegateEnabled = show
+ this.saveCache('', 'isDelegateEnabled', show)
break
case 10:
- App.isPreviewEnabled = show
- App.saveCache('', 'isPreviewEnabled', show)
+ this.isPreviewEnabled = show
+ this.saveCache('', 'isPreviewEnabled', show)
- App.onChange(false)
+ this.onChange(false)
break
case 12:
- App.isEncodeEnabled = show
- App.saveCache('', 'isEncodeEnabled', show)
+ this.isEncodeEnabled = show
+ this.saveCache('', 'isEncodeEnabled', show)
break
case 11:
- var did = ((App.currentRemoteItem || {}).Document || {}).id
+ var did = ((this.currentRemoteItem || {}).Document || {}).id
if (did == null) {
alert('请先选择一个已上传的用例!')
return
}
- App.isEditResponse = show
+ this.isEditResponse = show
// App.saveCache('', 'isEditResponse', show)
- vInput.value = ((App.view != 'code' || StringUtil.isEmpty(App.jsoncon, true) ? null : App.jsoncon)
- || (App.currentRemoteItem.TestRecord || {}).response) || ''
+ vInput.value = ((this.view != 'code' || StringUtil.isEmpty(this.jsoncon, true) ? null : this.jsoncon)
+ || (this.currentRemoteItem.TestRecord || {}).response) || ''
- vHeader.value = (App.currentRemoteItem.TestRecord || {}).header || ''
+ vHeader.value = (this.currentRemoteItem.TestRecord || {}).header || ''
- App.isTestCaseShow = false
- App.onChange(false)
+ this.isTestCaseShow = false
+ this.onChange(false)
break
}
}
else if (index == 3) {
- var host = StringUtil.get(App.host)
+ var host = StringUtil.get(this.host)
var branch = new String(vUrl.value)
- App.host = ''
+ this.host = ''
vUrl.value = host + branch //保证 showUrl 里拿到的 baseUrl = App.host (http://apijson.cn:8080/put /balance)
- App.setBaseUrl() //保证自动化测试等拿到的 baseUrl 是最新的
- App.showUrl(false, branch) //没必要导致必须重新获取 Response,App.onChange(false)
+ this.setBaseUrl() //保证自动化测试等拿到的 baseUrl 是最新的
+ this.showUrl(false, branch) //没必要导致必须重新获取 Response,App.onChange(false)
}
else if (index == 4) {
- App.isHeaderShow = show
- App.saveCache('', 'isHeaderShow', show)
+ this.isHeaderShow = show
+ this.saveCache('', 'isHeaderShow', show)
}
else if (index == 5) {
- App.isRandomShow = show
- App.saveCache('', 'isRandomShow', show)
+ this.isRandomShow = show
+ this.saveCache('', 'isRandomShow', show)
}
else if (index == 9) {
- App.isDelegateEnabled = show
- App.saveCache('', 'isDelegateEnabled', show)
+ this.isDelegateEnabled = show
+ this.saveCache('', 'isDelegateEnabled', show)
}
else if (index == 10) {
- App.isPreviewEnabled = show
- App.saveCache('', 'isPreviewEnabled', show)
+ this.isPreviewEnabled = show
+ this.saveCache('', 'isPreviewEnabled', show)
// vRequestMarkdown.innerHTML = ''
}
else if (index == 12) {
- App.isEncodeEnabled = show
- App.saveCache('', 'isEncodeEnabled', show)
+ this.isEncodeEnabled = show
+ this.saveCache('', 'isEncodeEnabled', show)
}
else if (index == 11) {
- App.isEditResponse = show
+ this.isEditResponse = show
// App.saveCache('', 'isEditResponse', show)
- vInput.value = (App.currentRemoteItem.Document || {}).request || ''
- vHeader.value = (App.currentRemoteItem.Document || {}).header || ''
+ vInput.value = (this.currentRemoteItem.Document || {}).request || ''
+ vHeader.value = (this.currentRemoteItem.Document || {}).header || ''
- App.isTestCaseShow = false
- App.onChange(false)
+ this.isTestCaseShow = false
+ this.onChange(false)
}
},
@@ -2560,7 +2560,7 @@
onClickAccount: function (index, item, callback) {
- App.isTestCaseShow = false
+ this.isTestCaseShow = false
if (this.currentAccountIndex == index) {
if (item == null) {
@@ -2643,21 +2643,21 @@
},
removeAccountTab: function () {
- if (App.accounts.length <= 1) {
+ if (this.accounts.length <= 1) {
alert('至少要 1 个测试账号!')
return
}
- App.accounts.splice(App.currentAccountIndex, 1)
- if (App.currentAccountIndex >= App.accounts.length) {
- App.currentAccountIndex = App.accounts.length - 1
+ this.accounts.splice(this.currentAccountIndex, 1)
+ if (this.currentAccountIndex >= this.accounts.length) {
+ this.currentAccountIndex = this.accounts.length - 1
}
- App.saveCache(App.getBaseUrl(), 'currentAccountIndex', App.currentAccountIndex)
- App.saveCache(App.getBaseUrl(), 'accounts', App.accounts)
+ this.saveCache(this.getBaseUrl(), 'currentAccountIndex', this.currentAccountIndex)
+ this.saveCache(this.getBaseUrl(), 'accounts', this.accounts)
},
addAccountTab: function () {
- App.showLogin(true, false)
+ this.showLogin(true, false)
},
@@ -2698,7 +2698,7 @@
this.isTestCaseShow = false
- var types = App.types
+ var types = this.types
var search = StringUtil.isEmpty(this.testCaseSearch, true) ? null : '%' + StringUtil.trim(this.testCaseSearch) + '%'
var url = this.server + '/get'
var req = {
@@ -2708,7 +2708,7 @@
'page': this.testCasePage || 0,
'Document': {
'@order': 'version-,date-',
- 'userId': App.User.id,
+ 'userId': this.User.id,
'name$': search,
'url$': search,
'@combine': search == null ? null : 'name$,url$',
@@ -2716,19 +2716,19 @@
},
'TestRecord': {
'documentId@': '/Document/id',
- 'userId': App.User.id,
- 'testAccountId': App.getCurrentAccountId(),
+ 'userId': this.User.id,
+ 'testAccountId': this.getCurrentAccountId(),
'randomId': 0,
'@order': 'date-',
- '@column': 'id,userId,documentId,duration,minDuration,maxDuration,response' + (App.isMLEnabled ? ',standard' : ''),
- '@having': App.isMLEnabled ? 'length(standard)>2' : null //用 MySQL 5.6 '@having': App.isMLEnabled ? 'json_length(standard)>0' : null
+ '@column': 'id,userId,documentId,duration,minDuration,maxDuration,response' + (this.isMLEnabled ? ',standard' : ''),
+ '@having': this.isMLEnabled ? 'length(standard)>2' : null //用 MySQL 5.6 '@having': this.isMLEnabled ? 'json_length(standard)>0' : null
}
},
'@role': 'LOGIN'
}
- App.onChange(false)
- App.request(true, REQUEST_TYPE_JSON, url, req, {}, function (url, res, err) {
+ this.onChange(false)
+ this.request(true, REQUEST_TYPE_JSON, url, req, {}, function (url, res, err) {
App.onResponse(url, res, err)
var rpObj = res.data
@@ -3169,7 +3169,7 @@
return;
}
- App.view = 'output';
+ this.view = 'output';
vComment.value = '';
// vUrlComment.value = '';
vOutput.value = 'resolving...';
@@ -3184,7 +3184,7 @@
throw new Error(e2.message)
}
- before = App.toDoubleJSON(StringUtil.trim(before));
+ before = this.toDoubleJSON(StringUtil.trim(before));
log('onHandle before = \n' + before);
var afterObj;
@@ -3199,7 +3199,7 @@
log('main.onHandle', 'return jsonlint.parse(App.removeComment(before));')
try {
- afterObj = jsonlint.parse(App.removeComment(before));
+ afterObj = jsonlint.parse(this.removeComment(before));
after = JSON.stringify(afterObj, null, " ");
} catch (e2) {
throw new Error('请求 JSON 格式错误!请检查并编辑请求!\n\n如果JSON中有注释,请 手动删除 或 点击左边的 \'/" 按钮 来去掉。\n\n' + e2.message)
@@ -3208,7 +3208,7 @@
//关键词let在IE和Safari上不兼容
var code = '';
- if (App.isEditResponse != true) {
+ if (this.isEditResponse != true) {
try {
code = this.getCode(after); //必须在before还是用 " 时使用,后面用会因为解析 ' 导致失败
} catch (e) {
@@ -3233,22 +3233,22 @@
+ ' \n'; //解决遮挡
vSend.disabled = false;
- if (App.isEditResponse != true) {
+ if (this.isEditResponse != true) {
vOutput.value = output = 'OK,请点击 [发送请求] 按钮来测试。[点击这里查看视频教程](https://i.youku.com/i/UNTg1NzI1MjQ4MA==/videos?spm=a2hzp.8244740.0.0)' + code;
- App.showDoc()
+ this.showDoc()
}
try {
var standardObj = null;
try {
- standardObj = JSON.parse(((App.currentRemoteItem || {})[App.isEditResponse ? 'TestRecord' : 'Document'] || {}).standard);
+ standardObj = JSON.parse(((this.currentRemoteItem || {})[this.isEditResponse ? 'TestRecord' : 'Document'] || {}).standard);
} catch (e3) {
log(e3)
}
- var m = App.getMethod();
- var c = isSingle ? '' : StringUtil.trim(CodeUtil.parseComment(after, docObj == null ? null : docObj['[]'], m, App.database, App.language, App.isEditResponse != true, standardObj))
+ var m = this.getMethod();
+ var c = isSingle ? '' : StringUtil.trim(CodeUtil.parseComment(after, docObj == null ? null : docObj['[]'], m, this.database, this.language, this.isEditResponse != true, standardObj))
+ '\n '
+ ' \n'; //解决遮挡
//TODO 统计行数,补全到一致 vInput.value.lineNumbers
@@ -3260,12 +3260,12 @@
}
}
vComment.value = c
- vUrlComment.value = isSingle || StringUtil.isEmpty(App.urlComment, true)
- ? '' : vUrl.value + CodeUtil.getComment(App.urlComment, false, ' ')
- + ' - ' + (App.requestVersion > 0 ? 'V' + App.requestVersion : 'V*');
+ vUrlComment.value = isSingle || StringUtil.isEmpty(this.urlComment, true)
+ ? '' : vUrl.value + CodeUtil.getComment(this.urlComment, false, ' ')
+ + ' - ' + (this.requestVersion > 0 ? 'V' + this.requestVersion : 'V*');
if (! isSingle) {
- var method = App.getMethod(); // m 已经 toUpperCase 了
+ var method = this.getMethod(); // m 已经 toUpperCase 了
var isRestful = ! JSONObject.isAPIJSONPath(method);
if (isRestful != true) {
method = method.toUpperCase();
@@ -3274,8 +3274,8 @@
var api = apiMap == null ? null : apiMap['/' + method];
var name = api == null ? null : api.name;
if (StringUtil.isEmpty(name, true) == false) {
- App.urlComment = name;
- vUrlComment.value = vUrl.value + CodeUtil.getComment(App.urlComment, false, ' ')
+ this.urlComment = name;
+ vUrlComment.value = vUrl.value + CodeUtil.getComment(this.urlComment, false, ' ')
}
}
@@ -3300,17 +3300,17 @@
log(e3)
}
- if (App.isEditResponse) {
- App.view = 'code';
- App.jsoncon = after
+ if (this.isEditResponse) {
+ this.view = 'code';
+ this.jsoncon = after
}
} catch(e) {
log(e)
vSend.disabled = true
- App.view = 'error'
- App.error = {
+ this.view = 'error'
+ this.error = {
msg: e.message
}
}
@@ -3329,9 +3329,13 @@
this.isDelayShow = delay;
- handler = setTimeout(function () {
- App.onHandle(inputted);
- }, delay ? 2*1000 : 0);
+ if (delay) {
+ handler = setTimeout(function () {
+ App.onHandle(inputted);
+ }, 2000);
+ } else {
+ this.onHandle(inputted);
+ }
},
/**单双引号切换
@@ -3517,7 +3521,7 @@
axios({
method: (type == REQUEST_TYPE_PARAM ? 'get' : 'post'),
url: (isAdminOperation == false && this.isDelegateEnabled ? (this.server + '/delegate?' + (type == REQUEST_TYPE_GRPC ? '$_type=GRPC&' : '') + '$_delegate_url=') : '' )
- + (App.isEncodeEnabled ? encodeURI(StringUtil.noBlank(url)) : StringUtil.noBlank(url)),
+ + (this.isEncodeEnabled ? encodeURI(StringUtil.noBlank(url)) : StringUtil.noBlank(url)),
params: (type == REQUEST_TYPE_PARAM || type == REQUEST_TYPE_FORM ? req : null),
data: (type == REQUEST_TYPE_JSON || type == REQUEST_TYPE_GRPC ? req : (type == REQUEST_TYPE_DATA ? toFormData(req) : null)),
headers: header, //Accept-Encoding(HTTP Header 大小写不敏感,SpringBoot 接收后自动转小写)可能导致 Response 乱码
@@ -3902,7 +3906,7 @@
+ '
'
);
- App.view = 'markdown';
+ this.view = 'markdown';
markdownToHTML(vOutput.value);
return true;
},
@@ -5803,9 +5807,11 @@
try {
var setting = JSON.parse(StringUtil.trim(rawReq.setting, true)) || {}
- var delayTime = 0
- if (setting.count != App.count || setting.page != App.page || setting.search != App.search) {
- delayTime += 2000
+ if ((setting.count != null && setting.count != App.count)
+ || (setting.page != null && setting.page != App.page)
+ || (setting.search != null && setting.search != App.search)) {
+ delayTime += Math.min(5000, 30*(setting.count) + 1000)
+ App.setDoc("");
App.getDoc(function (d) {
App.setDoc(d);
})
@@ -5824,12 +5830,12 @@
}
if (setting.isRandomShow && setting.isRandomListShow) {
- delayTime += 2000
+ delayTime += Math.min(5000, 20*(setting.randomCount || App.randomCount) + 1000)
App.showRandomList(true, setting.isRandomSubListShow ? App.currentRandomItem : null, setting.isRandomSubListShow)
}
if (setting.isTestCaseShow) {
- delayTime += 2000
+ delayTime += Math.min(5000, 10*(setting.testCaseCount || App.testCaseCount) + 1000)
App.showTestCase(true, setting.isLocalShow)
}
} catch (e) {
@@ -5864,7 +5870,7 @@
window.open(vUrl.value + "/" + encodeURIComponent(JSON.stringify(encode(JSON.parse(vInput.value)))))
}, 2000)
}
- }, delayTime)
+ }, Math.max(1000, delayTime))
}
}, 2000)
From 60d0b13106258ee5932f1da247c288c43a2952d5 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Thu, 7 Oct 2021 04:06:12 +0800
Subject: [PATCH 503/818] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=9C=89=E6=97=B6?=
=?UTF-8?q?=E5=90=AF=E5=8A=A8=E6=8A=A5=E9=94=99?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 616 +++++++++++++++++++++++++++--------------------------
1 file changed, 309 insertions(+), 307 deletions(-)
diff --git a/js/main.js b/js/main.js
index 12252af..a867156 100755
--- a/js/main.js
+++ b/js/main.js
@@ -651,7 +651,7 @@
// 全部展开
expandAll: function () {
- if (App.view != 'code') {
+ if (this.view != 'code') {
alert('请先获取正确的JSON Response!')
return
}
@@ -661,12 +661,12 @@
$('.expand-view').show()
$('.fold-view').hide()
- App.isExpand = true;
+ this.isExpand = true;
},
// 全部折叠
collapseAll: function () {
- if (App.view != 'code') {
+ if (this.view != 'code') {
alert('请先获取正确的JSON Response!')
return
}
@@ -676,29 +676,29 @@
$('.expand-view').hide()
$('.fold-view').show()
- App.isExpand = false;
+ this.isExpand = false;
},
// diff
diffTwo: function () {
var oldJSON = {}
var newJSON = {}
- App.view = 'code'
+ this.view = 'code'
try {
- oldJSON = jsonlint.parse(App.jsoncon)
+ oldJSON = jsonlint.parse(this.jsoncon)
} catch (ex) {
- App.view = 'error'
- App.error = {
+ this.view = 'error'
+ this.error = {
msg: '原 JSON 解析错误\r\n' + ex.message
}
return
}
try {
- newJSON = jsonlint.parse(App.jsoncon)
+ newJSON = jsonlint.parse(this.jsoncon)
} catch (ex) {
- App.view = 'error'
- App.error = {
+ this.view = 'error'
+ this.error = {
msg: '新 JSON 解析错误\r\n' + ex.message
}
return
@@ -720,33 +720,33 @@
},
baseViewToDiff: function () {
- App.baseview = 'diff'
- App.diffTwo()
+ this.baseview = 'diff'
+ this.diffTwo()
},
// 回到格式化视图
baseViewToFormater: function () {
- App.baseview = 'formater'
- App.view = 'code'
- App.showJsonView()
+ this.baseview = 'formater'
+ this.view = 'code'
+ this.showJsonView()
},
// 根据json内容变化格式化视图
showJsonView: function () {
- if (App.baseview === 'diff') {
+ if (this.baseview === 'diff') {
return
}
try {
if (this.jsoncon.trim() === '') {
- App.view = 'empty'
+ this.view = 'empty'
} else {
- App.view = 'code'
+ this.view = 'code'
if (isSingle) {
- App.jsonhtml = jsonlint.parse(this.jsoncon)
+ this.jsonhtml = jsonlint.parse(this.jsoncon)
}
else {
- App.jsonhtml = Object.assign({
+ this.jsonhtml = Object.assign({
_$_this_$_: JSON.stringify({
path: null,
table: null
@@ -756,8 +756,8 @@
}
} catch (ex) {
- App.view = 'error'
- App.error = {
+ this.view = 'error'
+ this.error = {
msg: ex.message
}
}
@@ -769,18 +769,18 @@
if (isAdminOperation != true) {
baseUrl = this.getBaseUrl()
}
- vUrl.value = (isAdminOperation ? App.server : baseUrl) + branchUrl
+ vUrl.value = (isAdminOperation ? this.server : baseUrl) + branchUrl
}
else { //隐藏(固定)URL Host
if (isAdminOperation) {
- this.host = App.server
+ this.host = this.server
}
vUrl.value = branchUrl
}
- vUrlComment.value = isSingle || StringUtil.isEmpty(App.urlComment, true)
- ? '' : vUrl.value + CodeUtil.getComment(App.urlComment, false, ' ')
- + ' - ' + (App.requestVersion > 0 ? 'V' + App.requestVersion : 'V*');
+ vUrlComment.value = isSingle || StringUtil.isEmpty(this.urlComment, true)
+ ? '' : vUrl.value + CodeUtil.getComment(this.urlComment, false, ' ')
+ + ' - ' + (this.requestVersion > 0 ? 'V' + this.requestVersion : 'V*');
},
//设置基地址
@@ -800,7 +800,7 @@
// this.remotes = []
// var index = baseUrl.indexOf(':') //http://localhost:8080
- // App.server = (index < 0 ? baseUrl : baseUrl.substring(0, baseUrl)) + ':9090'
+ // this.server = (index < 0 ? baseUrl : baseUrl.substring(0, baseUrl)) + ':9090'
}
},
@@ -849,7 +849,7 @@
},
getRequest: function (json, defaultValue) {
- var s = App.toDoubleJSON(json, defaultValue);
+ var s = this.toDoubleJSON(json, defaultValue);
if (StringUtil.isEmpty(s, true)) {
return defaultValue
}
@@ -858,8 +858,8 @@
}
catch (e) {
log('main.getRequest', 'try { return jsonlint.parse(s); \n } catch (e) {\n' + e.message)
- log('main.getRequest', 'return jsonlint.parse(App.removeComment(s));')
- return jsonlint.parse(App.removeComment(s));
+ log('main.getRequest', 'return jsonlint.parse(this.removeComment(s));')
+ return jsonlint.parse(this.removeComment(s));
}
},
getHeader: function (text) {
@@ -892,7 +892,7 @@
val = eval(val)
}
catch (e) {
- App.log("getHeader if (hs != null && hs.length > 0) { ... if (ind > 0 && val.indexOf(')') > ind) { ... try { val = eval(val) } catch (e) = " + e.message)
+ this.log("getHeader if (hs != null && hs.length > 0) { ... if (ind > 0 && val.indexOf(')') > ind) { ... try { val = eval(val) } catch (e) = " + e.message)
}
}
@@ -906,7 +906,7 @@
// 分享 APIAuto 特有链接,打开即可还原分享人的 JSON 参数、设置项、搜索关键词、分页数量及页码等配置
shareLink: function (isRandom) {
var jsonStr = null
- if (App.isTestCaseShow != true) {
+ if (this.isTestCaseShow != true) {
try {
jsonStr = JSON.stringify(encode(JSON.parse(vInput.value)))
} catch (e) { // 可能包含注释
@@ -919,50 +919,50 @@
var settingStr = null
try {
settingStr = JSON.stringify({
- requestVersion: App.requestVersion,
- requestCount: App.requestCount,
- isTestCaseShow: App.isTestCaseShow,
- // isHeaderShow: App.isHeaderShow,
- // isRandomShow: App.isRandomShow,
- isRandomListShow: App.isRandomShow ? App.isRandomListShow : undefined,
- isRandomSubListShow: App.isRandomListShow ? App.isRandomSubListShow : undefined,
- // isRandomEditable: App.isRandomEditable,
- isCrossEnabled: App.isCrossEnabled,
- isMLEnabled: App.isMLEnabled,
- isDelegateEnabled: App.isDelegateEnabled,
- isPreviewEnabled: App.isPreviewEnabled,
- isEncodeEnabled: App.isEncodeEnabled,
- isEditResponse: App.isEditResponse,
- isLocalShow: App.isTestCaseShow ? App.isLocalShow : undefined,
- page: App.page,
- count: App.count,
- testCasePage: App.testCasePage,
- testCaseCount: App.testCaseCount,
- testRandomCount: App.testRandomCount,
- randomPage: App.randomPage,
- randomCount: App.randomCount,
- randomSubPage: App.randomSubPage,
- randomSubCount: App.randomSubCount,
- host: StringUtil.isEmpty(App.host, true) ? undefined : encodeURIComponent(App.host),
- search: StringUtil.isEmpty(App.search, true) ? undefined : encodeURIComponent(App.search),
- testCaseSearch: StringUtil.isEmpty(App.testCaseSearch, true) ? undefined : App.testCaseSearch,
- randomSearch: StringUtil.isEmpty(App.randomSearch, true) ? undefined : encodeURIComponent(App.randomSearch),
- randomSubSearch: StringUtil.isEmpty(App.randomSubSearch, true) ? undefined : encodeURIComponent(App.randomSubSearch)
+ requestVersion: this.requestVersion,
+ requestCount: this.requestCount,
+ isTestCaseShow: this.isTestCaseShow,
+ // isHeaderShow: this.isHeaderShow,
+ // isRandomShow: this.isRandomShow,
+ isRandomListShow: this.isRandomShow ? this.isRandomListShow : undefined,
+ isRandomSubListShow: this.isRandomListShow ? this.isRandomSubListShow : undefined,
+ // isRandomEditable: this.isRandomEditable,
+ isCrossEnabled: this.isCrossEnabled,
+ isMLEnabled: this.isMLEnabled,
+ isDelegateEnabled: this.isDelegateEnabled,
+ isPreviewEnabled: this.isPreviewEnabled,
+ isEncodeEnabled: this.isEncodeEnabled,
+ isEditResponse: this.isEditResponse,
+ isLocalShow: this.isTestCaseShow ? this.isLocalShow : undefined,
+ page: this.page,
+ count: this.count,
+ testCasePage: this.testCasePage,
+ testCaseCount: this.testCaseCount,
+ testRandomCount: this.testRandomCount,
+ randomPage: this.randomPage,
+ randomCount: this.randomCount,
+ randomSubPage: this.randomSubPage,
+ randomSubCount: this.randomSubCount,
+ host: StringUtil.isEmpty(this.host, true) ? undefined : encodeURIComponent(this.host),
+ search: StringUtil.isEmpty(this.search, true) ? undefined : encodeURIComponent(this.search),
+ testCaseSearch: StringUtil.isEmpty(this.testCaseSearch, true) ? undefined : this.testCaseSearch,
+ randomSearch: StringUtil.isEmpty(this.randomSearch, true) ? undefined : encodeURIComponent(this.randomSearch),
+ randomSubSearch: StringUtil.isEmpty(this.randomSubSearch, true) ? undefined : encodeURIComponent(this.randomSubSearch)
})
} catch (e){
log(e)
}
- var headerStr = App.isTestCaseShow || StringUtil.isEmpty(vHeader.value, true) ? null : encodeURIComponent(StringUtil.trim(vHeader.value))
- var randomStr = App.isTestCaseShow || StringUtil.isEmpty(vRandom.value, true) ? null : encodeURIComponent(StringUtil.trim(vRandom.value))
+ var headerStr = this.isTestCaseShow || StringUtil.isEmpty(vHeader.value, true) ? null : encodeURIComponent(StringUtil.trim(vHeader.value))
+ var randomStr = this.isTestCaseShow || StringUtil.isEmpty(vRandom.value, true) ? null : encodeURIComponent(StringUtil.trim(vRandom.value))
var href = window.location.href || 'http://apijson.cn/api'
var ind = href == null ? -1 : href.indexOf('?') // url 后带参数只能 encodeURIComponent
// 实测 561059 长度的 URL 都支持,只是输入框显示长度约为 2000
window.open((ind < 0 ? href : href.substring(0, ind))
- + (App.view != 'code' ? "?send=false" : (isRandom ? "?send=random" : "?send=true"))
- + "&type=" + StringUtil.trim(App.type)
+ + (this.view != 'code' ? "?send=false" : (isRandom ? "?send=random" : "?send=true"))
+ + "&type=" + StringUtil.trim(this.type)
+ "&url=" + encodeURIComponent(StringUtil.trim(vUrl.value))
+ (StringUtil.isEmpty(jsonStr, true) ? '' : "&json=" + jsonStr)
+ (StringUtil.isEmpty(headerStr, true) ? '' : "&header=" + headerStr)
@@ -974,15 +974,15 @@
// 显示保存弹窗
showSave: function (show) {
if (show) {
- if (App.isTestCaseShow) {
+ if (this.isTestCaseShow) {
alert('请先输入请求内容!')
return
}
- var tag = App.getTag()
- App.history.name = (App.urlComment || App.getMethod() + (StringUtil.isEmpty(tag, true) ? '' : ' ' + tag)) + ' ' + App.formatTime() //不自定义名称的都是临时的,不需要时间太详细
+ var tag = this.getTag()
+ this.history.name = (this.urlComment || this.getMethod() + (StringUtil.isEmpty(tag, true) ? '' : ' ' + tag)) + ' ' + this.formatTime() //不自定义名称的都是临时的,不需要时间太详细
}
- App.isSaveShow = show
+ this.isSaveShow = show
},
// 显示导出弹窗
@@ -991,7 +991,7 @@
if (isRemote) { //共享测试用例
this.isExportRandom = isRandom
- if (isRandom != true) { // 分享搜索关键词和分页信息也挺好 } && App.isTestCaseShow != true) { // 没有拿到列表,没用
+ if (isRandom != true) { // 分享搜索关键词和分页信息也挺好 } && this.isTestCaseShow != true) { // 没有拿到列表,没用
setTimeout(function () {
App.shareLink(App.isRandomTest)
}, 1000)
@@ -1016,13 +1016,13 @@
return
}
- // var tag = App.getTag()
- this.exTxt.name = this.urlComment || '' // 避免偷懒不输入名称 App.getMethod() + (StringUtil.isEmpty(tag, true) ? '' : ' ' + tag)
+ // var tag = this.getTag()
+ this.exTxt.name = this.urlComment || '' // 避免偷懒不输入名称 this.getMethod() + (StringUtil.isEmpty(tag, true) ? '' : ' ' + tag)
}
}
else { //下载到本地
if (this.isTestCaseShow) { //文档
- this.exTxt.name = 'APIJSON自动化文档 ' + App.formatDateTime()
+ this.exTxt.name = 'APIJSON自动化文档 ' + this.formatDateTime()
}
else if (this.view == 'markdown' || this.view == 'output') {
var suffix
@@ -1183,7 +1183,7 @@
break
case 3:
this.host = this.getBaseUrl()
- this.showUrl(false, new String(vUrl.value).substring(this.host.length)) //没必要导致必须重新获取 Response,App.onChange(false)
+ this.showUrl(false, new String(vUrl.value).substring(this.host.length)) //没必要导致必须重新获取 Response,this.onChange(false)
break
case 4:
this.isHeaderShow = show
@@ -1215,7 +1215,7 @@
}
this.isEditResponse = show
- // App.saveCache('', 'isEditResponse', show)
+ // this.saveCache('', 'isEditResponse', show)
vInput.value = ((this.view != 'code' || StringUtil.isEmpty(this.jsoncon, true) ? null : this.jsoncon)
|| (this.currentRemoteItem.TestRecord || {}).response) || ''
@@ -1231,9 +1231,9 @@
var host = StringUtil.get(this.host)
var branch = new String(vUrl.value)
this.host = ''
- vUrl.value = host + branch //保证 showUrl 里拿到的 baseUrl = App.host (http://apijson.cn:8080/put /balance)
+ vUrl.value = host + branch //保证 showUrl 里拿到的 baseUrl = this.host (http://apijson.cn:8080/put /balance)
this.setBaseUrl() //保证自动化测试等拿到的 baseUrl 是最新的
- this.showUrl(false, branch) //没必要导致必须重新获取 Response,App.onChange(false)
+ this.showUrl(false, branch) //没必要导致必须重新获取 Response,this.onChange(false)
}
else if (index == 4) {
this.isHeaderShow = show
@@ -1258,7 +1258,7 @@
}
else if (index == 11) {
this.isEditResponse = show
- // App.saveCache('', 'isEditResponse', show)
+ // this.saveCache('', 'isEditResponse', show)
vInput.value = (this.currentRemoteItem.Document || {}).request || ''
vHeader.value = (this.currentRemoteItem.Document || {}).header || ''
@@ -1346,16 +1346,16 @@
// 保存当前的JSON
save: function () {
- if (App.history.name.trim() === '') {
+ if (this.history.name.trim() === '') {
Helper.alert('名称不能为空!', 'danger')
return
}
var val = {
- name: App.history.name,
- type: App.type,
+ name: this.history.name,
+ type: this.type,
url: '/' + this.getMethod(),
request: inputted,
- response: App.jsoncon,
+ response: this.jsoncon,
header: vHeader.value,
random: vRandom.value
}
@@ -1407,8 +1407,8 @@
var response = ((item || {}).TestRecord || {}).response
if (StringUtil.isEmpty(response, true) == false) {
- App.jsoncon = StringUtil.trim(response)
- App.view = 'code'
+ this.jsoncon = StringUtil.trim(response)
+ this.view = 'code'
}
},
// 根据测试用例/历史记录恢复数据
@@ -1423,7 +1423,7 @@
},
// 根据历史恢复数据
restore: function (item, response, isRemote, test) {
- App.isEditResponse = false
+ this.isEditResponse = false
item = item || {}
// localforage.getItem(item.key || '', function (err, value) {
@@ -1432,24 +1432,24 @@
branch = '/' + branch
}
- App.type = item.type;
- App.urlComment = item.name;
- App.requestVersion = item.version;
- App.showUrl(false, branch)
+ this.type = item.type;
+ this.urlComment = item.name;
+ this.requestVersion = item.version;
+ this.showUrl(false, branch)
- App.showTestCase(false, App.isLocalShow)
+ this.showTestCase(false, this.isLocalShow)
vInput.value = StringUtil.get(item.request)
vHeader.value = StringUtil.get(item.header)
vRandom.value = StringUtil.get(item.random)
- App.onChange(false)
+ this.onChange(false)
if (isRemote) {
- App.randoms = []
- App.showRandomList(App.isRandomListShow, item)
+ this.randoms = []
+ this.showRandomList(this.isRandomListShow, item)
}
if (test) {
- App.send(false)
+ this.send(false)
}
else {
if (StringUtil.isEmpty(response, true) == false) {
@@ -1479,53 +1479,53 @@
// 导出文本
exportTxt: function () {
- App.isExportShow = false
+ this.isExportShow = false
- if (App.isExportRemote == false) { //下载到本地
+ if (this.isExportRemote == false) { //下载到本地
- if (App.isTestCaseShow) { //文档
- saveTextAs('# ' + App.exTxt.name + '\n主页: https://github.com/Tencent/APIJSON'
+ if (this.isTestCaseShow) { //文档
+ saveTextAs('# ' + this.exTxt.name + '\n主页: https://github.com/Tencent/APIJSON'
+ '\n\nBASE_URL: ' + this.getBaseUrl()
- + '\n\n\n## 测试用例(Markdown格式,可用工具预览) \n\n' + App.getDoc4TestCase()
+ + '\n\n\n## 测试用例(Markdown格式,可用工具预览) \n\n' + this.getDoc4TestCase()
+ '\n\n\n\n\n\n\n\n## 文档(Markdown格式,可用工具预览) \n\n' + doc
- , App.exTxt.name + '.txt')
+ , this.exTxt.name + '.txt')
}
- else if (App.view == 'markdown' || App.view == 'output') { //model
- var clazz = StringUtil.trim(App.exTxt.name)
+ else if (this.view == 'markdown' || this.view == 'output') { //model
+ var clazz = StringUtil.trim(this.exTxt.name)
var txt = '' //配合下面 +=,实现注释判断,一次全生成,方便测试
if (clazz.endsWith('.java')) {
- txt += CodeUtil.parseJavaBean(docObj, clazz.substring(0, clazz.length - 5), App.database)
+ txt += CodeUtil.parseJavaBean(docObj, clazz.substring(0, clazz.length - 5), this.database)
}
else if (clazz.endsWith('.swift')) {
- txt += CodeUtil.parseSwiftStruct(docObj, clazz.substring(0, clazz.length - 6), App.database)
+ txt += CodeUtil.parseSwiftStruct(docObj, clazz.substring(0, clazz.length - 6), this.database)
}
else if (clazz.endsWith('.kt')) {
- txt += CodeUtil.parseKotlinDataClass(docObj, clazz.substring(0, clazz.length - 3), App.database)
+ txt += CodeUtil.parseKotlinDataClass(docObj, clazz.substring(0, clazz.length - 3), this.database)
}
else if (clazz.endsWith('.m')) {
- txt += CodeUtil.parseObjectiveCEntity(docObj, clazz.substring(0, clazz.length - 2), App.database)
+ txt += CodeUtil.parseObjectiveCEntity(docObj, clazz.substring(0, clazz.length - 2), this.database)
}
else if (clazz.endsWith('.cs')) {
- txt += CodeUtil.parseCSharpEntity(docObj, clazz.substring(0, clazz.length - 3), App.database)
+ txt += CodeUtil.parseCSharpEntity(docObj, clazz.substring(0, clazz.length - 3), this.database)
}
else if (clazz.endsWith('.php')) {
- txt += CodeUtil.parsePHPEntity(docObj, clazz.substring(0, clazz.length - 4), App.database)
+ txt += CodeUtil.parsePHPEntity(docObj, clazz.substring(0, clazz.length - 4), this.database)
}
else if (clazz.endsWith('.go')) {
- txt += CodeUtil.parseGoEntity(docObj, clazz.substring(0, clazz.length - 3), App.database)
+ txt += CodeUtil.parseGoEntity(docObj, clazz.substring(0, clazz.length - 3), this.database)
}
else if (clazz.endsWith('.cpp')) {
- txt += CodeUtil.parseCppStruct(docObj, clazz.substring(0, clazz.length - 4), App.database)
+ txt += CodeUtil.parseCppStruct(docObj, clazz.substring(0, clazz.length - 4), this.database)
}
else if (clazz.endsWith('.js')) {
- txt += CodeUtil.parseJavaScriptEntity(docObj, clazz.substring(0, clazz.length - 3), App.database)
+ txt += CodeUtil.parseJavaScriptEntity(docObj, clazz.substring(0, clazz.length - 3), this.database)
}
else if (clazz.endsWith('.ts')) {
- txt += CodeUtil.parseTypeScriptEntity(docObj, clazz.substring(0, clazz.length - 3), App.database)
+ txt += CodeUtil.parseTypeScriptEntity(docObj, clazz.substring(0, clazz.length - 3), this.database)
}
else if (clazz.endsWith('.py')) {
- txt += CodeUtil.parsePythonEntity(docObj, clazz.substring(0, clazz.length - 3), App.database)
+ txt += CodeUtil.parsePythonEntity(docObj, clazz.substring(0, clazz.length - 3), this.database)
}
else {
alert('请正确输入对应语言的类名后缀!')
@@ -1538,11 +1538,11 @@
saveTextAs(txt, clazz)
}
else {
- var res = JSON.parse(App.jsoncon)
+ var res = JSON.parse(this.jsoncon)
res = this.removeDebugInfo(res)
var s = ''
- switch (App.language) {
+ switch (this.language) {
case CodeUtil.LANGUAGE_KOTLIN:
s += '(Kotlin):\n\n' + CodeUtil.parseKotlinResponse('', res, 0, false, ! isSingle)
break;
@@ -1585,51 +1585,51 @@
break;
}
- saveTextAs('# ' + App.exTxt.name + '\n主页: https://github.com/Tencent/APIJSON'
+ saveTextAs('# ' + this.exTxt.name + '\n主页: https://github.com/Tencent/APIJSON'
+ '\n\n\nURL: ' + StringUtil.get(vUrl.value)
+ '\n\n\nHeader:\n' + StringUtil.get(vHeader.value)
+ '\n\n\nRequest:\n' + StringUtil.get(vInput.value)
- + '\n\n\nResponse:\n' + StringUtil.get(App.jsoncon)
+ + '\n\n\nResponse:\n' + StringUtil.get(this.jsoncon)
+ '\n\n\n## 解析 Response 的代码' + s
- , App.exTxt.name + '.txt')
+ , this.exTxt.name + '.txt')
}
}
else { //上传到远程服务器
- var id = App.User == null ? null : App.User.id
+ var id = this.User == null ? null : this.User.id
if (id == null || id <= 0) {
alert('请先登录!')
return
}
- var isExportRandom = App.isExportRandom
+ var isExportRandom = this.isExportRandom
- if (isExportRandom != true && StringUtil.isEmpty(App.exTxt.name, true)) {
+ if (isExportRandom != true && StringUtil.isEmpty(this.exTxt.name, true)) {
alert('请输入接口名!')
return
}
- var doc = (App.currentRemoteItem || {}).Document || {}
- var tr = (App.currentRemoteItem || {}).TestRecord || {}
+ var doc = (this.currentRemoteItem || {}).Document || {}
+ var tr = (this.currentRemoteItem || {}).TestRecord || {}
var did = doc.id
if (isExportRandom && did == null) {
alert('请先共享测试用例!')
return
}
- App.isTestCaseShow = false
+ this.isTestCaseShow = false
- var currentAccountId = App.getCurrentAccountId()
- var currentResponse = App.view != 'code' || StringUtil.isEmpty(App.jsoncon, true) ? {} : App.removeDebugInfo(JSON.parse(App.jsoncon));
+ var currentAccountId = this.getCurrentAccountId()
+ var currentResponse = this.view != 'code' || StringUtil.isEmpty(this.jsoncon, true) ? {} : this.removeDebugInfo(JSON.parse(this.jsoncon));
- var after = App.toDoubleJSON(inputted);
- var inputObj = App.getRequest(after, {});
+ var after = this.toDoubleJSON(inputted);
+ var inputObj = this.getRequest(after, {});
var commentObj = null;
if (isExportRandom != true) {
- var m = App.getMethod();
+ var m = this.getMethod();
var commentStddObj = null
try {
- commentStddObj = JSON.parse(App.isEditResponse ? tr.standard : doc.standard);
+ commentStddObj = JSON.parse(this.isEditResponse ? tr.standard : doc.standard);
}
catch(e) {
log(e)
@@ -1638,7 +1638,7 @@
inputObj.code = null // delete inputObj.code
commentObj = JSONResponse.updateStandard(commentStddObj, inputObj);
- CodeUtil.parseComment(after, docObj == null ? null : docObj['[]'], m, App.database, App.language, true, commentObj, true);
+ CodeUtil.parseComment(after, docObj == null ? null : docObj['[]'], m, this.database, this.language, true, commentObj, true);
inputObj.code = code_
}
@@ -1648,21 +1648,21 @@
delete currentResponse.code; //code必须一致
delete currentResponse.throw; //throw必须一致
- var isML = App.isMLEnabled;
+ var isML = this.isMLEnabled;
var stddObj = isML ? JSONResponse.updateStandard({}, currentResponse) : {};
stddObj.code = code;
stddObj.throw = thrw;
currentResponse.code = code;
currentResponse.throw = thrw;
- var url = App.server + (isExportRandom || App.isEditResponse || did == null ? '/post' : '/put')
+ var url = this.server + (isExportRandom || this.isEditResponse || did == null ? '/post' : '/put')
var req = isExportRandom ? {
format: false,
'Random': {
toId: 0,
documentId: did,
- count: App.requestCount,
- name: App.exTxt.name,
+ count: this.requestCount,
+ name: this.exTxt.name,
config: vRandom.value
},
'TestRecord': {
@@ -1672,28 +1672,28 @@
'tag': 'Random'
} : {
format: false,
- 'Document': App.isEditResponse ? null : {
+ 'Document': this.isEditResponse ? null : {
'id': did == null ? undefined : did,
'testAccountId': currentAccountId,
- 'name': App.exTxt.name,
- 'type': App.type,
- 'url': '/' + App.getMethod(),
+ 'name': this.exTxt.name,
+ 'type': this.type,
+ 'url': '/' + this.getMethod(),
'request': JSON.stringify(inputObj, null, ' '),
'standard': JSON.stringify(commentObj, null, ' '),
'header': vHeader.value
},
- 'TestRecord': App.isEditResponse != true && did != null ? null : {
- 'documentId': App.isEditResponse ? did : undefined,
+ 'TestRecord': this.isEditResponse != true && did != null ? null : {
+ 'documentId': this.isEditResponse ? did : undefined,
'randomId': 0,
- 'host': App.getBaseUrl(),
+ 'host': this.getBaseUrl(),
'testAccountId': currentAccountId,
- 'response': JSON.stringify(App.isEditResponse ? inputObj : currentResponse),
- 'standard': isML || App.isEditResponse ? JSON.stringify(App.isEditResponse ? commentObj : stddObj) : undefined
+ 'response': JSON.stringify(this.isEditResponse ? inputObj : currentResponse),
+ 'standard': isML || this.isEditResponse ? JSON.stringify(this.isEditResponse ? commentObj : stddObj) : undefined
},
- 'tag': App.isEditResponse ? 'TestRecord' : 'Document'
+ 'tag': this.isEditResponse ? 'TestRecord' : 'Document'
}
- App.request(true, REQUEST_TYPE_JSON, url, req, {}, function (url, res, err) {
+ this.request(true, REQUEST_TYPE_JSON, url, req, {}, function (url, res, err) {
App.onResponse(url, res, err)
var rpObj = res.data || {}
@@ -1817,7 +1817,7 @@
}
}
- config += App.newRandomConfig(childPath, k, v)
+ config += this.newRandomConfig(childPath, k, v)
}
}
else {
@@ -1898,45 +1898,45 @@
// 保存配置
saveConfig: function () {
- App.isConfigShow = App.exTxt.index == 8
+ this.isConfigShow = this.exTxt.index == 8
- switch (App.exTxt.index) {
+ switch (this.exTxt.index) {
case 0:
- App.database = CodeUtil.database = App.exTxt.name
- App.saveCache('', 'database', App.database)
+ this.database = CodeUtil.database = this.exTxt.name
+ this.saveCache('', 'database', this.database)
doc = null
- var item = App.accounts[App.currentAccountIndex]
+ var item = this.accounts[this.currentAccountIndex]
item.isLoggedIn = false
- App.onClickAccount(App.currentAccountIndex, item)
+ this.onClickAccount(this.currentAccountIndex, item)
break
case 1:
- App.schema = CodeUtil.schema = App.exTxt.name
- App.saveCache('', 'schema', App.schema)
+ this.schema = CodeUtil.schema = this.exTxt.name
+ this.saveCache('', 'schema', this.schema)
doc = null
- var item = App.accounts[App.currentAccountIndex]
+ var item = this.accounts[this.currentAccountIndex]
item.isLoggedIn = false
- App.onClickAccount(App.currentAccountIndex, item)
+ this.onClickAccount(this.currentAccountIndex, item)
break
case 2:
- App.language = CodeUtil.language = App.exTxt.name
- App.saveCache('', 'language', App.language)
+ this.language = CodeUtil.language = this.exTxt.name
+ this.saveCache('', 'language', this.language)
doc = null
- App.onChange(false)
+ this.onChange(false)
break
case 6:
- App.server = App.exTxt.name
- App.saveCache('', 'server', App.server)
- App.logout(true)
+ this.server = this.exTxt.name
+ this.saveCache('', 'server', this.server)
+ this.logout(true)
break
case 7:
- App.types = StringUtil.split(App.exTxt.name)
- App.saveCache('', 'types', App.types)
+ this.types = StringUtil.split(this.exTxt.name)
+ this.saveCache('', 'types', this.types)
break
case 8:
- App.getThirdPartyApiList(App.exTxt.name, function (platform, docUrl, listUrl, itemUrl, url_, res, err) {
+ this.getThirdPartyApiList(this.exTxt.name, function (platform, docUrl, listUrl, itemUrl, url_, res, err) {
var jsonData = (res || {}).data
var isJSONData = jsonData instanceof Object
if (isJSONData == false) { //后面是 URL 才存储;是 JSON 数据则不存储
@@ -2076,7 +2076,7 @@
},
getThirdPartyApiList: function (thirdParty, listCallback, itemCallback) {
- App.parseThirdParty(thirdParty, function (platform, jsonData, docUrl, listUrl, itemUrl) {
+ this.parseThirdParty(thirdParty, function (platform, jsonData, docUrl, listUrl, itemUrl) {
var isJSONData = jsonData instanceof Object
const header = App.getHeader(vHeader.value)
@@ -2169,7 +2169,7 @@
}
catch (e) {}
- var host = App.getBaseUrl()
+ var host = this.getBaseUrl()
var listUrl = null
var itemUrl = null
@@ -2209,11 +2209,11 @@
var api = docItem == null ? null : docItem[method]
if (api == null) {
log('postApi', 'api == null >> return')
- App.exTxt.button = 'All:' + App.uploadTotal + '\nDone:' + App.uploadDoneCount + '\nFail:' + App.uploadFailCount
+ this.exTxt.button = 'All:' + this.uploadTotal + '\nDone:' + this.uploadDoneCount + '\nFail:' + this.uploadFailCount
return false
}
- App.uploadTotal ++
+ this.uploadTotal ++
var parameters = api.parameters || []
var parameters2 = []
@@ -2230,7 +2230,7 @@
}
}
- return App.uploadThirdPartyApi(method == 'get' ? REQUEST_TYPE_PARAM : REQUEST_TYPE_JSON
+ return this.uploadThirdPartyApi(method == 'get' ? REQUEST_TYPE_PARAM : REQUEST_TYPE_JSON
, api.summary, url, parameters2, api.headers, api.description)
},
@@ -2242,11 +2242,11 @@
var api = docItem
if (api == null) {
log('postApi', 'api == null >> return')
- App.exTxt.button = 'All:' + App.uploadTotal + '\nDone:' + App.uploadDoneCount + '\nFail:' + App.uploadFailCount
+ this.exTxt.button = 'All:' + this.uploadTotal + '\nDone:' + this.uploadDoneCount + '\nFail:' + this.uploadFailCount
return false
}
- App.uploadTotal ++
+ this.uploadTotal ++
var type
switch ((api.summary || {}).requestParamsType || '') {
@@ -2303,7 +2303,7 @@
}
}
- return App.uploadThirdPartyApi(type, api.name, api.url, parameters2, header, api.description)
+ return this.uploadThirdPartyApi(type, api.name, api.url, parameters2, header, api.description)
},
/**上传 YApi
@@ -2313,11 +2313,11 @@
var api = docItem
if (api == null) {
log('postApi', 'api == null >> return')
- App.exTxt.button = 'All:' + App.uploadTotal + '\nDone:' + App.uploadDoneCount + '\nFail:' + App.uploadFailCount
+ this.exTxt.button = 'All:' + this.uploadTotal + '\nDone:' + this.uploadDoneCount + '\nFail:' + this.uploadFailCount
return false
}
- App.uploadTotal++
+ this.uploadTotal++
var headers = api.req_headers || []
var header = ''
@@ -2331,9 +2331,9 @@
+ (StringUtil.isEmpty(item.description, true) ? '' : ' // ' + item.description)
}
- var typeAndParam = App.parseYApiTypeAndParam(api)
+ var typeAndParam = this.parseYApiTypeAndParam(api)
- return App.uploadThirdPartyApi(
+ return this.uploadThirdPartyApi(
typeAndParam.type, api.title, api.path, typeAndParam.param, header
, (StringUtil.trim(api.username) + ': ' + StringUtil.trim(api.title)
+ '\n' + (api.up_time == null ? '' : (typeof api.up_time != 'number' ? api.up_time : new Date(1000*api.up_time).toLocaleString()))
@@ -2469,8 +2469,8 @@
}
- var currentAccountId = App.getCurrentAccountId()
- App.request(true, REQUEST_TYPE_JSON, App.server + '/post', {
+ var currentAccountId = this.getCurrentAccountId()
+ this.request(true, REQUEST_TYPE_JSON, this.server + '/post', {
format: false,
'Document': {
'creator': creator,
@@ -2483,7 +2483,7 @@
},
'TestRecord': {
'randomId': 0,
- 'host': App.getBaseUrl(),
+ 'host': this.getBaseUrl(),
'testAccountId': currentAccountId,
'response': ''
},
@@ -2523,20 +2523,20 @@
if (date == null) {
date = new Date()
}
- return date.getFullYear() + '-' + App.fillZero(date.getMonth() + 1) + '-' + App.fillZero(date.getDate())
+ return date.getFullYear() + '-' + this.fillZero(date.getMonth() + 1) + '-' + this.fillZero(date.getDate())
},
//格式化时间
formatTime: function (date) {
if (date == null) {
date = new Date()
}
- return App.fillZero(date.getHours()) + ':' + App.fillZero(date.getMinutes())
+ return this.fillZero(date.getHours()) + ':' + this.fillZero(date.getMinutes())
},
formatDateTime: function (date) {
if (date == null) {
date = new Date()
}
- return App.formatDate(date) + ' ' + App.formatTime(date)
+ return this.formatDate(date) + ' ' + this.formatTime(date)
},
//填充0
fillZero: function (num, n) {
@@ -2768,7 +2768,7 @@
var search = isSub ? subSearch : (StringUtil.isEmpty(this.randomSearch, true)
? null : '%' + StringUtil.trim(this.randomSearch) + '%')
- var url = App.server + '/get'
+ var url = this.server + '/get'
var req = {
'[]': {
'count': (isSub ? this.randomSubCount : this.randomCount) || 100,
@@ -2781,8 +2781,8 @@
},
'TestRecord': {
'randomId@': '/Random/id',
- 'testAccountId': App.getCurrentAccountId(),
- 'host': App.getBaseUrl(),
+ 'testAccountId': this.getCurrentAccountId(),
+ 'host': this.getBaseUrl(),
'@order': 'date-'
},
'[]': isSub ? null : {
@@ -2796,8 +2796,8 @@
},
'TestRecord': {
'randomId@': '/Random/id',
- 'testAccountId': App.getCurrentAccountId(),
- 'host': App.getBaseUrl(),
+ 'testAccountId': this.getCurrentAccountId(),
+ 'host': this.getBaseUrl(),
'@order': 'date-'
}
}
@@ -2853,7 +2853,7 @@
try {
cache = JSON.parse(cache)
} catch(e) {
- App.log('login App.send >> try { cache = JSON.parse(cache) } catch(e) {\n' + e.message)
+ this.log('login this.send >> try { cache = JSON.parse(cache) } catch(e) {\n' + e.message)
}
cache = cache || {}
var val = key == null ? cache : cache[key]
@@ -2863,15 +2863,15 @@
/**登录确认
*/
confirm: function () {
- switch (App.loginType) {
+ switch (this.loginType) {
case 'login':
- App.login(App.isAdminOperation)
+ this.login(this.isAdminOperation)
break
case 'register':
- App.register(App.isAdminOperation)
+ this.register(this.isAdminOperation)
break
case 'forget':
- App.resetPassword(App.isAdminOperation)
+ this.resetPassword(this.isAdminOperation)
break
}
},
@@ -2884,7 +2884,7 @@
return
}
- var user = isAdmin ? App.User : null // add account App.accounts[App.currentAccountIndex]
+ var user = isAdmin ? this.User : null // add account this.accounts[this.currentAccountIndex]
// alert("showLogin isAdmin = " + isAdmin + "; user = \n" + JSON.stringify(user, null, ' '))
@@ -2905,34 +2905,34 @@
},
getCurrentAccount: function() {
- return App.accounts == null ? null : App.accounts[App.currentAccountIndex]
+ return this.accounts == null ? null : this.accounts[this.currentAccountIndex]
},
getCurrentAccountId: function() {
- var a = App.getCurrentAccount()
+ var a = this.getCurrentAccount()
return a != null && a.isLoggedIn ? a.id : null
},
/**登录
*/
login: function (isAdminOperation, callback) {
- App.isLoginShow = false
- App.isEditResponse = false
+ this.isLoginShow = false
+ this.isEditResponse = false
const req = {
type: 0, // 登录方式,非必须 0-密码 1-验证码
- phone: App.account,
- password: App.password,
+ phone: this.account,
+ password: this.password,
version: 1, // 全局默认版本号,非必须
remember: vRemember.checked,
format: false,
defaults: {
- '@database': StringUtil.isEmpty(App.database, true) ? undefined : App.database,
- '@schema': StringUtil.isEmpty(App.schema, true) ? undefined : App.schema
+ '@database': StringUtil.isEmpty(this.database, true) ? undefined : this.database,
+ '@schema': StringUtil.isEmpty(this.schema, true) ? undefined : this.schema
}
}
if (isAdminOperation) {
- App.request(isAdminOperation, REQUEST_TYPE_JSON, App.server + '/login', req, {}, function (url, res, err) {
+ this.request(isAdminOperation, REQUEST_TYPE_JSON, this.server + '/login', req, {}, function (url, res, err) {
if (callback) {
callback(url, res, err)
return
@@ -2974,25 +2974,25 @@
else {
if (callback == null) {
var item
- for (var i in App.accounts) {
- item = App.accounts[i]
+ for (var i in this.accounts) {
+ item = this.accounts[i]
if (item != null && req.phone == item.phone) {
alert(req.phone + ' 已在测试账号中!')
- // App.currentAccountIndex = i
+ // this.currentAccountIndex = i
item.remember = vRemember.checked
- App.onClickAccount(i, item)
+ this.onClickAccount(i, item)
return
}
}
}
- App.showUrl(isAdminOperation, '/login')
+ this.showUrl(isAdminOperation, '/login')
vInput.value = JSON.stringify(req, null, ' ')
- App.type = REQUEST_TYPE_JSON
- App.showTestCase(false, App.isLocalShow)
- App.onChange(false)
- App.send(isAdminOperation, function (url, res, err) {
+ this.type = REQUEST_TYPE_JSON
+ this.showTestCase(false, this.isLocalShow)
+ this.onChange(false)
+ this.send(isAdminOperation, function (url, res, err) {
if (callback) {
callback(url, res, err)
return
@@ -3030,12 +3030,12 @@
/**注册
*/
register: function (isAdminOperation) {
- App.showUrl(isAdminOperation, '/register')
+ this.showUrl(isAdminOperation, '/register')
vInput.value = JSON.stringify(
{
Privacy: {
- phone: App.account,
- _password: App.password
+ phone: this.account,
+ _password: this.password
},
User: {
name: 'APIJSONUser'
@@ -3043,9 +3043,9 @@
verify: vVerify.value
},
null, ' ')
- App.showTestCase(false, false)
- App.onChange(false)
- App.send(isAdminOperation, function (url, res, err) {
+ this.showTestCase(false, false)
+ this.onChange(false)
+ this.send(isAdminOperation, function (url, res, err) {
App.onResponse(url, res, err)
var rpObj = res.data
@@ -3064,19 +3064,19 @@
/**重置密码
*/
resetPassword: function (isAdminOperation) {
- App.showUrl(isAdminOperation, '/put/password')
+ this.showUrl(isAdminOperation, '/put/password')
vInput.value = JSON.stringify(
{
verify: vVerify.value,
Privacy: {
- phone: App.account,
- _password: App.password
+ phone: this.account,
+ _password: this.password
}
},
null, ' ')
- App.showTestCase(false, App.isLocalShow)
- App.onChange(false)
- App.send(isAdminOperation, function (url, res, err) {
+ this.showTestCase(false, this.isLocalShow)
+ this.onChange(false)
+ this.send(isAdminOperation, function (url, res, err) {
App.onResponse(url, res, err)
var rpObj = res.data
@@ -3095,17 +3095,17 @@
/**退出
*/
logout: function (isAdminOperation, callback) {
- App.isEditResponse = false
+ this.isEditResponse = false
var req = {}
if (isAdminOperation) {
- // alert('logout isAdminOperation this.saveCache(App.server, User, {})')
- this.saveCache(App.server, 'User', {})
+ // alert('logout isAdminOperation this.saveCache(this.server, User, {})')
+ this.saveCache(this.server, 'User', {})
}
// alert('logout isAdminOperation = ' + isAdminOperation + '; url = ' + url)
if (isAdminOperation) {
- this.request(isAdminOperation, REQUEST_TYPE_JSON, App.server + '/logout', req, {}, function (url, res, err) {
+ this.request(isAdminOperation, REQUEST_TYPE_JSON, this.server + '/logout', req, {}, function (url, res, err) {
if (callback) {
callback(url, res, err)
return
@@ -3119,10 +3119,10 @@
})
}
else {
- App.showUrl(isAdminOperation, '/logout')
+ this.showUrl(isAdminOperation, '/logout')
vInput.value = JSON.stringify(req, null, ' ')
this.type = REQUEST_TYPE_JSON
- this.showTestCase(false, App.isLocalShow)
+ this.showTestCase(false, this.isLocalShow)
this.onChange(false)
this.send(isAdminOperation, callback)
}
@@ -3131,17 +3131,17 @@
/**获取验证码
*/
getVerify: function (isAdminOperation) {
- App.showUrl(isAdminOperation, '/post/verify')
- var type = App.loginType == 'login' ? 0 : (App.loginType == 'register' ? 1 : 2)
+ this.showUrl(isAdminOperation, '/post/verify')
+ var type = this.loginType == 'login' ? 0 : (this.loginType == 'register' ? 1 : 2)
vInput.value = JSON.stringify(
{
type: type,
- phone: App.account
+ phone: this.account
},
null, ' ')
- App.showTestCase(false, App.isLocalShow)
- App.onChange(false)
- App.send(isAdminOperation, function (url, res, err) {
+ this.showTestCase(false, this.isLocalShow)
+ this.onChange(false)
+ this.send(isAdminOperation, function (url, res, err) {
App.onResponse(url, res, err)
var data = res.data || {}
@@ -3154,10 +3154,10 @@
},
clearUser: function () {
- App.User.id = 0
- App.Privacy = {}
- App.remotes = []
- App.saveCache(App.server, 'User', App.User) //应该用lastBaseUrl,baseUrl应随watch输入变化重新获取
+ this.User.id = 0
+ this.Privacy = {}
+ this.remotes = []
+ this.saveCache(this.server, 'User', this.User) //应该用lastBaseUrl,baseUrl应随watch输入变化重新获取
},
/**计时回调
@@ -3196,7 +3196,7 @@
}
catch (e) {
log('main.onHandle', 'try { return jsonlint.parse(before); \n } catch (e) {\n' + e.message)
- log('main.onHandle', 'return jsonlint.parse(App.removeComment(before));')
+ log('main.onHandle', 'return jsonlint.parse(this.removeComment(before));')
try {
afterObj = jsonlint.parse(this.removeComment(before));
@@ -3294,7 +3294,7 @@
var start = raw.lastIndexOf('\n\/*')
var end = raw.lastIndexOf('\n*\/')
markdownToHTML('```js\n' + (StringUtil.isEmpty(ct) ? (start < 0 || end <= start ? raw.substring(0, start) : '') : ct) + '\n```\n'
- // + App.toMD(start < 0 || end <= start ? '' : raw.substring(start + '\n\/*'.length, end) ), true);
+ // + this.toMD(start < 0 || end <= start ? '' : raw.substring(start + '\n\/*'.length, end) ), true);
+ (start < 0 || end <= start ? '' : raw.substring(start + '\n\/*'.length, end) ), true);
} catch (e3) {
log(e3)
@@ -3431,11 +3431,11 @@
},
showAndSend: function (branchUrl, req, isAdminOperation, callback) {
- App.showUrl(isAdminOperation, branchUrl)
+ this.showUrl(isAdminOperation, branchUrl)
vInput.value = JSON.stringify(req, null, ' ')
- App.showTestCase(false, App.isLocalShow)
- App.onChange(false)
- App.send(isAdminOperation, callback)
+ this.showTestCase(false, this.isLocalShow)
+ this.onChange(false)
+ this.send(isAdminOperation, callback)
},
/**发送请求
@@ -3446,14 +3446,14 @@
return
}
- if (StringUtil.isEmpty(App.host, true)) {
+ if (StringUtil.isEmpty(this.host, true)) {
if (StringUtil.get(vUrl.value).startsWith('http://') != true && StringUtil.get(vUrl.value).startsWith('https://') != true) {
alert('URL 缺少 http:// 或 https:// 前缀,可能不完整或不合法,\n可能使用同域的 Host,很可能访问出错!')
}
}
else {
if (StringUtil.get(vUrl.value).indexOf('://') >= 0) {
- alert('URL Host 已经隐藏(固定) 为 \n' + App.host + ' \n将会自动在前面补全,导致 URL 不合法访问出错!\n如果要改 Host,右上角设置 > 显示(编辑)URL Host')
+ alert('URL Host 已经隐藏(固定) 为 \n' + this.host + ' \n将会自动在前面补全,导致 URL 不合法访问出错!\n如果要改 Host,右上角设置 > 显示(编辑)URL Host')
}
}
@@ -3461,8 +3461,8 @@
clearTimeout(handler)
- if (App.isEditResponse) {
- App.onChange(false)
+ if (this.isEditResponse) {
+ this.onChange(false)
return
}
@@ -3489,18 +3489,18 @@
if (this.locals.length >= 1000) { //最多1000条,太多会很卡
this.locals.splice(999, this.locals.length - 999)
}
- var method = App.getMethod()
+ var method = this.getMethod()
this.locals.unshift({
'Document': {
- 'userId': App.User.id,
- 'name': App.formatDateTime() + ' ' + (App.urlComment || StringUtil.trim(req.tag)),
- 'type': App.type,
+ 'userId': this.User.id,
+ 'name': this.formatDateTime() + ' ' + (this.urlComment || StringUtil.trim(req.tag)),
+ 'type': this.type,
'url': '/' + method,
'request': JSON.stringify(req, null, ' '),
'header': vHeader.value
}
})
- App.saveCache('', 'locals', this.locals)
+ this.saveCache('', 'locals', this.locals)
},
//请求
@@ -3585,18 +3585,18 @@
if (isSingle && data.code == CODE_SUCCESS) { //不格式化错误的结果
data = JSONResponse.formatObject(data);
}
- App.jsoncon = JSON.stringify(data, null, ' ');
- App.view = 'code';
+ this.jsoncon = JSON.stringify(data, null, ' ');
+ this.view = 'code';
vOutput.value = '';
// 会导致断言用了这个
- // if (App.currentRemoteItem == null) {
- // App.currentRemoteItem = {}
+ // if (this.currentRemoteItem == null) {
+ // this.currentRemoteItem = {}
// }
- // if (App.currentRemoteItem.TestRecord == null) {
- // App.currentRemoteItem.TestRecord = {}
+ // if (this.currentRemoteItem.TestRecord == null) {
+ // this.currentRemoteItem.TestRecord = {}
// }
- // App.currentRemoteItem.TestRecord.response = data
+ // this.currentRemoteItem.TestRecord.response = data
}
},
@@ -3610,8 +3610,8 @@
var obj = event.srcElement ? event.srcElement : event.target;
if ($(obj).attr('id') == 'vUrl') {
vUrlComment.value = ''
- App.currentDocItem = null
- App.currentRemoteItem = null
+ this.currentDocItem = null
+ this.currentRemoteItem = null
}
if (keyCode == 13) { // enter
@@ -3788,20 +3788,20 @@
*/
getCode: function (rq) {
var s = '\n\n\n### 请求代码(自动生成) \n';
- switch (App.language) {
+ switch (this.language) {
case CodeUtil.LANGUAGE_KOTLIN:
s += '\n#### <= Android-Kotlin: 空对象用 HashMap<String, Any>(),空数组用 ArrayList<Any>()\n'
+ '```kotlin \n'
- + CodeUtil.parseKotlinRequest(null, JSON.parse(rq), 0, isSingle, false, false, App.type, App.getBaseUrl(), '/' + App.getMethod(), App.urlComment)
+ + CodeUtil.parseKotlinRequest(null, JSON.parse(rq), 0, isSingle, false, false, this.type, this.getBaseUrl(), '/' + this.getMethod(), this.urlComment)
+ '\n ``` \n注:对象 {} 用 mapOf("key": value),数组 [] 用 listOf(value0, value1)\n';
break;
case CodeUtil.LANGUAGE_JAVA:
s += '\n#### <= Android-Java: 同名变量需要重命名'
+ ' \n ```java \n'
- + StringUtil.trim(CodeUtil.parseJavaRequest(null, JSON.parse(rq), 0, isSingle, false, false, App.type, '/' + App.getMethod(), App.urlComment))
+ + StringUtil.trim(CodeUtil.parseJavaRequest(null, JSON.parse(rq), 0, isSingle, false, false, this.type, '/' + this.getMethod(), this.urlComment))
+ '\n ``` \n注:' + (isSingle ? '用了 APIJSON 的 JSONRequest, JSONResponse 类,也可使用其它类封装,只要 JSON 有序就行\n' : 'LinkedHashMap<>() 可替换为 fastjson 的 JSONObject(true) 等有序JSON构造方法\n');
- var serverCode = CodeUtil.parseJavaServer(App.type, '/' + App.getMethod(), App.database, App.schema, JSON.parse(rq), isSingle);
+ var serverCode = CodeUtil.parseJavaServer(this.type, '/' + this.getMethod(), this.database, this.schema, JSON.parse(rq), isSingle);
if (StringUtil.isEmpty(serverCode, true) != true) {
s += '\n#### <= Server-Java: RESTful 等非 APIJSON 规范的 API'
+ ' \n ```java \n'
@@ -3866,7 +3866,7 @@
break;
}
- if (((App.User || {}).id || 0) > 0) {
+ if (((this.User || {}).id || 0) > 0) {
s += '\n\n#### 开放源码 '
+ '\nAPIJSON 接口测试: https://github.com/TommyLemon/APIAuto '
+ '\nAPIJSON 单元测试: https://github.com/TommyLemon/UnitAuto '
@@ -3960,7 +3960,7 @@
},
'PgClass': this.database != 'POSTGRESQL' ? null : {
'relname@': '/Table/table_name',
- //FIXME 多个 schema 有同名表时数据总是取前面的 不属于 pg_class 表 'nspname': App.schema,
+ //FIXME 多个 schema 有同名表时数据总是取前面的 不属于 pg_class 表 'nspname': this.schema,
'@column': 'oid;obj_description(oid):table_comment'
},
'SysTable': this.database != 'SQLSERVER' ? null : {
@@ -4374,11 +4374,11 @@
},
log: function (msg) {
- // App.log('Main. ' + msg)
+ // this.log('Main. ' + msg)
},
getDoc4TestCase: function () {
- var list = App.remotes || []
+ var list = this.remotes || []
var doc = ''
var item
for (var i = 0; i < list.length; i ++) {
@@ -4395,13 +4395,13 @@
enableCross: function (enable) {
this.isCrossEnabled = enable
this.crossProcess = enable ? '交叉账号:已开启' : '交叉账号:已关闭'
- this.saveCache(App.server, 'isCrossEnabled', enable)
+ this.saveCache(this.server, 'isCrossEnabled', enable)
},
enableML: function (enable) {
this.isMLEnabled = enable
this.testProcess = enable ? '机器学习:已开启' : '机器学习:已关闭'
- this.saveCache(App.server, 'isMLEnabled', enable)
+ this.saveCache(this.server, 'isMLEnabled', enable)
this.remotes = null
this.showTestCase(true, false)
},
@@ -4578,7 +4578,7 @@
resetCount: function (randomItem) {
if (randomItem == null) {
- App.log('resetCount randomItem == null >> return')
+ this.log('resetCount randomItem == null >> return')
return
}
randomItem.totalCount = 0
@@ -4613,8 +4613,8 @@
log(e)
vSend.disabled = true
- App.view = 'error'
- App.error = {
+ this.view = 'error'
+ this.error = {
msg: e.message
}
@@ -4975,7 +4975,7 @@
}
}
- var baseUrl = StringUtil.trim(App.getBaseUrl())
+ var baseUrl = StringUtil.trim(this.getBaseUrl())
if (baseUrl == '') {
alert('请先输入有效的URL!')
return
@@ -4990,7 +4990,7 @@
// return
// }
- const list = App.remotes || []
+ const list = this.remotes || []
const allCount = list.length
doneCount = 0
@@ -5015,7 +5015,7 @@
})
}
else {
- App.startTest(list, allCount, isRandom, accountIndex)
+ this.startTest(list, allCount, isRandom, accountIndex)
}
},
@@ -5030,22 +5030,22 @@
continue
}
if (document.url == '/login' || document.url == '/logout') { //login会导致登录用户改变为默认的但UI上还显示原来的,单独测试OWNER权限时能通过很困惑
- App.log('test document.url == "/login" || document.url == "/logout" >> continue')
+ this.log('test document.url == "/login" || document.url == "/logout" >> continue')
doneCount++
continue
}
- App.log('test document = ' + JSON.stringify(document, null, ' '))
+ this.log('test document = ' + JSON.stringify(document, null, ' '))
const index = i
var header = null
try {
- header = App.getHeader(document.header)
+ header = this.getHeader(document.header)
} catch (e) {
- App.log('test for ' + i + ' >> try { header = App.getHeader(document.header) } catch (e) { \n' + e.message)
+ this.log('test for ' + i + ' >> try { header = this.getHeader(document.header) } catch (e) { \n' + e.message)
}
- App.request(false, document.type, baseUrl + document.url, App.getRequest(document.request), header, function (url, res, err) {
+ this.request(false, document.type, baseUrl + document.url, this.getRequest(document.request), header, function (url, res, err) {
try {
App.onResponse(url, res, err)
@@ -5062,7 +5062,7 @@
compareResponse: function (allCount, list, index, item, response, isRandom, accountIndex, justRecoverTest, err) {
var it = item || {} //请求异步
- var d = (isRandom ? App.currentRemoteItem.Document : it.Document) || {} //请求异步
+ var d = (isRandom ? this.currentRemoteItem.Document : it.Document) || {} //请求异步
var r = isRandom ? it.Random : null //请求异步
var tr = it.TestRecord || {} //请求异步
@@ -5096,13 +5096,13 @@
}
}
else {
- var standardKey = App.isMLEnabled != true ? 'response' : 'standard'
+ var standardKey = this.isMLEnabled != true ? 'response' : 'standard'
var standard = StringUtil.isEmpty(tr[standardKey], true) ? null : JSON.parse(tr[standardKey])
- tr.compare = JSONResponse.compareResponse(standard, App.removeDebugInfo(response) || {}, '', App.isMLEnabled) || {}
+ tr.compare = JSONResponse.compareResponse(standard, this.removeDebugInfo(response) || {}, '', this.isMLEnabled) || {}
tr.compare.duration = it.durationHint
}
- App.onTestResponse(allCount, list, index, it, d, r, tr, response, tr.compare || {}, isRandom, accountIndex, justRecoverTest);
+ this.onTestResponse(allCount, list, index, it, d, r, tr, response, tr.compare || {}, isRandom, accountIndex, justRecoverTest);
},
onTestResponse: function(allCount, list, index, it, d, r, tr, response, cmp, isRandom, accountIndex, justRecoverTest) {
@@ -5198,9 +5198,9 @@
var toId = random == null ? null : random.toId
if (toId != null && toId > 0) {
- for (var i in App.randoms) {
+ for (var i in this.randoms) {
- var toIt = App.randoms[i]
+ var toIt = this.randoms[i]
if (toIt != null && toIt.Random != null && toIt.Random.id == toId) {
var toRandom = toIt.Random
@@ -5225,7 +5225,7 @@
}
}
- Vue.set(App.randoms, i, toIt)
+ Vue.set(this.randoms, i, toIt)
break;
}
@@ -5255,7 +5255,7 @@
item = item || {}
var document;
if (isRandom) {
- document = App.currentRemoteItem || {}
+ document = this.currentRemoteItem || {}
}
else {
document = item.Document = item.Document || {}
@@ -5510,8 +5510,8 @@
},
TestRecord: isDuration ? Object.assign(testRecord, {
id: undefined,
- host: App.getBaseUrl(),
- testAccountId: App.getCurrentAccountId(),
+ host: this.getBaseUrl(),
+ testAccountId: this.getCurrentAccountId(),
duration: item.duration,
minDuration: minDuration,
maxDuration: maxDuration,
@@ -5519,8 +5519,8 @@
}) : {
documentId: isNewRandom ? null : (isRandom ? random.documentId : document.id),
randomId: isRandom && ! isNewRandom ? random.id : null,
- host: App.getBaseUrl(),
- testAccountId: App.getCurrentAccountId(),
+ host: this.getBaseUrl(),
+ testAccountId: this.getCurrentAccountId(),
compare: JSON.stringify(testRecord.compare || {}),
response: JSON.stringify(currentResponse || {}),
standard: isML ? JSON.stringify(stddObj) : null
@@ -5529,7 +5529,7 @@
}
// }
// else {
- // url = App.server + '/post/testrecord/ml'
+ // url = this.server + '/post/testrecord/ml'
// req = {
// documentId: document.id
// }
@@ -5611,11 +5611,11 @@
TestRecord: {
documentId: isRandom ? doc.documentId : doc.id,
randomId: isRandom ? doc.id : null,
- testAccountId: App.getCurrentAccountId(),
- 'host': App.getBaseUrl(),
+ testAccountId: this.getCurrentAccountId(),
+ 'host': this.getBaseUrl(),
'@order': 'date-',
- '@column': 'id,userId,testAccountId,documentId,randomId,duration,minDuration,maxDuration,response' + (App.isMLEnabled ? ',standard' : ''),
- '@having': App.isMLEnabled ? 'length(standard)>2' : null // '@having': App.isMLEnabled ? 'json_length(standard)>0' : null
+ '@column': 'id,userId,testAccountId,documentId,randomId,duration,minDuration,maxDuration,response' + (this.isMLEnabled ? ',standard' : ''),
+ '@having': this.isMLEnabled ? 'length(standard)>2' : null // '@having': this.isMLEnabled ? 'json_length(standard)>0' : null
}
}, {}, function (url, res, err) {
App.onResponse(url, res, err)
@@ -5660,7 +5660,7 @@
},
watch: {
jsoncon: function () {
- App.showJsonView()
+ this.showJsonView()
}
},
computed: {
@@ -5762,7 +5762,7 @@
this.transfer()
if (this.User != null && this.User.id != null && this.User.id > 0) {
- this.showTestCase(true, false) // 本地历史仍然要求登录 App.User == null || App.User.id == null)
+ this.showTestCase(true, false) // 本地历史仍然要求登录 this.User == null || this.User.id == null)
}
}
else {
@@ -5801,6 +5801,8 @@
App.isRandomListShow = false
}
+ var delayTime = 0
+
// URL 太长导致截断和乱码
if (StringUtil.isEmpty(rawReq.setting, true) == false) {
var save = rawReq.save == 'true'
From e08ab9bd6c3d51d250bbd5e1beaed6593dadbf3d Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Thu, 7 Oct 2021 04:38:26 +0800
Subject: [PATCH 504/818] =?UTF-8?q?=E5=88=86=E4=BA=AB=EF=BC=9A=E4=BC=98?=
=?UTF-8?q?=E5=8C=96=E8=87=AA=E5=8A=A8=E6=89=A7=E8=A1=8C=E5=9B=9E=E5=BD=92?=
=?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=89=8D=E7=9A=84=E7=AD=89=E5=BE=85=E6=97=B6?=
=?UTF-8?q?=E9=97=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/js/main.js b/js/main.js
index a867156..fae8d8e 100755
--- a/js/main.js
+++ b/js/main.js
@@ -5832,12 +5832,12 @@
}
if (setting.isRandomShow && setting.isRandomListShow) {
- delayTime += Math.min(5000, 20*(setting.randomCount || App.randomCount) + 1000)
+ delayTime += Math.min(5000, (App.isMLEnabled ? 60 : 20)*(setting.randomCount || App.randomCount) + 1000)
App.showRandomList(true, setting.isRandomSubListShow ? App.currentRandomItem : null, setting.isRandomSubListShow)
}
if (setting.isTestCaseShow) {
- delayTime += Math.min(5000, 10*(setting.testCaseCount || App.testCaseCount) + 1000)
+ delayTime += Math.min(5000, (App.isMLEnabled ? 30 : 10)*(setting.testCaseCount || App.testCaseCount) + 1000)
App.showTestCase(true, setting.isLocalShow)
}
} catch (e) {
From 211f1d1927dd407c48939e1d6f49ef624d3f0e96 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Mon, 11 Oct 2021 21:11:34 +0800
Subject: [PATCH 505/818] =?UTF-8?q?=E9=80=9A=E8=BF=87=20APIJSON=20?=
=?UTF-8?q?=E4=BB=A3=E7=90=86=E6=8E=A5=E5=8F=A3=E8=A7=A3=E5=86=B3=E6=9C=89?=
=?UTF-8?q?=E6=97=B6=E5=8F=91=E9=80=81=E4=B8=8D=E4=BA=86=20Cookie=20?=
=?UTF-8?q?=E5=AF=BC=E8=87=B4=E7=99=BB=E5=BD=95=E9=89=B4=E6=9D=83=E5=A4=B1?=
=?UTF-8?q?=E8=B4=A5=E7=AD=89=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/js/main.js b/js/main.js
index fae8d8e..f81291a 100755
--- a/js/main.js
+++ b/js/main.js
@@ -3507,8 +3507,10 @@
request: function (isAdminOperation, type, url, req, header, callback) {
type = type || REQUEST_TYPE_JSON
+ var isDelegateEnabled = this.isDelegateEnabled
+
if (header != null && header.Cookie != null) {
- if (this.isDelegateEnabled) {
+ if (isDelegateEnabled) {
header['Set-Cookie'] = header.Cookie
delete header.Cookie
}
@@ -3517,10 +3519,18 @@
}
}
+ if (isDelegateEnabled && this.delegateId != null && (header == null || header['APIJSON-DELEGATE-ID'] == null)) {
+ if (header == null) {
+ header = {};
+ }
+ header['APIJSON-DELEGATE-ID'] = this.delegateId
+ }
+
// axios.defaults.withcredentials = true
axios({
method: (type == REQUEST_TYPE_PARAM ? 'get' : 'post'),
- url: (isAdminOperation == false && this.isDelegateEnabled ? (this.server + '/delegate?' + (type == REQUEST_TYPE_GRPC ? '$_type=GRPC&' : '') + '$_delegate_url=') : '' )
+ url: (isAdminOperation == false && isDelegateEnabled ? (this.server + '/delegate?' + (type == REQUEST_TYPE_GRPC ? '$_type=GRPC&' : '')
+ + (StringUtil.isEmpty(this.delegateId, true) ? '' : '$_delegate_id=' + this.delegateId + '&') + '$_delegate_url=') : '' )
+ (this.isEncodeEnabled ? encodeURI(StringUtil.noBlank(url)) : StringUtil.noBlank(url)),
params: (type == REQUEST_TYPE_PARAM || type == REQUEST_TYPE_FORM ? req : null),
data: (type == REQUEST_TYPE_JSON || type == REQUEST_TYPE_GRPC ? req : (type == REQUEST_TYPE_DATA ? toFormData(req) : null)),
@@ -3530,6 +3540,16 @@
})
.then(function (res) {
res = res || {}
+
+ if (isDelegateEnabled) {
+ var hs = res.headers || {}
+ var delegateId = hs['APIJSON-DELEGATE-ID'] || hs['apijson-delegate-id']
+ if (delegateId != null && delegateId != App.delegateId) {
+ App.delegateId = delegateId;
+ App.saveCache(App.server, 'delegateId', delegateId)
+ }
+ }
+
//any one of then callback throw error will cause it calls then(null)
// if ((res.config || {}).method == 'options') {
// return
@@ -5745,6 +5765,7 @@
this.randomCount = this.getCache(this.server, 'randomCount', this.randomCount)
this.randomSubPage = this.getCache(this.server, 'randomSubPage', this.randomSubPage)
this.randomSubCount = this.getCache(this.server, 'randomSubCount', this.randomSubCount)
+ this.delegateId = this.getCache(this.server, 'delegateId', this.delegateId)
CodeUtil.thirdPartyApiMap = this.getCache(this.thirdParty, 'thirdPartyApiMap')
} catch (e) {
From 2d7f537a6ee1fe62ba2f88a675277dcd1238dc43 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Mon, 11 Oct 2021 22:41:17 +0800
Subject: [PATCH 506/818] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=90=86?=
=?UTF-8?q?=E8=BD=AC=E4=B9=89=EF=BC=9B=E6=8A=8A=20apijson.cn=20=E5=8A=A0?=
=?UTF-8?q?=E5=85=A5=E4=BB=A3=E7=90=86=E5=90=8D=E5=8D=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/js/main.js b/js/main.js
index f81291a..5673494 100755
--- a/js/main.js
+++ b/js/main.js
@@ -3507,7 +3507,7 @@
request: function (isAdminOperation, type, url, req, header, callback) {
type = type || REQUEST_TYPE_JSON
- var isDelegateEnabled = this.isDelegateEnabled
+ var isDelegateEnabled = this.isDelegateEnabled || (url != null && url.indexOf('://apijson.cn') > 0)
if (header != null && header.Cookie != null) {
if (isDelegateEnabled) {
@@ -3531,7 +3531,7 @@
method: (type == REQUEST_TYPE_PARAM ? 'get' : 'post'),
url: (isAdminOperation == false && isDelegateEnabled ? (this.server + '/delegate?' + (type == REQUEST_TYPE_GRPC ? '$_type=GRPC&' : '')
+ (StringUtil.isEmpty(this.delegateId, true) ? '' : '$_delegate_id=' + this.delegateId + '&') + '$_delegate_url=') : '' )
- + (this.isEncodeEnabled ? encodeURI(StringUtil.noBlank(url)) : StringUtil.noBlank(url)),
+ + (isDelegateEnabled || this.isEncodeEnabled ? encodeURIComponent(StringUtil.noBlank(url)) : StringUtil.noBlank(url)),
params: (type == REQUEST_TYPE_PARAM || type == REQUEST_TYPE_FORM ? req : null),
data: (type == REQUEST_TYPE_JSON || type == REQUEST_TYPE_GRPC ? req : (type == REQUEST_TYPE_DATA ? toFormData(req) : null)),
headers: header, //Accept-Encoding(HTTP Header 大小写不敏感,SpringBoot 接收后自动转小写)可能导致 Response 乱码
From d68bcc4be95a16c2452621ad28b19a0830e717a7 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Tue, 12 Oct 2021 00:30:47 +0800
Subject: [PATCH 507/818] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=AE=80=E4=BB=8B?=
=?UTF-8?q?=E5=8F=8A=E6=90=9C=E7=B4=A2=E5=85=B3=E9=94=AE=E8=AF=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
index.html | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/index.html b/index.html
index 72bcb61..892f0d7 100755
--- a/index.html
+++ b/index.html
@@ -1,10 +1,10 @@
- APIAuto-机器学习测试、自动生成代码、自动静态检查、自动生成文档与注释等,做最先进的 HTTP 接口管理平台。
+ APIAuto-机器学习零代码测试、生成代码与静态检查、生成文档与光标悬浮注释
-
-
+
+
From e42e963dadf198cac3c3de1383c626bfa8368284 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Tue, 12 Oct 2021 00:53:09 +0800
Subject: [PATCH 508/818] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=9F=90=E4=BA=9B?=
=?UTF-8?q?=E6=83=85=E5=86=B5=E4=B8=8B=E9=94=99=E8=AF=AF=E5=9C=B0=E8=BD=AC?=
=?UTF-8?q?=E4=B9=89=20URL?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/js/main.js b/js/main.js
index 5673494..b39b374 100755
--- a/js/main.js
+++ b/js/main.js
@@ -3531,7 +3531,7 @@
method: (type == REQUEST_TYPE_PARAM ? 'get' : 'post'),
url: (isAdminOperation == false && isDelegateEnabled ? (this.server + '/delegate?' + (type == REQUEST_TYPE_GRPC ? '$_type=GRPC&' : '')
+ (StringUtil.isEmpty(this.delegateId, true) ? '' : '$_delegate_id=' + this.delegateId + '&') + '$_delegate_url=') : '' )
- + (isDelegateEnabled || this.isEncodeEnabled ? encodeURIComponent(StringUtil.noBlank(url)) : StringUtil.noBlank(url)),
+ + ((isAdminOperation == false && isDelegateEnabled) || this.isEncodeEnabled ? encodeURIComponent(StringUtil.noBlank(url)) : StringUtil.noBlank(url)),
params: (type == REQUEST_TYPE_PARAM || type == REQUEST_TYPE_FORM ? req : null),
data: (type == REQUEST_TYPE_JSON || type == REQUEST_TYPE_GRPC ? req : (type == REQUEST_TYPE_DATA ? toFormData(req) : null)),
headers: header, //Accept-Encoding(HTTP Header 大小写不敏感,SpringBoot 接收后自动转小写)可能导致 Response 乱码
From a6db519dc13350416053f9c8d3f168f5ca1cf281 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Tue, 12 Oct 2021 01:09:40 +0800
Subject: [PATCH 509/818] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E8=BD=AC=E4=B9=89?=
=?UTF-8?q?=E6=A8=A1=E5=BC=8F=E4=B8=8B=E9=94=99=E8=AF=AF=E5=9C=B0=E8=BD=AC?=
=?UTF-8?q?=E4=B9=89=20URL?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/js/main.js b/js/main.js
index b39b374..0446967 100755
--- a/js/main.js
+++ b/js/main.js
@@ -3506,8 +3506,9 @@
//请求
request: function (isAdminOperation, type, url, req, header, callback) {
type = type || REQUEST_TYPE_JSON
+ url = StringUtil.noBlank(url)
- var isDelegateEnabled = this.isDelegateEnabled || (url != null && url.indexOf('://apijson.cn') > 0)
+ var isDelegateEnabled = this.isDelegateEnabled || url.indexOf('://apijson.cn') > 0
if (header != null && header.Cookie != null) {
if (isDelegateEnabled) {
@@ -3529,9 +3530,14 @@
// axios.defaults.withcredentials = true
axios({
method: (type == REQUEST_TYPE_PARAM ? 'get' : 'post'),
- url: (isAdminOperation == false && isDelegateEnabled ? (this.server + '/delegate?' + (type == REQUEST_TYPE_GRPC ? '$_type=GRPC&' : '')
- + (StringUtil.isEmpty(this.delegateId, true) ? '' : '$_delegate_id=' + this.delegateId + '&') + '$_delegate_url=') : '' )
- + ((isAdminOperation == false && isDelegateEnabled) || this.isEncodeEnabled ? encodeURIComponent(StringUtil.noBlank(url)) : StringUtil.noBlank(url)),
+ url: (isAdminOperation == false && isDelegateEnabled
+ ? (
+ this.server + '/delegate?' + (type == REQUEST_TYPE_GRPC ? '$_type=GRPC&' : '')
+ + (StringUtil.isEmpty(this.delegateId, true) ? '' : '$_delegate_id=' + this.delegateId + '&') + '$_delegate_url=' + encodeURIComponent(url)
+ ) : (
+ this.isEncodeEnabled ? encodeURI(url) : url
+ )
+ ),
params: (type == REQUEST_TYPE_PARAM || type == REQUEST_TYPE_FORM ? req : null),
data: (type == REQUEST_TYPE_JSON || type == REQUEST_TYPE_GRPC ? req : (type == REQUEST_TYPE_DATA ? toFormData(req) : null)),
headers: header, //Accept-Encoding(HTTP Header 大小写不敏感,SpringBoot 接收后自动转小写)可能导致 Response 乱码
From f3e4760d4b73efaa091a72205d7ce22e58434d57 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Tue, 12 Oct 2021 01:26:48 +0800
Subject: [PATCH 510/818] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9C=8D=E5=8A=A1?=
=?UTF-8?q?=E5=99=A8=E4=BB=A3=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/js/main.js b/js/main.js
index 0446967..111d6f6 100755
--- a/js/main.js
+++ b/js/main.js
@@ -3508,10 +3508,10 @@
type = type || REQUEST_TYPE_JSON
url = StringUtil.noBlank(url)
- var isDelegateEnabled = this.isDelegateEnabled || url.indexOf('://apijson.cn') > 0
+ var isDelegate = (isAdminOperation == false && this.isDelegateEnabled) || (isAdminOperation && url.indexOf('://apijson.cn') > 0)
if (header != null && header.Cookie != null) {
- if (isDelegateEnabled) {
+ if (isDelegate) {
header['Set-Cookie'] = header.Cookie
delete header.Cookie
}
@@ -3520,7 +3520,7 @@
}
}
- if (isDelegateEnabled && this.delegateId != null && (header == null || header['APIJSON-DELEGATE-ID'] == null)) {
+ if (isDelegate && this.delegateId != null && (header == null || header['APIJSON-DELEGATE-ID'] == null)) {
if (header == null) {
header = {};
}
@@ -3530,7 +3530,7 @@
// axios.defaults.withcredentials = true
axios({
method: (type == REQUEST_TYPE_PARAM ? 'get' : 'post'),
- url: (isAdminOperation == false && isDelegateEnabled
+ url: (isDelegate
? (
this.server + '/delegate?' + (type == REQUEST_TYPE_GRPC ? '$_type=GRPC&' : '')
+ (StringUtil.isEmpty(this.delegateId, true) ? '' : '$_delegate_id=' + this.delegateId + '&') + '$_delegate_url=' + encodeURIComponent(url)
@@ -3547,7 +3547,7 @@
.then(function (res) {
res = res || {}
- if (isDelegateEnabled) {
+ if (isDelegate) {
var hs = res.headers || {}
var delegateId = hs['APIJSON-DELEGATE-ID'] || hs['apijson-delegate-id']
if (delegateId != null && delegateId != App.delegateId) {
From bf69e89b13c0f3c0c2a0b2469d400f4f00e736a8 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Tue, 12 Oct 2021 02:35:03 +0800
Subject: [PATCH 511/818] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BB=A3=E7=90=86?=
=?UTF-8?q?=E7=9B=B8=E5=85=B3=E7=9A=84=E8=AF=B7=E6=B1=82=E5=A4=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/js/main.js b/js/main.js
index 111d6f6..7b91d75 100755
--- a/js/main.js
+++ b/js/main.js
@@ -3520,11 +3520,11 @@
}
}
- if (isDelegate && this.delegateId != null && (header == null || header['APIJSON-DELEGATE-ID'] == null)) {
+ if (isDelegate && this.delegateId != null && (header == null || header['Apijson-Delegate-Id'] == null)) {
if (header == null) {
header = {};
}
- header['APIJSON-DELEGATE-ID'] = this.delegateId
+ header['Apijson-Delegate-Id'] = this.delegateId
}
// axios.defaults.withcredentials = true
@@ -3549,7 +3549,7 @@
if (isDelegate) {
var hs = res.headers || {}
- var delegateId = hs['APIJSON-DELEGATE-ID'] || hs['apijson-delegate-id']
+ var delegateId = hs['Apijson-Delegate-Id'] || hs['apijson-delegate-id']
if (delegateId != null && delegateId != App.delegateId) {
App.delegateId = delegateId;
App.saveCache(App.server, 'delegateId', delegateId)
From 708b11e77cf08c3da3b3bebf5dc4a9b85313920a Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Tue, 12 Oct 2021 03:53:08 +0800
Subject: [PATCH 512/818] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=90=86=20?=
=?UTF-8?q?id=20=E5=A4=B1=E6=95=88=E7=9A=84=E5=A4=84=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
js/main.js | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/js/main.js b/js/main.js
index 7b91d75..3dae061 100755
--- a/js/main.js
+++ b/js/main.js
@@ -3100,6 +3100,9 @@
if (isAdminOperation) {
// alert('logout isAdminOperation this.saveCache(this.server, User, {})')
+ this.delegateId = null
+ this.saveCache(this.server, 'delegateId', null)
+
this.saveCache(this.server, 'User', {})
}
@@ -3157,7 +3160,9 @@
this.User.id = 0
this.Privacy = {}
this.remotes = []
+ // 导致刚登录成功就马上退出 this.delegateId = null
this.saveCache(this.server, 'User', this.User) //应该用lastBaseUrl,baseUrl应随watch输入变化重新获取
+ // this.saveCache(this.server, 'delegateId', this.delegateId) //应该用lastBaseUrl,baseUrl应随watch输入变化重新获取
},
/**计时回调
@@ -3508,7 +3513,7 @@
type = type || REQUEST_TYPE_JSON
url = StringUtil.noBlank(url)
- var isDelegate = (isAdminOperation == false && this.isDelegateEnabled) || (isAdminOperation && url.indexOf('://apijson.cn') > 0)
+ var isDelegate = (isAdminOperation == false && this.isDelegateEnabled) || (isAdminOperation && url.indexOf('://apijson.cn:9090') > 0)
if (header != null && header.Cookie != null) {
if (isDelegate) {
@@ -3551,7 +3556,7 @@
var hs = res.headers || {}
var delegateId = hs['Apijson-Delegate-Id'] || hs['apijson-delegate-id']
if (delegateId != null && delegateId != App.delegateId) {
- App.delegateId = delegateId;
+ App.delegateId = delegateId
App.saveCache(App.server, 'delegateId', delegateId)
}
}
@@ -3587,6 +3592,10 @@
})
.catch(function (err) {
log('send >> error:\n' + err)
+ if (isAdminOperation) {
+ App.delegateId = null
+ }
+
if (callback != null) {
callback(url, {}, err)
return
From 3bd4dcb41cc37eaef9373aecf978aaef3036ecf1 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Wed, 20 Oct 2021 00:35:10 +0800
Subject: [PATCH 513/818] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=B8=85=E7=A9=BA?=
=?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=8F=82=E6=95=B0=E8=BE=93=E5=85=A5=E6=A1=86?=
=?UTF-8?q?=E6=9F=A5=E7=9C=8B=E5=8F=82=E6=95=B0=E7=BC=96=E5=86=99=E8=A7=84?=
=?UTF-8?q?=E5=88=99?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
index.html | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
js/main.js | 63 +++++++++++++++++++++++++++-------------------
2 files changed, 108 insertions(+), 28 deletions(-)
diff --git a/index.html b/index.html
index 892f0d7..ed477bf 100755
--- a/index.html
+++ b/index.html
@@ -159,7 +159,7 @@
-
+
搜索
@@ -193,7 +193,68 @@
-
diff --git a/js/main.js b/js/main.js
index 3dae061..12696e5 100755
--- a/js/main.js
+++ b/js/main.js
@@ -3189,30 +3189,37 @@
throw new Error(e2.message)
}
- before = this.toDoubleJSON(StringUtil.trim(before));
- log('onHandle before = \n' + before);
+ before = StringUtil.trim(before);
var afterObj;
var after;
- try {
- afterObj = jsonlint.parse(before);
- after = JSON.stringify(afterObj, null, " ");
- before = after;
- }
- catch (e) {
- log('main.onHandle', 'try { return jsonlint.parse(before); \n } catch (e) {\n' + e.message)
- log('main.onHandle', 'return jsonlint.parse(this.removeComment(before));')
+ var code = '';
+
+ if (StringUtil.isEmpty(before)) {
+ afterObj = {};
+ after = '';
+ } else {
+ before = this.toDoubleJSON(StringUtil.trim(before));
+ log('onHandle before = \n' + before);
try {
- afterObj = jsonlint.parse(this.removeComment(before));
+ afterObj = jsonlint.parse(before);
after = JSON.stringify(afterObj, null, " ");
- } catch (e2) {
- throw new Error('请求 JSON 格式错误!请检查并编辑请求!\n\n如果JSON中有注释,请 手动删除 或 点击左边的 \'/" 按钮 来去掉。\n\n' + e2.message)
+ before = after;
+ }
+ catch (e) {
+ log('main.onHandle', 'try { return jsonlint.parse(before); \n } catch (e) {\n' + e.message)
+ log('main.onHandle', 'return jsonlint.parse(this.removeComment(before));')
+
+ try {
+ afterObj = jsonlint.parse(this.removeComment(before));
+ after = JSON.stringify(afterObj, null, " ");
+ } catch (e2) {
+ throw new Error('请求 JSON 格式错误!请检查并编辑请求!\n\n如果JSON中有注释,请 手动删除 或 点击左边的 \'/" 按钮 来去掉。\n\n' + e2.message)
+ }
}
- }
//关键词let在IE和Safari上不兼容
- var code = '';
if (this.isEditResponse != true) {
try {
code = this.getCode(after); //必须在before还是用 " 时使用,后面用会因为解析 ' 导致失败
@@ -3222,20 +3229,22 @@
}
}
- if (isSingle) {
- if (before.indexOf('"') >= 0) {
- before = before.replace(/"/g, "'");
+ if (isSingle) {
+ if (before.indexOf('"') >= 0) {
+ before = before.replace(/"/g, "'");
+ }
}
- }
- else {
- if (before.indexOf("'") >= 0) {
- before = before.replace(/'/g, '"');
+ else {
+ if (before.indexOf("'") >= 0) {
+ before = before.replace(/'/g, '"');
+ }
}
+
+ vInput.value = before
+ + '\n\n\n '
+ + ' \n'; //解决遮挡
}
- vInput.value = StringUtil.trim(before)
- + '\n '
- + ' \n'; //解决遮挡
vSend.disabled = false;
if (this.isEditResponse != true) {
@@ -5798,7 +5807,9 @@
this.transfer()
if (this.User != null && this.User.id != null && this.User.id > 0) {
- this.showTestCase(true, false) // 本地历史仍然要求登录 this.User == null || this.User.id == null)
+ setTimeout(function () {
+ App.showTestCase(true, false) // 本地历史仍然要求登录 this.User == null || this.User.id == null)
+ }, 1000)
}
}
else {
From 1e63705ce8fa6ff645d5d3cc1246d756aa57a778 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Wed, 20 Oct 2021 00:57:59 +0800
Subject: [PATCH 514/818] =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=A4=B4=20Request?=
=?UTF-8?q?=20Header=EF=BC=9A=E6=96=B0=E5=A2=9E=E9=80=9A=E8=BF=87=E4=BB=A3?=
=?UTF-8?q?=E7=A0=81=E8=87=AA=E5=AE=9A=E4=B9=89=E7=9A=84=E8=AF=B4=E6=98=8E?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
index.html | 3 ++-
js/main.js | 7 ++++---
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/index.html b/index.html
index ed477bf..0d84083 100755
--- a/index.html
+++ b/index.html
@@ -414,7 +414,8 @@
-
+
diff --git a/js/main.js b/js/main.js
index 12696e5..e1a92dd 100755
--- a/js/main.js
+++ b/js/main.js
@@ -3262,9 +3262,7 @@
}
var m = this.getMethod();
- var c = isSingle ? '' : StringUtil.trim(CodeUtil.parseComment(after, docObj == null ? null : docObj['[]'], m, this.database, this.language, this.isEditResponse != true, standardObj))
- + '\n '
- + ' \n'; //解决遮挡
+ var c = isSingle ? '' : StringUtil.trim(CodeUtil.parseComment(after, docObj == null ? null : docObj['[]'], m, this.database, this.language, this.isEditResponse != true, standardObj));
//TODO 统计行数,补全到一致 vInput.value.lineNumbers
if (isSingle != true && afterObj.tag == null) {
@@ -3274,6 +3272,9 @@
}
}
vComment.value = c
+ + '\n\n\n '
+ + ' \n'; //解决遮挡
+
vUrlComment.value = isSingle || StringUtil.isEmpty(this.urlComment, true)
? '' : vUrl.value + CodeUtil.getComment(this.urlComment, false, ' ')
+ ' - ' + (this.requestVersion > 0 ? 'V' + this.requestVersion : 'V*');
From b08a2a9aef41a6d57e0dab72c8f50d2d8607da59 Mon Sep 17 00:00:00 2001
From: TommyLemon <1184482681@qq.com>
Date: Thu, 21 Oct 2021 18:49:31 +0800
Subject: [PATCH 515/818] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E9=9D=99=E6=80=81?=
=?UTF-8?q?=E6=A3=80=E6=9F=A5=EF=BC=9A=E8=AF=B7=E6=B1=82=E8=BE=93=E5=85=A5?=
=?UTF-8?q?=E6=A1=86=E7=9A=84=E6=8A=A5=E9=94=99=E6=8F=90=E7=A4=BA=E8=AF=AD?=
=?UTF-8?q?=E6=94=B9=E4=B8=BA=E7=BA=A2=E8=89=B2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
apijson/CodeUtil.js | 272 +++++++++++++++++++++++++-------------------
index.html | 5 +
js/main.js | 11 +-
3 files changed, 170 insertions(+), 118 deletions(-)
diff --git a/apijson/CodeUtil.js b/apijson/CodeUtil.js
index 2c17424..beea587 100644
--- a/apijson/CodeUtil.js
+++ b/apijson/CodeUtil.js
@@ -51,7 +51,7 @@ var CodeUtil = {
* @param language
* @return parseComment
*/
- parseComment: function (reqStr, tableList, method, database, language, isReq, standardObj, isExtract) { //怎么都获取不到真正的长度,cols不行,默认20不变,maxLineLength不行,默认undefined不变 , maxLineLength) {
+ parseComment: function (reqStr, tableList, method, database, language, isReq, standardObj, isExtract, isWarning) { //怎么都获取不到真正的长度,cols不行,默认20不变,maxLineLength不行,默认undefined不变 , maxLineLength) {
if (StringUtil.isEmpty(reqStr)) {
return '';
}
@@ -137,7 +137,7 @@ var CodeUtil = {
isInSubquery = key.endsWith('@');
- hintComment = CodeUtil.getComment4Request(tableList, names[depth - 1], key, value, method, false, database, language, isReq, names, isRestful, standardObj);
+ hintComment = CodeUtil.getComment4Request(tableList, names[depth - 1], key, value, method, false, database, language, isReq, names, isRestful, standardObj, isWarning);
names[depth] = key;
depth ++;
@@ -153,7 +153,7 @@ var CodeUtil = {
isInSubquery = false;
if (line.endsWith('{}')) { //对象,判断是不是Table,再加对应的注释
- hintComment = CodeUtil.getComment4Request(tableList, names[depth - 1], key, value, method, false, database, language, isReq, names, isRestful, standardObj);
+ hintComment = CodeUtil.getComment4Request(tableList, names[depth - 1], key, value, method, false, database, language, isReq, names, isRestful, standardObj, isWarning);
}
else {
depth --;
@@ -176,7 +176,7 @@ var CodeUtil = {
standardObj = JSONResponse.updateStandardByPath(standardObj, names, key, value, comment)
}
- hintComment = CodeUtil.getComment4Request(tableList, names[depth - 1], key, value, method, false, database, language, isReq, names, isRestful, standardObj);
+ hintComment = CodeUtil.getComment4Request(tableList, names[depth - 1], key, value, method, false, database, language, isReq, names, isRestful, standardObj, isWarning);
names[depth] = key;
depth ++;
@@ -190,7 +190,7 @@ var CodeUtil = {
}
if (line.endsWith('[]')) { //对象,判断是不是Table,再加对应的注释
- hintComment = CodeUtil.getComment4Request(tableList, names[depth - 1], key, value, method, false, database, language, isReq, names, isRestful, standardObj);
+ hintComment = CodeUtil.getComment4Request(tableList, names[depth - 1], key, value, method, false, database, language, isReq, names, isRestful, standardObj, isWarning);
}
else {
depth --;
@@ -213,7 +213,7 @@ var CodeUtil = {
}
}
// alert('depth = ' + depth + '; line = ' + line + '; isArray = ' + isArray);
- hintComment = CodeUtil.getComment4Request(tableList, names[depth - 1], key, value, method, isInSubquery, database, language, isReq, names, isRestful, standardObj);
+ hintComment = CodeUtil.getComment4Request(tableList, names[depth - 1], key, value, method, isInSubquery, database, language, isReq, names, isRestful, standardObj, isWarning);
}
}
@@ -222,7 +222,12 @@ var CodeUtil = {
}
}
- lines[i] += hintComment;
+ if (i > 0 && i < lines.length - 1 && StringUtil.isEmpty(hintComment, true)) {
+ lines[i] = ''; // 节约性能,收尾不能为空,否则外面 trim 一下格式就变了对不上原文本。奇怪的是右大括号 } 总是不走这里
+ }
+ else {
+ lines[i] += hintComment;
+ }
}
var apiMap = isRestful ? CodeUtil.thirdPartyApiMap : null;
@@ -5855,7 +5860,7 @@ var CodeUtil = {
* @param isInSubquery
* @param database
*/
- getComment4Request: function (tableList, name, key, value, method, isInSubquery, database, language, isReq, names, isRestful, standardObj) {
+ getComment4Request: function (tableList, name, key, value, method, isInSubquery, database, language, isReq, names, isRestful, standardObj, isWarning) {
// alert('name = ' + name + '; key = ' + key + '; value = ' + value + '; method = ' + method);
if (key == null) {
@@ -5886,9 +5891,12 @@ var CodeUtil = {
// }
try {
- var c = CodeUtil.getCommentFromDoc(tableList, name, key, method, database, language, false, isReq, pathKeys, isRestful, value == null ? {} : value, true, standardObj);
+ var c = CodeUtil.getCommentFromDoc(tableList, name, key, method, database, language, isRestful, isReq, pathKeys, isRestful, value == null ? {} : value, true, standardObj, null, isWarning);
if (isRestful == true || StringUtil.isEmpty(c) == false) { // TODO 最好都放行,查不到都去数据库查表和字段属性
- return StringUtil.isEmpty(c) ? ' ! 字段 ' + key + ' 不存在!' : (c.startsWith(' ! ') ? c : CodeUtil.getComment(c, false, ' '));
+ if (c.startsWith(' ! ')) {
+ return c;
+ }
+ return StringUtil.isEmpty(c) ? ' ! 字段 ' + key + ' 不存在!' : (isWarning ? '' : CodeUtil.getComment(c, false, ' '));
}
}
catch (e) {
@@ -5907,9 +5915,12 @@ var CodeUtil = {
var objName = key.substring(0, aliaIndex >= 0 ? aliaIndex : key.length - 2);
if (JSONObject.isTableKey(objName)) {
- var c = CodeUtil.getCommentFromDoc(tableList, objName, null, method, database, language, false, isReq, pathKeys, isRestful, value);
- return StringUtil.isEmpty(c) ? ' ! 表 ' + objName + ' 不存在!' : CodeUtil.getComment(
- (aliaIndex < 0 ? '' : '新建别名: ' + key.substring(aliaIndex + 1, key.length - 2) + ' < ') + objName + ': ' + c, false, ' ');
+ var c = CodeUtil.getCommentFromDoc(tableList, objName, null, method, database, language, isRestful, isReq, pathKeys, isRestful, value, null, null, null, isWarning);
+ if (c.startsWith(' ! ')) {
+ return c;
+ }
+ return StringUtil.isEmpty(c) ? ' ! 表 ' + objName + ' 不存在!' : (isWarning ? '' : CodeUtil.getComment(
+ (aliaIndex < 0 ? '' : '新建别名: ' + key.substring(aliaIndex + 1, key.length - 2) + ' < ') + objName + ': ' + c, false, ' '));
}
}
@@ -5917,10 +5928,14 @@ var CodeUtil = {
}
else if (value instanceof Object) {
if (isRestful != true && StringUtil.isEmpty(key, true)) {
- return ' ' + CodeUtil.getComment('根对象,可在内部加 format,tag,version,@role,@database,@schema,@datasource,@explain,@cache 等全局关键词键值对', false, ' ');
+ return isWarning ? '' : ' ' + CodeUtil.getComment('根对象,可在内部加 format,tag,version,@role,@database,@schema,@datasource,@explain,@cache 等全局关键词键值对', false, ' ');
}
if (isRestful != true && key.endsWith('@')) {
+ if (isWarning) {
+ return '';
+ }
+
if (key == '@from@') {
return CodeUtil.getComment('数据来源:子查询' + (isValueNotEmpty ? ',里面必须有 "from":Table, Table:{}' : ',例如 { "from":"User", "User":{} }'), false, ' ');
}
@@ -5928,14 +5943,18 @@ var CodeUtil = {
var aliaIndex = name == null ? -1 : name.indexOf(':');
var objName = aliaIndex < 0 ? name : name.substring(0, aliaIndex);
if (JSONObject.isTableKey(objName)) {
- return CodeUtil.getComment('子查询,里面必须有 "from":Table, Table:{} < ' + CodeUtil.getCommentFromDoc(tableList, objName, key.substring(0, key.length - 1), method, database, language, false, isReq, pathKeys, isRestful, value, null, null, true), false, ' ');
+ return CodeUtil.getComment('子查询,里面必须有 "from":Table, Table:{} < ' + CodeUtil.getCommentFromDoc(tableList, objName, key.substring(0, key.length - 1), method, database, language, isRestful, isReq, pathKeys, isRestful, value, null, null, true, isWarning), false, ' ');
}
return CodeUtil.getComment('子查询,可在内部加 from,range 或 数组关键词 等键值对,需要被下面的表字段相关 key 引用赋值', false, ' ');
}
if (isRestful != true && JSONObject.isArrayKey(key)) {
- if (method != 'GET') {
- return ' ! key[]:{}只支持GET方法!';
+ if (method != 'GET' && method != 'GETS') {
+ return ' ! key[]:{} 只支持 GET,GETS 方法!';
+ }
+
+ if (isWarning) {
+ return '';
}
key = key.substring(0, key.lastIndexOf('[]'));
@@ -5955,12 +5974,15 @@ var CodeUtil = {
var isTableKey = JSONObject.isTableKey(objName)
if (isRestful == true || isTableKey) {
- var c = CodeUtil.getCommentFromDoc(tableList, objName, null, method, database, language, false, isReq, pathKeys, isRestful, value);
- return StringUtil.isEmpty(c) ? ' ! 表不存在!' : CodeUtil.getComment(
- (aliaIndex < 0 ? '' : '新建别名: ' + key.substring(aliaIndex + 1, key.length) + ' < ' + objName + ': ') + c, false, ' ');
+ var c = CodeUtil.getCommentFromDoc(tableList, objName, null, method, database, language, isRestful, isReq, pathKeys, isRestful, value, null, null, null, isWarning);
+ if (c.startsWith(' ! ')) {
+ return c;
+ }
+ return StringUtil.isEmpty(c) ? ' ! 表不存在!' : (isWarning ? '' : CodeUtil.getComment(
+ (aliaIndex < 0 ? '' : '新建别名: ' + key.substring(aliaIndex + 1, key.length) + ' < ' + objName + ': ') + c, false, ' '));
}
- if (isRestful != true && isTableKey != true && StringUtil.isEmpty(objName) != true) {
+ if (isWarning != true && isRestful != true && isTableKey != true && StringUtil.isEmpty(objName) != true) {
return CodeUtil.getComment('普通对象。如果要对应数据库表请把 ' + objName + ' 改成 ' + StringUtil.firstCase(objName, true) + ' 这种以大写字母开头的 APIJSON 表名!数据库表不一样要这样,MySQL 默认大小写不敏感。', false, ' ');
}
@@ -5970,15 +5992,15 @@ var CodeUtil = {
if (isRestful != true && (isInSubquery || JSONObject.isArrayKey(name))) {
switch (key) {
case 'count':
- return value != null && valuesIsNotInteger ? ' ! value必须是Integer类型!' : CodeUtil.getComment('每页数量' + (isValueNotEmpty ? '' : ',例如 5 10 20 等'), false, ' ');
+ return value != null && valuesIsNotInteger ? ' ! value必须是Integer类型!' : (isWarning ? '' : CodeUtil.getComment('每页数量' + (isValueNotEmpty ? '' : ',例如 5 10 20 等'), false, ' '));
case 'page':
if (value != null && valuesIsNotInteger) {
return ' ! value必须是Integer类型!';
}
- return value != null && value < 0 ? ' ! 必须 >= 0 !' : CodeUtil.getComment('分页页码' + (isValueNotEmpty ? '' : ': 例如 0 1 2 ...'), false, ' ');
+ return value != null && value < 0 ? ' ! 必须 >= 0 !' : (isWarning ? '' : CodeUtil.getComment('分页页码' + (isValueNotEmpty ? '' : ': 例如 0 1 2 ...'), false, ' '));
case 'query':
var query = CodeUtil.QUERY_TYPES[value];
- return StringUtil.isEmpty(query) ? ' ! value必须是[' + CodeUtil.QUERY_TYPE_KEYS.join() + ']中的一种!' : CodeUtil.getComment('查询内容:0-对象 1-总数和分页详情 2-数据、总数和分页详情', false, ' ');
+ return StringUtil.isEmpty(query) ? ' ! value必须是[' + CodeUtil.QUERY_TYPE_KEYS.join() + ']中的一种!' : (isWarning ? '' : CodeUtil.getComment('查询内容:0-对象 1-总数和分页详情 2-数据、总数和分页详情', false, ' '));
case 'join':
if (valuesIsNotString) {
return ' ! value必须是String类型!';
@@ -6019,12 +6041,14 @@ var CodeUtil = {
return ' ! 表名 ' + t + ' 不合法 ! 必须是 Table 这种大驼峰格式' + (isValueNotEmpty ? '' : ',例如 "User" "Comment" "ViewTable" 等 !');
}
- s += CodeUtil.JOIN_TYPES[c] + ' JOIN ' + t + (a.length <= 0 ? '' : ' AS ' + a);
- must += (i > 0 ? ', ' : ',同一层级必须有 "') + t + '":{ "' + item.substring(lastIndex + 1) + '":"/../.." }';
+ if (isWarning != true) {
+ s += CodeUtil.JOIN_TYPES[c] + ' JOIN ' + t + (a.length <= 0 ? '' : ' AS ' + a);
+ must += (i > 0 ? ', ' : ',同一层级必须有 "') + t + '":{ "' + item.substring(lastIndex + 1) + '":"/../.." }';
+ }
}
}
- return CodeUtil.getComment('多表连接:' + (s + must || '例如 &/User/id@, RIGHT, * CROSS, & INNER, | FULL, ! OUTER, ^ SIDE, ( ANTI, ) FOREIGN'), false, ' ');
default:
if (isInSubquery) {
@@ -6033,9 +6057,9 @@ var CodeUtil = {
if (valuesIsNotString) {
return ' ! value必须是String类型!';
}
- return CodeUtil.SUBQUERY_RANGES.indexOf(value) < 0 ? ' ! value必须是[' + CodeUtil.SUBQUERY_RANGES.join() + ']中的一种!' : CodeUtil.getComment('比较范围:ANY-任意 ALL-全部', false, ' ');
+ return CodeUtil.SUBQUERY_RANGES.indexOf(value) < 0 ? ' ! value必须是[' + CodeUtil.SUBQUERY_RANGES.join() + ']中的一种!' : (isWarning ? '' : CodeUtil.getComment('比较范围:ANY-任意 ALL-全部', false, ' '));
case 'from':
- return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('数据来源' + (isValueNotEmpty ? ',同一层级必须有 "' + value + '":{...}' : ',例如 "User",同一层级必须有 "User":{...}'), false, ' ');
+ return valuesIsNotString ? ' ! value必须是String类型!' : (isWarning ? '' : CodeUtil.getComment('数据来源' + (isValueNotEmpty ? ',同一层级必须有 "' + value + '":{...}' : ',例如 "User",同一层级必须有 "User":{...}'), false, ' '));
}
}
break;
@@ -6049,69 +6073,72 @@ var CodeUtil = {
if (isRestful != true && JSONObject.isTableKey(objName)) {
switch (key) {
case '@column':
- return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('返回字段' + (isValueNotEmpty ? ',可传 字段(:别名)、SQL 函数(:别名,用分号 ; 隔开)、表达式,以及部分 SQL 关键词' : ':例如 "name" "toId:parentId" "id,userId;json_length(praiseUserIdList):praiseCount" 等'), false, ' ');
+ return valuesIsNotString ? ' ! value必须是String类型!' : (isWarning ? '' : CodeUtil.getComment('返回字段' + (isValueNotEmpty ? ',可传 字段(:别名)、SQL 函数(:别名,用分号 ; 隔开)、表达式,以及部分 SQL 关键词' : ':例如 "name" "toId:parentId" "id,userId;json_length(praiseUserIdList):praiseCount" 等'), false, ' '));
case '@from@': //value 类型为 Object 时 到不了这里,已在上方处理
- return valuesIsNotString && typeOfValue != 'object' ? ' ! value必须是String或Object类型!' : CodeUtil.getComment('数据来源:引用赋值 子查询 "' + value + '@":{...} ', false, ' ');
+ return valuesIsNotString && typeOfValue != 'object' ? ' ! value必须是String或Object类型!' : (isWarning ? '' : CodeUtil.getComment('数据来源:引用赋值 子查询 "' + value + '@":{...} ', false, ' '));
case '@group':
- return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('分组方式' + (isValueNotEmpty ? '' : ',例如 "userId" "momentId,toId" 等'), false, ' ');
+ return valuesIsNotString ? ' ! value必须是String类型!' : (isWarning ? '' : CodeUtil.getComment('分组方式' + (isValueNotEmpty ? '' : ',例如 "userId" "momentId,toId" 等'), false, ' '));
case '@having':
- return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('聚合函数' + (isValueNotEmpty ? ',可传 SQL 函数(用分号 ; 隔开)、表达式,以及部分 SQL 关键词' : ',例如 "max(id)>100" "length(phone)>0;sum(balance)<=10000" 等'), false, ' ');
+ return valuesIsNotString ? ' ! value必须是String类型!' : (isWarning ? '' : CodeUtil.getComment('聚合函数' + (isValueNotEmpty ? ',可传 SQL 函数(用分号 ; 隔开)、表达式,以及部分 SQL 关键词' : ',例如 "max(id)>100" "length(phone)>0;sum(balance)<=10000" 等'), false, ' '));
case '@order':
- return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('排序方式:+升序,-降序' + (isValueNotEmpty ? '' : ',例如 "date-" "name+,id-" 等'), false, ' ');
+ return valuesIsNotString ? ' ! value必须是String类型!' : (isWarning ? '' : CodeUtil.getComment('排序方式:+升序,-降序' + (isValueNotEmpty ? '' : ',例如 "date-" "name+,id-" 等'), false, ' '));
case '@combine': //TODO 解析 value 并直接给出条件组合结果
- return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('条件组合' + (isValueNotEmpty ? ',| 可省略。合并同类,外层按照 & | ! 顺序,内层按传参顺序组合成 (key0 & key1 & key6 & 其它key) & (key2 | key3 | key7) & !(key4 | key5)' : ',例如 "name$,tag$" "!userId<,!toId" 等'), false, ' ');
+ return valuesIsNotString ? ' ! value必须是String类型!' : (isWarning ? '' : CodeUtil.getComment('条件组合' + (isValueNotEmpty ? ',| 可省略。合并同类,外层按照 & | ! 顺序,内层按传参顺序组合成 (key0 & key1 & key6 & 其它key) & (key2 | key3 | key7) & !(key4 | key5)' : ',例如 "name$,tag$" "!userId<,!toId" 等'), false, ' '));
case '@schema':
- return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('集合空间(数据库名/模式)' + (isValueNotEmpty ? '' : ',例如 "sys" "apijson" "postgres" "dbo" 等'), false, ' ');
+ return valuesIsNotString ? ' ! value必须是String类型!' : (isWarning ? '' : CodeUtil.getComment('集合空间(数据库名/模式)' + (isValueNotEmpty ? '' : ',例如 "sys" "apijson" "postgres" "dbo" 等'), false, ' '));
case '@datasource':
- return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('跨数据源' + (isValueNotEmpty ? '' : ',例如 "DRUID" "HIKARICP" 等'), false, ' ');
+ return valuesIsNotString ? ' ! value必须是String类型!' : (isWarning ? '' : CodeUtil.getComment('跨数据源' + (isValueNotEmpty ? '' : ',例如 "DRUID" "HIKARICP" 等'), false, ' '));
case '@raw':
- return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('原始SQL片段' + (isValueNotEmpty ? ',由后端 RAW_MAP 代码配置指定 "key0,key1.." 中每个 key 对应 key:"SQL片段" 中的 SQL片段' : ',例如 "@column" "id{},@having" 等'), false, ' ');
+ return valuesIsNotString ? ' ! value必须是String类型!' : (isWarning ? '' : CodeUtil.getComment('原始SQL片段' + (isValueNotEmpty ? ',由后端 RAW_MAP 代码配置指定 "key0,key1.." 中每个 key 对应 key:"SQL片段" 中的 SQL片段' : ',例如 "@column" "id{},@having" 等'), false, ' '));
case '@json':
- return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('转为JSON' + (isValueNotEmpty ? '' : ',例如 "request" "gets,heads" 等'), false, ' ');
+ return valuesIsNotString ? ' ! value必须是String类型!' : (isWarning ? '' : CodeUtil.getComment('转为JSON' + (isValueNotEmpty ? '' : ',例如 "request" "gets,heads" 等'), false, ' '));
case '@database':
- return CodeUtil.DATABASE_KEYS.indexOf(value) < 0 ? ' ! value必须是[' + CodeUtil.DATABASE_KEYS.join() + ']中的一种!' : CodeUtil.getComment('数据库类型:例如 "MYSQL" "POSTGRESQL" "SQLSERVER" "ORACLE" "DB2" "CLICKHOUSE" 等', false, ' ');
+ return CodeUtil.DATABASE_KEYS.indexOf(value) < 0 ? ' ! value必须是[' + CodeUtil.DATABASE_KEYS.join() + ']中的一种!' : (isWarning ? '' : CodeUtil.getComment('数据库类型:例如 "MYSQL" "POSTGRESQL" "SQLSERVER" "ORACLE" "DB2" "CLICKHOUSE" 等', false, ' '));
case '@role':
var role = CodeUtil.ROLES[value];
- return StringUtil.isEmpty(role) ? ' ! value必须是[' + CodeUtil.ROLE_KEYS.join() + ']中的一种!' : CodeUtil.getComment('来访角色:' + role + ',限制可操作的数据,假定真实强制匹配', false, ' ');
+ return StringUtil.isEmpty(role) ? ' ! value必须是[' + CodeUtil.ROLE_KEYS.join() + ']中的一种!' : (isWarning ? '' : CodeUtil.getComment('来访角色:' + role + ',限制可操作的数据,假定真实强制匹配', false, ' '));
case '@cache':
var cache = CodeUtil.CACHE_TYPES[value];
- return StringUtil.isEmpty(cache) ? ' ! value必须是[' + CodeUtil.CACHE_TYPE_KEYS.join() + ']中的一种!' : CodeUtil.getComment('缓存方式:0-全部 1-磁盘 2-内存', false, ' ');
+ return StringUtil.isEmpty(cache) ? ' ! value必须是[' + CodeUtil.CACHE_TYPE_KEYS.join() + ']中的一种!' : (isWarning ? '' : CodeUtil.getComment('缓存方式:0-全部 1-磁盘 2-内存', false, ' '));
case '@explain':
- return valuesIsNotBoolean ? ' ! value必须是Boolean类型!' : CodeUtil.getComment('性能分析:true-开启 false-关闭,返回执行的 SQL 及查询计划', false, ' ');
+ return valuesIsNotBoolean ? ' ! value必须是Boolean类型!' : (isWarning ? '' : CodeUtil.getComment('性能分析:true-开启 false-关闭,返回执行的 SQL 及查询计划', false, ' '));
}
if (key.startsWith('@')) {
if (key.endsWith('()')) {
- return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('存储过程' + (isValueNotEmpty ? ',触发调用数据库存储过程' : ':例如 "getCommentByUserId(id,@limit,@offset)"'), false, ' ');
+ return valuesIsNotString ? ' ! value必须是String类型!' : (isWarning ? '' : CodeUtil.getComment('存储过程' + (isValueNotEmpty ? ',触发调用数据库存储过程' : ':例如 "getCommentByUserId(id,@limit,@offset)"'), false, ' '));
}
return '';
}
- var c = CodeUtil.getCommentFromDoc(tableList, objName, key, method, database, language, null, isReq, pathKeys, isRestful, value);
- return StringUtil.isEmpty(c) ? ' ! 字段不存在!' : CodeUtil.getComment(c, false, ' ');
+ var c = CodeUtil.getCommentFromDoc(tableList, objName, key, method, database, language, isRestful, isReq, pathKeys, isRestful, value, null, null, null, isWarning);
+ if (c.startsWith(' ! ')) {
+ return c;
+ }
+ return StringUtil.isEmpty(c) ? ' ! 字段不存在!' : (isWarning ? '' : CodeUtil.getComment(c, false, ' '));
}
// alert('name = ' + name + '; key = ' + key);
if (isRestful != true && StringUtil.isEmpty(name)) {
switch (key) {
case 'tag':
- return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('请求标识' + (method == 'GET' || method == 'HEAD' ? ',GET,HEAD 请求不会自动解析,仅为后续迭代可能的手动优化而预留' : (isValueNotEmpty ? ',用来区分不同请求并校验,由后端 Request 表中指定' : ',例如 "User" "Comment[]" "Privacy-CIRCLE" 等')), false, ' ');
+ return valuesIsNotString ? ' ! value必须是String类型!' : (isWarning ? '' : CodeUtil.getComment('请求标识' + (method == 'GET' || method == 'HEAD' ? ',GET,HEAD 请求不会自动解析,仅为后续迭代可能的手动优化而预留' : (isValueNotEmpty ? ',用来区分不同请求并校验,由后端 Request 表中指定' : ',例如 "User" "Comment[]" "Privacy-CIRCLE" 等')), false, ' '));
case 'version':
- return valuesIsNotInteger ? ' ! value必须是Integer类型!' : CodeUtil.getComment('版本号' + (method == 'GET' || method == 'HEAD' ? ',GET,HEAD 请求不会自动解析,仅为后续迭代可能的手动优化而预留' : (isValueNotEmpty ? ',用来使用特定版本的校验规则,由后端 Request 表中指定' : ',例如 1 2 3 等')), false, ' ');
+ return valuesIsNotInteger ? ' ! value必须是Integer类型!' : (isWarning ? '' : CodeUtil.getComment('版本号' + (method == 'GET' || method == 'HEAD' ? ',GET,HEAD 请求不会自动解析,仅为后续迭代可能的手动优化而预留' : (isValueNotEmpty ? ',用来使用特定版本的校验规则,由后端 Request 表中指定' : ',例如 1 2 3 等')), false, ' '));
case 'format':
- return valuesIsNotBoolean ? ' ! value必须是Boolean类型!' : CodeUtil.getComment('格式化: true-是 false-否,将 TableName 转为 tableName, TableName[] 转为 tableNameList, Table:alias 转为 alias 等小驼峰格式', false, ' ');
+ return valuesIsNotBoolean ? ' ! value必须是Boolean类型!' : (isWarning ? '' : CodeUtil.getComment('格式化: true-是 false-否,将 TableName 转为 tableName, TableName[] 转为 tableNameList, Table:alias 转为 alias 等小驼峰格式', false, ' '));
case '@schema':
- return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('集合空间(数据库名/模式)' + (isValueNotEmpty ? '' : ',例如 "sys" "apijson" "postgres" "dbo" 等'), false, ' ');
+ return valuesIsNotString ? ' ! value必须是String类型!' : (isWarning ? '' : CodeUtil.getComment('集合空间(数据库名/模式)' + (isValueNotEmpty ? '' : ',例如 "sys" "apijson" "postgres" "dbo" 等'), false, ' '));
case '@datasource':
- return valuesIsNotString ? ' ! value必须是String类型!' : CodeUtil.getComment('跨数据源' + (isValueNotEmpty ? '' : ',例如 "DRUID" "HIKARICP" 等'), false, ' ');
+ return valuesIsNotString ? ' ! value必须是String类型!' : (isWarning ? '' : CodeUtil.getComment('跨数据源' + (isValueNotEmpty ? '' : ',例如 "DRUID" "HIKARICP" 等'), false, ' '));
case '@database':
- return CodeUtil.DATABASE_KEYS.indexOf(value) < 0 ? ' ! value必须是[' + CodeUtil.DATABASE_KEYS.join() + ']中的一种!' : CodeUtil.getComment('数据库' + (isValueNotEmpty ? '' : ',例如 "MYSQL" "POSTGRESQL" "SQLSERVER" "ORACLE" 等'), false, ' ');
+ return CodeUtil.DATABASE_KEYS.indexOf(value) < 0 ? ' ! value必须是[' + CodeUtil.DATABASE_KEYS.join() + ']中的一种!' : (isWarning ? '' : CodeUtil.getComment('数据库' + (isValueNotEmpty ? '' : ',例如 "MYSQL" "POSTGRESQL" "SQLSERVER" "ORACLE" 等'), false, ' '));
case '@role':
var role = CodeUtil.ROLES[value];
- return StringUtil.isEmpty(role) ? ' ! value必须是[' + CodeUtil.ROLE_KEYS.join() + ']中的一种!' : CodeUtil.getComment('默认角色:' + role, false, ' ');
+ return StringUtil.isEmpty(role) ? ' ! value必须是[' + CodeUtil.ROLE_KEYS.join() + ']中的一种!' : (isWarning ? '' : CodeUtil.getComment('默认角色:' + role, false, ' '));
case '@cache':
var cache = CodeUtil.CACHE_TYPES[value];
- return StringUtil.isEmpty(cache) ? ' ! value必须是[' + CodeUtil.CACHE_TYPE_KEYS.join() + ']中的一种!' : CodeUtil.getComment('缓存方式:0-全部 1-磁盘 2-内存', false, ' ');
+ return StringUtil.isEmpty(cache) ? ' ! value必须是[' + CodeUtil.CACHE_TYPE_KEYS.join() + ']中的一种!' : (isWarning ? '' : CodeUtil.getComment('缓存方式:0-全部 1-磁盘 2-内存', false, ' '));
case '@explain':
- return valuesIsNotBoolean ? ' ! value必须是Boolean类型!' : CodeUtil.getComment('性能分析:true-开启 false-关闭,返回执行的 SQL 及查询计划', false, ' ');
+ return valuesIsNotBoolean ? ' ! value必须是Boolean类型!' : (isWarning ? '' : CodeUtil.getComment('性能分析:true-开启 false-关闭,返回执行的 SQL 及查询计划', false, ' '));
}
}
@@ -6128,7 +6155,7 @@ var CodeUtil = {
* @param onlyTableAndColumn
* @return {*}
*/
- getCommentFromDoc: function (tableList, tableName, columnName, method, database, language, onlyTableAndColumn, isReq, pathKeys, isRestful, value, ignoreError, standardObj, isSubquery) {
+ getCommentFromDoc: function (tableList, tableName, columnName, method, database, language, onlyTableAndColumn, isReq, pathKeys, isRestful, value, ignoreError, standardObj, isSubquery, isWarning) {
log('getCommentFromDoc tableName = ' + tableName + '; columnName = ' + columnName
+ '; method = ' + method + '; database = ' + database + '; language = ' + language
+ '; onlyTableAndColumn = ' + onlyTableAndColumn + '; tableList = \n' + JSON.stringify(tableList));
@@ -6139,10 +6166,14 @@ var CodeUtil = {
var targetComment = targetObj == null ? null : targetObj.comment;
var c = targetObj == null ? null : CodeUtil.getType4Language(language, t, true) + (targetObj.notnull ? ', ' : '? ') + StringUtil.trim(targetComment);
if (CodeUtil.isTypeMatch(t, CodeUtil.getType4Request(value))) {
- c = ' ! value必须是' + CodeUtil.getType4Language(language, t) + '类型!' + CodeUtil.getComment(c, false, ' ');
+ c = ' ! value必须是' + CodeUtil.getType4Language(language, t) + '类型!' + (isWarning ? ' ' : CodeUtil.getComment(c, false, ' '));
if (ignoreError != true) {
throw new Error(c);
}
+
+ if (isWarning) {
+ return c;
+ }
}
if (StringUtil.isEmpty(targetComment, true) == false) { // 如果这里没注释就从数据库/第三方平台取
@@ -6166,84 +6197,89 @@ var CodeUtil = {
if (isRestful == true && StringUtil.isEmpty(columnName, true) == false && StringUtil.isEmpty(CodeUtil.thirdParty, true) == false) { // } && CodeUtil.thirdParty == 'YAPI') {
var apiMap = CodeUtil.thirdPartyApiMap;
if (apiMap == null) {
- return '...';
+ // 用 下方 tableList 兜底 return isWarning ? ' ' : '...';
}
-
- var api = apiMap[(method.startsWith('/') ? '' : '/') + method];
- var doc = api == null ? null : (isReq ? api.request : api.response);
- if (doc != null) {
- if (pathKeys != null && pathKeys.length > 0) {
- for (var i = 0; i < pathKeys.length; i ++) {
- var p = pathKeys[i];
-
- if (doc instanceof Array) {
- var find = false;
- for (var j = 0; j < doc.length; j++) {
- var d = doc[j];
- if (d != null && d.name == p) {
- doc = d;
- find = true;
- break;
+ else {
+ var api = apiMap[(method.startsWith('/') ? '' : '/') + method];
+ var doc = api == null ? null : (isReq ? api.request : api.response);
+ if (doc != null) {
+ if (pathKeys != null && pathKeys.length > 0) {
+ for (var i = 0; i < pathKeys.length; i++) {
+ var p = pathKeys[i];
+
+ if (doc instanceof Array) {
+ var find = false;
+ for (var j = 0; j < doc.length; j++) {
+ var d = doc[j];
+ if (d != null && d.name == p) {
+ doc = d;
+ find = true;
+ break;
+ }
}
- }
- if (find == false) {
- doc = null;
- }
- }
- else if (doc instanceof Object) {
- if (doc.type == 'object') {
- doc = doc.properties;
+ if (find == false) {
+ doc = null;
+ }
}
- else if (doc.type == 'array') {
- doc = doc.items;
-
- try {
- if (p != null && p != '' && Number.isNaN(+ p)) {
- i --;
+ else if (doc instanceof Object) {
+ if (doc.type == 'object') {
+ doc = doc.properties;
+ }
+ else if (doc.type == 'array') {
+ doc = doc.items;
+
+ try {
+ if (p != null && p != '' && Number.isNaN(+p)) {
+ i--;
+ }
+ } catch (e) {
}
- } catch (e) {}
- continue;
- }
+ continue;
+ }
- doc = doc[p];
+ doc = doc[p];
+ }
}
}
- }
- else if (doc instanceof Array) {
- doc = null;
- }
+ else if (doc instanceof Array) {
+ doc = null;
+ }
- var t = doc == null ? null : doc.type;
- var c = doc == null ? null : CodeUtil.getType4Language(language, t, true) + (doc.required ? ', ' : '? ') + StringUtil.trim(doc.description || doc.title);
- if (t == null) {
- // 避免崩溃
- }
- else if (t.endsWith('[]')) {
- t = 'array';
- }
- else if (t == 'integer') {
- t = 'number';
- }
+ var t = doc == null ? null : doc.type;
+ var c = doc == null ? null : CodeUtil.getType4Language(language, t, true) + (doc.required ? ', ' : '? ') + StringUtil.trim(doc.description || doc.title);
+ if (t == null) {
+ // 避免崩溃
+ }
+ else if (t.endsWith('[]')) {
+ t = 'array';
+ }
+ else if (t == 'integer') {
+ t = 'number';
+ }
- if (CodeUtil.isTypeMatch(t, CodeUtil.getType4Request(value))) {
- c = ' ! value必须是' + CodeUtil.getType4Language(language, t) + '类型!' + CodeUtil.getComment(c, false, ' ')
+ if (CodeUtil.isTypeMatch(t, CodeUtil.getType4Request(value))) {
+ c = ' ! value必须是' + CodeUtil.getType4Language(language, t) + '类型!' + (isWarning ? ' ' : CodeUtil.getComment(c, false, ' '))
if (ignoreError != true) {
throw new Error(c);
}
return c;
- }
- else {
- if (c != null) { // 可能存在但只是没注释 StringUtil.isEmpty(c, true) == false) {
- return c;
}
+ else {
+ if (c != null) { // 可能存在但只是没注释 StringUtil.isEmpty(c, true) == false) {
+ return isWarning ? ' ' : c;
+ }
+ }
+
}
+
}
+
}
if (tableList == null || tableList.length <= 0) {
- return '...';
+ return isWarning ? ' ' : '...';
}
var item;
@@ -6305,6 +6341,10 @@ var CodeUtil = {
}
}
+ if (isWarning) {
+ return ' ';
+ }
+
var priority = '';
if (columnName.endsWith("-()")) {
priority = ' < 在解析所在对象前优先执行';
@@ -6518,10 +6558,10 @@ var CodeUtil = {
// if (ignoreError != true) {
// throw new Error(c);
// }
- return ' ! value必须是' + t + '类型!' + CodeUtil.getComment(c, false, ' ')
+ return ' ! value必须是' + t + '类型!' + (isWarning ? ' ' : CodeUtil.getComment(c, false, ' '));
}
- return c;
+ return isWarning ? ' ' : c;
}
return onlyTableAndColumn ? '' : ' ! 字段 ' + key + ' 不存在!只能是 [' + columnNames.join() + '] 中的一个!';
diff --git a/index.html b/index.html
index 0d84083..4655d19 100755
--- a/index.html
+++ b/index.html
@@ -193,6 +193,8 @@