<template>
  <el-upload
    class="upload-demo"
    action="api/protocol_version_manage/file_upload/"
    :show-file-list="false"
    :data="data"
  >
    <el-button type="primary">Click to upload</el-button>
  </el-upload>
  <br>
  <el-button type="primary" @click="downloadFile">下载原始文件</el-button>
  
</template>


<script lang="ts" setup>
import { ref } from "vue";
import axios from "axios";

const data = ref({
  "protocol_name": "HY_VirtualDevice_PROTOCOL",
  "version": "222",
});

const downloadFile = () => {
  let url = "api/protocol_version_manage/file_download/HY_VirtualDevice_PROTOCOL/222/";
  axios({
    url,
    method: "GET",
    responseType: "blob",
  }).then((res) => {
    // 下载文件
    console.log(res);
    const blob = new Blob([res.data], { type: "multipart/form-data" });
    const link = document.createElement("a");
    link.href = window.URL.createObjectURL(blob);
    link.download = decodeURIComponent(res.headers["filename"]);
    link.click();
  });
  console.log("downloadFile");
};

</script>
