Sin descripción

StudyMaterialDeail.js 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /**
  2. * 文件资料详情
  3. * */
  4. $(function() {
  5. // var fid = helper.request.queryString("edit_id");
  6. var fid = getQueryString("edit_id");
  7. if(fid) {
  8. getBtnsInfo(fid);
  9. }
  10. });
  11. //获取详情
  12. function getBtnsInfo(fid) {
  13. $.ajax({
  14. type: "get",
  15. url: huayi.config.callcenter_url + "equipmentapi/api/StudyMaterialsInfo/getdetails",
  16. dataType: 'json',
  17. async: true,
  18. data: {
  19. id: fid
  20. },
  21. success: function(data) {
  22. /*验证请求*/
  23. if(data.state == "success") {
  24. var res = data.data;
  25. if(res) {
  26. $("#projectname").text(res.projectname);
  27. $("#user").text(res.createby);
  28. $("#createtime").text(res.createtime);
  29. $("#columsTitle").text(res.title);
  30. $("#decription").html(decodeURIComponent((res.content)));
  31. //附件
  32. var EnclosureList = res.studymaterfile;
  33. if(EnclosureList && EnclosureList.length > 0) {
  34. var $list = $("#fileList");
  35. $.each(EnclosureList, function(i, v) {
  36. if(v.filesmallurl) {
  37. //原来的图片
  38. var $li = $(
  39. '<li><span class="img_mask"><a href="' + v.fileurl + '" download="filename" title="点击下载"><i class="glyphicon glyphicon-download-alt" aria-hidden="true"></i></a></span>' +
  40. '<img layer-src="' + v.fileurl + '" src="' + v.filesmallurl + '" title="图片" alt="' + v.filename + '"/>' +
  41. '<span class="file_name">' + v.filename + '</span>' +
  42. '</li>'
  43. );
  44. $list.append($li);
  45. } else {
  46. if(v.fileext === '.pdf') {
  47. var $liFile = $(
  48. '<li><span class="img_mask"><a href="' + v.fileurl + '" download="filename" title="点击下载"><i class="glyphicon glyphicon-download-alt" aria-hidden="true"></i></a></span>' +
  49. '<div onclick="btn_views(\'' + v.fileurl + '\')" class="noThumb thumb" title="文件"><i class="glyphicon glyphicon-paperclip"></i><p>点击预览</p></div>' +
  50. '<span class="file_name">' + v.filename + '</span>' +
  51. '</li>'
  52. );
  53. } else {
  54. var $liFile = $(
  55. '<li><span class="img_mask"><a href="' + v.fileurl + '" download="filename" title="点击下载"><i class="glyphicon glyphicon-download-alt" aria-hidden="true"></i></a></span>' +
  56. '<div class="noThumb" title="文件"><i class="glyphicon glyphicon-paperclip"></i><p>无法预览</p></div>' +
  57. '<span class="file_name">' + v.filename + '</span>' +
  58. '</li>'
  59. );
  60. }
  61. $list.append($liFile);
  62. }
  63. });
  64. layer.photos({
  65. photos: '#fileList',
  66. anim: 5, //0-6的选择,指定弹出图片动画类型,默认随机(请注意,3.0之前的版本用shift参数)
  67. title: '查看图片',
  68. move: '.layui-layer-title',
  69. shadeClose: false,
  70. closeBtn: 1,
  71. area: ['80%', '90%'],
  72. tab: function(pic, layero) {
  73. $('.layui-layer-content').on("mousewheel", function(e, d) {
  74. // helper.methods.zoomImg($('#layui-layer-photos').find('img[alt="' + pic.alt + '"]'), d);
  75. zoomImg($('#layui-layer-photos').find('img[alt="' + pic.alt + '"]'), d);
  76. $('#layui-layer-photos').find('img[alt="' + pic.alt + '"]').dragging({
  77. move: "both", //拖动方向,x y both
  78. randomPosition: false //初始位置是否随机
  79. });
  80. return false;
  81. });
  82. helper.methods.initLayerPhotos('#layui-layer-photos', pic, layero);
  83. },
  84. });
  85. } else {
  86. $("#fileList").html('<p class="abnormal">暂无内容。。。</p>');
  87. }
  88. }
  89. }
  90. }
  91. });
  92. }
  93. //生成pdf预览文件
  94. function btn_views(sfiles) {
  95. $('#the-canvas').empty();
  96. $('.preview_area').show();
  97. var url = sfiles;
  98. pdfjsLib.GlobalWorkerOptions.workerSrc =
  99. // '/js/pdfjs/pdf.worker.js';
  100. 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/2.0.943/pdf.worker.min.js';
  101. var pdfDoc = null,
  102. pageNum = 1,
  103. pageRendering = false,
  104. pageNumPending = null,
  105. scale = 1.5,
  106. canvas = document.getElementById('the-canvas'),
  107. ctx = canvas.getContext('2d');
  108. /**
  109. * Get page info from document, resize canvas accordingly, and render page.
  110. * @param num Page number.
  111. */
  112. function renderPage(num) {
  113. pageRendering = true;
  114. // Using promise to fetch the page
  115. pdfDoc.getPage(num).then(function(page) {
  116. var viewport = page.getViewport(scale);
  117. canvas.height = viewport.height;
  118. canvas.width = viewport.width;
  119. // Render PDF page into canvas context
  120. var renderContext = {
  121. canvasContext: ctx,
  122. viewport: viewport
  123. };
  124. var renderTask = page.render(renderContext);
  125. // Wait for rendering to finish
  126. renderTask.promise.then(function() {
  127. pageRendering = false;
  128. if(pageNumPending !== null) {
  129. // New page rendering is pending
  130. renderPage(pageNumPending);
  131. pageNumPending = null;
  132. }
  133. });
  134. });
  135. // Update page counters
  136. document.getElementById('page_num').textContent = num;
  137. }
  138. /**
  139. * If another page rendering in progress, waits until the rendering is
  140. * finised. Otherwise, executes rendering immediately.
  141. */
  142. function queueRenderPage(num) {
  143. if(pageRendering) {
  144. pageNumPending = num;
  145. } else {
  146. renderPage(num);
  147. }
  148. }
  149. /**
  150. * Displays previous page.
  151. */
  152. function onPrevPage() {
  153. if(pageNum <= 1) {
  154. return;
  155. }
  156. pageNum--;
  157. queueRenderPage(pageNum);
  158. }
  159. document.getElementById('prev').addEventListener('click', onPrevPage);
  160. /**
  161. * Displays next page.
  162. */
  163. function onNextPage() {
  164. if(pageNum >= pdfDoc.numPages) {
  165. return;
  166. }
  167. pageNum++;
  168. queueRenderPage(pageNum);
  169. }
  170. document.getElementById('next').addEventListener('click', onNextPage);
  171. /**
  172. * Asynchronously downloads PDF.
  173. */
  174. pdfjsLib.getDocument(url).then(function(pdfDoc_) {
  175. pdfDoc = pdfDoc_;
  176. document.getElementById('page_count').textContent = pdfDoc.numPages;
  177. // Initial/first page rendering
  178. renderPage(pageNum);
  179. });
  180. }
  181. function getQueryString(item) {
  182. var locationSearch = "";
  183. var tmpLocationArr = location.href.split("?");
  184. if(tmpLocationArr.length > 1) locationSearch = "?" + tmpLocationArr[1];
  185. var svalue = locationSearch.match(new RegExp("[\?\&]" + item + "=([^\&]*)(\&?)", "i"));
  186. var Qvalue = svalue ? svalue[1] : svalue;
  187. if(Qvalue == null) {
  188. return "";
  189. } else {
  190. return Qvalue.trim();
  191. }
  192. }
  193. /**
  194. * 鼠标滚轮放大缩小
  195. * o img元素
  196. * d 滚轮的方向
  197. * */
  198. function zoomImg(o, d) {
  199. //d 1 上 -1 下
  200. var width = $(o).width();
  201. var height = $(o).height();
  202. if(d === 1) {
  203. $(o).css({
  204. "left": "50%",
  205. "marginLeft": -(width * 1.2) / 2,
  206. "top": "50%",
  207. "marginTop": -(height * 1.2) / 2,
  208. "width": width * 1.2,
  209. "height": height * 1.2
  210. });
  211. }
  212. if(d === -1) {
  213. $(o).css({
  214. "left": "50%",
  215. "marginLeft": -(width * 1.2) / 2,
  216. "top": "50%",
  217. "marginTop": -(height * 1.2) / 2,
  218. "width": width / 1.2,
  219. "height": height / 1.2
  220. });
  221. }
  222. }