data.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import store from '@/store'
  2. import { baseURL } from '@/utils/http'
  3. export type FileListType = {
  4. id: number
  5. fileName: string
  6. filePath: string
  7. thumb: string
  8. type: 'img' | 'video' | 'doc'
  9. }
  10. // 查看 权限 图片 /视频 、音频
  11. export const authFilesLookFu = (name: string, url: string) => {
  12. let flag = false
  13. const nameRes = name ? name : ''
  14. // pdf和txt 直接新窗口打开
  15. const arr0: ('.pdf' | '.txt')[] = ['.pdf', '.txt']
  16. arr0.forEach(v => {
  17. if (nameRes.toLowerCase().endsWith(v)) {
  18. if (url) window.open(baseURL + url)
  19. flag = true
  20. }
  21. })
  22. // 图片使用 antd的图片预览组件
  23. const arr1 = ['.png', '.jpg', '.jpeg', '.gif']
  24. arr1.forEach(v => {
  25. if (nameRes.toLowerCase().endsWith(v)) {
  26. if (url) {
  27. store.dispatch({
  28. type: 'layout/lookBigImg',
  29. payload: {
  30. url: baseURL + url,
  31. show: true
  32. }
  33. })
  34. }
  35. flag = true
  36. }
  37. })
  38. // 视频和音频 使用自己的封装的组件
  39. let type: '' | 'video' | 'audio' = ''
  40. const arr2 = ['.mp3', '.wav']
  41. arr2.forEach(v => {
  42. if (nameRes.toLowerCase().endsWith(v)) {
  43. type = 'audio'
  44. flag = true
  45. }
  46. })
  47. if (nameRes.toLowerCase().endsWith('.mp4')) {
  48. type = 'video'
  49. flag = true
  50. }
  51. if (type && url) {
  52. store.dispatch({
  53. type: 'layout/lookDom',
  54. payload: {
  55. src: url,
  56. type
  57. }
  58. })
  59. }
  60. return flag
  61. }