script.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  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. $(".content").css("padding-left","0px");
  106. });
  107. // Menu END
  108. // Contact START
  109. $('.input-field input, textarea').on('input', function() {
  110. var inputValue = $(this).val();
  111. var inputpParent = $(this).parent('.input-field');
  112. if (inputValue.length > 0) {
  113. inputpParent.addClass('is-active');
  114. } else {
  115. inputpParent.removeClass('is-active');
  116. }
  117. });
  118. // Contact END
  119. // Gallery Single page START
  120. $('.grid-single .grid-item img').parazoom({
  121. customCursorIcon: 'images/magnify.svg',
  122. customCursorSize: '30px',
  123. transitionTime: '1s',
  124. transitionTimeLeave: '1s'
  125. });
  126. var $grid = $('.grid-single').masonry({
  127. itemSelector: '.grid-single .grid-item',
  128. percentPosition: true,
  129. columnWidth: '.grid-single .grid-sizer'
  130. });
  131. $grid.imagesLoaded().progress( function() {
  132. $grid.masonry({
  133. gutter: 15
  134. });
  135. });
  136. $('.grid-single .grid-item a').magnificPopup({
  137. type:'image',
  138. removalDelay: 500,
  139. gallery: {
  140. enabled: true
  141. },
  142. callbacks: {
  143. beforeOpen: function() {
  144. this.st.image.markup = this.st.image.markup.replace('mfp-figure', 'mfp-figure mfp-with-anim');
  145. this.st.mainClass = this.st.el.attr('data-effect');
  146. }
  147. },
  148. });
  149. // Gallery Single page END
  150. // Album page START
  151. function albumMasonry() {
  152. var $gridAlbum = $('.grid-album').masonry({
  153. itemSelector: '.grid-album .grid-item',
  154. percentPosition: true,
  155. columnWidth: '.grid-album .grid-sizer'
  156. });
  157. $gridAlbum.imagesLoaded().progress( function() {
  158. $gridAlbum.masonry({
  159. gutter: 44
  160. });
  161. });
  162. }
  163. albumMasonry();
  164. var bLazy = new Blazy();
  165. $('.album-tab a').on('click', function(e) {
  166. e.preventDefault();
  167. var href = $(this).attr('href');
  168. $('.album-tab a').removeClass('is-active');
  169. $(this).addClass('is-active');
  170. $('.grid-album').removeClass('is-active');
  171. $(href).addClass('is-active');
  172. $(href).addClass('animate__animated animate__slideInUp');
  173. $('.grid-album.is-active:not(' + href + ')').removeClass('animate__animated animate__slideInUp');
  174. albumMasonry();
  175. let column = $(this).attr('column');
  176. if (column == 'pdf' || column == 'video') {
  177. $(".download-all").hide();
  178. } else {
  179. $(".download-all").show();
  180. }
  181. });
  182. // Album page END
  183. // Settings START
  184. $('.settings-btn').on('click', function() {
  185. var settings = $('.settings-wrap');
  186. settings.toggleClass('is-active');
  187. });
  188. var savedColor = localStorage.getItem('boxColor');
  189. if (savedColor) {
  190. $(':root').css('--color-def', savedColor);
  191. }
  192. $('.settings-color-item').on('click', function() {
  193. var color = $(this).css('background-color');
  194. $('.settings-color-item').css('border-color', '#fff');
  195. $(this).css('border-color', color);
  196. $(':root').css('--color-def', color);
  197. localStorage.setItem('boxColor', color);
  198. });
  199. // Settings END
  200. // $('.menu-nav-item').first().click(function () {
  201. // console.log('first11');
  202. // $(this).parent().find('.menu-nav-son').stop(true, true).slideToggle(200);
  203. // });
  204. $('.menu-nav-item').each(function() {
  205. var firstLink = $(this).find('a').first();
  206. firstLink.on('click', function(event) {
  207. event.preventDefault(); // 阻止默认行为(如跳转)
  208. $(this).parent().find('.menu-nav-son').stop(true, true).slideToggle(200);
  209. });
  210. });
  211. // $('.menu-nav-son-li').hover(
  212. // function () {
  213. // // 显示当前 li 的子菜单
  214. // $(this).find('.menu-nav-son2').stop(true, true).slideDown(200);
  215. // }
  216. // );
  217. //
  218. // // 当鼠标离开 .menu-nav ul 时
  219. // $('.menu-nav-son-li').mouseleave(function () {
  220. // // 隐藏所有子菜单
  221. // $('.menu-nav-son2').stop(true, true).slideUp(0);
  222. // });
  223. var checkDownloadStatus = function() {
  224. var intervalId = setInterval(function() {
  225. console.log('checkDownloadStatus ....');
  226. $.ajax({
  227. url: '/download-status',
  228. method: 'GET',
  229. dataType: 'json',
  230. data: { reset: 0 },
  231. success: function(response) {
  232. console.log(response);
  233. if (response.status == "2") {
  234. console.log('clean');
  235. clearInterval(intervalId);
  236. layer.close(loadIndex); // 关闭加载层
  237. }
  238. }
  239. });
  240. }, 1000); // 每秒请求一次
  241. }
  242. // 放大图片 start
  243. // 创建全屏遮罩层
  244. $('.album-thumb-detail').on('click', function (event) {
  245. // 如果点击的是 download-icon,阻止后续代码执行
  246. if ($(event.target).closest('.download-icon').length) {
  247. return;
  248. }
  249. // 获取当前点击的 .album-thumb-detail 的父级 .grid-album 元素
  250. var $parentAlbum = $(this).closest('.grid-album');
  251. // 获取当前父级下所有 .album-thumb-detail img 的 src
  252. var imageSrcArray = [];
  253. $parentAlbum.find('.album-thumb-detail img').each(function () {
  254. src = $(this).attr('data-src');
  255. // newSrc = src.split('?')[0];
  256. imageSrcArray.push(src);
  257. });
  258. // 获取当前点击图片在数组中的索引
  259. var $albumThumbs = $parentAlbum.find('.album-thumb-detail');
  260. var currentImageIndex = $albumThumbs.index(this);
  261. // console.log(currentImageIndex);
  262. const $fullscreenMask = $('<div>').addClass('fullscreen-mask');
  263. const $fullscreenImg = $('<img>').attr('src', imageSrcArray[currentImageIndex]);
  264. const $btnLeft = $('<div>').addClass('fullscreen-btn fullscreen-btn-left').html('&lt;');
  265. const $btnRight = $('<div>').addClass('fullscreen-btn fullscreen-btn-right').html('&gt;');
  266. const $btnDownload = $('<div>').addClass('fullscreen-btn fullscreen-btn-download').html('&#11123;'); // 下载图标
  267. $fullscreenMask.append($fullscreenImg, $btnLeft, $btnRight, $btnDownload);
  268. // 将遮罩层添加到 body
  269. $('body').append($fullscreenMask);
  270. setTimeout(function () {
  271. $fullscreenMask.addClass('active');
  272. }, 10);
  273. // 点击遮罩层时关闭
  274. $fullscreenMask.on('click', function (e) {
  275. if (!$(e.target).is($btnLeft) && !$(e.target).is($btnRight) && !$(e.target).is($btnDownload)) {
  276. $fullscreenMask.removeClass('active');
  277. setTimeout(function () {
  278. $fullscreenMask.remove();
  279. }, 300);
  280. }
  281. });
  282. // 点击左按钮显示上一张图片
  283. $btnLeft.on('click', function () {
  284. currentImageIndex--;
  285. if (currentImageIndex < 0) {
  286. currentImageIndex = imageSrcArray.length - 1;
  287. }
  288. $fullscreenImg.attr('src', imageSrcArray[currentImageIndex]);
  289. });
  290. // 点击右按钮显示下一张图片
  291. $btnRight.on('click', function () {
  292. currentImageIndex++;
  293. if (currentImageIndex >= imageSrcArray.length) {
  294. currentImageIndex = 0;
  295. }
  296. $fullscreenImg.attr('src', imageSrcArray[currentImageIndex]);
  297. });
  298. // 点击下载按钮下载当前图片
  299. $btnDownload.on('click', function (e) {
  300. e.stopPropagation(); // 阻止事件冒泡
  301. loadIndex = layer.load(2, { shade: [0.8, '#000'] });
  302. $.ajax({
  303. url: '/download-status',
  304. method: 'GET',
  305. dataType: 'json',
  306. data: { reset: 1 },
  307. success: function(response) {
  308. const currentImageSrc = imageSrcArray[currentImageIndex];
  309. // 下载图片 js urlencode
  310. href_url = '/download-image?url='+encodeURIComponent(currentImageSrc);
  311. window.location.href = href_url;
  312. checkDownloadStatus();
  313. }
  314. });
  315. });
  316. });
  317. // 放大图片 end
  318. const $overlay = $('#overlay');
  319. const $videoPlayer = $('#videoPlayer');
  320. const $closeBtn = $('#closeBtn');
  321. const $videoBtns = $('.video-btn');
  322. // 点击播放按钮
  323. $videoBtns.on('click', function() {
  324. const videoSrc = $(this).data('src'); // 获取 data-src 属性
  325. $videoPlayer.attr('src', videoSrc); // 设置视频源
  326. $videoPlayer[0].autoplay = true; // 设置自动播放
  327. $overlay.css('display', 'flex'); // 显示遮罩层
  328. });
  329. // 点击关闭按钮
  330. $closeBtn.on('click', function() {
  331. $videoPlayer[0].pause(); // 暂停视频
  332. $videoPlayer.attr('src', ''); // 清空视频源
  333. $overlay.hide(); // 隐藏遮罩层
  334. });
  335. // 点击遮罩层关闭
  336. $overlay.on('click', function(event) {
  337. if (event.target === $overlay[0]) { // 判断是否点击的是遮罩层本身
  338. $videoPlayer[0].pause(); // 暂停视频
  339. $videoPlayer.attr('src', ''); // 清空视频源
  340. $overlay.hide(); // 隐藏遮罩层
  341. }
  342. });
  343. // 为 .log-date 绑定点击事件
  344. $('.log-date').on('click', function() {
  345. // 找到当前 .log-date 的同级 .log-line 元素
  346. $(this).siblings('.log-line').toggleClass('active');
  347. });
  348. //日志
  349. // 检查 update-log 是否存在
  350. if ($('.update-log').length > 0) {
  351. // 定义一个函数来执行 AJAX 请求
  352. function fetchUpdate() {
  353. $.ajax({
  354. url: '/next-log', // 替换为你的 API 端点
  355. method: 'GET', // 根据你的需求选择 GET 或 POST
  356. dataType: 'json', // 根据你的 API 返回的数据类型选择
  357. success: function(response) {
  358. // 假设 response 包含 timestamp 和 message
  359. var created_at = response.data.created_at;
  360. var action = response.data.action;
  361. if (action == 'aa') {
  362. action = '新增了';
  363. } else {
  364. action = '更新了';
  365. }
  366. var model = "<a href='/detail?id="+response.data.content_id+"'>" + response.data.model + '</a> 的';
  367. var content = response.data.content;
  368. var user_name = response.data.user_name;
  369. // 更新 timestamp 和 message
  370. $('.update-log .update-time').text(created_at);
  371. $('.update-log .user_name').text(user_name);
  372. $('.update-log .action').text(action);
  373. $('.update-log .model').html(model);
  374. $('.update-log .log-content').text(content);
  375. },
  376. error: function(xhr, status, error) {
  377. console.error('AJAX 请求失败:', status, error);
  378. }
  379. });
  380. }
  381. // 立即执行一次
  382. fetchUpdate();
  383. // 每 10 秒执行一次
  384. setInterval(fetchUpdate, 20000); // 10000 毫秒 = 10 秒
  385. }
  386. var downdHref = function() {
  387. // 查找 .album-tab 中带有 is-active 类的 <a> 标签
  388. let activeTab = $('.album-tab a.is-active').attr('href');
  389. // 将 #album- 替换为空,得到 tab 变量
  390. let tab = activeTab.replace('#album-', '');
  391. // 获取当前 URL 中的 id 参数
  392. let currentUrl = window.location.href;
  393. let urlParams = new URLSearchParams(currentUrl.split('?')[1]);
  394. let id = urlParams.get('id');
  395. // 拼接新的 URL
  396. let newUrl = `/download-all?id=${id}&tab=${tab}&refresh=true`;
  397. // 跳转到新 URL
  398. window.location.href = newUrl;
  399. }
  400. //ajax 定时请求 /download-status,直到返回状态为 0 时
  401. // 监听 .download-all 的点击事件
  402. $('.download-all').on('click', function() {
  403. loadIndex = layer.load(2, { shade: [0.8, '#000'] }); // 参数1表示加载样式,shade
  404. //jquery 请求 /download-status
  405. $.ajax({
  406. url: '/download-status',
  407. method: 'GET',
  408. dataType: 'json',
  409. data: { reset: 1 },
  410. success: function(response) {
  411. downdHref();
  412. checkDownloadStatus();
  413. }
  414. });
  415. });
  416. if ( window.innerWidth <= 768) {
  417. hamburgerMenuWrap = $('.menu-wrap');
  418. hamburgerMenuWrap.removeClass('menu-active');
  419. $(".content").css("padding-left","0px");
  420. }
  421. });
  422. function changeIframeSrc(url) {
  423. // 获取 iframe 元素
  424. const iframe = document.getElementById('myFrame');
  425. // 改变 iframe 的 src 属性
  426. iframe.src = url;
  427. if ( window.innerWidth <= 768) {
  428. hamburgerMenuWrap = $('.menu-wrap');
  429. hamburgerMenuWrap.removeClass('menu-active');
  430. $(".content").css("padding-left","0px");
  431. }
  432. }
  433. function logout() {
  434. window.top.location.href = "/logout";
  435. }