上传文件

<!--
 * @Author: mabo 9086467+mabo19920219@user.noreply.gitee.com
 * @Date: 2023-01-13 11:24:30
 * @LastEditors: mabo 9086467+mabo19920219@user.noreply.gitee.com
 * @LastEditTime: 2023-02-07 18:25:15
 * @FilePath: \a-gongfu\src\views\tryIt\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div style="background:#fff">
    <div class="envTopPart">气象海洋服务数据导入客户端</div>
    <div class="flexBox">
      <div class="topBox">
        <el-row>
          <el-col :span="2">
            <div class="choiceFiles">
              <i class="el-icon-folder-opened"></i> 选择文件
            </div>
          </el-col>
          <el-col :span="4">
            <el-select v-model="value" placeholder="请选择" @change='selectValue'>
              <el-option v-for="(item,index) in options" :key="index+'123'" :label="item" :value="item">
              </el-option>
            </el-select>
          </el-col>
          <el-col :span="18">
            <div class="choiceFile">
              <el-upload class="upload-demo" ref="upload" :before-upload="beforeUpload" :http-request="httpRequest" :on-preview="handlePreview" :on-remove="handleRemove" action=''
                :file-list="fileList" :auto-upload="false">
                <el-button slot="trigger" size="small" type="primary">选择文件</el-button>
                <el-button style="margin-left: 10px" size="small" type="success" @click="submitUpload">点击导入</el-button>
              </el-upload>
            </div>
          </el-col>
        </el-row>
      </div>

      <div class="rightPart">
        <el-row>
          <el-col :span="4">
            <div class="choiceFiles">
              <i class="el-icon-warning-outline"></i> 日志信息
            </div>
          </el-col>
          <el-col :span="20">
            <div class="grid-content bg-purple-light"></div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <div class="grid-content bg-purple-light">&nbsp;</div>
          </el-col>
        </el-row>
        <div class="rizhiContent">
          <el-table  v-loading="loading" :data="tableData" style="width: 100%">
            <el-table-column prop="upload_type" label="编号" width="180">
            </el-table-column>
            <el-table-column prop="upload_time" label="上传时间" width="180">
            </el-table-column>
            <el-table-column prop="upload_type" label="类型">
            </el-table-column>
            <el-table-column prop="end_time" label="结束时间">
            </el-table-column>
            <el-table-column prop="total_records" label="总记录数">
            </el-table-column>
            <el-table-column prop="insert_records" label="新增记录数">
            </el-table-column>
            <el-table-column prop="error_records" label="异常记录数">
            </el-table-column>
            <el-table-column prop="filepath" label="文件路径">
            </el-table-column>
            <el-table-column prop="filename" label="文件名">
            </el-table-column>
            <el-table-column prop="upload_status" label="上传状态">
              <template slot-scope="scope">
                {{scope.row.upload_status=='run'?'运行中':'停止'}}
              </template>
            </el-table-column>
            <el-table-column prop="upload_desc" label="上传描述">
            </el-table-column>
          </el-table>

        </div>
        <div class='paginations'>
          <el-pagination background :current-page.sync="currentPage" :page-sizes="pageSizes" :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios"
import { Message } from "element-ui"
export default {
  data() {
    return {
      fileList: [],
      options: [],
      value: "",
      tableData: [],loading:false,
      total: 0,
      pageSizes: [10],
      currentPage: 1,
      selectValues: "",
    }
  },
  created() {
    this.getInfo()
    this.getSelect()
  },
  methods: {
    beforeUpload(file) {
      this.fileList.push(file)
    },
    httpRequest(param) {
        if(this.selectValues===''){
             this.$message({
            message: "请先选择类型",
            type: "error",
          })
        }else{
            this.loading=true
let fd = new FormData()
      fd.append("file", param.file) // 传文件
      fd.append("upload_type", this.selectValues) // 传文件
      axios.post("/upload/uploadFile", fd, {
          headers: { "Content-Type": "multipart/form-data" }, //定义内容格式,很重要
          timeout: 20000,
        })
        .then((response) => {
          if ((response.code = 200)) {
            this.loading=false

            this.$message({
              message: "上传成功",
              type: "success",
            })
            this.getInfo()
            this.$refs.upload.clearFiles()
          }
        })
        .catch((err) => {
          this.$message({
            message: "上传失败",
            type: "error",
          })
            this.getInfo()

        })
        }
      
    },

    handleSizeChange(e) {},
    handleCurrentChange(e) {},
    submitUpload() {
      this.$refs.upload.submit()
    },
    handleRemove(file, fileList) {
        debugger
      console.log(file, fileList)
    },
    handlePreview(file) {
      console.log(file)
    },
    getInfo() {
      axios
        .get("/queryUploadInfo/queryInfo", { querypage: 1 }, "baseUrl")
        .then((res) => {
            if(res.data.code==200){
   this.tableData = res.data.data.values
          this.total = res.data.data.allrecords
            }
       
        })
    },
    getSelect() {
      axios.get("upload/getUploadTypes", {}, "baseUrl").then((res) => {
        if (res.data.code == 200) {
          this.options = res.data.data.values
        }
      })
    },
    selectValue(a) {
      this.selectValues = a
    },
  },
}
</script>

<style scoped lang="scss">
.envTopPart {
  font-size: 32px;
  text-align: center;
  height: 70px;
  line-height: 70px;
}
.flexBox {
  background: #ccc;
  height: 90vh;
  .topBox {
    padding: 0 10px;
    background-color: #fff;
    .choiceFiles {
      font-size: 16px;
      height: 40px;
      line-height: 40px;
    }
    .choiceFile {
      height: 40px;
      line-height: 40px;
    }
  }
  .rightPart {
    background-color: #fff;
    width: 100%;
    height: 100%;
    .choiceFiles {
      padding: 0 10px;
      background-color: #fff;
      font-size: 16px;
      height: 50px;
      line-height: 50px;
    }
    .rizhiContent {
      padding: 10px 20px;
    }
    .paginations{
        display: inline-block;
        float: right;
        width: 400px;
    }
  }
}
</style>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容