导入。。。。。。。。。。。。。。。。
This commit is contained in:
@@ -8,20 +8,33 @@
|
||||
:showUploadList="false"
|
||||
accept=".xls,.xlsx,.csv"
|
||||
>
|
||||
<a-button>市级导入</a-button>
|
||||
<a-button>江河导入</a-button>
|
||||
</a-upload>
|
||||
<!-- <a-upload
|
||||
:before-upload="importFileArea"
|
||||
<a-upload
|
||||
:before-upload="importFileFunctionArea"
|
||||
:showUploadList="false"
|
||||
accept=".xls,.xlsx,.csv"
|
||||
>
|
||||
<a-button>县级导入</a-button>
|
||||
</a-upload> -->
|
||||
<a-button>水功能区导入</a-button>
|
||||
</a-upload>
|
||||
<a-upload
|
||||
:before-upload="importFileStation"
|
||||
:showUploadList="false"
|
||||
accept=".xls,.xlsx,.csv"
|
||||
>
|
||||
<a-button>水站导入</a-button>
|
||||
</a-upload>
|
||||
</a-space>
|
||||
</template>
|
||||
<a-tabs v-model:activeKey="activeKey">
|
||||
<a-tab-pane tab="噪声信息" key="noise">
|
||||
<water-bill ref="noise"></water-bill>
|
||||
<a-tab-pane tab="江河信息" key="water">
|
||||
<water-bill ref="water"></water-bill>
|
||||
</a-tab-pane>
|
||||
<a-tab-pane tab="水功能区" key="functionWater">
|
||||
<function-bill ref="functionWater"></function-bill>
|
||||
</a-tab-pane>
|
||||
<a-tab-pane tab="水站" key="station">
|
||||
<station-bill ref="station"></station-bill>
|
||||
</a-tab-pane>
|
||||
</a-tabs>
|
||||
</a-card>
|
||||
@@ -33,16 +46,22 @@ import XLSX from "xlsx";
|
||||
import utils from "./utils";
|
||||
import {Modal} from "ant-design-vue";
|
||||
import WaterBill from "./water-bill.vue";
|
||||
import FunctionBill from "../../water-function-area/collect/water-bill"
|
||||
import StationBill from "../../river-station/collect/water-bill"
|
||||
import {saveWaterFunctionAreaBill} from "@/api/ecology/water-function-area"
|
||||
import {saveRiverBill} from "@/api/ecology/river";
|
||||
import {saveRiverStationBill} from "@/api/ecology/river-station";
|
||||
|
||||
export default {
|
||||
name: "RiverCollectIndex",
|
||||
components: {
|
||||
WaterBill,
|
||||
FunctionBill,
|
||||
StationBill
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
activeKey: "noise",
|
||||
activeKey: "functionWater",
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
@@ -106,7 +125,7 @@ export default {
|
||||
title: "导入成功",
|
||||
content: `成功导入${billData.length}条数据`,
|
||||
});
|
||||
this.$refs.noise && this.$refs.noise.reload();
|
||||
this.$refs.water && this.$refs.water.reload();
|
||||
} else {
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
@@ -137,7 +156,168 @@ export default {
|
||||
|
||||
return false;
|
||||
},
|
||||
importFileFunctionArea(file) {
|
||||
const hide = this.$message.loading("导入中..", 0);
|
||||
|
||||
let reader = new FileReader();
|
||||
reader.onload = (e) => {
|
||||
try {
|
||||
let data = new Uint8Array(e.target.result);
|
||||
let workbook = XLSX.read(data, {
|
||||
type: "array",
|
||||
});
|
||||
//0.昼间数据 1.夜间数据 2.其他信息
|
||||
let sheetNames = workbook.SheetNames;
|
||||
// 解析成二维数组
|
||||
let aoa = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[0]], {
|
||||
header: 1,
|
||||
});
|
||||
const riverList = aoa.filter(
|
||||
(item) => {
|
||||
console.log(item[8])
|
||||
return item.length >= 30 && item[8] && item[8] != "水体类型"
|
||||
}
|
||||
);
|
||||
// 解析成对象数组
|
||||
const billName = file.name;
|
||||
const billData = utils.toNationalLevelDataObj(riverList);
|
||||
if (!billData || billData.length == 0) {
|
||||
hide()
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: "找不到数据",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const tasks = [];
|
||||
if (billData.length > 0) {
|
||||
tasks.push(
|
||||
saveWaterFunctionAreaBill({
|
||||
billName: billName,
|
||||
nationalLevelWaterFunctionAreaList: billData,
|
||||
})
|
||||
);
|
||||
}
|
||||
// 上传到服务器
|
||||
|
||||
Promise.all(tasks)
|
||||
.then((res) => {
|
||||
if (res[0].data.code == 0) {
|
||||
Modal.success({
|
||||
title: "导入成功",
|
||||
content: `成功导入${billData.length}条数据`,
|
||||
});
|
||||
this.$refs.functionWater && this.$refs.functionWater.reload();
|
||||
} else {
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: "数据上传出错",
|
||||
});
|
||||
}
|
||||
|
||||
})
|
||||
.catch(() => {
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: "数据上传出错",
|
||||
});
|
||||
})
|
||||
.finally(() => {
|
||||
hide();
|
||||
});
|
||||
} catch (error) {
|
||||
hide();
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: error.message,
|
||||
});
|
||||
}
|
||||
// console.log(billData);
|
||||
};
|
||||
reader.readAsArrayBuffer(file);
|
||||
|
||||
return false;
|
||||
},
|
||||
importFileStation(file) {
|
||||
const hide = this.$message.loading("导入中..", 0);
|
||||
|
||||
let reader = new FileReader();
|
||||
reader.onload = (e) => {
|
||||
try {
|
||||
let data = new Uint8Array(e.target.result);
|
||||
let workbook = XLSX.read(data, {
|
||||
type: "array",
|
||||
});
|
||||
let sheetNames = workbook.SheetNames;
|
||||
// 解析成二维数组
|
||||
let aoa = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[0]], {
|
||||
header: 1,
|
||||
});
|
||||
const riverList = aoa.filter(
|
||||
(item) => {
|
||||
return item.length >= 15 && item[0] && item[0] != "序号"
|
||||
}
|
||||
);
|
||||
// 解析成对象数组
|
||||
const billName = file.name;
|
||||
const billData = utils.toRiverStationObjData(riverList);
|
||||
if (!billData || billData.length == 0) {
|
||||
hide()
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: "找不到数据",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const tasks = [];
|
||||
if (billData.length > 0) {
|
||||
tasks.push(
|
||||
saveRiverStationBill({
|
||||
billName: billName,
|
||||
waterStationWaterFunctionAreaList: billData,
|
||||
})
|
||||
);
|
||||
}
|
||||
// 上传到服务器
|
||||
|
||||
Promise.all(tasks)
|
||||
.then((res) => {
|
||||
if (res[0].data.code == 0) {
|
||||
Modal.success({
|
||||
title: "导入成功",
|
||||
content: `成功导入${billData.length}条数据`,
|
||||
});
|
||||
this.$refs.station && this.$refs.station.reload();
|
||||
} else {
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: "数据上传出错",
|
||||
});
|
||||
}
|
||||
|
||||
})
|
||||
.catch(() => {
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: "数据上传出错",
|
||||
});
|
||||
})
|
||||
.finally(() => {
|
||||
hide();
|
||||
});
|
||||
} catch (error) {
|
||||
hide();
|
||||
Modal.error({
|
||||
title: "导入失败",
|
||||
content: error.message,
|
||||
});
|
||||
}
|
||||
// console.log(billData);
|
||||
};
|
||||
reader.readAsArrayBuffer(file);
|
||||
|
||||
return false;
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user