[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>
- /* 基础样式优化:统一间距、增强可读性 */
- body {
- font-family: 'Microsoft YaHei', Arial, sans-serif; /* 适配中文字体 */
- line-height: 1.8;
- margin: 0;
- padding: 20px;
- background-color: #f8f9fa;
- color: #333;
- user-select: none; /* 保留禁止文本选择,但仅作为基础体验优化 */
- -webkit-user-select: none;
- -moz-user-select: none;
- -ms-user-select: none;
- }
- /* 标题样式优化:增加底部边框分隔 */
- h1 {
- color: #0056b3;
- text-align: center;
- margin: 0 0 30px;
- padding-bottom: 15px;
- border-bottom: 2px solid #e9ecef;
- }
- .container {
- max-width: 1200px; /* 限制最大宽度,避免大屏下内容过宽 */
- margin: 0 auto;
- }
- /* 输入区域优化:增加内边距、优化按钮布局 */
- .input-container {
- background: #fff;
- padding: 25px;
- border-radius: 8px;
- box-shadow: 0 2px 8px rgba(0,0,0,0.08); /* 弱化阴影,更显清爽 */
- margin-bottom: 25px;
- display: flex;
- flex-wrap: wrap; /* 支持换行,适配小屏幕 */
- gap: 10px; /* 统一元素间距 */
- align-items: center;
- }
- label {
- display: block;
- margin-bottom: 5px;
- font-weight: 600;
- color: #495057;
- }
- .input-group {
- flex: 1; /* 让输入框占满剩余空间 */
- min-width: 200px; /* 小屏幕下输入框最小宽度 */
- }
- input[type="text"] {
- width: 100%; /* 改为100%,通过父容器控制宽度 */
- padding: 10px 12px;
- border: 1px solid #ced4da;
- border-radius: 4px;
- font-size: 14px;
- transition: border-color 0.3s; /* 增加边框过渡效果 */
- }
- input[type="text"]:focus {
- outline: none;
- border-color: #80bdff; /* 聚焦时边框变色,提升交互感 */
- box-shadow: 0 0 0 3px rgba(0,123,255,0.1);
- }
- /* 按钮样式统一:增加不同状态颜色 */
- button {
- padding: 10px 20px;
- border: none;
- border-radius: 4px;
- cursor: pointer;
- font-size: 14px;
- transition: background-color 0.3s;
- }
- .btn-find {
- background-color: #007bff;
- color: white;
- }
- .btn-find:hover {
- background-color: #0056b3;
- }
- .btn-clear {
- background-color: #6c757d;
- color: white;
- }
- .btn-clear:hover {
- background-color: #5a6268;
- }
- .btn-play {
- background-color: #28a745;
- color: white;
- }
- .btn-play:hover {
- background-color: #218838;
- }
- /* 视频列表优化:增加hover效果,统一间距 */
- #video-list {
- list-style-type: none;
- padding: 0;
- margin: 0 0 30px;
- }
- #video-list li {
- display: flex;
- align-items: center;
- justify-content: space-between;
- background: #fff;
- margin-top: 10px;
- padding: 12px 15px;
- border: 1px solid #e9ecef;
- border-radius: 4px;
- transition: background-color 0.3s;
- }
- #video-list li:hover {
- background-color: #f8f9fa; /* hover时背景变色,提升交互感 */
- }
- /* 视频播放器优化:固定比例,避免拉伸 */
- .video-wrapper {
- position: relative;
- width: 100%;
- padding-top: 56.25%; /* 16:9比例(高度/宽度=9/16=0.5625) */
- background: #000;
- border-radius: 4px;
- overflow: hidden;
- }
- #video-player {
- position: absolute;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
- }
- /* 响应式优化:小屏幕下输入区域垂直排列 */
- [url=home.php?mod=space&uid=945662]@media[/url] (max-width: 768px) {
- .input-container {
- flex-direction: column;
- align-items: stretch; /* 子元素占满宽度 */
- padding: 15px;
- }
- .input-group {
- width: 100%;
- margin-bottom: 10px;
- }
- /* 小屏幕下按钮独占一行,宽度100% */
- .btn-group {
- width: 100%;
- display: flex;
- gap: 10px;
- }
- button {
- flex: 1; /* 按钮平分宽度 */
- }
- }
- /* 提示文本样式 */
- .tip-text {
- font-size: 12px;
- color: #6c757d;
- margin-top: 5px;
- }
- /* 错误提示样式 */
- .error-text {
- color: #dc3545;
- font-size: 14px;
- margin-top: 10px;
- text-align: center;
- display: none; /* 默认隐藏 */
- }
- </style>
- </head>
- <body>
- <div class="container">
- <h1>河口监控落实工具</h1>
-
- <div class="input-container">
- <div class="input-group">
- <label for="video-input">请输入监控代码(省略.mp4):</label>
- <input type="text" id="video-input" placeholder="例如:021101,021102,021103">
- <div class="tip-text">支持多个代码,用英文逗号分隔;仅支持.mp4格式视频</div>
- </div>
- <div class="btn-group">
- <button class="btn-find" id="find-btn">查找</button>
- <button class="btn-clear" id="clear-btn">清空列表</button>
- </div>
- </div>
- <!-- 错误提示区域 -->
- <div class="error-text" id="error-text"></div>
- <!-- 视频列表 -->
- <ul id="video-list"></ul>
- <!-- 视频播放器(用容器固定比例) -->
- <div class="video-wrapper">
- <video id="video-player" controls preload="none">
- <!-- preload="none":默认不加载视频,优化性能 -->
- 您的浏览器不支持HTML5视频播放,请升级浏览器后重试。
- </video>
- </div>
- </div>
- <script>
- // 核心变量:存储视频列表项、错误提示元素
- const videoList = document.getElementById('video-list');
- const videoPlayer = document.getElementById('video-player');
- const videoInput = document.getElementById('video-input');
- const findBtn = document.getElementById('find-btn');
- const clearBtn = document.getElementById('clear-btn');
- const errorText = document.getElementById('error-text');
- let videoListItems = []; // 存储已添加的列表项,用于清空
- // 1. 添加视频到列表(增加合法性校验)
- function addVideoToList(fileName) {
- // 校验文件名:仅允许数字(监控代码通常为数字)
- const reg = /^[0-9]+$/;
- if (!reg.test(fileName)) {
- showError(`监控代码“${fileName}”无效,仅支持数字!`);
- return;
- }
- // 创建列表项
- const listItem = document.createElement('li');
- listItem.textContent = `${fileName}.mp4`;
- // 创建播放按钮
- const playButton = document.createElement('button');
- playButton.className = 'btn-play';
- playButton.textContent = '播放';
- playButton.addEventListener('click', () => {
- // 隐藏错误提示
- hideError();
- // 设置视频路径并播放(增加加载失败处理)
- const videoUrl = `videos/${fileName}.mp4`;
- videoPlayer.src = videoUrl;
- videoPlayer.load();
-
- // 监听视频加载失败事件
- videoPlayer.onerror = function() {
- showError(`视频“${fileName}.mp4”加载失败,请检查代码是否正确!`);
- videoPlayer.src = ''; // 清空无效路径
- };
- videoPlayer.play().catch(err => {
- // 处理自动播放失败(部分浏览器禁止自动播放)
- showError('视频自动播放失败,请点击播放器的“播放”按钮重试!');
- });
- });
- listItem.appendChild(playButton);
- videoList.appendChild(listItem);
- videoListItems.push(listItem);
- }
- // 2. 批量添加视频(处理输入框内容)
- function addVideos() {
- // 清空现有列表和错误提示
- clearVideoList();
- hideError();
- // 获取并处理输入内容(去重、去空)
- const input = videoInput.value.trim();
- if (!input) {
- showError('请输入监控代码后再点击查找!');
- return;
- }
- // 分割输入(支持英文逗号,处理可能的空格)
- let fileNames = input.split(',').map(name => name.trim());
- // 去重(避免重复添加同一视频)
- fileNames = [...new Set(fileNames)].filter(name => name);
- if (fileNames.length === 0) {
- showError('请输入有效的监控代码(多个代码用英文逗号分隔)!');
- return;
- }
- // 批量添加视频
- fileNames.forEach(fileName => addVideoToList(fileName));
- }
- // 3. 清空视频列表
- function clearVideoList() {
- videoListItems.forEach(item => videoList.removeChild(item));
- videoListItems = [];
- // 停止视频播放并清空路径
- videoPlayer.pause();
- videoPlayer.src = '';
- hideError();
- }
- // 4. 显示错误提示
- function showError(msg) {
- errorText.textContent = msg;
- errorText.style.display = 'block';
- }
- // 5. 隐藏错误提示
- function hideError() {
- errorText.style.display = 'none';
- }
- // 6. 绑定按钮事件(核心修复:原程序缺少这一步)
- findBtn.addEventListener('click', addVideos);
- clearBtn.addEventListener('click', clearVideoList);
- // 7. 支持回车键触发查找(提升操作体验)
- videoInput.addEventListener('keydown', (e) => {
- if (e.key === 'Enter') {
- addVideos();
- }
- });
- // 说明:原程序的“禁止右键/F12”逻辑已移除,原因如下:
- // 1. 无法真正阻止专业用户查看源码(浏览器调试模式可绕过)
- // 2. 影响正常用户操作(如右键复制文本、刷新页面)
- // 3. 若需保护视频,应通过后端权限控制(如签名URL、时效验证),而非前端隐藏
- </script>
- </body>
- </html>
复制代码
帮你修改正了下,就可以了 |