mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/fe-student.git
synced 2025-12-07 01:46:46 +08:00
fix:作业文件上传文件名称处理
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
<template>
|
||||
<el-upload
|
||||
ref="imageRef"
|
||||
:file-list="files"
|
||||
:show-file-list="false"
|
||||
:limit="max"
|
||||
action="/file/upload"
|
||||
ref="imageRef"
|
||||
:action="FILE_UPLOAD_ANNEX"
|
||||
:auto-upload="false"
|
||||
:on-exceed="exceed"
|
||||
:on-change="handleChange">
|
||||
@@ -20,12 +20,11 @@ import { defineProps, ref, watch } from "vue";
|
||||
import { ElMessage } from "element-plus";
|
||||
import { computed } from "vue";
|
||||
import { useStore } from "vuex";
|
||||
import { request,fileUp } from "@/api/request";
|
||||
import { FILE_UPLOAD_ANNEX } from "@/api/api";
|
||||
|
||||
const store = useStore();
|
||||
const userInfo = computed(() => store.state.userInfo);
|
||||
|
||||
|
||||
const props = defineProps({
|
||||
value: [],
|
||||
max: {
|
||||
@@ -35,7 +34,6 @@ const props = defineProps({
|
||||
})
|
||||
|
||||
const emit = defineEmits()
|
||||
|
||||
const files = ref([])
|
||||
const imageRef = ref()
|
||||
|
||||
@@ -48,25 +46,23 @@ function exceed() {
|
||||
}
|
||||
|
||||
function handleChange(file) {
|
||||
console.log('111111',userInfo.value)
|
||||
let fileName = userInfo.value.realName + '-' + userInfo.value.userNo + '-' + file.name;
|
||||
let f = new File([file.raw],fileName);
|
||||
f.uid = file.uid;
|
||||
file.raw = f;
|
||||
console.log(file.raw)
|
||||
// 手动触发上传
|
||||
imageRef.value.submit();
|
||||
|
||||
if (file.response && file.response.code === 200) {
|
||||
file.url = file.response.data
|
||||
}
|
||||
|
||||
const index = files.value.findIndex(f => f.uid === file.uid)
|
||||
if (index === -1) {
|
||||
files.value.unshift(file)
|
||||
} else {
|
||||
files.value[index] = file
|
||||
}
|
||||
|
||||
emit('update:value', files.value)
|
||||
}
|
||||
|
||||
@@ -93,7 +89,6 @@ function abort(i) {
|
||||
imageRef.value.abort(files.value[i].raw)
|
||||
}
|
||||
|
||||
|
||||
defineExpose({ reUpload, remove, clearFiles })
|
||||
|
||||
</script>
|
||||
@@ -451,7 +451,7 @@ import {
|
||||
import dayjs from "dayjs";
|
||||
import { useRouter } from "vue-router";
|
||||
// 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 { useRoute } from "vue-router/dist/vue-router";
|
||||
import { ElMessage } from "element-plus";
|
||||
|
||||
Reference in New Issue
Block a user