diff --git a/resources/assets/js/functions/common.js b/resources/assets/js/functions/common.js index e794e267d..b6ab466f1 100755 --- a/resources/assets/js/functions/common.js +++ b/resources/assets/js/functions/common.js @@ -1643,7 +1643,7 @@ const timezone = require("dayjs/plugin/timezone"); contentType: 'application/x-www-form-urlencoded', timeout: 0 }; - let callbacks = ['beforeSend', 'error', 'complete', 'success', 'statusCode']; + const callbacks = ['beforeSend', 'error', 'complete', 'success', 'statusCode']; //For jQuery guys @@ -1749,7 +1749,10 @@ const timezone = require("dayjs/plugin/timezone"); } // Create XHR - let xhr = new XMLHttpRequest(); + const xhr = new XMLHttpRequest(); + + // 添加请求开始时间记录 + const requestStartTime = Date.now(); // Save Request URL xhr.requestUrl = options.url; @@ -1827,6 +1830,22 @@ const timezone = require("dayjs/plugin/timezone"); xhr.onload = function (e) { if (xhrTimeout) clearTimeout(xhrTimeout); if ((xhr.status >= 200 && xhr.status < 300) || xhr.status === 0) { + // 计算请求耗时 + const requestDuration = Date.now() - requestStartTime; + + // 获取响应标头时间信息 + const serverDate = xhr.getResponseHeader('Date'); + const lastModified = xhr.getResponseHeader('Last-Modified'); + const age = xhr.getResponseHeader('Age'); + + // 将时间信息添加到响应对象中 + xhr.timeData = { + serverDate: serverDate, + lastModified: lastModified, + age: age, + duration: requestDuration + }; + let responseData; if (options.dataType === 'json') { try { diff --git a/resources/assets/js/store/actions.js b/resources/assets/js/store/actions.js index 0745c45a0..c6cfc442e 100644 --- a/resources/assets/js/store/actions.js +++ b/resources/assets/js/store/actions.js @@ -273,7 +273,7 @@ export default { return } if (ret === 1) { - resolve({data, msg}) + resolve({data, msg, xhr}) } else { reject({ret, data, msg: msg || $A.L('未知错误')}) // @@ -1354,9 +1354,9 @@ export default { dispatch("call", { url: 'project/lists', data: callData.get() - }).then(({data}) => { + }).then(({data, xhr}) => { dispatch("saveProject", data.data); - callData.save(data).then(ids => dispatch("forgetProject", ids)) + callData.save(data, xhr.timeData.serverDate).then(ids => dispatch("forgetProject", ids)) state.projectTotal = data.total_all; // resolve(data) @@ -1853,12 +1853,12 @@ export default { dispatch("call", { url: 'project/task/lists', data: callData.get() - }).then(({data}) => { + }).then(({data, xhr}) => { if (requestData.project_id) { state.projectLoad--; } dispatch("saveTask", data.data); - callData.save(data).then(ids => dispatch("forgetTask", ids)) + callData.save(data, xhr.timeData.serverDate).then(ids => dispatch("forgetTask", ids)) // if (data.next_page_url) { requestData.page = data.current_page + 1 @@ -2757,9 +2757,9 @@ export default { dispatch("call", { url: 'dialog/lists', data: callData.get() - }).then(({data}) => { + }).then(({data, xhr}) => { dispatch("saveDialog", data.data); - callData.save(data).then(ids => dispatch("forgetDialog", ids)) + callData.save(data, xhr.timeData.serverDate).then(ids => dispatch("forgetDialog", ids)) // if (data.current_page === 1) { dispatch("getDialogLatestMsgs", data.data.map(({id}) => id)) diff --git a/resources/assets/js/store/utils.js b/resources/assets/js/store/utils.js index bdb73b576..cb0a6dc47 100644 --- a/resources/assets/js/store/utils.js +++ b/resources/assets/js/store/utils.js @@ -34,15 +34,16 @@ function __callData(key, requestData, state) { * @param total * @param current_page * @param deleted_id + * @param serverDate * @returns {Promise} */ - this.save = ({total, current_page, deleted_id}) => { + this.save = ({total, current_page, deleted_id}, serverDate = undefined) => { return new Promise(async resolve => { if (current_page !== 1) { return } let hasUpdate = false - const time = $A.dayjs().unix() + const time = $A.dayjs(serverDate).unix() if (total > 0) { callData.updated = time hasUpdate = true