取消表格导出功能,修复回滚(删表)功能的painc (#1310)

* [feature]:取消表格导出功能

* 修复回滚(删表)painc的问题

* [feature]:修改初始化
This commit is contained in:
奇淼(piexlmax
2022-12-12 14:42:47 +08:00
committed by GitHub
parent 0627359b6e
commit e47a512fc8
19 changed files with 21 additions and 461 deletions

View File

@@ -1,85 +0,0 @@
import service from '@/utils/request'
import { ElMessage } from 'element-plus'
const handleFileError = (res, fileName) => {
if (typeof (res.data) !== 'undefined') {
if (res.data.type === 'application/json') {
const reader = new FileReader()
reader.onload = function() {
const message = JSON.parse(reader.result).msg
ElMessage({
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)
})
}

View File

@@ -1,93 +0,0 @@
<template>
<div class="upload">
<div class="gva-table-box">
<div class="gva-btn-list">
<el-upload
class="excel-btn"
:action="`${path}/excel/importExcel`"
:headers="{'x-token':userStore.token}"
:on-success="loadExcel"
:show-file-list="false"
>
<el-button size="small" type="primary" icon="upload">导入</el-button>
</el-upload>
<el-button class="excel-btn" size="small" type="primary" icon="download" @click="handleExcelExport('ExcelExport.xlsx')">导出</el-button>
<el-button class="excel-btn" size="small" type="success" icon="download" @click="downloadExcelTemplate()">下载模板</el-button>
</div>
<el-table :data="tableData" row-key="ID">
<el-table-column align="left" label="ID" min-width="100" prop="ID" />
<el-table-column align="left" show-overflow-tooltip label="路由Name" min-width="160" prop="name" />
<el-table-column align="left" show-overflow-tooltip label="路由Path" min-width="160" prop="path" />
<el-table-column align="left" label="是否隐藏" min-width="100" prop="hidden">
<template #default="scope">
<span>{{ scope.row.hidden?"隐藏":"显示" }}</span>
</template>
</el-table-column>
<el-table-column align="left" label="父节点" min-width="90" prop="parentId" />
<el-table-column align="left" label="排序" min-width="70" prop="sort" />
<el-table-column align="left" label="文件路径" min-width="360" prop="component" />
</el-table>
</div>
</div>
</template>
<script>
export default {
name: 'Excel',
}
</script>
<script setup>
import { useUserStore } from '@/pinia/modules/user'
import { exportExcel, loadExcelData, downloadTemplate } from '@/api/excel'
import { getMenuList } from '@/api/menu'
import { ref } from 'vue'
const path = ref(import.meta.env.VITE_BASE_API)
const page = ref(1)
const total = ref(0)
const pageSize = ref(999)
const tableData = ref([])
// 查询
const getTableData = async(f = () => {}) => {
const table = await f({ page: page.value, pageSize: pageSize.value })
if (table.code === 0) {
tableData.value = table.data.list
total.value = table.data.total
page.value = table.data.page
pageSize.value = table.data.pageSize
}
}
getTableData(getMenuList)
const userStore = useUserStore()
const handleExcelExport = (fileName) => {
if (!fileName || typeof fileName !== 'string') {
fileName = 'ExcelExport.xlsx'
}
exportExcel(tableData.value, fileName)
}
const loadExcel = () => {
getTableData(loadExcelData)
}
const downloadExcelTemplate = () => {
downloadTemplate('ExcelTemplate.xlsx')
}
</script>
<style lang="scss" scoped>
.btn-list{
display: flex;
margin-bottom: 12px;
justify-content: flex-end;
}
.excel-btn+.excel-btn{
margin-left: 10px;
}
</style>