index.html 16.8 KB
<!DOCTYPE html>
<!-- 
文件名: app/templates/index.html 
职责: WebUI 主页面结构,提供任务控制、数据查询、文件上传、模板选择等交互界面。
注意: 不要删除这个注释。
-->
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>问界门店运营数据分析平台</title>
    <link rel="stylesheet" href="/static/css/style.css">
</head>
<body>
    <!-- 顶部导航栏 -->
    <header>
        <div class="logo">问界运营分析平台</div>
        <nav class="nav-links">
            <div class="nav-item active" data-module="task">任务调度</div>
            <div class="nav-item" data-module="catalog">数据目录</div>
            <div class="nav-item" data-module="upload">数据上传</div>
            <div class="nav-item" data-module="analysis">数据分析</div>
        </nav>
        <div class="user-info">管理员</div>
    </header>

    <main>
        <!-- 左侧明细导航栏 -->
        <aside id="sidebar">
            <div class="menu-group">
                <div class="menu-title">任务管理</div>
                <div class="menu-item active">ODS 同步任务</div>
                <div class="menu-item">DWS/DWM/DWA 任务</div>
                <div class="menu-item">历史任务查询</div>
            </div>
            <div class="menu-group">
                <div class="menu-title">系统配置</div>
                <div class="menu-item">同步元数据</div>
                <div class="menu-item">调度设置</div>
            </div>
        </aside>

        <!-- 右侧内容展示区 -->
        <section id="content-area">
            <div class="card">
                <h2 id="content-title">任务调度</h2>
                <div id="content-body">
                    <!-- 任务配置部分 (仅 ODS) -->
                    <div id="task-config-section" style="display:none; margin-bottom: 30px;">
                        <h3 style="margin-bottom:15px; font-size: 16px; color: #666;">定时任务配置</h3>
                        <div class="config-grid" style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; background: #f8f9fa; padding: 15px; border-radius: 4px;">
                            <div><strong>任务ID:</strong> <span id="conf-task-id">-</span></div>
                            <div><strong>状态:</strong> <span id="conf-status">-</span></div>
                            <div><strong>下次执行:</strong> <span id="conf-next-run">-</span></div>
                            <div><strong>触发器:</strong> <span id="conf-trigger">-</span></div>
                        </div>
                        <div style="margin-top: 15px;">
                            <button id="btn-run-ods" style="padding: 8px 16px; background: #1890ff; color: white; border: none; border-radius: 4px; cursor: pointer;">立即同步 ODS</button>
                        </div>
                    </div>

                    <!-- DW 加工控制部分 (DWS/DWM/DWA) -->
                    <div id="dw-process-section" style="display:none; margin-bottom: 30px; background: #f0f5ff; padding: 20px; border-radius: 8px;">
                        <h3 style="margin-bottom:15px; font-size: 16px; color: #1890ff;">数据加工控制</h3>
                        <div style="display: flex; gap: 15px; align-items: center; flex-wrap: wrap;">
                            <div>
                                <label>加工层级: </label>
                                <select id="dw-layer-select" style="padding: 5px;">
                                    <option value="DWS">DWS (宽表层)</option>
                                    <option value="DWM">DWM (指标层)</option>
                                    <option value="DWA">DWA (应用层)</option>
                                </select>
                            </div>
                            <div>
                                <label>开始日期: </label>
                                <input type="date" id="dw-start-date" style="padding: 4px;">
                            </div>
                            <div>
                                <label>结束日期: </label>
                                <input type="date" id="dw-end-date" style="padding: 4px;">
                            </div>
                            <div>
                                <label style="display: flex; align-items: center; gap: 4px; cursor: pointer; font-weight: normal;">
                                    <input type="checkbox" id="dw-full-sync" style="width: 16px; height: 16px;">
                                    全量覆盖
                                </label>
                            </div>
                            <button id="btn-run-dw" style="padding: 6px 20px; background: #52c41a; color: white; border: none; border-radius: 4px; cursor: pointer;">开始加工</button>
                        </div>
                        <p style="margin-top: 10px; font-size: 12px; color: #888;">* 提示:默认执行增量同步(最近一天),勾选"全量覆盖"后执行全量覆盖加工。指定日期范围时按日期范围处理。</p>
                    </div>

                    <!-- 历史记录部分 -->
                    <div id="task-history-section" style="display:none;">
                        <h3 style="margin-bottom:15px; font-size: 16px; color: #666;">执行历史记录</h3>
                        <table class="data-table" style="width: 100%; border-collapse: collapse;">
                            <thead>
                                <tr style="background: #fafafa; border-bottom: 1px solid #f0f0f0;">
                                    <th style="padding: 12px; text-align: left;">开始时间</th>
                                    <th style="padding: 12px; text-align: left;">数据范围</th>
                                    <th style="padding: 12px; text-align: left;">涉及表数</th>
                                    <th style="padding: 12px; text-align: left;">状态</th>
                                    <th style="padding: 12px; text-align: left;">详情</th>
                                </tr>
                            </thead>
                            <tbody id="history-tbody">
                                <!-- 数据动态加载 -->
                            </tbody>
                        </table>
                    </div>

                    <!-- 数据上传部分 -->
                    <div id="data-upload-section" style="display:none;">
                        <div style="background: #fff; border: 1px dashed #d9d9d9; padding: 30px; text-align: center; border-radius: 8px; margin-bottom: 20px;">
                            <input type="file" id="excel-file" style="display: none;" accept=".xlsx, .xls">
                            <div id="drop-zone" style="cursor: pointer;">
                                <div style="font-size: 40px; color: #1890ff; margin-bottom: 10px;">📤</div>
                                <p id="file-display-name">点击或将 Excel 文件拖拽到此处上传</p>
                                <p style="font-size: 12px; color: #999;">支持 .xlsx, .xls 格式</p>
                            </div>
                        </div>
                        
                        <div class="upload-form" style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; background: #fafafa; padding: 20px; border-radius: 8px;">
                            <div>
                                <label style="display: block; margin-bottom: 8px; font-weight: bold;">上传模式:</label>
                                <select id="upload-mode-select" style="width: 100%; padding: 8px; border: 1px solid #d9d9d9; border-radius: 4px;">
                                    <option value="dynamic">智能分析模式 (LLM 自动识别结构)</option>
                                    <option value="ods">固定表模式 (ODS 层同步)</option>
                                </select>
                            </div>
                            
                            <div id="ods-table-select-div" style="display:none;">
                                <label style="display: block; margin-bottom: 8px; font-weight: bold;">目标 ODS 表:</label>
                                <select id="upload-table-name" style="width: 100%; padding: 8px; border: 1px solid #d9d9d9; border-radius: 4px;">
                                    <option value="ods_staff_daily_report_huawei">员工日报华为表 (ODS)</option>
                                    <option value="ods_goods_order">商品订单主表 (ODS)</option>
                                    <option value="ods_host_plant_delivery">主机厂交付数据 (ODS)</option>
                                </select>
                            </div>

                            <div id="dynamic-type-select-div">
                                <label style="display: block; margin-bottom: 8px; font-weight: bold;">分析数据类型:</label>
                                <select id="upload-type-select" style="width: 100%; padding: 8px; border: 1px solid #d9d9d9; border-radius: 4px;">
                                    <option value="分析的门店列表">分析的门店列表</option>
                                    <option value="主机厂数据表">主机厂数据表</option>
                                    <option value="赔付方案数据表">赔付方案数据表</option>
                                </select>
                            </div>

                            <div>
                                <label style="display: block; margin-bottom: 8px; font-weight: bold;">版本标识 (可选):</label>
                                <input type="text" id="upload-version-tag" placeholder="如: 202406_v1" style="width: 100%; padding: 8px; border: 1px solid #d9d9d9; border-radius: 4px;">
                            </div>
                        </div>

                        <div style="margin-top: 20px; text-align: center;">
                            <button id="btn-do-upload" style="padding: 10px 40px; background: #52c41a; color: white; border: none; border-radius: 4px; font-size: 16px; cursor: pointer; transition: all 0.3s;">
                                开始解析并上传
                            </button>
                        </div>

                        <div id="upload-status-tip" style="margin-top: 20px; display: none; padding: 15px; background: #e6f7ff; border: 1px solid #91d5ff; border-radius: 4px;">
                            <span style="color: #1890ff;">ℹ️ 正在处理中,您可以前往“数据目录”查看已生成的表。</span>
                        </div>
                    </div>

                    <!-- 数据分析部分 -->
                    <div id="data-analysis-section" style="display:none;">
                        <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px;">
                            <!-- 步骤1: 上传门店列表 -->
                            <div style="background: #f8f9fa; padding: 20px; border-radius: 8px; border: 1px solid #e8e8e8;">
                                <h3 style="margin:0 0 12px; font-size:16px; color:#333;">步骤1: 上传门店列表</h3>
                                <div id="store-drop-zone" style="border: 1px dashed #d9d9d9; padding: 20px; text-align: center; border-radius: 4px; cursor: pointer; background: #fff;">
                                    <input type="file" id="store-file-input" style="display:none;" accept=".xlsx,.xls">
                                    <div style="font-size:30px; margin-bottom:8px;">🏪</div>
                                    <p id="store-file-name" style="margin:0; font-size:13px; color:#999;">点击选择门店列表文件</p>
                                    <a href="/api/analysis/template/store" style="font-size:12px; color:#1890ff; text-decoration:none; margin-top:8px; display:inline-block;">
                                        📥 下载门店列表模板
                                    </a>
                                </div>
                            </div>

                            <!-- 步骤2: 上传主机厂数据 -->
                            <div style="background: #f8f9fa; padding: 20px; border-radius: 8px; border: 1px solid #e8e8e8;">
                                <h3 style="margin:0 0 12px; font-size:16px; color:#333;">步骤2: 上传主机厂数据</h3>
                                <div id="factory-drop-zone" style="border: 1px dashed #d9d9d9; padding: 20px; text-align: center; border-radius: 4px; cursor: pointer; background: #fff;">
                                    <input type="file" id="factory-file-input" style="display:none;" accept=".xlsx,.xls">
                                    <div style="font-size:30px; margin-bottom:8px;">🏭</div>
                                    <p id="factory-file-name" style="margin:0; font-size:13px; color:#999;">点击选择主机厂数据文件</p>
                                    <p style="font-size:11px; color:#faad14; margin:4px 0;" title="Sheet名称需包含时间范围">⚠ Sheet名包含时间范围(如: (5.26-6.21))</p>
                                    <a href="/api/analysis/template/factory" style="font-size:12px; color:#1890ff; text-decoration:none; margin-top:4px; display:inline-block;">
                                        📥 下载主机厂数据模板
                                    </a>
                                </div>
                            </div>
                        </div>

                        <!-- 步骤3: 生成报表 -->
                        <div style="text-align: center; margin: 20px 0;">
                            <button id="btn-generate-report" style="padding: 12px 48px; background: #1890ff; color: white; border: none; border-radius: 6px; font-size: 16px; cursor: pointer; transition: all 0.3s;">
                                🚀 开始生成分析报表
                            </button>
                            <p style="font-size:12px; color:#999; margin-top:8px;">根据门店数据与主机厂数据,自动计算生态系数并生成Excel报表</p>
                            <p style="font-size:11px; color:#faad14;">📌 表头参考: <a href="/api/analysis/template/output" style="color:#1890ff;">输出样例</a></p>
                        </div>

                        <!-- 生成结果提示 -->
                        <div id="analysis-result" style="display:none; background: #f6ffed; border: 1px solid #b7eb8f; padding: 20px; border-radius: 8px; text-align: center;">
                            <h3 style="color:#52c41a; margin:0 0 10px;">✅ 报表生成成功</h3>
                            <div id="analysis-result-info" style="font-size:13px; color:#666; margin-bottom:15px;"></div>
                            <a id="btn-download-report" href="/api/analysis/download" 
                               style="display:inline-block; padding: 10px 32px; background: #52c41a; color: white; border: none; border-radius: 4px; font-size: 14px; text-decoration: none; cursor: pointer;">
                                📥 下载分析报表
                            </a>
                        </div>

                        <div id="analysis-error" style="display:none; background: #fff2f0; border: 1px solid #ffccc7; padding: 20px; border-radius: 8px; text-align: center;">
                            <h3 style="color:#f5222d; margin:0 0 10px;">❌ 报表生成失败</h3>
                            <p id="analysis-error-msg" style="margin:0; color:#666;"></p>
                        </div>
                    </div>

                    <div id="welcome-message">
                        <p>欢迎来到问界门店运营数据分析平台。请从左侧选择具体功能进行操作。</p>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <!-- 任务详情弹窗 (Modal) -->
    <div id="detail-modal" class="modal">
        <div class="modal-content">
            <div class="modal-header">
                <h3>任务执行详情</h3>
                <span class="close-btn" onclick="closeModal()">&times;</span>
            </div>
            <div class="modal-body">
                <table class="detail-table">
                    <thead>
                        <tr>
                            <th>源表/内容</th>
                            <th>目标表</th>
                            <th>时间范围</th>
                            <th>影响行数</th>
                            <th>状态</th>
                        </tr>
                    </thead>
                    <tbody id="detail-tbody">
                        <!-- 动态渲染 -->
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <script src="/static/js/app.js"></script>
</body>
</html>