CI / check (push) Failing after 15m48s
Signed-off-by: 南通一次元科技有限公司 <guwangtu@icimeta.com>
3981 lines
156 KiB
HTML
3981 lines
156 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="zh-CN">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>医院审计管理系统</title>
|
||
<style>
|
||
:root {
|
||
/* ===== 主色调 - 深邃蓝系 ===== */
|
||
--primary: #1a56db;
|
||
--primary-light: #e1effe;
|
||
--primary-hover: #1e429f;
|
||
--primary-text: #1e3a8a;
|
||
--primary-gradient: linear-gradient(135deg, #1a56db 0%, #1e429f 100%);
|
||
|
||
/* ===== 中性色 - 层次分明 ===== */
|
||
--surface: #f3f4f6;
|
||
--surface-card: #ffffff;
|
||
--surface-hover: #f9fafb;
|
||
--text: #111827;
|
||
--text-secondary: #4b5563;
|
||
--text-muted: #9ca3af;
|
||
--border: #e5e7eb;
|
||
--border-light: #f3f4f6;
|
||
|
||
/* ===== 圆角 - 现代柔和 ===== */
|
||
--radius: 6px;
|
||
--radius-md: 8px;
|
||
--radius-card: 12px;
|
||
--radius-lg: 16px;
|
||
|
||
/* ===== 功能色 - 审计专用 ===== */
|
||
--success: #047857;
|
||
--success-light: #d1fae5;
|
||
--warning: #b45309;
|
||
--warning-light: #fef3c7;
|
||
--danger: #dc2626;
|
||
--danger-light: #fee2e2;
|
||
--info: #0369a1;
|
||
--info-light: #e0f2fe;
|
||
|
||
/* ===== 徽章色系 - 协调精致 ===== */
|
||
--badge-blue-bg: #dbeafe;
|
||
--badge-blue-text: #1e40af;
|
||
--badge-green-bg: #d1fae5;
|
||
--badge-green-text: #065f46;
|
||
--badge-orange-bg: #ffedd5;
|
||
--badge-orange-text: #9a3412;
|
||
--badge-red-bg: #fee2e2;
|
||
--badge-red-text: #991b1b;
|
||
--badge-gray-bg: #f3f4f6;
|
||
--badge-gray-text: #4b5563;
|
||
--badge-purple-bg: #f3e8ff;
|
||
--badge-purple-text: #6b21a8;
|
||
|
||
/* ===== 阴影层级 ===== */
|
||
--shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
|
||
--shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
|
||
--shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
|
||
--shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
|
||
}
|
||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||
body {
|
||
font-family: "Noto Sans CJK SC", "PingFang SC", system-ui, -apple-system, sans-serif;
|
||
background: var(--surface);
|
||
color: var(--text);
|
||
min-height: 100vh;
|
||
}
|
||
.app-header {
|
||
background: var(--primary-gradient);
|
||
border-bottom: none;
|
||
padding: 16px 24px;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 16px;
|
||
box-shadow: var(--shadow-md);
|
||
position: relative;
|
||
z-index: 10;
|
||
}
|
||
.app-header h1 {
|
||
font-size: 18px;
|
||
font-weight: 700;
|
||
color: #ffffff;
|
||
letter-spacing: 0.3px;
|
||
}
|
||
.app-header .subtitle {
|
||
font-size: 13px;
|
||
color: rgba(255,255,255,0.75);
|
||
font-weight: 400;
|
||
}
|
||
.app-layout {
|
||
display: flex;
|
||
height: calc(100vh - 61px);
|
||
}
|
||
.sidebar {
|
||
background: var(--surface-card);
|
||
border-right: 1px solid var(--border);
|
||
display: flex;
|
||
flex-direction: column;
|
||
width: 280px;
|
||
min-width: 200px;
|
||
max-width: 500px;
|
||
flex-shrink: 0;
|
||
box-shadow: var(--shadow-sm);
|
||
}
|
||
.sidebar-nav {
|
||
display: flex;
|
||
gap: 6px;
|
||
margin-bottom: 0;
|
||
padding: 16px 16px 12px;
|
||
border-bottom: 1px solid var(--border-light);
|
||
flex-shrink: 0;
|
||
background: linear-gradient(180deg, var(--surface-card) 0%, var(--surface-hover) 100%);
|
||
}
|
||
.sidebar h2 {
|
||
font-size: 11px;
|
||
font-weight: 700;
|
||
color: var(--text-muted);
|
||
margin: 0 0 12px;
|
||
text-transform: uppercase;
|
||
letter-spacing: 1px;
|
||
}
|
||
.sidebar-content {
|
||
flex: 1;
|
||
overflow-y: auto;
|
||
padding: 12px 16px 16px;
|
||
}
|
||
.resizer {
|
||
width: 6px;
|
||
cursor: col-resize;
|
||
background: transparent;
|
||
transition: background 0.15s;
|
||
flex-shrink: 0;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
}
|
||
.resizer:hover { background: var(--border); }
|
||
.resizer.resizing { background: var(--primary); }
|
||
.resizer-line {
|
||
width: 2px;
|
||
height: 32px;
|
||
background: var(--border);
|
||
border-radius: 1px;
|
||
}
|
||
.resizer:hover .resizer-line,
|
||
.resizer.resizing .resizer-line { background: var(--primary); }
|
||
.main-content {
|
||
flex: 1;
|
||
padding: 24px;
|
||
overflow-y: auto;
|
||
min-width: 0;
|
||
position: relative;
|
||
background-image: url('/static/1.png');
|
||
background-size: cover;
|
||
background-position: center;
|
||
background-repeat: no-repeat;
|
||
background-attachment: fixed;
|
||
}
|
||
.main-content::before {
|
||
content: '';
|
||
position: absolute;
|
||
top: 0; left: 0; right: 0; bottom: 0;
|
||
background: linear-gradient(180deg, rgba(255,255,255,0.92) 0%, rgba(255,255,255,0.88) 50%, rgba(255,255,255,0.92) 100%);
|
||
pointer-events: none;
|
||
z-index: 0;
|
||
}
|
||
.main-content > * {
|
||
position: relative;
|
||
z-index: 1;
|
||
}
|
||
.nav-tab {
|
||
flex: 1;
|
||
padding: 8px 12px;
|
||
border: 1px solid var(--border);
|
||
border-radius: var(--radius-md);
|
||
background: var(--surface-card);
|
||
cursor: pointer;
|
||
font-size: 13px;
|
||
font-weight: 500;
|
||
text-align: center;
|
||
transition: all 0.2s ease;
|
||
box-shadow: var(--shadow-sm);
|
||
}
|
||
.nav-tab:hover {
|
||
border-color: var(--primary);
|
||
color: var(--primary);
|
||
transform: translateY(-1px);
|
||
box-shadow: var(--shadow);
|
||
}
|
||
.nav-tab.active {
|
||
background: var(--primary-gradient);
|
||
color: #fff;
|
||
border-color: transparent;
|
||
box-shadow: var(--shadow-md);
|
||
font-weight: 600;
|
||
}
|
||
.project-item, .data-table-item {
|
||
padding: 10px 12px;
|
||
border-radius: var(--radius-md);
|
||
cursor: pointer;
|
||
margin-bottom: 4px;
|
||
transition: all 0.2s ease;
|
||
font-size: 14px;
|
||
border: 1px solid transparent;
|
||
}
|
||
.project-item:hover, .data-table-item:hover {
|
||
background: var(--surface-hover);
|
||
border-color: var(--border);
|
||
transform: translateX(2px);
|
||
box-shadow: var(--shadow-sm);
|
||
}
|
||
.project-item.active, .data-table-item.active {
|
||
background: linear-gradient(90deg, var(--primary-light) 0%, rgba(225,239,254,0.5) 100%);
|
||
border-left: 3px solid var(--primary);
|
||
border-color: var(--primary-light);
|
||
box-shadow: var(--shadow-sm);
|
||
}
|
||
.project-item .name { font-size: 14px; font-weight: 600; color: var(--text); }
|
||
.project-item .meta { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
|
||
|
||
/* 树形菜单样式 */
|
||
.tree-node { margin-bottom: 2px; }
|
||
.tree-node-header {
|
||
display: flex;
|
||
align-items: center;
|
||
padding: 7px 10px;
|
||
border-radius: var(--radius-md);
|
||
cursor: pointer;
|
||
transition: all 0.2s ease;
|
||
font-size: 13px;
|
||
user-select: none;
|
||
border: 1px solid transparent;
|
||
}
|
||
.tree-node-header:hover {
|
||
background: var(--surface-hover);
|
||
border-color: var(--border);
|
||
box-shadow: var(--shadow-sm);
|
||
}
|
||
.tree-toggle {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
width: 18px;
|
||
height: 18px;
|
||
margin-right: 6px;
|
||
font-size: 10px;
|
||
color: var(--text-muted);
|
||
transition: transform 0.2s ease;
|
||
flex-shrink: 0;
|
||
border-radius: var(--radius);
|
||
}
|
||
.tree-toggle:hover { background: var(--surface); }
|
||
.tree-toggle.expanded { transform: rotate(90deg); }
|
||
.tree-toggle.empty { visibility: hidden; }
|
||
.tree-label {
|
||
flex: 1;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
}
|
||
.tree-badge {
|
||
font-size: 10px;
|
||
font-weight: 600;
|
||
color: var(--text-muted);
|
||
margin-left: 6px;
|
||
background: var(--surface);
|
||
padding: 1px 6px;
|
||
border-radius: 999px;
|
||
}
|
||
.tree-children {
|
||
margin-left: 16px;
|
||
display: none;
|
||
}
|
||
.tree-children.show { display: block; }
|
||
|
||
/* 层级颜色区分 */
|
||
.tree-lvl-1 .tree-label { font-weight: 700; font-size: 14px; color: var(--text); }
|
||
.tree-lvl-2 .tree-label { font-weight: 600; color: var(--text-secondary); }
|
||
.tree-lvl-3 .tree-label { font-weight: 500; color: var(--text-secondary); }
|
||
.tree-lvl-4 .tree-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
|
||
|
||
.tree-step-header {
|
||
display: flex;
|
||
align-items: center;
|
||
padding: 7px 10px;
|
||
border-radius: var(--radius-md);
|
||
cursor: pointer;
|
||
transition: all 0.2s ease;
|
||
font-size: 12px;
|
||
margin-left: 16px;
|
||
border: 1px solid transparent;
|
||
}
|
||
.tree-step-header:hover {
|
||
background: var(--surface-hover);
|
||
border-color: var(--border);
|
||
box-shadow: var(--shadow-sm);
|
||
}
|
||
.tree-step-header.active {
|
||
background: linear-gradient(90deg, var(--primary-light) 0%, rgba(225,239,254,0.5) 100%);
|
||
color: var(--primary-text);
|
||
font-weight: 700;
|
||
border-left: 3px solid var(--primary);
|
||
padding-left: 7px;
|
||
box-shadow: var(--shadow-sm);
|
||
}
|
||
|
||
/* 树节点操作按钮 */
|
||
.tree-actions {
|
||
display: none;
|
||
gap: 2px;
|
||
margin-left: auto;
|
||
flex-shrink: 0;
|
||
}
|
||
.tree-node-header:hover .tree-actions,
|
||
.tree-step-header:hover .tree-actions {
|
||
display: flex;
|
||
}
|
||
.tree-action-btn {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
width: 22px;
|
||
height: 22px;
|
||
border: none;
|
||
border-radius: 4px;
|
||
background: transparent;
|
||
cursor: pointer;
|
||
font-size: 12px;
|
||
color: var(--text-muted);
|
||
transition: all 0.15s ease;
|
||
padding: 0;
|
||
line-height: 1;
|
||
}
|
||
.tree-action-btn:hover {
|
||
background: var(--surface);
|
||
color: var(--primary);
|
||
}
|
||
.tree-action-btn.edit:hover { color: var(--info); }
|
||
.tree-action-btn.add:hover { color: var(--success); }
|
||
.tree-action-btn.del:hover { color: var(--danger); }
|
||
.tree-action-btn:active { transform: scale(0.9); }
|
||
|
||
/* 顶部添加按钮 */
|
||
.tree-add-root {
|
||
float: right;
|
||
font-size: 12px;
|
||
font-weight: 600;
|
||
color: var(--primary);
|
||
cursor: pointer;
|
||
padding: 2px 8px;
|
||
border-radius: var(--radius);
|
||
border: 1px dashed var(--primary);
|
||
transition: all 0.2s ease;
|
||
}
|
||
.tree-add-root:hover {
|
||
background: var(--primary-light);
|
||
}
|
||
|
||
/* 内联编辑输入框 */
|
||
.tree-edit-input {
|
||
flex: 1;
|
||
font-size: inherit;
|
||
font-weight: inherit;
|
||
border: 1px solid var(--primary);
|
||
border-radius: 4px;
|
||
padding: 2px 6px;
|
||
outline: none;
|
||
background: #fff;
|
||
color: var(--text);
|
||
}
|
||
|
||
/* 树节点删除警告样式 */
|
||
.tree-delete-warning {
|
||
font-size: 13px;
|
||
color: var(--danger);
|
||
margin: 8px 0;
|
||
padding: 8px 12px;
|
||
background: var(--danger-light);
|
||
border-radius: var(--radius-md);
|
||
border-left: 3px solid var(--danger);
|
||
}
|
||
.section-header {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
margin-bottom: 16px;
|
||
position: sticky;
|
||
top: 0;
|
||
z-index: 20;
|
||
background: var(--surface);
|
||
padding: 12px 0;
|
||
margin-top: -12px;
|
||
}
|
||
.section-header h2 { font-size: 18px; font-weight: 700; color: var(--text); }
|
||
.btn {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
padding: 8px 16px;
|
||
border: 1px solid var(--border);
|
||
border-radius: var(--radius-md);
|
||
background: var(--surface-card);
|
||
cursor: pointer;
|
||
font-size: 13px;
|
||
font-weight: 500;
|
||
transition: all 0.2s ease;
|
||
box-shadow: var(--shadow-sm);
|
||
}
|
||
.btn:hover {
|
||
border-color: var(--primary);
|
||
color: var(--primary);
|
||
transform: translateY(-1px);
|
||
box-shadow: var(--shadow);
|
||
}
|
||
.btn-primary {
|
||
background: var(--primary-gradient);
|
||
color: #fff;
|
||
border-color: transparent;
|
||
box-shadow: var(--shadow-md);
|
||
}
|
||
.btn-primary:hover {
|
||
opacity: 0.95;
|
||
color: #fff;
|
||
transform: translateY(-1px);
|
||
box-shadow: 0 4px 12px rgba(26,86,219,0.3);
|
||
}
|
||
.btn-success {
|
||
background: linear-gradient(135deg, #047857 0%, #065f46 100%);
|
||
color: #fff;
|
||
border-color: transparent;
|
||
box-shadow: var(--shadow-md);
|
||
}
|
||
.btn-success:hover {
|
||
opacity: 0.95;
|
||
color: #fff;
|
||
transform: translateY(-1px);
|
||
box-shadow: 0 4px 12px rgba(4,120,87,0.3);
|
||
}
|
||
.btn-danger {
|
||
background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
|
||
color: #fff;
|
||
border-color: transparent;
|
||
box-shadow: var(--shadow-md);
|
||
}
|
||
.btn-danger:hover {
|
||
opacity: 0.95;
|
||
color: #fff;
|
||
transform: translateY(-1px);
|
||
box-shadow: 0 4px 12px rgba(220,38,38,0.3);
|
||
}
|
||
.card {
|
||
background: var(--surface-card);
|
||
border: 1px solid var(--border);
|
||
border-radius: var(--radius-card);
|
||
padding: 20px;
|
||
margin-bottom: 16px;
|
||
box-shadow: var(--shadow-sm);
|
||
transition: box-shadow 0.2s ease;
|
||
}
|
||
.card:hover { box-shadow: var(--shadow-md); }
|
||
.card-title {
|
||
font-size: 15px;
|
||
font-weight: 700;
|
||
margin-bottom: 12px;
|
||
color: var(--text);
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
}
|
||
.doc-list { display: flex; flex-direction: column; gap: 8px; }
|
||
.doc-item {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
padding: 14px 18px;
|
||
border: 1px solid var(--border);
|
||
border-radius: var(--radius-md);
|
||
background: var(--surface-card);
|
||
cursor: pointer;
|
||
transition: all 0.2s ease;
|
||
box-shadow: var(--shadow-sm);
|
||
}
|
||
.doc-item:hover {
|
||
border-color: var(--primary);
|
||
transform: translateY(-1px);
|
||
box-shadow: var(--shadow-md);
|
||
}
|
||
.doc-item .info { flex: 1; }
|
||
.doc-item .title { font-size: 14px; font-weight: 600; color: var(--text); }
|
||
.doc-item .meta { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
|
||
.doc-item .actions { display: flex; gap: 8px; }
|
||
.badge {
|
||
display: inline-block;
|
||
padding: 3px 10px;
|
||
border-radius: 999px;
|
||
font-size: 11px;
|
||
font-weight: 600;
|
||
letter-spacing: 0.3px;
|
||
}
|
||
.badge-blue { background: var(--badge-blue-bg); color: var(--badge-blue-text); }
|
||
.badge-orange { background: var(--badge-orange-bg); color: var(--badge-orange-text); }
|
||
.badge-green { background: var(--badge-green-bg); color: var(--badge-green-text); }
|
||
.badge-gray { background: var(--badge-gray-bg); color: var(--badge-gray-text); }
|
||
.badge-red { background: var(--badge-red-bg); color: var(--badge-red-text); }
|
||
.risk-high { color: var(--danger); font-weight: 600; }
|
||
.risk-medium { color: var(--warning); font-weight: 600; }
|
||
.risk-low { color: var(--success); font-weight: 600; }
|
||
.modal-overlay {
|
||
display: none;
|
||
position: fixed;
|
||
top: 0; left: 0; right: 0; bottom: 0;
|
||
background: rgba(17,24,39,0.5);
|
||
backdrop-filter: blur(4px);
|
||
z-index: 100;
|
||
align-items: center;
|
||
justify-content: center;
|
||
}
|
||
.modal-overlay.show { display: flex; }
|
||
.modal {
|
||
background: var(--surface-card);
|
||
border-radius: var(--radius-lg);
|
||
padding: 28px;
|
||
width: 90%;
|
||
max-width: 640px;
|
||
max-height: 85vh;
|
||
overflow-y: auto;
|
||
box-shadow: var(--shadow-lg);
|
||
border: 1px solid var(--border);
|
||
}
|
||
.modal h3 {
|
||
font-size: 18px;
|
||
font-weight: 700;
|
||
margin-bottom: 20px;
|
||
color: var(--text);
|
||
padding-bottom: 12px;
|
||
border-bottom: 2px solid var(--primary-light);
|
||
}
|
||
.form-group { margin-bottom: 16px; }
|
||
.form-group label {
|
||
display: block;
|
||
font-size: 13px;
|
||
font-weight: 600;
|
||
color: var(--text-secondary);
|
||
margin-bottom: 6px;
|
||
}
|
||
.form-group input,
|
||
.form-group select,
|
||
.form-group textarea {
|
||
width: 100%;
|
||
padding: 10px 14px;
|
||
border: 1.5px solid var(--border);
|
||
border-radius: var(--radius-md);
|
||
font-size: 14px;
|
||
font-family: inherit;
|
||
background: var(--surface-card);
|
||
transition: all 0.2s ease;
|
||
}
|
||
.form-group input:focus,
|
||
.form-group select:focus,
|
||
.form-group textarea:focus {
|
||
outline: none;
|
||
border-color: var(--primary);
|
||
box-shadow: 0 0 0 3px rgba(26,86,219,0.1);
|
||
}
|
||
.form-group textarea { min-height: 100px; resize: vertical; }
|
||
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
|
||
.empty-state {
|
||
text-align: center;
|
||
padding: 40px 20px;
|
||
color: var(--text-muted);
|
||
}
|
||
.empty-state p { font-size: 14px; }
|
||
.result-card {
|
||
border: 1px solid var(--border);
|
||
border-radius: var(--radius-md);
|
||
padding: 18px;
|
||
margin-bottom: 12px;
|
||
background: var(--surface-card);
|
||
box-shadow: var(--shadow-sm);
|
||
transition: all 0.2s ease;
|
||
}
|
||
.result-card:hover { box-shadow: var(--shadow-md); }
|
||
.result-card .result-header {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
margin-bottom: 10px;
|
||
}
|
||
.result-card .result-type {
|
||
font-size: 13px;
|
||
font-weight: 700;
|
||
color: var(--primary-text);
|
||
background: var(--primary-light);
|
||
padding: 4px 10px;
|
||
border-radius: var(--radius);
|
||
}
|
||
.result-card .result-summary {
|
||
font-size: 14px;
|
||
margin-bottom: 10px;
|
||
color: var(--text);
|
||
font-weight: 500;
|
||
line-height: 1.5;
|
||
}
|
||
.result-card .result-detail { font-size: 13px; color: var(--text-secondary); }
|
||
.result-card .result-detail pre {
|
||
white-space: pre-wrap;
|
||
font-family: "SF Mono", Monaco, "Cascadia Code", monospace;
|
||
font-size: 12px;
|
||
background: var(--surface);
|
||
padding: 14px;
|
||
border-radius: var(--radius-md);
|
||
margin-top: 10px;
|
||
max-height: 200px;
|
||
overflow-y: auto;
|
||
border: 1px solid var(--border-light);
|
||
line-height: 1.6;
|
||
}
|
||
.loading {
|
||
display: inline-block;
|
||
width: 16px; height: 16px;
|
||
border: 2px solid var(--border);
|
||
border-top-color: var(--primary);
|
||
border-radius: 50%;
|
||
animation: spin 0.6s linear infinite;
|
||
}
|
||
@keyframes spin { to { transform: rotate(360deg); } }
|
||
.toast {
|
||
position: fixed;
|
||
top: 20px;
|
||
right: 20px;
|
||
padding: 12px 20px;
|
||
border-radius: var(--radius);
|
||
color: #fff;
|
||
font-size: 14px;
|
||
z-index: 200;
|
||
opacity: 0;
|
||
transform: translateY(-10px);
|
||
transition: all 0.3s;
|
||
}
|
||
.toast.show { opacity: 1; transform: translateY(0); }
|
||
.toast-success { background: var(--success); }
|
||
.toast-error { background: var(--danger); }
|
||
.analysis-section { margin-top: 16px; }
|
||
|
||
/* 滚动条美化 */
|
||
::-webkit-scrollbar { width: 6px; height: 6px; }
|
||
::-webkit-scrollbar-track { background: transparent; }
|
||
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; opacity: 0.3; }
|
||
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }
|
||
|
||
/* 加载动画优化 */
|
||
.loading {
|
||
display: inline-block;
|
||
width: 18px; height: 18px;
|
||
border: 2.5px solid var(--border);
|
||
border-top-color: var(--primary);
|
||
border-radius: 50%;
|
||
animation: spin 0.7s linear infinite;
|
||
}
|
||
|
||
/* Toast 提示优化 */
|
||
.toast {
|
||
position: fixed;
|
||
top: 20px;
|
||
right: 20px;
|
||
padding: 14px 24px;
|
||
border-radius: var(--radius-md);
|
||
color: #fff;
|
||
font-size: 14px;
|
||
font-weight: 500;
|
||
z-index: 200;
|
||
opacity: 0;
|
||
transform: translateY(-10px) scale(0.95);
|
||
transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
|
||
box-shadow: var(--shadow-lg);
|
||
}
|
||
.toast.show { opacity: 1; transform: translateY(0) scale(1); }
|
||
.toast-success {
|
||
background: linear-gradient(135deg, #047857 0%, #065f46 100%);
|
||
}
|
||
.toast-error {
|
||
background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
|
||
}
|
||
|
||
/* 空状态优化 */
|
||
.empty-state {
|
||
text-align: center;
|
||
padding: 60px 20px;
|
||
color: var(--text-muted);
|
||
}
|
||
.empty-state p { font-size: 15px; font-weight: 500; }
|
||
|
||
/* 状态点颜色 */
|
||
.status-dot {
|
||
display: inline-block;
|
||
width: 8px;
|
||
height: 8px;
|
||
border-radius: 50%;
|
||
margin-right: 6px;
|
||
}
|
||
.status-dot-blue { background: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); }
|
||
.status-dot-green { background: var(--success); box-shadow: 0 0 0 2px var(--success-light); }
|
||
.status-dot-orange { background: var(--warning); box-shadow: 0 0 0 2px var(--warning-light); }
|
||
.status-dot-red { background: var(--danger); box-shadow: 0 0 0 2px var(--danger-light); }
|
||
.status-dot-gray { background: var(--text-muted); }
|
||
|
||
/* 步骤分组样式 */
|
||
.step-group {
|
||
border: 1px solid var(--border);
|
||
border-radius: var(--radius-md);
|
||
margin-bottom: 12px;
|
||
overflow: hidden;
|
||
background: var(--surface-card);
|
||
box-shadow: var(--shadow-sm);
|
||
transition: box-shadow 0.2s ease;
|
||
}
|
||
.step-group:hover { box-shadow: var(--shadow); }
|
||
.step-header {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
padding: 12px 18px;
|
||
background: linear-gradient(90deg, var(--surface) 0%, var(--surface-hover) 100%);
|
||
border-bottom: 1px solid var(--border);
|
||
}
|
||
.step-info {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 10px;
|
||
}
|
||
.step-name {
|
||
font-size: 14px;
|
||
font-weight: 700;
|
||
color: var(--text);
|
||
}
|
||
.step-meta {
|
||
font-size: 12px;
|
||
color: var(--text-muted);
|
||
font-weight: 500;
|
||
}
|
||
.step-docs {
|
||
padding: 12px 18px;
|
||
}
|
||
.btn-sm {
|
||
padding: 5px 12px !important;
|
||
font-size: 12px !important;
|
||
border-radius: var(--radius) !important;
|
||
}
|
||
|
||
/* Header 按钮 - 深色背景专用 */
|
||
.header-btn {
|
||
background: rgba(255,255,255,0.15) !important;
|
||
border-color: rgba(255,255,255,0.25) !important;
|
||
color: #ffffff !important;
|
||
backdrop-filter: blur(8px);
|
||
}
|
||
.header-btn:hover {
|
||
background: rgba(255,255,255,0.25) !important;
|
||
border-color: rgba(255,255,255,0.4) !important;
|
||
color: #ffffff !important;
|
||
transform: translateY(-1px);
|
||
}
|
||
|
||
/* Token Banner */
|
||
.token-banner {
|
||
background: linear-gradient(90deg, var(--warning-light) 0%, #fff7ed 100%) !important;
|
||
border-bottom: 2px solid var(--warning) !important;
|
||
color: var(--warning) !important;
|
||
box-shadow: var(--shadow-md);
|
||
}
|
||
.token-banner strong {
|
||
font-weight: 700;
|
||
}
|
||
|
||
/* 数据录入表格样式 */
|
||
.data-table {
|
||
width: 100%;
|
||
border-collapse: separate;
|
||
border-spacing: 0;
|
||
font-size: 13px;
|
||
background: var(--surface-card);
|
||
border-radius: var(--radius-md);
|
||
overflow: hidden;
|
||
box-shadow: var(--shadow-sm);
|
||
}
|
||
.data-table th,
|
||
.data-table td {
|
||
padding: 12px 16px;
|
||
text-align: left;
|
||
border-bottom: 1px solid var(--border-light);
|
||
}
|
||
.data-table th {
|
||
background: linear-gradient(180deg, var(--surface) 0%, var(--surface-hover) 100%);
|
||
font-weight: 700;
|
||
color: var(--text-secondary);
|
||
font-size: 11px;
|
||
text-transform: uppercase;
|
||
letter-spacing: 0.8px;
|
||
border-bottom: 2px solid var(--border);
|
||
}
|
||
.data-table tr { transition: background 0.15s ease; }
|
||
.data-table tr:hover { background: var(--surface-hover); }
|
||
.data-table td { color: var(--text); font-weight: 500; }
|
||
.data-table .cell-muted { color: var(--text-muted); font-size: 12px; font-weight: 400; }
|
||
.data-table tr:last-child td { border-bottom: none; }
|
||
|
||
/* 附件列表样式 */
|
||
.attachment-list { display: flex; flex-direction: column; gap: 6px; }
|
||
.attachment-item {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
padding: 8px 12px;
|
||
border: 1px solid var(--border);
|
||
border-radius: var(--radius-md);
|
||
background: var(--surface);
|
||
font-size: 13px;
|
||
transition: all 0.2s ease;
|
||
}
|
||
.attachment-item:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); }
|
||
.attachment-item .file-icon { font-size: 16px; flex-shrink: 0; }
|
||
.attachment-item .file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); font-weight: 500; }
|
||
.attachment-item .file-size { font-size: 11px; color: var(--text-muted); flex-shrink: 0; }
|
||
.attachment-item .file-download {
|
||
color: var(--primary);
|
||
cursor: pointer;
|
||
font-size: 12px;
|
||
font-weight: 600;
|
||
flex-shrink: 0;
|
||
text-decoration: none;
|
||
padding: 2px 8px;
|
||
border-radius: var(--radius);
|
||
transition: background 0.15s;
|
||
}
|
||
.attachment-item .file-download:hover { background: var(--primary-light); }
|
||
.attachment-item .file-delete {
|
||
color: var(--danger);
|
||
cursor: pointer;
|
||
font-size: 12px;
|
||
font-weight: 600;
|
||
flex-shrink: 0;
|
||
text-decoration: none;
|
||
padding: 2px 8px;
|
||
border-radius: var(--radius);
|
||
transition: background 0.15s;
|
||
border: none;
|
||
background: transparent;
|
||
}
|
||
.attachment-item .file-delete:hover { background: rgba(239, 68, 68, 0.1); }
|
||
.attachment-item .file-preview {
|
||
color: var(--info, #17a2b8);
|
||
cursor: pointer;
|
||
font-size: 12px;
|
||
font-weight: 600;
|
||
flex-shrink: 0;
|
||
padding: 2px 8px;
|
||
border-radius: var(--radius);
|
||
transition: background 0.15s;
|
||
border: none;
|
||
background: transparent;
|
||
}
|
||
.attachment-item .file-preview:hover { background: rgba(23, 162, 184, 0.1); }
|
||
#previewBody iframe { width: 100%; height: 100%; border: none; }
|
||
#previewBody .preview-html { padding: 20px; }
|
||
#previewBody .preview-loading { display:flex;align-items:center;justify-content:center;height:100%;color:var(--text-muted);font-size:14px; }
|
||
#previewBody .preview-error { display:flex;align-items:center;justify-content:center;height:100%;color:var(--danger);font-size:14px; }
|
||
</style>
|
||
<style>
|
||
|
||
/* ===== 子系统统一配色(2026-10-17) ===== */
|
||
:root {
|
||
--primary:#22d3ee; --primary-light:rgba(34,211,238,.12); --primary-hover:#0ea5e9; --primary-text:#9fe8ff;
|
||
--primary-gradient:linear-gradient(135deg,#0ea5e9,#22d3ee);
|
||
--surface:#0f2027; --surface-card:rgba(255,255,255,.06); --surface-hover:rgba(255,255,255,.09);
|
||
--text:#e8f4ff; --text-secondary:#b9d3e2; --text-muted:#8fb0c2;
|
||
--border:rgba(120,220,255,.18); --border-light:rgba(120,220,255,.12);
|
||
--success:#4ade80; --success-light:rgba(74,222,128,.14);
|
||
--warning:#f0b34a; --warning-light:rgba(240,179,74,.14);
|
||
--danger:#f87171; --danger-light:rgba(248,113,113,.14);
|
||
--info:#38bdf8; --info-light:rgba(56,189,248,.14);
|
||
--badge-blue-bg:rgba(56,189,248,.16); --badge-blue-text:#9fe8ff;
|
||
--badge-green-bg:rgba(74,222,128,.16); --badge-green-text:#86efac;
|
||
--badge-orange-bg:rgba(240,179,74,.16); --badge-orange-text:#fcd34d;
|
||
--badge-red-bg:rgba(248,113,113,.16); --badge-red-text:#fca5a5;
|
||
--badge-gray-bg:rgba(255,255,255,.08); --badge-gray-text:#cbd5e1;
|
||
--badge-purple-bg:rgba(167,139,250,.16); --badge-purple-text:#c4b5fd;
|
||
}
|
||
body { background:linear-gradient(135deg,#0f2027 0%,#203a43 45%,#2c5364 100%) !important;
|
||
background-attachment:fixed !important; color:#e8f4ff !important; }
|
||
.app-header { background:rgba(10,25,32,.55) !important; border-bottom:1px solid rgba(120,220,255,.14) !important;
|
||
backdrop-filter:blur(12px); }
|
||
.app-header h1, .app-header .subtitle { color:#e8f4ff !important; }
|
||
.sidebar { background:rgba(255,255,255,.04) !important; border-right:1px solid rgba(120,220,255,.14) !important; }
|
||
.main-content { background:transparent !important; background-image:none !important; }
|
||
.main-content::before { display:none !important; }
|
||
table th { background:rgba(255,255,255,.06) !important; color:#9fe8ff !important; border-color:rgba(120,220,255,.18) !important; }
|
||
table td { border-color:rgba(120,220,255,.12) !important; }
|
||
tr:hover td { background:rgba(255,255,255,.05) !important; }
|
||
input, select, textarea { background:rgba(0,0,0,.25) !important; color:#eaf7ff !important;
|
||
border-color:rgba(140,220,255,.28) !important; }
|
||
input::placeholder, textarea::placeholder { color:#7c9aac !important; }
|
||
.btn { background:rgba(255,255,255,.06) !important; border-color:rgba(120,220,255,.25) !important; color:#b9d3e2 !important; }
|
||
.btn:hover { background:rgba(255,255,255,.1) !important; }
|
||
.btn-primary { background:linear-gradient(90deg,#0ea5e9,#22d3ee) !important; border:none !important; color:#03202c !important; }
|
||
.card, .panel, .modal { background:rgba(255,255,255,.06) !important; border-color:rgba(120,220,255,.2) !important; }
|
||
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<div class="app-header">
|
||
<h1>医院审计管理系统</h1>
|
||
<span class="subtitle">本地数据库 · 大模型分析</span>
|
||
<div style="margin-left:auto;display:flex;gap:8px;">
|
||
<button class="btn header-btn" onclick="openBackupModal()">备份</button>
|
||
<button class="btn header-btn" onclick="openAuditPlanModal()">生成审计实施方案</button>
|
||
<button class="btn header-btn" onclick="openAuditReportModal()">生成审计报告</button>
|
||
<button class="btn header-btn" id="restartBtnTop" onclick="restartServer()" title="重启后端服务" style="border-color:var(--warning);color:var(--warning);">重启服务</button>
|
||
</div>
|
||
</div>
|
||
<div class="app-layout" id="appLayout">
|
||
<div class="sidebar" id="sidebar">
|
||
<div class="sidebar-nav">
|
||
<div class="nav-tab active" id="navProject" onclick="switchView('project')">审计项目</div>
|
||
<div class="nav-tab" id="navData" onclick="switchView('data')">基础数据</div>
|
||
</div>
|
||
<div class="sidebar-content">
|
||
<div id="sidebarContent">
|
||
<h2>审计项目</h2>
|
||
<div id="projectTree"></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="resizer" id="resizer"><div class="resizer-line"></div></div>
|
||
<div class="main-content" id="mainContent">
|
||
<div class="empty-state">
|
||
<p>请从左侧选择一个项目步骤</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 新建/编辑资料弹窗 -->
|
||
<div class="modal-overlay" id="modalCreateDoc">
|
||
<div class="modal">
|
||
<h3 id="docModalTitle">新建审计资料</h3>
|
||
<div class="form-group">
|
||
<label>资料标题</label>
|
||
<input type="text" id="docTitle" placeholder="输入资料标题">
|
||
</div>
|
||
<div class="form-group">
|
||
<label>资料类型</label>
|
||
<select id="docType">
|
||
<option value="报告">报告</option>
|
||
<option value="方案">方案</option>
|
||
<option value="底稿">底稿</option>
|
||
<option value="其他">其他</option>
|
||
</select>
|
||
</div>
|
||
<div class="form-group">
|
||
<label>所属步骤</label>
|
||
<select id="docStep">
|
||
<option value="">-- 不关联步骤 --</option>
|
||
</select>
|
||
</div>
|
||
<div class="form-group">
|
||
<label>正文内容(用于大模型分析)</label>
|
||
<textarea id="docContent" placeholder="输入审计资料正文内容..."></textarea>
|
||
</div>
|
||
<div class="form-group" id="docFileGroup">
|
||
<label>附件文件</label>
|
||
<div id="existingAttachments" style="margin-bottom:8px;"></div>
|
||
<input type="file" id="docFile">
|
||
</div>
|
||
<div class="form-actions">
|
||
<button class="btn" onclick="closeModal('modalCreateDoc')">取消</button>
|
||
<button class="btn btn-primary" id="docModalSubmit" onclick="submitDoc()">创建</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 详情弹窗 -->
|
||
<div class="modal-overlay" id="modalDetail">
|
||
<div class="modal">
|
||
<div style="display:flex;align-items:center;justify-content:space-between;">
|
||
<h3 id="detailTitle" style="margin:0;">资料详情</h3>
|
||
<span style="font-size:24px;cursor:pointer;color:var(--text-muted);line-height:1;padding:0 4px;" onclick="closeModal('modalDetail')">×</span>
|
||
</div>
|
||
<div id="detailContent" style="margin-top:12px;"></div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 通用新建记录弹窗 -->
|
||
<div class="modal-overlay" id="modalCreateRecord">
|
||
<div class="modal">
|
||
<h3 id="recordModalTitle">新建记录</h3>
|
||
<div id="recordModalBody"></div>
|
||
<div class="form-actions">
|
||
<button class="btn" onclick="closeModal('modalCreateRecord')">取消</button>
|
||
<button class="btn btn-primary" id="recordModalSubmit" onclick="submitRecord()">创建</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 删除确认弹窗 -->
|
||
<div class="modal-overlay" id="modalDelete">
|
||
<div class="modal">
|
||
<h3>确认删除</h3>
|
||
<p id="deleteMessage">确定要删除这条记录吗?此操作不可恢复。</p>
|
||
<div id="relatedRecords" style="margin:12px 0;"></div>
|
||
<div class="form-actions">
|
||
<button class="btn" onclick="closeModal('modalDelete')">取消</button>
|
||
<button class="btn btn-danger" id="confirmDelete">删除</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="toast" id="toast"></div>
|
||
|
||
<!-- 知识库选择弹窗 -->
|
||
<div class="modal-overlay" id="modalWikiSelect">
|
||
<div class="modal" style="max-width:780px;width:90%;max-height:90vh;display:flex;flex-direction:column;">
|
||
<h3>分析配置</h3>
|
||
<p style="font-size:13px;color:var(--text-muted);margin-bottom:12px;">选择知识库参考材料 + 可填写本次分析的指导要求</p>
|
||
<div id="wikiSpaceList" style="max-height:220px;overflow-y:auto;display:flex;flex-direction:column;gap:8px;margin-bottom:12px;">
|
||
<p style="font-size:13px;color:var(--text-muted);">加载中...</p>
|
||
</div>
|
||
<div class="form-group" style="margin-bottom:12px;">
|
||
<label>分析指导(可选)</label>
|
||
<p style="font-size:12px;color:var(--text-muted);margin-bottom:6px;">可填写本次分析的特殊要求,如:只分析Excel中的"采购明细"工作表、指定输出风格、聚焦某类风险等。留空则按默认全面分析。</p>
|
||
<textarea id="userGuidance" rows="4" placeholder='示例:只分析此Excel中的"采购明细"工作表,重点关注单价异常和供应商集中度问题,输出风格用简短要点式。' style="width:100%;padding:8px 10px;border:1px solid var(--border);border-radius:var(--radius-md);font-size:13px;font-family:inherit;resize:vertical;background:var(--surface-card);color:var(--text);box-sizing:border-box;"></textarea>
|
||
</div>
|
||
<div class="form-actions">
|
||
<button class="btn" onclick="closeModal('modalWikiSelect')">取消</button>
|
||
<button class="btn" onclick="analyzeDocWithWiki([])" style="margin-right:4px;">直接分析</button>
|
||
<button class="btn" onclick="confirmWikiAnalyze()" style="margin-right:4px;">引用知识库分析</button>
|
||
<button class="btn btn-primary" id="confirmWikiAnalyze" onclick="confirmCombinedAnalyze()">综合分析</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 修改分析结果弹窗 -->
|
||
<div class="modal-overlay" id="modalEditResult">
|
||
<div class="modal">
|
||
<h3>修改分析结果</h3>
|
||
<div class="form-group">
|
||
<label>分析类型</label>
|
||
<input type="text" id="resultType" placeholder="分析类型">
|
||
</div>
|
||
<div class="form-group">
|
||
<label>风险等级</label>
|
||
<select id="resultRisk">
|
||
<option value="高">高</option>
|
||
<option value="中">中</option>
|
||
<option value="低">低</option>
|
||
<option value="无">无</option>
|
||
</select>
|
||
</div>
|
||
<div class="form-group">
|
||
<label>分析摘要</label>
|
||
<textarea id="resultSummary" placeholder="分析摘要"></textarea>
|
||
</div>
|
||
<div class="form-group">
|
||
<label>关键发现</label>
|
||
<textarea id="resultFindings" placeholder="关键发现" style="min-height:100px;"></textarea>
|
||
</div>
|
||
<div class="form-group">
|
||
<label>改进建议</label>
|
||
<textarea id="resultSuggestions" placeholder="改进建议" style="min-height:100px;"></textarea>
|
||
</div>
|
||
<div class="form-actions">
|
||
<button class="btn" onclick="closeModal('modalEditResult')">取消</button>
|
||
<button class="btn btn-primary" onclick="submitResultEdit()">保存</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 备份弹窗 -->
|
||
<div class="modal-overlay" id="modalBackup">
|
||
<div class="modal">
|
||
<h3>项目备份</h3>
|
||
<div style="margin-bottom:16px;">
|
||
<button class="btn btn-primary" id="backupBtn" onclick="doBackup()">立即备份</button>
|
||
<span style="font-size:13px;color:var(--text-muted);margin-left:8px;">备份到 F:\ 根目录</span>
|
||
</div>
|
||
<div class="card-title">备份历史</div>
|
||
<div id="backupList" style="max-height:300px;overflow-y:auto;">
|
||
<p style="color:var(--text-muted);font-size:13px;">加载中...</p>
|
||
</div>
|
||
<div class="form-actions">
|
||
<button class="btn" onclick="closeModal('modalBackup')">关闭</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 文件预览弹窗 -->
|
||
<div class="modal-overlay" id="modalPreview">
|
||
<div class="modal" id="previewModalBox" style="max-width:900px;width:90%;height:85vh;display:flex;flex-direction:column;transition:all 0.3s ease;">
|
||
<div style="display:flex;align-items:center;justify-content:space-between;padding:12px 20px;border-bottom:1px solid var(--border-color);">
|
||
<h3 id="previewTitle" style="margin:0;font-size:16px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;flex:1;margin-right:12px;">文件预览</h3>
|
||
<div style="display:flex;gap:6px;flex-shrink:0;">
|
||
<button class="btn" style="padding:4px 10px;font-size:14px;" id="previewZoomOut" title="缩小">−</button>
|
||
<span id="previewZoomLabel" style="font-size:12px;color:var(--text-muted);min-width:42px;text-align:center;line-height:28px;">100%</span>
|
||
<button class="btn" style="padding:4px 10px;font-size:14px;" id="previewZoomIn" title="放大">+</button>
|
||
<button class="btn" style="padding:4px 10px;font-size:14px;" id="previewFullscreen" title="全屏">⛶</button>
|
||
<button class="btn" style="padding:4px 16px;" onclick="closeModal('modalPreview')">关闭</button>
|
||
</div>
|
||
</div>
|
||
<div id="previewBody" style="flex:1;overflow:auto;padding:0;background:#f5f5f5;"></div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 审计实施方案弹窗 -->
|
||
<div class="modal-overlay" id="modalAuditPlan">
|
||
<div class="modal" style="max-width:680px;">
|
||
<h3>生成审计实施方案</h3>
|
||
|
||
<!-- 输入区域 -->
|
||
<div id="planInputArea">
|
||
<div class="form-group">
|
||
<label>审计项目描述</label>
|
||
<textarea id="planDesc" rows="5" placeholder="请描述审计项目的大概事项,例如:对医院2026年度财务收支及内部控制进行审计,重点关注药品采购、设备购置、收费合规性等领域..." style="width:100%;resize:vertical;font-size:13px;"></textarea>
|
||
</div>
|
||
|
||
<div class="form-group">
|
||
<label>引用知识库(可选)</label>
|
||
<p style="font-size:12px;color:var(--text-muted);margin-bottom:8px;">选择知识空间作为方案编制的内部制度依据</p>
|
||
<div id="planWikiList" style="max-height:180px;overflow-y:auto;display:flex;flex-direction:column;gap:6px;">
|
||
<p style="font-size:13px;color:var(--text-muted);">点击上方按钮后加载...</p>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="form-actions">
|
||
<button class="btn" onclick="closeModal('modalAuditPlan')">取消</button>
|
||
<button class="btn btn-primary" id="generatePlanBtn" onclick="generateAuditPlan()">生成方案</button>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 结果展示区域 -->
|
||
<div id="planResultArea" style="display:none;">
|
||
<div id="planResultMeta" style="margin-bottom:12px;"></div>
|
||
<div style="background:var(--surface-card);border:1px solid var(--border);border-radius:var(--radius-md);padding:16px;max-height:400px;overflow-y:auto;">
|
||
<div id="planResultContent" style="font-size:13px;line-height:1.7;white-space:pre-wrap;"></div>
|
||
</div>
|
||
<div id="planReferencesArea" style="margin-top:12px;display:none;">
|
||
<div style="font-size:13px;font-weight:600;margin-bottom:6px;">参考资料来源</div>
|
||
<div id="planReferences" style="font-size:12px;color:var(--text-muted);background:var(--primary-light);border-radius:var(--radius-md);padding:12px;white-space:pre-wrap;"></div>
|
||
</div>
|
||
<div class="form-actions" style="margin-top:16px;">
|
||
<button class="btn" onclick="resetPlanModal()">重新生成</button>
|
||
<button class="btn" onclick="downloadPlanMd()" style="margin-left:auto;">下载 Markdown</button>
|
||
<button class="btn btn-primary" onclick="downloadPlanDocx()">下载 Word 文档</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 审计报告弹窗 -->
|
||
<div class="modal-overlay" id="modalAuditReport">
|
||
<div class="modal" style="max-width:780px;">
|
||
<h3>生成审计报告</h3>
|
||
|
||
<!-- 输入区域 -->
|
||
<div id="reportInputArea">
|
||
<div class="form-group">
|
||
<label>选择项目</label>
|
||
<p style="font-size:12px;color:var(--text-muted);margin-bottom:8px;">逐级展开大类 → 年度,点击项目进行选择</p>
|
||
<div id="reportProjectTree" style="max-height:200px;overflow-y:auto;border:1px solid var(--border);border-radius:var(--radius-md);padding:8px;background:var(--surface-card);">
|
||
<p style="font-size:13px;color:var(--text-muted);text-align:center;padding:12px;">加载中...</p>
|
||
</div>
|
||
</div>
|
||
|
||
<div id="reportProjectInfo" style="display:none;margin-bottom:12px;">
|
||
<div style="background:var(--primary-light);border-radius:var(--radius-md);padding:12px;font-size:13px;">
|
||
<div id="reportBreadcrumb" style="color:var(--text-muted);margin-bottom:4px;"></div>
|
||
<div id="reportProjectSummary" style="font-weight:600;"></div>
|
||
</div>
|
||
</div>
|
||
|
||
<div id="reportSelectionArea" style="display:none;margin-bottom:12px;">
|
||
<div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:8px;">
|
||
<label style="font-size:13px;font-weight:600;">审计资料与分析结果</label>
|
||
<div style="display:flex;gap:6px;">
|
||
<button class="btn" style="padding:2px 10px;font-size:12px;" onclick="reportSelectAll(true)">全选</button>
|
||
<button class="btn" style="padding:2px 10px;font-size:12px;" onclick="reportSelectAll(false)">反选</button>
|
||
</div>
|
||
</div>
|
||
<div id="reportDocList" style="max-height:220px;overflow-y:auto;border:1px solid var(--border);border-radius:var(--radius-md);padding:8px;background:var(--surface-card);display:flex;flex-direction:column;gap:4px;">
|
||
</div>
|
||
</div>
|
||
|
||
<div class="form-group">
|
||
<label>报告要求与格式描述</label>
|
||
<textarea id="reportDesc" rows="4" placeholder="请描述审计报告的要求和格式,例如:按照内部审计准则格式编写,重点突出风险发现和改进建议,包含审计结论和整改意见..." style="width:100%;resize:vertical;font-size:13px;"></textarea>
|
||
</div>
|
||
|
||
<div class="form-group">
|
||
<label>引用知识库(可选)</label>
|
||
<p style="font-size:12px;color:var(--text-muted);margin-bottom:8px;">选择知识空间作为报告编制的制度依据</p>
|
||
<div id="reportWikiList" style="max-height:150px;overflow-y:auto;display:flex;flex-direction:column;gap:6px;">
|
||
<p style="font-size:13px;color:var(--text-muted);">加载中...</p>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="form-actions">
|
||
<button class="btn" onclick="closeModal('modalAuditReport')">取消</button>
|
||
<button class="btn btn-primary" id="generateReportBtn" onclick="generateAuditReport()">生成报告</button>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 结果展示区域 -->
|
||
<div id="reportResultArea" style="display:none;">
|
||
<div id="reportResultMeta" style="margin-bottom:12px;"></div>
|
||
<div style="background:var(--surface-card);border:1px solid var(--border);border-radius:var(--radius-md);padding:16px;max-height:400px;overflow-y:auto;">
|
||
<div id="reportResultContent" style="font-size:13px;line-height:1.7;white-space:pre-wrap;"></div>
|
||
</div>
|
||
<div id="reportReferencesArea" style="margin-top:12px;display:none;">
|
||
<div style="font-size:13px;font-weight:600;margin-bottom:6px;">参考资料来源</div>
|
||
<div id="reportReferences" style="font-size:12px;color:var(--text-muted);background:var(--primary-light);border-radius:var(--radius-md);padding:12px;white-space:pre-wrap;"></div>
|
||
</div>
|
||
<div class="form-actions" style="margin-top:16px;">
|
||
<button class="btn" onclick="resetReportModal()">重新生成</button>
|
||
<button class="btn" onclick="downloadReportMd()" style="margin-left:auto;">下载 Markdown</button>
|
||
<button class="btn btn-primary" onclick="downloadReportDocx()">下载 Word 文档</button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Token 过期提示横幅 -->
|
||
|
||
|
||
<script>
|
||
// ====== 全局状态 ======
|
||
let viewMode = 'project'; // 'project' | 'data'
|
||
let currentProjectId = null;
|
||
let currentStepId = null; // 当前选中的步骤ID
|
||
let currentDataTable = 'person'; // person | category | year | project | step
|
||
let currentEditId = null; // 当前编辑的基础数据记录ID
|
||
let currentEditDocId = null; // 当前编辑的审计资料ID
|
||
let currentEditResultId = null; // 当前编辑的分析结果ID
|
||
let expandedNodes = {}; // 记录树形菜单展开状态
|
||
let projects = [];
|
||
let docs = [];
|
||
let results = [];
|
||
let persons = [];
|
||
let categories = [];
|
||
let years = [];
|
||
let steps = [];
|
||
|
||
const DATA_TABLES = [
|
||
{ key: 'person', label: '人员表', api: '/api/persons', nameField: '姓名' },
|
||
{ key: 'category', label: '项目大类表', api: '/api/categories', nameField: '大类名称' },
|
||
{ key: 'year', label: '年度表', api: '/api/years', nameField: '年度名称' },
|
||
{ key: 'project', label: '项目表', api: '/api/projects', nameField: '项目名称' },
|
||
{ key: 'step', label: '项目步骤表', api: '/api/steps', nameField: '步骤名称' }
|
||
];
|
||
|
||
// ====== 初始化 ======
|
||
async function init() {
|
||
await loadCategories();
|
||
await loadYears();
|
||
await loadProjects();
|
||
await loadSteps();
|
||
await loadDocs();
|
||
await loadResults();
|
||
}
|
||
|
||
// ====== Toast 提示 ======
|
||
function showToast(msg, type = "success") {
|
||
const t = document.getElementById("toast");
|
||
t.textContent = msg;
|
||
t.className = `toast toast-${type} show`;
|
||
setTimeout(() => t.classList.remove("show"), 3000);
|
||
}
|
||
|
||
// ====== Token 过期检测 ======
|
||
function checkTokenExpired(res) {
|
||
if (res.status === 401) {
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
// ====== 重启后端服务 ======
|
||
async function restartServer() {
|
||
// 同时支持顶部常驻按钮和横幅按钮
|
||
const btns = [document.getElementById('restartBtnTop'), document.getElementById('restartBtn')].filter(b => b);
|
||
btns.forEach(b => { b.disabled = true; b.textContent = '重启中...'; });
|
||
try {
|
||
await fetch('/api/restart', { method: 'POST' });
|
||
} catch (e) {
|
||
// 服务重启会导致连接断开,这是正常的
|
||
}
|
||
// 等待服务重启完成,每2秒检测一次
|
||
let attempts = 0;
|
||
const checkInterval = setInterval(async () => {
|
||
attempts++;
|
||
try {
|
||
const res = await fetch('/api/health');
|
||
if (res.ok) {
|
||
clearInterval(checkInterval);
|
||
btns.forEach(b => { b.textContent = '重启成功'; });
|
||
showToast('服务重启成功,正在刷新页面...');
|
||
setTimeout(() => location.reload(), 1000);
|
||
}
|
||
} catch (e) {
|
||
// 服务还没启动,继续等待
|
||
}
|
||
if (attempts > 15) {
|
||
clearInterval(checkInterval);
|
||
btns.forEach(b => { b.disabled = false; b.textContent = '重启服务'; });
|
||
showToast('重启超时,请手动刷新页面', 'error');
|
||
}
|
||
}, 2000);
|
||
}
|
||
|
||
|
||
// ====== 视图切换 ======
|
||
function switchView(mode) {
|
||
viewMode = mode;
|
||
document.getElementById('navProject').classList.toggle('active', mode === 'project');
|
||
document.getElementById('navData').classList.toggle('active', mode === 'data');
|
||
|
||
if (mode === 'project') {
|
||
renderSidebarProjects();
|
||
if (currentStepId) renderStepDetail();
|
||
else {
|
||
document.getElementById('mainContent').innerHTML = '<div class="empty-state"><p>请从左侧选择一个项目步骤</p></div>';
|
||
}
|
||
} else {
|
||
renderSidebarDataTables();
|
||
renderDataView();
|
||
}
|
||
}
|
||
|
||
function renderSidebarProjects() {
|
||
const el = document.getElementById('sidebarContent');
|
||
el.innerHTML = '<h2>审计项目<span class="tree-add-root" onclick="openTreeAddModal(\'category\', null)">+ 添加大类</span></h2><div id="projectTree"></div>';
|
||
renderProjectTree();
|
||
}
|
||
|
||
function renderSidebarDataTables() {
|
||
const el = document.getElementById('sidebarContent');
|
||
el.innerHTML = '<h2>数据表</h2>' + DATA_TABLES.map(t =>
|
||
`<div class="data-table-item ${currentDataTable === t.key ? 'active' : ''}" onclick="selectDataTable('${t.key}')">${t.label}</div>`
|
||
).join('');
|
||
}
|
||
|
||
function selectDataTable(key) {
|
||
currentDataTable = key;
|
||
renderSidebarDataTables();
|
||
renderDataView();
|
||
}
|
||
|
||
// ====== 加载大类 ======
|
||
async function loadCategories() {
|
||
try {
|
||
const res = await fetch("/api/categories");
|
||
if (checkTokenExpired(res)) return;
|
||
const data = await res.json();
|
||
categories = data.categories || [];
|
||
} catch (e) { console.error("加载大类失败", e); }
|
||
}
|
||
|
||
// ====== 加载年度 ======
|
||
async function loadYears() {
|
||
try {
|
||
const res = await fetch("/api/years");
|
||
if (checkTokenExpired(res)) return;
|
||
const data = await res.json();
|
||
years = data.years || [];
|
||
} catch (e) { console.error("加载年度失败", e); }
|
||
}
|
||
|
||
// ====== 加载项目 ======
|
||
async function loadProjects() {
|
||
try {
|
||
const res = await fetch("/api/projects");
|
||
if (checkTokenExpired(res)) return;
|
||
const data = await res.json();
|
||
projects = data.projects;
|
||
if (viewMode === 'project') renderProjectTree();
|
||
} catch (e) {
|
||
showToast("加载项目列表失败", "error");
|
||
}
|
||
}
|
||
|
||
function getStatusBadge(status) {
|
||
const map = {
|
||
"进行中": '<span class="badge badge-blue">进行中</span>',
|
||
"已完成": '<span class="badge badge-green">已完成</span>',
|
||
"暂停": '<span class="badge badge-orange">暂停</span>',
|
||
"已取消": '<span class="badge badge-gray">已取消</span>',
|
||
"未开始": '<span class="badge badge-gray">未开始</span>',
|
||
"待开始": '<span class="badge badge-gray">待开始</span>'
|
||
};
|
||
return map[status] || `<span class="badge badge-gray">${status}</span>`;
|
||
}
|
||
|
||
// ====== 树形菜单渲染 ======
|
||
function renderProjectTree() {
|
||
const el = document.getElementById("projectTree");
|
||
if (!el) return;
|
||
|
||
if (categories.length === 0) {
|
||
el.innerHTML = '<div class="empty-state" style="padding:20px"><p>暂无项目大类<br>点击上方"添加大类"创建</p></div>';
|
||
return;
|
||
}
|
||
|
||
let html = '';
|
||
categories.forEach(cat => {
|
||
const catId = cat.id;
|
||
const catName = cat["大类名称"] || "未命名大类";
|
||
const catYears = years.filter(y => {
|
||
const rel = y["所属大类"];
|
||
return rel && rel.includes(catId);
|
||
});
|
||
|
||
// 如果大类下没有年度,仍然显示大类节点
|
||
html += `<div class="tree-node tree-lvl-1">`;
|
||
html += `<div class="tree-node-header" onclick="toggleNode('cat_${catId}')">`;
|
||
html += `<span class="tree-toggle ${expandedNodes['cat_' + catId] ? 'expanded' : ''} ${catYears.length === 0 ? 'empty' : ''}">▶</span>`;
|
||
html += `<span class="tree-label" id="label_cat_${catId}" ondblclick="startInlineEdit('category','${catId}')">${catName}</span>`;
|
||
if (catYears.length > 0) html += `<span class="tree-badge">${catYears.length}</span>`;
|
||
html += `<span class="tree-actions">`;
|
||
html += `<button class="tree-action-btn edit" title="重命名" onclick="event.stopPropagation();startInlineEdit('category','${catId}')">✏️</button>`;
|
||
html += `<button class="tree-action-btn add" title="添加年度" onclick="event.stopPropagation();openTreeAddModal('year','${catId}')">+</button>`;
|
||
html += `<button class="tree-action-btn del" title="删除" onclick="event.stopPropagation();treeDeleteNode('category','${catId}','${catName}')">🗑</button>`;
|
||
html += `</span>`;
|
||
html += `</div>`;
|
||
|
||
if (expandedNodes['cat_' + catId]) {
|
||
html += `<div class="tree-children show">`;
|
||
catYears.forEach(yr => {
|
||
const yrId = yr.id;
|
||
const yrName = yr["年度名称"] || yr["年度"] || "未命名年度";
|
||
const yrProjects = projects.filter(p => {
|
||
const rel = p["所属年度"];
|
||
return rel && rel.includes(yrId);
|
||
});
|
||
|
||
html += `<div class="tree-node tree-lvl-2">`;
|
||
html += `<div class="tree-node-header" onclick="toggleNode('yr_${yrId}')">`;
|
||
html += `<span class="tree-toggle ${expandedNodes['yr_' + yrId] ? 'expanded' : ''} ${yrProjects.length === 0 ? 'empty' : ''}">▶</span>`;
|
||
html += `<span class="tree-label" id="label_yr_${yrId}" ondblclick="startInlineEdit('year','${yrId}')">${yrName}</span>`;
|
||
if (yrProjects.length > 0) html += `<span class="tree-badge">${yrProjects.length}</span>`;
|
||
html += `<span class="tree-actions">`;
|
||
html += `<button class="tree-action-btn edit" title="重命名" onclick="event.stopPropagation();startInlineEdit('year','${yrId}')">✏️</button>`;
|
||
html += `<button class="tree-action-btn add" title="添加项目" onclick="event.stopPropagation();openTreeAddModal('project','${yrId}')">+</button>`;
|
||
html += `<button class="tree-action-btn del" title="删除" onclick="event.stopPropagation();treeDeleteNode('year','${yrId}','${yrName}')">🗑</button>`;
|
||
html += `</span>`;
|
||
html += `</div>`;
|
||
|
||
if (expandedNodes['yr_' + yrId]) {
|
||
html += `<div class="tree-children show">`;
|
||
yrProjects.forEach(proj => {
|
||
const projId = proj.id;
|
||
const projName = proj["项目名称"] || "未命名项目";
|
||
const projSteps = steps.filter(s => {
|
||
const rel = s["所属项目"];
|
||
return rel && rel.includes(projId);
|
||
});
|
||
|
||
html += `<div class="tree-node tree-lvl-3">`;
|
||
html += `<div class="tree-node-header" onclick="toggleNode('proj_${projId}')">`;
|
||
html += `<span class="tree-toggle ${expandedNodes['proj_' + projId] ? 'expanded' : ''} ${projSteps.length === 0 ? 'empty' : ''}">▶</span>`;
|
||
html += `<span class="tree-label" id="label_proj_${projId}" ondblclick="startInlineEdit('project','${projId}')">${projName}</span>`;
|
||
if (projSteps.length > 0) html += `<span class="tree-badge">${projSteps.length}</span>`;
|
||
html += `<span class="tree-actions">`;
|
||
html += `<button class="tree-action-btn edit" title="重命名" onclick="event.stopPropagation();startInlineEdit('project','${projId}')">✏️</button>`;
|
||
html += `<button class="tree-action-btn add" title="添加步骤" onclick="event.stopPropagation();openTreeAddModal('step','${projId}')">+</button>`;
|
||
html += `<button class="tree-action-btn del" title="删除" onclick="event.stopPropagation();treeDeleteNode('project','${projId}','${projName}')">🗑</button>`;
|
||
html += `</span>`;
|
||
html += `</div>`;
|
||
|
||
if (expandedNodes['proj_' + projId]) {
|
||
html += `<div class="tree-children show">`;
|
||
if (projSteps.length === 0) {
|
||
html += `<div style="padding:4px 8px;font-size:12px;color:var(--text-muted);">暂无步骤,点击 + 添加</div>`;
|
||
} else {
|
||
projSteps.forEach(step => {
|
||
const stepId = step.id;
|
||
const stepName = step["步骤名称"] || "未命名步骤";
|
||
const stepStatus = step["步骤状态"] || "";
|
||
html += `<div class="tree-step-header ${stepId === currentStepId ? 'active' : ''}" onclick="selectStep('${stepId}', '${projId}')">`;
|
||
html += `<span style="margin-right:4px;">${getStatusDot(stepStatus)}</span>`;
|
||
html += `<span id="label_step_${stepId}" ondblclick="event.stopPropagation();startInlineEdit('step','${stepId}')">${stepName}</span>`;
|
||
html += `<span class="tree-actions">`;
|
||
html += `<button class="tree-action-btn edit" title="重命名" onclick="event.stopPropagation();startInlineEdit('step','${stepId}')">✏️</button>`;
|
||
html += `<button class="tree-action-btn del" title="删除" onclick="event.stopPropagation();treeDeleteNode('step','${stepId}','${stepName}')">🗑</button>`;
|
||
html += `</span>`;
|
||
html += `</div>`;
|
||
});
|
||
}
|
||
html += `</div>`;
|
||
}
|
||
html += `</div>`;
|
||
});
|
||
html += `</div>`;
|
||
}
|
||
html += `</div>`;
|
||
});
|
||
html += `</div>`;
|
||
}
|
||
html += `</div>`;
|
||
});
|
||
|
||
el.innerHTML = html;
|
||
}
|
||
|
||
function getStatusDot(status) {
|
||
const colors = {
|
||
"进行中": "#4B3FE3",
|
||
"已完成": "#1DC981",
|
||
"待开始": "#9CA3AF",
|
||
"未开始": "#9CA3AF",
|
||
"阻塞": "#E8463A",
|
||
"已取消": "#9CA3AF"
|
||
};
|
||
const color = colors[status] || "#9CA3AF";
|
||
return `<span style="display:inline-block;width:6px;height:6px;border-radius:50%;background:${color};"></span>`;
|
||
}
|
||
|
||
function toggleNode(key) {
|
||
expandedNodes[key] = !expandedNodes[key];
|
||
renderProjectTree();
|
||
}
|
||
|
||
// 自动展开到选中步骤的路径
|
||
function autoExpandToStep(stepId) {
|
||
const step = steps.find(s => s.id === stepId);
|
||
if (!step) return;
|
||
const projIds = step["所属项目"] || [];
|
||
const projId = projIds[0];
|
||
if (!projId) return;
|
||
const proj = projects.find(p => p.id === projId);
|
||
if (!proj) return;
|
||
const yrIds = proj["所属年度"] || [];
|
||
const yrId = yrIds[0];
|
||
if (!yrId) return;
|
||
const yr = years.find(y => y.id === yrId);
|
||
if (!yr) return;
|
||
const catIds = yr["所属大类"] || [];
|
||
const catId = catIds[0];
|
||
if (!catId) return;
|
||
|
||
expandedNodes['cat_' + catId] = true;
|
||
expandedNodes['yr_' + yrId] = true;
|
||
expandedNodes['proj_' + projId] = true;
|
||
}
|
||
|
||
function selectStep(stepId, projectId) {
|
||
currentStepId = stepId;
|
||
currentProjectId = projectId;
|
||
renderProjectTree();
|
||
renderStepDetail();
|
||
}
|
||
|
||
// ====== 树节点内联改名 ======
|
||
function startInlineEdit(type, id) {
|
||
const labelId = `label_${type === 'category' ? 'cat' : type === 'year' ? 'yr' : type === 'project' ? 'proj' : 'step'}_${id}`;
|
||
const labelEl = document.getElementById(labelId);
|
||
if (!labelEl) return;
|
||
|
||
const oldName = labelEl.textContent;
|
||
const input = document.createElement('input');
|
||
input.type = 'text';
|
||
input.className = 'tree-edit-input';
|
||
input.value = oldName;
|
||
input.style.fontSize = window.getComputedStyle(labelEl).fontSize;
|
||
|
||
labelEl.replaceWith(input);
|
||
input.focus();
|
||
input.select();
|
||
|
||
let saved = false;
|
||
async function save() {
|
||
if (saved) return;
|
||
saved = true;
|
||
const newName = input.value.trim();
|
||
if (!newName || newName === oldName) {
|
||
input.replaceWith(labelEl);
|
||
return;
|
||
}
|
||
try {
|
||
const form = new FormData();
|
||
const apiPath = type === 'category' ? '/api/categories' : type === 'year' ? '/api/years' : type === 'project' ? '/api/projects' : '/api/steps';
|
||
const nameField = type === 'category' ? 'name' : type === 'year' ? 'name' : type === 'project' ? 'name' : 'name';
|
||
form.append(nameField, newName);
|
||
const res = await fetch(`${apiPath}/${id}`, { method: 'PUT', body: form });
|
||
if (res.ok) {
|
||
showToast('名称已更新');
|
||
if (type === 'category') await loadCategories();
|
||
else if (type === 'year') await loadYears();
|
||
else if (type === 'project') await loadProjects();
|
||
else await loadSteps();
|
||
renderProjectTree();
|
||
} else {
|
||
showToast('更新失败', 'error');
|
||
input.replaceWith(labelEl);
|
||
}
|
||
} catch (e) {
|
||
showToast('网络错误', 'error');
|
||
input.replaceWith(labelEl);
|
||
}
|
||
}
|
||
|
||
input.addEventListener('blur', save);
|
||
input.addEventListener('keydown', (e) => {
|
||
if (e.key === 'Enter') { e.preventDefault(); input.blur(); }
|
||
if (e.key === 'Escape') { saved = true; input.replaceWith(labelEl); }
|
||
});
|
||
}
|
||
|
||
// ====== 树节点添加子节点弹窗 ======
|
||
let treeAddContext = null;
|
||
|
||
async function openTreeAddModal(type, parentId) {
|
||
treeAddContext = { type, parentId };
|
||
|
||
const formDef = RECORD_FORMS[type];
|
||
const titleMap = { category: '新建大类', year: '新建年度', project: '新建项目', step: '新建步骤' };
|
||
document.getElementById('recordModalTitle').textContent = titleMap[type] || formDef.title;
|
||
document.getElementById('recordModalSubmit').textContent = '创建';
|
||
currentEditId = null;
|
||
|
||
// 确保引用数据已加载
|
||
const needPersons = formDef.fields.some(f => f.ref === 'person');
|
||
const needCategories = formDef.fields.some(f => f.ref === 'category');
|
||
const needYears = formDef.fields.some(f => f.ref === 'year');
|
||
const needProjects = formDef.fields.some(f => f.ref === 'project');
|
||
const needSteps = formDef.fields.some(f => f.ref === 'step');
|
||
const loads = [];
|
||
if (needPersons && !persons.length) loads.push(loadDataTable('person'));
|
||
if (needCategories && !categories.length) loads.push(loadDataTable('category'));
|
||
if (needYears && !years.length) loads.push(loadDataTable('year'));
|
||
if (needProjects && !projects.length) loads.push(loadDataTable('project'));
|
||
if (needSteps && !steps.length) loads.push(loadDataTable('step'));
|
||
if (loads.length) await Promise.all(loads);
|
||
|
||
// 构建预填值
|
||
const presets = {};
|
||
if (type === 'year' && parentId) {
|
||
presets['category_id'] = parentId;
|
||
} else if (type === 'project' && parentId) {
|
||
presets['year_id'] = parentId;
|
||
// 自动推断所属大类
|
||
const yr = years.find(y => y.id === parentId);
|
||
if (yr) {
|
||
const catIds = yr["所属大类"] || [];
|
||
if (catIds.length > 0) presets['category_id'] = catIds[0];
|
||
}
|
||
} else if (type === 'step' && parentId) {
|
||
presets['project_id'] = parentId;
|
||
}
|
||
|
||
// 默认值
|
||
const defaults = {
|
||
'status': type === 'step' ? '待开始' : '未开始',
|
||
'priority': 'P2',
|
||
'progress': '0',
|
||
'budget': '0'
|
||
};
|
||
|
||
const html = formDef.fields.map(f => {
|
||
// 预填外键字段:设为只读
|
||
const isPreset = presets.hasOwnProperty(f.name);
|
||
|
||
if (f.type === 'select') {
|
||
const defVal = defaults[f.name] || '';
|
||
const opts = f.options.map(o => `<option value="${o}" ${isPreset ? '' : (o === defVal ? 'selected' : '')}>${o}</option>`).join('');
|
||
return `<div class="form-group"><label>${f.label}${f.required ? ' *' : ''}</label><select id="f_${f.name}" ${isPreset ? 'disabled' : ''}>${opts}</select></div>`;
|
||
}
|
||
if (f.type === 'select_ref') {
|
||
let options = [];
|
||
if (f.ref === 'person') options = persons;
|
||
if (f.ref === 'category') options = categories;
|
||
if (f.ref === 'year') options = years;
|
||
if (f.ref === 'project') options = projects;
|
||
if (f.ref === 'step') options = steps;
|
||
|
||
const presetVal = presets[f.name] || '';
|
||
const opts = options.map(o => {
|
||
const label = o[f.refLabel] || o['姓名'] || o['大类名称'] || o['年度名称'] || o['项目名称'] || o['步骤名称'] || o.id;
|
||
return `<option value="${o.id}" ${o.id === presetVal ? 'selected' : ''}>${label}</option>`;
|
||
}).join('');
|
||
|
||
if (isPreset && presetVal) {
|
||
// 预填且只读
|
||
const sel = options.find(o => o.id === presetVal);
|
||
const selLabel = sel ? (sel[f.refLabel] || sel['姓名'] || sel['大类名称'] || sel['年度名称'] || sel['项目名称'] || sel['步骤名称'] || presetVal) : presetVal;
|
||
return `<div class="form-group"><label>${f.label}</label><select id="f_${f.name}" disabled><option value="${presetVal}" selected>${selLabel}</option></select><input type="hidden" id="f_${f.name}_val" value="${presetVal}"></div>`;
|
||
}
|
||
return `<div class="form-group"><label>${f.label}</label><select id="f_${f.name}"><option value="">-- 请选择 --</option>${opts}</select></div>`;
|
||
}
|
||
if (f.type === 'textarea') {
|
||
return `<div class="form-group"><label>${f.label}${f.required ? ' *' : ''}</label><textarea id="f_${f.name}" placeholder="${f.placeholder || ''}"></textarea></div>`;
|
||
}
|
||
const inputType = f.type === 'number' ? 'number' : f.type === 'date' ? 'date' : 'text';
|
||
const defVal = defaults[f.name] || '';
|
||
return `<div class="form-group"><label>${f.label}${f.required ? ' *' : ''}</label><input type="${inputType}" id="f_${f.name}" placeholder="${f.placeholder || ''}" value="${defVal}"></div>`;
|
||
}).join('');
|
||
|
||
document.getElementById('recordModalBody').innerHTML = html;
|
||
document.getElementById('modalCreateRecord').classList.add('show');
|
||
}
|
||
|
||
// 树模式提交(由 submitRecord 调用)
|
||
async function submitTreeRecord() {
|
||
const { type, parentId } = treeAddContext;
|
||
const formDef = RECORD_FORMS[type];
|
||
const vals = {};
|
||
for (const f of formDef.fields) {
|
||
const el = document.getElementById(`f_${f.name}`);
|
||
if (el && el.disabled) {
|
||
const hidden = document.getElementById(`f_${f.name}_val`);
|
||
vals[f.name] = hidden ? hidden.value : el.value;
|
||
} else {
|
||
vals[f.name] = el ? el.value.trim() : '';
|
||
}
|
||
if (f.required && !vals[f.name]) {
|
||
showToast(`${f.label} 不能为空`, "error");
|
||
return;
|
||
}
|
||
}
|
||
try {
|
||
const res = await formDef.submit(vals);
|
||
const data = await res.json();
|
||
if (res.ok) {
|
||
showToast(`${formDef.title}成功`);
|
||
closeModal('modalCreateRecord');
|
||
treeAddContext = null;
|
||
// 重新加载数据
|
||
if (type === 'category') await loadCategories();
|
||
else if (type === 'year') await loadYears();
|
||
else if (type === 'project') await loadProjects();
|
||
else if (type === 'step') await loadSteps();
|
||
// 展开父节点
|
||
if (parentId) {
|
||
if (type === 'year') expandedNodes['cat_' + parentId] = true;
|
||
else if (type === 'project') expandedNodes['yr_' + parentId] = true;
|
||
else if (type === 'step') expandedNodes['proj_' + parentId] = true;
|
||
}
|
||
renderProjectTree();
|
||
} else {
|
||
showToast(data.detail || '创建失败', "error");
|
||
}
|
||
} catch (e) { showToast("网络错误", "error"); }
|
||
}
|
||
|
||
// ====== 树节点删除 ======
|
||
let treeDeleteContext = null;
|
||
|
||
async function treeDeleteNode(type, id, name) {
|
||
treeDeleteContext = { type, id, name };
|
||
|
||
const tableKey = type === 'category' ? 'category' : type === 'year' ? 'year' : type === 'project' ? 'project' : 'step';
|
||
const table = DATA_TABLES.find(t => t.key === tableKey);
|
||
const apiPath = table.api;
|
||
|
||
// 统计子节点数量
|
||
let childCount = 0;
|
||
let childDesc = '';
|
||
if (type === 'category') {
|
||
const catYears = years.filter(y => { const r = y["所属大类"]; return r && r.includes(id); });
|
||
childCount = catYears.length;
|
||
childDesc = `${childCount} 个年度`;
|
||
let total = 0;
|
||
catYears.forEach(yr => {
|
||
const yrProjs = projects.filter(p => { const r = p["所属年度"]; return r && r.includes(yr.id); });
|
||
total += yrProjs.length;
|
||
yrProjs.forEach(p => {
|
||
const s = steps.filter(st => { const r = st["所属项目"]; return r && r.includes(p.id); });
|
||
total += s.length;
|
||
});
|
||
});
|
||
if (total > 0) childDesc += `、${total} 个项目/步骤`;
|
||
} else if (type === 'year') {
|
||
const yrProjs = projects.filter(p => { const r = p["所属年度"]; return r && r.includes(id); });
|
||
childCount = yrProjs.length;
|
||
childDesc = `${childCount} 个项目`;
|
||
let total = 0;
|
||
yrProjs.forEach(p => {
|
||
const s = steps.filter(st => { const r = st["所属项目"]; return r && r.includes(p.id); });
|
||
total += s.length;
|
||
});
|
||
if (total > 0) childDesc += `、${total} 个步骤`;
|
||
} else if (type === 'project') {
|
||
const projSteps = steps.filter(s => { const r = s["所属项目"]; return r && r.includes(id); });
|
||
childCount = projSteps.length;
|
||
childDesc = `${childCount} 个步骤`;
|
||
}
|
||
|
||
const typeLabel = type === 'category' ? '大类' : type === 'year' ? '年度' : type === 'project' ? '项目' : '步骤';
|
||
const msg = childCount > 0
|
||
? `确定要删除${typeLabel}"${name}"吗?\n\n该${typeLabel}下包含 ${childDesc} 及相关审计资料,删除后不可恢复。`
|
||
: `确定要删除${typeLabel}"${name}"吗?此操作不可恢复。`;
|
||
|
||
const relatedEl = document.getElementById('relatedRecords');
|
||
const msgEl = document.getElementById('deleteMessage');
|
||
const confirmBtn = document.getElementById('confirmDelete');
|
||
|
||
msgEl.textContent = msg;
|
||
relatedEl.innerHTML = childCount > 0
|
||
? `<div class="tree-delete-warning">⚠️ 级联删除:将同时删除所有子节点及关联数据</div>`
|
||
: '';
|
||
confirmBtn.disabled = false;
|
||
confirmBtn.onclick = async () => {
|
||
confirmBtn.disabled = true;
|
||
try {
|
||
const delRes = await fetch(`${apiPath}/${id}`, { method: 'DELETE' });
|
||
const delData = await delRes.json();
|
||
if (delRes.ok) {
|
||
showToast('删除成功');
|
||
closeModal('modalDelete');
|
||
treeDeleteContext = null;
|
||
// 清空当前选中的步骤如果被删除
|
||
if (type === 'step' && currentStepId === id) {
|
||
currentStepId = null;
|
||
}
|
||
// 重新加载
|
||
if (type === 'category') { await loadCategories(); await loadYears(); await loadProjects(); await loadSteps(); }
|
||
else if (type === 'year') { await loadYears(); await loadProjects(); await loadSteps(); }
|
||
else if (type === 'project') { await loadProjects(); await loadSteps(); }
|
||
else { await loadSteps(); }
|
||
renderProjectTree();
|
||
if (currentStepId) renderStepDetail();
|
||
else document.getElementById('mainContent').innerHTML = '<div class="empty-state"><p>请从左侧选择一个项目步骤</p></div>';
|
||
} else {
|
||
const errMsg = delData.detail && delData.detail.message ? delData.detail.message : (delData.detail || '删除失败');
|
||
showToast(errMsg, 'error');
|
||
confirmBtn.disabled = false;
|
||
}
|
||
} catch (e) {
|
||
showToast('网络错误', 'error');
|
||
confirmBtn.disabled = false;
|
||
}
|
||
};
|
||
document.getElementById('modalDelete').classList.add('show');
|
||
}
|
||
|
||
// ====== 加载步骤 ======
|
||
async function loadSteps() {
|
||
try {
|
||
const res = await fetch("/api/steps");
|
||
if (checkTokenExpired(res)) return;
|
||
const data = await res.json();
|
||
steps = data.steps || [];
|
||
} catch (e) { console.error("加载步骤失败", e); }
|
||
}
|
||
|
||
// ====== 加载资料 ======
|
||
async function loadDocs() {
|
||
try {
|
||
const res = await fetch("/api/docs");
|
||
if (checkTokenExpired(res)) return;
|
||
const data = await res.json();
|
||
docs = data.docs;
|
||
} catch (e) { console.error("加载资料失败", e); }
|
||
}
|
||
|
||
// ====== 加载分析结果 ======
|
||
async function loadResults() {
|
||
try {
|
||
const res = await fetch("/api/results");
|
||
if (checkTokenExpired(res)) return;
|
||
const data = await res.json();
|
||
results = data.results;
|
||
} catch (e) { console.error("加载结果失败", e); }
|
||
}
|
||
|
||
// ====== 渲染步骤详情(右侧) ======
|
||
async function renderStepDetail() {
|
||
const main = document.getElementById("mainContent");
|
||
if (!currentStepId) {
|
||
main.innerHTML = '<div class="empty-state"><p>请从左侧选择一个项目步骤</p></div>';
|
||
return;
|
||
}
|
||
|
||
const step = steps.find(s => s.id === currentStepId);
|
||
if (!step) {
|
||
main.innerHTML = '<div class="empty-state"><p>步骤不存在</p></div>';
|
||
return;
|
||
}
|
||
|
||
// 确保数据已加载
|
||
if (!steps.length) await loadSteps();
|
||
if (!docs.length) await loadDocs();
|
||
if (!results.length) await loadResults();
|
||
|
||
const stepName = step["步骤名称"] || "未命名步骤";
|
||
const stepStatus = step["步骤状态"] || "";
|
||
const stepPriority = step["优先级"] || "";
|
||
const stepProgress = step["进度"];
|
||
const stepDeliverable = step["交付物"] || "";
|
||
const stepRemark = step["备注"] || "";
|
||
const startDate = step["开始日期"] || "";
|
||
const endDate = step["结束日期"] || "";
|
||
|
||
// 查找所属项目信息(用于面包屑和新建资料)
|
||
const project = projects.find(p => p.id === currentProjectId);
|
||
const projectName = project ? (project["项目名称"] || "未命名项目") : "";
|
||
|
||
// 查找项目所属年度和大类(面包屑)
|
||
let yearName = "";
|
||
let catName = "";
|
||
if (project) {
|
||
const yrIds = project["所属年度"] || [];
|
||
if (yrIds.length > 0) {
|
||
const yr = years.find(y => y.id === yrIds[0]);
|
||
if (yr) {
|
||
yearName = yr["年度名称"] || yr["年度"] || "";
|
||
const catIds = yr["所属大类"] || [];
|
||
if (catIds.length > 0) {
|
||
const cat = categories.find(c => c.id === catIds[0]);
|
||
if (cat) catName = cat["大类名称"] || "";
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// 筛选当前步骤的审计资料
|
||
const stepDocs = docs.filter(d => {
|
||
const stepIds = d["所属步骤"] || [];
|
||
return stepIds.includes(currentStepId);
|
||
});
|
||
|
||
// 筛选当前步骤资料的分析结果
|
||
const stepResults = [];
|
||
results.forEach(r => {
|
||
const docRefs = r["关联资料"] || [];
|
||
docRefs.forEach(rid => {
|
||
if (stepDocs.find(d => d.id === rid)) {
|
||
if (!stepResults.find(sr => sr.id === r.id)) stepResults.push(r);
|
||
}
|
||
});
|
||
});
|
||
|
||
// 构建面包屑
|
||
const breadcrumb = [catName, yearName, projectName, stepName].filter(Boolean).join(" › ");
|
||
|
||
main.innerHTML = `
|
||
<div class="section-header">
|
||
<div>
|
||
<div style="font-size:12px;color:var(--text-muted);margin-bottom:4px;">${breadcrumb}</div>
|
||
<h2>${stepName}</h2>
|
||
<div style="margin-top:4px;display:flex;gap:8px;align-items:center;flex-wrap:wrap;">
|
||
${getStatusBadge(stepStatus)}
|
||
${stepPriority ? `<span class="badge badge-gray">${stepPriority}</span>` : ""}
|
||
${stepProgress !== undefined && stepProgress !== null ? `<span style="font-size:12px;color:var(--text-muted)">进度: ${stepProgress}%</span>` : ""}
|
||
${startDate ? `<span style="font-size:12px;color:var(--text-muted)">${startDate} ~ ${endDate || '至今'}</span>` : ""}
|
||
</div>
|
||
</div>
|
||
<button class="btn btn-primary" onclick="openCreateDoc('${currentStepId}')">+ 新建资料</button>
|
||
</div>
|
||
|
||
${(stepDeliverable || stepRemark) ? `<div class="card">
|
||
<div class="card-title">步骤信息</div>
|
||
${stepDeliverable ? `<div style="font-size:14px;margin-bottom:6px;"><strong>交付物:</strong>${stepDeliverable}</div>` : ""}
|
||
${stepRemark ? `<div style="font-size:14px;color:var(--text-muted);"><strong>备注:</strong>${stepRemark}</div>` : ""}
|
||
</div>` : ""}
|
||
|
||
<div class="card">
|
||
<div class="card-title">审计资料(${stepDocs.length})</div>
|
||
${stepDocs.length === 0
|
||
? '<div class="empty-state" style="padding:12px"><p>暂无资料,点击上方按钮新建</p></div>'
|
||
: `<div class="doc-list">${stepDocs.map(doc => renderDocItem(doc)).join("")}</div>`
|
||
}
|
||
</div>
|
||
|
||
<div class="card">
|
||
<div class="card-title">分析结果(${stepResults.length})</div>
|
||
${stepResults.length === 0
|
||
? '<div class="empty-state" style="padding:12px"><p>暂无分析结果</p></div>'
|
||
: `<div>${stepResults.map(r => renderResultItem(r)).join("")}</div>`
|
||
}
|
||
</div>
|
||
`;
|
||
}
|
||
|
||
function renderDocItem(doc) {
|
||
const title = doc["资料标题"] || "未命名";
|
||
const type = doc["资料类型"] || "";
|
||
const status = doc["资料状态"] || "";
|
||
const atts = parseAttachments(doc["附件"]);
|
||
const attBadge = atts.length > 0 ? `<span class="badge badge-blue" style="margin-left:4px;">📎 ${atts.length}个附件</span>` : '';
|
||
return `<div class="doc-item">
|
||
<div class="info">
|
||
<div class="title">${title}</div>
|
||
<div class="meta">${getTypeBadge(type)} ${getDocStatusBadge(status)}${doc["流程状态"] ? getWorkflowBadge(doc["流程状态"], doc["作业类别"]) : ""}${attBadge}</div>
|
||
</div>
|
||
<div class="actions">
|
||
<button class="btn" onclick="viewDoc('${doc.id}')">详情</button>
|
||
<button class="btn" onclick="openEditDocModal('${doc.id}')">修改</button>
|
||
<button class="btn btn-danger" onclick="deleteDoc('${doc.id}')">删除</button>
|
||
${status === "待分析" ? `<button class="btn btn-primary" onclick="analyzeDoc('${doc.id}')">分析</button>` : ""}
|
||
</div>
|
||
</div>`;
|
||
}
|
||
|
||
function getTypeBadge(type) {
|
||
const map = { "报告": '<span class="badge badge-blue">报告</span>', "方案": '<span class="badge badge-orange">方案</span>', "底稿": '<span class="badge badge-green">底稿</span>' };
|
||
return map[type] || `<span class="badge badge-gray">${type}</span>`;
|
||
}
|
||
|
||
function getWorkflowBadge(status, category) {
|
||
if (!status) return "";
|
||
const label = (category === "workpaper" ? "底稿" : category === "evidence" ? "取证" : category === "report" ? "报告" : "作业") + " · " + status;
|
||
const map = { "草稿": "badge-gray", "待复核": "badge-orange", "已复核": "badge-green", "已归档": "badge-blue",
|
||
"待签收": "badge-orange", "已签收": "badge-blue",
|
||
"编制中": "badge-gray", "已签发": "badge-green" };
|
||
return `<span class="badge ${map[status] || "badge-gray"}">${label}</span>`;
|
||
}
|
||
|
||
function getDocStatusBadge(status) {
|
||
const map = { "待分析": '<span class="badge badge-gray">待分析</span>', "分析中": '<span class="badge badge-orange">分析中</span>', "已完成": '<span class="badge badge-green">已完成</span>' };
|
||
return map[status] || `<span class="badge badge-gray">${status}</span>`;
|
||
}
|
||
|
||
function renderResultItem(r) {
|
||
const type = r["分析类型"] || "";
|
||
const summary = r["分析摘要"] || "";
|
||
const risk = r["风险等级"] || "";
|
||
const findings = r["关键发现"] || "";
|
||
const suggestions = r["改进建议"] || "";
|
||
const raw = r["原始模型输出"] || "";
|
||
const riskBadge = risk === "高" ? "badge-red" : risk === "中" ? "badge-orange" : "badge-green";
|
||
|
||
// 反查对应资料名称(从已加载的 docs 列表里找)
|
||
const docRefs = r["关联资料"] || [];
|
||
const docNames = docRefs.map(rid => {
|
||
const d = docs.find(x => x.id === rid);
|
||
return d ? (d["资料标题"] || "未命名资料") : "";
|
||
}).filter(Boolean);
|
||
const docLabel = docNames.length > 0
|
||
? `<div style="font-size:12px;color:var(--text-muted);margin-bottom:6px;">📄 对应资料:${docNames.map(n => `<strong>${n}</strong>`).join("、")}</div>`
|
||
: "";
|
||
|
||
// 从原始模型输出中提取 references 字段(历史分析结果可能没有单独存储)
|
||
let references = "";
|
||
if (raw) {
|
||
try {
|
||
const parsed = JSON.parse(raw);
|
||
references = parsed.references || "";
|
||
} catch (e) { /* 非JSON格式,忽略 */ }
|
||
}
|
||
|
||
return `<div class="result-card">
|
||
${docLabel}
|
||
<div class="result-header">
|
||
<span class="result-type">${type}</span>
|
||
<div style="display:flex;gap:8px;align-items:center;">
|
||
<span class="badge ${riskBadge}">风险等级: ${risk}</span>
|
||
<button class="btn" style="padding:4px 12px;font-size:12px;" onclick="reanalyzeResult('${r.id}')">重新分析</button>
|
||
<button class="btn" style="padding:4px 12px;font-size:12px;" onclick="openEditResultModal('${r.id}')">修改</button>
|
||
<button class="btn btn-danger" style="padding:4px 12px;font-size:12px;" onclick="deleteResult('${r.id}')">删除</button>
|
||
</div>
|
||
</div>
|
||
<div class="result-summary">${summary}</div>
|
||
${findings ? `<div class="result-detail"><strong>关键发现:</strong><pre>${findings}</pre></div>` : ""}
|
||
${suggestions ? `<div class="result-detail"><strong>改进建议:</strong><pre>${suggestions}</pre></div>` : ""}
|
||
${references ? `<div class="result-detail" style="border-left:3px solid var(--primary);padding-left:12px;background:var(--primary-light);border-radius:var(--radius-md);"><strong>📚 引用制度依据:</strong><pre style="background:var(--surface-card);">${references}</pre></div>` : ""}
|
||
${raw ? `<div class="result-detail" style="margin-top:8px;"><small><a href="#" onclick="toggleRaw(this)">查看原始模型输出</a></small><pre style="display:none">${raw}</pre></div>` : ""}
|
||
</div>`;
|
||
}
|
||
|
||
function toggleRaw(el) {
|
||
const pre = el.nextElementSibling;
|
||
if (pre.style.display === "none") { pre.style.display = "block"; el.textContent = "收起原始输出"; }
|
||
else { pre.style.display = "none"; el.textContent = "查看原始模型输出"; }
|
||
return false;
|
||
}
|
||
|
||
// ====== 附件处理 ======
|
||
|
||
// 清理文件名中的UUID前缀(形如 904704a1-xxxx-xxxx_filename.docx)
|
||
function cleanFileName(name) {
|
||
if (!name) return name;
|
||
// 匹配 UUID前缀_ 的模式
|
||
return name.replace(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}_/i, '');
|
||
}
|
||
|
||
// 格式化文件大小
|
||
function formatFileSize(bytes) {
|
||
if (!bytes || bytes === 0) return '';
|
||
if (bytes < 1024) return bytes + ' B';
|
||
if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + ' KB';
|
||
return (bytes / (1024 * 1024)).toFixed(1) + ' MB';
|
||
}
|
||
|
||
// 获取文件图标
|
||
function getFileIcon(name) {
|
||
if (!name) return '📄';
|
||
const ext = name.split('.').pop().toLowerCase();
|
||
const icons = { 'doc': '📝', 'docx': '📝', 'xls': '📊', 'xlsx': '📊', 'pdf': '📄', 'ppt': '📑', 'pptx': '📑', 'zip': '📦', 'rar': '📦', 'jpg': '🖼️', 'jpeg': '🖼️', 'png': '🖼️', 'gif': '🖼️', 'txt': '📄', 'csv': '📊' };
|
||
return icons[ext] || '📄';
|
||
}
|
||
|
||
// 解析附件字段,返回标准数组
|
||
function parseAttachments(attField) {
|
||
if (!attField) return [];
|
||
if (Array.isArray(attField)) {
|
||
return attField.map(a => {
|
||
if (typeof a === 'string') return { name: cleanFileName(a), file_token: '', size: 0 };
|
||
return { name: cleanFileName(a.name || a.file_token || '未知文件'), file_token: a.file_token || '', size: a.size || 0 };
|
||
});
|
||
}
|
||
if (typeof attField === 'string') return [{ name: cleanFileName(attField), file_token: '', size: 0 }];
|
||
return [];
|
||
}
|
||
|
||
// 渲染附件列表HTML
|
||
// editable: 是否显示删除按钮
|
||
// onDelete: 删除后的回调函数(可选)
|
||
function renderAttachmentList(attField, docId, editable = false, onDelete = null) {
|
||
const atts = parseAttachments(attField);
|
||
if (atts.length === 0) return '<div style="font-size:13px;color:var(--text-muted);">无附件</div>';
|
||
return '<div class="attachment-list">' + atts.map(a => {
|
||
const downloadLink = a.file_token
|
||
? `<a class="file-download" href="/api/docs/${docId}/download?file_token=${a.file_token}" target="_blank">下载</a>`
|
||
: '';
|
||
const deleteBtn = (editable && a.file_token)
|
||
? `<button class="file-delete" onclick="deleteAttachment('${docId}', '${a.file_token}', '${a.name.replace(/'/g, "\\'")}')">删除</button>`
|
||
: '';
|
||
const previewBtn = a.file_token
|
||
? `<button class="file-preview" onclick="previewAttachment('${a.file_token}', '${a.name.replace(/'/g, "\\'")}')">预览</button>`
|
||
: '';
|
||
return `<div class="attachment-item" data-file-token="${a.file_token || ''}">
|
||
<span class="file-icon">${getFileIcon(a.name)}</span>
|
||
<span class="file-name" title="${a.name}">${a.name}</span>
|
||
${a.size ? `<span class="file-size">${formatFileSize(a.size)}</span>` : ''}
|
||
${previewBtn}
|
||
${downloadLink}
|
||
${deleteBtn}
|
||
</div>`;
|
||
}).join('') + '</div>';
|
||
}
|
||
|
||
// 删除附件
|
||
async function deleteAttachment(docId, fileToken, fileName) {
|
||
if (!confirm(`确定要删除附件「${fileName}」吗?`)) return;
|
||
try {
|
||
const res = await fetch(`/api/docs/${docId}/attachments/${fileToken}`, { method: 'DELETE' });
|
||
if (res.ok) {
|
||
showToast('附件删除成功');
|
||
// 刷新数据
|
||
await loadDocs();
|
||
// 如果当前在查看详情,刷新详情
|
||
const detailModal = document.getElementById('modalDetail');
|
||
if (detailModal && detailModal.classList.contains('show')) {
|
||
await viewDoc(docId);
|
||
}
|
||
// 如果当前在编辑弹窗,刷新已有附件列表
|
||
const editModal = document.getElementById('modalCreateRecord');
|
||
if (editModal && editModal.classList.contains('show') && currentEditDocId === docId) {
|
||
const doc = docs.find(d => d.id === docId);
|
||
if (doc) {
|
||
const attContainer = document.getElementById('existingAttachments');
|
||
const atts = parseAttachments(doc['附件']);
|
||
if (atts.length > 0) {
|
||
attContainer.innerHTML = '<div style="font-size:12px;color:var(--text-muted);margin-bottom:6px;">已有附件:</div>' + atts.map(a => {
|
||
const downloadLink = a.file_token
|
||
? `<a class="file-download" href="/api/docs/${docId}/download?file_token=${a.file_token}" target="_blank">下载</a>`
|
||
: '';
|
||
const deleteBtn = a.file_token
|
||
? `<button class="file-delete" onclick="deleteAttachment('${docId}', '${a.file_token}', '${a.name.replace(/'/g, "\\'")}')">删除</button>`
|
||
: '';
|
||
return `<div class="attachment-item">
|
||
<span class="file-icon">${getFileIcon(a.name)}</span>
|
||
<span class="file-name" title="${a.name}">${a.name}</span>
|
||
${a.size ? `<span class="file-size">${formatFileSize(a.size)}</span>` : ''}
|
||
${downloadLink}
|
||
${deleteBtn}
|
||
</div>`;
|
||
}).join('');
|
||
} else {
|
||
attContainer.innerHTML = '<div style="font-size:12px;color:var(--text-muted);">暂无附件</div>';
|
||
}
|
||
}
|
||
}
|
||
// 如果在步骤详情页,刷新详情
|
||
if (currentStepId) renderStepDetail();
|
||
} else {
|
||
const data = await res.json();
|
||
showToast(data.detail || '删除失败', 'error');
|
||
}
|
||
} catch (e) {
|
||
showToast('删除失败:网络错误', 'error');
|
||
}
|
||
}
|
||
|
||
// ====== 文件预览 ======
|
||
let previewZoom = 100;
|
||
let previewIsFullscreen = false;
|
||
|
||
function applyPreviewZoom() {
|
||
const body = document.getElementById('previewBody');
|
||
const htmlDiv = body.querySelector('.preview-html');
|
||
if (htmlDiv) {
|
||
htmlDiv.style.zoom = previewZoom + '%';
|
||
htmlDiv.style.transform = `scale(${previewZoom / 100})`;
|
||
htmlDiv.style.transformOrigin = 'top left';
|
||
}
|
||
document.getElementById('previewZoomLabel').textContent = previewZoom + '%';
|
||
}
|
||
|
||
async function previewAttachment(fileToken, fileName) {
|
||
const ext = (fileName.split('.').pop() || '').toLowerCase();
|
||
const supported = ['pdf', 'docx', 'xlsx'];
|
||
|
||
if (!supported.includes(ext)) {
|
||
showToast(`不支持预览 .${ext} 格式,请下载后查看`, "error");
|
||
return;
|
||
}
|
||
|
||
previewZoom = 100;
|
||
previewIsFullscreen = false;
|
||
const box = document.getElementById('previewModalBox');
|
||
box.style.width = '90%';
|
||
box.style.maxWidth = '900px';
|
||
box.style.maxHeight = '85vh';
|
||
box.style.height = '85vh';
|
||
box.style.borderRadius = '';
|
||
|
||
document.getElementById('previewTitle').textContent = fileName;
|
||
document.getElementById('previewZoomLabel').textContent = '100%';
|
||
const body = document.getElementById('previewBody');
|
||
body.innerHTML = '<div class="preview-loading">加载中...</div>';
|
||
document.getElementById('modalPreview').classList.add('show');
|
||
|
||
try {
|
||
if (ext === 'pdf') {
|
||
body.innerHTML = `<iframe src="/api/preview/${fileToken}" title="预览"></iframe>`;
|
||
} else {
|
||
const resp = await fetch(`/api/preview/${fileToken}`);
|
||
if (!resp.ok) {
|
||
const err = await resp.json();
|
||
body.innerHTML = `<div class="preview-error">${err.detail || '预览失败'}</div>`;
|
||
return;
|
||
}
|
||
const html = await resp.text();
|
||
body.innerHTML = `<div class="preview-html">${html}</div>`;
|
||
}
|
||
} catch (e) {
|
||
body.innerHTML = '<div class="preview-error">预览失败:网络错误</div>';
|
||
}
|
||
}
|
||
|
||
function bindPreviewControls() {
|
||
var zi = document.getElementById('previewZoomIn');
|
||
var zo = document.getElementById('previewZoomOut');
|
||
var fs = document.getElementById('previewFullscreen');
|
||
if (zi) zi.addEventListener('click', function() { if (previewZoom < 200) { previewZoom += 10; applyPreviewZoom(); } });
|
||
if (zo) zo.addEventListener('click', function() { if (previewZoom > 50) { previewZoom -= 10; applyPreviewZoom(); } });
|
||
if (fs) fs.addEventListener('click', function() {
|
||
previewIsFullscreen = !previewIsFullscreen;
|
||
var box = document.getElementById('previewModalBox');
|
||
if (previewIsFullscreen) {
|
||
box.style.width = '100%';
|
||
box.style.maxWidth = '100%';
|
||
box.style.maxHeight = '100vh';
|
||
box.style.height = '100vh';
|
||
box.style.borderRadius = '0';
|
||
} else {
|
||
box.style.width = '90%';
|
||
box.style.maxWidth = '900px';
|
||
box.style.maxHeight = '85vh';
|
||
box.style.height = '85vh';
|
||
box.style.borderRadius = '';
|
||
}
|
||
});
|
||
}
|
||
bindPreviewControls();
|
||
|
||
// ====== 新建资料弹窗 ======
|
||
function openCreateDoc(stepId) {
|
||
if (!currentProjectId) { showToast("请先选择一个项目", "error"); return; }
|
||
currentEditDocId = null;
|
||
document.getElementById("docModalTitle").textContent = "新建审计资料";
|
||
document.getElementById("docModalSubmit").textContent = "创建";
|
||
document.getElementById("docFileGroup").style.display = "block";
|
||
document.getElementById("docFileGroup").querySelector("label").textContent = "附件文件";
|
||
document.getElementById("modalCreateDoc").classList.add("show");
|
||
document.getElementById("docTitle").value = "";
|
||
document.getElementById("docType").value = "报告";
|
||
document.getElementById("docContent").value = "";
|
||
document.getElementById("docFile").value = "";
|
||
document.getElementById("existingAttachments").innerHTML = "";
|
||
|
||
// 填充所属步骤下拉框(仅显示当前项目的步骤)
|
||
const stepSelect = document.getElementById("docStep");
|
||
const projectSteps = steps.filter(s => {
|
||
const rel = s["所属项目"];
|
||
return rel && rel.includes(currentProjectId);
|
||
});
|
||
stepSelect.innerHTML = '<option value="">-- 不关联步骤 --</option>' +
|
||
projectSteps.map(s => `<option value="${s.id}">${s['步骤名称'] || '未命名'}</option>`).join('');
|
||
stepSelect.value = stepId || '';
|
||
}
|
||
|
||
async function openEditDocModal(docId) {
|
||
currentEditDocId = docId;
|
||
try {
|
||
const res = await fetch(`/api/docs/${docId}`);
|
||
if (checkTokenExpired(res)) return;
|
||
const data = await res.json();
|
||
const doc = data.doc;
|
||
if (!doc) { showToast("资料不存在", "error"); return; }
|
||
|
||
document.getElementById("docModalTitle").textContent = "修改审计资料";
|
||
document.getElementById("docModalSubmit").textContent = "保存";
|
||
document.getElementById("docFileGroup").style.display = "block";
|
||
document.getElementById("docFileGroup").querySelector("label").textContent = "上传新附件(可选)";
|
||
document.getElementById("docTitle").value = doc["资料标题"] || "";
|
||
document.getElementById("docType").value = doc["资料类型"] || "报告";
|
||
document.getElementById("docContent").value = doc["正文内容"] || "";
|
||
document.getElementById("docFile").value = "";
|
||
|
||
// 显示已有附件
|
||
const attContainer = document.getElementById("existingAttachments");
|
||
const atts = parseAttachments(doc["附件"]);
|
||
if (atts.length > 0) {
|
||
attContainer.innerHTML = '<div style="font-size:12px;color:var(--text-muted);margin-bottom:6px;">已有附件(可删除):</div>' + atts.map(a => {
|
||
const downloadLink = a.file_token
|
||
? `<a class="file-download" href="/api/docs/${docId}/download?file_token=${a.file_token}" target="_blank">下载</a>`
|
||
: '';
|
||
const deleteBtn = a.file_token
|
||
? `<button class="file-delete" onclick="deleteAttachment('${docId}', '${a.file_token}', '${a.name.replace(/'/g, "\\'")}')">删除</button>`
|
||
: '';
|
||
const previewBtn = a.file_token
|
||
? `<button class="file-preview" onclick="previewAttachment('${a.file_token}', '${a.name.replace(/'/g, "\\'")}')">预览</button>`
|
||
: '';
|
||
return `<div class="attachment-item">
|
||
<span class="file-icon">${getFileIcon(a.name)}</span>
|
||
<span class="file-name" title="${a.name}">${a.name}</span>
|
||
${a.size ? `<span class="file-size">${formatFileSize(a.size)}</span>` : ''}
|
||
${previewBtn}
|
||
${downloadLink}
|
||
${deleteBtn}
|
||
</div>`;
|
||
}).join('');
|
||
} else {
|
||
attContainer.innerHTML = '';
|
||
}
|
||
|
||
// 填充所属步骤下拉框并预选当前值
|
||
const stepSelect = document.getElementById("docStep");
|
||
const projectSteps = steps.filter(s => {
|
||
const rel = s["所属项目"];
|
||
return rel && rel.includes(currentProjectId);
|
||
});
|
||
const currentStepIdVal = (doc["所属步骤"] || [])[0] || '';
|
||
stepSelect.innerHTML = '<option value="">-- 不关联步骤 --</option>' +
|
||
projectSteps.map(s => `<option value="${s.id}">${s['步骤名称'] || '未命名'}</option>`).join('');
|
||
stepSelect.value = currentStepIdVal;
|
||
|
||
document.getElementById("modalCreateDoc").classList.add("show");
|
||
} catch (e) { showToast("加载资料失败", "error"); }
|
||
}
|
||
|
||
function closeModal(id) {
|
||
document.getElementById(id).classList.remove("show");
|
||
if (id === 'modalCreateRecord') {
|
||
treeAddContext = null;
|
||
currentEditId = null;
|
||
}
|
||
if (id === 'modalDelete') {
|
||
treeDeleteContext = null;
|
||
}
|
||
}
|
||
|
||
async function submitDoc() {
|
||
const title = document.getElementById("docTitle").value.trim();
|
||
const type = document.getElementById("docType").value;
|
||
const content = document.getElementById("docContent").value.trim();
|
||
const fileInput = document.getElementById("docFile");
|
||
const file = fileInput.files[0];
|
||
if (!title) { showToast("请输入资料标题", "error"); return; }
|
||
|
||
const formData = new FormData();
|
||
formData.append("title", title);
|
||
formData.append("doc_type", type);
|
||
formData.append("content", content);
|
||
formData.append("step_id", document.getElementById("docStep").value);
|
||
|
||
try {
|
||
let res;
|
||
let fileUploaded = false;
|
||
if (currentEditDocId) {
|
||
// 编辑模式:先更新字段,再上传附件(如有)
|
||
res = await fetch(`/api/docs/${currentEditDocId}`, { method: "PUT", body: formData });
|
||
const data = await res.json();
|
||
if (!res.ok) {
|
||
showToast(data.detail || "保存失败", "error");
|
||
return;
|
||
}
|
||
// 如果有新附件,上传附件
|
||
if (file) {
|
||
try {
|
||
const attachForm = new FormData();
|
||
attachForm.append("file", file);
|
||
const attachRes = await fetch(`/api/docs/${currentEditDocId}/upload`, { method: "POST", body: attachForm });
|
||
const attachData = await attachRes.json();
|
||
if (attachRes.ok) {
|
||
fileUploaded = true;
|
||
} else {
|
||
showToast("资料已保存,但附件上传失败:" + (attachData.detail || "未知错误"), "error");
|
||
}
|
||
} catch (e) {
|
||
showToast("资料已保存,但附件上传失败:网络错误", "error");
|
||
}
|
||
}
|
||
showToast("资料保存成功" + (fileUploaded ? ",附件已上传" : ""));
|
||
closeModal('modalCreateDoc');
|
||
currentEditDocId = null;
|
||
await loadDocs();
|
||
renderStepDetail();
|
||
} else {
|
||
// 新建模式
|
||
formData.append("project_id", currentProjectId);
|
||
if (file) formData.append("file", file);
|
||
res = await fetch("/api/docs", { method: "POST", body: formData });
|
||
const data = await res.json();
|
||
if (res.ok) {
|
||
showToast("资料创建成功" + (file ? ",附件已上传" : ""));
|
||
closeModal('modalCreateDoc');
|
||
currentEditDocId = null;
|
||
await loadDocs();
|
||
renderStepDetail();
|
||
} else {
|
||
showToast(data.detail || "创建失败", "error");
|
||
}
|
||
}
|
||
} catch (e) { showToast("网络错误", "error"); }
|
||
}
|
||
|
||
// ====== 查看资料详情 ======
|
||
async function viewDoc(docId) {
|
||
try {
|
||
const res = await fetch(`/api/docs/${docId}`);
|
||
if (checkTokenExpired(res)) return;
|
||
const data = await res.json();
|
||
const doc = data.doc;
|
||
if (!doc) { showToast("资料不存在", "error"); return; }
|
||
const title = doc["资料标题"] || "未命名";
|
||
const type = doc["资料类型"] || "";
|
||
const status = doc["资料状态"] || "";
|
||
const content = doc["正文内容"] || "(无正文内容)";
|
||
document.getElementById("detailTitle").textContent = title;
|
||
document.getElementById("detailContent").innerHTML = `
|
||
<div style="display:flex;gap:8px;margin-bottom:12px;flex-wrap:wrap">${getTypeBadge(type)} ${getDocStatusBadge(status)}${doc["流程状态"] ? getWorkflowBadge(doc["流程状态"], doc["作业类别"]) : ""}</div>
|
||
<div class="form-group"><label>正文内容</label><pre style="white-space:pre-wrap;font-family:inherit;font-size:14px;background:var(--surface);padding:12px;border-radius:var(--radius-md);">${content}</pre></div>
|
||
<div class="form-group"><label>附件</label>${renderAttachmentList(doc["附件"], docId, true)}</div>`;
|
||
document.getElementById("modalDetail").classList.add("show");
|
||
} catch (e) { showToast("加载详情失败", "error"); }
|
||
}
|
||
|
||
// ====== 大模型分析 ======
|
||
|
||
let pendingAnalyzeDocId = null;
|
||
let wikiSpaces = [];
|
||
|
||
async function analyzeDoc(docId) {
|
||
pendingAnalyzeDocId = docId;
|
||
// 清空上次的用户指导文本
|
||
const guidanceEl = document.getElementById('userGuidance');
|
||
if (guidanceEl) guidanceEl.value = '';
|
||
// 打开分析配置弹窗
|
||
document.getElementById('modalWikiSelect').classList.add('show');
|
||
await loadWikiSpaces();
|
||
}
|
||
|
||
async function loadWikiSpaces() {
|
||
const container = document.getElementById('wikiSpaceList');
|
||
container.innerHTML = '<p style="font-size:13px;color:var(--text-muted);">加载中...</p>';
|
||
try {
|
||
const res = await fetch('/api/wiki/spaces');
|
||
if (!res.ok) { container.innerHTML = '<p style="font-size:13px;color:var(--danger);">知识库加载失败</p>'; return; }
|
||
const data = await res.json();
|
||
wikiSpaces = data.spaces || [];
|
||
if (wikiSpaces.length === 0) {
|
||
container.innerHTML = '<p style="font-size:13px;color:var(--text-muted);">暂无可访问的知识空间</p>';
|
||
return;
|
||
}
|
||
container.innerHTML = wikiSpaces.map(s => `
|
||
<label style="display:flex;align-items:flex-start;gap:10px;padding:10px 14px;border:1px solid var(--border);border-radius:var(--radius-md);cursor:pointer;transition:all 0.2s;background:var(--surface-card);">
|
||
<input type="checkbox" value="${s.space_id}" style="margin-top:3px;flex-shrink:0;width:16px;height:16px;">
|
||
<div style="flex:1;">
|
||
<div style="font-size:14px;font-weight:600;color:var(--text);">${s.name}</div>
|
||
${s.description ? `<div style="font-size:12px;color:var(--text-muted);margin-top:2px;">${s.description}</div>` : ''}
|
||
</div>
|
||
</label>
|
||
`).join('');
|
||
} catch (e) {
|
||
container.innerHTML = '<p style="font-size:13px;color:var(--danger);">加载失败:网络错误</p>';
|
||
}
|
||
}
|
||
|
||
function getSelectedWikiSpaceIds() {
|
||
return Array.from(document.querySelectorAll('#wikiSpaceList input[type=checkbox]:checked'))
|
||
.map(cb => cb.value);
|
||
}
|
||
|
||
async function confirmWikiAnalyze() {
|
||
const selectedIds = getSelectedWikiSpaceIds();
|
||
await analyzeDocWithWiki(selectedIds);
|
||
}
|
||
|
||
async function confirmCombinedAnalyze() {
|
||
const selectedIds = getSelectedWikiSpaceIds();
|
||
if (selectedIds.length === 0) {
|
||
showToast('综合分析需要选择至少一个知识空间', 'error');
|
||
return;
|
||
}
|
||
await analyzeDocCombined(selectedIds);
|
||
}
|
||
|
||
async function analyzeDocCombined(spaceIds) {
|
||
closeModal('modalWikiSelect');
|
||
const docId = pendingAnalyzeDocId;
|
||
if (!docId) return;
|
||
|
||
const userGuidance = (document.getElementById('userGuidance') || {}).value || '';
|
||
showToast(`正在综合分析中...(直接分析 + 引用${spaceIds.length}个知识空间 + 整合结果,请稍候)`);
|
||
|
||
try {
|
||
const formData = new FormData();
|
||
formData.append('wiki_space_ids', spaceIds.join(','));
|
||
if (userGuidance) formData.append('user_guidance', userGuidance);
|
||
const res = await fetch(`/api/analyze-combined/${docId}`, { method: "POST", body: formData });
|
||
const data = await res.json();
|
||
if (res.ok) {
|
||
showToast("综合分析完成(已整合直接分析与知识库分析结果)");
|
||
await loadDocs(); await loadResults(); renderStepDetail();
|
||
} else { showToast(data.detail || "综合分析失败", "error"); }
|
||
} catch (e) { showToast("网络错误", "error"); }
|
||
}
|
||
|
||
async function analyzeDocWithWiki(spaceIds) {
|
||
closeModal('modalWikiSelect');
|
||
const docId = pendingAnalyzeDocId;
|
||
if (!docId) return;
|
||
|
||
const userGuidance = (document.getElementById('userGuidance') || {}).value || '';
|
||
const btnHint = spaceIds.length > 0 ? `(引用${spaceIds.length}个知识空间)` : '';
|
||
showToast(`正在分析中...${btnHint}`);
|
||
|
||
try {
|
||
const formData = new FormData();
|
||
if (spaceIds.length > 0) {
|
||
formData.append('wiki_space_ids', spaceIds.join(','));
|
||
}
|
||
if (userGuidance) formData.append('user_guidance', userGuidance);
|
||
const res = await fetch(`/api/analyze/${docId}`, { method: "POST", body: formData });
|
||
const data = await res.json();
|
||
if (res.ok) {
|
||
const msg = data.knowledge_used ? "分析完成(已引用知识库制度)" : "分析完成";
|
||
showToast(msg);
|
||
await loadDocs(); await loadResults(); renderStepDetail();
|
||
} else { showToast(data.detail || "分析失败", "error"); }
|
||
} catch (e) { showToast("网络错误", "error"); }
|
||
}
|
||
|
||
// ====== 删除审计资料 ======
|
||
async function deleteDoc(docId) {
|
||
const relatedEl = document.getElementById('relatedRecords');
|
||
const msgEl = document.getElementById('deleteMessage');
|
||
const confirmBtn = document.getElementById('confirmDelete');
|
||
|
||
relatedEl.innerHTML = '<p style="font-size:13px;color:var(--text-muted);">检查关联中...</p>';
|
||
msgEl.textContent = '';
|
||
confirmBtn.disabled = true;
|
||
confirmBtn.onclick = null;
|
||
document.getElementById('modalDelete').classList.add('show');
|
||
|
||
try {
|
||
const res = await fetch(`/api/docs/${docId}/related`);
|
||
if (checkTokenExpired(res)) return;
|
||
const data = await res.json();
|
||
|
||
if (data.related && data.related.length > 0) {
|
||
// 有关联分析结果:提示将同步删除
|
||
msgEl.textContent = '该审计资料存在关联记录,删除时将同步删除以下关联内容:';
|
||
let html = '<div style="font-size:13px;color:var(--warning);margin-bottom:8px;">⚠ 删除后将同步删除关联的分析结果,此操作不可恢复</div>';
|
||
html += '<ul style="font-size:12px;margin:0;padding-left:16px;max-height:150px;overflow-y:auto;">';
|
||
html += data.related.map(r => `<li style="margin-bottom:4px;"><strong>${r.table}</strong> — ${r.record || '未命名'}(${r.field})</li>`).join('');
|
||
html += '</ul>';
|
||
relatedEl.innerHTML = html;
|
||
confirmBtn.disabled = false;
|
||
confirmBtn.textContent = '确认删除';
|
||
confirmBtn.onclick = async () => {
|
||
confirmBtn.disabled = true;
|
||
try {
|
||
const delRes = await fetch(`/api/docs/${docId}`, { method: 'DELETE' });
|
||
if (checkTokenExpired(delRes)) return;
|
||
const delData = await delRes.json();
|
||
if (delRes.ok) {
|
||
showToast(delData.message || '删除成功');
|
||
closeModal('modalDelete');
|
||
await loadDocs();
|
||
await loadResults();
|
||
renderStepDetail();
|
||
} else {
|
||
const errMsg = delData.detail && delData.detail.message ? delData.detail.message : (delData.detail || '删除失败');
|
||
showToast(errMsg, 'error');
|
||
confirmBtn.disabled = false;
|
||
}
|
||
} catch (e) {
|
||
showToast('网络错误', 'error');
|
||
confirmBtn.disabled = false;
|
||
}
|
||
};
|
||
} else {
|
||
// 无关联:普通删除
|
||
msgEl.textContent = '确定要删除这条审计资料吗?此操作不可恢复。';
|
||
relatedEl.innerHTML = '';
|
||
confirmBtn.disabled = false;
|
||
confirmBtn.textContent = '删除';
|
||
confirmBtn.onclick = async () => {
|
||
confirmBtn.disabled = true;
|
||
try {
|
||
const delRes = await fetch(`/api/docs/${docId}`, { method: 'DELETE' });
|
||
if (checkTokenExpired(delRes)) return;
|
||
const delData = await delRes.json();
|
||
if (delRes.ok) {
|
||
showToast(delData.message || '删除成功');
|
||
closeModal('modalDelete');
|
||
await loadDocs();
|
||
renderStepDetail();
|
||
} else {
|
||
const errMsg = delData.detail && delData.detail.message ? delData.detail.message : (delData.detail || '删除失败');
|
||
showToast(errMsg, 'error');
|
||
confirmBtn.disabled = false;
|
||
}
|
||
} catch (e) {
|
||
showToast('网络错误', 'error');
|
||
confirmBtn.disabled = false;
|
||
}
|
||
};
|
||
}
|
||
} catch (e) {
|
||
showToast('检查关联失败', 'error');
|
||
closeModal('modalDelete');
|
||
}
|
||
}
|
||
|
||
// ====== 修改分析结果 ======
|
||
// ====== 删除分析结果 ======
|
||
async function deleteResult(resultId) {
|
||
if (!resultId) { showToast("结果ID缺失", "error"); return; }
|
||
if (!confirm("确认删除这条分析结果?\n\n· 审计资料不会被删除\n· 资料状态将回退为'待分析'\n· 此操作不可恢复")) return;
|
||
try {
|
||
const res = await fetch(`/api/results/${resultId}`, { method: "DELETE" });
|
||
if (checkTokenExpired(res)) return;
|
||
if (!res.ok) {
|
||
const err = await res.json().catch(() => ({}));
|
||
showToast("删除失败:" + (err.detail || res.status), "error"); return;
|
||
}
|
||
showToast("分析结果已删除");
|
||
await loadResults();
|
||
await loadDocs();
|
||
renderStepDetail();
|
||
} catch (e) { showToast("删除失败:" + e.message, "error"); }
|
||
}
|
||
|
||
// ====== 重新分析(直接覆盖旧结果) ======
|
||
async function reanalyzeResult(resultId) {
|
||
if (!resultId) { showToast("结果ID缺失", "error"); return; }
|
||
// 先从 results 列表里找到这条记录,拿到关联的资料ID
|
||
const r = results.find(x => x.id === resultId);
|
||
if (!r) { showToast("分析结果不存在", "error"); return; }
|
||
const docRefs = r["关联资料"] || [];
|
||
if (docRefs.length === 0) {
|
||
showToast("该分析结果未关联审计资料,无法重新分析", "error"); return;
|
||
}
|
||
const docId = docRefs[0];
|
||
// 反查资料名,给用户一个确认提示
|
||
const d = docs.find(x => x.id === docId);
|
||
const docName = d ? (d["资料标题"] || "未命名") : "未命名";
|
||
if (!confirm(`确认重新分析资料【${docName}】?\n\n· 将使用最新大模型与知识库重新生成\n· 旧分析结果会被新结果覆盖`)) return;
|
||
showToast("正在重新分析,请稍候...", "info");
|
||
try {
|
||
const res = await fetch(`/api/analyze/${docId}`, { method: "POST" });
|
||
if (checkTokenExpired(res)) return;
|
||
if (!res.ok) {
|
||
const err = await res.json().catch(() => ({}));
|
||
showToast("重新分析失败:" + (err.detail || res.status), "error"); return;
|
||
}
|
||
showToast("重新分析完成");
|
||
await loadResults();
|
||
await loadDocs();
|
||
renderStepDetail();
|
||
} catch (e) { showToast("重新分析失败:" + e.message, "error"); }
|
||
}
|
||
|
||
async function openEditResultModal(resultId) {
|
||
currentEditResultId = resultId;
|
||
try {
|
||
const res = await fetch(`/api/results/${resultId}`);
|
||
if (checkTokenExpired(res)) return;
|
||
const data = await res.json();
|
||
const r = data.result;
|
||
if (!r) { showToast("分析结果不存在", "error"); return; }
|
||
|
||
document.getElementById("resultType").value = r["分析类型"] || "";
|
||
document.getElementById("resultRisk").value = r["风险等级"] || "中";
|
||
document.getElementById("resultSummary").value = r["分析摘要"] || "";
|
||
document.getElementById("resultFindings").value = r["关键发现"] || "";
|
||
document.getElementById("resultSuggestions").value = r["改进建议"] || "";
|
||
document.getElementById("modalEditResult").classList.add("show");
|
||
} catch (e) { showToast("加载分析结果失败", "error"); }
|
||
}
|
||
|
||
async function submitResultEdit() {
|
||
if (!currentEditResultId) return;
|
||
const analysis_type = document.getElementById("resultType").value.trim();
|
||
const risk_level = document.getElementById("resultRisk").value;
|
||
const summary = document.getElementById("resultSummary").value.trim();
|
||
const findings = document.getElementById("resultFindings").value.trim();
|
||
const suggestions = document.getElementById("resultSuggestions").value.trim();
|
||
|
||
const formData = new FormData();
|
||
formData.append("analysis_type", analysis_type);
|
||
formData.append("risk_level", risk_level);
|
||
formData.append("summary", summary);
|
||
formData.append("findings", findings);
|
||
formData.append("suggestions", suggestions);
|
||
|
||
try {
|
||
const res = await fetch(`/api/results/${currentEditResultId}`, { method: "PUT", body: formData });
|
||
if (checkTokenExpired(res)) return;
|
||
const data = await res.json();
|
||
if (res.ok) {
|
||
showToast("分析结果保存成功");
|
||
closeModal('modalEditResult');
|
||
currentEditResultId = null;
|
||
await loadResults();
|
||
renderStepDetail();
|
||
} else {
|
||
showToast(data.detail || "保存失败", "error");
|
||
}
|
||
} catch (e) { showToast("网络错误", "error"); }
|
||
}
|
||
|
||
// ====== 数据录入模块 ======
|
||
|
||
async function loadDataTable(key) {
|
||
const table = DATA_TABLES.find(t => t.key === key);
|
||
try {
|
||
const res = await fetch(table.api);
|
||
if (checkTokenExpired(res)) return;
|
||
const data = await res.json();
|
||
if (key === 'person') persons = data.persons || [];
|
||
if (key === 'category') categories = data.categories || [];
|
||
if (key === 'year') years = data.years || [];
|
||
if (key === 'project') projects = data.projects || [];
|
||
if (key === 'step') steps = data.steps || [];
|
||
} catch (e) { showToast(`加载${table.label}失败`, "error"); }
|
||
}
|
||
|
||
function renderDataView() {
|
||
const main = document.getElementById('mainContent');
|
||
const table = DATA_TABLES.find(t => t.key === currentDataTable);
|
||
main.innerHTML = `
|
||
<div class="section-header">
|
||
<h2>${table.label}</h2>
|
||
<button class="btn btn-primary" onclick="openCreateRecord()">+ 新建</button>
|
||
</div>
|
||
<div class="card">
|
||
<div id="dataTableContainer">加载中...</div>
|
||
</div>
|
||
`;
|
||
loadAndRenderTable(currentDataTable);
|
||
}
|
||
|
||
async function loadAndRenderTable(key) {
|
||
await loadDataTable(key);
|
||
const container = document.getElementById('dataTableContainer');
|
||
if (key === 'person') container.innerHTML = renderPersonTable();
|
||
if (key === 'category') container.innerHTML = renderCategoryTable();
|
||
if (key === 'year') container.innerHTML = renderYearTable();
|
||
if (key === 'project') container.innerHTML = renderProjectTable();
|
||
if (key === 'step') container.innerHTML = renderStepTable();
|
||
}
|
||
|
||
function renderPersonTable() {
|
||
if (!persons.length) return '<div class="empty-state"><p>暂无人员记录</p></div>';
|
||
return `<table class="data-table">
|
||
<thead><tr><th>姓名</th><th>部门</th><th>角色</th><th>联系方式</th><th style="width:120px;">操作</th></tr></thead>
|
||
<tbody>${persons.map(p => `<tr>
|
||
<td>${p['姓名'] || ''}</td>
|
||
<td>${p['部门'] || ''}</td>
|
||
<td>${p['角色'] || ''}</td>
|
||
<td class="cell-muted">${p['联系方式'] || '-'}</td>
|
||
<td>
|
||
<button class="btn" style="padding:4px 8px;font-size:12px;margin-right:4px;" onclick="openEditRecord('${p.id}')">修改</button>
|
||
<button class="btn btn-danger" style="padding:4px 8px;font-size:12px;" onclick="deleteRecord('${p.id}')">删除</button>
|
||
</td>
|
||
</tr>`).join('')}</tbody>
|
||
</table>`;
|
||
}
|
||
|
||
function renderCategoryTable() {
|
||
if (!categories.length) return '<div class="empty-state"><p>暂无项目大类记录</p></div>';
|
||
return `<table class="data-table">
|
||
<thead><tr><th>大类名称</th><th>大类状态</th><th>大类描述</th><th style="width:120px;">操作</th></tr></thead>
|
||
<tbody>${categories.map(c => `<tr>
|
||
<td>${c['大类名称'] || ''}</td>
|
||
<td>${getStatusBadge(c['大类状态'])}</td>
|
||
<td class="cell-muted">${c['大类描述'] || '-'}</td>
|
||
<td>
|
||
<button class="btn" style="padding:4px 8px;font-size:12px;margin-right:4px;" onclick="openEditRecord('${c.id}')">修改</button>
|
||
<button class="btn btn-danger" style="padding:4px 8px;font-size:12px;" onclick="deleteRecord('${c.id}')">删除</button>
|
||
</td>
|
||
</tr>`).join('')}</tbody>
|
||
</table>`;
|
||
}
|
||
|
||
function renderYearTable() {
|
||
if (!years.length) return '<div class="empty-state"><p>暂无年度记录</p></div>';
|
||
return `<table class="data-table">
|
||
<thead><tr><th>年度</th><th>年度名称</th><th>年度状态</th><th>年度预算</th><th>年度目标</th><th style="width:120px;">操作</th></tr></thead>
|
||
<tbody>${years.map(y => `<tr>
|
||
<td>${y['年度'] || ''}</td>
|
||
<td>${y['年度名称'] || ''}</td>
|
||
<td>${getStatusBadge(y['年度状态'])}</td>
|
||
<td>${y['年度预算'] !== undefined && y['年度预算'] !== null ? '¥' + y['年度预算'] : '-'}</td>
|
||
<td class="cell-muted">${(y['年度目标'] || '').substring(0, 30)}${(y['年度目标'] || '').length > 30 ? '...' : ''}</td>
|
||
<td>
|
||
<button class="btn" style="padding:4px 8px;font-size:12px;margin-right:4px;" onclick="openEditRecord('${y.id}')">修改</button>
|
||
<button class="btn btn-danger" style="padding:4px 8px;font-size:12px;" onclick="deleteRecord('${y.id}')">删除</button>
|
||
</td>
|
||
</tr>`).join('')}</tbody>
|
||
</table>`;
|
||
}
|
||
|
||
function renderProjectTable() {
|
||
if (!projects.length) return '<div class="empty-state"><p>暂无项目记录</p></div>';
|
||
return `<table class="data-table">
|
||
<thead><tr><th>项目名称</th><th>项目状态</th><th>优先级</th><th>开始日期</th><th>结束日期</th><th style="width:120px;">操作</th></tr></thead>
|
||
<tbody>${projects.map(p => `<tr>
|
||
<td>${p['项目名称'] || ''}</td>
|
||
<td>${getStatusBadge(p['项目状态'])}</td>
|
||
<td><span class="badge badge-gray">${p['优先级'] || ''}</span></td>
|
||
<td class="cell-muted">${p['开始日期'] || '-'}</td>
|
||
<td class="cell-muted">${p['结束日期'] || '-'}</td>
|
||
<td>
|
||
<button class="btn" style="padding:4px 8px;font-size:12px;margin-right:4px;" onclick="openEditRecord('${p.id}')">修改</button>
|
||
<button class="btn btn-danger" style="padding:4px 8px;font-size:12px;" onclick="deleteRecord('${p.id}')">删除</button>
|
||
</td>
|
||
</tr>`).join('')}</tbody>
|
||
</table>`;
|
||
}
|
||
|
||
function renderStepTable() {
|
||
if (!steps.length) return '<div class="empty-state"><p>暂无项目步骤记录</p></div>';
|
||
return `<table class="data-table">
|
||
<thead><tr><th>步骤名称</th><th>步骤状态</th><th>优先级</th><th>进度</th><th>交付物</th><th style="width:120px;">操作</th></tr></thead>
|
||
<tbody>${steps.map(s => `<tr>
|
||
<td>${s['步骤名称'] || ''}</td>
|
||
<td>${getStatusBadge(s['步骤状态'])}</td>
|
||
<td><span class="badge badge-gray">${s['优先级'] || ''}</span></td>
|
||
<td>${s['进度'] !== undefined && s['进度'] !== null ? s['进度'] + '%' : '-'}</td>
|
||
<td class="cell-muted">${s['交付物'] || '-'}</td>
|
||
<td>
|
||
<button class="btn" style="padding:4px 8px;font-size:12px;margin-right:4px;" onclick="openEditRecord('${s.id}')">修改</button>
|
||
<button class="btn btn-danger" style="padding:4px 8px;font-size:12px;" onclick="deleteRecord('${s.id}')">删除</button>
|
||
</td>
|
||
</tr>`).join('')}</tbody>
|
||
</table>`;
|
||
}
|
||
|
||
// ====== 删除记录 ======
|
||
let deleteTargetId = null;
|
||
|
||
async function deleteRecord(id) {
|
||
deleteTargetId = id;
|
||
const table = DATA_TABLES.find(t => t.key === currentDataTable);
|
||
const relatedEl = document.getElementById('relatedRecords');
|
||
const msgEl = document.getElementById('deleteMessage');
|
||
const confirmBtn = document.getElementById('confirmDelete');
|
||
|
||
relatedEl.innerHTML = '<p style="font-size:13px;color:var(--text-muted);">检查关联中...</p>';
|
||
msgEl.textContent = '';
|
||
confirmBtn.disabled = true;
|
||
confirmBtn.onclick = null;
|
||
document.getElementById('modalDelete').classList.add('show');
|
||
|
||
try {
|
||
const res = await fetch(`${table.api}/${id}/related`);
|
||
if (checkTokenExpired(res)) return;
|
||
const data = await res.json();
|
||
|
||
if (data.related && data.related.length > 0) {
|
||
msgEl.textContent = '无法删除,该记录存在以下关联记录:';
|
||
let html = '<div style="font-size:13px;color:var(--danger);margin-bottom:8px;">存在关联记录,请先解除关联后再删除</div>';
|
||
html += '<ul style="font-size:12px;margin:0;padding-left:16px;max-height:150px;overflow-y:auto;">';
|
||
html += data.related.map(r => `<li style="margin-bottom:4px;"><strong>${r.table}</strong> — ${r.record || '未命名'}(${r.field})</li>`).join('');
|
||
html += '</ul>';
|
||
relatedEl.innerHTML = html;
|
||
confirmBtn.disabled = true;
|
||
} else {
|
||
msgEl.textContent = '确定要删除这条记录吗?此操作不可恢复。';
|
||
relatedEl.innerHTML = '';
|
||
confirmBtn.disabled = false;
|
||
confirmBtn.onclick = async () => {
|
||
confirmBtn.disabled = true;
|
||
try {
|
||
const delRes = await fetch(`${table.api}/${id}`, { method: 'DELETE' });
|
||
if (checkTokenExpired(delRes)) return;
|
||
const delData = await delRes.json();
|
||
if (delRes.ok) {
|
||
showToast('删除成功');
|
||
closeModal('modalDelete');
|
||
// 清空缓存数据,强制重新加载
|
||
if (currentDataTable === 'person') persons = [];
|
||
if (currentDataTable === 'category') categories = [];
|
||
if (currentDataTable === 'year') years = [];
|
||
if (currentDataTable === 'project') projects = [];
|
||
if (currentDataTable === 'step') steps = [];
|
||
// 重新渲染整个视图
|
||
renderDataView();
|
||
if (currentDataTable === 'project') await loadProjects();
|
||
} else {
|
||
const errMsg = delData.detail && delData.detail.message ? delData.detail.message : (delData.detail || '删除失败');
|
||
showToast(errMsg, 'error');
|
||
confirmBtn.disabled = false;
|
||
}
|
||
} catch (e) {
|
||
showToast('网络错误', 'error');
|
||
confirmBtn.disabled = false;
|
||
}
|
||
};
|
||
}
|
||
} catch (e) {
|
||
relatedEl.innerHTML = '<p style="font-size:13px;color:var(--danger);">检查关联失败</p>';
|
||
msgEl.textContent = '';
|
||
confirmBtn.disabled = true;
|
||
}
|
||
}
|
||
|
||
// ====== 通用新建记录弹窗 ======
|
||
|
||
const RECORD_FORMS = {
|
||
person: {
|
||
title: '新建人员',
|
||
editTitle: '修改人员',
|
||
fields: [
|
||
{ name: 'name', label: '姓名', type: 'text', required: true, mapTo: '姓名' },
|
||
{ name: 'dept', label: '部门', type: 'select', options: ['审计科'], required: true, mapTo: '部门' },
|
||
{ name: 'role', label: '角色', type: 'select', options: ['科长', '科员'], required: true, mapTo: '角色' },
|
||
{ name: 'contact', label: '联系方式', type: 'text', mapTo: '联系方式' }
|
||
],
|
||
submit: async (vals) => {
|
||
const form = new FormData();
|
||
form.append('name', vals.name);
|
||
form.append('dept', vals.dept);
|
||
form.append('role', vals.role);
|
||
form.append('contact', vals.contact || '');
|
||
const res = await fetch('/api/persons', { method: 'POST', body: form });
|
||
return res;
|
||
},
|
||
editSubmit: async (id, vals) => {
|
||
const form = new FormData();
|
||
form.append('name', vals.name);
|
||
form.append('dept', vals.dept);
|
||
form.append('role', vals.role);
|
||
form.append('contact', vals.contact || '');
|
||
const res = await fetch(`/api/persons/${id}`, { method: 'PUT', body: form });
|
||
return res;
|
||
}
|
||
},
|
||
category: {
|
||
title: '新建项目大类',
|
||
editTitle: '修改项目大类',
|
||
fields: [
|
||
{ name: 'name', label: '大类名称', type: 'text', required: true, mapTo: '大类名称' },
|
||
{ name: 'description', label: '大类描述', type: 'textarea', mapTo: '大类描述' },
|
||
{ name: 'status', label: '大类状态', type: 'select', options: ['未开始', '进行中', '已完成', '已归档'], mapTo: '大类状态' },
|
||
{ name: 'leader_id', label: '大类负责人', type: 'select_ref', ref: 'person', refLabel: '姓名', mapTo: '大类负责人' }
|
||
],
|
||
submit: async (vals) => {
|
||
const form = new FormData();
|
||
form.append('name', vals.name);
|
||
form.append('description', vals.description || '');
|
||
form.append('status', vals.status || '未开始');
|
||
form.append('leader_id', vals.leader_id || '');
|
||
const res = await fetch('/api/categories', { method: 'POST', body: form });
|
||
return res;
|
||
},
|
||
editSubmit: async (id, vals) => {
|
||
const form = new FormData();
|
||
form.append('name', vals.name);
|
||
form.append('description', vals.description || '');
|
||
form.append('status', vals.status || '未开始');
|
||
form.append('leader_id', vals.leader_id || '');
|
||
const res = await fetch(`/api/categories/${id}`, { method: 'PUT', body: form });
|
||
return res;
|
||
}
|
||
},
|
||
year: {
|
||
title: '新建年度',
|
||
editTitle: '修改年度',
|
||
fields: [
|
||
{ name: 'year', label: '年度', type: 'text', required: true, placeholder: '如 2026', mapTo: '年度' },
|
||
{ name: 'name', label: '年度名称', type: 'text', required: true, mapTo: '年度名称' },
|
||
{ name: 'goal', label: '年度目标', type: 'textarea', mapTo: '年度目标' },
|
||
{ name: 'budget', label: '年度预算', type: 'number', mapTo: '年度预算' },
|
||
{ name: 'status', label: '年度状态', type: 'select', options: ['未开始', '进行中', '已完成', '已归档'], mapTo: '年度状态' },
|
||
{ name: 'category_id', label: '所属大类', type: 'select_ref', ref: 'category', refLabel: '大类名称', mapTo: '所属大类' },
|
||
{ name: 'leader_id', label: '年度负责人', type: 'select_ref', ref: 'person', refLabel: '姓名', mapTo: '年度负责人' }
|
||
],
|
||
submit: async (vals) => {
|
||
const form = new FormData();
|
||
form.append('year', vals.year);
|
||
form.append('name', vals.name);
|
||
form.append('goal', vals.goal || '');
|
||
form.append('budget', vals.budget || '0');
|
||
form.append('status', vals.status || '未开始');
|
||
form.append('category_id', vals.category_id || '');
|
||
form.append('leader_id', vals.leader_id || '');
|
||
const res = await fetch('/api/years', { method: 'POST', body: form });
|
||
return res;
|
||
},
|
||
editSubmit: async (id, vals) => {
|
||
const form = new FormData();
|
||
form.append('year', vals.year);
|
||
form.append('name', vals.name);
|
||
form.append('goal', vals.goal || '');
|
||
form.append('budget', vals.budget || '0');
|
||
form.append('status', vals.status || '未开始');
|
||
form.append('category_id', vals.category_id || '');
|
||
form.append('leader_id', vals.leader_id || '');
|
||
const res = await fetch(`/api/years/${id}`, { method: 'PUT', body: form });
|
||
return res;
|
||
}
|
||
},
|
||
project: {
|
||
title: '新建项目',
|
||
editTitle: '修改项目',
|
||
fields: [
|
||
{ name: 'name', label: '项目名称', type: 'text', required: true, mapTo: '项目名称' },
|
||
{ name: 'description', label: '项目描述', type: 'textarea', mapTo: '项目描述' },
|
||
{ name: 'status', label: '项目状态', type: 'select', options: ['未开始', '进行中', '已完成', '暂停', '已取消'], mapTo: '项目状态' },
|
||
{ name: 'priority', label: '优先级', type: 'select', options: ['P0', 'P1', 'P2', 'P3'], mapTo: '优先级' },
|
||
{ name: 'start_date', label: '开始日期', type: 'date', mapTo: '开始日期' },
|
||
{ name: 'end_date', label: '结束日期', type: 'date', mapTo: '结束日期' },
|
||
{ name: 'budget', label: '项目预算', type: 'number', mapTo: '项目预算' },
|
||
{ name: 'risks', label: '风险与问题', type: 'textarea', mapTo: '风险与问题' },
|
||
{ name: 'leader_id', label: '项目负责人', type: 'select_ref', ref: 'person', refLabel: '姓名', mapTo: '项目负责人' },
|
||
{ name: 'year_id', label: '所属年度', type: 'select_ref', ref: 'year', refLabel: '年度名称', mapTo: '所属年度' },
|
||
{ name: 'category_id', label: '所属大类', type: 'select_ref', ref: 'category', refLabel: '大类名称', mapTo: '所属大类' }
|
||
],
|
||
submit: async (vals) => {
|
||
const form = new FormData();
|
||
form.append('name', vals.name);
|
||
form.append('description', vals.description || '');
|
||
form.append('status', vals.status || '未开始');
|
||
form.append('priority', vals.priority || 'P2');
|
||
form.append('start_date', vals.start_date || '');
|
||
form.append('end_date', vals.end_date || '');
|
||
form.append('budget', vals.budget || '0');
|
||
form.append('risks', vals.risks || '');
|
||
form.append('leader_id', vals.leader_id || '');
|
||
form.append('year_id', vals.year_id || '');
|
||
form.append('category_id', vals.category_id || '');
|
||
const res = await fetch('/api/projects', { method: 'POST', body: form });
|
||
return res;
|
||
},
|
||
editSubmit: async (id, vals) => {
|
||
const form = new FormData();
|
||
form.append('name', vals.name);
|
||
form.append('description', vals.description || '');
|
||
form.append('status', vals.status || '未开始');
|
||
form.append('priority', vals.priority || 'P2');
|
||
form.append('start_date', vals.start_date || '');
|
||
form.append('end_date', vals.end_date || '');
|
||
form.append('budget', vals.budget || '0');
|
||
form.append('risks', vals.risks || '');
|
||
form.append('leader_id', vals.leader_id || '');
|
||
form.append('year_id', vals.year_id || '');
|
||
form.append('category_id', vals.category_id || '');
|
||
const res = await fetch(`/api/projects/${id}`, { method: 'PUT', body: form });
|
||
return res;
|
||
}
|
||
},
|
||
step: {
|
||
title: '新建项目步骤',
|
||
editTitle: '修改项目步骤',
|
||
fields: [
|
||
{ name: 'name', label: '步骤名称', type: 'text', required: true, mapTo: '步骤名称' },
|
||
{ name: 'status', label: '步骤状态', type: 'select', options: ['待开始', '进行中', '已完成', '阻塞', '已取消'], mapTo: '步骤状态' },
|
||
{ name: 'priority', label: '优先级', type: 'select', options: ['P0', 'P1', 'P2', 'P3'], mapTo: '优先级' },
|
||
{ name: 'start_date', label: '开始日期', type: 'date', mapTo: '开始日期' },
|
||
{ name: 'end_date', label: '结束日期', type: 'date', mapTo: '结束日期' },
|
||
{ name: 'progress', label: '进度 (%)', type: 'number', placeholder: '0-100', mapTo: '进度' },
|
||
{ name: 'deliverable', label: '交付物', type: 'text', mapTo: '交付物' },
|
||
{ name: 'remark', label: '备注', type: 'textarea', mapTo: '备注' },
|
||
{ name: 'leader_id', label: '步骤负责人', type: 'select_ref', ref: 'person', refLabel: '姓名', mapTo: '步骤负责人' },
|
||
{ name: 'project_id', label: '所属项目', type: 'select_ref', ref: 'project', refLabel: '项目名称', mapTo: '所属项目' },
|
||
{ name: 'prev_step_id', label: '前置依赖', type: 'select_ref', ref: 'step', refLabel: '步骤名称', mapTo: '前置依赖' }
|
||
],
|
||
submit: async (vals) => {
|
||
const form = new FormData();
|
||
form.append('name', vals.name);
|
||
form.append('status', vals.status || '待开始');
|
||
form.append('priority', vals.priority || 'P2');
|
||
form.append('start_date', vals.start_date || '');
|
||
form.append('end_date', vals.end_date || '');
|
||
form.append('progress', vals.progress || '0');
|
||
form.append('deliverable', vals.deliverable || '');
|
||
form.append('remark', vals.remark || '');
|
||
form.append('leader_id', vals.leader_id || '');
|
||
form.append('project_id', vals.project_id || '');
|
||
form.append('prev_step_id', vals.prev_step_id || '');
|
||
const res = await fetch('/api/steps', { method: 'POST', body: form });
|
||
return res;
|
||
},
|
||
editSubmit: async (id, vals) => {
|
||
const form = new FormData();
|
||
form.append('name', vals.name);
|
||
form.append('status', vals.status || '待开始');
|
||
form.append('priority', vals.priority || 'P2');
|
||
form.append('start_date', vals.start_date || '');
|
||
form.append('end_date', vals.end_date || '');
|
||
form.append('progress', vals.progress || '0');
|
||
form.append('deliverable', vals.deliverable || '');
|
||
form.append('remark', vals.remark || '');
|
||
form.append('leader_id', vals.leader_id || '');
|
||
form.append('project_id', vals.project_id || '');
|
||
form.append('prev_step_id', vals.prev_step_id || '');
|
||
const res = await fetch(`/api/steps/${id}`, { method: 'PUT', body: form });
|
||
return res;
|
||
}
|
||
}
|
||
};
|
||
|
||
async function openCreateRecord() {
|
||
currentEditId = null;
|
||
await _buildRecordForm();
|
||
}
|
||
|
||
async function openEditRecord(id) {
|
||
currentEditId = id;
|
||
await _buildRecordForm(id);
|
||
}
|
||
|
||
async function _buildRecordForm(editId) {
|
||
const formDef = RECORD_FORMS[currentDataTable];
|
||
const isEdit = !!editId;
|
||
document.getElementById('recordModalTitle').textContent = isEdit ? formDef.editTitle : formDef.title;
|
||
document.getElementById('recordModalSubmit').textContent = isEdit ? '保存' : '创建';
|
||
|
||
// 获取当前记录数据(编辑时)
|
||
let record = null;
|
||
if (isEdit) {
|
||
const table = DATA_TABLES.find(t => t.key === currentDataTable);
|
||
const dataArr = { person: persons, category: categories, year: years, project: projects, step: steps }[currentDataTable];
|
||
record = dataArr.find(r => r.id === editId);
|
||
}
|
||
|
||
// 为 link 字段准备选项数据
|
||
const needPersons = formDef.fields.some(f => f.ref === 'person');
|
||
const needCategories = formDef.fields.some(f => f.ref === 'category');
|
||
const needYears = formDef.fields.some(f => f.ref === 'year');
|
||
const needProjects = formDef.fields.some(f => f.ref === 'project');
|
||
const needSteps = formDef.fields.some(f => f.ref === 'step');
|
||
|
||
const loads = [];
|
||
if (needPersons && !persons.length) loads.push(loadDataTable('person'));
|
||
if (needCategories && !categories.length) loads.push(loadDataTable('category'));
|
||
if (needYears && !years.length) loads.push(loadDataTable('year'));
|
||
if (needProjects && !projects.length) loads.push(loadDataTable('project'));
|
||
if (needSteps && !steps.length) loads.push(loadDataTable('step'));
|
||
if (loads.length) await Promise.all(loads);
|
||
|
||
const html = formDef.fields.map(f => {
|
||
// 获取当前值(编辑模式)
|
||
let currentVal = '';
|
||
if (isEdit && record && f.mapTo) {
|
||
const raw = record[f.mapTo];
|
||
if (raw !== undefined && raw !== null) {
|
||
if (Array.isArray(raw)) {
|
||
// 关联字段返回的是 ID 数组
|
||
currentVal = raw[0] || '';
|
||
} else {
|
||
currentVal = raw;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (f.type === 'select') {
|
||
const opts = f.options.map(o => `<option value="${o}" ${o === currentVal ? 'selected' : ''}>${o}</option>`).join('');
|
||
return `<div class="form-group"><label>${f.label}${f.required ? ' *' : ''}</label><select id="f_${f.name}">${opts}</select></div>`;
|
||
}
|
||
if (f.type === 'select_ref') {
|
||
let options = [];
|
||
if (f.ref === 'person') options = persons;
|
||
if (f.ref === 'category') options = categories;
|
||
if (f.ref === 'year') options = years;
|
||
if (f.ref === 'project') options = projects;
|
||
if (f.ref === 'step') options = steps;
|
||
const opts = options.map(o => `<option value="${o.id}" ${o.id === currentVal ? 'selected' : ''}>${o[f.refLabel] || o['姓名'] || o['大类名称'] || o['年度名称'] || o['项目名称'] || o['步骤名称'] || o.id}</option>`).join('');
|
||
return `<div class="form-group"><label>${f.label}</label><select id="f_${f.name}"><option value="">-- 请选择 --</option>${opts}</select></div>`;
|
||
}
|
||
if (f.type === 'textarea') {
|
||
return `<div class="form-group"><label>${f.label}${f.required ? ' *' : ''}</label><textarea id="f_${f.name}" placeholder="${f.placeholder || ''}">${currentVal}</textarea></div>`;
|
||
}
|
||
const inputType = f.type === 'number' ? 'number' : f.type === 'date' ? 'date' : 'text';
|
||
// 日期值格式化:去掉时间部分
|
||
let val = currentVal;
|
||
if (inputType === 'date' && val && val.includes(' ')) {
|
||
val = val.split(' ')[0];
|
||
}
|
||
return `<div class="form-group"><label>${f.label}${f.required ? ' *' : ''}</label><input type="${inputType}" id="f_${f.name}" placeholder="${f.placeholder || ''}" value="${val}"></div>`;
|
||
}).join('');
|
||
|
||
document.getElementById('recordModalBody').innerHTML = html;
|
||
document.getElementById('modalCreateRecord').classList.add('show');
|
||
}
|
||
|
||
async function submitRecord() {
|
||
if (treeAddContext) {
|
||
await submitTreeRecord();
|
||
return;
|
||
}
|
||
const formDef = RECORD_FORMS[currentDataTable];
|
||
const vals = {};
|
||
for (const f of formDef.fields) {
|
||
const el = document.getElementById(`f_${f.name}`);
|
||
vals[f.name] = el ? el.value.trim() : '';
|
||
if (f.required && !vals[f.name]) {
|
||
showToast(`${f.label} 不能为空`, "error");
|
||
return;
|
||
}
|
||
}
|
||
|
||
try {
|
||
let res;
|
||
if (currentEditId) {
|
||
res = await formDef.editSubmit(currentEditId, vals);
|
||
} else {
|
||
res = await formDef.submit(vals);
|
||
}
|
||
const data = await res.json();
|
||
if (res.ok) {
|
||
showToast(currentEditId ? '保存成功' : `${formDef.title}成功`);
|
||
closeModal('modalCreateRecord');
|
||
currentEditId = null;
|
||
renderDataView();
|
||
if (currentDataTable === 'project') await loadProjects();
|
||
} else {
|
||
showToast(data.detail || (currentEditId ? '保存失败' : '创建失败'), "error");
|
||
}
|
||
} catch (e) { showToast("网络错误", "error"); }
|
||
}
|
||
|
||
// ====== 备份功能 ======
|
||
|
||
async function openBackupModal() {
|
||
document.getElementById('modalBackup').classList.add('show');
|
||
await loadBackups();
|
||
}
|
||
|
||
async function loadBackups() {
|
||
try {
|
||
const res = await fetch('/api/backups');
|
||
if (checkTokenExpired(res)) return;
|
||
const data = await res.json();
|
||
const el = document.getElementById('backupList');
|
||
if (!data.backups || data.backups.length === 0) {
|
||
el.innerHTML = '<p style="color:var(--text-muted);font-size:13px;">暂无备份记录</p>';
|
||
return;
|
||
}
|
||
el.innerHTML = data.backups.map(b => `
|
||
<div class="doc-item" style="margin-bottom:6px;">
|
||
<div class="info">
|
||
<div class="title" style="font-size:13px;">${b.name}</div>
|
||
<div class="meta">${b.time} · ${b.file_count} 个文件</div>
|
||
</div>
|
||
</div>
|
||
`).join('');
|
||
} catch (e) {
|
||
showToast('加载备份列表失败', 'error');
|
||
}
|
||
}
|
||
|
||
async function doBackup() {
|
||
const btn = document.getElementById('backupBtn');
|
||
const originalText = btn.textContent;
|
||
btn.disabled = true;
|
||
btn.innerHTML = '<span class="loading"></span> 备份中...';
|
||
|
||
try {
|
||
const res = await fetch('/api/backup', { method: 'POST' });
|
||
const data = await res.json();
|
||
if (res.ok) {
|
||
showToast(`备份成功:${data.file_count} 个文件`);
|
||
await loadBackups();
|
||
} else {
|
||
showToast(data.detail || '备份失败', 'error');
|
||
}
|
||
} catch (e) {
|
||
showToast('网络错误', 'error');
|
||
} finally {
|
||
btn.disabled = false;
|
||
btn.textContent = originalText;
|
||
}
|
||
}
|
||
|
||
// ====== 审计实施方案生成 ======
|
||
|
||
let currentPlanId = null;
|
||
let planWikiSpaces = [];
|
||
|
||
async function openAuditPlanModal() {
|
||
// 重置状态
|
||
resetPlanModal();
|
||
document.getElementById('modalAuditPlan').classList.add('show');
|
||
await loadPlanWikiSpaces();
|
||
}
|
||
|
||
function resetPlanModal() {
|
||
document.getElementById('planInputArea').style.display = '';
|
||
document.getElementById('planResultArea').style.display = 'none';
|
||
document.getElementById('planDesc').value = '';
|
||
currentPlanId = null;
|
||
}
|
||
|
||
async function loadPlanWikiSpaces() {
|
||
const container = document.getElementById('planWikiList');
|
||
container.innerHTML = '<p style="font-size:13px;color:var(--text-muted);">加载中...</p>';
|
||
try {
|
||
const res = await fetch('/api/wiki/spaces');
|
||
if (!res.ok) { container.innerHTML = '<p style="font-size:13px;color:var(--danger);">知识库加载失败</p>'; return; }
|
||
const data = await res.json();
|
||
planWikiSpaces = data.spaces || [];
|
||
if (planWikiSpaces.length === 0) {
|
||
container.innerHTML = '<p style="font-size:13px;color:var(--text-muted);">暂无可访问的知识空间</p>';
|
||
return;
|
||
}
|
||
container.innerHTML = planWikiSpaces.map(s => `
|
||
<label style="display:flex;align-items:flex-start;gap:8px;padding:8px 12px;border:1px solid var(--border);border-radius:var(--radius-md);cursor:pointer;transition:all 0.2s;background:var(--surface-card);">
|
||
<input type="checkbox" value="${s.space_id}" style="margin-top:3px;flex-shrink:0;width:15px;height:15px;">
|
||
<div style="flex:1;">
|
||
<div style="font-size:13px;font-weight:600;color:var(--text);">${s.name}</div>
|
||
${s.description ? `<div style="font-size:11px;color:var(--text-muted);margin-top:1px;">${s.description}</div>` : ''}
|
||
</div>
|
||
</label>
|
||
`).join('');
|
||
} catch (e) {
|
||
container.innerHTML = '<p style="font-size:13px;color:var(--danger);">加载失败</p>';
|
||
}
|
||
}
|
||
|
||
async function generateAuditPlan() {
|
||
const desc = document.getElementById('planDesc').value.trim();
|
||
if (!desc) { showToast('请输入审计项目描述', 'error'); return; }
|
||
|
||
const selectedIds = Array.from(document.querySelectorAll('#planWikiList input[type=checkbox]:checked')).map(cb => cb.value);
|
||
const btn = document.getElementById('generatePlanBtn');
|
||
const originalText = btn.textContent;
|
||
btn.disabled = true;
|
||
btn.innerHTML = '<span class="loading"></span> 正在生成方案...';
|
||
|
||
const hints = [];
|
||
if (selectedIds.length > 0) hints.push(`引用${selectedIds.length}个知识空间`);
|
||
hints.push('搜索网络补充材料');
|
||
showToast(`正在生成审计实施方案(${hints.join(' + ')}),请稍候...`);
|
||
|
||
try {
|
||
const formData = new FormData();
|
||
formData.append('project_desc', desc);
|
||
if (selectedIds.length > 0) {
|
||
formData.append('wiki_space_ids', selectedIds.join(','));
|
||
}
|
||
const res = await fetch('/api/audit-plan/generate', { method: 'POST', body: formData });
|
||
const data = await res.json();
|
||
if (res.ok) {
|
||
currentPlanId = data.plan_id;
|
||
showPlanResult(data);
|
||
showToast('审计实施方案生成完成');
|
||
} else {
|
||
showToast(data.detail || '方案生成失败', 'error');
|
||
}
|
||
} catch (e) {
|
||
showToast('网络错误', 'error');
|
||
} finally {
|
||
btn.disabled = false;
|
||
btn.textContent = originalText;
|
||
}
|
||
}
|
||
|
||
function showPlanResult(data) {
|
||
document.getElementById('planInputArea').style.display = 'none';
|
||
document.getElementById('planResultArea').style.display = '';
|
||
|
||
// 元信息
|
||
const metaParts = [];
|
||
metaParts.push(`<strong style="font-size:15px;">${data.title}</strong>`);
|
||
const tags = [];
|
||
if (data.knowledge_used) tags.push('<span class="badge badge-blue">已引用知识库</span>');
|
||
if (data.web_used) tags.push('<span class="badge badge-green">已搜索网络</span>');
|
||
if (tags.length > 0) metaParts.push(tags.join(' '));
|
||
document.getElementById('planResultMeta').innerHTML = metaParts.join('<br>');
|
||
|
||
// 正文内容
|
||
document.getElementById('planResultContent').textContent = data.content;
|
||
|
||
// 参考资料
|
||
if (data.references) {
|
||
document.getElementById('planReferencesArea').style.display = '';
|
||
document.getElementById('planReferences').textContent = data.references;
|
||
} else {
|
||
document.getElementById('planReferencesArea').style.display = 'none';
|
||
}
|
||
}
|
||
|
||
function downloadPlanMd() {
|
||
if (!currentPlanId) { showToast('请先生成方案', 'error'); return; }
|
||
window.open(`/api/audit-plan/${currentPlanId}/download`, '_blank');
|
||
}
|
||
|
||
async function downloadPlanDocx() {
|
||
if (!currentPlanId) { showToast('请先生成方案', 'error'); return; }
|
||
showToast('正在生成 Word 文档...');
|
||
try {
|
||
const res = await fetch(`/api/audit-plan/${currentPlanId}/download-docx`, { method: 'POST' });
|
||
if (res.ok) {
|
||
const blob = await res.blob();
|
||
const url = URL.createObjectURL(blob);
|
||
const a = document.createElement('a');
|
||
a.href = url;
|
||
const disposition = res.headers.get('content-disposition') || '';
|
||
const match = disposition.match(/filename="?([^"]+)"?/);
|
||
a.download = match ? match[1] : '审计实施方案.docx';
|
||
document.body.appendChild(a);
|
||
a.click();
|
||
document.body.removeChild(a);
|
||
URL.revokeObjectURL(url);
|
||
showToast('Word 文档下载已开始');
|
||
} else {
|
||
const data = await res.json();
|
||
showToast(data.detail || '文档生成失败', 'error');
|
||
}
|
||
} catch (e) {
|
||
showToast('下载失败', 'error');
|
||
}
|
||
}
|
||
|
||
// ====== 审计报告生成 ======
|
||
|
||
let currentReportId = null;
|
||
let reportWikiSpaces = [];
|
||
let selectedReportProjectId = null;
|
||
let reportTreeExpanded = {};
|
||
let reportProjectDocs = [];
|
||
let reportProjectResults = [];
|
||
|
||
async function openAuditReportModal() {
|
||
resetReportModal();
|
||
document.getElementById('modalAuditReport').classList.add('show');
|
||
await loadReportProjectOptions();
|
||
await loadReportWikiSpaces();
|
||
}
|
||
|
||
function resetReportModal() {
|
||
document.getElementById('reportInputArea').style.display = '';
|
||
document.getElementById('reportResultArea').style.display = 'none';
|
||
document.getElementById('reportDesc').value = '';
|
||
document.getElementById('reportProjectInfo').style.display = 'none';
|
||
document.getElementById('reportSelectionArea').style.display = 'none';
|
||
currentReportId = null;
|
||
selectedReportProjectId = null;
|
||
reportTreeExpanded = {};
|
||
reportProjectDocs = [];
|
||
reportProjectResults = [];
|
||
}
|
||
|
||
async function loadReportProjectOptions() {
|
||
if (!projects.length) await loadProjects();
|
||
if (!years.length) await loadYears();
|
||
if (!categories.length) await loadCategories();
|
||
renderReportProjectTree();
|
||
}
|
||
|
||
function renderReportProjectTree() {
|
||
const container = document.getElementById('reportProjectTree');
|
||
if (categories.length === 0) {
|
||
container.innerHTML = '<p style="font-size:13px;color:var(--text-muted);text-align:center;padding:12px;">暂无项目大类数据</p>';
|
||
return;
|
||
}
|
||
|
||
let html = '';
|
||
categories.forEach(cat => {
|
||
const catId = cat.id;
|
||
const catName = cat["大类名称"] || "未命名大类";
|
||
const catYears = years.filter(y => {
|
||
const rel = y["所属大类"];
|
||
return rel && rel.includes(catId);
|
||
});
|
||
|
||
html += `<div class="tree-node tree-lvl-1">`;
|
||
html += `<div class="tree-node-header" onclick="toggleReportNode('cat_${catId}')">`;
|
||
html += `<span class="tree-toggle ${reportTreeExpanded['cat_' + catId] ? 'expanded' : ''} ${catYears.length === 0 ? 'empty' : ''}">▶</span>`;
|
||
html += `<span class="tree-label">${catName}</span>`;
|
||
if (catYears.length > 0) html += `<span class="tree-badge">${catYears.length}</span>`;
|
||
html += `</div>`;
|
||
|
||
if (reportTreeExpanded['cat_' + catId]) {
|
||
html += `<div class="tree-children show">`;
|
||
if (catYears.length === 0) {
|
||
html += `<div style="padding:4px 8px;font-size:12px;color:var(--text-muted);">暂无年度</div>`;
|
||
} else {
|
||
catYears.forEach(yr => {
|
||
const yrId = yr.id;
|
||
const yrName = yr["年度名称"] || yr["年度"] || "未命名年度";
|
||
const yrProjects = projects.filter(p => {
|
||
const rel = p["所属年度"];
|
||
return rel && rel.includes(yrId);
|
||
});
|
||
|
||
html += `<div class="tree-node tree-lvl-2">`;
|
||
html += `<div class="tree-node-header" onclick="toggleReportNode('yr_${yrId}')">`;
|
||
html += `<span class="tree-toggle ${reportTreeExpanded['yr_' + yrId] ? 'expanded' : ''} ${yrProjects.length === 0 ? 'empty' : ''}">▶</span>`;
|
||
html += `<span class="tree-label">${yrName}</span>`;
|
||
if (yrProjects.length > 0) html += `<span class="tree-badge">${yrProjects.length}</span>`;
|
||
html += `</div>`;
|
||
|
||
if (reportTreeExpanded['yr_' + yrId]) {
|
||
html += `<div class="tree-children show">`;
|
||
if (yrProjects.length === 0) {
|
||
html += `<div style="padding:4px 8px;font-size:12px;color:var(--text-muted);">暂无项目</div>`;
|
||
} else {
|
||
yrProjects.forEach(proj => {
|
||
const projId = proj.id;
|
||
const projName = proj["项目名称"] || "未命名项目";
|
||
const isActive = projId === selectedReportProjectId;
|
||
html += `<div class="tree-step-header ${isActive ? 'active' : ''}" onclick="selectReportProject('${projId}')" style="padding:6px 12px;cursor:pointer;border-radius:var(--radius-sm);transition:all 0.2s;">`;
|
||
html += `<span>${projName}</span>`;
|
||
html += `</div>`;
|
||
});
|
||
}
|
||
html += `</div>`;
|
||
}
|
||
html += `</div>`;
|
||
});
|
||
}
|
||
html += `</div>`;
|
||
}
|
||
html += `</div>`;
|
||
});
|
||
|
||
container.innerHTML = html;
|
||
}
|
||
|
||
function toggleReportNode(key) {
|
||
reportTreeExpanded[key] = !reportTreeExpanded[key];
|
||
renderReportProjectTree();
|
||
}
|
||
|
||
async function selectReportProject(projId) {
|
||
selectedReportProjectId = projId;
|
||
renderReportProjectTree();
|
||
await loadProjectDocsAndResults(projId);
|
||
updateReportProjectInfo();
|
||
}
|
||
|
||
async function loadProjectDocsAndResults(projId) {
|
||
const listContainer = document.getElementById('reportDocList');
|
||
const selArea = document.getElementById('reportSelectionArea');
|
||
listContainer.innerHTML = '<p style="font-size:13px;color:var(--text-muted);text-align:center;padding:8px;">加载中...</p>';
|
||
selArea.style.display = '';
|
||
|
||
try {
|
||
const res = await fetch(`/api/audit-report/project-docs/${projId}`);
|
||
if (!res.ok) {
|
||
const err = await res.json();
|
||
listContainer.innerHTML = `<p style="font-size:13px;color:var(--danger);padding:8px;">${err.detail || '加载失败'}</p>`;
|
||
return;
|
||
}
|
||
const data = await res.json();
|
||
reportProjectDocs = data.docs || [];
|
||
reportProjectResults = data.results || [];
|
||
|
||
if (reportProjectDocs.length === 0 && reportProjectResults.length === 0) {
|
||
listContainer.innerHTML = '<p style="font-size:13px;color:var(--text-muted);padding:8px;">该项目下暂无审计资料和分析结果</p>';
|
||
return;
|
||
}
|
||
|
||
let html = '';
|
||
if (reportProjectDocs.length > 0) {
|
||
html += `<div style="font-size:12px;color:var(--text-muted);padding:4px 0;">审计资料(${reportProjectDocs.length})</div>`;
|
||
reportProjectDocs.forEach(d => {
|
||
const stepLabel = d.step_names && d.step_names.length > 0 ? ` [${d.step_names.join('、')}]` : '';
|
||
html += `
|
||
<label style="display:flex;align-items:flex-start;gap:6px;padding:6px 8px;border:1px solid var(--border);border-radius:var(--radius-sm);cursor:pointer;font-size:13px;">
|
||
<input type="checkbox" class="report-doc-cb" value="${d.id}" checked style="margin-top:2px;flex-shrink:0;width:14px;height:14px;">
|
||
<div style="flex:1;">
|
||
<div style="font-weight:500;">${d.title}</div>
|
||
<div style="font-size:11px;color:var(--text-muted);">${d.type} · ${d.status}${stepLabel}</div>
|
||
</div>
|
||
</label>`;
|
||
});
|
||
}
|
||
if (reportProjectResults.length > 0) {
|
||
html += `<div style="font-size:12px;color:var(--text-muted);padding:4px 0;margin-top:6px;">分析结果(${reportProjectResults.length})</div>`;
|
||
reportProjectResults.forEach(r => {
|
||
const riskColor = r.risk_level === '高' ? 'var(--danger)' : r.risk_level === '中' ? 'var(--warning)' : 'var(--text-muted)';
|
||
html += `
|
||
<label style="display:flex;align-items:flex-start;gap:6px;padding:6px 8px;border:1px solid var(--border);border-radius:var(--radius-sm);cursor:pointer;font-size:13px;">
|
||
<input type="checkbox" class="report-result-cb" value="${r.id}" checked style="margin-top:2px;flex-shrink:0;width:14px;height:14px;">
|
||
<div style="flex:1;">
|
||
<div style="font-weight:500;">${r.analysis_type} <span style="color:${riskColor};font-size:11px;">[${r.risk_level}]</span></div>
|
||
${r.summary ? `<div style="font-size:11px;color:var(--text-muted);">${r.summary.substring(0, 60)}${r.summary.length > 60 ? '...' : ''}</div>` : ''}
|
||
</div>
|
||
</label>`;
|
||
});
|
||
}
|
||
listContainer.innerHTML = html;
|
||
} catch (e) {
|
||
listContainer.innerHTML = '<p style="font-size:13px;color:var(--danger);padding:8px;">加载失败</p>';
|
||
}
|
||
}
|
||
|
||
function updateReportProjectInfo() {
|
||
const infoArea = document.getElementById('reportProjectInfo');
|
||
if (!selectedReportProjectId) { infoArea.style.display = 'none'; return; }
|
||
|
||
const proj = projects.find(p => p.id === selectedReportProjectId);
|
||
if (!proj) { infoArea.style.display = 'none'; return; }
|
||
|
||
const projName = proj["项目名称"] || "未命名项目";
|
||
|
||
let breadcrumb = "";
|
||
const yrIds = proj["所属年度"] || [];
|
||
if (yrIds.length > 0) {
|
||
const yr = years.find(y => y.id === yrIds[0]);
|
||
if (yr) {
|
||
const yrName = yr["年度名称"] || yr["年度"] || "";
|
||
const catIds = yr["所属大类"] || [];
|
||
if (catIds.length > 0) {
|
||
const cat = categories.find(c => c.id === catIds[0]);
|
||
if (cat) {
|
||
breadcrumb = `${cat["大类名称"] || ""} › ${yrName}`;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
document.getElementById('reportBreadcrumb').textContent = breadcrumb;
|
||
document.getElementById('reportProjectSummary').textContent = projName;
|
||
infoArea.style.display = '';
|
||
}
|
||
|
||
function reportSelectAll(selectAll) {
|
||
document.querySelectorAll('.report-doc-cb, .report-result-cb').forEach(cb => {
|
||
if (selectAll) {
|
||
cb.checked = true;
|
||
} else {
|
||
cb.checked = !cb.checked;
|
||
}
|
||
});
|
||
}
|
||
|
||
async function loadReportWikiSpaces() {
|
||
const container = document.getElementById('reportWikiList');
|
||
container.innerHTML = '<p style="font-size:13px;color:var(--text-muted);">加载中...</p>';
|
||
try {
|
||
const res = await fetch('/api/wiki/spaces');
|
||
if (!res.ok) { container.innerHTML = '<p style="font-size:13px;color:var(--danger);">知识库加载失败</p>'; return; }
|
||
const data = await res.json();
|
||
reportWikiSpaces = data.spaces || [];
|
||
if (reportWikiSpaces.length === 0) {
|
||
container.innerHTML = '<p style="font-size:13px;color:var(--text-muted);">暂无可访问的知识空间</p>';
|
||
return;
|
||
}
|
||
container.innerHTML = reportWikiSpaces.map(s => `
|
||
<label style="display:flex;align-items:flex-start;gap:8px;padding:8px 12px;border:1px solid var(--border);border-radius:var(--radius-md);cursor:pointer;transition:all 0.2s;background:var(--surface-card);">
|
||
<input type="checkbox" value="${s.space_id}" style="margin-top:3px;flex-shrink:0;width:15px;height:15px;">
|
||
<div style="flex:1;">
|
||
<div style="font-size:13px;font-weight:600;color:var(--text);">${s.name}</div>
|
||
${s.description ? `<div style="font-size:11px;color:var(--text-muted);margin-top:1px;">${s.description}</div>` : ''}
|
||
</div>
|
||
</label>
|
||
`).join('');
|
||
} catch (e) {
|
||
container.innerHTML = '<p style="font-size:13px;color:var(--danger);">加载失败</p>';
|
||
}
|
||
}
|
||
|
||
async function generateAuditReport() {
|
||
if (!selectedReportProjectId) { showToast('请选择项目', 'error'); return; }
|
||
|
||
const selectedDocIds = Array.from(document.querySelectorAll('.report-doc-cb:checked')).map(cb => cb.value);
|
||
const selectedResultIds = Array.from(document.querySelectorAll('.report-result-cb:checked')).map(cb => cb.value);
|
||
const wikiIds = Array.from(document.querySelectorAll('#reportWikiList input[type=checkbox]:checked')).map(cb => cb.value);
|
||
const desc = document.getElementById('reportDesc').value.trim();
|
||
|
||
if (selectedDocIds.length === 0) { showToast('请至少选择一份审计资料', 'error'); return; }
|
||
|
||
const btn = document.getElementById('generateReportBtn');
|
||
const originalText = btn.textContent;
|
||
btn.disabled = true;
|
||
btn.innerHTML = '<span class="loading"></span> 正在生成报告...';
|
||
|
||
const hints = [`引用${selectedDocIds.length}份资料`];
|
||
if (selectedResultIds.length > 0) hints.push(`${selectedResultIds.length}条分析结果`);
|
||
if (wikiIds.length > 0) hints.push(`${wikiIds.length}个知识空间`);
|
||
hints.push('搜索网络');
|
||
showToast(`正在生成审计报告(${hints.join(' + ')}),请稍候...`);
|
||
|
||
try {
|
||
const formData = new FormData();
|
||
formData.append('project_id', selectedReportProjectId);
|
||
formData.append('doc_ids', selectedDocIds.join(','));
|
||
formData.append('result_ids', selectedResultIds.join(','));
|
||
if (desc) formData.append('report_desc', desc);
|
||
if (wikiIds.length > 0) formData.append('wiki_space_ids', wikiIds.join(','));
|
||
|
||
const res = await fetch('/api/audit-report/generate', { method: 'POST', body: formData });
|
||
const data = await res.json();
|
||
if (res.ok) {
|
||
currentReportId = data.report_id;
|
||
showReportResult(data);
|
||
showToast('审计报告生成完成');
|
||
} else {
|
||
showToast(data.detail || '报告生成失败', 'error');
|
||
}
|
||
} catch (e) {
|
||
showToast('网络错误', 'error');
|
||
} finally {
|
||
btn.disabled = false;
|
||
btn.textContent = originalText;
|
||
}
|
||
}
|
||
|
||
function showReportResult(data) {
|
||
document.getElementById('reportInputArea').style.display = 'none';
|
||
document.getElementById('reportResultArea').style.display = '';
|
||
|
||
const metaParts = [];
|
||
metaParts.push(`<strong style="font-size:15px;">${data.title}</strong>`);
|
||
const tags = [];
|
||
tags.push(`<span class="badge badge-gray">${data.doc_count} 份资料</span>`);
|
||
tags.push(`<span class="badge badge-gray">${data.result_count} 条分析</span>`);
|
||
if (data.knowledge_used) tags.push('<span class="badge badge-blue">已引用知识库</span>');
|
||
if (data.web_used) tags.push('<span class="badge badge-green">已搜索网络</span>');
|
||
metaParts.push(tags.join(' '));
|
||
document.getElementById('reportResultMeta').innerHTML = metaParts.join('<br>');
|
||
|
||
document.getElementById('reportResultContent').textContent = data.content;
|
||
|
||
if (data.references) {
|
||
document.getElementById('reportReferencesArea').style.display = '';
|
||
document.getElementById('reportReferences').textContent = data.references;
|
||
} else {
|
||
document.getElementById('reportReferencesArea').style.display = 'none';
|
||
}
|
||
}
|
||
|
||
function downloadReportMd() {
|
||
if (!currentReportId) { showToast('请先生成报告', 'error'); return; }
|
||
window.open(`/api/audit-report/${currentReportId}/download`, '_blank');
|
||
}
|
||
|
||
async function downloadReportDocx() {
|
||
if (!currentReportId) { showToast('请先生成报告', 'error'); return; }
|
||
showToast('正在生成 Word 文档...');
|
||
try {
|
||
const res = await fetch(`/api/audit-report/${currentReportId}/download-docx`, { method: 'POST' });
|
||
if (res.ok) {
|
||
const blob = await res.blob();
|
||
const url = URL.createObjectURL(blob);
|
||
const a = document.createElement('a');
|
||
a.href = url;
|
||
const disposition = res.headers.get('content-disposition') || '';
|
||
const match = disposition.match(/filename="?([^"]+)"?/);
|
||
a.download = match ? match[1] : '审计报告.docx';
|
||
document.body.appendChild(a);
|
||
a.click();
|
||
document.body.removeChild(a);
|
||
URL.revokeObjectURL(url);
|
||
showToast('Word 文档下载已开始');
|
||
} else {
|
||
const data = await res.json();
|
||
showToast(data.detail || '文档生成失败', 'error');
|
||
}
|
||
} catch (e) {
|
||
showToast('下载失败', 'error');
|
||
}
|
||
}
|
||
|
||
// ====== 点击弹窗外部关闭 ======
|
||
document.querySelectorAll(".modal-overlay").forEach(el => {
|
||
el.addEventListener("click", function(e) {
|
||
if (e.target === this) this.classList.remove("show");
|
||
});
|
||
});
|
||
|
||
// ====== 拖拽调整侧边栏宽度 ======
|
||
(function initResizer() {
|
||
const sidebar = document.getElementById('sidebar');
|
||
const resizer = document.getElementById('resizer');
|
||
if (!resizer || !sidebar) return;
|
||
|
||
let isResizing = false;
|
||
|
||
resizer.addEventListener('mousedown', function(e) {
|
||
isResizing = true;
|
||
resizer.classList.add('resizing');
|
||
document.body.style.cursor = 'col-resize';
|
||
document.body.style.userSelect = 'none';
|
||
e.preventDefault();
|
||
});
|
||
|
||
document.addEventListener('mousemove', function(e) {
|
||
if (!isResizing) return;
|
||
const newWidth = e.clientX;
|
||
if (newWidth >= 200 && newWidth <= 500) {
|
||
sidebar.style.width = newWidth + 'px';
|
||
}
|
||
});
|
||
|
||
document.addEventListener('mouseup', function() {
|
||
if (isResizing) {
|
||
isResizing = false;
|
||
resizer.classList.remove('resizing');
|
||
document.body.style.cursor = '';
|
||
document.body.style.userSelect = '';
|
||
}
|
||
});
|
||
})();
|
||
|
||
// ====== 启动 ======
|
||
init();
|
||
</script>
|
||
<!-- 返回门户按钮(由部署脚本添加) -->
|
||
<a id="portalBackBtn" href="#" title="返回综合门户" style="position:fixed;left:18px;bottom:18px;z-index:99999;display:inline-flex;align-items:center;gap:6px;padding:9px 16px;border-radius:22px;background:rgba(12,32,48,.85);border:1px solid rgba(90,210,255,.45);color:#bfe9ff;font-family:'Microsoft YaHei','PingFang SC',sans-serif;font-size:13px;font-weight:500;text-decoration:none;box-shadow:0 6px 18px rgba(0,0,0,.35);backdrop-filter:blur(6px)">← 返回门户</a>
|
||
<script>
|
||
(function(){
|
||
var b = document.getElementById('portalBackBtn');
|
||
if (!b) return;
|
||
var p = location.port, proto = location.protocol;
|
||
var target = (p === '8000' || p === '8001' || p === '8090')
|
||
? (proto + '//' + location.hostname + ':8080/')
|
||
: (proto + '//' + location.host + '/');
|
||
b.href = target;
|
||
})();
|
||
</script>
|
||
<script>
|
||
/* 右上角返回门户(2026-10-17) */
|
||
(function () {
|
||
if (document.getElementById('portalTopBack')) return;
|
||
var url = 'http://' + location.hostname + ':8080/';
|
||
var a = document.createElement('a');
|
||
a.id = 'portalTopBack';
|
||
a.href = url;
|
||
a.textContent = '← 返回门户';
|
||
a.style.cssText = 'display:inline-flex;align-items:center;gap:6px;padding:7px 14px;border-radius:20px;' +
|
||
'background:rgba(10,30,45,.6);border:1px solid rgba(80,200,255,.35);color:#9fe8ff;' +
|
||
'font-size:13px;text-decoration:none;font-family:inherit;white-space:nowrap;';
|
||
var target = document.querySelector('.topbar-actions') ||
|
||
document.querySelector('.topbar-right') ||
|
||
document.querySelector('.app-header > div:last-child');
|
||
if (target) {
|
||
target.appendChild(a);
|
||
} else {
|
||
a.style.position = 'fixed';
|
||
a.style.right = '18px';
|
||
a.style.top = '18px';
|
||
a.style.zIndex = '99999';
|
||
a.style.background = 'rgba(10,30,45,.72)';
|
||
a.style.backdropFilter = 'blur(6px)';
|
||
document.body.appendChild(a);
|
||
}
|
||
})();
|
||
</script>
|
||
|
||
<script>
|
||
/* 深链:?expand=all / ?project= 自动展开并打开项目(2026-10-17) */
|
||
(function () {
|
||
const p = new URLSearchParams(location.search);
|
||
const pid = p.get('project');
|
||
if (p.get('expand') !== 'all' && !pid) return;
|
||
let tries = 0;
|
||
const timer = setInterval(function () {
|
||
tries++;
|
||
const ready = (typeof projects !== 'undefined' && projects.length) || tries > 40;
|
||
if (!ready) return;
|
||
clearInterval(timer);
|
||
if (typeof years !== 'undefined') years.forEach(y => { expandedNodes['yr_' + y.id] = true; });
|
||
if (typeof projects !== 'undefined') projects.forEach(pr => { expandedNodes['proj_' + pr.id] = true; });
|
||
if (typeof renderProjectTree === 'function') renderProjectTree();
|
||
|
||
if (!pid) return;
|
||
// 等步骤数据加载后再打开
|
||
let t2 = 0;
|
||
const timer2 = setInterval(function () {
|
||
t2++;
|
||
if (typeof steps === 'undefined') { if (t2 > 40) clearInterval(timer2); return; }
|
||
clearInterval(timer2);
|
||
const step = steps.find(s => {
|
||
const rel = s['所属项目'];
|
||
return rel && rel.includes(String(pid));
|
||
});
|
||
if (step && typeof selectStep === 'function') {
|
||
selectStep(step.id, pid);
|
||
const el = document.getElementById('label_proj_' + pid);
|
||
if (el) el.style.background = 'rgba(34,211,238,.18)';
|
||
return;
|
||
}
|
||
// 没有步骤:显示项目基本信息
|
||
const proj = projects.find(x => String(x.id) === String(pid));
|
||
const main = document.getElementById('mainContent');
|
||
if (proj && main) {
|
||
const name = proj['项目名称'] || proj.name || '项目';
|
||
const status = proj['项目状态'] || proj.status || '-';
|
||
const start = proj['开始日期'] || proj.start_date || '-';
|
||
const end = proj['结束日期'] || proj.end_date || '-';
|
||
main.innerHTML = '<div style="padding:28px">' +
|
||
'<h2 style="margin-bottom:16px">' + name + '</h2>' +
|
||
'<div style="font-size:14px;line-height:2;color:var(--text-secondary)">' +
|
||
'状态:' + status + '<br>开始日期:' + start + '<br>结束日期:' + end +
|
||
'<br><br><span style="color:var(--text-muted)">该项目暂未添加步骤,可在左侧树中点击 + 添加步骤。</span></div></div>';
|
||
}
|
||
}, 300);
|
||
}, 300);
|
||
})();
|
||
</script>
|
||
|
||
<style id="platform-embed-style">
|
||
/* shared/embed_theme.css — 统一平台外壳嵌入主题(唯一来源)
|
||
* 由 deploy/同步统一主题.py 注入到各业务页面的 <style id="platform-embed-style">。
|
||
* 规则:只隐藏子系统顶栏,保留业务侧栏(项目树/风险菜单/合同功能/知识库分类)。
|
||
*/
|
||
body.embedded .app-header,
|
||
body.embedded .topbar { display:none !important; }
|
||
body.embedded { background:#0a1622 !important; }
|
||
body.embedded #portalBackBtn,
|
||
body.embedded #portalTopBack { display:none !important; }
|
||
body.embedded .main-content,
|
||
body.embedded .main-area,
|
||
body.embedded .main { background:transparent !important; }
|
||
body.embedded iframe { border:0; }
|
||
body.embedded .sidebar { height:100vh !important; top:0 !important; }
|
||
body.embedded .main-content,
|
||
body.embedded .main-area { height:100vh !important; }
|
||
body.embedded .app-body { min-height:100vh !important; }
|
||
body.embedded .layout { min-height:100vh !important; }
|
||
|
||
/* ===== 统一组件细节(颜色跟随各页面主题,不改变原有配色) ===== */
|
||
body.embedded button,
|
||
body.embedded .btn { border-radius:8px; transition:background .15s ease, border-color .15s ease, transform .1s ease; }
|
||
body.embedded button:active,
|
||
body.embedded .btn:active { transform:translateY(1px); }
|
||
body.embedded button:focus-visible,
|
||
body.embedded .btn:focus-visible,
|
||
body.embedded a:focus-visible { outline:2px solid currentColor; outline-offset:2px; }
|
||
body.embedded input:focus,
|
||
body.embedded select:focus,
|
||
body.embedded textarea:focus { outline:2px solid rgba(79,209,255,.5); outline-offset:1px; }
|
||
body.embedded table tbody tr { transition:background .12s ease; }
|
||
body.embedded .empty { padding:26px 12px; text-align:center; border-radius:10px; }
|
||
</style>
|
||
<script id="platform-embed-script">
|
||
(function(){
|
||
try {
|
||
var embedded = location.search.indexOf('embed=1') >= 0 || window.self !== window.top;
|
||
if (embedded) {
|
||
document.addEventListener('DOMContentLoaded', function(){ document.body.classList.add('embedded'); });
|
||
if (document.body) document.body.classList.add('embedded');
|
||
}
|
||
} catch(e) {}
|
||
})();
|
||
</script>
|
||
|
||
</body>
|
||
</html>
|
||
|