refactor: 重构项目结构,按功能模块拆分文件
- 后端:将 app.py 拆分为 lib/api/ 目录下的多个蓝图模块 - config_api.py: 配置管理 API - entity_api.py: 实体管理 API - field_api.py: 字段列表 API - report_api.py: 日报生成和历史记录 API - init_api.py: 数据库初始化 API - download_api.py: 文件下载 API - 前端:将 index.html 拆分为多个文件 - static/css/style.css: CSS 样式 - static/js/common.js: 通用工具函数 - static/js/config.js: 配置管理 - static/js/entity.js: 实体管理 - static/js/report.js: 日报生成 - static/js/history.js: 历史记录 - 更新 app.py 使用蓝图注册 API - 创建 AGENTS.md 项目文档 Coze-Commit-Type: user Coze-User-ID: 3722323274763196 Coze-Conversation-ID: 9894087
This commit is contained in:
108
static/js/entity.js
Normal file
108
static/js/entity.js
Normal file
@@ -0,0 +1,108 @@
|
||||
// 加载企业/用户列表(支持分页和搜索)
|
||||
async function loadEntities(page = 1, search = '') {
|
||||
const splitType = document.getElementById('split-type').value;
|
||||
const select = document.getElementById('split-value');
|
||||
|
||||
// 显示/隐藏合并特来电选项(仅按企业拆分时显示)
|
||||
const mergeTelecomGroup = document.getElementById('merge-telecom-group');
|
||||
if (mergeTelecomGroup) {
|
||||
mergeTelecomGroup.style.display = splitType === 'company_id' ? 'block' : 'none';
|
||||
if (splitType !== 'company_id') {
|
||||
document.getElementById('merge-telecom').checked = false;
|
||||
toggleTelecomVehicleNo();
|
||||
}
|
||||
}
|
||||
|
||||
if (!splitType) {
|
||||
select.innerHTML = '<option value="">请先选择拆分方式</option>';
|
||||
return;
|
||||
}
|
||||
|
||||
// 保存当前状态
|
||||
currentEntityType = splitType === 'company_id' ? 'company' :
|
||||
splitType === 'user_id' ? 'user' :
|
||||
splitType === 'station_id' ? 'station' : '';
|
||||
entityPage = page;
|
||||
currentSearch = search;
|
||||
|
||||
select.innerHTML = '<option value="">加载中...</option>';
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/entities?type=${currentEntityType}&page=${page}&page_size=${entityPageSize}&search=${encodeURIComponent(search)}`);
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
const entities = result.data;
|
||||
const total = result.total || 0;
|
||||
const totalPages = Math.ceil(total / entityPageSize);
|
||||
|
||||
if (entities.length === 0) {
|
||||
select.innerHTML = '<option value="">无数据</option>';
|
||||
} else {
|
||||
select.innerHTML = entities.map(e => {
|
||||
let value = '';
|
||||
let name = '';
|
||||
let typeLabel = '';
|
||||
|
||||
if (splitType === 'company_id') {
|
||||
value = e.company_id;
|
||||
name = e.company_name;
|
||||
} else if (splitType === 'user_id') {
|
||||
value = e.user_id;
|
||||
name = e.user_name;
|
||||
typeLabel = e.order_type === 3 ? '(企业用户)' : '(普通用户)';
|
||||
if (e.phone) {
|
||||
name = `${e.user_name} (${e.phone})`;
|
||||
}
|
||||
} else if (splitType === 'station_id') {
|
||||
value = e.station_id;
|
||||
name = e.station_name;
|
||||
}
|
||||
|
||||
return `<option value="${value}" data-name="${name}">${name} ${typeLabel}</option>`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
// 更新分页UI
|
||||
updatePagination(totalPages, total);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载列表失败:', error);
|
||||
select.innerHTML = '<option value="">加载失败</option>';
|
||||
}
|
||||
}
|
||||
|
||||
// 更新分页UI
|
||||
function updatePagination(totalPages, total) {
|
||||
const paginationDiv = document.getElementById('entity-pagination');
|
||||
if (totalPages <= 1) {
|
||||
paginationDiv.innerHTML = `<small class="text-muted">共 ${total} 条</small>`;
|
||||
return;
|
||||
}
|
||||
|
||||
let html = `<small class="text-muted">共 ${total} 条</small>`;
|
||||
html += `<button type="button" class="btn btn-sm btn-secondary" onclick="loadEntities(${entityPage - 1}, currentSearch)" ${entityPage <= 1 ? 'disabled' : ''}>上一页</button>`;
|
||||
html += `<span>${entityPage}/${totalPages}</span>`;
|
||||
html += `<button type="button" class="btn btn-sm btn-secondary" onclick="loadEntities(${entityPage + 1}, currentSearch)" ${entityPage >= totalPages ? 'disabled' : ''}>下一页</button>`;
|
||||
|
||||
paginationDiv.innerHTML = html;
|
||||
}
|
||||
|
||||
// 搜索实体
|
||||
function searchEntities() {
|
||||
const search = document.getElementById('entity-search').value.trim();
|
||||
loadEntities(1, search);
|
||||
}
|
||||
|
||||
// 回车搜索
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const searchInput = document.getElementById('entity-search');
|
||||
if (searchInput) {
|
||||
searchInput.addEventListener('keypress', function(e) {
|
||||
if (e.key === 'Enter') {
|
||||
searchEntities();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user