script.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. $(document).ready(function() {
  2. var loadIndex = null;
  3. new WOW({
  4. mobile: false,
  5. animateClass: 'animate__animated',
  6. }).init();
  7. setTimeout(function() {
  8. $('.prelodaer-wrap').fadeOut('slow');
  9. }, 4500);
  10. //Ajax Form Send START
  11. $('#contact-form').on('submit', function() {
  12. var th = $(this);
  13. $.ajax({
  14. type: 'POST',
  15. url: 'mail.php',
  16. data: th.serialize(),
  17. success: function() {
  18. th.trigger('reset');
  19. $('.input-field').removeClass('is-active');
  20. $.magnificPopup.open({
  21. items: {
  22. src: '<div class="form-alert"><p>Your application has been successfully sent. <br> Expect a call!</p></div>',
  23. type: 'inline'
  24. }
  25. });
  26. },
  27. error: function() {
  28. th.trigger('reset');
  29. $('.input-field').removeClass('is-active');
  30. $.magnificPopup.open({
  31. items: {
  32. src: '<div class="form-alert"><p>An error occurred, please try again</p></div>',
  33. type: 'inline'
  34. }
  35. });
  36. }
  37. });
  38. return false;
  39. });
  40. //Ajax Form Send END
  41. // Banner START
  42. const swiperBanner = new Swiper('.swiper-banner', {
  43. speed: 800,
  44. spaceBetween: 100,
  45. effect: 'fade',
  46. fadeEffect: {
  47. crossFade: true
  48. },
  49. navigation: {
  50. nextEl: '.swiper-banner .swiper-button-next',
  51. prevEl: '.swiper-banner .swiper-button-prev',
  52. },
  53. scrollbar: {
  54. el: '.swiper-banner .swiper-scrollbar',
  55. enabled: true,
  56. draggable: true
  57. },
  58. });
  59. // Banner END
  60. // Menu START
  61. $('body').on('click', '.hamburger-button', function(e) {
  62. e.preventDefault();
  63. hamburger_click = 1;
  64. hamburgerButton = $('.hamburger-button');
  65. hamburgerMenuWrap = $('.menu-wrap');
  66. hamburgerMenuItem = $('.menu-nav');
  67. hamburgerMenuWrap.addClass('menu-active');
  68. hamburgerMenuItem.addClass('menu-item-active');
  69. menuOverlay = $('.menu-overlay');
  70. if ( window.innerWidth <= 768) {
  71. $(".content").css("padding-left","257px");
  72. } else {
  73. $(".content").css("padding-left","264px");
  74. }
  75. });
  76. /*
  77. $('.menu-close__wrap').on('mouseup', function(e) {
  78. e.preventDefault();
  79. menuClose = $('.menu-close');
  80. hamburgerMenuWrap = $('.menu-wrap');
  81. hamburgerMenuItem = $('.menu-nav');
  82. menuOverlay = $('.menu-overlay');
  83. if (!hamburgerMenuWrap.is(e.target) && hamburgerMenuWrap.has(e.target).length === 0) {
  84. hamburgerMenuWrap.removeClass('menu-active');
  85. hamburgerMenuItem.removeClass('menu-item-active');
  86. menuOverlay.removeClass('menu-overlay__active');
  87. }
  88. menuClose.on('mousedown', function() {
  89. hamburgerMenuWrap.removeClass('menu-active');
  90. hamburgerMenuItem.removeClass('menu-item-active');
  91. menuOverlay.removeClass('menu-overlay__active');
  92. });
  93. $(".content").css("padding-left","80px");
  94. });
  95. */
  96. $('.menu-close__wrap').on('click', function(e) {
  97. e.preventDefault();
  98. menuClose = $('.menu-close');
  99. hamburgerMenuWrap = $('.menu-wrap');
  100. hamburgerMenuItem = $('.menu-nav');
  101. menuOverlay = $('.menu-overlay');
  102. hamburgerMenuWrap.removeClass('menu-active');
  103. hamburgerMenuItem.removeClass('menu-item-active');
  104. menuOverlay.removeClass('menu-overlay__active');
  105. if ( window.innerWidth <= 768) {
  106. $(".content").css("padding-left","0px");
  107. } else {
  108. $(".content").css("padding-left","80px");
  109. }
  110. });
  111. // Menu END
  112. // Contact START
  113. $('.input-field input, textarea').on('input', function() {
  114. var inputValue = $(this).val();
  115. var inputpParent = $(this).parent('.input-field');
  116. if (inputValue.length > 0) {
  117. inputpParent.addClass('is-active');
  118. } else {
  119. inputpParent.removeClass('is-active');
  120. }
  121. });
  122. // Contact END
  123. // Gallery Single page START
  124. $('.grid-single .grid-item img').parazoom({
  125. customCursorIcon: 'images/magnify.svg',
  126. customCursorSize: '30px',
  127. transitionTime: '1s',
  128. transitionTimeLeave: '1s'
  129. });
  130. var $grid = $('.grid-single').masonry({
  131. itemSelector: '.grid-single .grid-item',
  132. percentPosition: true,
  133. columnWidth: '.grid-single .grid-sizer'
  134. });
  135. $grid.imagesLoaded().progress( function() {
  136. $grid.masonry({
  137. gutter: 15
  138. });
  139. });
  140. $('.grid-single .grid-item a').magnificPopup({
  141. type:'image',
  142. removalDelay: 500,
  143. gallery: {
  144. enabled: true
  145. },
  146. callbacks: {
  147. beforeOpen: function() {
  148. this.st.image.markup = this.st.image.markup.replace('mfp-figure', 'mfp-figure mfp-with-anim');
  149. this.st.mainClass = this.st.el.attr('data-effect');
  150. }
  151. },
  152. });
  153. // Gallery Single page END
  154. // Album page START
  155. function albumMasonry() {
  156. var $gridAlbum = $('.grid-album').masonry({
  157. itemSelector: '.grid-album .grid-item',
  158. percentPosition: true,
  159. columnWidth: '.grid-album .grid-sizer'
  160. });
  161. $gridAlbum.imagesLoaded().progress( function() {
  162. console.log('innerWidth ....'+window.innerWidth);
  163. if ( window.innerWidth <= 575) {
  164. $gridAlbum.masonry({
  165. gutter: 50
  166. });
  167. return;
  168. } else if ( window.innerWidth <= 768) {
  169. $gridAlbum.masonry({
  170. gutter: 38
  171. });
  172. return;
  173. } else if ( window.innerWidth <= 992) {
  174. $gridAlbum.masonry({
  175. gutter: 35
  176. });
  177. return;
  178. } else if ( window.innerWidth <= 1656) {
  179. $gridAlbum.masonry({
  180. gutter: 35
  181. });
  182. return;
  183. }else {
  184. $gridAlbum.masonry({
  185. gutter: 40
  186. });
  187. return;
  188. }
  189. });
  190. }
  191. albumMasonry();
  192. var bLazy = new Blazy();
  193. $('.album-tab a').on('click', function(e) {
  194. e.preventDefault();
  195. var href = $(this).attr('href');
  196. $('.album-tab a').removeClass('is-active');
  197. $(this).addClass('is-active');
  198. $('.grid-album').removeClass('is-active');
  199. $(href).addClass('is-active');
  200. $(href).addClass('animate__animated animate__slideInUp');
  201. $('.grid-album.is-active:not(' + href + ')').removeClass('animate__animated animate__slideInUp');
  202. albumMasonry();
  203. let column = $(this).attr('column');
  204. if (column == 'pdf' || column == 'video') {
  205. $(".download-all").hide();
  206. } else {
  207. $(".download-all").show();
  208. }
  209. });
  210. // Album page END
  211. // Settings START
  212. $('.settings-btn').on('click', function() {
  213. var settings = $('.settings-wrap');
  214. settings.toggleClass('is-active');
  215. });
  216. var savedColor = localStorage.getItem('boxColor');
  217. if (savedColor) {
  218. $(':root').css('--color-def', savedColor);
  219. }
  220. $('.settings-color-item').on('click', function() {
  221. var color = $(this).css('background-color');
  222. $('.settings-color-item').css('border-color', '#fff');
  223. $(this).css('border-color', color);
  224. $(':root').css('--color-def', color);
  225. localStorage.setItem('boxColor', color);
  226. });
  227. // Settings END
  228. // $('.menu-nav-item').first().click(function () {
  229. // console.log('first11');
  230. // $(this).parent().find('.menu-nav-son').stop(true, true).slideToggle(200);
  231. // });
  232. $('.menu-nav-item').each(function() {
  233. var firstLink = $(this).find('a').first();
  234. firstLink.on('click', function(event) {
  235. event.preventDefault(); // 阻止默认行为(如跳转)
  236. $(this).parent().find('.menu-nav-son').stop(true, true).slideToggle(200);
  237. });
  238. });
  239. // $('.menu-nav-son-li').hover(
  240. // function () {
  241. // // 显示当前 li 的子菜单
  242. // $(this).find('.menu-nav-son2').stop(true, true).slideDown(200);
  243. // }
  244. // );
  245. //
  246. // // 当鼠标离开 .menu-nav ul 时
  247. // $('.menu-nav-son-li').mouseleave(function () {
  248. // // 隐藏所有子菜单
  249. // $('.menu-nav-son2').stop(true, true).slideUp(0);
  250. // });
  251. var checkDownloadStatus = function() {
  252. var intervalId = setInterval(function() {
  253. console.log('checkDownloadStatus ....');
  254. $.ajax({
  255. url: '/download-status',
  256. method: 'GET',
  257. dataType: 'json',
  258. data: { reset: 0 },
  259. success: function(response) {
  260. console.log(response);
  261. if (response.status == "2") {
  262. console.log('clean');
  263. clearInterval(intervalId);
  264. layer.close(loadIndex); // 关闭加载层
  265. }
  266. }
  267. });
  268. }, 1000); // 每秒请求一次
  269. }
  270. // 放大图片 start
  271. // 创建全屏遮罩层
  272. $('.album-thumb-detail').on('click', function (event) {
  273. // 如果点击的是 download-icon,阻止后续代码执行
  274. if ($(event.target).closest('.download-icon').length) {
  275. return;
  276. }
  277. // 获取当前点击的 .album-thumb-detail 的父级 .grid-album 元素
  278. var $parentAlbum = $(this).closest('.grid-album');
  279. // 获取当前父级下所有 .album-thumb-detail img 的 src
  280. var imageSrcArray = [];
  281. $parentAlbum.find('.album-thumb-detail img').each(function () {
  282. src = $(this).attr('data-src');
  283. // newSrc = src.split('?')[0];
  284. imageSrcArray.push(src);
  285. });
  286. // 获取当前点击图片在数组中的索引
  287. var $albumThumbs = $parentAlbum.find('.album-thumb-detail');
  288. var currentImageIndex = $albumThumbs.index(this);
  289. // console.log(currentImageIndex);
  290. const $fullscreenMask = $('<div>').addClass('fullscreen-mask');
  291. const $fullscreenImg = $('<img>').attr('src', imageSrcArray[currentImageIndex]);
  292. const $btnLeft = $('<div>').addClass('fullscreen-btn fullscreen-btn-left').html('&lt;');
  293. const $btnRight = $('<div>').addClass('fullscreen-btn fullscreen-btn-right').html('&gt;');
  294. const $btnDownload = $('<div>').addClass('fullscreen-btn fullscreen-btn-download').html('&#11123;'); // 下载图标
  295. $fullscreenMask.append($fullscreenImg, $btnLeft, $btnRight, $btnDownload);
  296. // 将遮罩层添加到 body
  297. $('body').append($fullscreenMask);
  298. setTimeout(function () {
  299. $fullscreenMask.addClass('active');
  300. }, 10);
  301. // 点击遮罩层时关闭
  302. $fullscreenMask.on('click', function (e) {
  303. if (!$(e.target).is($btnLeft) && !$(e.target).is($btnRight) && !$(e.target).is($btnDownload)) {
  304. $fullscreenMask.removeClass('active');
  305. setTimeout(function () {
  306. $fullscreenMask.remove();
  307. }, 300);
  308. }
  309. });
  310. // 点击左按钮显示上一张图片
  311. $btnLeft.on('click', function () {
  312. currentImageIndex--;
  313. if (currentImageIndex < 0) {
  314. currentImageIndex = imageSrcArray.length - 1;
  315. }
  316. $fullscreenImg.attr('src', imageSrcArray[currentImageIndex]);
  317. });
  318. // 点击右按钮显示下一张图片
  319. $btnRight.on('click', function () {
  320. currentImageIndex++;
  321. if (currentImageIndex >= imageSrcArray.length) {
  322. currentImageIndex = 0;
  323. }
  324. $fullscreenImg.attr('src', imageSrcArray[currentImageIndex]);
  325. });
  326. // 点击下载按钮下载当前图片
  327. $btnDownload.on('click', function (e) {
  328. e.stopPropagation(); // 阻止事件冒泡
  329. loadIndex = layer.load(2, { shade: [0.8, '#000'] });
  330. $.ajax({
  331. url: '/download-status',
  332. method: 'GET',
  333. dataType: 'json',
  334. data: { reset: 1 },
  335. success: function(response) {
  336. const currentImageSrc = imageSrcArray[currentImageIndex];
  337. // 下载图片 js urlencode
  338. href_url = '/download-image?url='+encodeURIComponent(currentImageSrc);
  339. window.location.href = href_url;
  340. checkDownloadStatus();
  341. }
  342. });
  343. });
  344. });
  345. // 放大图片 end
  346. const $overlay = $('#overlay');
  347. const $videoPlayer = $('#videoPlayer');
  348. const $closeBtn = $('#closeBtn');
  349. const $videoBtns = $('.video-btn');
  350. // 点击播放按钮
  351. $videoBtns.on('click', function() {
  352. const videoSrc = $(this).data('src'); // 获取 data-src 属性
  353. $videoPlayer.attr('src', videoSrc); // 设置视频源
  354. $videoPlayer[0].autoplay = true; // 设置自动播放
  355. $overlay.css('display', 'flex'); // 显示遮罩层
  356. });
  357. // 点击关闭按钮
  358. $closeBtn.on('click', function() {
  359. $videoPlayer[0].pause(); // 暂停视频
  360. $videoPlayer.attr('src', ''); // 清空视频源
  361. $overlay.hide(); // 隐藏遮罩层
  362. });
  363. // 点击遮罩层关闭
  364. $overlay.on('click', function(event) {
  365. if (event.target === $overlay[0]) { // 判断是否点击的是遮罩层本身
  366. $videoPlayer[0].pause(); // 暂停视频
  367. $videoPlayer.attr('src', ''); // 清空视频源
  368. $overlay.hide(); // 隐藏遮罩层
  369. }
  370. });
  371. // 为 .log-date 绑定点击事件
  372. $('.log-date').on('click', function() {
  373. // 找到当前 .log-date 的同级 .log-line 元素
  374. $(this).siblings('.log-line').toggleClass('active');
  375. });
  376. //日志
  377. // 检查 update-log 是否存在
  378. if ($('.update-log').length > 0) {
  379. // 定义一个函数来执行 AJAX 请求
  380. function fetchUpdate() {
  381. $.ajax({
  382. url: '/next-log', // 替换为你的 API 端点
  383. method: 'GET', // 根据你的需求选择 GET 或 POST
  384. dataType: 'json', // 根据你的 API 返回的数据类型选择
  385. success: function(response) {
  386. // 假设 response 包含 timestamp 和 message
  387. var created_at = response.data.created_at;
  388. var action = response.data.action;
  389. if (action == 'aa') {
  390. action = '新增了';
  391. } else {
  392. action = '更新了';
  393. }
  394. var model = "<a href='/detail?id="+response.data.content_id+"'>" + response.data.model + '</a> 的';
  395. var content = response.data.content;
  396. var user_name = response.data.user_name;
  397. // 更新 timestamp 和 message
  398. $('.update-log .update-time').text(created_at);
  399. $('.update-log .user_name').text(user_name);
  400. $('.update-log .action').text(action);
  401. $('.update-log .model').html(model);
  402. $('.update-log .log-content').text(content);
  403. },
  404. error: function(xhr, status, error) {
  405. console.error('AJAX 请求失败:', status, error);
  406. }
  407. });
  408. }
  409. // 立即执行一次
  410. fetchUpdate();
  411. // 每 10 秒执行一次
  412. setInterval(fetchUpdate, 20000); // 10000 毫秒 = 10 秒
  413. }
  414. var downdHref = function() {
  415. // 查找 .album-tab 中带有 is-active 类的 <a> 标签
  416. let activeTab = $('.album-tab a.is-active').attr('href');
  417. // 将 #album- 替换为空,得到 tab 变量
  418. let tab = activeTab.replace('#album-', '');
  419. // 获取当前 URL 中的 id 参数
  420. let currentUrl = window.location.href;
  421. let urlParams = new URLSearchParams(currentUrl.split('?')[1]);
  422. let id = urlParams.get('id');
  423. // 拼接新的 URL
  424. let newUrl = `/download-all?id=${id}&tab=${tab}&refresh=true`;
  425. // 跳转到新 URL
  426. window.location.href = newUrl;
  427. }
  428. //ajax 定时请求 /download-status,直到返回状态为 0 时
  429. // 监听 .download-all 的点击事件
  430. $('.download-all').on('click', function() {
  431. loadIndex = layer.load(2, { shade: [0.8, '#000'] }); // 参数1表示加载样式,shade
  432. //jquery 请求 /download-status
  433. $.ajax({
  434. url: '/download-status',
  435. method: 'GET',
  436. dataType: 'json',
  437. data: { reset: 1 },
  438. success: function(response) {
  439. downdHref();
  440. checkDownloadStatus();
  441. }
  442. });
  443. });
  444. if ( window.innerWidth <= 768) {
  445. hamburgerMenuWrap = $('.menu-wrap');
  446. hamburgerMenuWrap.removeClass('menu-active');
  447. $(".content").css("padding-left","0px");
  448. }
  449. });
  450. function changeIframeSrc(url) {
  451. // 获取 iframe 元素
  452. const iframe = document.getElementById('myFrame');
  453. // 改变 iframe 的 src 属性
  454. iframe.src = url;
  455. if ( window.innerWidth <= 768) {
  456. hamburgerMenuWrap = $('.menu-wrap');
  457. hamburgerMenuWrap.removeClass('menu-active');
  458. $(".content").css("padding-left","0px");
  459. }
  460. }
  461. function logout() {
  462. layer.confirm('是否确定退出登录?', {
  463. btn: ['确定', '关闭'] //按钮
  464. }, function(){
  465. window.top.location.href = "/logout";
  466. }, function(){
  467. layer.close();
  468. });
  469. }