index.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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: Function,
  13. deleteFile: Function,
  14. downLoadRecord: Function
  15. },
  16. lifetimes: {
  17. attached() {
  18. getApp().globalData.Language.getLanguagePackage(this)
  19. }
  20. },
  21. methods: {
  22. butClick(e) {
  23. const {
  24. item,
  25. type
  26. } = e.currentTarget.dataset;
  27. const that = this;
  28. if (type == '播放') {
  29. this.triggerEvent("callBack", item);
  30. } else if (type == '删除') {
  31. wx.showModal({
  32. title: getApp().globalData.Language.getMapText('提示'),
  33. content: getApp().globalData.Language.getMapText('是否确认删除该附件') + "?",
  34. cancelText: getApp().globalData.Language.getMapText('取消'),
  35. confirmText: getApp().globalData.Language.getMapText('确定'),
  36. success: res => {
  37. if (res.confirm) that.triggerEvent("deleteFile", item);
  38. }
  39. })
  40. } else if (type == '下载') {
  41. wx.downloadFile({
  42. url: item.url,
  43. success(res) {
  44. if (res.statusCode === 200) {
  45. wx.shareFileMessage({
  46. filePath: res.tempFilePath,
  47. fileName: item.document,
  48. success(res) {
  49. console.log("转发", res)
  50. },
  51. fail: console.error,
  52. })
  53. } else {
  54. getApp().globalData.Language.showToast('微信下载保存失败')
  55. }
  56. },
  57. fail() {
  58. getApp().globalData.Language.showToast('文件下载失败')
  59. }
  60. });
  61. this.triggerEvent("downLoadRecord");
  62. };
  63. },
  64. callback(e) {
  65. const {
  66. item
  67. } = e.currentTarget.dataset;
  68. this.triggerEvent("callBack", item);
  69. },
  70. checkFile(e) {
  71. const {
  72. item
  73. } = e.currentTarget.dataset;
  74. if (item.fileType == 'video' && this.data.butType == '商学院' || this.data.butType == '播放') return this.triggerEvent("callBack", item);
  75. cf.checkFile(item);
  76. }
  77. }
  78. })