Files
aler_dashboard_git/work_order.php.6.0
T
2026-07-09 16:31:30 +08:00

850 lines
39 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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");
// 兼容低PHP版本 替代str_contains
if (!function_exists('str_contains')) {
function str_contains($haystack, $needle) {
return $needle === '' || strpos($haystack, $needle) !== false;
}
}
$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);
if(!$connConfig){
die("配置库连接失败");
}
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 = [];
$smtpQuery = mysqli_query($connConfig, "SELECT * FROM sys_smtp_config WHERE id=1");
if($smtpQuery){
$smtpRow = mysqli_fetch_assoc($smtpQuery);
}
$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' => '工单标题',
'create_time' => '创建时间',
'update_time' => '更新时间',
'all_work_order' => '全部工单列表',
'no_work_data' => '暂无工单数据',
'save' => '保存',
'cancel' => '取消',
'title_placeholder' => '填写故障/需求标题',
'content_placeholder' => '详细描述故障现象、操作步骤、处理方案',
'select_handler' => '选择处理人(留空暂不分配)',
'status_1' => '待处理',
'status_2' => '处理中',
'status_3' => '已完成',
'status_4' => '已关闭',
'no_alert_option' => '不关联任何告警',
'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' => 'Disk Capacity',
'alert_list_page' => 'History Alert',
'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',
'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',
'create_time' => 'Create Time',
'update_time' => 'Update Time',
'all_work_order' => 'All Work Orders',
'no_work_data' => 'No work orders',
'save' => 'Save',
'cancel' => 'Cancel',
'title_placeholder' => 'Fill fault or demand title',
'content_placeholder' => 'Describe fault, steps and handling plan',
'select_handler' => 'Select handler (empty for unassigned)',
'status_1' => 'Pending',
'status_2' => 'Processing',
'status_3' => 'Finished',
'status_4' => 'Closed',
'no_alert_option' => '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 Email',
'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("工单数据库 monitor 连接失败");
}
mysqli_set_charset($connWork, "utf8mb4");
$loginUid = $_SESSION['user_id'];
// 获取当前用户角色权限
$isAdmin = 0;
$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);
if($stmtRole){
mysqli_stmt_bind_param($stmtRole, 's', $loginUid);
mysqli_stmt_execute($stmtRole);
$roleRow = mysqli_fetch_assoc(mysqli_stmt_get_result($stmtRole));
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($stmtCnt){
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);
}else{
$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);
$orderList = [];
if($stmtList){
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);
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:#0f2347;}
.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-spin{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;}
.panel-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;}
.panel-head{display:flex;justify-content:space-between;align-items:center;margin-bottom:26px;padding-bottom:16px;border-bottom:1px solid #eef2fb;}
.panel-title{display:flex;align-items:center;gap:12px;font-size:19px;font-weight:600;color:#152c5b;}
.panel-title i{color:#3b82f6;font-size:21px}
.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-tip{text-align:center;padding:80px 20px;color:#94a3b8;font-size:15px;}
.empty-tip i{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;}
.tag-pending{background:#ffedd5;color:#ea580c}
.tag-processing{background:#dbeafe;color:#2563eb}
.tag-finished{background:#dcfce7;color:#16a34a}
.tag-closed{background:#f1f5f9;color:#64748b}
.pagination{display:flex;justify-content:space-between;align-items:center;margin-top:20px;}
.page-btn{padding:8px 16px;border:1px solid #cbd5e1;background:#fff;border-radius:8px;cursor:pointer;font-size:14px;}
.page-btn:hover{background:#f7f8fc;border-color:#152c5b;}
.checkbox-wrap{display:flex;gap:16px;flex-wrap:wrap;padding:8px 0;}
.checkbox-item{display:flex;align-items:center;gap:6px;}
.input-readonly{background:#f7f8fc;color:#64748b;}
.divider-top{margin:24px 0 8px;padding-top:16px;border-top:1px solid #eef2fb;}
@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}
.panel-card{padding:24px}
}
</style>
</head>
<body>
<div class="mask" id="loadingMask">
<div class="mask-box"><span class="loading-spin"></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#disk'">
<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']); ?>','_blank')">
<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><span id="nowTime">--</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="location.reload()"><i class="fa fa-refresh"></i><?php echo $t['refresh_all']; ?></button>
<button class="btn-base btn-primary" onclick="location.href='logout.php'"><i class="fa fa-sign-out"></i><?php echo $t['logout']; ?></button>
</div>
</div>
<div class="container">
<div class="panel-card">
<div class="panel-head">
<div class="panel-title"><i class="fa fa-ticket"></i><?php echo $t['all_work_order']; ?></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-o"></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-o"></i><?php echo $t['create_time']; ?></th>
<th><i class="fa fa-clock-o"></i><?php echo $t['update_time']; ?></th>
<th>OP</th>
</tr>
</thead>
<tbody>
<?php if (count($orderList) === 0): ?>
<tr>
<td colspan="9">
<div class="empty-tip">
<i class="fa fa-ticket"></i>
<div><?php echo $t['no_work_data']; ?></div>
</div>
</td>
</tr>
<?php else: ?>
<?php foreach ($orderList as $item): ?>
<?php
$statusText = ''; $statusClass = '';
switch ($item['status']) {
case 1:$statusText=$t['status_1'];$statusClass='tag-pending';break;
case 2:$statusText=$t['status_2'];$statusClass='tag-processing';break;
case 3:$statusText=$t['status_3'];$statusClass='tag-finished';break;
case 4:$statusText=$t['status_4'];$statusClass='tag-closed';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><?php echo $t['work_edit']; ?></button>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
<div class="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-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-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 class="modal-mask" id="createModal">
<div class="modal-box">
<div class="modal-head">
<div class="panel-title"><i class="fa fa-plus"></i><?php echo $t['work_create']; ?></div>
<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_option']; ?> --</option>
</select>
<div class="form-desc"><?php echo $currentLang==='zh'?'选择后自动填充工单标题与告警基础信息':'Auto fill title and 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['title_placeholder']; ?>">
</div>
<div class="form-row">
<label><?php echo $t['work_content']; ?></label>
<textarea id="orderContent" placeholder="<?php echo $t['content_placeholder']; ?>"></textarea>
</div>
<div class="form-row">
<label><?php echo $t['work_handler']; ?></label>
<select id="orderAssign">
<option value=""><?php echo $t['select_handler']; ?></option>
<?php echo $userOptions; ?>
</select>
</div>
<div class="divider-top"></div>
<div class="panel-title" style="font-size:16px;margin-bottom:12px;"><i class="fa fa-bell"></i><?php echo $t['notify_title']; ?></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-wrap">
<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['save']; ?></button>
<button class="btn-base btn-outline" id="resetForm"><i class="fa fa-refresh"></i><?php echo $t['cancel']; ?></button>
</div>
</div>
</div>
<!-- 编辑工单弹窗 -->
<div class="modal-mask" id="editModal">
<div class="modal-box">
<div class="modal-head">
<div class="panel-title"><i class="fa fa-edit"></i><?php echo $t['work_edit']; ?></div>
<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="input-readonly">
</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 class="divider-top"></div>
<div class="panel-title" style="font-size:16px;margin-bottom:12px;"><i class="fa fa-bell"></i><?php echo $t['notify_title']; ?></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-wrap">
<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['save']; ?></button>
<button class="btn-base btn-outline" id="cancelEdit"><?php echo $t['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 = [];
// 更新顶部时间
function updateNowTime() {
const d = new Date();
const Y = d.getFullYear();
const M = String(d.getMonth()+1).padStart(2,'0');
const D = String(d.getDate()).padStart(2,'0');
const h = String(d.getHours()).padStart(2,'0');
const m = String(d.getMinutes()).padStart(2,'0');
const s = String(d.getSeconds()).padStart(2,'0');
$("#nowTime").text(`${Y}-${M}-${D} ${h}:${m}:${s}`);
}
setInterval(updateNowTime,1000);
updateNowTime();
// 语言切换
$("#langSwitch").change(function(){
const lang = $(this).val();
$.post("./api/index.php",{act:"set_lang",lang:lang},function(){
location.reload();
})
})
// 加载活跃告警下拉
function loadActiveAlert(){
$.getJSON(apiOrder+"?action=get_firing_alert",function(res){
const sel = $("#relateAlertSelect");
sel.html('<option value="">-- <?php echo $t['no_alert_option']; ?> --</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 tip = 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(tip);
});
// 弹窗开关
$("#openCreateModal").click(()=>$("#createModal").css("display","flex"));
$("#closeCreateModal,#resetForm").click(function(){
$("#relateAlertSelect").val("");
$("#orderTitle").val("");
$("#orderContent").val("");
$("#orderAssign").val("");
$("#notifyUserSelect").val([]);
$("#chMail,#chDing,#chWecom").prop("checked",false);
$("#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"));
const relateAid = tr.data("relate") || "";
$("#editRelateAlertId").val(relateAid);
$("#editRelateAlertShow").val(relateAid || (currentLang==="zh"?"无关联告警":"No related alert"));
// 通知用户多选
const userRaw = tr.data("notifyuser") || "";
const userArr = userRaw.split(",").filter(x=>x);
$("#editNotifyUser").val(userArr);
// 渠道勾选
const chRaw = tr.data("notifychannel") || "";
const chArr = chRaw.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'?"保存失败":"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){
alert(res.msg);
location.reload();
},
error(){
alert(currentLang==='zh'?"状态更新失败":"Status update failed");
}
})
});
// 管理员分发人员
$(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){
alert(res.msg);
location.reload();
},
error(){
alert(currentLang==='zh'?"分发失败":"Assign failed");
}
})
});
// 页面加载完成执行
$(function(){
loadActiveAlert();
})
</script>
</body>
</html>