添加导入提示

This commit is contained in:
庞东林
2022-01-05 17:40:21 +08:00
parent bf4a31a4a1
commit 19b5a12146
3 changed files with 143 additions and 260 deletions

View File

@@ -1,6 +1,11 @@
import axios from 'axios'; import axios from 'axios';
// ----------------------列表----------------------- // ----------------------列表-----------------------
const pageBillUrl = '/lakeLibrary/lakeLibraryInnerCityBill/page'; const pageBillUrl = '/lakeLibrary/lakeLibraryInnerCityBill/page';
const getInnerData = function (data) {
return axios.get(pageBillUrl,{params:data})
}
// 添加 // 添加
const saveLakeBill = function (data) { const saveLakeBill = function (data) {
return axios.post("/lakeLibrary/lakeLibraryInnerCityBill/importBatch",data) return axios.post("/lakeLibrary/lakeLibraryInnerCityBill/importBatch",data)
@@ -75,6 +80,7 @@ export {
getHistoryyears, getHistoryyears,
getColumnOptions, getColumnOptions,
statisticSourceUrl, statisticSourceUrl,
statisticYearUrl statisticYearUrl,
getInnerData
} }

View File

@@ -1,6 +1,9 @@
import axios from 'axios'; import axios from 'axios';
// ----------------------列表----------------------- // ----------------------列表-----------------------
const pageBillUrl = '/lakeLibrary/lakeLibrarySpecialBill/page'; const pageBillUrl = '/lakeLibrary/lakeLibrarySpecialBill/page';
const getSpecialData = function (data) {
return axios.get(pageBillUrl,{params:data})
}
// 添加 // 添加
const saveLakeBill = function (data) { const saveLakeBill = function (data) {
return axios.post("/lakeLibrary/lakeLibrarySpecialBill/importBatch",data) return axios.post("/lakeLibrary/lakeLibrarySpecialBill/importBatch",data)
@@ -72,6 +75,6 @@ export {
avgUrl, avgUrl,
getHistoryyears, getHistoryyears,
getColumnOptions, getColumnOptions,
getSpecialData
} }

View File

@@ -83,6 +83,12 @@ import { DownOutlined } from "@ant-design/icons-vue";
// import {saveLakeBill} from "@/api/ecology/lake"; // import {saveLakeBill} from "@/api/ecology/lake";
// import {saveLakeBill as saveSpecialLake} from "@/api/ecology/special-lake"; // import {saveLakeBill as saveSpecialLake} from "@/api/ecology/special-lake";
import {importCityOther,importCppointCity,importSpecial} from "@/api/ecology/water/lake/import"; import {importCityOther,importCppointCity,importSpecial} from "@/api/ecology/water/lake/import";
import {
getInnerData
} from "@/api/ecology/lake";
import {
getSpecialData
} from "@/api/ecology/special-lake";
export default { export default {
name: "LakeCollectIndex", name: "LakeCollectIndex",
@@ -94,9 +100,27 @@ export default {
data() { data() {
return { return {
activeKey: "water", activeKey: "water",
waterData:[],
specialData:[]
}; };
}, },
created(){
this.reload()
},
methods: { methods: {
getInnerData(){
getInnerData({page: 1, limit: 1000}).then(res=>{
this.waterData = res.data.data
})
},
getSpecialData(){
getSpecialData({page: 1, limit: 1000}).then(res=>{
this.specialData = res.data.data
})
},
// 模板下载 // 模板下载
download (name,url){ download (name,url){
var a = document.createElement("a"); var a = document.createElement("a");
@@ -111,121 +135,66 @@ export default {
document.getElementById(e.key).click() document.getElementById(e.key).click()
}, },
/* 导入本地excel文件 */ /* 导入本地excel文件 */
importFileInnerCity(file) { importFileCity(file,hide){
const hide = this.$message.loading("导入中..", 0);
const formData = new FormData(); const formData = new FormData();
formData.append('file', file); formData.append('file', file);
importCityOther(formData).then(res=>{ importCityOther(formData).then(res=>{
console.log(res) console.log(res)
if(!res.data.code){ if(!res.data.code){
Modal.success({ title:res.data.msg, }); Modal.success({ title:res.data.msg, });
}else{ this.reload()
Modal.error({ title:res.data.msg || '文件导入失败', }); }else{
Modal.error({ title:res.data.msg || '文件导入失败', });
}
hide()
}).catch(err=>{
console.log(err)
Modal.error({ title:err.data.msg || '文件导入失败', });
hide()
})
},
importFileInnerCity(file) {
const hide = this.$message.loading("导入中..", 0);
const table = this.waterData;
let isHas = false;
if(Array.isArray(table) && table.length>0){
table.forEach(item=>{
if(item.billName==file.name){
isHas = true
} }
hide()
}).catch(err=>{
console.log(err)
Modal.error({ title:err.data.msg || '文件导入失败', });
hide()
}) })
}
// let reader = new FileReader(); if(isHas){
// reader.onload = (e) => { const _this = this;
// try { Modal.confirm({
// let data = new Uint8Array(e.target.result); title: '有重复数据,确认是否覆盖?',
// let workbook = XLSX.read(data, { onOk() {
// type: "array", _this.importFileCity(file,hide)
// }); },
// //0.昼间数据 1.夜间数据 2.其他信息 onCancel() {
// let sheetNames = workbook.SheetNames; console.log('Cancel');
// // 解析成二维数组 hide()
// let aoa = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[0]], { },
// header: 1, });
// }); }else{
this.importFileCity(file,hide)
// const reportDate = aoa[2][0].replace(/[^\d]+/g, "-"); }
// const lakeList = aoa.filter(
// (item) => {
// return item.length >= 24 && item[0] && !item[0].includes("点位名称");
// }
// );
// // 解析成对象数组
// const billName = file.name;
// const billData = utils.toInnerCityLakeObjData(lakeList, reportDate);
// if (!billData || billData.length == 0) {
// hide()
// Modal.error({
// title: "导入失败",
// content: "找不到数据",
// });
// return;
// }
// const tasks = [];
// if (billData.length > 0) {
// tasks.push(
// saveLakeBill({
// reportTime: new Date(reportDate).getTime(),
// billName: billName,
// regionLevel: "市级",
// lakeLibraryInnerCityList: billData,
// })
// );
// }
// // 上传到服务器
// Promise.all(tasks)
// .then((res) => {
// if (res[0].data.code == 0) {
// Modal.success({
// title: "导入成功",
// content: `成功导入${billData.length}条数据`,
// });
// this.$refs.water && this.$refs.water.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; return false;
}, },
importFileWuxiang(file) {
const hide = this.$message.loading("导入中..", 0);
const formData = new FormData(); importWuXiang(file,hide){
const formData = new FormData();
formData.append('file', file); formData.append('file', file);
importCppointCity(formData).then(res=>{ importCppointCity(formData).then(res=>{
console.log(res) console.log(res)
if(!res.data.code){ if(!res.data.code){
Modal.success({ title:res.data.msg, }); Modal.success({ title:res.data.msg, });
this.reload()
}else{ }else{
Modal.error({ title:res.data.msg || '文件导入失败', }); Modal.error({ title:res.data.msg || '文件导入失败', });
} }
@@ -235,95 +204,45 @@ export default {
Modal.error({ title:err.data.msg || '文件导入失败', }); Modal.error({ title:err.data.msg || '文件导入失败', });
hide() hide()
}) })
},
importFileWuxiang(file) {
const hide = this.$message.loading("导入中..", 0);
const table = this.waterData;
let isHas = false;
if(Array.isArray(table) && table.length>0){
table.forEach(item=>{
if(item.billName==file.name){
isHas = true
}
})
}
// let reader = new FileReader(); if(isHas){
// reader.onload = (e) => { const _this = this;
// try { Modal.confirm({
// let data = new Uint8Array(e.target.result); title: '有重复数据,确认是否覆盖?',
// let workbook = XLSX.read(data, { onOk() {
// type: "array", _this.importWuXiang(file,hide)
// }); },
// let sheetNames = workbook.SheetNames; onCancel() {
// // 解析成二维数组 console.log('Cancel');
// let aoa = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[0]], { hide()
// header: 1, },
// }); });
// const lakeList = aoa.filter( }else{
// (item) => { this.importWuXiang(file,hide)
// return item.length >= 24 && item[0] && !item[0].includes("点位名称"); }
// }
// );
// // 解析成对象数组
// const billName = file.name;
// const billData = utils.toWuxiangLakeObjData(lakeList);
// if (!billData || billData.length == 0) {
// hide()
// Modal.error({
// title: "导入失败",
// content: "找不到数据",
// });
// return;
// }
// const tasks = [];
// if (billData.length > 0) {
// tasks.push(
// saveLakeBill({
// billName: billName,
// lakeLibraryInnerCityList: billData,
// })
// );
// }
// // 上传到服务器
// Promise.all(tasks)
// .then((res) => {
// if (res[0].data.code == 0) {
// Modal.success({
// title: "导入成功",
// content: `成功导入${billData.length}条数据`,
// });
// this.$refs.water && this.$refs.water.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; return false;
}, },
importFileSpecial(file) {
const hide = this.$message.loading("导入中..", 0); importSpecialFile(file,hide){
const formData = new FormData(); const formData = new FormData();
formData.append('file', file); formData.append('file', file);
importSpecial(formData).then(res=>{ importSpecial(formData).then(res=>{
console.log(res)
if(!res.data.code){ if(!res.data.code){
Modal.success({ title:res.data.msg, }); Modal.success({ title:res.data.msg, });
this.reload()
}else{ }else{
Modal.error({ title:res.data.msg || '文件导入失败', }); Modal.error({ title:res.data.msg || '文件导入失败', });
} }
@@ -333,87 +252,42 @@ export default {
Modal.error({ title:err.data.msg || '文件导入失败', }); Modal.error({ title:err.data.msg || '文件导入失败', });
hide() hide()
}) })
},
// let reader = new FileReader(); importFileSpecial(file) {
// reader.onload = (e) => { const hide = this.$message.loading("导入中..", 0);
// try { const table = this.specialData;
// let data = new Uint8Array(e.target.result); let isHas = false;
// let workbook = XLSX.read(data, { if(Array.isArray(table) && table.length>0){
// type: "array", table.forEach(item=>{
// }); if(item.billName==file.name){
// let sheetNames = workbook.SheetNames; isHas = true
// // 解析成二维数组 }
// let aoa = XLSX.utils.sheet_to_json(workbook.Sheets[sheetNames[0]], { })
// header: 1, }
// });
// const lakeList = aoa.filter(
// (item) => {
// return item.length >= 24 && item[1] && !item[1].includes("测站名称");
// }
// );
// // 解析成对象数组
// const billName = file.name;
// const billData = utils.toSpecialLakeData(lakeList);
// if (!billData || billData.length == 0) {
// hide()
// Modal.error({
// title: "导入失败",
// content: "找不到数据",
// });
// return;
// }
// const tasks = [];
// if (billData.length > 0) {
// tasks.push(
// saveSpecialLake({
// billName: billName,
// lakeLibrarySpecialList: billData,
// })
// );
// }
if(isHas){
// // 上传到服务器 const _this = this;
Modal.confirm({
// Promise.all(tasks) title: '有重复数据,确认是否覆盖?',
// .then((res) => { onOk() {
// if (res[0].data.code == 0) { _this.importSpecialFile(file,hide)
// Modal.success({ },
// title: "导入成功", onCancel() {
// content: `成功导入${billData.length}条数据`, console.log('Cancel');
// }); hide()
// this.$refs.special && this.$refs.special.reload(); },
// } else { });
// Modal.error({ }else{
// title: "导入失败", this.importSpecialFile(file,hide)
// 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; return false;
}, },
reload(){
this.getInnerData()
this.getSpecialData()
}
}, },
}; };
</script> </script>