init 全新仓库,清除全部历史

This commit is contained in:
2026-07-09 09:54:43 +08:00
commit 0c2fe393df
154 changed files with 56586 additions and 0 deletions
+823
View File
@@ -0,0 +1,823 @@
<?php
session_start();
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Pragma: no-cache");
header("Expires: Thu, 01 Jan 1970 00:00:00 GMT");
$expire = 1800;
if (empty($_SESSION['user_id']) || (time() - $_SESSION['login_time'] > $expire)) {
session_destroy();
header("Location: login.php");
exit;
}
$_SESSION['login_time'] = time();
$userName = htmlspecialchars($_SESSION['username']);
$userRoleId = $_SESSION['role_id'];
// 读取全局配置库 alert_mail_stat
$dbConfigHost = "10.150.117.190";
$dbConfigUser = "root";
$dbConfigPwd = "hp93000";
$dbConfigName = "alert_mail_stat";
$connConfig = mysqli_connect($dbConfigHost, $dbConfigUser, $dbConfigPwd, $dbConfigName);
mysqli_set_charset($connConfig, "utf8mb4");
$configSql = "SELECT k,v FROM sys_config";
$configRes = mysqli_query($connConfig, $configSql);
$sysConfig = [];
while ($row = mysqli_fetch_assoc($configRes)) {
$sysConfig[$row['k']] = $row['v'];
}
// 读取SMTP配置
$smtpRow = mysqli_fetch_assoc(mysqli_query($connConfig, "SELECT * FROM sys_smtp_config WHERE id=1"));
$smtpConfig = $smtpRow ?? [];
$pageTitle = htmlspecialchars($sysConfig['page_title'] ?? "告警监控系统");
$currentLang = $sysConfig['lang'] ?? "zh";
$sidebarRawLinks = $sysConfig['sidebar_links'] ?? "";
mysqli_close($connConfig);
// 多语言词典
$langMap = [
'zh' => [
'html_lang' => 'zh-CN',
'page_subtitle' => '爱德万测试 · 运维告警监控平台',
'monitor_panel' => '监控面板',
'alert_overview' => '告警监控总览',
'disk_capacity' => '服务器磁盘容量',
'alert_list_page' => '历史告警查询',
'quick_link' => '快捷外链',
'system_manage' => '系统管理',
'system_config' => '后台配置管理',
'smtp_config' => '邮箱SMTP配置',
'current_user' => '当前用户:',
'sys_time' => '系统时间:',
'refresh_all' => '刷新全部数据',
'export_csv' => '导出CSV',
'logout' => '退出登录',
'lang_text' => '语言:',
'work_order_mgr' => '工单系统',
'work_create' => '新建工单',
'work_edit' => '编辑工单',
'work_assign' => '分发工单',
'work_status' => '工单状态',
'work_creator' => '创建人',
'work_handler' => '处理人',
'work_content' => '工单内容/备注',
'work_title' => '工单标题',
'work_create_time' => '创建时间',
'work_update_time' => '更新时间',
'work_all_list' => '全部工单列表',
'work_no_data' => '暂无工单记录',
'work_save' => '保存',
'work_cancel' => '取消',
'work_placeholder_title' => '填写故障/需求标题',
'work_placeholder_content' => '详细描述故障、操作步骤、处理备注',
'work_select_handler' => '选择处理人(留空暂不分配)',
'status_1' => '待处理',
'status_2' => '处理中',
'status_3' => '已完成',
'status_4' => '已关闭',
'no_alert_choose' => '不关联任何告警',
'relate_alert' => '关联告警(可选)',
'relate_alert_id' => '关联告警ID',
'notify_title' => '通知配置',
'notify_user' => '通知接收人',
'notify_channel' => '通知渠道',
'channel_mail' => '邮箱',
'channel_ding' => '钉钉',
'channel_wecom' => '企业微信',
'smtp_host' => 'SMTP服务器',
'smtp_port' => '端口',
'smtp_ssl' => '启用SSL/TLS',
'smtp_account' => '发件账号',
'smtp_pwd' => '授权密码',
'smtp_from' => '发件人名称',
'save_smtp' => '保存SMTP配置',
'alert_loading' => '加载当前活跃告警...',
'no_alert_data' => '暂无正在触发的告警',
'user_loading' => '加载用户列表...',
'no_user_data' => '无可用用户',
'perm_deny' => '权限不足,无法访问',
],
'en' => [
'html_lang' => 'en',
'page_subtitle' => 'Advantest · O&M Alert Monitor Platform',
'monitor_panel' => 'Monitor Panel',
'alert_overview' => 'Alert Overview',
'disk_capacity' => 'Server Disk Capacity',
'alert_list_page' => 'Alert Pagination List',
'quick_link' => 'Quick Links',
'system_manage' => 'System Manage',
'system_config' => 'System Config',
'smtp_config' => 'SMTP Mail Config',
'current_user' => 'User: ',
'sys_time' => 'System Time: ',
'refresh_all' => 'Refresh All Data',
'export_csv' => 'Export CSV',
'logout' => 'Logout',
'lang_text' => 'Lang: ',
'work_order_mgr' => 'Work Order System',
'work_create' => 'Create Order',
'work_edit' => 'Edit Order',
'work_assign' => 'Assign Order',
'work_status' => 'Status',
'work_creator' => 'Creator',
'work_handler' => 'Handler',
'work_content' => 'Content / Remark',
'work_title' => 'Order Title',
'work_create_time' => 'Create Time',
'work_update_time' => 'Update Time',
'work_all_list' => 'All Work Order List',
'work_no_data' => 'No order data',
'work_save' => 'Save',
'work_cancel' => 'Cancel',
'work_placeholder_title' => 'Fill fault or demand title',
'work_placeholder_content' => 'Describe fault, steps and handling remark',
'work_select_handler' => 'Select handler (empty for unassigned)',
'status_1' => 'Pending',
'status_2' => 'Processing',
'status_3' => 'Finished',
'status_4' => 'Closed',
'no_alert_choose' => 'No related alert',
'relate_alert' => 'Relate Alert (Optional)',
'relate_alert_id' => 'Relate Alert ID',
'notify_title' => 'Notification Config',
'notify_user' => 'Notify Users',
'notify_channel' => 'Notify Channel',
'channel_mail' => 'Email',
'channel_ding' => 'DingTalk',
'channel_wecom' => 'WeCom',
'smtp_host' => 'SMTP Host',
'smtp_port' => 'Port',
'smtp_ssl' => 'Enable SSL/TLS',
'smtp_account' => 'SMTP Account',
'smtp_pwd' => 'Auth Password',
'smtp_from' => 'Sender Name',
'save_smtp' => 'Save SMTP Config',
'alert_loading' => 'Loading active alerts...',
'no_alert_data' => 'No active firing alerts',
'user_loading' => 'Loading user list...',
'no_user_data' => 'No available users',
'perm_deny' => 'Permission denied',
]
];
$t = $langMap[$currentLang];
// 解析外链菜单
$sidebarLinkList = [];
if (!empty($sidebarRawLinks)) {
$lines = explode("\n", $sidebarRawLinks);
foreach ($lines as $line) {
$line = trim($line);
if (empty($line)) continue;
$item = explode("|", $line, 2);
if (count($item) === 2) {
$sidebarLinkList[] = ["name" => trim($item[0]), "url" => trim($item[1])];
}
}
}
// ========== 工单业务库 monitor ==========
$dbWorkHost = "10.150.117.190";
$dbWorkUser = "root";
$dbWorkPwd = "hp93000";
$dbWorkName = "monitor";
$connWork = mysqli_connect($dbWorkHost, $dbWorkUser, $dbWorkPwd, $dbWorkName);
if (!$connWork) die("Work DB connect fail: " . mysqli_connect_error());
mysqli_set_charset($connWork, "utf8mb4");
$loginUid = $_SESSION['user_id'];
// 读取当前用户角色权限
$permList = "";
$roleSql = "SELECT r.is_admin, r.perm_list FROM sys_user u LEFT JOIN sys_role r ON u.role_id=r.id WHERE u.uid = ?";
$stmtRole = mysqli_prepare($connWork, $roleSql);
mysqli_stmt_bind_param($stmtRole, 's', $loginUid);
mysqli_stmt_execute($stmtRole);
$roleRow = mysqli_fetch_assoc(mysqli_stmt_get_result($stmtRole));
$isAdmin = 0;
$permList = "";
if ($roleRow) {
$isAdmin = intval($roleRow['is_admin']);
$permList = $roleRow['perm_list'];
}
$hasWorkPerm = str_contains($permList, "work_order");
if (!$hasWorkPerm) {
echo "<script>alert('".$t['perm_deny']."');location.href='dashboard.php';</script>";
exit;
}
// 加载全部系统用户(解决处理人下拉空白)
$userOptions = "";
$userAll = mysqli_query($connWork, "SELECT uid, real_name, username FROM sys_user WHERE enable = 1 ORDER BY real_name ASC");
while ($u = mysqli_fetch_assoc($userAll)) {
$userOptions .= '<option value="' . $u['uid'] . '">' . $u['real_name'] . '(' . $u['username'] . ')</option>';
}
// 分页修复防报错
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
$pageSize = intval($sysConfig['page_size'] ?? 20);
if ($pageSize < 1) $pageSize = 20;
$offset = ($page - 1) * $pageSize;
// 权限过滤
if ($isAdmin === 1) {
$whereSql = " 1=1 ";
} else {
$whereSql = " (create_uid = ? OR assign_uid = ?) ";
}
// 统计总数
$cntSql = "SELECT COUNT(*) total FROM work_order WHERE " . $whereSql;
$stmtCnt = mysqli_prepare($connWork, $cntSql);
if ($isAdmin !== 1) {
mysqli_stmt_bind_param($stmtCnt, 'ss', $loginUid, $loginUid);
}
mysqli_stmt_execute($stmtCnt);
$cntRow = mysqli_fetch_assoc(mysqli_stmt_get_result($stmtCnt));
$total = intval($cntRow['total'] ?? 0);
$totalPage = $pageSize <= 0 ? 1 : ceil($total / $pageSize);
// 工单列表查询
$listSql = "SELECT wo.*, uc.real_name create_name, ua.real_name assign_name
FROM work_order wo
LEFT JOIN sys_user uc ON wo.create_uid = uc.uid
LEFT JOIN sys_user ua ON wo.assign_uid = ua.uid
WHERE " . $whereSql . " ORDER BY create_time DESC LIMIT ?, ?";
$stmtList = mysqli_prepare($connWork, $listSql);
if ($isAdmin === 1) {
mysqli_stmt_bind_param($stmtList, 'ii', $offset, $pageSize);
} else {
mysqli_stmt_bind_param($stmtList, 'ssii', $loginUid, $loginUid, $offset, $pageSize);
}
mysqli_stmt_execute($stmtList);
$listResult = mysqli_stmt_get_result($stmtList);
$orderList = [];
while ($row = mysqli_fetch_assoc($listResult)) {
$orderList[] = $row;
}
mysqli_close($connWork);
?>
<!DOCTYPE html>
<html lang="<?php echo $t['html_lang']; ?>">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo $pageTitle; ?> - Advantest <?php echo $t['work_order_mgr']; ?></title>
<link rel="stylesheet" href="/static/css/font-awesome.min.css">
<script src="/static/js/echarts.min.js"></script>
<script src="/static/js/jquery.min.js"></script>
<style>
*{box-sizing:border-box;margin:0;padding:0}
body{background:#f9fafc;font-family:"Inter","PingFang SC","Microsoft YaHei";color:#1d2939;line-height:1.6;display:flex;flex-direction:column;height:100vh;overflow:hidden;}
.wrap-main{display:flex;flex:1;overflow:hidden;}
.sidebar{width:240px;background:#152c5b;color:#e2e8f0;flex-shrink:0;overflow-y:auto;}
.sidebar-brand{padding:26px 24px;border-bottom:1px solid rgba(255,255,255,0.1);}
.sidebar-brand-en{font-size:20px;font-weight:700;letter-spacing:1px;color:#fff;}
.sidebar-brand-cn{font-size:13px;color:#a5b4fc;margin-top:4px;}
.sidebar-menu{padding:16px 0;}
.menu-title{padding:10px 24px;font-size:12px;color:#94a3b8;letter-spacing:1px;}
.menu-item{display:flex;align-items:center;gap:12px;padding:14px 24px;cursor:pointer;font-size:14px;transition:0.2s;color:#cbd5e1;}
.menu-item i{font-size:16px;width:20px;text-align:center;}
.menu-item.active{background:rgba(255,255,255,0.12);color:#fff;border-left:4px solid #3b82f6;}
.menu-item:hover:not(.active){background:rgba(255,255,255,0.06);color:#fff;}
.main-content{flex:1;overflow-y:auto;display:flex;flex-direction:column;}
.header{background:#ffffff;border-bottom:1px solid #eef2fb;color:#152c5b;padding:20px 40px;display:flex;justify-content:space-between;align-items:center;box-shadow:0 2px 12px rgba(21,44,91,0.05);flex-shrink:0;}
.header-left{display:flex;align-items:center;gap:14px;}
.header-brand-en{font-size:24px;font-weight:700;letter-spacing:2px;color:#152c5b;}
.header-brand-cn{font-size:15px;color:#64748b;}
.header-right{display:flex;align-items:center;gap:18px;font-size:14px;flex-wrap:wrap;}
.user-info,.time-info,.lang-box{color:#475569;display:flex;align-items:center;gap:6px;}
.lang-box select{padding:4px 8px;border:1px solid #cbd5e1;border-radius:6px;}
.btn-base{border:none;padding:9px 20px;border-radius:8px;cursor:pointer;font-size:14px;display:flex;align-items:center;gap:6px;transition:all 0.2s ease;}
.btn-outline{background:#ffffff;color:#152c5b;border:1px solid #cbd5e1;}
.btn-outline:hover{background:#f7f8fc;border-color:#152c5b;}
.btn-primary{background:#152c5b;color:#fff;}
.btn-primary:hover{background:#0f1e42;}
.btn-success{background:#10b981;color:#fff;}
.btn-success:hover{background:#059669;}
.mask{position:fixed;left:0;top:0;width:100%;height:100%;background:rgba(255,255,255,0.85);display:none;z-index:999;align-items:center;justify-content:center;}
.mask-box{background:#fff;padding:30px 40px;border-radius:14px;font-size:15px;display:flex;gap:14px;align-items:center;box-shadow:0 8px 30px rgba(21,44,91,0.12);border:1px solid #eef2fb;}
.loading{display:inline-block;width:20px;height:20px;border:2px solid #e2e8f0;border-top-color:#152c5b;border-radius:50%;animation:spin 0.8s linear infinite;}
@keyframes spin{to{transform:rotate(360deg)}}
.container{padding:36px 40px;max-width:100%;flex:1;}
.page-panel{display:none;}
.page-panel.active{display:block;}
.base-card{background:#fff;border-radius:16px;padding:32px;box-shadow:0 3px 18px rgba(21,44,91,0.06);border:1px solid #eef2fb;margin-bottom:36px;}
.title-wrap{display:flex;justify-content:space-between;align-items:center;margin-bottom:26px;padding-bottom:16px;border-bottom:1px solid #eef2fb;}
.title-left{display:flex;align-items:center;gap:12px;font-size:19px;font-weight:600;color:#152c5b;}
.title-left i{color:#2563eb;font-size:21px}
.table-count{font-size:14px;color:#64748b}
.table-wrap{overflow-x:auto}
table{width:100%;border-collapse:collapse;font-size:14px}
th{background:#f9fafc;color:#475569;font-weight:600;padding:16px 18px;text-align:left;border-bottom:2px solid #e2e8f0;white-space:nowrap;}
th i{margin-right:6px;font-size:13px;color:#94a3b8}
td{padding:18px;border-bottom:1px solid #f1f5f9;color:#334155;}
tbody tr{transition:background 0.2s}
tbody tr:hover{background:#f7f8fc}
tbody tr:nth-child(even){background:#fbfcfe}
.empty-state{text-align:center;padding:80px 20px;color:#94a3b8;font-size:15px;}
.empty-icon{font-size:56px;margin-bottom:18px;opacity:0.35;}
.modal-mask{position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.4);display:none;align-items:center;justify-content:center;z-index:999;}
.modal-box{width:720px;background:#fff;border-radius:16px;padding:32px;box-shadow:0 8px 30px rgba(21,44,91,0.12);max-height:90vh;overflow-y:auto;}
.modal-head{display:flex;justify-content:space-between;align-items:center;margin-bottom:26px;padding-bottom:16px;border-bottom:1px solid #eef2fb;}
.modal-close{cursor:pointer;font-size:22px;color:#94a3b8;}
.form-row{margin-bottom:20px;}
.form-row label{display:block;margin-bottom:8px;color:#475569;font-weight:500;}
.form-row input,.form-row select,.form-row textarea{width:100%;padding:10px 14px;border:1px solid #cbd5e1;border-radius:8px;font-size:14px;}
.form-row textarea{height:140px;resize:none;}
.btn-group{display:flex;gap:14px;margin-top:10px;}
.select-sm{padding:6px 8px;border:1px solid #cbd5e1;border-radius:6px;font-size:13px;}
.status-tag{display:inline-flex;align-items:center;gap:5px;padding:6px 14px;border-radius:24px;font-size:13px;font-weight:500;}
.status-1{background:#ffedd5;color:#ea580c}
.status-2{background:#dbeafe;color:#2563eb}
.status-3{background:#dcfce7;color:#16a34a}
.status-4{background:#f1f5f9;color:#64748b}
.page-pagination{display:flex;justify-content:space-between;align-items:center;margin-top:20px;}
.page-pag-btn{padding:8px 16px;border:1px solid #cbd5e1;background:#fff;border-radius:8px;cursor:pointer;font-size:14px;}
.page-pag-btn:hover{background:#f7f8fc;border-color:#152c5b;}
.checkbox-group{display:flex;gap:16px;flex-wrap:wrap;padding:8px 0;}
.checkbox-item{display:flex;align-items:center;gap:6px;}
.readonly-input{background:#f7f8fc;color:#64748b;}
@media (max-width:768px){
.wrap-main{flex-direction:column;}
.sidebar{width:100%;height:auto}
.header{padding:16px 24px;flex-direction:column;gap:16px;align-items:flex-start}
.header-right{flex-wrap:wrap}
.container{padding:24px}
.base-card{padding:24px}
}
</style>
</head>
<body>
<div class="mask" id="exportMask">
<div class="mask-box"><span class="loading"></span><span></span></div>
</div>
<div class="wrap-main">
<div class="sidebar">
<div class="sidebar-brand">
<div class="sidebar-brand-en">Advantest</div>
<div class="sidebar-brand-cn"><?php echo $t['page_subtitle']; ?></div>
</div>
<div class="sidebar-menu">
<div class="menu-title"><?php echo $t['monitor_panel']; ?></div>
<div class="menu-item" onclick="location.href='dashboard.php'">
<i class="fa fa-line-chart"></i><span><?php echo $t['alert_overview']; ?></span>
</div>
<div class="menu-item" onclick="location.href='dashboard.php#diskPage'">
<i class="fa fa-hdd-o"></i><span><?php echo $t['disk_capacity']; ?></span>
</div>
<div class="menu-item" onclick="window.open('alert_list.php','_blank')">
<i class="fa fa-list"></i><span><?php echo $t['alert_list_page']; ?></span>
</div>
<div class="menu-item active">
<i class="fa fa-ticket"></i><span><?php echo $t['work_order_mgr']; ?></span>
</div>
<?php if (!empty($sidebarLinkList)): ?>
<div class="menu-title"><?php echo $t['quick_link']; ?></div>
<?php foreach ($sidebarLinkList as $link): ?>
<div class="menu-item" onclick="window.open('<?php echo htmlspecialchars($link['url']); ?>')">
<i class="fa fa-external-link"></i><span><?php echo htmlspecialchars($link['name']); ?></span>
</div>
<?php endforeach; ?>
<?php endif; ?>
<div class="menu-title"><?php echo $t['system_manage']; ?></div>
<div class="menu-item" onclick="location.href='admin.php'">
<i class="fa fa-cog"></i><span><?php echo $t['system_config']; ?></span>
</div>
<div class="menu-item" onclick="location.href='smtp_config.php'">
<i class="fa fa-envelope-o"></i><span><?php echo $t['smtp_config']; ?></span>
</div>
</div>
</div>
<div class="main-content">
<div class="header">
<div class="header-left">
<div>
<div class="header-brand-en">Advantest</div>
<div class="header-brand-cn"><?php echo $t['page_subtitle']; ?></div>
</div>
</div>
<div class="header-right">
<span class="user-info"><i class="fa fa-user-circle"></i><?php echo $t['current_user']; ?><?php echo $userName; ?></span>
<span class="time-info"><i class="fa fa-clock-o"></i><?php echo $t['sys_time']; ?><span id="updateTime">--</span></span>
<div class="lang-box">
<span><?php echo $t['lang_text']; ?></span>
<select id="langSwitch">
<option value="zh" <?php echo $currentLang==='zh'?'selected':''; ?>>中文</option>
<option value="en" <?php echo $currentLang==='en'?'selected':''; ?>>EN</option>
</select>
</div>
<button class="btn-base btn-outline" onclick="loadAllData()"><i class="fa fa-refresh"></i><?php echo $t['refresh_all']; ?></button>
<button class="btn-base btn-primary" id="logoutBtn"><i class="fa fa-sign-out"></i><?php echo $t['logout']; ?></button>
</div>
</div>
<div class="container">
<div class="page-panel active" id="workOrderPage">
<div class="base-card">
<div class="title-wrap">
<div class="title-left"><i class="fa fa-ticket"></i><?php echo $t['work_all_list']; ?></div>
<button class="btn-base btn-success" id="openCreateModal"><i class="fa fa-plus"></i><?php echo $t['work_create']; ?></button>
</div>
<div class="table-wrap">
<table>
<thead>
<tr>
<th>ID</th>
<th><i class="fa fa-link"></i><?php echo $t['relate_alert_id']; ?></th>
<th><i class="fa fa-file-text"></i><?php echo $t['work_title']; ?></th>
<th><i class="fa fa-user"></i><?php echo $t['work_creator']; ?></th>
<th><i class="fa fa-user-o"></i><?php echo $t['work_handler']; ?></th>
<th><i class="fa fa-tag"></i><?php echo $t['work_status']; ?></th>
<th><i class="fa fa-calendar"></i><?php echo $t['work_create_time']; ?></th>
<th><i class="fa fa-clock-o"></i><?php echo $t['work_update_time']; ?></th>
<th>操作</th>
</tr>
</thead>
<tbody>
<?php if (count($orderList) === 0): ?>
<tr><td colspan="9"><div class="empty-state"><div class="empty-icon"><i class="fa fa-ticket"></i></div><div><?php echo $t['work_no_data']; ?></div></div></td>
<?php else: ?>
<?php foreach ($orderList as $item): ?>
<?php
$statusText = ''; $statusClass = '';
switch ($item['status']) {
case 1:$statusText=$t['status_1'];$statusClass='status-1';break;
case 2:$statusText=$t['status_2'];$statusClass='status-2';break;
case 3:$statusText=$t['status_3'];$statusClass='status-3';break;
case 4:$statusText=$t['status_4'];$statusClass='status-4';break;
}
?>
<tr data-id="<?php echo $item['id']; ?>"
data-title="<?php echo htmlspecialchars($item['title']); ?>"
data-content="<?php echo htmlspecialchars($item['content']); ?>"
data-assign="<?php echo $item['assign_uid']; ?>"
data-status="<?php echo $item['status']; ?>"
data-relate="<?php echo htmlspecialchars($item['relate_alert_id'] ?? ''); ?>"
data-notifyuser="<?php echo htmlspecialchars($item['notify_user'] ?? ''); ?>"
data-notifychannel="<?php echo htmlspecialchars($item['notify_channel'] ?? ''); ?>">
<td><?php echo $item['id']; ?></td>
<td><?php echo htmlspecialchars($item['relate_alert_id'] ?? '-'); ?></td>
<td><?php echo htmlspecialchars($item['title']); ?></td>
<td><?php echo $item['create_name'] ?? '-'; ?></td>
<td><?php echo $item['assign_name'] ?? '-'; ?></td>
<td><span class="status-tag <?php echo $statusClass; ?>"><?php echo $statusText; ?></span></td>
<td><?php echo $item['create_time']; ?></td>
<td><?php echo $item['update_time'] ?? '-'; ?></td>
<td style="display:flex;gap:6px;align-items:center;">
<?php if ($isAdmin === 1): ?>
<select class="assign-user select-sm">
<option value="">--</option>
<?php echo $userOptions; ?>
</select>
<?php endif; ?>
<select class="status-select select-sm">
<option value="1" <?php echo $item['status']==1?'selected':''; ?>><?php echo $t['status_1']; ?></option>
<option value="2" <?php echo $item['status']==2?'selected':''; ?>><?php echo $t['status_2']; ?></option>
<option value="3" <?php echo $item['status']==3?'selected':''; ?>><?php echo $t['status_3']; ?></option>
<option value="4" <?php echo $item['status']==4?'selected':''; ?>><?php echo $t['status_4']; ?></option>
</select>
<button class="btn-base btn-outline btn-sm edit-order"><i class="fa fa-edit"></i></button>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
<div class="page-pagination">
<div><?php echo $currentLang==='zh'?'共 ':'Total '; ?><?php echo $total; ?> <?php echo $currentLang==='zh'?'条':'records'; ?></div>
<div style="display:flex;gap:10px;align-items:center;">
<?php if ($page > 1): ?>
<button class="page-pag-btn" onclick="location.href='work_order.php?page=<?php echo $page-1; ?>'"><?php echo $currentLang==='zh'?'上一页':'Prev' ?></button>
<?php endif; ?>
<span><?php echo $currentLang==='zh'?'第':'Page '; ?><?php echo $page; ?> / <?php echo $totalPage; ?></span>
<?php if ($page < $totalPage): ?>
<button class="page-pag-btn" onclick="location.href='work_order.php?page=<?php echo $page+1; ?>'"><?php echo $currentLang==='zh'?'下一页':'Next' ?></button>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- 新建工单弹窗:告警下拉+通知人+多渠道 -->
<div class="modal-mask" id="createModal">
<div class="modal-box">
<div class="modal-head">
<h3 class="title-left"><i class="fa fa-plus"></i><?php echo $t['work_create']; ?></h3>
<span class="modal-close" id="closeCreateModal">×</span>
</div>
<div class="form-row">
<label><?php echo $t['relate_alert']; ?></label>
<select id="relateAlertSelect">
<option value="">-- <?php echo $t['no_alert_choose']; ?> --</option>
</select>
<div class="form-desc"><?php echo $currentLang==='zh'?'选择后自动填充工单标题与基础告警信息':'Auto fill title & alert info after select'; ?></div>
</div>
<div class="form-row">
<label><?php echo $t['work_title']; ?></label>
<input type="text" id="orderTitle" placeholder="<?php echo $t['work_placeholder_title']; ?>">
</div>
<div class="form-row">
<label><?php echo $t['work_content']; ?></label>
<textarea id="orderContent" placeholder="<?php echo $t['work_placeholder_content']; ?>"></textarea>
</div>
<div class="form-row">
<label><?php echo $t['work_handler']; ?></label>
<select id="orderAssign">
<option value=""><?php echo $t['work_select_handler']; ?></option>
<?php echo $userOptions; ?>
</select>
</div>
<!-- 通知配置区域 -->
<div style="margin:24px 0 8px;padding-top:16px;border-top:1px solid #eef2fb;">
<div class="title-left" style="font-size:16px;"><i class="fa fa-bell"></i><?php echo $t['notify_title']; ?></div>
</div>
<div class="form-row">
<label><?php echo $t['notify_user']; ?></label>
<select id="notifyUserSelect" multiple style="height:120px;">
<?php echo $userOptions; ?>
</select>
<div class="form-desc"><?php echo $currentLang==='zh'?'按住Ctrl多选通知人员':'Hold Ctrl multi-select users'; ?></div>
</div>
<div class="form-row">
<label><?php echo $t['notify_channel']; ?></label>
<div class="checkbox-group">
<div class="checkbox-item">
<input type="checkbox" id="chMail" value="mail">
<label for="chMail"><?php echo $t['channel_mail']; ?></label>
</div>
<div class="checkbox-item">
<input type="checkbox" id="chDing" value="dingtalk">
<label for="chDing"><?php echo $t['channel_ding']; ?></label>
</div>
<div class="checkbox-item">
<input type="checkbox" id="chWecom" value="wecom">
<label for="chWecom"><?php echo $t['channel_wecom']; ?></label>
</div>
</div>
</div>
<div class="btn-group">
<button class="btn-base btn-primary" id="submitOrder"><i class="fa fa-save"></i><?php echo $t['work_save']; ?></button>
<button class="btn-base btn-outline" id="resetForm"><?php echo $t['work_cancel']; ?></button>
</div>
</div>
</div>
<!-- 编辑工单弹窗 -->
<div class="modal-mask" id="editModal">
<div class="modal-box">
<div class="modal-head">
<h3 class="title-left"><i class="fa fa-edit"></i><?php echo $t['work_edit']; ?></h3>
<span class="modal-close" id="closeEditModal">×</span>
</div>
<input type="hidden" id="editOrderId">
<input type="hidden" id="editRelateAlertId">
<div class="form-row">
<label><?php echo $t['relate_alert']; ?></label>
<input type="text" id="editRelateAlertShow" readonly class="readonly-input">
</div>
<div class="form-row">
<label><?php echo $t['work_title']; ?></label>
<input type="text" id="editTitle">
</div>
<div class="form-row">
<label><?php echo $t['work_content']; ?></label>
<textarea id="editContent"></textarea>
</div>
<div class="form-row">
<label><?php echo $t['work_handler']; ?></label>
<select id="editAssign">
<option value="">--</option>
<?php echo $userOptions; ?>
</select>
</div>
<div style="margin:24px 0 8px;padding-top:16px;border-top:1px solid #eef2fb;">
<div class="title-left" style="font-size:16px;"><i class="fa fa-bell"></i><?php echo $t['notify_title']; ?></div>
</div>
<div class="form-row">
<label><?php echo $t['notify_user']; ?></label>
<select id="editNotifyUser" multiple style="height:120px;">
<?php echo $userOptions; ?>
</select>
</div>
<div class="form-row">
<label><?php echo $t['notify_channel']; ?></label>
<div class="checkbox-group">
<div class="checkbox-item"><input type="checkbox" id="editChMail" value="mail"><label for="editChMail"><?php echo $t['channel_mail']; ?></label></div>
<div class="checkbox-item"><input type="checkbox" id="editChDing" value="dingtalk"><label for="editChDing"><?php echo $t['channel_ding']; ?></label></div>
<div class="checkbox-item"><input type="checkbox" id="editChWecom" value="wecom"><label for="editChWecom"><?php echo $t['channel_wecom']; ?></label></div>
</div>
</div>
<div class="btn-group">
<button class="btn-base btn-primary" id="saveEdit"><i class="fa fa-save"></i><?php echo $t['work_save']; ?></button>
<button class="btn-base btn-outline" id="cancelEdit"><?php echo $t['work_cancel']; ?></button>
</div>
</div>
</div>
<script>
const apiOrder = "./api/work_order_api.php";
const loginUid = "<?php echo $loginUid; ?>";
const isAdmin = <?php echo $isAdmin; ?>;
const currentLang = "<?php echo $currentLang; ?>";
let activeAlertList = [];
// 语言切换
$("#langSwitch").change(function(){
const newLang = $(this).val();
fetch("./api/index.php",{
method:"POST",
headers:{"Content-Type":"application/x-www-form-urlencoded"},
body:"act=save_lang&lang="+newLang
}).then(()=>location.href = "work_order.php?_t="+new Date().getTime());
})
// 加载当前活跃告警填入下拉
function loadActiveAlert(){
$.getJSON(apiOrder+"?action=get_firing_alert",function(res){
const sel = $("#relateAlertSelect");
sel.html('<option value="">-- <?php echo $t['no_alert_choose']; ?> --</option>');
activeAlertList = res.list || [];
if(activeAlertList.length === 0) return;
activeAlertList.forEach(item=>{
sel.append(`<option value="${item.alert_id}" data-name="${item.alert_name}" data-ip="${item.instance}">[${item.alert_id}] ${item.alert_name} | ${item.instance}</option>`);
})
}).fail(()=>{
$("#relateAlertSelect").html(`<option value=""><?php echo $t['no_alert_data']; ?></option>`);
})
}
// 选中告警自动回填
$("#relateAlertSelect").change(function(){
const opt = $(this).find("option:selected");
const aid = opt.val();
const aname = opt.data("name") || "";
const ip = opt.data("ip") || "";
if(!aid){
$("#orderTitle").val("");
$("#orderContent").val("");
return;
}
const baseText = currentLang === "zh"
? `关联告警ID${aid}\n实例IP${ip}\n告警名称:${aname}\n=====处理备注=====\n`
: `Relate Alert ID: ${aid}\nInstance IP: ${ip}\nAlert Name: ${aname}\n=====Handling Remark=====\n`;
$("#orderTitle").val(aname);
$("#orderContent").val(baseText);
});
// 重置表单
$("#resetForm").click(function(){
$("#relateAlertSelect").val("");
$("#orderTitle").val("");
$("#orderContent").val("");
$("#orderAssign").val("");
$("#notifyUserSelect").val([]);
$("#chMail,#chDing,#chWecom").prop("checked",false);
});
$("#closeCreateModal").click(()=>$("#createModal").hide());
$("#closeEditModal,#cancelEdit").click(()=>$("#editModal").hide());
// 打开编辑回填
$(document).on("click",".edit-order",function(){
const tr = $(this).closest("tr");
$("#editOrderId").val(tr.data("id"));
$("#editTitle").val(tr.data("title"));
$("#editContent").val(tr.data("content"));
$("#editAssign").val(tr.data("assign"));
$("#editRelateAlertId").val(tr.data("relate"));
$("#editRelateAlertShow").val(tr.data("relate") || (currentLang==="zh"?"无关联告警":"No related alert"));
// 通知用户多选
const notifyUserRaw = tr.data("notifyuser") || "";
const notifyUserArr = notifyUserRaw.split(",").filter(x=>x);
$("#editNotifyUser").val(notifyUserArr);
// 渠道勾选
const channelRaw = tr.data("notifychannel") || "";
const chArr = channelRaw.split(",").filter(x=>x);
$("#editChMail").prop("checked", chArr.includes("mail"));
$("#editChDing").prop("checked", chArr.includes("dingtalk"));
$("#editChWecom").prop("checked", chArr.includes("wecom"));
$("#editModal").css("display","flex");
});
// 新建提交
$("#submitOrder").click(function(){
const title = $("#orderTitle").val().trim();
const content = $("#orderContent").val().trim();
const assign = $("#orderAssign").val();
const relateAlertId = $("#relateAlertSelect").val();
// 通知用户多选取值
const notifyUserArr = $("#notifyUserSelect").val() || [];
const notifyUser = notifyUserArr.join(",");
// 渠道
let channelArr = [];
if($("#chMail").prop("checked")) channelArr.push("mail");
if($("#chDing").prop("checked")) channelArr.push("dingtalk");
if($("#chWecom").prop("checked")) channelArr.push("wecom");
const notifyChannel = channelArr.join(",");
if(!title) return alert(currentLang==='zh'?"请填写工单标题":"Fill order title");
if(!content) return alert(currentLang==='zh'?"请填写工单内容":"Fill order content");
$.ajax({
url: apiOrder + "?action=create",
method: "POST",
contentType: "application/json",
data: JSON.stringify({title,content,assign_uid:assign,relate_alert_id:relateAlertId,notify_user:notifyUser,notify_channel:notifyChannel}),
dataType: "json",
success(res){
alert(res.msg);
if(res.code === 0) location.reload();
},
error(){alert(currentLang==='zh'?"提交失败,接口异常":"Submit failed, API error")}
})
});
// 编辑保存
$("#saveEdit").click(function(){
const id = $("#editOrderId").val();
const title = $("#editTitle").val().trim();
const content = $("#editContent").val().trim();
const assign = $("#editAssign").val();
const notifyUserArr = $("#editNotifyUser").val() || [];
const notifyUser = notifyUserArr.join(",");
let channelArr = [];
if($("#editChMail").prop("checked")) channelArr.push("mail");
if($("#editChDing").prop("checked")) channelArr.push("dingtalk");
if($("#editChWecom").prop("checked")) channelArr.push("wecom");
const notifyChannel = channelArr.join(",");
if(!title || !content) return alert(currentLang==='zh'?"标题和内容不能为空":"Title and content required");
$.ajax({
url: apiOrder + "?action=edit",
method: "POST",
contentType: "application/json",
data: JSON.stringify({id,title,content,assign_uid:assign,notify_user:notifyUser,notify_channel:notifyChannel}),
dataType: "json",
success(res){
alert(res.msg);
if(res.code === 0) location.reload();
},
error(){alert(currentLang==='zh'?"编辑保存失败":"Edit save failed")}
})
});
// 修改状态
$(document).on("change", ".status-select", function(){
const tr = $(this).closest("tr");
const id = tr.data("id");
const status = $(this).val();
$.ajax({
url: apiOrder + "?action=update_status",
method: "POST",
contentType: "application/json",
data: JSON.stringify({id,status}),
dataType: "json",
success(res){
if(res.code !== 0) alert(res.msg);
else location.reload();
}
})
});
// 管理员分发
$(document).on("change", ".assign-user", function(){
const tr = $(this).closest("tr");
const id = tr.data("id");
const assignUid = $(this).val();
$.ajax({
url: apiOrder + "?action=assign_order",
method: "POST",
contentType: "application/json",
data: JSON.stringify({id,assign_uid:assignUid}),
dataType: "json",
success(res){
if(res.code !== 0) alert(res.msg);
else location.reload();
}
})
});
// 顶部时间
function updateTime() {
const now = new Date();
const Y = now.getFullYear();
const M = String(now.getMonth() + 1).padStart(2, '0');
const D = String(now.getDate()).padStart(2, '0');
const h = String(now.getHours()).padStart(2, '0');
const m = String(now.getMinutes()).padStart(2, '0');
const s = String(now.getSeconds()).padStart(2, '0');
$("#updateTime").text(`${Y}-${M}-${D} ${h}:${m}:${s}`);
}
function loadAllData(){
updateTime();
loadActiveAlert();
}
$(function() {
loadAllData();
setInterval(updateTime, 1000);
$("#logoutBtn").click(function(){location.href="logout.php";})
});
</script>
</body>
</html>