瀏覽代碼

指标文件上传

hsh 3 月之前
父節點
當前提交
417b05124e

+ 18 - 0
src/api/target-management/target-dict.js

@@ -159,4 +159,22 @@ export function returnTargetReportScoreByShf(data) {
         method: 'post',
         data,
     })
+}
+
+// 查询根据条件指标文件
+export function selectTargetFileById(data) {
+    return request({
+        url: '/targetManagement/selectTargetFileById',
+        method: 'post',
+        data,
+    })
+}
+
+// 删除文件
+export function deleteTargetFileByFileId(fileId, id, pid, year) {
+    return request({
+        url: '/targetManagement/deleteTargetFileByFileId',
+        method: 'get',
+        params: {fileId,id,pid,year},
+    })
 }

+ 139 - 0
src/views/target-management/target-comm/UploadTargetFile.vue

@@ -0,0 +1,139 @@
+<template>
+  <div style="margin-top: 10px; height: 400px">
+    <div style="margin-top: 10px">
+      <el-upload
+          class="upload-demo"
+          ref="upload"
+          accept=".xlsx,.xls,.png,.jpg,.jpeg,.text"
+          :action="apiUrl + '/targetManagement/uploadTargetFile'"
+          :headers="header"
+          :file-list="fileList"
+          :limit="1"
+          :data="targetFileData"
+          :on-success="uploadSuccess"
+          :on-error="uploadError"
+          :on-exceed="handleExceed"
+          :before-upload="beforeUpload"
+          :auto-upload="false"
+      >
+        <template #trigger>
+          <el-button type="primary" icon="Picture">选取文件</el-button>
+        </template>
+        <el-button
+            style="margin-left: 10px"
+            type="success"
+            icon="Upload"
+            @click="submitUpload"
+        >上传</el-button>
+        <template #tip>
+          <div class="el-upload__tip">
+            只能上传 xls/xlsx/png/jpg/jpeg/text 类型文件,且一次只能传一个文件
+          </div>
+        </template>
+      </el-upload>
+    </div>
+    <div id="ss" style="padding-top: 30px">
+      <el-table :data="QtResultData" stripe border highlight-current-row row-key="childKey" height="240" style="width: 100%">
+        <el-table-column prop="id" label="文件id" header-align="center" v-if="false"/>
+        <el-table-column prop="name" label="文件名称" header-align="center"/>
+        <el-table-column prop="path" label="操作" header-align="center" align="center" width="300">
+          <template v-slot="scope">
+<!--            <el-button type="primary" @click="seeFile(scope.row)">预览文件</el-button>-->
+            <el-button type="primary" v-if="scope.row.name.endsWith('.xls') || scope.row.name.endsWith('.xlsx') || scope.row.name.endsWith('.text')" @click="downloadFile(scope.row)">下载文件</el-button>
+            <el-image v-else :src="'http://webhis.thyy.cn:8080' + scope.row.path" :preview-src-list="['http://webhis.thyy.cn:8080' + scope.row.path]" fit="cover"
+                      style="width: 80px; height: 20px; cursor: pointer; padding-right: 8px; padding-top: 6px"></el-image>
+            <el-button type="primary" @click="deleteFile(scope.row)" :loading="downloading">{{ downloading ? '删除中...' : '删除文件' }}</el-button>
+          </template>
+        </el-table-column>
+      </el-table>
+    </div>
+  </div>
+</template>
+<script setup lang="ts">
+import {nextTick, onMounted, ref, watch} from "vue";
+import {ElMessage, UploadFile, UploadFiles} from "element-plus";
+import env from "@/utils/setting";
+import {deleteTargetFileByFileId, selectTargetFileById} from '@/api/target-management/target-dict'
+import {useUserStore} from "@/pinia/user-store";
+
+const props = defineProps({
+  targetFileInfo: {
+    type: Object,
+    default: {}
+  }
+})
+
+const targetFileData = ref({})
+const downloading = ref(false)
+const downloadingD = ref(false)
+const QtResultData = ref([])
+
+watch(() => props.targetFileInfo, () => {
+  targetFileData.value = props.targetFileInfo
+  queryTargetFileById(props.targetFileInfo.fileId)
+})
+
+onMounted(() => {
+  nextTick(() => {
+    targetFileData.value = props.targetFileInfo
+    queryTargetFileById(props.targetFileInfo.fileId)
+  })
+})
+
+// ------------------ 上传 ---------------------
+const fileList = ref([]);
+const apiUrl = env.VITE_BASE_URL;
+
+const upload = ref(null);
+const header = {
+  token: useUserStore().getToken,
+};
+const submitUpload = () => {
+  nextTick(() => {
+    upload.value.submit();
+  });
+};
+const uploadSuccess = (response: any, uploadFile: UploadFile, uploadFiles: UploadFiles) => {
+  console.log(response, uploadFile, uploadFiles);
+  ElMessage.success("上传成功!");
+};
+const uploadError = () => {
+  ElMessage.error("上传失败!");
+};
+const handleExceed: UploadProps['onExceed'] = (files) => {
+  upload.value!.clearFiles()
+  const file = files[0] as UploadRawFile
+  file.uid = genFileId()
+  upload.value!.handleStart(file)
+}
+const beforeUpload = (file: File, row) => {
+  if (file.size / 1024 / 1024 > 2) {
+    ElMessage.error('上传图片大小不能超过 2MB!')
+    row.isOversize = true
+  }
+}
+const queryTargetFileById = (fileId: String)=> {
+  selectTargetFileById({fileId: fileId})
+    .then((res: any) => {
+      QtResultData.value = res.fileList
+    });
+}
+// 下载文件
+const downloadFile = (row) => {
+  if(row.name.endsWith(".xls") || row.name.endsWith(".xlsx") || row.name.endsWith(".text")){
+    window.location.href = 'http://webhis.thyy.cn:8080' + row.path
+  } else {
+    // downloadImageNew('http://webhis.thyy.cn:8080' + row.path, row.name);
+  }
+}
+//删除文件
+const deleteFile = (row) => {
+  downloadingD.value = true
+  deleteTargetFileByFileId(row.id, props.targetFileInfo.id, props.targetFileInfo.pid, props.targetFileInfo.year).then((res: any) => {
+    ElMessage.success("删除指标文件成功!");
+    queryTargetFileById(props.targetFileInfo.fileId)
+    downloadingD.value = false
+  });
+}
+
+</script>

