previewfile.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. (function($) {
  2. 'use strict';
  3. $.extend($.fn.bootstrapTable.defaults, {
  4. previewfile: true,
  5. });
  6. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  7. _initTable = BootstrapTable.prototype.initTable,
  8. _initBody = BootstrapTable.prototype.initBody;
  9. BootstrapTable.prototype.initTable = function() {
  10. _initTable.apply(this, Array.prototype.slice.apply(arguments));
  11. if (!this.options.previewfile) {
  12. return;
  13. }
  14. $.each(this.columns, function(i, column) {
  15. if (!column.previewfile) {
  16. return;
  17. }
  18. column.formatter = function(value, row, index) {
  19. var result = column._formatter ? column._formatter(value, row, index) : value;
  20. var tpl = '';
  21. var video_url_array = []
  22. if(result){
  23. video_url_array = result.split(',');
  24. }
  25. video_url_array.forEach(function(url){
  26. var ext = url.slice(url.lastIndexOf(".")+1).toLowerCase();
  27. if(ext.lastIndexOf("?") > -1){
  28. ext = ext.slice(0,ext.lastIndexOf("?")).toLowerCase();
  29. }
  30. var img = '/assets/addons/previewfile/image/file.png';
  31. var title = '文件预览';
  32. if(ext == 'docx' || ext == 'doc') {
  33. img = '/assets/addons/previewfile/image/word.png';
  34. title = 'Word文档预览';
  35. }else if(ext == 'xlsx' || ext == 'xls' || ext == 'csv'){
  36. img = '/assets/addons/previewfile/image/excel.png';
  37. title = 'Execl文档预览';
  38. }else if(ext == 'pdf'){
  39. img = '/assets/addons/previewfile/image/pdf.png';
  40. title = 'PDF文件预览';
  41. }else if(ext == 'ppt' || ext == 'pptx'){
  42. img = '/assets/addons/previewfile/image/pptx.png';
  43. title = 'PPT文件预览';
  44. }else if(ext == 'mp4'){
  45. img = '/assets/addons/previewfile/image/video.png';
  46. title = '视频播放';
  47. }
  48. tpl += '<a href="javascript:void(0)"'+
  49. ' data-name="' + column.field + '"'+
  50. ' data-title="' + title + '"'+
  51. ' data-url="' + url + '" >'+
  52. '<img src="'+img+'" class="img-sm img-center" ></a>';
  53. })
  54. return [tpl].join('');
  55. };
  56. });
  57. };
  58. BootstrapTable.prototype.initBody = function() {
  59. var that = this;
  60. _initBody.apply(this, Array.prototype.slice.apply(arguments));
  61. if (!this.options.previewfile) {
  62. return;
  63. }
  64. $.each(this.columns, function(i, column) {
  65. if (!column.previewfile) {
  66. return;
  67. }
  68. that.$body.find('a[data-name="' + column.field + '"]').click(function(v){
  69. var url = $(this).data('url');
  70. var title = $(this).data('title');
  71. window.Fast.api.open('/addons/previewfile/index?url='+url, title,{
  72. callback:function(value){
  73. }
  74. })
  75. })
  76. });
  77. };
  78. })(jQuery);