index.js 1.7 KB

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