设备台账:上传路径修改,文件上传修改为原生方式
上传组件:新增上传文件公共组件
This commit is contained in:
parent
4eba6e48d1
commit
84151f6f01
@ -301,14 +301,15 @@ export function delOtherParamsReq(params: any) {
|
|||||||
export function uploadOtherParamsFileReq(formData: FormData, V: string) {
|
export function uploadOtherParamsFileReq(formData: FormData, V: string) {
|
||||||
const token = encrypt_aes(adminInfo.token, V)
|
const token = encrypt_aes(adminInfo.token, V)
|
||||||
return createAxios({
|
return createAxios({
|
||||||
url: '/api/equipment//file/upload',
|
url: '/api/equipment/file/upload',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: formData,
|
data: formData,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'multipart/form-data',
|
'Content-Type': 'multipart/form-data',
|
||||||
V,
|
V,
|
||||||
token,
|
token,
|
||||||
}
|
},
|
||||||
|
timeout: 1000 * 60 * 2,
|
||||||
},
|
},
|
||||||
{ customEncrypt: true })
|
{ customEncrypt: true })
|
||||||
}
|
}
|
||||||
|
46
ui/dasadmin/src/components/upload/index.vue
Normal file
46
ui/dasadmin/src/components/upload/index.vue
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<template>
|
||||||
|
<div class="uploadContainer" @click="upload">
|
||||||
|
<slot></slot>
|
||||||
|
<input ref="uploadRef" type="file" style="display: none" :multiple="props.multiple" @change="change" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref } from 'vue'
|
||||||
|
const props = defineProps({
|
||||||
|
multiple: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
onChange: {
|
||||||
|
type: Function,
|
||||||
|
default: () => {},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const uploadRef = ref()
|
||||||
|
|
||||||
|
const upload = (e:any) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
uploadRef.value!.click()
|
||||||
|
}
|
||||||
|
|
||||||
|
const change = (payload: Event) => {
|
||||||
|
payload.preventDefault()
|
||||||
|
const files = (payload.target as HTMLInputElement).files
|
||||||
|
props.onChange(files)
|
||||||
|
}
|
||||||
|
const clearFiles = () => {
|
||||||
|
uploadRef.value!.value = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
clearFiles,
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.uploadContainer {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
</style>
|
@ -84,7 +84,15 @@
|
|||||||
</el-main>
|
</el-main>
|
||||||
</el-container>
|
</el-container>
|
||||||
<!-- 机组设备弹窗 -->
|
<!-- 机组设备弹窗 -->
|
||||||
<el-dialog v-model="type10002DialogVisible" width="800" :title="type10002DialogTitle" align-center :close-on-click-modal="false" @close="cancelType10002Dialog">
|
<el-dialog
|
||||||
|
v-model="type10002DialogVisible"
|
||||||
|
width="800"
|
||||||
|
:title="type10002DialogTitle"
|
||||||
|
align-center
|
||||||
|
:close-on-click-modal="false"
|
||||||
|
@close="cancelType10002Dialog"
|
||||||
|
:before-close="beforeCloseType10002Dialog"
|
||||||
|
>
|
||||||
<el-tabs v-model="activeName">
|
<el-tabs v-model="activeName">
|
||||||
<el-form ref="deviceDataFormRef" label-width="auto" :model="deviceData" :rules="editAddDeviceRules">
|
<el-form ref="deviceDataFormRef" label-width="auto" :model="deviceData" :rules="editAddDeviceRules">
|
||||||
<el-tab-pane label="风机参数" name="1">
|
<el-tab-pane label="风机参数" name="1">
|
||||||
@ -605,12 +613,9 @@
|
|||||||
<el-dialog v-model="attachmentDialogVisible" :title="attachmentDialogTitle" :width="800" :close-on-click-modal="false">
|
<el-dialog v-model="attachmentDialogVisible" :title="attachmentDialogTitle" :width="800" :close-on-click-modal="false">
|
||||||
<div class="attachmentContainer">
|
<div class="attachmentContainer">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<!-- <el-button @click="uploadAttachment">添加附件</el-button> -->
|
<CustomUpload multiple :onChange="uploadAttachment" ref="customUploadRef">
|
||||||
<el-upload ref="uploadRef" :show-file-list="false" :http-request="uploadAttachment" multiple>
|
<el-button type="primary" :loading="uploadAttachmentLoading">添加附件</el-button>
|
||||||
<template #trigger>
|
</CustomUpload>
|
||||||
<el-button type="primary">添加附件</el-button>
|
|
||||||
</template>
|
|
||||||
</el-upload>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<el-carousel indicator-position="outside" @change="changeImgIndex">
|
<el-carousel indicator-position="outside" @change="changeImgIndex">
|
||||||
@ -660,20 +665,12 @@ import {
|
|||||||
updateOtherParamsReq,
|
updateOtherParamsReq,
|
||||||
delOtherParamsReq,
|
delOtherParamsReq,
|
||||||
uploadOtherParamsFileReq,
|
uploadOtherParamsFileReq,
|
||||||
readFileReq,
|
|
||||||
} from '/@/api/backend'
|
} from '/@/api/backend'
|
||||||
import {
|
import {
|
||||||
ElTable,
|
ElTable,
|
||||||
ElMessage,
|
ElMessage,
|
||||||
ElMessageBox,
|
ElMessageBox,
|
||||||
FormInstance,
|
FormInstance,
|
||||||
UploadInstance,
|
|
||||||
genFileId,
|
|
||||||
UploadProps,
|
|
||||||
UploadRawFile,
|
|
||||||
UploadFile,
|
|
||||||
UploadFiles,
|
|
||||||
UploadRequestOptions,
|
|
||||||
} from 'element-plus'
|
} from 'element-plus'
|
||||||
import { useAdminInfo } from '/@/stores/adminInfo'
|
import { useAdminInfo } from '/@/stores/adminInfo'
|
||||||
import { encrypt_aes, generateRandomNumber } from '/@/utils/crypto'
|
import { encrypt_aes, generateRandomNumber } from '/@/utils/crypto'
|
||||||
@ -681,6 +678,7 @@ import ControlPage from './control.vue'
|
|||||||
import MeasurementPage from './measurement.vue'
|
import MeasurementPage from './measurement.vue'
|
||||||
import { ModelAttributeType } from '/@/views/backend/auth/model/type'
|
import { ModelAttributeType } from '/@/views/backend/auth/model/type'
|
||||||
import { theoreticalpowerCurveList } from '/@/api/backend/theoreticalpowerCurve/request'
|
import { theoreticalpowerCurveList } from '/@/api/backend/theoreticalpowerCurve/request'
|
||||||
|
import CustomUpload from '/@/components/upload/index.vue'
|
||||||
import { permission } from '/@/utils/directive'
|
import { permission } from '/@/utils/directive'
|
||||||
const vPermission = permission()
|
const vPermission = permission()
|
||||||
|
|
||||||
@ -1262,8 +1260,6 @@ const getCurDialogState = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const saveDeviceData = () => {
|
const saveDeviceData = () => {
|
||||||
// console.log(deviceData, 'deviceData')
|
|
||||||
|
|
||||||
deviceDataFormRef.value?.validate((valid: boolean) => {
|
deviceDataFormRef.value?.validate((valid: boolean) => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
deviceData.standard = deviceData.standard ? 1 : 0
|
deviceData.standard = deviceData.standard ? 1 : 0
|
||||||
@ -1344,6 +1340,24 @@ const saveDeviceData = () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
const beforeCloseType10002Dialog = (done: () => void) =>{
|
||||||
|
if (addImgList.value.length) {
|
||||||
|
ElMessageBox.confirm('上传图片未保存,确认取消?', '', {
|
||||||
|
confirmButtonText: '确认',
|
||||||
|
cancelButtonText: '取消',
|
||||||
|
type: 'warning',
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
done()
|
||||||
|
addImgList.value = []
|
||||||
|
imgList.value = []
|
||||||
|
})
|
||||||
|
.catch(() => {})
|
||||||
|
} else {
|
||||||
|
done()
|
||||||
|
imgList.value = []
|
||||||
|
}
|
||||||
|
}
|
||||||
const cancelType10002Dialog = () => {
|
const cancelType10002Dialog = () => {
|
||||||
if (addImgList.value.length) {
|
if (addImgList.value.length) {
|
||||||
ElMessageBox.confirm('上传图片未保存,确认取消?', '', {
|
ElMessageBox.confirm('上传图片未保存,确认取消?', '', {
|
||||||
@ -1410,30 +1424,26 @@ const setOtherParamsFormData = (data: any = {}) => {
|
|||||||
const attachmentDialogVisible = ref(false)
|
const attachmentDialogVisible = ref(false)
|
||||||
const attachmentDialogTitle = ref('风机详细信息')
|
const attachmentDialogTitle = ref('风机详细信息')
|
||||||
|
|
||||||
const uploadRef = ref<UploadInstance>()
|
const customUploadRef = ref()
|
||||||
const uploadAttachment = (file: UploadRequestOptions) => {
|
const uploadAttachmentLoading =ref(false)
|
||||||
|
const uploadAttachment = (files: FileList) => {
|
||||||
|
uploadAttachmentLoading.value = true
|
||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
formData.append('fileList', file.file)
|
for (let i = 0; i < files.length; i++) {
|
||||||
|
formData.append('fileList', files[i])
|
||||||
|
}
|
||||||
const v = generateRandomNumber(16)
|
const v = generateRandomNumber(16)
|
||||||
return uploadOtherParamsFileReq(formData, v).then((res) => {
|
return uploadOtherParamsFileReq(formData, v).then((res) => {
|
||||||
addImgList.value.push({
|
customUploadRef.value?.clearFiles()
|
||||||
name: file.file.name,
|
res.data.forEach((item:{ name:string, url:string})=>{
|
||||||
url: res.data[0].url,
|
addImgList.value.push({
|
||||||
component: attachmentComponent.value,
|
name: item.name,
|
||||||
|
url: item.url,
|
||||||
|
component: attachmentComponent.value,
|
||||||
|
})
|
||||||
})
|
})
|
||||||
addImgList.value.push({
|
|
||||||
name: file.file.name,
|
|
||||||
url: res.data[1].url,
|
|
||||||
component: attachmentComponent.value,
|
|
||||||
})
|
|
||||||
const imgListUrl = imgList.value.map((item: any) => item.url)
|
|
||||||
for (let i = addImgList.value.length - 1; i >= 0; i--) {
|
|
||||||
if (imgListUrl.includes('/api/equipment/file/read?path=' + addImgList.value[i].url)) {
|
|
||||||
const index = imgList.value.findIndex((item: any) => item.url === '/api/equipment/file/read?path=' + addImgList.value[i].url)
|
|
||||||
imgList.value.splice(index, 1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
previewImg([...imgList.value, ...addImgList.value])
|
previewImg([...imgList.value, ...addImgList.value])
|
||||||
|
uploadAttachmentLoading.value = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
const setUploadImgInfo = (id: string) => {
|
const setUploadImgInfo = (id: string) => {
|
||||||
@ -1442,13 +1452,7 @@ const setUploadImgInfo = (id: string) => {
|
|||||||
item.deviceId = id
|
item.deviceId = id
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
const handleExceed: UploadProps['onExceed'] = (files) => {
|
|
||||||
uploadRef.value!.clearFiles()
|
|
||||||
const file = files[0] as UploadRawFile
|
|
||||||
file.uid = genFileId()
|
|
||||||
uploadRef.value!.handleStart(file)
|
|
||||||
uploadRef.value!.submit()
|
|
||||||
}
|
|
||||||
const attachmentComponent = ref('')
|
const attachmentComponent = ref('')
|
||||||
const openAttachment = (type: string) => {
|
const openAttachment = (type: string) => {
|
||||||
attachmentComponent.value = type
|
attachmentComponent.value = type
|
||||||
@ -1491,6 +1495,7 @@ const previewImgIndex = ref(0)
|
|||||||
const changeImgIndex = (index: number) => {
|
const changeImgIndex = (index: number) => {
|
||||||
previewImgIndex.value = index
|
previewImgIndex.value = index
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
|
Loading…
Reference in New Issue
Block a user