提交同步状态为异步
This commit is contained in:
@@ -244,6 +244,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
|
||||
/** @type {number[]} 正在手动同步的工单 ID */
|
||||
syncingTicketIds: [],
|
||||
syncPollTimer: null,
|
||||
syncPollStartedAt: 0,
|
||||
syncPollGraceMs: 8000,
|
||||
|
||||
/**
|
||||
* 渲染筛选结果汇总行(全量筛选数据,非当前页)
|
||||
@@ -269,7 +272,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
},
|
||||
|
||||
/**
|
||||
* 后台同步:标记「同步中」并请求 sync 接口
|
||||
* 后台同步:标记「同步中」、投递 CLI,并轮询直至锁释放
|
||||
*
|
||||
* @param {object} table bootstrapTable 实例
|
||||
* @param {number[]} ids 工单 ID
|
||||
@@ -292,13 +295,81 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
url: 'split.ticket/sync',
|
||||
data: {ids: ids.join(',')},
|
||||
loading: false
|
||||
}, function () {
|
||||
Controller.api.finishTicketsSync(table);
|
||||
}, function (data, ret) {
|
||||
var queued = (ret.data && ret.data.queued) ? ret.data.queued : ids;
|
||||
Controller.api.syncingTicketIds = (queued || []).map(function (id) {
|
||||
return parseInt(id, 10);
|
||||
}).filter(function (id) {
|
||||
return !isNaN(id) && id > 0;
|
||||
});
|
||||
if (Controller.api.syncingTicketIds.length) {
|
||||
Controller.api.startSyncPolling(table);
|
||||
} else {
|
||||
Controller.api.finishTicketsSync(table);
|
||||
}
|
||||
}, function () {
|
||||
Controller.api.finishTicketsSync(table);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* 轮询同步锁状态,全部完成后刷新列表
|
||||
*/
|
||||
startSyncPolling: function (table) {
|
||||
Controller.api.stopSyncPolling();
|
||||
if (!Controller.api.syncingTicketIds.length) {
|
||||
return;
|
||||
}
|
||||
Controller.api.syncPollStartedAt = Date.now();
|
||||
Controller.api.syncPollTimer = setInterval(function () {
|
||||
if (!Controller.api.syncingTicketIds.length) {
|
||||
Controller.api.stopSyncPolling();
|
||||
return;
|
||||
}
|
||||
Fast.api.ajax({
|
||||
url: 'split.ticket/syncpolling',
|
||||
data: {ids: Controller.api.syncingTicketIds.join(',')},
|
||||
loading: false
|
||||
}, function (data, ret) {
|
||||
var still = (ret.data && ret.data.syncing) ? ret.data.syncing : [];
|
||||
still = (still || []).map(function (id) {
|
||||
return parseInt(id, 10);
|
||||
}).filter(function (id) {
|
||||
return !isNaN(id) && id > 0;
|
||||
});
|
||||
var elapsed = Date.now() - (Controller.api.syncPollStartedAt || 0);
|
||||
var graceMs = Controller.api.syncPollGraceMs || 8000;
|
||||
if (still.length === 0 && elapsed < graceMs) {
|
||||
table.bootstrapTable('refresh', {silent: true});
|
||||
return false;
|
||||
}
|
||||
if (still.length === 0) {
|
||||
Controller.api.stopSyncPolling();
|
||||
var doneMsg = (typeof Config.syncDoneMsg !== 'undefined' && Config.syncDoneMsg)
|
||||
? Config.syncDoneMsg
|
||||
: '同步完成';
|
||||
Toastr.success(doneMsg);
|
||||
Controller.api.finishTicketsSync(table);
|
||||
return false;
|
||||
}
|
||||
if (still.join(',') !== Controller.api.syncingTicketIds.join(',')) {
|
||||
Controller.api.syncingTicketIds = still;
|
||||
var rowData = table.bootstrapTable('getData');
|
||||
table.bootstrapTable('load', rowData);
|
||||
}
|
||||
table.bootstrapTable('refresh', {silent: true});
|
||||
return false;
|
||||
});
|
||||
}, 3000);
|
||||
},
|
||||
|
||||
stopSyncPolling: function () {
|
||||
if (Controller.api.syncPollTimer) {
|
||||
clearInterval(Controller.api.syncPollTimer);
|
||||
Controller.api.syncPollTimer = null;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 将选中工单标记为「同步中」并刷新列表展示(不请求后端)
|
||||
*/
|
||||
@@ -316,6 +387,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
|
||||
* 同步结束:清除标记并刷新列表数据
|
||||
*/
|
||||
finishTicketsSync: function (table) {
|
||||
Controller.api.stopSyncPolling();
|
||||
Controller.api.syncingTicketIds = [];
|
||||
table.bootstrapTable('refresh', {
|
||||
silent: true
|
||||
|
||||
Reference in New Issue
Block a user