+ 23 - 10
src/views/target-management/target-dict/TargetDictConfig.vue

@@ -290,15 +290,12 @@
                       </el-table-column>
                       <el-table-column prop="opTime" label="统计时间" header-align="center" width="160"/>
                       <el-table-column prop="op" label="统计人员" header-align="center" />
-<!--                      <el-table-column prop="fileUpDown" label="附件上传" header-align="center">-->
-<!--                        <template v-slot="scope">-->
-<!--                          <el-input v-if="scope.row.isEdit" size="small" v-model="scope.row.fileUpDown"></el-input>-->
-<!--                          <span v-else>{{ scope.row.fileUpDown }}</span>-->
-<!--                        </template>-->
-<!--                      </el-table-column>-->
-                      <el-table-column prop="cz" label="操作" min-width="180" width="180" header-align="center">
+                      <el-table-column prop="cz" label="操作" min-width="280" width="280" header-align="center">
                         <template #default="scope">
-                          <el-button type="primary" size="small" v-if="!scope.row.isEdit" @click="editRow(scope.$index, scope.row)">
+                          <el-button type="primary" size="small" @click="uploadFile(scope.row)">
+                            上传与查看
+                          </el-button>
+                          <el-button type="primary" size="small" v-if="!scope.row.isEdit" @click="editRow(scope.row)">
                             修改
                           </el-button>
                           <el-button type="primary" size="small" v-if="scope.row.isEdit" @click="updateRow(scope.row)">
@@ -361,6 +358,10 @@
   <el-drawer :title="'Sql编辑'" v-model="isSqlEdit" size="80%" destroy-on-close>
     <SqlEditPage :sqlEditData="sqlEditData" />
   </el-drawer>
+  <el-dialog v-model="showUploadTd" :close-on-click-modal="false" :close-on-press-escape="false"
+             destroy-on-close title="指标文件上传" width="60%" top="40px">
+    <UploadTargetFile :targetFileInfo="targetFileInfo" />
+  </el-dialog>
 </template>
 <script setup name="TargetDictConfig" lang="ts">
 import {nextTick, onMounted, reactive, ref} from 'vue'
@@ -393,6 +394,7 @@ import {
 } from '@/api/target-management/target-sql'
 import {useUserStore} from "@/pinia/user-store";
 import {power} from "@/utils/excel-base-function";
+import UploadTargetFile from "@/views/target-management/target-comm/UploadTargetFile.vue";
 
 const targetTreeData = ref({
   data: [{}],
@@ -1002,6 +1004,7 @@ interface resultData {
   calcResult: string
   op: string
   opTime: string
+  fileId: string
   yearRate: string
   cz: object
 }
@@ -1232,7 +1235,7 @@ const reportResultFormat = (e) => {
 
 //-------------手工计算数据修改开始--------------------
 // 手工计算数据修改
-const editRow = (index, row) => {
+const editRow = (row) => {
   // 备份原始数据
   row['oldRow'] = JSON.parse(JSON.stringify(row))
   row.isEdit = true
@@ -1496,7 +1499,8 @@ const callAverageAnnualGrowthRate = (data) => {
   let d2 = data.filter((item) => {
     return item.year === sqlForm.endTime
   })
-  if(d1 && d2){
+  console.log('========= d1:' + d1)
+  if(d1.length !== 0 && d2.length !== 0){
     let r1 = d1[0].calcResult
     let r2 = d2[0].calcResult
     let v = power(r2/r1, 1/3) - 1
@@ -1545,6 +1549,15 @@ const returnTargetDictSh = () => {
   }).catch(() => {
   })
 }
+
+// 上传文件
+const showUploadTd = ref(false)
+const targetFileInfo = ref({})
+const uploadFile = (row) => {
+  targetFileInfo.value = row
+  showUploadTd.value = true
+}
+
 </script>
 <style lang="scss" scoped>
 :deep(.hd-cl) {