drugInfo.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import {post, imageUrlPrefix,getUrlArgObject, throttle} from './promise.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 param = {
  9. "type": getUrlArgObject('type'),
  10. "questionId": getUrlArgObject('questionId'),
  11. "position": getUrlArgObject('position')
  12. };
  13. post(infoUrl, param).then((res) => {
  14. const data = res.data.data
  15. var str='',anchors='',item='';
  16. if(!data){
  17. $("h1").html("暂时没有数据");
  18. $(".anchors").css("display", "none");
  19. return;
  20. }
  21. var list = data.introduceDetailList;
  22. $("h1").html(data.tagName);
  23. //list.map((item,i) =>{
  24. for(var i=0;i<list.length;i++) {
  25. item = list[i];
  26. item.content = item.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix)
  27. anchors = '<li><i></i><a href="#' + item.id +
  28. '">' + item.title + '</a></li><li class="anchor-line"></li>';
  29. str = '<div class="title"><h2 id="' + item.id +
  30. '">' + '【'+ item.title + '】'+
  31. '</h2></div>' +
  32. '<div class="contentBox">' + item.content + '<div>';
  33. $(".infos").append(str);
  34. $(".anchors ul").append(anchors);
  35. //});
  36. }
  37. addLinkClickEvent();
  38. adjustHeight();
  39. function addScrollEvent() {
  40. var scrollTop = $('.infos').scrollTop()
  41. var divHeight = 0;
  42. for (var i = 0; i < list.length; i++) {
  43. divHeight = divHeight + parseInt($('#' + list[i].id).css('height')) + parseInt($('#' + list[i].id).parent().next().css('height')) +40
  44. if(divHeight > scrollTop) {
  45. // this.setState({
  46. // currentIndex: i
  47. // })
  48. var anchor = 2*i
  49. $('.anchors ul').children().eq(anchor).addClass('active').siblings().removeClass('active')
  50. return
  51. }
  52. }
  53. }
  54. $(".infos").scroll(throttle(addScrollEvent,200))
  55. })
  56. }
  57. function addLinkClickEvent(){
  58. $("li:first").addClass("active");
  59. $("li>a").on("click",function(){
  60. $(".active").removeClass('active');
  61. $(this).parent().addClass("active");
  62. });
  63. }
  64. function adjustHeight(){
  65. var ht = window.innerHeight;
  66. $(".content").height(ht-145+"px");
  67. }
  68. })();