增加求和采集和细节修改
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
// 当前配置列表缓存(用于乐观更新)
|
||||
let currentConfigList = [];
|
||||
|
||||
// 加载配置列表
|
||||
async function loadConfigs() {
|
||||
try {
|
||||
@@ -5,7 +8,8 @@ async function loadConfigs() {
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
renderConfigList(result.data);
|
||||
currentConfigList = result.data;
|
||||
renderConfigList(currentConfigList);
|
||||
} else {
|
||||
alert('加载配置失败:' + result.message);
|
||||
}
|
||||
@@ -23,7 +27,10 @@ function renderConfigList(configs) {
|
||||
return;
|
||||
}
|
||||
|
||||
tbody.innerHTML = configs.map(config => `
|
||||
tbody.innerHTML = configs.map((config, index) => {
|
||||
const isFirst = index === 0;
|
||||
const isLast = index === configs.length - 1;
|
||||
return `
|
||||
<tr>
|
||||
<td>${config.config_name}</td>
|
||||
<td>${config.split_type === 'company_id' ? '按企业 ID' : config.split_type === 'user_id' ? '按用户 ID' : '按场站 ID'}</td>
|
||||
@@ -41,11 +48,11 @@ function renderConfigList(configs) {
|
||||
<button class="btn btn-sm btn-primary" onclick="editConfig(${config.id})">编辑</button>
|
||||
<button class="btn btn-sm btn-success" onclick="copyConfig(${config.id})">复制</button>
|
||||
<button class="btn btn-sm btn-danger" onclick="deleteConfig(${config.id})">删除</button>
|
||||
<button class="btn btn-sm" onclick="moveConfig(${config.id}, 'up')">↑</button>
|
||||
<button class="btn btn-sm" onclick="moveConfig(${config.id}, 'down')">↓</button>
|
||||
<button class="btn btn-sm" onclick="moveConfig(${config.id}, 'up')" ${isFirst ? 'disabled style="opacity:0.4;cursor:not-allowed;"' : ''}>↑</button>
|
||||
<button class="btn btn-sm" onclick="moveConfig(${config.id}, 'down')" ${isLast ? 'disabled style="opacity:0.4;cursor:not-allowed;"' : ''}>↓</button>
|
||||
</td>
|
||||
</tr>
|
||||
`).join('');
|
||||
`}).join('');
|
||||
}
|
||||
|
||||
function showCreateModal() {
|
||||
@@ -776,6 +783,21 @@ async function toggleConfig(configId) {
|
||||
|
||||
// 移动配置
|
||||
async function moveConfig(configId, direction) {
|
||||
// 找到当前配置索引
|
||||
const currentIndex = currentConfigList.findIndex(c => c.id === configId);
|
||||
if (currentIndex === -1) return;
|
||||
|
||||
// 边界检查
|
||||
const targetIndex = direction === 'up' ? currentIndex - 1 : currentIndex + 1;
|
||||
if (targetIndex < 0 || targetIndex >= currentConfigList.length) return;
|
||||
|
||||
// 乐观更新:先在前端交换,立即刷新UI
|
||||
const temp = currentConfigList[currentIndex];
|
||||
currentConfigList[currentIndex] = currentConfigList[targetIndex];
|
||||
currentConfigList[targetIndex] = temp;
|
||||
renderConfigList(currentConfigList);
|
||||
|
||||
// 异步同步到后端
|
||||
try {
|
||||
const response = await fetch(`/api/config/${configId}/move`, {
|
||||
method: 'POST',
|
||||
@@ -784,12 +806,28 @@ async function moveConfig(configId, direction) {
|
||||
});
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
loadConfigs();
|
||||
} else {
|
||||
if (!result.success) {
|
||||
// 失败了就回滚
|
||||
const rollbackIndex = currentConfigList.findIndex(c => c.id === configId);
|
||||
const rollbackTarget = direction === 'up' ? rollbackIndex + 1 : rollbackIndex - 1;
|
||||
if (rollbackTarget >= 0 && rollbackTarget < currentConfigList.length) {
|
||||
const temp = currentConfigList[rollbackIndex];
|
||||
currentConfigList[rollbackIndex] = currentConfigList[rollbackTarget];
|
||||
currentConfigList[rollbackTarget] = temp;
|
||||
renderConfigList(currentConfigList);
|
||||
}
|
||||
alert('移动失败: ' + result.message);
|
||||
}
|
||||
} catch (error) {
|
||||
// 网络错误也回滚
|
||||
const rollbackIndex = currentConfigList.findIndex(c => c.id === configId);
|
||||
const rollbackTarget = direction === 'up' ? rollbackIndex + 1 : rollbackIndex - 1;
|
||||
if (rollbackTarget >= 0 && rollbackTarget < currentConfigList.length) {
|
||||
const temp = currentConfigList[rollbackIndex];
|
||||
currentConfigList[rollbackIndex] = currentConfigList[rollbackTarget];
|
||||
currentConfigList[rollbackTarget] = temp;
|
||||
renderConfigList(currentConfigList);
|
||||
}
|
||||
alert('移动失败: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user