information.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. $('.content img').bind('contextmenu', function(){
  62. return false
  63. })
  64. function addScrollEvent() {
  65. var scrollTop = $('.infos').scrollTop()
  66. var divHeight = 0;
  67. for (var i = 0; i < list.length; i++) {
  68. divHeight = divHeight + parseInt($('#' + list[i].title).css('height')) + parseInt($('#' + list[i].title).parent().next().css('height')) + 40
  69. if (divHeight > scrollTop) {
  70. var anchor = 2 * i;
  71. $('.anchors ul').children().eq(anchor).addClass('active').siblings().removeClass('active');
  72. return;
  73. }
  74. }
  75. }
  76. $(".infos").scroll(throttle(addScrollEvent, 200));
  77. })
  78. }
  79. getInfomation();
  80. function addLinkClickEvent() {
  81. $("li:first").addClass("active");
  82. $("li>a").on("click", function () {
  83. $(".active").removeClass('active');
  84. $(this).parent().addClass("active");
  85. });
  86. }
  87. function adjustHeight() {
  88. var ht = window.innerHeight;
  89. $(".content").height(ht - 145 + "px");
  90. }
  91. $(window).on('resize', function(){
  92. adjustHeight()
  93. })