index.js 2.7 KB

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