Selaa lähdekoodia

电子书和视频

zhangxc 5 vuotta sitten
vanhempi
commit
73c2642de5
4 muutettua tiedostoa jossa 162 lisäystä ja 18 poistoa
  1. 35 1
      src/css/information.less
  2. BIN
      src/images/txtIcon.png
  3. BIN
      src/images/vedioIcon.png
  4. 127 17
      src/js/information.js

+ 35 - 1
src/css/information.less

@@ -176,7 +176,41 @@
     background-color: #F5F6F7;
     background: url('../images/icon_current.png') center center no-repeat;
   }
-
+  .infos>.downBox{
+    margin-right: 0;
+  }
+  .downImg{
+    width: 29px;
+    margin-right: 10px;
+    position: relative;
+  }
+  .BtnBox,.txtBox{
+    margin-top: 20px;
+    text-align: center;
+  }
+  .txtBox{
+    line-height: 50px;
+    font-size: 14px;
+    font-weight: bold;
+    color: #333;
+    position: relative;
+  }
+  .sizeBox{
+    line-height:16px;
+    text-align: center;
+    color: #777777;
+  }
+  .download{
+    cursor: pointer;
+    display: inline-block;
+    width:80px;
+    height:34px;
+    line-height: 34px;
+    text-align: center;
+    background:rgba(59,158,208,1);
+    border-radius:4px;
+    color: #fff;
+  }
   a:visited {
     color: #777;
   }

BIN
src/images/txtIcon.png


BIN
src/images/vedioIcon.png


+ 127 - 17
src/js/information.js

@@ -4,10 +4,20 @@ const {
   throttle,
   imageUrlPrefix,
   config,
-  getUrlArgObject
+  getUrlArgObject,
+  isIe8
 } = require('./promise.js');
 const $ = require("jquery");
+let TxtICon = require('./../images/txtIcon.png')
+let VedioIcon = require('./../images/VedioIcon.png')
 
