导入导出
This commit is contained in:
@@ -88,19 +88,26 @@
|
||||
文明班级列表
|
||||
</span>
|
||||
<div class="header-actions">
|
||||
<el-button
|
||||
icon="Plus"
|
||||
type="primary"
|
||||
<el-button
|
||||
icon="Plus"
|
||||
type="primary"
|
||||
@click="formDialogRef.openDialog()">
|
||||
新增
|
||||
</el-button>
|
||||
<el-button
|
||||
icon="Upload"
|
||||
type="success"
|
||||
class="ml10"
|
||||
<el-button
|
||||
icon="Upload"
|
||||
type="success"
|
||||
class="ml10"
|
||||
@click="handleImport">
|
||||
导入
|
||||
</el-button>
|
||||
<el-button
|
||||
icon="Download"
|
||||
type="warning"
|
||||
class="ml10"
|
||||
@click="handleExport">
|
||||
导出
|
||||
</el-button>
|
||||
<right-toolbar
|
||||
v-model:showSearch="showSearch"
|
||||
class="ml10"
|
||||
@@ -254,7 +261,8 @@
|
||||
<script setup lang="ts" name="RewardClass">
|
||||
import { reactive, ref, onMounted } from 'vue'
|
||||
import { BasicTableProps, useTable } from "/@/hooks/table";
|
||||
import { fetchList, delObj, importExcel } from "/@/api/stuwork/rewardclass";
|
||||
import { fetchList, delObj } from "/@/api/stuwork/rewardclass";
|
||||
import { exportRewardClassTemplate, importRewardClass, downloadBlobFile } from "/@/api/stuwork/file";
|
||||
import { getDeptList } from "/@/api/basic/basicclass";
|
||||
import { getClassListByRole } from "/@/api/basic/basicclass";
|
||||
import { queryAllSchoolYear } from "/@/api/basic/basicyear";
|
||||
@@ -360,29 +368,14 @@ const handleImport = () => {
|
||||
uploadRef.value?.clearFiles()
|
||||
}
|
||||
|
||||
// 导出
|
||||
const handleExport = async () => {
|
||||
await downloadBlobFile(exportRewardClassTemplate(), '文明班级导入模板.xlsx')
|
||||
}
|
||||
|
||||
// 下载模板
|
||||
const handleDownloadTemplate = async () => {
|
||||
try {
|
||||
const fileName = '文明班级导入模板.xlsx'
|
||||
// 使用动态导入获取文件URL,从 views/stuwork/rewardclass 到 assets/file 的相对路径
|
||||
const fileUrl = new URL(`../../../assets/file/${fileName}`, import.meta.url).href
|
||||
const response = await fetch(fileUrl)
|
||||
if (!response.ok) {
|
||||
throw new Error('文件下载失败')
|
||||
}
|
||||
const blob = await response.blob()
|
||||
const url = window.URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
link.download = fileName
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
window.URL.revokeObjectURL(url)
|
||||
document.body.removeChild(link)
|
||||
useMessage().success('模板下载成功')
|
||||
} catch (error) {
|
||||
useMessage().error('模板下载失败,请检查模板文件是否存在')
|
||||
}
|
||||
await downloadBlobFile(exportRewardClassTemplate(), '文明班级导入模板.xlsx')
|
||||
}
|
||||
|
||||
// 文件变化
|
||||
@@ -396,10 +389,12 @@ const handleImportSubmit = async () => {
|
||||
useMessage().warning('请选择要导入的文件')
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
importLoading.value = true
|
||||
try {
|
||||
await importExcel(importFile.value)
|
||||
const formData = new FormData()
|
||||
formData.append('file', importFile.value)
|
||||
await importRewardClass(formData)
|
||||
useMessage().success('导入成功')
|
||||
importDialogVisible.value = false
|
||||
importFile.value = null
|
||||
|
||||
Reference in New Issue
Block a user