|
@@ -6,7 +6,8 @@ import { ref } from "vue";
|
|
import * as XLSX from "xlsx";
|
|
import * as XLSX from "xlsx";
|
|
import {
|
|
import {
|
|
GetdownloadDataRosterTemplateApi,
|
|
GetdownloadDataRosterTemplateApi,
|
|
- postUpdateDeptApi
|
|
|
|
|
|
+ postUpdateDeptApi,
|
|
|
|
+ getListTable
|
|
} from "@/api/download";
|
|
} from "@/api/download";
|
|
import { ElMessage } from "element-plus";
|
|
import { ElMessage } from "element-plus";
|
|
import { useRouter } from "vue-router";
|
|
import { useRouter } from "vue-router";
|
|
@@ -26,7 +27,6 @@ const uploadFile = async () => {
|
|
try {
|
|
try {
|
|
const formData = new FormData();
|
|
const formData = new FormData();
|
|
formData.append("file", fileDocument.value); // 将文件添加到表单数据
|
|
formData.append("file", fileDocument.value); // 将文件添加到表单数据
|
|
- console.log("文件上传", fileDocument.value, formData);
|
|
|
|
// 调用 API 上传文件
|
|
// 调用 API 上传文件
|
|
const { data } = await postUpdateDeptApi(formData);
|
|
const { data } = await postUpdateDeptApi(formData);
|
|
if (data.code === 200) {
|
|
if (data.code === 200) {
|
|
@@ -37,13 +37,6 @@ const uploadFile = async () => {
|
|
backDefine();
|
|
backDefine();
|
|
$router.push("/indexDefine/children/define");
|
|
$router.push("/indexDefine/children/define");
|
|
tableHeaders.value = []; // 清空表头
|
|
tableHeaders.value = []; // 清空表头
|
|
- tableData.value = [
|
|
|
|
- { name: "" },
|
|
|
|
- { defin: "" },
|
|
|
|
- { caliber: "" },
|
|
|
|
- { type: "" },
|
|
|
|
- { from: "" }
|
|
|
|
- ]; // 清空表格数据
|
|
|
|
} else {
|
|
} else {
|
|
ElMessage.error(data.msg);
|
|
ElMessage.error(data.msg);
|
|
}
|
|
}
|
|
@@ -54,69 +47,77 @@ const uploadFile = async () => {
|
|
};
|
|
};
|
|
|
|
|
|
const tableHeaders = ref<any>([]);
|
|
const tableHeaders = ref<any>([]);
|
|
-const tableData = ref<any>([
|
|
|
|
- { name: "" },
|
|
|
|
- { defin: "" },
|
|
|
|
- { caliber: "" },
|
|
|
|
- { type: "" },
|
|
|
|
- { from: "" }
|
|
|
|
-]);
|
|
|
|
|
|
+const tableData = ref<any>([]);
|
|
|
|
|
|
const backDefine = () => {
|
|
const backDefine = () => {
|
|
emit("handleImport");
|
|
emit("handleImport");
|
|
};
|
|
};
|
|
|
|
|
|
// 处理文件上传并解析 Excel 内容
|
|
// 处理文件上传并解析 Excel 内容
|
|
-const handleUploadChange = (file: File) => {
|
|
|
|
|
|
+const handleUploadChange = async (file: File) => {
|
|
fileDocument.value = file; // 保存文件
|
|
fileDocument.value = file; // 保存文件
|
|
const reader = new FileReader();
|
|
const reader = new FileReader();
|
|
let fileType = file.name.slice(-4);
|
|
let fileType = file.name.slice(-4);
|
|
console.log("文件", file.name.slice(-4));
|
|
console.log("文件", file.name.slice(-4));
|
|
if (fileType == "xlsx") {
|
|
if (fileType == "xlsx") {
|
|
- reader.onload = e => {
|
|
|
|
- const data = new Uint8Array(e.target?.result as ArrayBuffer);
|
|
|
|
- const workbook = XLSX.read(data, { type: "array" }); // 读取 Excel 文件
|
|
|
|
- const firstSheetName = workbook.SheetNames[0]; // 获取第一个工作表名
|
|
|
|
- const worksheet = workbook.Sheets[firstSheetName]; // 获取第一个工作表
|
|
|
|
- const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1 }); // 将工作表转为 JSON
|
|
|
|
- if (jsonData[1].length == 6) {
|
|
|
|
- tableHeaders.value = [
|
|
|
|
- "指标名称",
|
|
|
|
- "指标定义",
|
|
|
|
- "指标口径",
|
|
|
|
- "指标分类",
|
|
|
|
- "来源",
|
|
|
|
- "状态"
|
|
|
|
- ]; // 表头
|
|
|
|
|
|
+ const formData = new FormData();
|
|
|
|
+ formData.append("file", fileDocument.value); // 将文件添加到表单数据
|
|
|
|
+ // 调用 API 上传文件
|
|
|
|
+ const { data } = await getListTable(formData);
|
|
|
|
+ if (data.code === 200) {
|
|
|
|
+ tableData.value = data.data;
|
|
|
|
+ }
|
|
|
|
+ // reader.onload = e => {
|
|
|
|
+ // const data = new Uint8Array(e.target?.result as ArrayBuffer);
|
|
|
|
+ // const workbook = XLSX.read(data, { type: "array" }); // 读取 Excel 文件
|
|
|
|
+ // const firstSheetName = workbook.SheetNames[0]; // 获取第一个工作表名
|
|
|
|
+ // const worksheet = workbook.Sheets[firstSheetName]; // 获取第一个工作表
|
|
|
|
+ // const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1 }); // 将工作表转为 JSON
|
|
|
|
+ // if (jsonData[1].length == 6) {
|
|
|
|
+ // tableHeaders.value = [
|
|
|
|
+ // "指标名称",
|
|
|
|
+ // "指标定义",
|
|
|
|
+ // "指标口径",
|
|
|
|
+ // "指标分类",
|
|
|
|
+ // "来源",
|
|
|
|
+ // "状态"
|
|
|
|
+ // ]; // 表头
|
|
|
|
+
|
|
|
|
+ // const arr = jsonData.slice(3).map(row => {
|
|
|
|
+ // if (row[0] && row[1] && row[2] && row[3]) {
|
|
|
|
+ // const rowData = {};
|
|
|
|
+ // tableHeaders.value.forEach((header, index) => {
|
|
|
|
+ // if (row[index] && row[index].trim().length > 0) {
|
|
|
|
+ // rowData[header] = row[index];
|
|
|
|
+ // } else if (header == "来源") {
|
|
|
|
+ // rowData[header] = "-";
|
|
|
|
+ // } else if (header == "状态") {
|
|
|
|
+ // rowData[header] = "草稿";
|
|
|
|
+ // }
|
|
|
|
+ // });
|
|
|
|
+ // return rowData;
|
|
|
|
+ // }
|
|
|
|
+ // });
|
|
|
|
+ // tableData.value = arr.filter(item => item);
|
|
|
|
+ // console.log("111", tableData.value)
|
|
|
|
|
|
- const arr = jsonData.slice(3).map(row => {
|
|
|
|
- if (row[0] && row[1] && row[2] && row[3]) {
|
|
|
|
- const rowData = {};
|
|
|
|
- tableHeaders.value.forEach((header, index) => {
|
|
|
|
- if (row[index] && row[index].trim().length > 0) {
|
|
|
|
- rowData[header] = row[index];
|
|
|
|
- } else if (header == "来源") {
|
|
|
|
- rowData[header] = "-";
|
|
|
|
- } else if (header == "状态") {
|
|
|
|
- rowData[header] = "草稿";
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- return rowData;
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- tableData.value = arr.filter(item => item);
|
|
|
|
- ElMessage.success("文件上传成功");
|
|
|
|
- uploadShow.value = false; // 隐藏上传区域,显示数据表
|
|
|
|
- } else {
|
|
|
|
- ElMessage.error("文件为空或格式不正确");
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
|
|
+ // ElMessage.success("文件上传成功");
|
|
|
|
+ uploadShow.value = false; // 隐藏上传区域,显示数据表
|
|
|
|
+ // } else {
|
|
|
|
+ // ElMessage.error("文件为空或格式不正确");
|
|
|
|
+ // }
|
|
|
|
+ // };
|
|
} else {
|
|
} else {
|
|
ElMessage.error("请上传xlsx文件");
|
|
ElMessage.error("请上传xlsx文件");
|
|
}
|
|
}
|
|
|
|
|
|
reader.readAsArrayBuffer(file); // 读取文件为 ArrayBuffer
|
|
reader.readAsArrayBuffer(file); // 读取文件为 ArrayBuffer
|
|
};
|
|
};
|
|
|
|
+
|
|
|
|
+const stateDone = state => {
|
|
|
|
+ const arr = ["草稿", "发布", "下架"];
|
|
|
|
+ return arr[state];
|
|
|
|
+};
|
|
</script>
|
|
</script>
|
|
|
|
|
|
<template>
|
|
<template>
|
|
@@ -162,12 +163,16 @@ const handleUploadChange = (file: File) => {
|
|
style="width: 100%"
|
|
style="width: 100%"
|
|
max-height="250"
|
|
max-height="250"
|
|
>
|
|
>
|
|
- <el-table-column
|
|
|
|
- v-for="header in tableHeaders"
|
|
|
|
- :key="header"
|
|
|
|
- :label="header"
|
|
|
|
- :prop="header"
|
|
|
|
- />
|
|
|
|
|
|
+ <el-table-column prop="name" label="指标名称" />
|
|
|
|
+ <el-table-column prop="define" label="指标定义" />
|
|
|
|
+ <el-table-column prop="caliber" label="指标口径" />
|
|
|
|
+ <el-table-column prop="categoryName" label="指标分类" />
|
|
|
|
+ <el-table-column prop="source" label="来源" />
|
|
|
|
+ <el-table-column prop="statue" label="状态">
|
|
|
|
+ <template #default="scope">
|
|
|
|
+ {{ stateDone(scope.row.statue) }}
|
|
|
|
+ </template>
|
|
|
|
+ </el-table-column>
|
|
</el-table>
|
|
</el-table>
|
|
</div>
|
|
</div>
|
|
<div class="float-right">
|
|
<div class="float-right">
|