information.js 8.9 KB

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