Nessuna descrizione

StudyMaterialDeail.js 6.5KB

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