script.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  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. if ( window.innerWidth <= 575) {
  163. $gridAlbum.masonry({
  164. gutter: 38
  165. });
  166. return;
  167. } else if ( window.innerWidth <= 768) {
  168. $gridAlbum.masonry({
  169. gutter: 38
  170. });
  171. return;
  172. } else if ( window.innerWidth <= 992) {
  173. $gridAlbum.masonry({
  174. gutter: 35
  175. });
  176. return;
  177. } else if ( window.innerWidth <= 1656) {
  178. $gridAlbum.masonry({
  179. gutter: 35
  180. });
  181. return;
  182. }else {
  183. $gridAlbum.masonry({
  184. gutter: 40
  185. });
  186. return;
  187. }
  188. });
  189. }
  190. albumMasonry();
  191. var bLazy = new Blazy();
  192. $('.album-tab a').on('click', function(e) {
  193. e.preventDefault();
  194. var href = $(this).attr('href');
  195. $('.album-tab a').removeClass('is-active');
  196. $(this).addClass('is-active');
  197. $('.grid-album').removeClass('is-active');
  198. $(href).addClass('is-active');
  199. $(href).addClass('animate__animated animate__slideInUp');
  200. $('.grid-album.is-active:not(' + href + ')').removeClass('animate__animated animate__slideInUp');
  201. albumMasonry();
  202. let column = $(this).attr('column');
  203. if (column == 'pdf' || column == 'video') {
  204. $(".download-all").hide();
  205. } else {
  206. $(".download-all").show();
  207. }
  208. });
  209. // Album page END
  210. // Settings START
  211. $('.settings-btn').on('click', function() {
  212. var settings = $('.settings-wrap');
  213. settings.toggleClass('is-active');
  214. });
  215. var savedColor = localStorage.getItem('boxColor');
  216. if (savedColor) {
  217. $(':root').css('--color-def', savedColor);
  218. }
  219. $('.settings-color-item').on('click', function() {
  220. var color = $(this).css('background-color');
  221. $('.settings-color-item').css('border-color', '#fff');
  222. $(this).css('border-color', color);
  223. $(':root').css('--color-def', color);
  224. localStorage.setItem('boxColor', color);
  225. });
  226. // Settings END
  227. // $('.menu-nav-item').first().click(function () {
  228. // console.log('first11');
  229. // $(this).parent().find('.menu-nav-son').stop(true, true).slideToggle(200);
  230. // });
  231. $('.menu-nav-item').each(function() {
  232. var firstLink = $(this).find('a').first();
  233. firstLink.on('click', function(event) {
  234. event.preventDefault(); // 阻止默认行为(如跳转)
  235. $(this).parent().find('.menu-nav-son').stop(true, true).slideToggle(200);
  236. });
  237. });
  238. // $('.menu-nav-son-li').hover(
  239. // function () {
  240. // // 显示当前 li 的子菜单
  241. // $(this).find('.menu-nav-son2').stop(true, true).slideDown(200);
  242. // }
  243. // );
  244. //
  245. // // 当鼠标离开 .menu-nav ul 时
  246. // $('.menu-nav-son-li').mouseleave(function () {
  247. // // 隐藏所有子菜单
  248. // $('.menu-nav-son2').stop(true, true).slideUp(0);
  249. // });
  250. var checkDownloadStatus = function() {
  251. var intervalId = setInterval(function() {
  252. //console.log('checkDownloadStatus ....');
  253. $.ajax({
  254. url: '/download-status',
  255. method: 'GET',
  256. dataType: 'json',
  257. data: { reset: 0 },
  258. success: function(response) {
  259. console.log(response);
  260. if (response.status == "2") {
  261. console.log('clean');
  262. clearInterval(intervalId);
  263. layer.close(loadIndex); // 关闭加载层
  264. }
  265. }
  266. });
  267. }, 1000); // 每秒请求一次
  268. }
  269. // 放大图片 start
  270. // 创建全屏遮罩层
  271. $('.album-thumb-detail').on('click', function (event) {
  272. // 如果点击的是 download-icon,阻止后续代码执行
  273. if ($(event.target).closest('.download-icon').length) {
  274. return;
  275. }
  276. // 获取当前点击的 .album-thumb-detail 的父级 .grid-album 元素
  277. var $parentAlbum = $(this).closest('.grid-album');
  278. // 获取当前父级下所有 .album-thumb-detail img 的 src
  279. var imageSrcArray = [];
  280. $parentAlbum.find('.album-thumb-detail img').each(function () {
  281. src = $(this).attr('data-src')+"?x-oss-process=image/resize,w_800";
  282. // newSrc = src.split('?')[0];
  283. imageSrcArray.push(src);
  284. });
  285. // 获取当前点击图片在数组中的索引
  286. var $albumThumbs = $parentAlbum.find('.album-thumb-detail');
  287. var currentImageIndex = $albumThumbs.index(this);
  288. // console.log(currentImageIndex);
  289. const $fullscreenMask = $('<div>').addClass('fullscreen-mask');
  290. const $fullscreenImg = $('<img>').attr('src', imageSrcArray[currentImageIndex]);
  291. const $btnLeft = $('<div>').addClass('fullscreen-btn fullscreen-btn-left').html('&lt;');
  292. const $btnRight = $('<div>').addClass('fullscreen-btn fullscreen-btn-right').html('&gt;');
  293. const $btnDownload = $('<div>').addClass('fullscreen-btn fullscreen-btn-download').html('&#11123;'); // 下载图标
  294. $fullscreenMask.append($fullscreenImg, $btnLeft, $btnRight, $btnDownload);
  295. // 将遮罩层添加到 body
  296. $('body').append($fullscreenMask);
  297. setTimeout(function () {
  298. $fullscreenMask.addClass('active');
  299. }, 10);
  300. // 点击遮罩层时关闭
  301. $fullscreenMask.on('click', function (e) {
  302. if (!$(e.target).is($btnLeft) && !$(e.target).is($btnRight) && !$(e.target).is($btnDownload)) {
  303. $fullscreenMask.removeClass('active');
  304. setTimeout(function () {
  305. $fullscreenMask.remove();
  306. }, 300);
  307. }
  308. });
  309. // 点击左按钮显示上一张图片
  310. $btnLeft.on('click', function () {
  311. currentImageIndex--;
  312. if (currentImageIndex < 0) {
  313. currentImageIndex = imageSrcArray.length - 1;
  314. }
  315. $fullscreenImg.attr('src', imageSrcArray[currentImageIndex]);
  316. });
  317. // 点击右按钮显示下一张图片
  318. $btnRight.on('click', function () {
  319. currentImageIndex++;
  320. if (currentImageIndex >= imageSrcArray.length) {
  321. currentImageIndex = 0;
  322. }
  323. $fullscreenImg.attr('src', imageSrcArray[currentImageIndex]);
  324. });
  325. // 点击下载按钮下载当前图片
  326. $btnDownload.on('click', function (e) {
  327. e.stopPropagation(); // 阻止事件冒泡
  328. loadIndex = layer.load(2, { shade: [0.8, '#000'] });
  329. $.ajax({
  330. url: '/download-status',
  331. method: 'GET',
  332. dataType: 'json',
  333. data: { reset: 1 },
  334. success: function(response) {
  335. const currentImageSrc = imageSrcArray[currentImageIndex];
  336. // 下载图片 js urlencode
  337. href_url = '/download-image?url='+encodeURIComponent(currentImageSrc);
  338. window.location.href = href_url;
  339. //延迟执行,等待下载完成
  340. // setTimeout(function() {
  341. // layer.close(loadIndex); // 关闭加载层
  342. // }, 2000);
  343. checkDownloadStatus();
  344. }
  345. });
  346. });
  347. });
  348. // 放大图片 end
  349. const $overlay = $('#overlay');
  350. const $videoPlayer = $('#videoPlayer');
  351. const $closeBtn = $('#closeBtn');
  352. const $videoBtns = $('.video-btn');
  353. // 点击播放按钮
  354. $videoBtns.on('click', function() {
  355. const videoSrc = $(this).data('src'); // 获取 data-src 属性
  356. $videoPlayer.attr('src', videoSrc); // 设置视频源
  357. $videoPlayer[0].autoplay = true; // 设置自动播放
  358. $overlay.css('display', 'flex'); // 显示遮罩层
  359. });
  360. // 点击关闭按钮
  361. $closeBtn.on('click', function() {
  362. $videoPlayer[0].pause(); // 暂停视频
  363. $videoPlayer.attr('src', ''); // 清空视频源
  364. $overlay.hide(); // 隐藏遮罩层
  365. });
  366. // 点击遮罩层关闭
  367. $overlay.on('click', function(event) {
  368. if (event.target === $overlay[0]) { // 判断是否点击的是遮罩层本身
  369. $videoPlayer[0].pause(); // 暂停视频
  370. $videoPlayer.attr('src', ''); // 清空视频源
  371. $overlay.hide(); // 隐藏遮罩层
  372. }
  373. });
  374. // 为 .log-date 绑定点击事件
  375. $('.log-date').on('click', function() {
  376. // 找到当前 .log-date 的同级 .log-line 元素
  377. $(this).siblings('.log-line').toggleClass('active');
  378. });
  379. //日志
  380. // 检查 update-log 是否存在
  381. if ($('.update-log').length > 0) {
  382. // 定义一个函数来执行 AJAX 请求
  383. function fetchUpdate() {
  384. $.ajax({
  385. url: '/next-log', // 替换为你的 API 端点
  386. method: 'GET', // 根据你的需求选择 GET 或 POST
  387. dataType: 'json', // 根据你的 API 返回的数据类型选择
  388. success: function(response) {
  389. // 假设 response 包含 timestamp 和 message
  390. var created_at = response.data.created_at;
  391. var action = response.data.action;
  392. if (action == 'aa') {
  393. action = '新增了';
  394. } else {
  395. action = '更新了';
  396. }
  397. var model = "<a href='/detail?id="+response.data.content_id+"'>" + response.data.model + '</a> 的';
  398. var content = response.data.content;
  399. var user_name = response.data.user_name;
  400. // 更新 timestamp 和 message
  401. $('.update-log .update-time').text(created_at);
  402. $('.update-log .user_name').text(user_name);
  403. $('.update-log .action').text(action);
  404. $('.update-log .model').html(model);
  405. $('.update-log .log-content').text(content);
  406. },
  407. error: function(xhr, status, error) {
  408. console.error('AJAX 请求失败:', status, error);
  409. }
  410. });
  411. }
  412. // 立即执行一次
  413. fetchUpdate();
  414. // 每 10 秒执行一次
  415. setInterval(fetchUpdate, 20000); // 10000 毫秒 = 10 秒
  416. }
  417. var downdHref = function() {
  418. // 查找 .album-tab 中带有 is-active 类的 <a> 标签
  419. let activeTab = $('.album-tab a.is-active').attr('href');
  420. // 将 #album- 替换为空,得到 tab 变量
  421. let tab = activeTab.replace('#album-', '');
  422. // 获取当前 URL 中的 id 参数
  423. let currentUrl = window.location.href;
  424. let urlParams = new URLSearchParams(currentUrl.split('?')[1]);
  425. let id = urlParams.get('id');
  426. // 拼接新的 URL
  427. let newUrl = `/download-all?id=${id}&tab=${tab}&refresh=true`;
  428. // 跳转到新 URL
  429. window.location.href = newUrl;
  430. }
  431. //ajax 定时请求 /download-status,直到返回状态为 0 时
  432. // 监听 .download-all 的点击事件
  433. $('.download-all').on('click', function() {
  434. loadIndex = layer.load(2, { shade: [0.8, '#000'] }); // 参数1表示加载样式,shade
  435. //jquery 请求 /download-status
  436. $.ajax({
  437. url: '/download-status',
  438. method: 'GET',
  439. dataType: 'json',
  440. data: { reset: 1 },
  441. success: function(response) {
  442. downdHref();
  443. checkDownloadStatus();
  444. }
  445. });
  446. });
  447. $('.download-btn').on('click', function() {
  448. loadIndex = layer.load(2, { shade: [0.8, '#000'] }); // 参数1表示加载样式,shade
  449. //jquery 请求 /download-status
  450. // window.location.href = $(this).attr('url');
  451. //
  452. setTimeout(function() {
  453. layer.close(loadIndex); // 关闭加载层
  454. }, 1500);
  455. });
  456. if ( window.innerWidth <= 768) {
  457. hamburgerMenuWrap = $('.menu-wrap');
  458. hamburgerMenuWrap.removeClass('menu-active');
  459. $(".content").css("padding-left","0px");
  460. }
  461. $(".download-icon").on('click', function() {
  462. loadIndex = layer.load(2, {shade: [0.8, '#000']});
  463. const currentImageSrc = $(this).attr('data-src');
  464. $.ajax({
  465. url: '/download-status',
  466. method: 'GET',
  467. dataType: 'json',
  468. data: {reset: 1},
  469. success: function (response) {
  470. // 下载图片 js urlencode
  471. href_url = '/download-image?url=' + encodeURIComponent(currentImageSrc);
  472. window.location.href = href_url;
  473. checkDownloadStatus();
  474. }
  475. });
  476. });
  477. });
  478. function changeIframeSrc(url) {
  479. // 获取 iframe 元素
  480. const iframe = document.getElementById('myFrame');
  481. // 改变 iframe 的 src 属性
  482. iframe.src = url;
  483. if ( window.innerWidth <= 768) {
  484. hamburgerMenuWrap = $('.menu-wrap');
  485. hamburgerMenuWrap.removeClass('menu-active');
  486. $(".content").css("padding-left","0px");
  487. }
  488. }
  489. function logout() {
  490. layer.confirm('是否确定退出登录?', {
  491. btn: ['确定', '关闭'] //按钮
  492. }, function(){
  493. window.top.location.href = "/logout";
  494. }, function(){
  495. layer.close();
  496. });
  497. }