1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
| <template> <el-card v-if="scene === 0" class="dataShow"> <el-button type="primary" size="default" icon="Plus" style="margin-bottom:10px" @click="addData">添加数据</el-button> <el-button type="primary" size="default" icon="Plus" style="margin-bottom:10px" @click="scene=2">抽屉</el-button> <h3>数据列表</h3> <el-table stripe> <el-table-column prop="name" label="异常名称" width="180"></el-table-column> <el-table-column prop="type" label="异常类型" width="180"></el-table-column> <el-table-column prop="date" label="发生时间"></el-table-column> <el-table-column prop="operator" label="操作"> <el-button icon="Monitor">综合</el-button> <el-button icon="Delete">删除</el-button> </el-table-column> </el-table> </el-card> <el-card v-if="scene === 1" class="dataLoad"> <el-form label-width="100px"> <el-form-item label="异常名称"> <el-input v-model="dataUpLoadVar.name"></el-input> </el-form-item> <el-form-item label="异常类型" > <el-select v-model="dataUpLoadVar.type"> <el-option label="火灾" value="fire"></el-option> <el-option label="地震" value="earthquake"></el-option> <el-option label="水华" value="algae_bloom"></el-option> <el-option label="滑坡" value="landslide"></el-option> <el-option label="其他" value="other"></el-option> </el-select> </el-form-item> <el-form-item label="发生时间" > <el-input type="date" v-model="dataUpLoadVar.date"></el-input> </el-form-item> <el-form-item label="异常强度数据" > <div class="uploadDiv"> <upload ref="loadIntensity" ></upload> </div> </el-form-item> <el-form-item label="异常影响数据" > <div class="uploadDiv"> <upload ref="loadInfluence" ></upload> </div> </el-form-item> <el-form-item label="异常属性数据" > <div class="uploadDiv"> <upload ref="loadProperty" ></upload> </div> </el-form-item> </el-form> <div class="btnPosition"> <el-button type="primary" size="default" @click="cancel">取消</el-button> <el-button type="primary" size="default" @click="submitData">提交</el-button> </div> </el-card> <!-- ref="mainCRef" 控制子组件 --> <mainC v-if="scene === 2" @changemainScene="changeSceneTo"></mainC> </template>
<script setup lang="ts"> import {ref, provide} from 'vue' import {reqSubmitData} from '@/api/map/index' import upload from './upload/index.vue' import mainC from '@/view/mainC/index.vue' import { ElMessage } from 'element-plus'; let scene = ref(0) // 父传给子的属性 // let intensityFileList:Array<any> =[]; // let impactFileList:Array<any> = []; // let attributeFileList:Array<any> = []; provide('pscene', scene) //数据上传页面所需变量 let dataUpLoadVar = ref<any>({ name:'', type:'', date:'', intensity:'', influence:'', property:'' }) // 获取子组件的实例 const loadIntensity = ref() const loadInfluence = ref() const loadProperty = ref() let mainCRef = ref() const addData = ()=>{ scene.value = 1 console.log('添加数据') //导入本地数据
} // 提交函数 const submitData = () => { console.log('提交数据') const formData = new FormData() formData.append('name', dataUpLoadVar.value.name) formData.append('type', dataUpLoadVar.value.type) formData.append('date', dataUpLoadVar.value.date) // console.log(loadIntensity.value.fileList[0].url) // console.log(loadInfluence.value.fileList[0].url) // console.log(loadProperty.value.fileList[0].url) formData.append('intensity_file',loadIntensity.value.fileList[0].url) formData.append('impact_file', loadInfluence.value.fileList[0].url) formData.append('attribute_file', loadProperty.value.fileList[0].url) // 不能直接console.log(FormData),需要遍历 // 打印 FormData 对象的内容 for (let [key, value] of formData.entries()) { console.log(key, value) }
// 提交数据 reqSubmitData(formData).then(res => { console.log(res) if (res.code === 200) { console.log('提交成功') } else { console.log('提交失败') ElMessage.error('提交失败') } }) // 清空数据 dataUpLoadVar = Object.assign(dataUpLoadVar.value, { name: '', type: '', date: '', // ... })
//切换场景 scene.value = 0 }
const cancel = ()=>{ console.log('取消') // 清空数据 dataUpLoadVar = Object.assign(dataUpLoadVar.value,{ name:'', type:'', date:'', intensity:'', influence:'', property:'' }) //切换场景 scene.value = 0 } const changeSceneTo = (num: number)=>{ scene.value = num } </script>
|