index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. const cf = require("../../utils/checkFile")
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. butType: {
  8. type: String,
  9. value: "下载"
  10. },
  11. list: {
  12. type: Array,
  13. value: []
  14. },
  15. callBack: {
  16. type: Function
  17. },
  18. deleteFile: {
  19. type: Function
  20. }
  21. },
  22. options: {
  23. addGlobalClass: true
  24. },
  25. /**
  26. * 组件的初始数据
  27. */
  28. data: {
  29. },
  30. /**
  31. * 组件的方法列表
  32. */
  33. methods: {
  34. butClick(e) {
  35. const {
  36. item
  37. } = e.currentTarget.dataset;
  38. const that = this;
  39. if (this.data.butType == '播放') {
  40. this.triggerEvent("callBack", item);
  41. } else if (this.data.butType == '删除') {
  42. wx.showModal({
  43. title: "通知",
  44. content: "是否确认删除该附件?",
  45. success: res => {
  46. if (res.confirm) that.triggerEvent("deleteFile", item);
  47. }
  48. })
  49. } else if (this.data.butType == '下载') {
  50. wx.downloadFile({
  51. url: item.url,
  52. success(res) {
  53. if (res.statusCode === 200) {
  54. wx.shareFileMessage({
  55. filePath: res.tempFilePath,
  56. fileName: item.document,
  57. success(res) {
  58. console.log("转发", res)
  59. },
  60. fail: console.error,
  61. })
  62. } else {
  63. wx.showToast({
  64. title: '微信下载保存失败',
  65. icon: "none"
  66. })
  67. }
  68. },
  69. fail() {
  70. wx.showToast({
  71. title: '文件下载失败',
  72. icon: "none"
  73. })
  74. }
  75. })
  76. };
  77. },
  78. callback(e) {
  79. const {
  80. item
  81. } = e.currentTarget.dataset;
  82. this.triggerEvent("callBack", item);
  83. },
  84. checkFile(e) {
  85. const {
  86. item
  87. } = e.currentTarget.dataset;
  88. if (item.fileType == 'video' && this.data.butType == '商学院' || this.data.butType == '播放') return this.triggerEvent("callBack", item);
  89. cf.checkFile(item);
  90. }
  91. }
  92. })