drugInfo.js 4.4 KB

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