<!--
 * @Author: Gui
 * @Date: 2023-05-12 11:36:28
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-06-06 14:57:14
 * @Description: kxs files
 * @filePath: 
-->
<template>
  <el-button type="primary" @click="clickupload">
    {{ btntext }}
    <slot
  /></el-button>
  <input type="file" id="inputfile" style="display: none" />
</template>
<script lang="ts" setup>
import { ref, onMounted } from "vue";
import Ossupload from "@/utils/OSSupload";
type Res = {
  uploadurl?: string;
};
const props = defineProps<{
  btntext?: string;
  FilePath: {
    type: Function;
    default: () => {};
  };
}>();
const uploaddo = ref(null);
onMounted(() => {
  uploaddo.value = document.querySelector("#inputfile");
  uploaddo.value.addEventListener("change", function (evt) {
    const file = evt.target.files[0];
    Ossupload(file).then((res: Res) => {
      props.FilePath(res.uploadurl);
    });
  });
});
const clickupload = function () {
  uploaddo.value.click();
};
</script>
