新增 管理员导入功能 #22

Merged
hy merged 1 commits from dev into staging 2025-10-14 11:08:03 +08:00
2 changed files with 77 additions and 1 deletions

25
src/api/admin.ts Normal file
View File

@ -0,0 +1,25 @@
import { http } from "@/utils/http";
import { Res } from "@/utils/http/types";
// import type { Res } from "@/utils/http/types";
/**
* @description
* @return {object}
*/
export function ImportAdminInfo( file: File) {
let formData = new FormData();
formData.append("file", file);
return http.request<any>(
"post",
`Admin/Import`,
{
data: formData
},
{
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
responseType: "blob"
}
);
}

View File

@ -4,6 +4,8 @@ import { ConditionalType, intTableData, TableConfig } from "@/components/hTable/
import { onMounted, ref, defineOptions } from "vue";
import { fa } from "element-plus/es/locales.mjs";
import { hTableAPI } from "@/api/hTable";
import { ElMessage } from "element-plus";
import { ImportAdminInfo } from "@/api/admin";
import {
ruleAccount,
rulePassword,
@ -60,11 +62,22 @@ const tableData: TableConfig = intTableData({
},
{
topBtn: false, //
show: true,
label: "删除",
btnType: "del", // add edit del
btnStyle: "danger", // topBtn: true success danger
},
{
topBtn: true, //
label: "导入",
click:entryAdminnfo,
btnStyle: "info", // topBtn: true success danger
},
{
topBtn: true, //
label: "导入模板",
click:DwImportTemplate,
btnStyle: "info", // topBtn: true success danger
},
],
column: {
//
@ -114,6 +127,44 @@ const tableData: TableConfig = intTableData({
selectRows: [],
});
function entryAdminnfo(eid: number) {
let fileE = document.createElement("input");
fileE.type = "file";
var formData = new window.FormData();
fileE.onchange = async function () {
formData.append("File", fileE.files[0]);
let res = await ImportAdminInfo(fileE.files[0]);
if (res.code != undefined) {
if (res.code !== 200) return ElMessage.error(res.message);
else return ElMessage.success("所有数据录入成功");
} else if (res.type === "application/json") {
let json = JSON.parse(await res.text());
if (json !== undefined && json.code !== 200) {
return ElMessage.error(json.message);
} else {
return ElMessage.success("操所有数据录入成功作成功");
}
} else if (res === undefined || res.size === 0)
return ElMessage.success("所有数据录入成功");
const url = res && window.URL.createObjectURL(res);
const link = document.createElement("a");
link.href = url;
link.setAttribute("download","导入失败管理员信息.xlsx");
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
ElMessage.warning("导入失败,已导出错误数据");
};
try {
fileE.click();
} catch (error) { }
}
function DwImportTemplate(obj, row, callBack) {
const baseUrl = import.meta.env.VITE_API_BASEURL;
const excelImportUsersUrl = `${baseUrl}/Admin/DwImportTemplate`;
window.open(excelImportUsersUrl, "_blank");
}
const showTable = ref(false);
onMounted(async () => {
//