fix:作业文件上传文件名称处理

This commit is contained in:
wyx
2023-02-27 02:22:11 +08:00
parent 2bd9cee5a3
commit 649b3bacd3
2 changed files with 5 additions and 10 deletions

View File

@@ -1,10 +1,10 @@
<template> <template>
<el-upload <el-upload
ref="imageRef"
:file-list="files" :file-list="files"
:show-file-list="false" :show-file-list="false"
:limit="max" :limit="max"
action="/file/upload" :action="FILE_UPLOAD_ANNEX"
ref="imageRef"
:auto-upload="false" :auto-upload="false"
:on-exceed="exceed" :on-exceed="exceed"
:on-change="handleChange"> :on-change="handleChange">
@@ -20,12 +20,11 @@ import { defineProps, ref, watch } from "vue";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import { computed } from "vue"; import { computed } from "vue";
import { useStore } from "vuex"; import { useStore } from "vuex";
import { request,fileUp } from "@/api/request"; import { FILE_UPLOAD_ANNEX } from "@/api/api";
const store = useStore(); const store = useStore();
const userInfo = computed(() => store.state.userInfo); const userInfo = computed(() => store.state.userInfo);
const props = defineProps({ const props = defineProps({
value: [], value: [],
max: { max: {
@@ -35,7 +34,6 @@ const props = defineProps({
}) })
const emit = defineEmits() const emit = defineEmits()
const files = ref([]) const files = ref([])
const imageRef = ref() const imageRef = ref()
@@ -48,25 +46,23 @@ function exceed() {
} }
function handleChange(file) { function handleChange(file) {
console.log('111111',userInfo.value)
let fileName = userInfo.value.realName + '-' + userInfo.value.userNo + '-' + file.name; let fileName = userInfo.value.realName + '-' + userInfo.value.userNo + '-' + file.name;
let f = new File([file.raw],fileName); let f = new File([file.raw],fileName);
f.uid = file.uid; f.uid = file.uid;
file.raw = f; file.raw = f;
console.log(file.raw) console.log(file.raw)
//
imageRef.value.submit(); imageRef.value.submit();
if (file.response && file.response.code === 200) { if (file.response && file.response.code === 200) {
file.url = file.response.data file.url = file.response.data
} }
const index = files.value.findIndex(f => f.uid === file.uid) const index = files.value.findIndex(f => f.uid === file.uid)
if (index === -1) { if (index === -1) {
files.value.unshift(file) files.value.unshift(file)
} else { } else {
files.value[index] = file files.value[index] = file
} }
emit('update:value', files.value) emit('update:value', files.value)
} }
@@ -93,7 +89,6 @@ function abort(i) {
imageRef.value.abort(files.value[i].raw) imageRef.value.abort(files.value[i].raw)
} }
defineExpose({ reUpload, remove, clearFiles }) defineExpose({ reUpload, remove, clearFiles })
</script> </script>

View File

@@ -451,7 +451,7 @@ import {
import dayjs from "dayjs"; import dayjs from "dayjs";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
// import store from "@/store"; // import store from "@/store";
import UploadImg from "@/components/img/UploadImg2HomeWork.vue"; import UploadImg from "@/components/img/UploadImgHomeWork.vue";
import FileTypeImg from "@/components/FileTypeImg.vue"; import FileTypeImg from "@/components/FileTypeImg.vue";
import { useRoute } from "vue-router/dist/vue-router"; import { useRoute } from "vue-router/dist/vue-router";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";