information.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. const {
  2. post,
  3. throttle,
  4. imageUrlPrefix,
  5. config,
  6. getUrlArgObject
  7. } = require('./promise.js');
  8. const $ = require("jquery");
  9. function getInfomation() {
  10. var param = {
  11. "type": getUrlArgObject('type'),
  12. "name": getUrlArgObject('name'),
  13. "position": getUrlArgObject('position')
  14. };
  15. const uname = getUrlArgObject('uname')
  16. const showName = param.name
  17. if (param.type == 5 || param.type == 51) {
  18. param.type = 12;
  19. param.name = uname;
  20. }
  21. post(config.information, param).then((res) => {
  22. const data = res.data.data
  23. document.title = showName
  24. var str = '';
  25. var anchors = '';
  26. var item = '';
  27. if (!data) {
  28. $("h1").html("暂时没有数据");
  29. $(".anchors").css("display", "none");
  30. return;
  31. }
  32. var list = data.details;
  33. $("h1").html(showName);
  34. $("h1").css({
  35. "color": "#267FD7",
  36. "borderBottom": "4px solid #E9E9E9",
  37. "padding": "0px 60px 50px 0px"
  38. });
  39. for (var i = 0; i < list.length; i++) {
  40. item = list[i];
  41. item.content = item.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix);
  42. anchors = '<li><i></i><a href="#' + item.title +
  43. '">' + item.title + '</a></li><li class="anchor-line"></li>';
  44. str = '<div class="title"><h2 id="' + item.title +
  45. '">'
  46. if (getUrlArgObject('type') == 8) {
  47. str += '【' + item.title + '】'
  48. } else {
  49. str += item.title
  50. }
  51. str += '</h2></div>' +
  52. '<div><pre>' + item.content + '</pre><div>';
  53. if (i != list.length - 1 && getUrlArgObject('type') != 8) {
  54. str += '<div class="line"></div>'
  55. }
  56. $(".infos").append(str);
  57. $(".anchors ul").append(anchors);
  58. }
  59. addLinkClickEvent();
  60. adjustHeight();
  61. function addScrollEvent() {
  62. var scrollTop = $('.infos').scrollTop()
  63. var divHeight = 0;
  64. for (var i = 0; i < list.length; i++) {
  65. divHeight = divHeight + parseInt($('#' + list[i].title).css('height')) + parseInt($('#' + list[i].title).parent().next().css('height')) + 40
  66. if (divHeight > scrollTop) {
  67. var anchor = 2 * i;
  68. $('.anchors ul').children().eq(anchor).addClass('active').siblings().removeClass('active');
  69. return;
  70. }
  71. }
  72. }
  73. $(".infos").scroll(throttle(addScrollEvent, 200));
  74. })
  75. }
  76. getInfomation();
  77. function addLinkClickEvent() {
  78. $("li:first").addClass("active");
  79. $("li>a").on("click", function () {
  80. $(".active").removeClass('active');
  81. $(this).parent().addClass("active");
  82. });
  83. }
  84. function adjustHeight() {
  85. var ht = window.innerHeight;
  86. $(".content").height(ht - 145 + "px");
  87. }
  88. $(window).on('resize', function(){
  89. adjustHeight()
  90. })