index.js 2.8 KB

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