69 lines
2.9 KiB
JavaScript
69 lines
2.9 KiB
JavaScript
async function loadConfigs() {
|
|
try {
|
|
const response = await fetch('/api/config');
|
|
const result = await response.json();
|
|
|
|
if (result.success) {
|
|
renderConfigList(result.data);
|
|
} else {
|
|
alert('加载配置失败: ' + result.message);
|
|
}
|
|
} catch (error) {
|
|
alert('加载配置失败: ' + error.message);
|
|
}
|
|
}
|
|
|
|
// 渲染配置列表
|
|
function renderConfigList(configs) {
|
|
const tbody = document.getElementById('config-list');
|
|
|
|
if (configs.length === 0) {
|
|
tbody.innerHTML = '<tr><td colspan="6" class="empty">暂无配置,请点击"创建配置"按钮</td></tr>';
|
|
return;
|
|
}
|
|
|
|
tbody.innerHTML = configs.map(config => `
|
|
<tr>
|
|
<td>${config.config_name}</td>
|
|
<td>${config.split_type === 'company_id' ? '按企业ID' : '按用户ID'}</td>
|
|
<td>${config.split_name || config.split_value}</td>
|
|
<td>${config.selected_fields.length}</td>
|
|
<td>
|
|
<span class="status-badge ${config.is_active ? 'status-active' : 'status-inactive'}">
|
|
${config.is_active ? '已启用' : '已禁用'}
|
|
</span>
|
|
</td>
|
|
<td>
|
|
<div class="action-buttons">
|
|
<button class="btn btn-sm btn-warning" onclick="toggleConfig(${config.id})">
|
|
${config.is_active ? '禁用' : '启用'}
|
|
</button>
|
|
<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>
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
`).join('');
|
|
}
|
|
|
|
// 显示创建模态框
|
|
function showCreateModal() {
|
|
editingConfigId = null;
|
|
document.getElementById('modal-title').textContent = '创建配置';
|
|
document.getElementById('config-name').value = '';
|
|
document.getElementById('split-type').value = '';
|
|
document.getElementById('split-value').innerHTML = '<option value="">请先选择拆分方式</option>';
|
|
|
|
// 重置字段自定义名头
|
|
fieldCustomNames = {};
|
|
|
|
// 重置合并特来电配置
|
|
const mergeTelecomCheckbox = document.getElementById('merge-telecom');
|
|
const telecomVehicleNoInput = document.getElementById('telecom-vehicle-no');
|
|
const mergeTelecomGroup = document.getElementById('merge-telecom-group');
|
|
if (mergeTelecomCheckbox) mergeTelecomCheckbox.checked = false;
|
|
if (telecomVehicleNoInput) telecomVehicleNoInput.value = '';
|