mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/fe-student.git
synced 2025-12-11 11:56:48 +08:00
fix:作业附件上传组件值未清空,作业内容及作业附件判断有一即可
This commit is contained in:
@@ -1,32 +1,24 @@
|
|||||||
<template>
|
<template>
|
||||||
<el-upload
|
<el-upload :file-list="files" :action="FILE_UPLOAD" method="POST" :show-file-list="false" :on-change="handleChange"
|
||||||
:file-list="files"
|
:limit="max" ref="imageRef" :on-exceed="exceed">
|
||||||
:action="FILE_UPLOAD"
|
<template #trigger>
|
||||||
method="POST"
|
<div>
|
||||||
:show-file-list="false"
|
<slot></slot>
|
||||||
:on-change="handleChange"
|
</div>
|
||||||
:limit="max"
|
</template>
|
||||||
ref="imageRef"
|
</el-upload>
|
||||||
:on-exceed="exceed"
|
|
||||||
>
|
|
||||||
<template #trigger>
|
|
||||||
<div>
|
|
||||||
<slot></slot>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</el-upload>
|
|
||||||
</template>
|
</template>
|
||||||
<script setup>
|
<script setup>
|
||||||
import {FILE_UPLOAD} from "@/api/api";
|
import { FILE_UPLOAD } from "@/api/api";
|
||||||
import {defineProps, ref, watch} from "vue";
|
import { defineProps, ref, watch } from "vue";
|
||||||
import {ElMessage} from "element-plus";
|
import { ElMessage } from "element-plus";
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
value: [],
|
value: [],
|
||||||
max: {
|
max: {
|
||||||
type: Number,
|
type: Number,
|
||||||
default: 1
|
default: 1
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const emit = defineEmits()
|
const emit = defineEmits()
|
||||||
@@ -35,46 +27,48 @@ const files = ref([])
|
|||||||
const imageRef = ref()
|
const imageRef = ref()
|
||||||
|
|
||||||
watch(props.value, () => {
|
watch(props.value, () => {
|
||||||
props.value.length || (files.value = props.value)
|
props.value.length || (files.value = props.value)
|
||||||
})
|
})
|
||||||
|
|
||||||
function exceed() {
|
function exceed() {
|
||||||
ElMessage.error(`只能上传${props.max}个附件`);
|
ElMessage.error(`只能上传${props.max}个附件`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleChange(e) {
|
function handleChange(e) {
|
||||||
if (e.response && e.response.code === 200) {
|
if (e.response && e.response.code === 200) {
|
||||||
e.url = e.response.data
|
e.url = e.response.data
|
||||||
}
|
}
|
||||||
|
|
||||||
const index = files.value.findIndex(f => f.uid === e.uid)
|
const index = files.value.findIndex(f => f.uid === e.uid)
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
files.value.unshift(e)
|
files.value.unshift(e)
|
||||||
} else {
|
} else {
|
||||||
files.value[index] = e
|
files.value[index] = e
|
||||||
}
|
}
|
||||||
emit('update:value', files.value)
|
emit('update:value', files.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove(i) {
|
function remove(i) {
|
||||||
files.value.splice(i, 1)
|
files.value.splice(i, 1)
|
||||||
|
console.log(imageRef)
|
||||||
|
imageRef.value.clearFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
function reUpload(i) {
|
function reUpload(i) {
|
||||||
if (files.value[i].status === 'ready' || files.value[i].status === 'uploading') {
|
if (files.value[i].status === 'ready' || files.value[i].status === 'uploading') {
|
||||||
imageRef.value.abort(files.value[i].raw)
|
imageRef.value.abort(files.value[i].raw)
|
||||||
files.value[i].status = 'abort';
|
files.value[i].status = 'abort';
|
||||||
} else if (files.value[i].status === 'fail' || files.value[i].status === 'abort') {
|
} else if (files.value[i].status === 'fail' || files.value[i].status === 'abort') {
|
||||||
imageRef.value.handleStart(files.value[i].raw)
|
imageRef.value.handleStart(files.value[i].raw)
|
||||||
imageRef.value.submit()
|
imageRef.value.submit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function abort(i) {
|
function abort(i) {
|
||||||
imageRef.value.abort(files.value[i].raw)
|
imageRef.value.abort(files.value[i].raw)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
defineExpose({reUpload, remove})
|
defineExpose({ reUpload, remove })
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user