12345678910111213141516171819202122232425262728293031323334353637 |
- import Vue from 'vue'
- import { downloadFile } from '@/utils'
- /**
- * 上传
- * @param {Promise} api 提交api
- * @param {File} file 文件
- * @param {Promise} init 实例
- */
- export async function upload (api, file) {
- const formData = new FormData()
- formData.append('file', file)
- try {
- await api(formData)
- Vue.prototype.$message.success('导入成功')
- return true
- } catch (error) {
- Vue.prototype.$message.error(error)
- }
- }
- /**
- * 下载
- * @param {Promise} api
- * @param {Object} params
- */
- export async function download (api, params) {
- try {
- const { data, name } = await api(params)
- downloadFile(data, name)
- return true
- } catch (error) {
- this.$message.error(error)
- }
- }
|