Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. import Swiper from 'swiper/bundle'
  2. import gsap from 'gsap'
  3. import Common from '../common/js/Common'
  4. import {
  5. isMobile
  6. } from '../common/js/utils'
  7. // const BASEURL = 'http://192.168.1.33:9100';
  8. const BASEURL = 'http://localhost:3002/api';
  9. const pageSize = 5;
  10. export default class App {
  11. constructor() {
  12. let common = new Common(document.querySelector('.main'),4) //导航菜单高亮,0是首页,后面的按顺序添加
  13. this.isMobile = isMobile()
  14. this.num = 0;
  15. this.bindDom();
  16. // this.fold()
  17. // 获取当前链接的 hash 部分
  18. // 监听 hashchange 事件
  19. window.addEventListener('hashchange', ()=>this.handleHashChange());
  20. // 如果需要在页面加载时也获取一次当前 hash
  21. this.handleHashChange();
  22. }
  23. // 定义一个函数来处理 hash 变化
  24. handleHashChange() {
  25. const hash = window.location.hash; // 获取当前链接的 hash 部分
  26. const params = hash.substring(1); // 去掉 #
  27. console.log(params); // 输出变化后的参数
  28. if(!params) return;
  29. if(this.getAnchorPoint) {
  30. this.getAnchorPoint(params)
  31. }else {
  32. getAnchorPoint(params)
  33. }
  34. }
  35. getAnchorPoint(params){
  36. const tabs_ul = document.querySelectorAll(".tabs_li");
  37. const news_ul = document.querySelector(".news_ul");
  38. const typeCon = document.querySelector(".typeCon");
  39. tabs_ul.forEach((item,index)=>{
  40. tabs_ul.forEach((li) => {
  41. li.classList.remove('tabs_lis');
  42. });
  43. if(params == 'p2'){
  44. tabs_ul[1].classList.add('tabs_lis')
  45. news_ul.style.display = 'none';
  46. typeCon.style.display = 'block';
  47. }else{
  48. tabs_ul[0].classList.add('tabs_lis')
  49. news_ul.style.display = 'block';
  50. typeCon.style.display = 'none';
  51. }
  52. // 获取目标元素
  53. const targetElement = document.querySelector('#tab');
  54. // 获取目标元素的位置信息
  55. if (targetElement) {
  56. const topPosition = targetElement.getBoundingClientRect().top + window.scrollY;
  57. // 滚动到目标元素的位置
  58. window.scrollTo({ top: topPosition, behavior: 'smooth' });
  59. }
  60. })
  61. }
  62. bindDom(){
  63. const tabs_ul = document.querySelectorAll(".tabs_li");
  64. const news_ul = document.querySelector(".news_ul");
  65. const typeCon = document.querySelector(".typeCon");
  66. tabs_ul.forEach((item,index)=>{
  67. item.addEventListener('click',()=>{
  68. tabs_ul.forEach((li) => {
  69. li.classList.remove('tabs_lis');
  70. });
  71. if(index == 0){
  72. news_ul.style.display = 'block';
  73. typeCon.style.display = 'none';
  74. }else{
  75. news_ul.style.display = 'none';
  76. typeCon.style.display = 'block';
  77. this.fold()
  78. }
  79. // 给当前点击的元素添加 tabs_lis 类名
  80. item.classList.add('tabs_lis');
  81. })
  82. })
  83. }
  84. fold(){
  85. let isMobile=this.isMobile;
  86. if(this.num == 0){
  87. let liTitleArray = document.querySelectorAll('.liTitle');
  88. liTitleArray.forEach((child )=>{
  89. child.addEventListener('click', (event) => {
  90. // 获取被点击元素的父元素
  91. let parentElement = event.currentTarget.parentNode;
  92. let infoSonLi = parentElement.querySelector('.infoSonLi');
  93. let actualHeight = infoSonLi.offsetHeight;
  94. // 初始化子元素总高度
  95. let childrenTotalHeight = isMobile?30:0;
  96. // 遍历所有子元素,累加它们的高度
  97. Array.from(infoSonLi.children).forEach(child => {
  98. childrenTotalHeight += child.offsetHeight;
  99. });
  100. let totalHeight = actualHeight + childrenTotalHeight;
  101. if (parentElement.classList.contains("infoLiShow")) {
  102. parentElement.classList.remove('infoLiShow');
  103. gsap.to(infoSonLi,{height:0,duration:0.5})
  104. }else{
  105. parentElement.classList.add('infoLiShow');
  106. gsap.to(infoSonLi,{height:totalHeight,duration:0.5})
  107. // gsap.to(infoSonLi,{height:totalHeight,duration:1,onComplete: () => infoSonLi.style.height = 'auto'})
  108. }
  109. });
  110. });
  111. let typeTitCkArray = document.querySelectorAll('.typeTitCk');
  112. let inFoul = document.querySelector('.infoul');
  113. let infoLiArray = document.querySelectorAll('.infoLi');
  114. function addClassType() {
  115. infoLiArray.forEach((val)=>{
  116. val.classList.remove('infoLiShow');
  117. })
  118. typeTitCkArray.forEach((child )=>{
  119. child.classList.remove('ck');
  120. });
  121. }
  122. //
  123. let typeOld="all";
  124. let element=document.querySelector('.typeTitle');
  125. typeTitCkArray.forEach((child )=>{
  126. child.addEventListener('click', (event) => {
  127. addClassType();
  128. let domElement = event.target;
  129. domElement.classList.add('ck');
  130. let typeName = domElement.dataset.type;
  131. inFoul.className = 'infoul '+ typeName;
  132. if(isMobile){
  133. if(typeName=='type2'&&typeOld!='type3'){
  134. element.scrollLeft = element.scrollWidth - element.clientWidth;
  135. }else if(typeName=='type2'&&typeOld=='type3'){
  136. element.scrollLeft = 0;
  137. }
  138. }
  139. });
  140. });
  141. //添加表单动画
  142. let liTits = document.querySelectorAll('.liTit');
  143. liTits.forEach((val)=>{
  144. val.style.height = val.offsetHeight+'px';
  145. let liTitMove = val.querySelector('.liTitMove');
  146. if(isMobile){
  147. liTitMove.classList.remove("moveUp");
  148. liTitMove.classList.add("fadeInUp");
  149. }else{
  150. // 获取 liTit 下的所有 div 元素
  151. let divs = liTitMove.querySelector('div');
  152. if(divs){
  153. // 克隆 div 元素
  154. let clonedDiv = divs.cloneNode(true);
  155. // 将克隆的 div 插入到 liTit 的后面
  156. divs.parentElement.appendChild(clonedDiv);;
  157. }
  158. }
  159. })
  160. this.num = 1;
  161. }
  162. }
  163. hotNews(){
  164. const news_banner = document.querySelector('.news_banner');
  165. const img = news_banner.querySelector('img')
  166. const cont1 = news_banner.querySelector('.cont1')
  167. const cont2 = news_banner.querySelector('.cont2')
  168. const cont3 = news_banner.querySelector('.cont3')
  169. fetch(BASEURL+'/system/news/top')
  170. .then(response => {
  171. if (!response.ok) {
  172. throw new Error('网络响应不是 OK');
  173. }
  174. return response.json();
  175. })
  176. .then(response => {
  177. if (response.surfaceUrl) img.src = response.surfaceUrl
  178. cont1.textContent = response.title
  179. cont2.textContent = response.digest
  180. cont3.textContent = response.date
  181. news_banner.addEventListener('click',() => {
  182. window.open('/articleDetails.html?id='+response.uuid)
  183. })
  184. })
  185. .catch(error => {
  186. console.error('请求失败:', error); // 处理错误
  187. });
  188. }
  189. pageTurningClickEvent (){
  190. // 上一页
  191. const previousPage = document.querySelector('#previousPage');
  192. previousPage.addEventListener('click', function(event) {
  193. event.preventDefault()
  194. const currentPage = sessionStorage.getItem('news_currentPage');
  195. if(currentPage && parseInt(currentPage) > 1){
  196. initList(parseInt(currentPage) - 1)
  197. }
  198. })
  199. //下一页
  200. const nextPage = document.querySelector('#nextPage');
  201. nextPage.addEventListener('click', function(event) {
  202. event.preventDefault()
  203. const currentPage = sessionStorage.getItem('news_currentPage');
  204. const pageCount = Math.ceil(parseInt(sessionStorage.getItem('news_total')) / pageSize)
  205. if(currentPage && parseInt(currentPage) < pageCount){
  206. initList(parseInt(currentPage) + 1)
  207. }
  208. })
  209. }
  210. }