information.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. str = '<div class="infoBox"><div class="title"> <div class= "circleBox"><span class="circle"> <span></div> <h2 class="titleH2">'
  91. if (getUrlArgObject('type') == 8) {
  92. str += '【' + item.title + '】'
  93. } else {
  94. str += item.title
  95. }
  96. str += '</h2></div>' +
  97. '<div><pre>' + item.content + '</pre><div></div>';
  98. str = `<div class="infoWrapper">${str}</div>`
  99. $(".infos").append(str);
  100. $(".anchors ul").append(anchors);
  101. }
  102. }
  103. addLinkClickEvent();
  104. adjustHeight();
  105. adjustWidth()
  106. $('.content img').bind('contextmenu', function(){
  107. return false
  108. })
  109. function addScrollEvent() {
  110. var scrollTop = $('.infos').scrollTop()
  111. var divHeight = 0;
  112. for (var i = 0; i < list.length; i++) {
  113. divHeight = divHeight + parseInt($('#' + list[i].title).css('height')) + parseInt($('#' + list[i].title).parent().next().css('height')) + 40
  114. if (divHeight > scrollTop) {
  115. var anchor = 2 * i;
  116. $('.anchors ul').children().eq(anchor).addClass('active').siblings().removeClass('active');
  117. return;
  118. }
  119. }
  120. }
  121. $(".infos").scroll(throttle(addScrollEvent, 200));
  122. })
  123. }
  124. getInfomation();
  125. function addLinkClickEvent() {
  126. $(".anchors ul li:first").addClass("active");
  127. $(".anchors ul li>a").on("click", function () {
  128. $(".active").removeClass('active');
  129. $(this).parent().addClass("active");
  130. });
  131. }
  132. function downLoadFile() {
  133. $(".download").on("click", function(){
  134. const downUrl = $(this).attr('data-url')
  135. const url = isLocal ?'http://192.168.2.236:82'+downUrl + '?download=1' : 'http://'+window.location.hostname+':82'+downUrl + '?download=1'
  136. console.log('urlurl',url)
  137. const downTitle = $(this).attr('data-title')
  138. // download(url, downTitle)
  139. downLoadFileIe(url, downTitle)
  140. })
  141. // var $form = $('<form method="GET"></form>');
  142. // $form.attr('action', url);
  143. // $form.appendTo($('body'));
  144. // $form.submit();
  145. // const ele = document.createElement('a');
  146. //   ele.setAttribute('download' , 'download');//用于设置下载文件的文件名
  147. //   ele.setAttribute('href',url); //设置下载文件的url地址
  148. //   ele.click();
  149. }
  150. // function getBlob(url,cb) {
  151. // var xhr = new XMLHttpRequest();
  152. // xhr.open('GET', url, true);
  153. // xhr.responseType = 'blob';
  154. // xhr.onload = function() {
  155. // if (xhr.status === 200) {
  156. // cb(xhr.response);
  157. // }
  158. // };
  159. // xhr.send();
  160. // }
  161. // function saveAs(blob, filename) {
  162. // if (window.navigator.msSaveOrOpenBlob) {
  163. // navigator.msSaveBlob(blob, filename);
  164. // } else {
  165. // var link = document.createElement('a');
  166. // var body = document.querySelector('body');
  167. // link.href = window.URL.createObjectURL(blob);
  168. // link.download = filename;
  169. // // fix Firefox
  170. // link.style.display = 'none';
  171. // body.appendChild(link);
  172. // link.click();
  173. // body.removeChild(link);
  174. // window.URL.revokeObjectURL(link.href);
  175. // };
  176. // }
  177. // function download(url, filename){
  178. // getBlob(url, function(blob) {
  179. // saveAs(blob, filename);
  180. // });
  181. // }
  182. function adjustWidth() {
  183. var wt = window.innerWidth || document.documentElement.clientWidth;
  184. console.log('wt',wt)
  185. $(".titleH2").width(wt- 0.2*wt -33 - 200 - 17 - 40 -15 + 'px')
  186. $("pre").width(wt- 0.2*wt -33 - 200 - 17 - 40 -15 + 'px')
  187. }
  188. function adjustHeight() {
  189. var ht = window.innerHeight || document.documentElement.clientHeight;
  190. $(".content").height(ht - 145 + "px");
  191. }
  192. $(window).on('resize', function(){
  193. adjustHeight()
  194. adjustWidth()
  195. })
  196. function downLoadFileIe (url, name) {
  197. if (!!window.ActiveXObject || "ActiveXObject" in window) {
  198. //ie
  199. var oPow = window.open(url, "", "width = 1, height = 1, top = 5000, left = 5000 ");
  200. var isOpen = true; //判断window.open是否被禁用
  201. try {
  202. if (oPow == null) {
  203. isOpen = false
  204. }
  205. } catch (err) {
  206. isOpen = false
  207. }
  208. if (isOpen) {
  209. //没禁用window.open采用window.open下载
  210. // while (oPow.document.readyState !== "complete") {
  211. // if (oPow.document.readyState === "complete") break;
  212. // }
  213. oPow.document.execCommand("SaveAs", true, name);
  214. oPow.close();
  215. } else {
  216. //禁用了window.open采用iframe下载
  217. var oIrame = document.createElement('iframe');
  218. oIrame.style.width = "0px";
  219. oIrame.style.height = "0px";
  220. oIrame.style.opacity = 1;
  221. document.body.appendChild(oIrame)
  222. oIrame.src = url;
  223. var IfDoc = oIrame.contentDocument || oIrame.document;
  224. oIrame.onreadystatechange = function () { // IE下的节点都有onreadystatechange这个事件
  225. if (oIrame.readyState == "complete") {
  226. // oIrame.execCommand("SaveAs", true, name)
  227. document.body.removeChild(oIrame)
  228. }
  229. };
  230. }
  231. } else {
  232. if (typeof url == 'object' && url instanceof Blob) {
  233. url = URL.createObjectURL(url); // 创建blob地址
  234. }
  235. var aLink = document.createElement('a');
  236. aLink.href = url;
  237. aLink.download = name || ''; // HTML5新增的属性,指定保存文件名,可以不要后缀,注意,file:///模式下不会生效
  238. var event;
  239. if (window.MouseEvent) {
  240. event = new MouseEvent('click');
  241. } else {
  242. if (document.createEvent) {
  243. event = document.createEvent('MouseEvents');
  244. event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  245. }
  246. }
  247. aLink.dispatchEvent(event);
  248. }
  249. }