From a1865d4dbb0ede0fef12a9c244a22e812e1c5aab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=82=A5=E7=BE=8A?= <1048382248@qq.com> Date: Tue, 14 Oct 2025 10:57:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=E5=AF=BC=E5=85=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/admin.ts | 25 ++++++++++++++++++ src/views/admin/index.vue | 53 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 src/api/admin.ts diff --git a/src/api/admin.ts b/src/api/admin.ts new file mode 100644 index 0000000..04254f5 --- /dev/null +++ b/src/api/admin.ts @@ -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( + "post", + `Admin/Import`, + { + data: formData + }, + { + headers: { + "Content-Type": "application/x-www-form-urlencoded" + }, + responseType: "blob" + } + ); +} diff --git a/src/views/admin/index.vue b/src/views/admin/index.vue index d1b3168..4c21d29 100644 --- a/src/views/admin/index.vue +++ b/src/views/admin/index.vue @@ -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 () => { //初始化数据原 -- 2.40.1