seatonwan9
2025-08-28 e126797e6062fde53359c9957c9da7fc51e284b2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 * @Description:图片流d url获取 和文件流url生成
 * @Version: 2.0
 * @Autor: wuyun
 * @Date: 2022-09-06 13:51:31
 * @LastEditors: wuyun
 * @LastEditTime: 2023-02-20 17:30:40
 */
import axios from 'axios'
import { useUserInfo } from '@/stores/modules/userInfo'
import commonApi from '@/api/commonApi'
 
const userInfoStore = useUserInfo()
export function getImgFlowUrl(id: string) {
  const config: any = {
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
      token: userInfoStore.getAdminToken
    },
    responseType: 'blob'
  }
 
  return new Promise((resolve, reject) => {
    axios
      .post('api/admin/common/filePreview', { fileId: id }, config)
      .then((res: any) => {
        resolve(res)
      })
      .catch((error) => {
        reject(error)
      })
  })
}
 
export function getImgFlowUrlT(id: string) {
  const config: any = {
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
      token: userInfoStore.getAdminToken
    },
    responseType: 'blob'
  }
 
  return new Promise((resolve, reject) => {
    axios
        .post('api/admin/common/url', { fileId: id }, config)
        .then((res: any) => {
 
          resolve(res)
        })
        .catch((error) => {
          reject(error)
        })
  })
}
 
// PDF预览方法
export function getFileFlowUrl(id: string) {
  return new Promise((resolve, reject) => {
    commonApi.getFileFlowById({ fileId: id }).then((res: any) => {
      let fileURL = ''
      var blob: any = new Blob([res.data], { type: 'application/pdf' })
      if (window.webkitURL != undefined) {
        // webkit or chrome
        try {
          fileURL = window.webkitURL.createObjectURL(blob)
        } catch (error) {
        }
      } else if (window.URL != undefined) {
        // mozilla(firefox)
        try {
          fileURL = window.URL.createObjectURL(blob)
        } catch (error) {
        }
      }
      window.open(fileURL)
      resolve(res)
    }).catch((error) => {
      reject(error)
    })
 
  })
}