2025-04-16 13:55:57 +08:00
|
|
|
<template>
|
2025-04-17 16:26:09 +08:00
|
|
|
<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">
|
2025-04-17 16:26:09 +08:00
|
|
|
<el-form-item label="icd文件">
|
2025-04-16 13:55:57 +08:00
|
|
|
<el-upload
|
2025-04-17 16:26:09 +08:00
|
|
|
v-model:file-list="reportPath"
|
2025-04-16 13:55:57 +08:00
|
|
|
ref="uploadRef"
|
|
|
|
|
action=""
|
|
|
|
|
:limit="1"
|
2025-04-22 09:08:35 +08:00
|
|
|
accept=".xml"
|
2025-04-16 13:55:57 +08:00
|
|
|
:on-exceed="handleExceed"
|
|
|
|
|
:auto-upload="false"
|
|
|
|
|
:on-remove="removeFile"
|
2025-04-22 09:08:35 +08:00
|
|
|
:on-change="choose"
|
2025-04-16 13:55:57 +08:00
|
|
|
>
|
|
|
|
|
<template #trigger>
|
|
|
|
|
<el-button type="primary">上传文件</el-button>
|
|
|
|
|
</template>
|
2025-04-22 09:08:35 +08:00
|
|
|
<template #tip>
|
|
|
|
|
<div>请上传xml文件</div>
|
|
|
|
|
</template>
|
2025-04-16 13:55:57 +08:00
|
|
|
</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'
|
2025-04-17 16:26:09 +08:00
|
|
|
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'
|
2025-04-17 16:26:09 +08:00
|
|
|
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>({
|
2025-04-17 16:26:09 +08:00
|
|
|
fileName: '',
|
|
|
|
|
filePath: '',
|
|
|
|
|
id: ''
|
2025-04-16 13:55:57 +08:00
|
|
|
})
|
2025-04-17 16:26:09 +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' }],
|
2025-04-17 16:26:09 +08:00
|
|
|
fileName: [{ required: true, message: '请输入任务名称', trigger: 'blur' }]
|
2025-04-16 13:55:57 +08:00
|
|
|
}
|
|
|
|
|
|
2025-04-17 16:26:09 +08:00
|
|
|
const open = (text: string, data?: any) => {
|
|
|
|
|
reportPath.value = []
|
2025-04-16 13:55:57 +08:00
|
|
|
title.value = text
|
|
|
|
|
dialogVisible.value = true
|
2025-04-17 16:26:09 +08:00
|
|
|
if (data?.path) {
|
|
|
|
|
reportPath.value = [
|
|
|
|
|
{
|
|
|
|
|
name: data?.path.split('/icd/')[1]
|
|
|
|
|
}
|
|
|
|
|
]
|
2025-04-16 13:55:57 +08:00
|
|
|
}
|
2025-04-17 16:26:09 +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()
|
2025-04-22 09:08:35 +08:00
|
|
|
/**
|
|
|
|
|
* 选择待上传文件
|
|
|
|
|
*/
|
|
|
|
|
const choose = (e: any) => {
|
|
|
|
|
const file = e.raw
|
|
|
|
|
if (!isValidFile(file)) {
|
|
|
|
|
uploadRef.value!.clearFiles()
|
|
|
|
|
form.filePath = []
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
form.filePath.file = file
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 文件校验函数
|
|
|
|
|
*/
|
|
|
|
|
const isValidFile = (file: UploadRawFile) => {
|
|
|
|
|
const validExtensions = ['.xml']
|
|
|
|
|
const fileExtension = file.name.slice(((file.name.lastIndexOf('.') - 1) >>> 0) + 2)
|
|
|
|
|
if (!validExtensions.includes(`.${fileExtension}`)) {
|
|
|
|
|
ElMessage.error('文件类型不支持,请选择 .xml')
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
// 上传报告
|
|
|
|
|
|
2025-04-16 13:55:57 +08:00
|
|
|
const handleExceed: UploadProps['onExceed'] = files => {
|
2026-01-06 08:35:36 +08:00
|
|
|
|
2025-04-22 09:08:35 +08:00
|
|
|
|
2025-04-16 13:55:57 +08:00
|
|
|
uploadRef.value!.clearFiles()
|
|
|
|
|
const file = files[0] as UploadRawFile
|
|
|
|
|
file.uid = genFileId()
|
|
|
|
|
uploadRef.value!.handleStart(file)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//移除文件上传
|
|
|
|
|
const removeFile = (file: any, uploadFiles: any) => {
|
2025-04-17 16:26:09 +08:00
|
|
|
form.filePath = ''
|
2025-04-16 13:55:57 +08:00
|
|
|
}
|
|
|
|
|
|
2025-04-17 16:26:09 +08:00
|
|
|
const submit = async () => {
|
2026-01-06 08:35:36 +08:00
|
|
|
|
2025-04-17 16:26:09 +08:00
|
|
|
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
|
|
|
|
|
})
|
2025-04-22 09:08:35 +08:00
|
|
|
}
|
|
|
|
|
|
2025-04-17 16:26:09 +08:00
|
|
|
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>
|
2025-04-17 16:26:09 +08:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
:deep(.el-upload-list__item) {
|
|
|
|
|
width: 300px;
|
|
|
|
|
}
|
|
|
|
|
</style>
|