江河水模块代码提交

This commit is contained in:
shixiaoman
2021-11-18 17:11:38 +08:00
parent f58090ad06
commit 3d7b525650
30 changed files with 3168 additions and 309 deletions

View File

@@ -2,29 +2,75 @@
<div class="ele-body">
<a-card style="width: 100%" :bordered="false">
<template #title>
<a-space>
<a-upload
:before-upload="importFileCity"
:showUploadList="false"
accept=".xls,.xlsx,.csv"
>
<div>
<a-space>
<a-upload
:before-upload="importFileCity"
:showUploadList="false"
accept=".xls,.xlsx,.csv"
>
<a-button>江河导入</a-button>
</a-upload>
<a-upload
:before-upload="importFileFunctionArea"
:showUploadList="false"
accept=".xls,.xlsx,.csv"
>
<a-button>水功能区导入</a-button>
</a-upload>
<a-upload
:before-upload="importFileStation"
:showUploadList="false"
accept=".xls,.xlsx,.csv"
>
<a-button>水站导入</a-button>
</a-upload>
</a-upload>
<a-button @click="showModal" >水功能区导入</a-button>
<a-modal v-model:visible="visible" title="水功能区导入" :footer="null">
<a-select allowClear placeholder="请选择行政级别" @change="currentVal" style="width:150px">
<a-select-option :value="'1'">国家级水功能</a-select-option>
<a-select-option :value="'2'">区控水站水功能</a-select-option>
</a-select>
<a-upload
:before-upload="importFileFunctionArea"
:showUploadList="false"
accept=".xls,.xlsx,.csv">
<a-button key="submit" type="primary" :loading="loading">导入</a-button>
</a-upload>
</a-modal>
<a-button @click="showModalWater" >水站导入</a-button>
<a-modal v-model:visible="visibleWater" title="水站导入" :footer="null">
<a-select allowClear placeholder="请选择站名" @change="currentSel" style="width:150px">
<a-select-option
v-for="item in form"
:key="item.waterStationPointId"
:label="item.stationName" :value="item"
>{{item.stationName}}</a-select-option
>
</a-select>
<a-upload
:before-upload="importFileStation"
:showUploadList="false"
accept=".xls,.xlsx,.csv">
<a-button key="submit" type="primary" :loading="loading">导入</a-button>
</a-upload>
</a-modal>
<a-button @click="templateExp" >模板下载</a-button>
<a-modal v-model:visible="visibleTemplate" title="模板下载" :footer="null">
<div>
<a-button @click="downloadRiver">江河模板下载</a-button>
</div>
<div>
<a-button @click="downloadNational">国家级水功能模板下载</a-button>
<a-button @click="downloadWater">区控水功能模板下载</a-button>
</div>
<div>
<a-button @click="downloadState">国家水站模板下载</a-button>
<a-button @click="downloadCity">广西水站模板下载</a-button>
</div>
</a-modal>
</a-space>
</div>
<!-- <div>
<a-space align="center" style="margin-top: 10px;">
<a-button @click="downloadRiver">江河模板下载</a-button>
<a-button @click="downloadNational">国家级水功能模板下载</a-button>
<a-button @click="downloadState">国家水站模板下载</a-button>
</a-space>
</div>
<div>
<a-space align="center" style="margin-top: 10px;">
<a-button > </a-button>
<a-button @click="downloadWater" style="margin-left:85px">区控水功能模板下载</a-button>
<a-button @click="downloadCity" style="margin-left:13px">广西水站模板下载</a-button>
</a-space>
</div> -->
</template>
<a-tabs v-model:activeKey="activeKey">
<a-tab-pane tab="江河信息" key="water">
@@ -52,8 +98,14 @@ import {saveWaterFunctionAreaBill} from "@/api/ecology/water-function-area"
import {saveRiverBill} from "@/api/ecology/river";
import {saveRiverStationBill} from "@/api/ecology/river-station";
import {listInfo} from "@/api/ecology/water/river-water";
import {saveRiverSiteBill} from "@/api/ecology/river-site";
import {downloadTemplate} from "@/utils/excel-util";
export default {
name: "RiverCollectIndex",
components: {
WaterBill,
FunctionBill,
@@ -62,9 +114,63 @@ export default {
data() {
return {
activeKey: "functionWater",
visible: false,
exportType:String,
visibleWater:false,
visibleTemplate:false,
form:{},
param:{}
};
},
methods: {
//模板下载
downloadRiver() {
let filename = "江河"
(filename)
},
downloadNational() {
let filename = "国家级水功能区"
downloadTemplate(filename)
},
downloadWater() {
let filename = "区控水功能区"
downloadTemplate(filename)
},
downloadState() {
let filename = "国家水站"
downloadTemplate(filename)
},
downloadCity() {
let filename = "广西水站"
downloadTemplate(filename)
},
currentSel(selVal) {
this.param.waterStationPointId = selVal.waterStationPointId;
this.param.riverName = selVal.riverName;
this.param.stationName = selVal.stationName;
this.param.system = selVal.system;
this.param.waterTarget = selVal.waterTarget;
},
currentVal(val) {
this.exportType = val;
},
showModal(){
this.visible = true;
},
templateExp(){
this.visibleTemplate = true;
},
showModalWater(){
listInfo().then((res) => {
if (res.data.code == 0) {
console.log(res.data.data)
this.visibleWater = true;
this.form = res.data.data
} else {
this.$message.error(res.data.msg);
}
})
},
/* 导入本地excel文件 */
importFileCity(file) {
const hide = this.$message.loading("导入中..", 0);
@@ -174,13 +280,25 @@ export default {
});
const riverList = aoa.filter(
(item) => {
console.log(item[8])
return item.length >= 30 && item[8] && item[8] != "水体类型"
console.log("export"+this.exportType)
if(this.exportType == "1"){ //国家级水功能
return item.length >= 30 && item[8] && item[8] != "水体类型"
}else{ //区控水站水功能模板
return item[6] && item[6] != "站点名称"
}
}
);
console.log(riverList)
// 解析成对象数组
const billName = file.name;
const billData = utils.toNationalLevelDataObj(riverList);
var billData;
if(this.exportType == "1"){
billData = utils.toNationalLevelDataObj(riverList);
}else{
billData = utils.towaterStationDataObj(riverList);
}
if (!billData || billData.length == 0) {
hide()
Modal.error({
@@ -191,15 +309,27 @@ export default {
}
const tasks = [];
if (billData.length > 0) {
tasks.push(
saveWaterFunctionAreaBill({
billName: billName,
nationalLevelWaterFunctionAreaList: billData,
})
);
if(this.exportType == "1"){
tasks.push(
saveWaterFunctionAreaBill({
billName: billName,
regionLevel:this.exportType,
nationalLevelWaterFunctionAreaList: billData,
})
);
}else{
tasks.push(
saveRiverStationBill({
billName: billName,
regionLevel:this.exportType,
waterStationWaterFunctionAreaList: billData,
})
);
}
}
// 上传到服务器
console.log(tasks);
Promise.all(tasks)
.then((res) => {
if (res[0].data.code == 0) {
@@ -207,11 +337,12 @@ export default {
title: "导入成功",
content: `成功导入${billData.length}条数据`,
});
this.visible=false;
this.$refs.functionWater && this.$refs.functionWater.reload();
} else {
Modal.error({
title: "导入失败",
content: "数据上传出错",
content: res[0].data.msg,
});
}
@@ -247,6 +378,7 @@ export default {
let data = new Uint8Array(e.target.result);
let workbook = XLSX.read(data, {
type: "array",
cellDates:true
});
let sheetNames = workbook.SheetNames;
// 解析成二维数组
@@ -255,12 +387,25 @@ export default {
});
const riverList = aoa.filter(
(item) => {
return item.length >= 15 && item[0] && item[0] != "序号"
if(this.param.system == "1"){
return item[1] && item[1] != "时间"
}else{
return item[2] && item[2] != "时间" && item[2] != "三类标准"&& item[2] != "平均值"&& item[2] != "最大值"&& item[2] != "最小值"&& item[2] != "有效数据个数"&& item[2] != "总数据个数"
}
}
);
console.log(riverList)
// 解析成对象数组
const billName = file.name;
const billData = utils.toRiverStationObjData(riverList);
var billData;
if(this.param.system == "1"){ //国家系统
billData = utils.toRiverStationObjData(riverList,this.param);
}else{
billData = utils.toCityStationObjData(riverList,this.param);
}
if (!billData || billData.length == 0) {
hide()
Modal.error({
@@ -272,9 +417,10 @@ export default {
const tasks = [];
if (billData.length > 0) {
tasks.push(
saveRiverStationBill({
saveRiverSiteBill({
billName: billName,
waterStationWaterFunctionAreaList: billData,
systemType:this.param.system,
waterSiteList: billData,
})
);
}
@@ -287,6 +433,7 @@ export default {
title: "导入成功",
content: `成功导入${billData.length}条数据`,
});
this.visibleWater=false;
this.$refs.station && this.$refs.station.reload();
} else {
Modal.error({