添加导入提示

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

View File

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

View File

@@ -83,6 +83,12 @@ import { DownOutlined } from "@ant-design/icons-vue";
// import {saveLakeBill} from "@/api/ecology/lake";
// import {saveLakeBill as saveSpecialLake} from "@/api/ecology/special-lake";
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 {
name: "LakeCollectIndex",
@@ -94,9 +100,27 @@ export default {
data() {
return {
activeKey: "water",
waterData:[],
specialData:[]
};
},
created(){
this.reload()
},
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){
var a = document.createElement("a");
@@ -111,121 +135,66 @@ export default {
document.getElementById(e.key).click()
},
/* 导入本地excel文件 */
importFileInnerCity(file) {
const hide = this.$message.loading("导入中..", 0);
importFileCity(file,hide){
const formData = new FormData();
formData.append('file', file);
importCityOther(formData).then(res=>{
console.log(res)
if(!res.data.code){
Modal.success({ title:res.data.msg, });
}else{
Modal.error({ title:res.data.msg || '文件导入失败', });
importCityOther(formData).then(res=>{
console.log(res)
if(!res.data.code){
Modal.success({ title:res.data.msg, });
this.reload()
}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();
// 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 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);
if(isHas){
const _this = this;
Modal.confirm({
title: '有重复数据,确认是否覆盖?',
onOk() {
_this.importFileCity(file,hide)
},
onCancel() {
console.log('Cancel');
hide()
},
});
}else{
this.importFileCity(file,hide)
}
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);
importCppointCity(formData).then(res=>{
console.log(res)
if(!res.data.code){
Modal.success({ title:res.data.msg, });
this.reload()
}else{
Modal.error({ title:res.data.msg || '文件导入失败', });
}
@@ -235,95 +204,45 @@ export default {
Modal.error({ title:err.data.msg || '文件导入失败', });
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();
// 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 lakeList = aoa.filter(
// (item) => {
// 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);
if(isHas){
const _this = this;
Modal.confirm({
title: '有重复数据,确认是否覆盖?',
onOk() {
_this.importWuXiang(file,hide)
},
onCancel() {
console.log('Cancel');
hide()
},
});
}else{
this.importWuXiang(file,hide)
}
return false;
},
importFileSpecial(file) {
const hide = this.$message.loading("导入中..", 0);
importSpecialFile(file,hide){
const formData = new FormData();
formData.append('file', file);
importSpecial(formData).then(res=>{
console.log(res)
if(!res.data.code){
Modal.success({ title:res.data.msg, });
this.reload()
}else{
Modal.error({ title:res.data.msg || '文件导入失败', });
}
@@ -333,87 +252,42 @@ export default {
Modal.error({ title:err.data.msg || '文件导入失败', });
hide()
})
},
// 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 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,
// })
// );
// }
importFileSpecial(file) {
const hide = this.$message.loading("导入中..", 0);
const table = this.specialData;
let isHas = false;
if(Array.isArray(table) && table.length>0){
table.forEach(item=>{
if(item.billName==file.name){
isHas = true
}
})
}
// // 上传到服务器
// Promise.all(tasks)
// .then((res) => {
// if (res[0].data.code == 0) {
// Modal.success({
// title: "导入成功",
// content: `成功导入${billData.length}条数据`,
// });
// this.$refs.special && this.$refs.special.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);
if(isHas){
const _this = this;
Modal.confirm({
title: '有重复数据,确认是否覆盖?',
onOk() {
_this.importSpecialFile(file,hide)
},
onCancel() {
console.log('Cancel');
hide()
},
});
}else{
this.importSpecialFile(file,hide)
}
return false;
},
reload(){
this.getInnerData()
this.getSpecialData()
}
},
};
</script>