262 lines
7.8 KiB
Plaintext
262 lines
7.8 KiB
Plaintext
<script setup lang="ts">
|
|
import AppBlock from '@/components/AppBlock.vue'
|
|
import type { UploadProps, UploadUserFile } from 'element-plus'
|
|
import { useUserStore } from '@/stores/modules/user'
|
|
import {useMessage} from 'naive-ui'
|
|
import {updateAct,getCsrActList } from '@/api/daikin/base'
|
|
import { time } from 'echarts'
|
|
const message = useMessage()
|
|
const form = ref({
|
|
lable1:{
|
|
id:0,
|
|
title: '',
|
|
fileList:[],
|
|
filePath:''
|
|
},
|
|
lable2:{
|
|
id:0,
|
|
title: '',
|
|
fileList:[],
|
|
filePath:''
|
|
},
|
|
lable3:{
|
|
id:0,
|
|
title: '',
|
|
fileList:[],
|
|
filePath:''
|
|
},
|
|
})
|
|
let fileList= ref()
|
|
let fileList2= ref()
|
|
let fileList3= ref()
|
|
|
|
async function onSubmit() {
|
|
console.log(fileList.value,fileList2.value,fileList3.value)
|
|
if(fileList.value){
|
|
form.value.lable1.filePath = fileList.value.map(item =>
|
|
{
|
|
if(item.response){
|
|
return item.response.url
|
|
}
|
|
else{
|
|
return item.url
|
|
}
|
|
}
|
|
).join(',')
|
|
}
|
|
if(fileList2.value){
|
|
form.value.lable2.filePath = fileList2.value.map(item => {
|
|
if(item.response){
|
|
return item.response.url
|
|
}
|
|
else{
|
|
return item.url
|
|
}
|
|
}).join(',')
|
|
}
|
|
if(fileList3.value){
|
|
|
|
form.value.lable3.filePath = fileList3.value.map(item => {
|
|
if(item.response){
|
|
return item.response.url
|
|
}
|
|
else{
|
|
return item.url
|
|
}
|
|
}).join(',')
|
|
|
|
}
|
|
const list = [ form.value.lable1, form.value.lable2, form.value.lable3]
|
|
const formWithoutFileList = {};
|
|
|
|
for (const key in list) {
|
|
const { fileList,filePathList,csrId, ...rest } = list[key];
|
|
formWithoutFileList[key] = rest;
|
|
}
|
|
const datas = Object.values(formWithoutFileList)
|
|
// console.log(JSON.stringify(Object.values(formWithoutFileList)))
|
|
console.log( datas)
|
|
const {code,msg} = await updateAct(datas)
|
|
if(code===200){message.success("修改成功")}
|
|
else message.warning(msg)
|
|
window.location.reload();
|
|
// console.log(form.value)
|
|
}
|
|
|
|
const handleRemove: UploadProps['onRemove'] = (file: any, uploadFiles: any) => {
|
|
console.log(file, uploadFiles)
|
|
|
|
}
|
|
|
|
const handlePreview1: UploadProps['onSuccess'] = (uploadFile: any) => {
|
|
|
|
// fileList = uploadFile.map((item: { filetitle: any }) => item.filetitle).join(',')
|
|
// fileList.push(uploadFile)
|
|
console.log(uploadFile)
|
|
form.value.lable1.fileList.push(uploadFile)
|
|
// console.log(uploadFile)
|
|
}
|
|
const handlePreview2: UploadProps['onSuccess'] = (uploadFile: any) => {
|
|
console.log(uploadFile)
|
|
// fileList2.push(uploadFile)
|
|
form.value.lable2.fileList.push(uploadFile)
|
|
}
|
|
const handlePreview3: UploadProps['onSuccess'] = (uploadFile: any) => {
|
|
console.log(uploadFile)
|
|
// fileList3.push(uploadFile)
|
|
form.value.lable3.fileList.push(uploadFile)
|
|
}
|
|
|
|
const handleExceed: UploadProps['onExceed'] = (files: string | any[], uploadFiles: string | any[]) => {
|
|
// ElMessage.warning(
|
|
// `The limit is 3, you selected ${files.length} files this time, add up to ${
|
|
// files.length + uploadFiles.length
|
|
// } totally`
|
|
// )
|
|
console.log(uploadFiles)
|
|
}
|
|
|
|
const beforeRemove: UploadProps['beforeRemove'] = (uploadFile: { title: any }, uploadFiles: any) => {
|
|
return ElMessageBox.confirm(
|
|
`删除 ${uploadFile.title}文件 ?`
|
|
).then(
|
|
() => true,
|
|
() => false
|
|
)
|
|
}
|
|
const store = useUserStore()
|
|
const header = {'token':store.user.token}
|
|
|
|
|
|
|
|
const eachDat = (data)=>{
|
|
return data.filePathList.map((item: any) => {
|
|
const list = {name:item.originalFileName,url:item.url}
|
|
console.log(list)
|
|
return list
|
|
})
|
|
}
|
|
onMounted(async () => {
|
|
const { data } =await getCsrActList()
|
|
if(data&&data.length>0){
|
|
form.value.lable1 =Object.assign(data[0],{
|
|
fileList:[]
|
|
})
|
|
form.value.lable2 = Object.assign(data[1],{
|
|
fileList:[]
|
|
})
|
|
form.value.lable3= Object.assign(data[2],{
|
|
fileList:[]
|
|
})
|
|
}
|
|
console.log(form.value.lable1)
|
|
if(form.value.lable1.filePathList&&form.value.lable1.filePathList.length>0){
|
|
fileList.value =eachDat(form.value.lable1)
|
|
}
|
|
if(form.value.lable2.filePathList&&form.value.lable2.filePathList.length>0){
|
|
|
|
fileList2.value =eachDat(form.value.lable2)
|
|
}
|
|
if(form.value.lable3.filePathList&&form.value.lable3.filePathList.length>0){
|
|
fileList3.value =eachDat(form.value.lable3)
|
|
|
|
}
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<div class="flex w-full h-full">
|
|
<AppBlock class="w-full p60px">
|
|
|
|
<el-form :model="form.lable1" label-width="120px" :inline="true">
|
|
<!-- <el-form-item label="专题" >
|
|
<el-input v-model="form.lable1.title"/>
|
|
</el-form-item> -->
|
|
<br>
|
|
<el-form-item label="标题" >
|
|
<el-input v-model="form.lable1.title"/>
|
|
</el-form-item>
|
|
<br>
|
|
<el-form-item label="文件" >
|
|
<el-upload
|
|
v-model:file-list="fileList"
|
|
class="upload-demo"
|
|
:headers="header"
|
|
action="/test-api/common/upload"
|
|
multiple
|
|
:on-success="handlePreview1"
|
|
:on-remove="handleRemove"
|
|
:before-remove="beforeRemove"
|
|
:on-exceed="handleExceed"
|
|
>
|
|
<el-button type="primary">选择文件</el-button>
|
|
<template #tip>
|
|
<div class="el-upload__tip">
|
|
|
|
</div>
|
|
</template>
|
|
</el-upload>
|
|
</el-form-item>
|
|
</el-form>
|
|
<hr class="mb15px border-#f1f1f1">
|
|
<el-form :model="form.lable2" label-width="120px" :inline="true">
|
|
<el-form-item label="标题" >
|
|
<el-input v-model="form.lable2.title"/>
|
|
</el-form-item>
|
|
<br>
|
|
<el-form-item label="文件" >
|
|
<el-upload
|
|
v-model:file-list="fileList2"
|
|
class="upload-demo"
|
|
:headers="header"
|
|
action="/test-api/common/upload"
|
|
multiple
|
|
:on-success="handlePreview2"
|
|
:on-remove="handleRemove"
|
|
:before-remove="beforeRemove"
|
|
:on-exceed="handleExceed"
|
|
>
|
|
<el-button type="primary">选择文件</el-button>
|
|
<template #tip>
|
|
<div class="el-upload__tip">
|
|
|
|
</div>
|
|
</template>
|
|
</el-upload>
|
|
</el-form-item>
|
|
</el-form>
|
|
<hr class="mb15px border-#f1f1f1">
|
|
<el-form :model="form.lable3" label-width="120px" :inline="true">
|
|
<el-form-item label="标题" >
|
|
<el-input v-model="form.lable3.title"/>
|
|
</el-form-item>
|
|
<br>
|
|
<el-form-item label="文件" >
|
|
<el-upload
|
|
v-model:file-list="fileList3"
|
|
class="upload-demo"
|
|
:headers="header"
|
|
action="/test-api/common/upload"
|
|
multiple
|
|
:on-success="handlePreview3"
|
|
:on-remove="handleRemove"
|
|
:before-remove="beforeRemove"
|
|
:on-exceed="handleExceed"
|
|
>
|
|
<el-button type="primary">选择文件</el-button>
|
|
<template #tip>
|
|
<div class="el-upload__tip">
|
|
|
|
</div>
|
|
</template>
|
|
</el-upload>
|
|
</el-form-item>
|
|
</el-form>
|
|
<el-form-item>
|
|
<el-button type="primary" @click="onSubmit">提交</el-button>
|
|
</el-form-item>
|
|
</AppBlock>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped lang="less"></style> |