update:禁止上传重名文件
This commit is contained in:
@@ -35,12 +35,11 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, watch, nextTick } from 'vue';
|
import { ref, watch } from 'vue';
|
||||||
import { View, Delete, Download } from '@element-plus/icons-vue';
|
import { View, Delete, Download } from '@element-plus/icons-vue';
|
||||||
import FilePreview from '@/components/common/filePreview/index.vue';
|
import FilePreview from '@/components/common/filePreview/index.vue';
|
||||||
import { downloadFileById, fileUploadAllocationIconFun } from '@/utils/file';
|
import { downloadFileById, fileUploadAllocationIconFun } from '@/utils/file';
|
||||||
import { isArray } from 'lodash-es';
|
import { isArray } from 'lodash-es';
|
||||||
import { ElMessage } from 'element-plus';
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
modelValue: any;
|
modelValue: any;
|
||||||
@@ -86,16 +85,38 @@ const downloadFun = (data: any) => {
|
|||||||
downloadFileById(data.fileId);
|
downloadFileById(data.fileId);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let changing = false;
|
||||||
|
const changeData: any = [];
|
||||||
|
const removeRepeatFun = () => {
|
||||||
|
if (changing) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
changing = true;
|
||||||
|
if (changeData[0]) {
|
||||||
|
setTimeout(() => {
|
||||||
|
fileList.value.some((item: any, index: number) => {
|
||||||
|
if (item.name === changeData[0].name) {
|
||||||
|
removeFun(index);
|
||||||
|
changeData.splice(index, 1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
changing = false;
|
||||||
|
if (changeData.length > 0) {
|
||||||
|
removeRepeatFun();
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const changeFun = (data: any, dataList: any) => {
|
const changeFun = (data: any, dataList: any) => {
|
||||||
emit('change', data);
|
emit('change', data);
|
||||||
const fileNum = dataList.filter((item: any) => item.name === data.name);
|
const fileNum = dataList.filter((item: any) => item.name === data.name);
|
||||||
if (fileNum.length > 1) {
|
if (fileNum.length > 1) {
|
||||||
ElMessage.warning('不允许上传重名文件');
|
changeData.push(data);
|
||||||
setTimeout(() => {
|
}
|
||||||
nextTick(() => {
|
if (changeData.length > 0 && !changing) {
|
||||||
removeFun(fileList.value.length - 1);
|
removeRepeatFun();
|
||||||
});
|
|
||||||
}, 0);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -136,6 +136,7 @@
|
|||||||
:attrs="attrs"
|
:attrs="attrs"
|
||||||
v-model="formData[item.searchKey || item.key]"
|
v-model="formData[item.searchKey || item.key]"
|
||||||
:disabled="attrs.disabled || (item.disabled && showDisabled)"
|
:disabled="attrs.disabled || (item.disabled && showDisabled)"
|
||||||
|
:multiple="attrs.multiple"
|
||||||
@change="(val: any) => changeFun(item.key, val)"
|
@change="(val: any) => changeFun(item.key, val)"
|
||||||
@remove="(val: any) => removeFun(item.key, val)"
|
@remove="(val: any) => removeFun(item.key, val)"
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user