Merge pull request '新增 管理员导入功能' (#22) from dev into staging
Reviewed-on: #22
This commit is contained in:
commit
67aa84d0b3
|
|
@ -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"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -4,6 +4,8 @@ import { ConditionalType, intTableData, TableConfig } from "@/components/hTable/
|
||||||
import { onMounted, ref, defineOptions } from "vue";
|
import { onMounted, ref, defineOptions } from "vue";
|
||||||
import { fa } from "element-plus/es/locales.mjs";
|
import { fa } from "element-plus/es/locales.mjs";
|
||||||
import { hTableAPI } from "@/api/hTable";
|
import { hTableAPI } from "@/api/hTable";
|
||||||
|
import { ElMessage } from "element-plus";
|
||||||
|
import { ImportAdminInfo } from "@/api/admin";
|
||||||
import {
|
import {
|
||||||
ruleAccount,
|
ruleAccount,
|
||||||
rulePassword,
|
rulePassword,
|
||||||
|
|
@ -60,11 +62,22 @@ const tableData: TableConfig = intTableData({
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
topBtn: false, // 头部按钮
|
topBtn: false, // 头部按钮
|
||||||
show: true,
|
|
||||||
label: "删除",
|
label: "删除",
|
||||||
btnType: "del", // 按钮类型 add edit del 不设置则 自定义按钮
|
btnType: "del", // 按钮类型 add edit del 不设置则 自定义按钮
|
||||||
btnStyle: "danger", // topBtn: true才生效 success danger
|
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: {
|
column: {
|
||||||
// 行数据
|
// 行数据
|
||||||
|
|
@ -114,6 +127,44 @@ const tableData: TableConfig = intTableData({
|
||||||
selectRows: [],
|
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);
|
const showTable = ref(false);
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
//初始化数据原
|
//初始化数据原
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue