mixins.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { downLoad2 } from '@/utils'
  2. export const File = {
  3. methods: {
  4. downLoad(item){
  5. if(item.originalName){
  6. var href = `http://${this.$c.hostname}:8801/fileManager/downloadSystemFile?fileId=${item.id}`
  7. const anchor = document.createElement('a');
  8. const fileName = 'download';
  9. if ('download' in anchor) {
  10. anchor.href = href;
  11. anchor.setAttribute("download", fileName);
  12. anchor.className = "download-js-link";
  13. anchor.innerHTML = "downloading...";
  14. anchor.style.display = "none";
  15. document.body.appendChild(anchor);
  16. setTimeout(function () {
  17. anchor.click();
  18. document.body.removeChild(anchor);
  19. }, 66);
  20. return true;
  21. }
  22. }else{
  23. downLoad2(item.url)
  24. }
  25. },
  26. preview(row){
  27. var item = JSON.parse(JSON.stringify(row))
  28. if(item.originalName){
  29. item.url = `http://${this.$c.hostname}:8801/fileManager/downloadSystemFile?fileId=${item.id}`
  30. var arr = ['png','jpeg','bmp','jpg']
  31. if(arr.includes(item.suffix)){
  32. var FileUrl = item.url
  33. var isPicture = 1
  34. }else if(item.suffix == 'pdf'){
  35. var FileUrl = item.url
  36. var isPicture = 0
  37. }else{
  38. var FileUrl = `http://${this.$c.hostname}:8012/onlinePreview?url=`+ btoa(encodeURIComponent(item.url))
  39. var isPicture = 0
  40. }
  41. const router = this.$router.resolve({
  42. path: '/checkFile',
  43. query: {
  44. row: JSON.stringify(item),
  45. FileUrl: FileUrl,
  46. isPicture:isPicture
  47. }
  48. })
  49. window.open(router.href, '_blank');
  50. return false
  51. }
  52. var arr = ['png','jpeg','bmp','jpg']
  53. if(arr.includes(item.suffix)){
  54. var FileUrl = this.$p + item.url
  55. var isPicture = 1
  56. }else if(item.suffix == 'pdf'){
  57. var FileUrl = this.$p + item.url
  58. var isPicture = 0
  59. }else{
  60. var FileUrl = `http://${this.$c.hostname}:8012/onlinePreview?url=`+ btoa(encodeURIComponent(this.$p + item.url))
  61. var isPicture = 0
  62. }
  63. const router = this.$router.resolve({
  64. path: '/checkFile',
  65. query: {
  66. row: JSON.stringify(item),
  67. FileUrl: FileUrl,
  68. isPicture:isPicture
  69. }
  70. })
  71. window.open(router.href, '_blank');
  72. },
  73. delFile(item){
  74. this.$emit('delFile',item.id)
  75. }
  76. },
  77. }