mirror of
https://github.com/flipped-aurora/gin-vue-admin.git
synced 2026-09-21 20:35:16 +00:00
excel导入导出功能合并并且细节修改完成
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
import service from '@/utils/request';
|
||||
import { Message } from 'element-ui';
|
||||
|
||||
const handleFileError = (res, fileName) => {
|
||||
if (typeof(res.data) !== "undefined") {
|
||||
if (res.data.type == "application/json") {
|
||||
const reader = new FileReader();
|
||||
reader.onload = function() {
|
||||
let message = JSON.parse(reader.result).msg;
|
||||
Message({
|
||||
showClose: true,
|
||||
message: message,
|
||||
type: 'error'
|
||||
})
|
||||
};
|
||||
reader.readAsText(new Blob([res.data]));
|
||||
}
|
||||
} else {
|
||||
var downloadUrl = window.URL.createObjectURL(new Blob([res]));
|
||||
var a = document.createElement('a');
|
||||
a.style.display = 'none';
|
||||
a.href = downloadUrl;
|
||||
a.download = fileName;
|
||||
var event = new MouseEvent("click");
|
||||
a.dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags excel
|
||||
// @Summary 导出Excel
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/octet-stream
|
||||
// @Param data body model.ExcelInfo true "导出Excel文件信息"
|
||||
// @Success 200
|
||||
// @Router /excel/exportExcel [post]
|
||||
export const exportExcel = (tableData, fileName) => {
|
||||
service({
|
||||
url: "/excel/exportExcel",
|
||||
method: 'post',
|
||||
data: {
|
||||
fileName: fileName,
|
||||
infoList: tableData
|
||||
},
|
||||
responseType: 'blob'
|
||||
}).then((res) => {
|
||||
handleFileError(res, fileName)
|
||||
})
|
||||
}
|
||||
|
||||
// @Tags excel
|
||||
// @Summary 导入Excel文件
|
||||
// @Security ApiKeyAuth
|
||||
// @accept multipart/form-data
|
||||
// @Produce application/json
|
||||
// @Param file formData file true "导入Excel文件"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"导入成功"}"
|
||||
// @Router /excel/importExcel [post]
|
||||
export const loadExcelData = () => {
|
||||
return service({
|
||||
url: "/excel/loadExcel",
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
// @Tags excel
|
||||
// @Summary 下载模板
|
||||
// @Security ApiKeyAuth
|
||||
// @accept multipart/form-data
|
||||
// @Produce application/json
|
||||
// @Param fileName query fileName true "模板名称"
|
||||
// @Success 200
|
||||
// @Router /excel/downloadTemplate [get]
|
||||
export const downloadTemplate = (fileName) => {
|
||||
return service({
|
||||
url: "/excel/downloadTemplate",
|
||||
method: 'get',
|
||||
params: {
|
||||
fileName: fileName
|
||||
},
|
||||
responseType: 'blob'
|
||||
}).then((res) => {
|
||||
handleFileError(res, fileName)
|
||||
})
|
||||
}
|
||||
@@ -1,30 +1,4 @@
|
||||
import service from '@/utils/request';
|
||||
import { Message } from 'element-ui';
|
||||
|
||||
const handleFileError = (res, fileName) => {
|
||||
if (typeof(res.data) !== "undefined") {
|
||||
if (res.data.type == "application/json") {
|
||||
const reader = new FileReader();
|
||||
reader.onload = function() {
|
||||
let message = JSON.parse(reader.result).msg;
|
||||
Message({
|
||||
showClose: true,
|
||||
message: message,
|
||||
type: 'error'
|
||||
})
|
||||
};
|
||||
reader.readAsText(new Blob([res.data]));
|
||||
}
|
||||
} else {
|
||||
var downloadUrl = window.URL.createObjectURL(new Blob([res]));
|
||||
var a = document.createElement('a');
|
||||
a.style.display = 'none';
|
||||
a.href = downloadUrl;
|
||||
a.download = fileName;
|
||||
var event = new MouseEvent("click");
|
||||
a.dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
// @Tags FileUploadAndDownload
|
||||
// @Summary 分页文件列表
|
||||
@@ -55,62 +29,4 @@ export const deleteFile = (data) => {
|
||||
method: "post",
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
// @Tags ExaFileUploadAndDownload
|
||||
// @Summary 导出Excel
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/octet-stream
|
||||
// @Param data body request.ExcelInfo true "导出Excel文件信息"
|
||||
// @Success 200
|
||||
// @Router /fileUploadAndDownload/exportExcel [post]
|
||||
export const exportExcel = (tableData, fileName) => {
|
||||
service({
|
||||
url: "/fileUploadAndDownload/exportExcel",
|
||||
method: 'post',
|
||||
data: {
|
||||
fileName: fileName,
|
||||
infoList: tableData
|
||||
},
|
||||
responseType: 'blob'
|
||||
}).then((res)=>{
|
||||
handleFileError(res, fileName)
|
||||
})
|
||||
}
|
||||
|
||||
// @Tags ExaFileUploadAndDownload
|
||||
// @Summary 导入Excel文件
|
||||
// @Security ApiKeyAuth
|
||||
// @accept multipart/form-data
|
||||
// @Produce application/json
|
||||
// @Param file formData file true "导入Excel文件"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"导入成功"}"
|
||||
// @Router /fileUploadAndDownload/importExcel [post]
|
||||
export const loadExcelData = () => {
|
||||
return service({
|
||||
url: "/fileUploadAndDownload/loadExcel",
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
// @Tags ExaFileUploadAndDownload
|
||||
// @Summary 下载模板
|
||||
// @Security ApiKeyAuth
|
||||
// @accept multipart/form-data
|
||||
// @Produce application/json
|
||||
// @Param fileName query fileName true "模板名称"
|
||||
// @Success 200
|
||||
// @Router /fileUploadAndDownload/downloadTemplate [get]
|
||||
export const downloadTemplate = (fileName) => {
|
||||
return service({
|
||||
url: "/fileUploadAndDownload/downloadTemplate",
|
||||
method: 'get',
|
||||
params:{
|
||||
fileName: fileName
|
||||
},
|
||||
responseType: 'blob'
|
||||
}).then((res)=>{
|
||||
handleFileError(res, fileName)
|
||||
})
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
<el-row>
|
||||
<el-col :span="2">
|
||||
<el-upload
|
||||
:action="`${path}/fileUploadAndDownload/importExcel`"
|
||||
:action="`${path}/excel/importExcel`"
|
||||
:headers="{'x-token':token}"
|
||||
:on-success="loadExcel"
|
||||
:show-file-list="false"
|
||||
@@ -37,7 +37,7 @@
|
||||
const path = process.env.VUE_APP_BASE_API;
|
||||
import { mapGetters } from 'vuex';
|
||||
import infoList from "@/mixins/infoList";
|
||||
import { exportExcel, loadExcelData, downloadTemplate } from "@/api/fileUploadAndDownload";
|
||||
import { exportExcel, loadExcelData, downloadTemplate } from "@/api/excel";
|
||||
import { getMenuList } from "@/api/menu";
|
||||
export default {
|
||||
name: 'Excel',
|
||||
|
||||
Reference in New Issue
Block a user