Skip to content

Commit f1baa0f

Browse files
committed
Demo: MultiDataSource 解决 APIAuto 在快速多次操作后,可能用例列表等显示的不是最新的(切换分组导致先发后至)
1 parent 3053800 commit f1baa0f

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ var CodeUtil = {
135135
if (isExtract && standardObj != null && (isReq || depth != 1
136136
|| [JSONResponse.KEY_CODE, JSONResponse.KEY_MSG, JSONResponse.KEY_THROW].indexOf(key) < 0)) {
137137
comment = line.substring(cIndex + ccLen).trim();
138-
// standardObj = CodeUtil.updateStandardPart(standardObj, names, key, value, comment)
138+
// standardObj = CodeUtil.updateStandardByPath(standardObj, names, key, value, comment)
139139
}
140140

141141
line = line.substring(0, cIndex).trim();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1758,7 +1758,7 @@ var JSONResponse = {
17581758
return null;
17591759
}
17601760

1761-
tgt[pathKeys[pathKeys.length - 1]] = val;
1761+
tgt[pathKeys[depth - 1]] = val;
17621762

17631763
return target;
17641764
},

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@
370370
" >
371371
{
372372
"User": {
373-
"id": 82001
373+
"id": "82001"
374374
}, // 以上查一个对象,以下查一个数组,Comment.userId = User.id。在键值对后按 Enter 回车键自动智能生成补全提示
375375
"[]": {
376376
Comment : {

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6822,6 +6822,22 @@ https://github.com/Tencent/APIJSON/issues
68226822
req = newReq
68236823
}
68246824

6825+
axios.interceptors.request.use(function (config) {
6826+
config.metadata = { startTime: new Date().getTime()}
6827+
return config;
6828+
}, function (error) {
6829+
return Promise.reject(error);
6830+
});
6831+
axios.interceptors.response.use(function (response) {
6832+
response.config.metadata.endTime = new Date().getTime()
6833+
response.duration = response.config.metadata.endTime - response.config.metadata.startTime
6834+
return response;
6835+
}, function (error) {
6836+
error.config.metadata.endTime = new Date().getTime();
6837+
error.duration = error.config.metadata.endTime - error.config.metadata.startTime;
6838+
return Promise.reject(error);
6839+
});
6840+
68256841
// axios.defaults.withcredentials = true
68266842
axios({
68276843
method: method != null ? method : (HTTP_METHODS.indexOf(type) >= 0 ? type.toLowerCase() : (type == REQUEST_TYPE_PARAM ? 'get' : 'post')),
@@ -7037,13 +7053,21 @@ https://github.com/Tencent/APIJSON/issues
70377053
retryReq()
70387054
},
70397055

7040-
7056+
lastReqTime: 0,
70417057
/**请求回调
70427058
*/
70437059
onResponse: function (url, res, err) {
70447060
if (res == null) {
70457061
res = {}
7062+
} else {
7063+
var time = res.config == null || res.config.metadata == null ? 0 : (res.config.metadata.startTime || 0)
7064+
if (time < this.lastReqTime) {
7065+
return
7066+
}
7067+
7068+
this.lastReqTime = time
70467069
}
7070+
70477071
if (DEBUG) {
70487072
log('onResponse url = ' + url + '\nerr = ' + err + '\nreq = \n'
70497073
+ (res.request == null || res.request.data == null ? 'null' : JSON.stringify(res.request.data))
@@ -8054,6 +8078,7 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea
80548078
})
80558079
},
80568080

8081+
lastDocReqTime: 0,
80578082
onDocumentListResponse: function(url, res, err, callback) {
80588083
if (err != null || res == null || res.data == null) {
80598084
log('getDoc err != null || res == null || res.data == null >> return;');
@@ -8063,6 +8088,13 @@ Content-Type: ` + contentType) + (StringUtil.isEmpty(headerStr, true) ? '' : hea
80638088
return;
80648089
}
80658090

8091+
var time = res.config == null || res.config.metadata == null ? 0 : (res.config.metadata.startTime || 0)
8092+
if (time < this.lastDocReqTime) {
8093+
return
8094+
}
8095+
8096+
this.lastDocReqTime = time;
8097+
80668098
// log('getDoc docRq.responseText = \n' + docRq.responseText);
80678099
docObj = res.data || {}; //避免后面又调用 onChange ,onChange 又调用 getDoc 导致死循环
80688100

0 commit comments

Comments
 (0)