Нет описания

StudyMaterialDeail.js 6.8KB

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