mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 11:19:56 +00:00
perf: 优化仪表盘任务更新规则
This commit is contained in:
parent
c16e37023c
commit
46a623b430
23
resources/assets/js/functions/common.js
vendored
23
resources/assets/js/functions/common.js
vendored
@ -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 {
|
||||
|
||||
14
resources/assets/js/store/actions.js
vendored
14
resources/assets/js/store/actions.js
vendored
@ -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))
|
||||
|
||||
5
resources/assets/js/store/utils.js
vendored
5
resources/assets/js/store/utils.js
vendored
@ -34,15 +34,16 @@ function __callData(key, requestData, state) {
|
||||
* @param total
|
||||
* @param current_page
|
||||
* @param deleted_id
|
||||
* @param serverDate
|
||||
* @returns {Promise<unknown>}
|
||||
*/
|
||||
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user