infomation.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. (function($){
  2. getInfomation();
  3. function getInfomation(){
  4. // var infoUrl ="http://" + window.location.host+'/icss-web/kl/introduce/get_by_itemidAndType';
  5. // var infoUrl ="http://" + window.location.host+'/api/icss/introduceInfo/getByQuestionId';
  6. var infoUrl ='http://192.168.2.236:5050/api/icss/introduceInfo/getByQuestionId'
  7. var imageUrlPrefix = 'http://192.168.2.236:82'
  8. var urlParam = parseUrlParams();
  9. console.log(urlParam)
  10. var param = {
  11. "type": urlParam.type,
  12. "questionId": urlParam.questionId,
  13. position:2
  14. };
  15. $.ajax({
  16. type: 'POST',
  17. url: infoUrl,
  18. data: JSON.stringify(param),
  19. headers: {
  20. // 'Accept': 'application/json, text/plain, */*',
  21. 'Content-Type':'application/json; charset=utf-8'
  22. },
  23. success: function(res) {
  24. console.log(res)
  25. var str='',anchors='',item='';
  26. if(!res.data){
  27. $("h1").html("暂时没有数据");
  28. return;
  29. }
  30. var list = res.data.introduceDetailList;
  31. $("h1").html(res.data.tagName);
  32. //list.map((item,i) =>{
  33. for(var i=0;i<list.length;i++) {
  34. item = list[i];
  35. item.content = item.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix)
  36. anchors = '<li><i></i><a href="#anchor' + i +
  37. '">' + item.title + '</a></li><li class="anchor-line"></li>';
  38. str = '<div class="title"><h2 id="anchor' + i +
  39. '">' + item.title +
  40. '</h2><div class="line"></div></div>' +
  41. '<div>' + item.content + '<div>';
  42. $(".infos").append(str);
  43. $(".anchors ul").append(anchors);
  44. //});
  45. }
  46. addLinkClickEvent();
  47. adjustHeight();
  48. }
  49. })
  50. // $.post(infoUrl,param,function(res){
  51. // console.log('resssss', res)
  52. // if(res.ret == 0){
  53. // var str='',anchors='',item='';
  54. // if(!res.data){
  55. // $("h1").html("暂时没有数据");
  56. // return;
  57. // }
  58. // var list = res.data.introduceDetailList;
  59. // $("h1").html(res.data.shortName);
  60. // //list.map((item,i) =>{
  61. // for(var i=0;i<list.length;i++) {
  62. // item = list[i];
  63. // anchors = '<li><i></i><a href="#anchor' + i +
  64. // '">' + item.title + '</a></li><li class="anchor-line"></li>';
  65. // str = '<div class="title"><h2 id="anchor' + i +
  66. // '">' + item.title +
  67. // '</h2><div class="line"></div></div>' +
  68. // '<div>' + item.description + '<div>';
  69. // $(".infos").append(str);
  70. // $(".anchors ul").append(anchors);
  71. // //});
  72. // }
  73. // addLinkClickEvent();
  74. // adjustHeight();
  75. // }else{
  76. // $(".container").html(res.msg);
  77. // }
  78. // }
  79. // );
  80. }
  81. function parseUrlParams(){
  82. var url = window.location.search;
  83. var params = url.substring(1).split("&");
  84. var tmp = '',obj = {},it={};
  85. //params.map((it) =>{
  86. for(var i=0;i<params.length;i++) {
  87. it = params[i];
  88. tmp = it.split("=");
  89. if (tmp[0] && tmp[1]) {
  90. obj[tmp[0]] = tmp[1];
  91. }
  92. }
  93. //});
  94. return obj;
  95. }
  96. function addLinkClickEvent(){
  97. $("li:first").addClass("active");
  98. $("li>a").on("click",function(){
  99. $(".active").removeClass('active');
  100. $(this).parent().addClass("active");
  101. });
  102. }
  103. function adjustHeight(){
  104. var ht = window.innerHeight;
  105. $(".content").height(ht-145+"px");
  106. }
  107. })(jQuery);