').addClass('fullscreen-btn fullscreen-btn-right').html('>');
const $btnDownload = $('
').addClass('fullscreen-btn fullscreen-btn-download').html('⭳'); // 下载图标
$fullscreenMask.append($fullscreenImg, $btnLeft, $btnRight, $btnDownload);
// 将遮罩层添加到 body
$('body').append($fullscreenMask);
setTimeout(function () {
$fullscreenMask.addClass('active');
}, 10);
// 点击遮罩层时关闭
$fullscreenMask.on('click', function (e) {
if (!$(e.target).is($btnLeft) && !$(e.target).is($btnRight) && !$(e.target).is($btnDownload)) {
$fullscreenMask.removeClass('active');
setTimeout(function () {
$fullscreenMask.remove();
}, 300);
}
});
// 点击左按钮显示上一张图片
$btnLeft.on('click', function () {
currentImageIndex--;
if (currentImageIndex < 0) {
currentImageIndex = imageSrcArray.length - 1;
}
$fullscreenImg.attr('src', imageSrcArray[currentImageIndex]);
});
// 点击右按钮显示下一张图片
$btnRight.on('click', function () {
currentImageIndex++;
if (currentImageIndex >= imageSrcArray.length) {
currentImageIndex = 0;
}
$fullscreenImg.attr('src', imageSrcArray[currentImageIndex]);
});
// 点击下载按钮下载当前图片
$btnDownload.on('click', function (e) {
e.stopPropagation(); // 阻止事件冒泡
loadIndex = layer.load(2, { shade: [0.8, '#000'] });
$.ajax({
url: '/download-status',
method: 'GET',
dataType: 'json',
data: { reset: 1 },
success: function(response) {
const currentImageSrc = imageSrcArray[currentImageIndex];
// 下载图片 js urlencode
href_url = '/download-image?url='+encodeURIComponent(currentImageSrc);
window.location.href = href_url;
//延迟执行,等待下载完成
// setTimeout(function() {
// layer.close(loadIndex); // 关闭加载层
// }, 2000);
checkDownloadStatus();
}
});
});
});
// 放大图片 end
const $overlay = $('#overlay');
const $videoPlayer = $('#videoPlayer');
const $closeBtn = $('#closeBtn');
const $videoBtns = $('.video-btn');
// 点击播放按钮
$videoBtns.on('click', function() {
const videoSrc = $(this).data('src'); // 获取 data-src 属性
$videoPlayer.attr('src', videoSrc); // 设置视频源
$videoPlayer[0].autoplay = true; // 设置自动播放
$overlay.css('display', 'flex'); // 显示遮罩层
});
// 点击关闭按钮
$closeBtn.on('click', function() {
$videoPlayer[0].pause(); // 暂停视频
$videoPlayer.attr('src', ''); // 清空视频源
$overlay.hide(); // 隐藏遮罩层
});
// 点击遮罩层关闭
$overlay.on('click', function(event) {
if (event.target === $overlay[0]) { // 判断是否点击的是遮罩层本身
$videoPlayer[0].pause(); // 暂停视频
$videoPlayer.attr('src', ''); // 清空视频源
$overlay.hide(); // 隐藏遮罩层
}
});
// 为 .log-date 绑定点击事件
$('.log-date').on('click', function() {
// 找到当前 .log-date 的同级 .log-line 元素
$(this).siblings('.log-line').toggleClass('active');
});
//日志
// 检查 update-log 是否存在
if ($('.update-log').length > 0) {
// 定义一个函数来执行 AJAX 请求
function fetchUpdate() {
$.ajax({
url: '/next-log', // 替换为你的 API 端点
method: 'GET', // 根据你的需求选择 GET 或 POST
dataType: 'json', // 根据你的 API 返回的数据类型选择
success: function(response) {
// 假设 response 包含 timestamp 和 message
var created_at = response.data.created_at;
var action = response.data.action;
if (action == 'aa') {
action = '新增了';
} else {
action = '更新了';
}
var model = "
" + response.data.model + ' 的';
var content = response.data.content;
var user_name = response.data.user_name;
// 更新 timestamp 和 message
$('.update-log .update-time').text(created_at);
$('.update-log .user_name').text(user_name);
$('.update-log .action').text(action);
$('.update-log .model').html(model);
$('.update-log .log-content').text(content);
},
error: function(xhr, status, error) {
console.error('AJAX 请求失败:', status, error);
}
});
}
// 立即执行一次
fetchUpdate();
// 每 10 秒执行一次
setInterval(fetchUpdate, 20000); // 10000 毫秒 = 10 秒
}
var downdHref = function() {
// 查找 .album-tab 中带有 is-active 类的
标签
let activeTab = $('.album-tab a.is-active').attr('href');
// 将 #album- 替换为空,得到 tab 变量
let tab = activeTab.replace('#album-', '');
// 获取当前 URL 中的 id 参数
let currentUrl = window.location.href;
let urlParams = new URLSearchParams(currentUrl.split('?')[1]);
let id = urlParams.get('id');
// 拼接新的 URL
let newUrl = `/download-all?id=${id}&tab=${tab}&refresh=true`;
// 跳转到新 URL
window.location.href = newUrl;
}
//ajax 定时请求 /download-status,直到返回状态为 0 时
// 监听 .download-all 的点击事件
$('.download-all').on('click', function() {
loadIndex = layer.load(2, { shade: [0.8, '#000'] }); // 参数1表示加载样式,shade
//jquery 请求 /download-status
$.ajax({
url: '/download-status',
method: 'GET',
dataType: 'json',
data: { reset: 1 },
success: function(response) {
downdHref();
checkDownloadStatus();
}
});
});
$('.download-btn').on('click', function() {
loadIndex = layer.load(2, { shade: [0.8, '#000'] }); // 参数1表示加载样式,shade
//jquery 请求 /download-status
// window.location.href = $(this).attr('url');
//
setTimeout(function() {
layer.close(loadIndex); // 关闭加载层
}, 1500);
});
if ( window.innerWidth <= 768) {
hamburgerMenuWrap = $('.menu-wrap');
hamburgerMenuWrap.removeClass('menu-active');
$(".content").css("padding-left","0px");
}
$(".download-icon").on('click', function() {
loadIndex = layer.load(2, {shade: [0.8, '#000']});
const currentImageSrc = $(this).attr('data-src');
$.ajax({
url: '/download-status',
method: 'GET',
dataType: 'json',
data: {reset: 1},
success: function (response) {
// 下载图片 js urlencode
href_url = '/download-image?url=' + encodeURIComponent(currentImageSrc);
window.location.href = href_url;
checkDownloadStatus();
}
});
});
});
function changeIframeSrc(url) {
// 获取 iframe 元素
const iframe = document.getElementById('myFrame');
// 改变 iframe 的 src 属性
iframe.src = url;
if ( window.innerWidth <= 768) {
hamburgerMenuWrap = $('.menu-wrap');
hamburgerMenuWrap.removeClass('menu-active');
$(".content").css("padding-left","0px");
}
}
function logout() {
layer.confirm('是否确定退出登录?', {
btn: ['确定', '关闭'] //按钮
}, function(){
window.top.location.href = "/logout";
}, function(){
layer.close();
});
}