zs
2025-04-29 716eeb4b87efbdc5b149410bbea4c1f35ac116ac
HIAWms/web/src/widgets/HIAWms/Controllers/File.ts
对比新文件
@@ -0,0 +1,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,
  }
}