|
|
|
@ -9,6 +9,7 @@
|
|
|
|
|
:http-request="handleUpload"
|
|
|
|
|
list-type="text"
|
|
|
|
|
:on-exceed="handleExceed"
|
|
|
|
|
:on-remove="handleRemove"
|
|
|
|
|
show-file-list
|
|
|
|
|
>
|
|
|
|
|
<el-button type="primary">
|
|
|
|
@ -56,8 +57,12 @@
|
|
|
|
|
type: String,
|
|
|
|
|
default: '*/*',
|
|
|
|
|
},
|
|
|
|
|
loading: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
const emits = defineEmits(['update:modelValue']);
|
|
|
|
|
const emits = defineEmits(['update:modelValue', 'update:loading']);
|
|
|
|
|
const imgList = ref([]);
|
|
|
|
|
const attrs = useAttrs();
|
|
|
|
|
watch(
|
|
|
|
@ -97,6 +102,12 @@
|
|
|
|
|
console.info('[upload] exceed', list);
|
|
|
|
|
ElMessage.error('超出最大上传数量');
|
|
|
|
|
};
|
|
|
|
|
const handleRemove = (file) => {
|
|
|
|
|
console.info('[upload] remove', file);
|
|
|
|
|
if (file.status !== 'success') {
|
|
|
|
|
unref(cancelToken).cancel('用户手动取消请求');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const handleBeforeUpload = (file) => {
|
|
|
|
|
console.info('[upload] upload', file);
|
|
|
|
|
let res = true;
|
|
|
|
@ -106,8 +117,17 @@
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
};
|
|
|
|
|
const cancelToken = ref(null);
|
|
|
|
|
const loading = ref(props.loading);
|
|
|
|
|
watch(loading, (value) => {
|
|
|
|
|
emits('update:loading', value);
|
|
|
|
|
});
|
|
|
|
|
const handleUpload = async ({ file }) => {
|
|
|
|
|
return await upload(props.serviceName, props.configId, file);
|
|
|
|
|
loading.value = true;
|
|
|
|
|
cancelToken.value = axios.CancelToken.source();
|
|
|
|
|
let res = await upload(props.serviceName, props.configId, file, unref(cancelToken).token);
|
|
|
|
|
loading.value = false;
|
|
|
|
|
return res;
|
|
|
|
|
};
|
|
|
|
|
const fmtSize = computed(() => {
|
|
|
|
|
const units = ['byte', 'KB', 'MB', 'GB', 'TB'];
|
|
|
|
|