完整版V1 加入爬虫功能

This commit is contained in:
root
2026-06-09 03:36:30 +08:00
parent 34d76cce74
commit a68b83fcbd
69 changed files with 5058 additions and 56 deletions
@@ -57,6 +57,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
},
{field: 'order_limit', title: __('Order_limit'), operate: false},
{field: 'assign_ratio', title: __('Assign_ratio'), operate: false},
{field: 'ticket_total', title: __('Ticket_total'), operate: false, sortable: true},
{field: 'complete_count', title: __('Complete_count'), operate: false, sortable: true},
{
field: 'ticket_progress_text',
@@ -117,14 +118,130 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
});
Table.api.bindevent(table);
Controller.api.syncingTicketIds = [];
window.__splitTicketPendingPostAddSyncIds = window.__splitTicketPendingPostAddSyncIds || [];
table.on('load-success.bs.table', function () {
var pendingIds = window.__splitTicketPendingPostAddSyncIds;
if (!pendingIds || !pendingIds.length) {
return;
}
window.__splitTicketPendingPostAddSyncIds = [];
Controller.api.startBackgroundSync(table, pendingIds, false);
});
table.on('check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table', function () {
var ids = Table.api.selectedids(table);
$('.btn-sync').toggleClass('btn-disabled disabled', ids.length === 0);
});
$('.btn-sync').on('click', function (e) {
e.preventDefault();
e.stopPropagation();
var ids = Table.api.selectedids(table);
if (!ids.length) {
Toastr.error(__('Please select at least one record'));
return false;
}
var syncConfirmMsg = (typeof Config.syncConfirmMsg !== 'undefined' && Config.syncConfirmMsg)
? Config.syncConfirmMsg
: '确定同步所选工单吗?任务将在后台执行,完成后自动提示结果。';
var syncBackgroundMsg = (typeof Config.syncBackgroundStartedMsg !== 'undefined' && Config.syncBackgroundStartedMsg)
? Config.syncBackgroundStartedMsg
: '同步任务已在后台执行,请稍候…';
Layer.confirm(syncConfirmMsg, {icon: 3, title: __('Sync_status_btn')}, function (index) {
Layer.close(index);
Toastr.info(syncBackgroundMsg);
Controller.api.startBackgroundSync(table, ids, true);
});
return false;
});
},
add: function () {
Controller.api.bindevent();
Form.api.bindevent($('form[role=form]'), function (data, ret) {
var ticketId = ret.data && ret.data.id ? parseInt(ret.data.id, 10) : 0;
var syncTicketMsg = (typeof Config.syncTicketStartedMsg !== 'undefined' && Config.syncTicketStartedMsg)
? Config.syncTicketStartedMsg
: '正在同步工单';
if (ticketId > 0) {
parent.__splitTicketPendingPostAddSyncIds = parent.__splitTicketPendingPostAddSyncIds || [];
parent.__splitTicketPendingPostAddSyncIds.push(ticketId);
}
if (parent && parent.Toastr) {
parent.Toastr.info(syncTicketMsg);
}
parent.$('.btn-refresh').trigger('click');
if (window.name) {
var layerIndex = parent.Layer.getFrameIndex(window.name);
parent.Layer.close(layerIndex);
}
return false;
});
Controller.api.fixSelectPlaceholder();
Controller.api.bindNumberTypeToggle();
Controller.api.bindEndTimeCheck();
},
edit: function () {
Controller.api.bindevent();
},
api: {
/** @type {number[]} 正在手动同步的工单 ID */
syncingTicketIds: [],
/**
* 后台同步:标记「同步中」并请求 sync 接口
*
* @param {object} table bootstrapTable 实例
* @param {number[]} ids 工单 ID
* @param {boolean} disableSyncBtn 是否禁用工具栏同步按钮
*/
startBackgroundSync: function (table, ids, disableSyncBtn) {
ids = (ids || []).map(function (id) {
return parseInt(id, 10);
}).filter(function (id) {
return !isNaN(id) && id > 0;
});
if (!ids.length) {
return;
}
Controller.api.markTicketsSyncing(table, ids);
if (disableSyncBtn) {
$('.btn-sync').addClass('btn-disabled disabled');
}
Fast.api.ajax({
url: 'split.ticket/sync',
data: {ids: ids.join(',')},
loading: false
}, function () {
Controller.api.finishTicketsSync(table);
}, function () {
Controller.api.finishTicketsSync(table);
});
},
/**
* 将选中工单标记为「同步中」并刷新列表展示(不请求后端)
*/
markTicketsSyncing: function (table, ids) {
Controller.api.syncingTicketIds = (ids || []).map(function (id) {
return parseInt(id, 10);
}).filter(function (id) {
return !isNaN(id) && id > 0;
});
var data = table.bootstrapTable('getData');
table.bootstrapTable('load', data);
},
/**
* 同步结束:清除标记并刷新列表数据
*/
finishTicketsSync: function (table) {
Controller.api.syncingTicketIds = [];
table.bootstrapTable('refresh');
var ids = Table.api.selectedids(table);
$('.btn-sync').toggleClass('btn-disabled disabled', ids.length === 0);
},
formatter: {
/**
* 工单类型:纯文本展示,无链接/标签样式
@@ -168,9 +285,27 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
return String(total);
},
syncDisplay: function (value, row) {
var rowId = parseInt(row.id, 10);
if (Controller.api.syncingTicketIds.indexOf(rowId) !== -1) {
return Controller.api.formatter.syncingDisplayHtml();
}
var text = value || '';
var color = row.sync_status === 'success' ? 'success' : 'danger';
var color = 'danger';
if (row.sync_status === 'success') {
color = 'success';
} else if (row.sync_status === 'pending') {
color = 'muted';
}
return '<span class="text-' + color + '">' + Fast.api.escape(text) + '</span>';
},
syncingDisplayHtml: function () {
var label = (typeof Config.syncInProgressMsg !== 'undefined' && Config.syncInProgressMsg)
? Config.syncInProgressMsg
: '同步中';
return '<span class="split-ticket-sync-pending">'
+ '<i class="fa fa-refresh fa-spin"></i>'
+ '<span class="split-ticket-sync-label">' + Fast.api.escape(label) + '</span>'
+ '</span>';
}
},
bindevent: function () {