information.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. require('../css/information.less')
  2. const {
  3. post,
  4. throttle,
  5. imageUrlPrefix,
  6. config,
  7. getUrlArgObject,
  8. isIe8
  9. } = require('./promise.js');
  10. const $ = require("jquery");
  11. let TxtICon = require('./../images/txtIcon.png')
  12. let VedioIcon = require('./../images/vedioIcon.png')
  13. if(isIe8()) {
  14. let reg = /undefined/g
  15. TxtICon = TxtICon.replace(reg, '')
  16. VedioIcon = VedioIcon.replace(reg, '')
  17. }
  18. const isLocal = window.location.hostname.indexOf('localhost') !=-1;
  19. function getInfomation() {
  20. var param = {
  21. "type": getUrlArgObject('type'),
  22. "name": getUrlArgObject('name'),
  23. "position": getUrlArgObject('position')
  24. };
  25. const uname = getUrlArgObject('uname')
  26. const showName = param.name
  27. if (param.type == 5 || param.type == 51) {
  28. param.type = 12;
  29. param.name = uname;
  30. }
  31. if (param.type == 82) {
  32. param.position = "8";
  33. }
  34. if (param.type == 83) {
  35. param.position = "9";
  36. }
  37. post(config.information, param).then((res) => {
  38. const data = res.data.data
  39. document.title = showName
  40. var str = '';
  41. var anchors = '';
  42. var item = '';
  43. if (!data) {
  44. $("h1").html("暂时没有数据");
  45. $(".anchors").css("display", "none");
  46. return;
  47. }
  48. var list = data.details;
  49. // $("h1").css({
  50. // "color": "#267FD7",
  51. // "borderBottom": "4px solid #E9E9E9",
  52. // "padding": "0px 60px 50px 0px"
  53. // });
  54. if(param.type == 82 || param.type == 83){
  55. for (var i = 0; i < list.length; i++) {
  56. item = list[i];
  57. let contentObj = JSON.parse(item.content)
  58. // anchors = '<li><i></i><a href="#' + item.title +
  59. // '">' + item.title + '</a></li><li class="anchor-line"></li>';
  60. // str = '<div class="infoBox"><div class="title"> <div class= "circleBox"><span class="circle"> <span></div> <h2 class="titleH2" id="' + item.title +
  61. // '">'
  62. // if (getUrlArgObject('type') == 8) {
  63. // str += '【' + item.title + '】'
  64. // } else {
  65. // str += item.title
  66. // }
  67. // str += '</h2></div>' +
  68. // '<div><pre>' + item.content + '</pre><div></div>';
  69. // str = `<div class="infoWrapper">${str}</div>`
  70. // $(".infos").append(str);
  71. $(".anchors").css("display","none");
  72. // $(".anchors ul").append(anchors);
  73. str = `<div class="downBox">
  74. <p class="txtBox"><img style="top:${param.type == '82' ? '11px':'13px'}" class="downImg" src="${param.type == '82' ? TxtICon:VedioIcon}">${item.title}</p>
  75. <p class="sizeBox">文件大小${contentObj.size}</p>
  76. <div class="BtnBox"><span class="download" data-url="${contentObj.url}" data-title="${contentObj.name}">下载</span></div>
  77. </div>`
  78. }
  79. $(".infos").append(str);
  80. downLoadFile()
  81. }else{
  82. $("h1").html(showName);
  83. for (var i = 0; i < list.length; i++) {
  84. item = list[i];
  85. item.content = item.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix);
  86. anchors = '<li><i></i><a href="#' + item.title +
  87. '">' + item.title + '</a></li><li class="anchor-line"></li>';
  88. str = '<div class="infoBox"><div class="title"> <div class= "circleBox"><span class="circle"> <span></div> <h2 class="titleH2" id="' + item.title +
  89. '">'
  90. if (getUrlArgObject('type') == 8) {
  91. str += '【' + item.title + '】'
  92. } else {
  93. str += item.title
  94. }
  95. str += '</h2></div>' +
  96. '<div><pre>' + item.content + '</pre><div></div>';
  97. str = `<div class="infoWrapper">${str}</div>`
  98. $(".infos").append(str);
  99. $(".anchors ul").append(anchors);
  100. }
  101. }
  102. addLinkClickEvent();
  103. adjustHeight();
  104. adjustWidth()
  105. $('.content img').bind('contextmenu', function(){
  106. return false
  107. })
  108. function addScrollEvent() {
  109. var scrollTop = $('.infos').scrollTop()
  110. var divHeight = 0;
  111. for (var i = 0; i < list.length; i++) {
  112. divHeight = divHeight + parseInt($('#' + list[i].title).css('height')) + parseInt($('#' + list[i].title).parent().next().css('height')) + 30
  113. if (divHeight > scrollTop) {
  114. var anchor = 2 * (i);
  115. $('.anchors ul').children().eq(anchor).addClass('active').siblings().removeClass('active');
  116. return;
  117. }
  118. }
  119. }
  120. $(".infos").scroll(throttle(addScrollEvent, 200));
  121. })
  122. }
  123. getInfomation();
  124. function addLinkClickEvent() {
  125. $(".anchors ul li:first").addClass("active");
  126. $(".anchors ul li>a").on("click", function () {
  127. $(".active").removeClass('active');
  128. $(this).parent().addClass("active");
  129. });
  130. }
  131. function downLoadFile() {
  132. $(".download").on("click", function(){
  133. const downUrl = $(this).attr('data-url')
  134. const url = isLocal ?'http://192.168.2.236:82'+downUrl + '?download=1' : 'http://'+window.location.hostname+':82'+downUrl + '?download=1'
  135. console.log('urlurl',url)
  136. const downTitle = $(this).attr('data-title')
  137. // download(url, downTitle)
  138. downLoadFileIe(url, downTitle)
  139. })
  140. // var $form = $('<form method="GET"></form>');
  141. // $form.attr('action', url);
  142. // $form.appendTo($('body'));
  143. // $form.submit();
  144. // const ele = document.createElement('a');
  145. //   ele.setAttribute('download' , 'download');//用于设置下载文件的文件名
  146. //   ele.setAttribute('href',url); //设置下载文件的url地址
  147. //   ele.click();
  148. }
  149. // function getBlob(url,cb) {
  150. // var xhr = new XMLHttpRequest();
  151. // xhr.open('GET', url, true);
  152. // xhr.responseType = 'blob';
  153. // xhr.onload = function() {
  154. // if (xhr.status === 200) {
  155. // cb(xhr.response);
  156. // }
  157. // };
  158. // xhr.send();
  159. // }
  160. // function saveAs(blob, filename) {
  161. // if (window.navigator.msSaveOrOpenBlob) {
  162. // navigator.msSaveBlob(blob, filename);
  163. // } else {
  164. // var link = document.createElement('a');
  165. // var body = document.querySelector('body');
  166. // link.href = window.URL.createObjectURL(blob);
  167. // link.download = filename;
  168. // // fix Firefox
  169. // link.style.display = 'none';
  170. // body.appendChild(link);
  171. // link.click();
  172. // body.removeChild(link);
  173. // window.URL.revokeObjectURL(link.href);
  174. // };
  175. // }
  176. // function download(url, filename){
  177. // getBlob(url, function(blob) {
  178. // saveAs(blob, filename);
  179. // });
  180. // }
  181. function adjustWidth() {
  182. var wt = window.innerWidth || document.documentElement.clientWidth;
  183. $(".titleH2").width(wt- 0.2*wt -33 - 200 - 17 - 40 -15 + 'px')
  184. $("pre").width(wt- 0.2*wt -33 - 200 - 17 - 40 -15 + 'px')
  185. }
  186. function adjustHeight() {
  187. var ht = window.innerHeight || document.documentElement.clientHeight;
  188. $(".content").height(ht - 145 + "px");
  189. }
  190. $(window).on('resize', function(){
  191. adjustHeight()
  192. adjustWidth()
  193. })
  194. function downLoadFileIe (url, name) {
  195. if (!!window.ActiveXObject || "ActiveXObject" in window) {
  196. //ie
  197. var oPow = window.open(url, "", "width = 1, height = 1, top = 5000, left = 5000 ");
  198. var isOpen = true; //判断window.open是否被禁用
  199. try {
  200. if (oPow == null) {
  201. isOpen = false
  202. }
  203. } catch (err) {
  204. isOpen = false
  205. }
  206. if (isOpen) {
  207. //没禁用window.open采用window.open下载
  208. // while (oPow.document.readyState !== "complete") {
  209. // if (oPow.document.readyState === "complete") break;
  210. // }
  211. oPow.document.execCommand("SaveAs", true, name);
  212. oPow.close();
  213. } else {
  214. //禁用了window.open采用iframe下载
  215. var oIrame = document.createElement('iframe');
  216. oIrame.style.width = "0px";
  217. oIrame.style.height = "0px";
  218. oIrame.style.opacity = 1;
  219. document.body.appendChild(oIrame)
  220. oIrame.src = url;
  221. var IfDoc = oIrame.contentDocument || oIrame.document;
  222. oIrame.onreadystatechange = function () { // IE下的节点都有onreadystatechange这个事件
  223. if (oIrame.readyState == "complete") {
  224. // oIrame.execCommand("SaveAs", true, name)
  225. document.body.removeChild(oIrame)
  226. }
  227. };
  228. }
  229. } else {
  230. if (typeof url == 'object' && url instanceof Blob) {
  231. url = URL.createObjectURL(url); // 创建blob地址
  232. }
  233. var aLink = document.createElement('a');
  234. aLink.href = url;
  235. aLink.download = name || ''; // HTML5新增的属性,指定保存文件名,可以不要后缀,注意,file:///模式下不会生效
  236. var event;
  237. if (window.MouseEvent) {
  238. event = new MouseEvent('click');
  239. } else {
  240. if (document.createEvent) {
  241. event = document.createEvent('MouseEvents');
  242. event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  243. }
  244. }
  245. aLink.dispatchEvent(event);
  246. }
  247. }