+if(isIe8()) {
+  let reg = /undefined/g
+  TxtICon = TxtICon.replace(reg, '')
+  VedioIcon = VedioIcon.replace(reg, '')
+}
+const isLocal = window.location.hostname.indexOf('localhost') !=-1;
+console.log('isLocal',isLocal)
 function getInfomation() {
   var param = {
     "type": getUrlArgObject('type'),
@@ -20,6 +30,12 @@ function getInfomation() {
     param.type = 12;
     param.name = uname;
   }
+  if (param.type == 82) {
+    param.position = "8";
+  }
+  if (param.type == 83) {
+    param.position = "9";
+  }
 
   post(config.information, param).then((res) => {
     const data = res.data.data
@@ -33,30 +49,62 @@ function getInfomation() {
       return;
     }
     var list = data.details;
-    $("h1").html(showName);
+    
     // $("h1").css({
     //   "color": "#267FD7",
     //   "borderBottom": "4px solid  #E9E9E9",
     //   "padding": "0px 60px 50px 0px"
     // });
-    for (var i = 0; i < list.length; i++) {
-      item = list[i];
-      item.content = item.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix);
-      anchors = '<li><i></i><a href="#' + item.title +
-        '">' + item.title + '</a></li><li class="anchor-line"></li>';
-      str = '<div class="infoBox"><div class="title"> <div class= "circleBox"><span class="circle"> <span></div> <h2 class="titleH2" id="' + item.title +
-        '">'
-      if (getUrlArgObject('type') == 8) {
-        str += '【' + item.title + '】'
-      } else {
-        str += item.title
+    if(param.type == 82 || param.type == 83){
+      console.log('list',list)
+      for (var i = 0; i < list.length; i++) {
+        item = list[i];
+        let contentObj = JSON.parse(item.content)
+        // anchors = '<li><i></i><a href="#' + item.title +
+        //   '">' + item.title + '</a></li><li class="anchor-line"></li>';
+        // str = '<div class="infoBox"><div class="title"> <div class= "circleBox"><span class="circle"> <span></div> <h2 class="titleH2" id="' + item.title +
+        //   '">'
+        // if (getUrlArgObject('type') == 8) {
+        //   str += '【' + item.title + '】'
+        // } else {
+        //   str += item.title
+        // }
+        // str += '</h2></div>' +
+        //   '<div><pre>' + item.content + '</pre><div></div>';
+        //   str = `<div class="infoWrapper">${str}</div>`
+        // $(".infos").append(str);
+        $(".anchors").css("display","none");
+        // $(".anchors ul").append(anchors);
+        str = `<div class="downBox">
+          <p class="txtBox"><img style="top:${param.type == '82' ? '11px':'13px'}" class="downImg" src="${param.type == '82' ? TxtICon:VedioIcon}">${item.title}</p>
+         <p class="sizeBox">文件大小${contentObj.size}</p>
+          <div class="BtnBox"><span class="download" data-url="${contentObj.url}" data-title="${contentObj.name}">下载</span></div>
+        </div>`
       }
-      str += '</h2></div>' +
-        '<div><pre>' + item.content + '</pre><div></div>';
-        str = `<div class="infoWrapper">${str}</div>`
       $(".infos").append(str);
-      $(".anchors ul").append(anchors);
+      downLoadFile()
+    }else{
+      $("h1").html(showName);
+      for (var i = 0; i < list.length; i++) {
+        item = list[i];
+        item.content = item.content.replace(/{imageUrlPrefix}/g, imageUrlPrefix);
+        anchors = '<li><i></i><a href="#' + item.title +
+          '">' + item.title + '</a></li><li class="anchor-line"></li>';
+        str = '<div class="infoBox"><div class="title"> <div class= "circleBox"><span class="circle"> <span></div> <h2 class="titleH2" id="' + item.title +
+          '">'
+        if (getUrlArgObject('type') == 8) {
+          str += '【' + item.title + '】'
+        } else {
+          str += item.title
+        }
+        str += '</h2></div>' +
+          '<div><pre>' + item.content + '</pre><div></div>';
+          str = `<div class="infoWrapper">${str}</div>`
+        $(".infos").append(str);
+        $(".anchors ul").append(anchors);
+      }
     }
+    
     addLinkClickEvent();
     adjustHeight();
     $('.content img').bind('contextmenu', function(){
@@ -86,6 +134,68 @@ function addLinkClickEvent() {
     $(this).parent().addClass("active");
   });
 }
+
+function downLoadFile() {
+  $(".download").on("click", function(){
+    const downUrl = $(this).attr('data-url')
+    const url = isLocal ?'http://192.168.2.236:82'+downUrl + '?download=1' : window.location.hostname+':82'+downUrl + '?download=1'
+    console.log('urlurl',url)
+    const downTitle = $(this).attr('data-title')
+    download(url, downTitle)
+  })
+
+  // var $form = $('<form method="GET"></form>');
+  // $form.attr('action', url);
+  // $form.appendTo($('body'));
+  // $form.submit();
+
+//     const ele = document.createElement('a');
+//     ele.setAttribute('download' , 'download');//用于设置下载文件的文件名
+
+//     ele.setAttribute('href',url); //设置下载文件的url地址
+
+
+//     ele.click();
+
+
+}
+function getBlob(url,cb) {
+  var xhr = new XMLHttpRequest();
+  xhr.open('GET', url, true);
+  xhr.responseType = 'blob';
+  xhr.onload = function() {
+          if (xhr.status === 200) {
+              cb(xhr.response);
+          }
+  };
+  xhr.send();
+}
+function saveAs(blob, filename) {
+  if (window.navigator.msSaveOrOpenBlob) {
+      navigator.msSaveBlob(blob, filename);
+  } else {
+      var link = document.createElement('a');
+      var body = document.querySelector('body');
+
+      link.href = window.URL.createObjectURL(blob);
+      link.download = filename;
+
+      // fix Firefox
+      link.style.display = 'none';
+      body.appendChild(link);
+      
+      link.click();
+      body.removeChild(link);
+
+      window.URL.revokeObjectURL(link.href);
+  };
+}
+function download(url, filename){
+  getBlob(url, function(blob) {
+      saveAs(blob, filename);
+  });
+}
+
 function adjustHeight() {
   var ht = window.innerHeight;
   $(".content").height(ht - 145 + "px");