Przeglądaj źródła

feat: 指标数据【日志、批量导入】

haifeng.zhang 1 miesiąc temu
rodzic
commit
c80a87a6c5

+ 21 - 1
src/api/indexData.ts

@@ -2,11 +2,13 @@
  * @Author: zhanghaifeng
  * @Date: 2025-01-06 17:11:11
  * @LastEditors: zhanghaifeng
- * @LastEditTime: 2025-01-08 11:04:59
+ * @LastEditTime: 2025-01-10 17:53:26
  * @Description:
  * @FilePath: /hospital-project/src/api/indexData.ts
  */
 import { http } from "@/utils/http";
+import axios from "axios";
+const FLIE_URL = import.meta.env.VITE_BASE_URL;
 
 type PageListType = {
   code: number;
@@ -48,3 +50,21 @@ export const editListApi = data => {
     data
   });
 };
+
+// 分页-日志
+export const getLogInfo = params => {
+  return http.request<PageListType>("get", "/source/getSourceDataUpdateText", {
+    params
+  });
+};
+
+// 批量导入
+export const uploadData = async data => {
+  const token = localStorage.getItem("token") || "";
+  return axios.post(`${FLIE_URL}/source/importSourceData`, data, {
+    headers: {
+      "Content-Type": "multipart/form-data", // 指定内容类型
+      satoken: token // 将 Token 添加到请求头
+    }
+  });
+};

+ 10 - 52
src/views/indexData/components/indexImport.vue

@@ -3,15 +3,14 @@ defineOptions({
   name: "IndexDefineImport"
 });
 import { ref } from "vue";
-import { postUpdateDeptApi, getListTable } from "@/api/download";
+import { uploadData } from "@/api/indexData";
 import { ElMessage } from "element-plus";
 import { useRouter } from "vue-router";
 const $router = useRouter();
 const emit = defineEmits(["handleImport"]);
-const uploadShow = ref(true);
 const fileDocument = ref<File | null>(null); // 存储文件
 const backupUrl =
-  import.meta.env.VITE_BACKUP_URL + "/download/指标导入模板.xlsx";
+  import.meta.env.VITE_BACKUP_URL + "/download/指标数据模板.xlsx";
 // 上传文件函数
 // 上传文件函数
 const uploadFile = async () => {
@@ -24,30 +23,22 @@ const uploadFile = async () => {
     const formData = new FormData();
     // 将生成的文件添加到 FormData 中
     formData.append("file", fileDocument.value);
-    // 获取文件并执行上传
-    const fileToSend = formData.get("file");
     // 调用 API 上传文件
-    const { data } = await postUpdateDeptApi({ file: fileToSend });
-    // const { data } = await postUpdateDeptApi({ file: formData });
+    const { data } = await uploadData(formData);
     if (data.code === 200) {
       // 根据后端返回的 code 判断是否成功
       ElMessage.success("文件上传并导入成功");
       // 重置上传状态
       backDefine();
-      $router.push("/indexDefine/children/define");
-      tableHeaders.value = []; // 清空表头
+      $router.push("/indexData/index");
     } else {
       ElMessage.error(data.msg);
     }
   } catch (error) {
     ElMessage.error("上传失败,请重试");
-    console.error(error);
   }
 };
 
-const tableHeaders = ref<any>([]);
-const tableData = ref<any>([]);
-
 const backDefine = () => {
   emit("handleImport");
 };
@@ -55,27 +46,11 @@ const backDefine = () => {
 // 处理文件上传并解析 Excel 内容
 const handleUploadChange = async (file: File) => {
   fileDocument.value = file; // 保存文件
-  const reader = new FileReader();
   let fileType = file.name.slice(-4);
-  if (fileType == "xlsx") {
-    const formData = new FormData();
-    formData.append("file", fileDocument.value); // 将文件添加到表单数据
-    // 调用 API 上传文件
-    const { data } = await getListTable(formData);
-    if (data.code === 200) {
-      tableData.value = data.data;
-    }
-    uploadShow.value = false; // 隐藏上传区域,显示数据表
-  } else {
+  if (fileType !== "xlsx") {
     ElMessage.error("请上传xlsx文件");
   }
-
-  reader.readAsArrayBuffer(file); // 读取文件为 ArrayBuffer
-};
-
-const stateDone = state => {
-  const arr = ["草稿", "发布", "下架"];
-  return arr[state];
+  return false;
 };
 </script>
 
@@ -97,38 +72,21 @@ const stateDone = state => {
         <p class="text-xs mt-2 text mb-2">
           更新信息的模板中,如有空的数据列,则相应字段信息会被清空,请谨慎填写
         </p>
-        <div v-if="uploadShow">
+        <div>
           <el-upload
             class="upload-demo"
             drag
             multiple
             :before-upload="file => handleUploadChange(file)"
-            :show-file-list="false"
           >
             <el-icon class="el-icon--upload"><upload-filled /></el-icon>
             <div class="el-upload__text">
               点击<em>图标选择上传</em>或者将文件拖拽到此区域
             </div>
           </el-upload>
-        </div>
-        <div v-else class="mb-2">
-          <el-table
-            :data="tableData"
-            border
-            style="width: 100%"
-            max-height="250"
-          >
-            <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>
+          <div v-if="fileDocument && fileDocument.name">
+            {{ fileDocument.name }}
+          </div>
         </div>
         <div class="float-right">
           <el-button @click="backDefine">取消</el-button>

+ 10 - 7
src/views/indexData/components/logDrawer.vue

@@ -2,22 +2,21 @@
  * @Author: zhanghaifeng
  * @Date: 2025-01-03 16:46:09
  * @LastEditors: zhanghaifeng
- * @LastEditTime: 2025-01-03 17:10:33
+ * @LastEditTime: 2025-01-10 15:42:18
  * @Description:
  * @FilePath: /hospital-project/src/views/indexData/components/logDrawer.vue
 -->
 <script setup lang="ts">
 import { ref } from "vue";
 import type { DrawerProps } from "element-plus";
-import { getQuotaLogInfo } from "@/api/indexDefine";
+import { getLogInfo } from "@/api/indexData";
 import dayjs from "dayjs";
 const drawer = ref(false);
 const quotaId = ref();
 const direction = ref<DrawerProps["direction"]>("rtl");
-const logList = ref([]);
+const logList = ref<any>([]);
 const getQuotaLogInfoApi = async () => {
-  const { code, data } = await getQuotaLogInfo(quotaId.value);
-  console.log(data);
+  const { code, data } = await getLogInfo({ sourceDataId: quotaId.value });
   if (code === 200) {
     logList.value = data;
   }
@@ -49,7 +48,7 @@ defineExpose({
               <div
                 class="bg-gray-100 pl-3 pb-2 pt-2 rounded text-sm text-gray-500"
               >
-                {{ item.updateUser }}
+                {{ item.createUser }}
               </div>
             </div>
             <div class="mt-4">
@@ -57,7 +56,11 @@ defineExpose({
               <div
                 class="bg-gray-100 pl-3 pb-2 pt-2 rounded text-sm text-gray-500"
               >
-                {{ dayjs(item.updateTime).format("YYYY-MM-DD HH:mm:ss") }}
+                {{
+                  item.createTime
+                    ? dayjs(item.createTime).format("YYYY-MM-DD HH:mm:ss")
+                    : ""
+                }}
               </div>
             </div>
             <div class="mt-4">