index.js 2.7 KB

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