infomation.js 4.2 KB

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