flies.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // const fs = wx.getFileSystemManager();
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. list: {
  8. type: Array,
  9. value: []
  10. },
  11. checkedId: {
  12. type: String,
  13. value: 0
  14. },
  15. changeId: {
  16. type: Function
  17. }
  18. },
  19. options: {
  20. addGlobalClass: true
  21. },
  22. /**
  23. * 组件的初始数据
  24. */
  25. data: {
  26. show: false,
  27. fileSelected: {},
  28. },
  29. /**
  30. * 组件的方法列表
  31. */
  32. methods: {
  33. /* 打开文件 */
  34. openFile(e) {
  35. const {
  36. item
  37. } = e.currentTarget.dataset;
  38. if (item.fileType == 'folder') {
  39. wx.navigateTo({
  40. url: '/pages/tabbar/smartStore/folder?item=' + JSON.stringify(item),
  41. })
  42. } else if (['image', 'video'].includes(item.fileType)) {
  43. this.preViewMedia(item)
  44. } else if (['word', 'excel', 'ppt', 'pdf'].includes(item.fileType)) {
  45. this.openDocument(item)
  46. } else {
  47. wx.setClipboardData({
  48. data: item.url,
  49. success: function () {
  50. wx.showToast({
  51. title: '当前文件类型不支持在线浏览,已将文件下载地址复制到剪切板,您可在浏览器中打开链接下载到本地浏览',
  52. icon: "none",
  53. duration: 5000
  54. });
  55. }
  56. })
  57. }
  58. },
  59. preViewMedia(item) {
  60. wx.previewMedia({
  61. sources: [{
  62. url: item.url,
  63. type: item.fileType,
  64. }],
  65. current: 0,
  66. showmenu: true
  67. })
  68. },
  69. openDocument(item) {
  70. wx.downloadFile({
  71. url: item.url,
  72. success: function (res) {
  73. console.log(res.tempFilePath)
  74. wx.openDocument({
  75. filePath: res.tempFilePath,
  76. fileType: item.postfix,
  77. showMenu: true,
  78. success: function (res) {
  79. console.log(res)
  80. console.log('打开文档成功')
  81. },
  82. fail: (err) => {
  83. wx.showToast({
  84. title: '打开失败',
  85. icon: "none"
  86. })
  87. }
  88. })
  89. }
  90. })
  91. },
  92. changeChecked(e) {
  93. this.triggerEvent("changeId", e.target.dataset.item)
  94. }
  95. }
  96. })