Files
admin-sjzx/src/views/system/icd/form.vue

116 lines
3.5 KiB
Vue
Raw Normal View History

2025-04-16 13:55:57 +08:00
<template>
<el-dialog draggable width="400px" v-model="dialogVisible" :title="title">
2025-04-16 13:55:57 +08:00
<el-form :inline="false" :model="form" label-width="auto" class="form-one" :rules="rules" ref="formRef">
<el-form-item label="icd文件">
2025-04-16 13:55:57 +08:00
<el-upload
v-model:file-list="reportPath"
2025-04-16 13:55:57 +08:00
ref="uploadRef"
action=""
accept=""
:limit="1"
:on-exceed="handleExceed"
:auto-upload="false"
:on-remove="removeFile"
>
<template #trigger>
<el-button type="primary">上传文件</el-button>
</template>
</el-upload>
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="submit">确认</el-button>
</span>
</template>
</el-dialog>
</template>
<script lang="ts" setup>
import { ref, inject, onMounted } from 'vue'
import { uploadFile } from '@/api/system-boot/file'
2025-04-16 13:55:57 +08:00
import { reactive } from 'vue'
import { UploadInstance, UploadProps, UploadRawFile, ElMessage, genFileId } from 'element-plus'
import { addIcdPath, updateIcdPath } from '@/api/device-boot/icd'
2025-04-16 13:55:57 +08:00
const emit = defineEmits(['submit'])
const dialogVisible = ref(false)
const title = ref('')
// 注意不要和表单ref的命名冲突
const form = reactive<anyObj>({
fileName: '',
filePath: '',
id: ''
2025-04-16 13:55:57 +08:00
})
const reportPath: any = ref([])
2025-04-16 13:55:57 +08:00
const formRef = ref()
const rules = {
path: [{ required: true, message: '请选择任务执行器', trigger: 'change' }],
fileName: [{ required: true, message: '请输入任务名称', trigger: 'blur' }]
2025-04-16 13:55:57 +08:00
}
const open = (text: string, data?: any) => {
reportPath.value = []
2025-04-16 13:55:57 +08:00
title.value = text
dialogVisible.value = true
if (data?.path) {
reportPath.value = [
{
name: data?.path.split('/icd/')[1]
}
]
2025-04-16 13:55:57 +08:00
}
form.fileName = data?.name
form.id = data?.id
form.filePath = data?.path
2025-04-16 13:55:57 +08:00
}
// 上传报告
const uploadRef = ref()
const handleExceed: UploadProps['onExceed'] = files => {
uploadRef.value!.clearFiles()
const file = files[0] as UploadRawFile
file.uid = genFileId()
uploadRef.value!.handleStart(file)
}
//移除文件上传
const removeFile = (file: any, uploadFiles: any) => {
form.filePath = ''
2025-04-16 13:55:57 +08:00
}
const submit = async () => {
console.log(123, reportPath.value[0]?.raw)
if (reportPath.value.length == 0) {
return ElMessage.warning('请上传icd文件')
}
if (reportPath.value[0]?.raw != undefined) {
await uploadFile(reportPath.value[0].raw, '/icd/').then(res => {
//治理工程验收报告
form.fileName = res.data.fileName.split('.')[0]
form.filePath = res.data.name
})
}
if (title.value == '新增icd文件') {
await addIcdPath(form).then(res => {
ElMessage.success('新增成功!')
dialogVisible.value = false
emit('submit')
})
} else {
await updateIcdPath(form).then(res => {
ElMessage.success('编辑成功!')
dialogVisible.value = false
emit('submit')
})
}
2025-04-16 13:55:57 +08:00
}
defineExpose({ open })
</script>
<style lang="scss" scoped>
:deep(.el-upload-list__item) {
width: 300px;
}
</style>