schangxiang@126.com
2025-04-29 27ba504441037666e787ded85b4af2f65be65c17
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
import { importFileToService, exportFileToClient } from '@/api/file'
import { ElMessage } from 'element-plus'
import { downloadFile } from '@/utils'
import dayjs from 'dayjs'
 
export const useFile = () => {
  /**
   * 导入文件
   * @param url
   */
  const importFile = async (url: string, file: File) => {
    const formData = new FormData()
    formData.append('file', file)
    await importFileToService(url, formData)
    ElMessage('导入成功')
  }
  /**
   * 导出文件
   * @param url
   */
  const exportFile = async (url: string, params: any, name: string) => {
    const res = await exportFileToClient(url, params)
    downloadFile(res, `${name}_${dayjs().format('YYYYMMDDHHMMss')}.xlsx`)
    ElMessage.success('导出成功')
  }
 
  return {
    importFile,
    exportFile,
  }
}