fix(Uploader): multiple reupload only choose one & cancel choose problem (#12359)

* fix(Uploader): multiple reupload only choose one & cancel chose problem

* fix(Uploader): multiple reupload only choose one & cancel chose problem

* fix(Uploader): refactor code

* fix(Uploader): refactor code
This commit is contained in:
ShuGang Zhou 2023-10-13 20:17:54 -05:00 committed by GitHub
parent 1219e4386c
commit 6f74d77da9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,6 +5,7 @@ import {
onBeforeUnmount, onBeforeUnmount,
type PropType, type PropType,
type ExtractPropTypes, type ExtractPropTypes,
nextTick,
} from 'vue'; } from 'vue';
// Utils // Utils
@ -104,6 +105,7 @@ export default defineComponent({
const inputRef = ref(); const inputRef = ref();
const urls: string[] = []; const urls: string[] = [];
const reuploadIndex = ref(-1); const reuploadIndex = ref(-1);
const isReuploading = ref(false);
const getDetail = (index = props.modelValue.length) => ({ const getDetail = (index = props.modelValue.length) => ({
name: props.name, name: props.name,
@ -278,9 +280,15 @@ export default defineComponent({
}; };
const reuploadImage = (index: number) => { const reuploadImage = (index: number) => {
// eslint-disable-next-line no-use-before-define isReuploading.value = true;
chooseFile();
reuploadIndex.value = index; reuploadIndex.value = index;
nextTick(() => chooseFile());
};
const onInputClick = () => {
if (!isReuploading.value) {
reuploadIndex.value = -1;
}
isReuploading.value = false;
}; };
const renderPreviewItem = (item: UploaderFileListItem, index: number) => { const renderPreviewItem = (item: UploaderFileListItem, index: number) => {
@ -344,6 +352,7 @@ export default defineComponent({
multiple={props.multiple && reuploadIndex.value === -1} multiple={props.multiple && reuploadIndex.value === -1}
disabled={props.disabled} disabled={props.disabled}
onChange={onChange} onChange={onChange}
onClick={onInputClick}
/> />
); );