开源软件列表查询及批量校验相关问题修复

This commit is contained in:
付民康
2025-03-15 20:32:13 +08:00
parent c57c932e45
commit 236942a229
7 changed files with 1234 additions and 210 deletions

View File

@@ -0,0 +1,78 @@
<template>
<div>
<!-- 文件上传按钮 -->
<d-button
class="mr-2"
variant="solid"
:loading="loading"
@click="triggerFileInput"
>
{{ buttonText }}
</d-button>
<!-- 隐藏的文件上传输入框 -->
<input
ref="fileInput"
type="file"
:accept="accept"
style="display: none"
@change="handleFileUpload"
/>
</div>
</template>
<script setup>
import { ref } from 'vue';
// 定义组件属性
const props = defineProps({
buttonText: {
type: String,
default: '上传文件',
},
accept: {
type: String,
default: '.xml', // 默认接受 XML 文件
},
onFileUpload: {
type: Function,
required: true,
},
});
// 文件输入框的引用
const fileInput = ref(null);
// 加载状态
const loading = ref(false);
// 触发文件选择
const triggerFileInput = () => {
fileInput.value.click(); // 触发文件选择
};
// 处理文件上传
const handleFileUpload = async (event) => {
const file = event.target.files[0]; // 获取选择的文件
if (file) {
// 检查文件类型
if (file.type === 'text/xml' || file.name.endsWith('.xml')) {
loading.value = true; // 显示加载状态
try {
await props.onFileUpload(file); // 调用父组件传递的上传方法
} catch (error) {
console.error('文件上传失败:', error);
alert('文件上传失败,请重试!');
} finally {
loading.value = false; // 隐藏加载状态
}
} else {
alert('请选择有效的 XML 文件!');
}
}
};
</script>
<style lang="scss" scoped>
/* 自定义样式 */
</style>