fileDetail.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { mapGetters } from 'vuex'
  2. import downloadFile from '~/utils/donwload-tools'
  3. export default {
  4. data() {
  5. return {
  6. fileId: '',
  7. fileData: {},
  8. }
  9. },
  10. computed: {
  11. ...mapGetters(['routePrefix', 'supplierInfo', 'authUserId']),
  12. fileType() {
  13. const mime = this.fileData.mime
  14. if (!mime) return 'other'
  15. if (mime.indexOf('image') > -1) return 'image'
  16. if (mime.indexOf('video') > -1) return 'video'
  17. return 'other'
  18. },
  19. },
  20. created() {
  21. this.fileId = this.$route.query.id
  22. this.fetchFileDetail()
  23. },
  24. methods: {
  25. async fetchFileDetail() {
  26. try {
  27. const res = await this.$http.api.fetchFileDetail({
  28. fileId: this.fileId,
  29. authUserId: this.authUserId,
  30. })
  31. this.fileData = res.data
  32. } catch (error) {
  33. console.log(error)
  34. }
  35. },
  36. // 下载文件
  37. onDownload(row, $event) {
  38. console.log(row)
  39. let downUrl = ''
  40. if (row.packageType === 0) {
  41. downUrl = `${process.env.BASE_URL}/wx/data/path/package/zip?fileId=${row.id}&fileName=${encodeURIComponent(row.fileName)}&authUserId=${this.authUserId}`
  42. } else {
  43. downUrl = `${process.env.BASE_URL}/download/file?ossName=${row.ossName}&fileName=${encodeURIComponent(row.fileName)}`
  44. }
  45. downloadFile(downUrl, row.fileName, this, $event)
  46. },
  47. },
  48. }