file_preview.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. document.write('<script src="https://cdn.jsdelivr.net/npm/vue@2.6/dist/vue.min.js"></script>');
  2. document.write('<script src="https://cdn.jsdelivr.net/npm/vant@2.4/lib/vant.min.js"></script>');
  3. document.write('<script src="https://cdn.jsdelivr.net/npm/@vant/touch-emulator"></script>');
  4. document.write('<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vant@2.4/lib/index.css">');
  5. function filePreviewForMobile(id,filename,url,type){
  6. if(!type){
  7. // var fileName = url.substring(url.lastIndexOf('/')+1);
  8. var dotIndex = filename.lastIndexOf('.');
  9. var suffix = filename.substring(dotIndex+1);
  10. suffix = suffix.toLowerCase();
  11. if(suffix=='doc' || suffix=='docx'||suffix=='xls'||suffix=='xlsx'){
  12. type='office';
  13. }else if(suffix=='pdf'){
  14. type='pdf';
  15. }else {
  16. type='image';
  17. }
  18. }
  19. type=type.toLowerCase();
  20. if(type=='office'){//word excel
  21. $.get("weboffice/wps.do?url&_w_fname=" + filename+"&fileId="+id , function(result) {
  22. if(isPc()){
  23. window.open(result.wpsUrl);
  24. }else{
  25. location = result.wpsUrl;
  26. }
  27. },'json');
  28. }else if(type=='pdf'){
  29. var path='/hgl';
  30. if(typeof(webBasePath)!='undefined') {
  31. path=webBasePath
  32. }
  33. location=path+'/webpage/cn/com/lzt/pdf/web/pdfview.jsp?title='+encodeURI(filename)+'&file='+encodeURIComponent(url);
  34. }else if(type=='image'){
  35. vant.ImagePreview({
  36. images:[url]
  37. ,className:'imgView'
  38. });
  39. }
  40. }
  41. function isPc(){
  42. if (/(iPhone|iPad|iPod|iOS|Android)/i.test(navigator.userAgent)) { //移动端
  43. return false;
  44. }
  45. return true;
  46. }